Ownable.behaviour.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. const { expectThrow } = require('../helpers/expectThrow');
  2. const { EVMRevert } = require('../helpers/EVMRevert');
  3. const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
  4. require('chai')
  5. .should();
  6. function shouldBehaveLikeOwnable (accounts) {
  7. describe('as an ownable', function () {
  8. it('should have an owner', async function () {
  9. let owner = await this.ownable.owner();
  10. owner.should.not.eq(ZERO_ADDRESS);
  11. });
  12. it('changes owner after transfer', async function () {
  13. let other = accounts[1];
  14. await this.ownable.transferOwnership(other);
  15. let owner = await this.ownable.owner();
  16. owner.should.eq(other);
  17. });
  18. it('should prevent non-owners from transfering', async function () {
  19. const other = accounts[2];
  20. const owner = await this.ownable.owner.call();
  21. owner.should.not.eq(other);
  22. await expectThrow(this.ownable.transferOwnership(other, { from: other }), EVMRevert);
  23. });
  24. it('should guard ownership against stuck state', async function () {
  25. let originalOwner = await this.ownable.owner();
  26. await expectThrow(this.ownable.transferOwnership(null, { from: originalOwner }), EVMRevert);
  27. });
  28. it('loses owner after renouncement', async function () {
  29. await this.ownable.renounceOwnership();
  30. let owner = await this.ownable.owner();
  31. owner.should.eq(ZERO_ADDRESS);
  32. });
  33. it('should prevent non-owners from renouncement', async function () {
  34. const other = accounts[2];
  35. const owner = await this.ownable.owner.call();
  36. owner.should.not.eq(other);
  37. await expectThrow(this.ownable.renounceOwnership({ from: other }), EVMRevert);
  38. });
  39. });
  40. }
  41. module.exports = {
  42. shouldBehaveLikeOwnable,
  43. };