Ownable.behavior.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. const { expectThrow } = require('../helpers/expectThrow');
  2. const { EVMRevert } = require('../helpers/EVMRevert');
  3. const expectEvent = require('../helpers/expectEvent');
  4. const { ZERO_ADDRESS } = require('../helpers/constants');
  5. require('chai')
  6. .should();
  7. function shouldBehaveLikeOwnable (owner, [anyone]) {
  8. describe('as an ownable', function () {
  9. it('should have an owner', async function () {
  10. (await this.ownable.owner()).should.equal(owner);
  11. });
  12. it('changes owner after transfer', async function () {
  13. (await this.ownable.isOwner({ from: anyone })).should.be.equal(false);
  14. const { logs } = await this.ownable.transferOwnership(anyone, { from: owner });
  15. expectEvent.inLogs(logs, 'OwnershipTransferred');
  16. (await this.ownable.owner()).should.equal(anyone);
  17. (await this.ownable.isOwner({ from: anyone })).should.be.equal(true);
  18. });
  19. it('should prevent non-owners from transfering', async function () {
  20. await expectThrow(this.ownable.transferOwnership(anyone, { from: anyone }), EVMRevert);
  21. });
  22. it('should guard ownership against stuck state', async function () {
  23. await expectThrow(this.ownable.transferOwnership(null, { from: owner }), EVMRevert);
  24. });
  25. it('loses owner after renouncement', async function () {
  26. const { logs } = await this.ownable.renounceOwnership({ from: owner });
  27. expectEvent.inLogs(logs, 'OwnershipTransferred');
  28. (await this.ownable.owner()).should.equal(ZERO_ADDRESS);
  29. });
  30. it('should prevent non-owners from renouncement', async function () {
  31. await expectThrow(this.ownable.renounceOwnership({ from: anyone }), EVMRevert);
  32. });
  33. });
  34. }
  35. module.exports = {
  36. shouldBehaveLikeOwnable,
  37. };