Ownable.behavior.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 (owner, [anyone]) {
  7. describe('as an ownable', function () {
  8. it('should have an owner', async function () {
  9. (await this.ownable.owner()).should.equal(owner);
  10. });
  11. it('changes owner after transfer', async function () {
  12. (await this.ownable.isOwner({ from: anyone })).should.be.equal(false);
  13. await this.ownable.transferOwnership(anyone, { from: owner });
  14. (await this.ownable.owner()).should.equal(anyone);
  15. (await this.ownable.isOwner({ from: anyone })).should.be.equal(true);
  16. });
  17. it('should prevent non-owners from transfering', async function () {
  18. await expectThrow(this.ownable.transferOwnership(anyone, { from: anyone }), EVMRevert);
  19. });
  20. it('should guard ownership against stuck state', async function () {
  21. await expectThrow(this.ownable.transferOwnership(null, { from: owner }), EVMRevert);
  22. });
  23. it('loses owner after renouncement', async function () {
  24. await this.ownable.renounceOwnership({ from: owner });
  25. (await this.ownable.owner()).should.equal(ZERO_ADDRESS);
  26. });
  27. it('should prevent non-owners from renouncement', async function () {
  28. await expectThrow(this.ownable.renounceOwnership({ from: anyone }), EVMRevert);
  29. });
  30. });
  31. }
  32. module.exports = {
  33. shouldBehaveLikeOwnable,
  34. };