Ownable.behavior.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. const shouldFail = require('../helpers/shouldFail');
  2. const expectEvent = require('../helpers/expectEvent');
  3. const { ZERO_ADDRESS } = require('../helpers/constants');
  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. const { logs } = await this.ownable.transferOwnership(anyone, { from: owner });
  14. expectEvent.inLogs(logs, 'OwnershipTransferred');
  15. (await this.ownable.owner()).should.equal(anyone);
  16. (await this.ownable.isOwner({ from: anyone })).should.be.equal(true);
  17. });
  18. it('should prevent non-owners from transfering', async function () {
  19. await shouldFail.reverting(this.ownable.transferOwnership(anyone, { from: anyone }));
  20. });
  21. it('should guard ownership against stuck state', async function () {
  22. await shouldFail.reverting(this.ownable.transferOwnership(null, { from: owner }));
  23. });
  24. it('loses owner after renouncement', async function () {
  25. const { logs } = await this.ownable.renounceOwnership({ from: owner });
  26. expectEvent.inLogs(logs, 'OwnershipTransferred');
  27. (await this.ownable.owner()).should.equal(ZERO_ADDRESS);
  28. });
  29. it('should prevent non-owners from renouncement', async function () {
  30. await shouldFail.reverting(this.ownable.renounceOwnership({ from: anyone }));
  31. });
  32. });
  33. }
  34. module.exports = {
  35. shouldBehaveLikeOwnable,
  36. };