EnumerableSet.test.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. const EnumerableSet = artifacts.require('$EnumerableSet');
  2. const { mapValues } = require('../../helpers/map-values');
  3. const { shouldBehaveLikeSet } = require('./EnumerableSet.behavior');
  4. const getMethods = (ms) => {
  5. return mapValues(ms, m => (self, ...args) => self.methods[m](0, ...args));
  6. };
  7. contract('EnumerableSet', function (accounts) {
  8. beforeEach(async function () {
  9. this.set = await EnumerableSet.new();
  10. });
  11. // Bytes32Set
  12. describe('EnumerableBytes32Set', function () {
  13. shouldBehaveLikeSet(
  14. [ '0xdeadbeef', '0x0123456789', '0x42424242' ].map(e => e.padEnd(66, '0')),
  15. getMethods({
  16. add: '$add(uint256,bytes32)',
  17. remove: '$remove(uint256,bytes32)',
  18. contains: '$contains(uint256,bytes32)',
  19. length: '$length_EnumerableSet_Bytes32Set(uint256)',
  20. at: '$at_EnumerableSet_Bytes32Set(uint256,uint256)',
  21. values: '$values_EnumerableSet_Bytes32Set(uint256)',
  22. }),
  23. {
  24. addReturn: 'return$add_EnumerableSet_Bytes32Set_bytes32',
  25. removeReturn: 'return$remove_EnumerableSet_Bytes32Set_bytes32',
  26. },
  27. );
  28. });
  29. // AddressSet
  30. describe('EnumerableAddressSet', function () {
  31. shouldBehaveLikeSet(
  32. accounts,
  33. getMethods({
  34. add: '$add(uint256,address)',
  35. remove: '$remove(uint256,address)',
  36. contains: '$contains(uint256,address)',
  37. length: '$length_EnumerableSet_AddressSet(uint256)',
  38. at: '$at_EnumerableSet_AddressSet(uint256,uint256)',
  39. values: '$values_EnumerableSet_AddressSet(uint256)',
  40. }),
  41. {
  42. addReturn: 'return$add_EnumerableSet_AddressSet_address',
  43. removeReturn: 'return$remove_EnumerableSet_AddressSet_address',
  44. },
  45. );
  46. });
  47. // UintSet
  48. describe('EnumerableUintSet', function () {
  49. shouldBehaveLikeSet(
  50. [ 1234, 5678, 9101112 ].map(e => web3.utils.toBN(e)),
  51. getMethods({
  52. add: '$add(uint256,uint256)',
  53. remove: '$remove(uint256,uint256)',
  54. contains: '$contains(uint256,uint256)',
  55. length: '$length_EnumerableSet_UintSet(uint256)',
  56. at: '$at_EnumerableSet_UintSet(uint256,uint256)',
  57. values: '$values_EnumerableSet_UintSet(uint256)',
  58. }),
  59. {
  60. addReturn: 'return$add_EnumerableSet_UintSet_uint256',
  61. removeReturn: 'return$remove_EnumerableSet_UintSet_uint256',
  62. },
  63. );
  64. });
  65. });