Ownable.test.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import assertRevert from '../helpers/assertRevert';
  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. const other = accounts[2];
  20. const owner = await ownable.owner.call();
  21. assert.isTrue(owner !== other);
  22. await assertRevert(ownable.transferOwnership(other, { from: other }));
  23. });
  24. it('should guard ownership against stuck state', async function () {
  25. let originalOwner = await ownable.owner();
  26. await assertRevert(ownable.transferOwnership(null, { from: originalOwner }));
  27. });
  28. });