Ownable.behaviour.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import EVMRevert from '../helpers/EVMRevert';
  2. const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
  3. require('chai')
  4. .use(require('chai-as-promised'))
  5. .should();
  6. export default function (accounts) {
  7. describe('as an ownable', function () {
  8. it('should have an owner', async function () {
  9. let owner = await this.ownable.owner();
  10. owner.should.not.eq(ZERO_ADDRESS);
  11. });
  12. it('changes owner after transfer', async function () {
  13. let other = accounts[1];
  14. await this.ownable.transferOwnership(other);
  15. let owner = await this.ownable.owner();
  16. owner.should.eq(other);
  17. });
  18. it('should prevent non-owners from transfering', async function () {
  19. const other = accounts[2];
  20. const owner = await this.ownable.owner.call();
  21. owner.should.not.eq(other);
  22. await this.ownable.transferOwnership(other, { from: other }).should.be.rejectedWith(EVMRevert);
  23. });
  24. it('should guard ownership against stuck state', async function () {
  25. let originalOwner = await this.ownable.owner();
  26. await this.ownable.transferOwnership(null, { from: originalOwner }).should.be.rejectedWith(EVMRevert);
  27. });
  28. it('loses owner after renouncement', async function () {
  29. await this.ownable.renounceOwnership();
  30. let owner = await this.ownable.owner();
  31. owner.should.eq(ZERO_ADDRESS);
  32. });
  33. it('should prevent non-owners from renouncement', async function () {
  34. const other = accounts[2];
  35. const owner = await this.ownable.owner.call();
  36. owner.should.not.eq(other);
  37. await this.ownable.renounceOwnership({ from: other }).should.be.rejectedWith(EVMRevert);
  38. });
  39. });
  40. };