AuthorityUtils.test.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. this.immediate = true;
  49. this.delay = web3.utils.toBN(42);
  50. await this.authority._setImmediate(this.immediate);
  51. await this.authority._setDelay(this.delay);
  52. });
  53. it('returns (immediate, delay)', async function () {
  54. const { immediate, delay } = await this.mock.$canCallWithDelay(
  55. this.authority.address,
  56. user,
  57. other,
  58. '0x12345678',
  59. );
  60. expect(immediate).to.equal(this.immediate);
  61. expect(delay).to.be.bignumber.equal(this.delay);
  62. });
  63. });
  64. describe('when authority replies with empty data', function () {
  65. beforeEach(async function () {
  66. this.authority = await AuthorityNoResponse.new();
  67. });
  68. it('returns (immediate = 0, delay = 0)', async function () {
  69. const { immediate, delay } = await this.mock.$canCallWithDelay(
  70. this.authority.address,
  71. user,
  72. other,
  73. '0x12345678',
  74. );
  75. expect(immediate).to.equal(false);
  76. expect(delay).to.be.bignumber.equal('0');
  77. });
  78. });
  79. });
  80. });