EnumerableMap.test.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 { shouldBehaveLikeMap } = require('./EnumerableMap.behavior');
  6. contract('EnumerableMap', function (accounts) {
  7. const [ accountA, accountB, accountC ] = accounts;
  8. const keyA = new BN('7891');
  9. const keyB = new BN('451');
  10. const keyC = new BN('9592328');
  11. const bytesA = '0xdeadbeef'.padEnd(66, '0');
  12. const bytesB = '0x0123456789'.padEnd(66, '0');
  13. const bytesC = '0x42424242'.padEnd(66, '0');
  14. // AddressToUintMap
  15. describe('AddressToUintMap', function () {
  16. beforeEach(async function () {
  17. this.map = await AddressToUintMapMock.new();
  18. });
  19. shouldBehaveLikeMap(
  20. [accountA, accountB, accountC],
  21. [keyA, keyB, keyC],
  22. new BN('0'),
  23. );
  24. });
  25. // UintToAddressMap
  26. describe('UintToAddressMap', function () {
  27. beforeEach(async function () {
  28. this.map = await UintToAddressMapMock.new();
  29. });
  30. shouldBehaveLikeMap(
  31. [keyA, keyB, keyC],
  32. [accountA, accountB, accountC],
  33. constants.ZERO_ADDRESS,
  34. );
  35. });
  36. // Bytes32ToBytes32Map
  37. describe('Bytes32ToBytes32Map', function () {
  38. beforeEach(async function () {
  39. this.map = await Bytes32ToBytes32MapMock.new();
  40. });
  41. shouldBehaveLikeMap(
  42. [keyA, keyB, keyC].map(k => ('0x' + k.toString(16)).padEnd(66, '0')),
  43. [bytesA, bytesB, bytesC],
  44. constants.ZERO_BYTES32,
  45. );
  46. });
  47. });