Secondary.test.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. const { constants, expectEvent, shouldFail } = require('openzeppelin-test-helpers');
  2. const { ZERO_ADDRESS } = constants;
  3. const SecondaryMock = artifacts.require('SecondaryMock');
  4. contract('Secondary', function ([_, primary, newPrimary, other]) {
  5. beforeEach(async function () {
  6. this.secondary = await SecondaryMock.new({ from: primary });
  7. });
  8. it('stores the primary\'s address', async function () {
  9. (await this.secondary.primary()).should.equal(primary);
  10. });
  11. describe('onlyPrimary', function () {
  12. it('allows the primary account to call onlyPrimary functions', async function () {
  13. await this.secondary.onlyPrimaryMock({ from: primary });
  14. });
  15. it('reverts when anyone calls onlyPrimary functions', async function () {
  16. await shouldFail.reverting(this.secondary.onlyPrimaryMock({ from: other }));
  17. });
  18. });
  19. describe('transferPrimary', function () {
  20. it('makes the recipient the new primary', async function () {
  21. const { logs } = await this.secondary.transferPrimary(newPrimary, { from: primary });
  22. expectEvent.inLogs(logs, 'PrimaryTransferred', { recipient: newPrimary });
  23. (await this.secondary.primary()).should.equal(newPrimary);
  24. });
  25. it('reverts when transferring to the null address', async function () {
  26. await shouldFail.reverting(this.secondary.transferPrimary(ZERO_ADDRESS, { from: primary }));
  27. });
  28. it('reverts when called by anyone', async function () {
  29. await shouldFail.reverting(this.secondary.transferPrimary(newPrimary, { from: other }));
  30. });
  31. context('with new primary', function () {
  32. beforeEach(async function () {
  33. await this.secondary.transferPrimary(newPrimary, { from: primary });
  34. });
  35. it('allows the new primary account to call onlyPrimary functions', async function () {
  36. await this.secondary.onlyPrimaryMock({ from: newPrimary });
  37. });
  38. it('reverts when the old primary account calls onlyPrimary functions', async function () {
  39. await shouldFail.reverting(this.secondary.onlyPrimaryMock({ from: primary }));
  40. });
  41. });
  42. });
  43. });