Secondary.test.js 2.1 KB

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