Secondary.test.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. const { assertRevert } = require('../helpers/assertRevert');
  2. const { ZERO_ADDRESS } = require('../helpers/constants');
  3. const SecondaryMock = artifacts.require('SecondaryMock');
  4. require('chai')
  5. .should();
  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 assertRevert(this.secondary.onlyPrimaryMock({ from: anyone }));
  19. });
  20. });
  21. describe('transferPrimary', function () {
  22. it('makes the recipient the new primary', async function () {
  23. await this.secondary.transferPrimary(newPrimary, { from: primary });
  24. (await this.secondary.primary()).should.equal(newPrimary);
  25. });
  26. it('reverts when transfering to the null address', async function () {
  27. await assertRevert(this.secondary.transferPrimary(ZERO_ADDRESS, { from: primary }));
  28. });
  29. it('reverts when called by anyone', async function () {
  30. await assertRevert(this.secondary.transferPrimary(newPrimary, { from: anyone }));
  31. });
  32. context('with new primary', function () {
  33. beforeEach(async function () {
  34. await this.secondary.transferPrimary(newPrimary, { from: primary });
  35. });
  36. it('allows the new primary account to call onlyPrimary functions', async function () {
  37. await this.secondary.onlyPrimaryMock({ from: newPrimary });
  38. });
  39. it('reverts when the old primary account calls onlyPrimary functions', async function () {
  40. await assertRevert(this.secondary.onlyPrimaryMock({ from: primary }));
  41. });
  42. });
  43. });
  44. });