EnumerableMap.test.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. const { BN, constants } = require('@openzeppelin/test-helpers');
  2. const AddressToUintMapMock = artifacts.require('AddressToUintMapMock');
  3. const UintToAddressMapMock = artifacts.require('UintToAddressMapMock');
  4. const Bytes32ToBytes32MapMock = artifacts.require('Bytes32ToBytes32MapMock');
  5. const UintToUintMapMock = artifacts.require('UintToUintMapMock');
  6. const { shouldBehaveLikeMap } = require('./EnumerableMap.behavior');
  7. contract('EnumerableMap', function (accounts) {
  8. const [ accountA, accountB, accountC ] = accounts;
  9. const keyA = new BN('7891');
  10. const keyB = new BN('451');
  11. const keyC = new BN('9592328');
  12. const bytesA = '0xdeadbeef'.padEnd(66, '0');
  13. const bytesB = '0x0123456789'.padEnd(66, '0');
  14. const bytesC = '0x42424242'.padEnd(66, '0');
  15. // AddressToUintMap
  16. describe('AddressToUintMap', function () {
  17. beforeEach(async function () {
  18. this.map = await AddressToUintMapMock.new();
  19. });
  20. shouldBehaveLikeMap(
  21. [accountA, accountB, accountC],
  22. [keyA, keyB, keyC],
  23. new BN('0'),
  24. );
  25. });
  26. // UintToAddressMap
  27. describe('UintToAddressMap', function () {
  28. beforeEach(async function () {
  29. this.map = await UintToAddressMapMock.new();
  30. });
  31. shouldBehaveLikeMap(
  32. [keyA, keyB, keyC],
  33. [accountA, accountB, accountC],
  34. constants.ZERO_ADDRESS,
  35. );
  36. });
  37. // Bytes32ToBytes32Map
  38. describe('Bytes32ToBytes32Map', function () {
  39. beforeEach(async function () {
  40. this.map = await Bytes32ToBytes32MapMock.new();
  41. });
  42. shouldBehaveLikeMap(
  43. [keyA, keyB, keyC].map(k => ('0x' + k.toString(16)).padEnd(66, '0')),
  44. [bytesA, bytesB, bytesC],
  45. constants.ZERO_BYTES32,
  46. );
  47. });
  48. // UintToUintMap
  49. describe('UintToUintMap', function () {
  50. beforeEach(async function () {
  51. this.map = await UintToUintMapMock.new();
  52. });
  53. shouldBehaveLikeMap(
  54. [ keyA, keyB, keyC ],
  55. [ keyA, keyB, keyC ].map(k => k.add(new BN('1332'))),
  56. new BN('0'),
  57. );
  58. });
  59. });