Ownable.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. assert.fail('should have thrown before');
  26. } catch(error) {
  27. assertJump(error);
  28. }
  29. });
  30. it('should guard ownership against stuck state', async function() {
  31. let originalOwner = await ownable.owner();
  32. try {
  33. await ownable.transferOwnership(null, {from: originalOwner});
  34. assert.fail();
  35. } catch(error) {
  36. assertJump(error);
  37. }
  38. });
  39. });