Ownable.test.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import assertRevert from '../helpers/assertRevert';
  2. var Ownable = artifacts.require('Ownable');
  3. const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
  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. await assertRevert(ownable.transferOwnership(other, { from: other }));
  24. });
  25. it('should guard ownership against stuck state', async function () {
  26. let originalOwner = await ownable.owner();
  27. await assertRevert(ownable.transferOwnership(null, { from: originalOwner }));
  28. });
  29. it('loses owner after renouncement', async function () {
  30. await ownable.renounceOwnership();
  31. let owner = await ownable.owner();
  32. assert.isTrue(owner === ZERO_ADDRESS);
  33. });
  34. it('should prevent non-owners from renouncement', async function () {
  35. const other = accounts[2];
  36. const owner = await ownable.owner.call();
  37. assert.isTrue(owner !== other);
  38. await assertRevert(ownable.renounceOwnership({ from: other }));
  39. });
  40. });