Ownable.behavior.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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.transferOwnership(anyone, { from: owner });
  13. (await this.ownable.owner()).should.equal(anyone);
  14. });
  15. it('should prevent non-owners from transfering', async function () {
  16. await expectThrow(this.ownable.transferOwnership(anyone, { from: anyone }), EVMRevert);
  17. });
  18. it('should guard ownership against stuck state', async function () {
  19. await expectThrow(this.ownable.transferOwnership(null, { from: owner }), EVMRevert);
  20. });
  21. it('loses owner after renouncement', async function () {
  22. await this.ownable.renounceOwnership({ from: owner });
  23. (await this.ownable.owner()).should.equal(ZERO_ADDRESS);
  24. });
  25. it('should prevent non-owners from renouncement', async function () {
  26. await expectThrow(this.ownable.renounceOwnership({ from: anyone }), EVMRevert);
  27. });
  28. });
  29. }
  30. module.exports = {
  31. shouldBehaveLikeOwnable,
  32. };