AuthorityUtils.test.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. require('@openzeppelin/test-helpers');
  2. const AuthorityUtils = artifacts.require('$AuthorityUtils');
  3. const NotAuthorityMock = artifacts.require('NotAuthorityMock');
  4. const AuthorityNoDelayMock = artifacts.require('AuthorityNoDelayMock');
  5. const AuthorityDelayMock = artifacts.require('AuthorityDelayMock');
  6. const AuthorityNoResponse = artifacts.require('AuthorityNoResponse');
  7. contract('AuthorityUtils', function (accounts) {
  8. const [user, other] = accounts;
  9. beforeEach(async function () {
  10. this.mock = await AuthorityUtils.new();
  11. });
  12. describe('canCallWithDelay', function () {
  13. describe('when authority does not have a canCall function', function () {
  14. beforeEach(async function () {
  15. this.authority = await NotAuthorityMock.new();
  16. });
  17. it('returns (immediate = 0, delay = 0)', async function () {
  18. const { immediate, delay } = await this.mock.$canCallWithDelay(
  19. this.authority.address,
  20. user,
  21. other,
  22. '0x12345678',
  23. );
  24. expect(immediate).to.equal(false);
  25. expect(delay).to.be.bignumber.equal('0');
  26. });
  27. });
  28. describe('when authority has no delay', function () {
  29. beforeEach(async function () {
  30. this.authority = await AuthorityNoDelayMock.new();
  31. this.immediate = true;
  32. await this.authority._setImmediate(this.immediate);
  33. });
  34. it('returns (immediate, delay = 0)', async function () {
  35. const { immediate, delay } = await this.mock.$canCallWithDelay(
  36. this.authority.address,
  37. user,
  38. other,
  39. '0x12345678',
  40. );
  41. expect(immediate).to.equal(this.immediate);
  42. expect(delay).to.be.bignumber.equal('0');
  43. });
  44. });
  45. describe('when authority replies with a delay', function () {
  46. beforeEach(async function () {
  47. this.authority = await AuthorityDelayMock.new();
  48. });
  49. for (const immediate of [true, false]) {
  50. for (const delay of ['0', '42']) {
  51. it(`returns (immediate=${immediate}, delay=${delay})`, async function () {
  52. await this.authority._setImmediate(immediate);
  53. await this.authority._setDelay(delay);
  54. const result = await this.mock.$canCallWithDelay(this.authority.address, user, other, '0x12345678');
  55. expect(result.immediate).to.equal(immediate);
  56. expect(result.delay).to.be.bignumber.equal(delay);
  57. });
  58. }
  59. }
  60. });
  61. describe('when authority replies with empty data', function () {
  62. beforeEach(async function () {
  63. this.authority = await AuthorityNoResponse.new();
  64. });
  65. it('returns (immediate = 0, delay = 0)', async function () {
  66. const { immediate, delay } = await this.mock.$canCallWithDelay(
  67. this.authority.address,
  68. user,
  69. other,
  70. '0x12345678',
  71. );
  72. expect(immediate).to.equal(false);
  73. expect(delay).to.be.bignumber.equal('0');
  74. });
  75. });
  76. });
  77. });