Secondary.test.js 2.1 KB

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