EnumerableSet.test.js 2.3 KB

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