Ownable.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. 'use strict';
  2. const assertJump = require('./helpers/assertJump');
  3. var Ownable = artifacts.require('../contracts/ownership/Ownable.sol');
  4. contract('Ownable', function(accounts) {
  5. let ownable;
  6. beforeEach(async function() {
  7. ownable = await Ownable.new();
  8. });
  9. it('should have an owner', async function() {
  10. let owner = await ownable.owner();
  11. assert.isTrue(owner !== 0);
  12. });
  13. it('changes owner after transfer', async function() {
  14. let other = accounts[1];
  15. await ownable.transferOwnership(other);
  16. let owner = await ownable.owner();
  17. assert.isTrue(owner === other);
  18. });
  19. it('should prevent non-owners from transfering', async function() {
  20. const other = accounts[2];
  21. const owner = await ownable.owner.call();
  22. assert.isTrue(owner !== other);
  23. try {
  24. await ownable.transferOwnership(other, {from: other});
  25. } catch(error) {
  26. assertJump(error);
  27. }
  28. });
  29. it('should guard ownership against stuck state', async function() {
  30. let originalOwner = await ownable.owner();
  31. try {
  32. await ownable.transferOwnership(null, {from: originalOwner});
  33. assert.fail();
  34. } catch(error) {
  35. assertJump(error);
  36. }
  37. });
  38. });