Ownable.js 1.1 KB

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