Ownable.behavior.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. const shouldFail = require('../helpers/shouldFail');
  2. const expectEvent = require('../helpers/expectEvent');
  3. const { ZERO_ADDRESS } = require('../helpers/constants');
  4. require('./../helpers/setup');
  5. function shouldBehaveLikeOwnable (owner, [anyone]) {
  6. describe('as an ownable', function () {
  7. it('should have an owner', async function () {
  8. (await this.ownable.owner()).should.equal(owner);
  9. });
  10. it('changes owner after transfer', async function () {
  11. (await this.ownable.isOwner({ from: anyone })).should.be.equal(false);
  12. const { logs } = await this.ownable.transferOwnership(anyone, { from: owner });
  13. expectEvent.inLogs(logs, 'OwnershipTransferred');
  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 shouldFail.reverting(this.ownable.transferOwnership(anyone, { from: anyone }));
  19. });
  20. it('should guard ownership against stuck state', async function () {
  21. await shouldFail.reverting(this.ownable.transferOwnership(null, { from: owner }));
  22. });
  23. it('loses owner after renouncement', async function () {
  24. const { logs } = await this.ownable.renounceOwnership({ from: owner });
  25. expectEvent.inLogs(logs, 'OwnershipTransferred');
  26. (await this.ownable.owner()).should.equal(ZERO_ADDRESS);
  27. });
  28. it('should prevent non-owners from renouncement', async function () {
  29. await shouldFail.reverting(this.ownable.renounceOwnership({ from: anyone }));
  30. });
  31. });
  32. }
  33. module.exports = {
  34. shouldBehaveLikeOwnable,
  35. };