essential-eth 0.9.0 → 0.9.1-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/dist/cjs/classes/Contract.js +38 -34
  2. package/dist/cjs/classes/test/Contract/crv.test.js +146 -339
  3. package/dist/cjs/classes/test/Contract/ens-abi.d.ts +1 -1
  4. package/dist/cjs/classes/test/Contract/ens.test.js +9 -66
  5. package/dist/cjs/classes/test/Contract/fei.test.js +11 -11
  6. package/dist/cjs/classes/test/Contract/foo-abi.d.ts +1 -1
  7. package/dist/cjs/classes/test/Contract/uni.test.js +66 -164
  8. package/dist/cjs/classes/utils/clean-block.js +4 -4
  9. package/dist/cjs/classes/utils/clean-log.js +4 -4
  10. package/dist/cjs/classes/utils/clean-transaction-receipt.js +4 -4
  11. package/dist/cjs/classes/utils/clean-transaction.js +4 -4
  12. package/dist/cjs/classes/utils/encode-decode-transaction.js +10 -10
  13. package/dist/cjs/classes/utils/fetchers.d.ts +8 -2
  14. package/dist/cjs/classes/utils/fetchers.js +20 -12
  15. package/dist/cjs/classes/utils/prepare-transaction.js +4 -4
  16. package/dist/cjs/index.d.ts +21 -22
  17. package/dist/cjs/index.js +21 -22
  18. package/dist/cjs/index.umd.js +1 -1
  19. package/dist/cjs/index.umd.js.map +1 -1
  20. package/dist/cjs/logger/logger.js +79 -41
  21. package/dist/cjs/logger/package-version.d.ts +1 -1
  22. package/dist/cjs/logger/package-version.js +1 -1
  23. package/dist/cjs/providers/AlchemyProvider.js +22 -22
  24. package/dist/cjs/providers/BaseProvider.js +471 -404
  25. package/dist/cjs/providers/FallthroughProvider.js +62 -30
  26. package/dist/cjs/providers/JsonRpcProvider.js +52 -31
  27. package/dist/cjs/providers/test/fallthrough-provider/get-gas-price.test.js +9 -9
  28. package/dist/cjs/providers/test/get-transaction-count.test.js +54 -91
  29. package/dist/cjs/providers/test/json-rpc-provider/call.test.js +87 -148
  30. package/dist/cjs/providers/test/json-rpc-provider/estimate-gas.test.js +45 -116
  31. package/dist/cjs/providers/test/json-rpc-provider/get-balance.test.js +36 -74
  32. package/dist/cjs/providers/test/json-rpc-provider/get-block-number.test.js +13 -9
  33. package/dist/cjs/providers/test/json-rpc-provider/get-block.test.js +191 -254
  34. package/dist/cjs/providers/test/json-rpc-provider/get-code.test.js +106 -135
  35. package/dist/cjs/providers/test/json-rpc-provider/get-fee-data.test.js +48 -73
  36. package/dist/cjs/providers/test/json-rpc-provider/get-gas-price.test.js +11 -8
  37. package/dist/cjs/providers/test/json-rpc-provider/get-logs/get-logs.test.js +219 -0
  38. package/dist/cjs/providers/test/json-rpc-provider/get-logs/mocks.d.ts +14 -0
  39. package/dist/cjs/providers/test/json-rpc-provider/get-logs/mocks.js +149 -0
  40. package/dist/cjs/providers/test/json-rpc-provider/get-network.test.js +37 -79
  41. package/dist/cjs/providers/test/json-rpc-provider/get-transaction-receipt.test.js +136 -157
  42. package/dist/cjs/providers/test/json-rpc-provider/get-transaction.test.js +121 -162
  43. package/dist/cjs/providers/test/mock-of.js +0 -5
  44. package/dist/cjs/providers/test/rpc-urls.d.ts +1 -0
  45. package/dist/cjs/providers/test/rpc-urls.js +5 -4
  46. package/dist/cjs/providers/test/test-alchemy-provider.test.js +5 -5
  47. package/dist/cjs/providers/utils/chains-info.d.ts +5 -448
  48. package/dist/cjs/providers/utils/chains-info.js +13 -1344
  49. package/dist/cjs/shared/tiny-big/helpers.js +18 -18
  50. package/dist/cjs/shared/tiny-big/tiny-big.js +96 -56
  51. package/dist/cjs/shared/tiny-big/tiny-big.test.js +2 -2
  52. package/dist/cjs/shared/validate-type.d.ts +1 -1
  53. package/dist/cjs/shared/validate-type.js +4 -4
  54. package/dist/cjs/types/Block.types.d.ts +3 -3
  55. package/dist/cjs/types/Contract.types.d.ts +4 -4
  56. package/dist/cjs/types/Transaction.types.d.ts +5 -5
  57. package/dist/cjs/utils/bytes.d.ts +4 -4
  58. package/dist/cjs/utils/bytes.js +3 -3
  59. package/dist/cjs/utils/tests/bytes/arrayify.test.js +48 -24
  60. package/dist/cjs/utils/tests/bytes/concat.test.js +5 -3
  61. package/dist/cjs/utils/tests/bytes/hex-concat.test.js +15 -13
  62. package/dist/cjs/utils/tests/bytes/hex-data-length.test.js +49 -32
  63. package/dist/cjs/utils/tests/bytes/hex-data-slice.test.js +15 -16
  64. package/dist/cjs/utils/tests/bytes/hex-strip-zeros.test.js +57 -40
  65. package/dist/cjs/utils/tests/bytes/hex-value.test.js +118 -62
  66. package/dist/cjs/utils/tests/bytes/hex-zero-pad.test.js +71 -33
  67. package/dist/cjs/utils/tests/bytes/hexlify.test.js +45 -29
  68. package/dist/cjs/utils/tests/bytes/is-bytes-like.test.js +10 -11
  69. package/dist/cjs/utils/tests/bytes/is-bytes.test.js +70 -27
  70. package/dist/cjs/utils/tests/bytes/is-hex-string.test.js +37 -28
  71. package/dist/cjs/utils/tests/bytes/strip-zeros.test.js +94 -45
  72. package/dist/cjs/utils/tests/bytes/zero-pad.test.js +98 -34
  73. package/dist/cjs/utils/tests/compute-address.test.js +42 -20
  74. package/dist/cjs/utils/tests/compute-public-key.test.js +20 -9
  75. package/dist/cjs/utils/tests/ether-to-wei.test.js +5 -13
  76. package/dist/cjs/utils/tests/hash-message.test.js +26 -15
  77. package/dist/cjs/utils/tests/is-address.test.js +2 -9
  78. package/dist/cjs/utils/tests/keccak256.test.js +36 -12
  79. package/dist/cjs/utils/tests/solidity-keccak256.test.js +43 -42
  80. package/dist/cjs/utils/tests/split-signature.test.js +29 -8
  81. package/dist/cjs/utils/tests/to-checksum-address.test.js +1 -4
  82. package/dist/cjs/utils/tests/to-utf8-bytes.test.js +28 -8
  83. package/dist/cjs/utils/tests/wei-to-ether.test.js +10 -20
  84. package/dist/esm/classes/test/Contract/ens-abi.d.ts +1 -1
  85. package/dist/esm/classes/test/Contract/foo-abi.d.ts +1 -1
  86. package/dist/esm/classes/utils/fetchers.d.ts +8 -2
  87. package/dist/esm/classes/utils/fetchers.js +6 -3
  88. package/dist/esm/index.d.ts +21 -22
  89. package/dist/esm/index.js +16 -17
  90. package/dist/esm/logger/package-version.d.ts +1 -1
  91. package/dist/esm/logger/package-version.js +1 -1
  92. package/dist/esm/providers/FallthroughProvider.js +3 -3
  93. package/dist/esm/providers/test/json-rpc-provider/get-logs/mocks.d.ts +14 -0
  94. package/dist/esm/providers/test/json-rpc-provider/get-logs/mocks.js +142 -0
  95. package/dist/esm/providers/test/rpc-urls.d.ts +1 -0
  96. package/dist/esm/providers/test/rpc-urls.js +7 -4
  97. package/dist/esm/providers/utils/chains-info.d.ts +5 -448
  98. package/dist/esm/providers/utils/chains-info.js +13 -1344
  99. package/dist/esm/shared/validate-type.d.ts +1 -1
  100. package/dist/esm/types/Block.types.d.ts +3 -3
  101. package/dist/esm/types/Contract.types.d.ts +4 -4
  102. package/dist/esm/types/Transaction.types.d.ts +5 -5
  103. package/dist/esm/utils/bytes.d.ts +4 -4
  104. package/package.json +22 -50
  105. package/readme.md +15 -38
  106. package/dist/cjs/providers/test/json-rpc-provider/get-logs.test.js +0 -361
@@ -1,43 +1,60 @@
1
- import { utils as ethers } from "ethers";
2
1
  import { hexDataLength } from "../../bytes";
3
2
  describe("utils.hexDataLength", function() {
4
- it("should match ethers.js - hex values", function() {
5
- var values = [
6
- "0x9347",
7
- "0x185754",
8
- "0x00005823"
3
+ it("should match expected value - hex values", function() {
4
+ var testCases = [
5
+ {
6
+ value: "0x9347",
7
+ expected: 2
8
+ },
9
+ {
10
+ value: "0x185754",
11
+ expected: 3
12
+ },
13
+ {
14
+ value: "0x00005823",
15
+ expected: 4
16
+ }
9
17
  ];
10
- values.forEach(function(value) {
11
- expect(hexDataLength(value)).toBe(ethers.hexDataLength(value));
18
+ testCases.forEach(function(testCase) {
19
+ expect(hexDataLength(testCase.value)).toStrictEqual(testCase.expected);
12
20
  });
13
21
  });
14
- it("should match ethers.js - UInt8Array values", function() {
15
- var values = [
16
- [
17
- 9,
18
- 58,
19
- 29,
20
- 24
21
- ],
22
- [
23
- 185,
24
- 203
25
- ],
26
- [
27
- 239,
28
- 30,
29
- 49,
30
- 41,
31
- 5,
32
- 10,
33
- 42
34
- ]
22
+ it("should match expected value - UInt8Array values", function() {
23
+ var testCases = [
24
+ {
25
+ value: new Uint8Array([
26
+ 9,
27
+ 58,
28
+ 29,
29
+ 24
30
+ ]),
31
+ expected: 4
32
+ },
33
+ {
34
+ value: new Uint8Array([
35
+ 185,
36
+ 203
37
+ ]),
38
+ expected: 2
39
+ },
40
+ {
41
+ value: new Uint8Array([
42
+ 239,
43
+ 30,
44
+ 49,
45
+ 41,
46
+ 5,
47
+ 10,
48
+ 42
49
+ ]),
50
+ expected: 7
51
+ }
35
52
  ];
36
- values.forEach(function(value) {
37
- expect(hexDataLength(value)).toBe(ethers.hexDataLength(value));
53
+ testCases.forEach(function(testCase) {
54
+ expect(hexDataLength(testCase.value)).toStrictEqual(testCase.expected);
38
55
  });
39
56
  });
40
- it("should return null - not hex value or not divisible by 2", function() {
57
+ it("should return null - non-hex values or hex values not divisible by 2", function() {
41
58
  var values = [
42
59
  "0x383",
43
60
  "non-hex string"
@@ -1,26 +1,25 @@
1
- import { utils as ethers } from "ethers";
2
1
  import { hexDataSlice } from "../../bytes";
3
2
  describe("utils.hexDataSlice", function() {
4
- it("numbers - matches ethers strings", function() {
5
- var decimalValues = [
3
+ it("should match expected slice - hexadecimal strings", function() {
4
+ var hexValues = [
6
5
  "0x123456"
7
6
  ];
8
- decimalValues.forEach(function(decimalValue) {
9
- expect(hexDataSlice(decimalValue, 0, 2)).toStrictEqual(ethers.hexDataSlice(decimalValue, 0, 2));
7
+ hexValues.forEach(function(hexValue) {
8
+ expect(hexDataSlice(hexValue, 0, 2)).toBe("0x1234");
10
9
  });
11
10
  });
12
- it("numbers - matches ethers hex numbers", function() {
13
- var decimalValues = [
11
+ it("should match expected slice - hexadecimal numbers", function() {
12
+ var hexValues = [
14
13
  0x1234567891011
15
14
  ];
16
- decimalValues.forEach(function(decimalValue) {
17
- expect(hexDataSlice(decimalValue, 3)).toStrictEqual(ethers.hexDataSlice(decimalValue, 3));
18
- expect(hexDataSlice(decimalValue, 2, 4)).toStrictEqual(ethers.hexDataSlice(decimalValue, 2, 4));
19
- expect(hexDataSlice(decimalValue, 100)).toStrictEqual(ethers.hexDataSlice(decimalValue, 100));
15
+ hexValues.forEach(function(hexValue) {
16
+ expect(hexDataSlice(hexValue, 3)).toBe("0x67891011");
17
+ expect(hexDataSlice(hexValue, 2, 4)).toBe("0x4567");
18
+ expect(hexDataSlice(hexValue, 100)).toBe("0x");
20
19
  });
21
20
  });
22
- it("numbers - matches ethers decimals", function() {
23
- var decimalValues = [
21
+ it("should match expected slice - arrays of decimal numbers", function() {
22
+ var decimalArrays = [
24
23
  [
25
24
  0,
26
25
  1,
@@ -34,11 +33,11 @@ describe("utils.hexDataSlice", function() {
34
33
  9
35
34
  ]
36
35
  ];
37
- decimalValues.forEach(function(decimalValue) {
38
- expect(hexDataSlice(decimalValue, 1, 2)).toStrictEqual(ethers.hexDataSlice(decimalValue, 1, 2));
36
+ decimalArrays.forEach(function(decimalArray) {
37
+ expect(hexDataSlice(decimalArray, 1, 2)).toBe("0x01");
39
38
  });
40
39
  });
41
- it("should throw error - invalid hexData", function() {
40
+ it("should throw error - invalid hex data", function() {
42
41
  var values = [
43
42
  "non-hex string",
44
43
  "0x938"
@@ -1,51 +1,68 @@
1
- import { utils as ethers } from "ethers";
2
1
  import { hexStripZeros } from "../../bytes";
3
2
  describe("utils.hexStripZeros", function() {
4
- it("should match ethers.js - hex values", function() {
5
- var values = [
6
- "0x00009347",
7
- "0x00185754",
8
- "0x00000000005823"
3
+ it("should correctly strip leading zeros - hex strings", function() {
4
+ var testCases = [
5
+ {
6
+ value: "0x00009347",
7
+ expected: "0x9347"
8
+ },
9
+ {
10
+ value: "0x00185754",
11
+ expected: "0x185754"
12
+ },
13
+ {
14
+ value: "0x00000000005823",
15
+ expected: "0x5823"
16
+ }
9
17
  ];
10
- values.forEach(function(value) {
11
- expect(hexStripZeros(value)).toBe(ethers.hexStripZeros(value));
18
+ testCases.forEach(function(testCase) {
19
+ expect(hexStripZeros(testCase.value)).toBe(testCase.expected);
12
20
  });
13
21
  });
14
- it("should match ethers.js - UInt8Array values", function() {
15
- var values = [
16
- [
17
- 0,
18
- 0,
19
- 0,
20
- 9,
21
- 58,
22
- 29,
23
- 24
24
- ],
25
- [
26
- 0,
27
- 185,
28
- 203
29
- ],
30
- [
31
- 0,
32
- 0,
33
- 0,
34
- 0,
35
- 239,
36
- 30,
37
- 49,
38
- 41,
39
- 5,
40
- 10,
41
- 42
42
- ]
22
+ it("should correctly strip leading zeros - byte arrays", function() {
23
+ var testCases = [
24
+ {
25
+ value: new Uint8Array([
26
+ 0,
27
+ 0,
28
+ 0,
29
+ 9,
30
+ 58,
31
+ 29,
32
+ 24
33
+ ]),
34
+ expected: "0x93a1d18"
35
+ },
36
+ {
37
+ value: new Uint8Array([
38
+ 0,
39
+ 185,
40
+ 203
41
+ ]),
42
+ expected: "0xb9cb"
43
+ },
44
+ {
45
+ value: new Uint8Array([
46
+ 0,
47
+ 0,
48
+ 0,
49
+ 0,
50
+ 239,
51
+ 30,
52
+ 49,
53
+ 41,
54
+ 5,
55
+ 10,
56
+ 42
57
+ ]),
58
+ expected: "0xef1e3129050a2a"
59
+ }
43
60
  ];
44
- values.forEach(function(value) {
45
- expect(hexStripZeros(value)).toBe(ethers.hexStripZeros(value));
61
+ testCases.forEach(function(testCase) {
62
+ expect(hexStripZeros(testCase.value)).toBe(testCase.expected);
46
63
  });
47
64
  });
48
- it("should throw error - invalid hex string", function() {
65
+ it("should throw error - invalid hex strings", function() {
49
66
  var values = [
50
67
  "non-hex string"
51
68
  ];
@@ -1,85 +1,141 @@
1
- import { utils as ethers } from "ethers";
2
1
  import { hexValue } from "../../bytes";
3
2
  import { tinyBig } from "./../../../shared/tiny-big/tiny-big";
4
3
  describe("utils.hexValue", function() {
5
- it("should match ethers.js - hex string", function() {
6
- var values = [
7
- "0x9347",
8
- "0x185754",
9
- "0x00005823"
4
+ it("should correctly convert - hex string", function() {
5
+ var testCases = [
6
+ {
7
+ value: "0x9347",
8
+ expected: "0x9347"
9
+ },
10
+ {
11
+ value: "0x185754",
12
+ expected: "0x185754"
13
+ },
14
+ {
15
+ value: "0x00005823",
16
+ expected: "0x5823"
17
+ }
10
18
  ];
11
- values.forEach(function(value) {
12
- expect(hexValue(value)).toBe(ethers.hexValue(value));
19
+ testCases.forEach(function(testCase) {
20
+ expect(hexValue(testCase.value)).toStrictEqual(testCase.expected);
13
21
  });
14
22
  });
15
- it("should match ethers.js - UInt8Array", function() {
16
- var values = [
17
- [
18
- 4,
19
- 50,
20
- 2
21
- ],
22
- [
23
- 231,
24
- 49,
25
- 40,
26
- 70,
27
- 19
28
- ],
29
- [
30
- 10,
31
- 68,
32
- 20,
33
- 98
34
- ]
23
+ it("should correctly convert - byte array", function() {
24
+ var testCases = [
25
+ {
26
+ value: [
27
+ 4,
28
+ 50,
29
+ 2
30
+ ],
31
+ expected: "0x43202"
32
+ },
33
+ {
34
+ value: [
35
+ 231,
36
+ 49,
37
+ 40,
38
+ 70,
39
+ 19
40
+ ],
41
+ expected: "0xe731284613"
42
+ },
43
+ {
44
+ value: [
45
+ 10,
46
+ 68,
47
+ 20,
48
+ 98
49
+ ],
50
+ expected: "0xa441462"
51
+ }
35
52
  ];
36
- values.forEach(function(value) {
37
- expect(hexValue(value)).toBe(ethers.hexValue(value));
53
+ testCases.forEach(function(testCase) {
54
+ expect(hexValue(testCase.value)).toStrictEqual(testCase.expected);
38
55
  });
39
56
  });
40
- it("should match ethers.js - TinyBig (hexable)", function() {
41
- var values = [
42
- tinyBig("29389"),
43
- tinyBig(2834),
44
- tinyBig(402)
57
+ it("should correctly convert - TinyBig instance", function() {
58
+ var testCases = [
59
+ {
60
+ value: tinyBig("29389"),
61
+ expected: "0x72cd"
62
+ },
63
+ {
64
+ value: tinyBig(2834),
65
+ expected: "0xb12"
66
+ },
67
+ {
68
+ value: tinyBig(402),
69
+ expected: "0x192"
70
+ }
45
71
  ];
46
- values.forEach(function(value) {
47
- expect(hexValue(value)).toBe(ethers.hexValue(value));
72
+ testCases.forEach(function(testCase) {
73
+ expect(hexValue(testCase.value)).toStrictEqual(testCase.expected);
48
74
  });
49
75
  });
50
- it("should match ethers.js - number", function() {
51
- var values = [
52
- 624,
53
- 457,
54
- 23451
76
+ it("should correctly convert - number", function() {
77
+ var testCases = [
78
+ {
79
+ value: 624,
80
+ expected: "0x270"
81
+ },
82
+ {
83
+ value: 457,
84
+ expected: "0x1c9"
85
+ },
86
+ {
87
+ value: 23451,
88
+ expected: "0x5b9b"
89
+ }
55
90
  ];
56
- values.forEach(function(value) {
57
- expect(hexValue(value)).toBe(ethers.hexValue(value));
91
+ testCases.forEach(function(testCase) {
92
+ expect(hexValue(testCase.value)).toStrictEqual(testCase.expected);
58
93
  });
59
94
  });
60
- it("should match ethers.js - BigInt", function() {
61
- var values = [
62
- BigInt(204),
63
- BigInt("23491"),
64
- BigInt(4183459235723491)
95
+ it("should correctly convert - BigInt", function() {
96
+ var testCases = [
97
+ {
98
+ value: BigInt(204),
99
+ expected: "0xcc"
100
+ },
101
+ {
102
+ value: BigInt("23491"),
103
+ expected: "0x5bc3"
104
+ },
105
+ {
106
+ value: BigInt(4183459235723491),
107
+ expected: "0xedcd581ad78e3"
108
+ }
65
109
  ];
66
- values.forEach(function(value) {
67
- expect(hexValue(value)).toBe(ethers.hexValue(value));
110
+ testCases.forEach(function(testCase) {
111
+ expect(hexValue(testCase.value)).toStrictEqual(testCase.expected);
68
112
  });
69
113
  });
70
114
  it("should return 0x0 - only zero data given", function() {
71
- var values = [
72
- BigInt(0),
73
- 0,
74
- "0x0000",
75
- [
76
- 0,
77
- 0,
78
- 0
79
- ]
115
+ var testCases = [
116
+ {
117
+ value: BigInt(0),
118
+ expected: "0x0"
119
+ },
120
+ {
121
+ value: 0,
122
+ expected: "0x0"
123
+ },
124
+ {
125
+ value: "0x0000",
126
+ expected: "0x0"
127
+ },
128
+ {
129
+ value: [
130
+ 0,
131
+ 0,
132
+ 0
133
+ ],
134
+ expected: "0x0"
135
+ }
80
136
  ];
81
- values.forEach(function(value) {
82
- expect(hexValue(value)).toBe("0x0");
137
+ testCases.forEach(function(testCase) {
138
+ expect(hexValue(testCase.value)).toStrictEqual(testCase.expected);
83
139
  });
84
140
  });
85
141
  });
@@ -1,35 +1,43 @@
1
- import * as ethers from "ethers";
2
1
  import { hexZeroPad } from "../../../";
3
2
  describe("hexZeroPad", function() {
4
- it("numbers - matches ethers", function() {
5
- var decimalValues = [
6
- 123,
7
- 0
3
+ it("should correctly pad - numbers", function() {
4
+ var testCases = [
5
+ {
6
+ value: 123,
7
+ expected: "0x000000000000000000000000000000000000007b"
8
+ },
9
+ {
10
+ value: 0,
11
+ expected: "0x0000000000000000000000000000000000000000"
12
+ }
8
13
  ];
9
- decimalValues.forEach(function(decimalValue) {
10
- expect(hexZeroPad(decimalValue, 30)).toStrictEqual(ethers.utils.hexZeroPad(decimalValue, 30));
14
+ testCases.forEach(function(testCase) {
15
+ expect(hexZeroPad(testCase.value, 20)).toStrictEqual(testCase.expected);
11
16
  });
12
17
  });
13
- it("arrays of numbers - matches ethers", function() {
14
- var decimalValues = [
15
- [
16
- 1,
17
- 2,
18
- 3,
19
- 4
20
- ]
18
+ it("should correctly pad - arrays of numbers", function() {
19
+ var testCases = [
20
+ {
21
+ value: [
22
+ 1,
23
+ 2,
24
+ 3,
25
+ 4
26
+ ],
27
+ expected: "0x000000000000000000000001020304"
28
+ }
21
29
  ];
22
- decimalValues.forEach(function(decimalValue) {
23
- expect(hexZeroPad(decimalValue, 30)).toStrictEqual(ethers.utils.hexZeroPad(decimalValue, 30));
30
+ testCases.forEach(function(testCase) {
31
+ expect(hexZeroPad(testCase.value, 15)).toStrictEqual(testCase.expected);
24
32
  });
25
33
  });
26
- it("should reject strings passed in which are not hex strings", function() {
34
+ it("should throw error - non-hex string", function() {
27
35
  var value = "52908";
28
36
  expect(function() {
29
37
  hexZeroPad(value, 23);
30
38
  }).toThrow();
31
39
  });
32
- it("should throw error when value is already longer than desired length", function() {
40
+ it("should throw error - values longer than desired length", function() {
33
41
  var hexValues = [
34
42
  0x123456,
35
43
  "0x5aAebAd",
@@ -42,21 +50,51 @@ describe("hexZeroPad", function() {
42
50
  }).toThrow();
43
51
  });
44
52
  });
45
- it("should match ethers.js when padding can be applied", function() {
46
- var values = [
47
- 10,
48
- "0x5290",
49
- "0x8617E3",
50
- "0xde709f210",
51
- "0x27b",
52
- 0x0,
53
- 0x5aaeb605,
54
- "0xfB6916095ca1df",
55
- "0xdbF03B407c01E7cD3CBea99509d93",
56
- 0xd1220a0cf4
53
+ it("should correctly pad - valid hex values", function() {
54
+ var testCases = [
55
+ {
56
+ value: 10,
57
+ expected: "0x00000000000000000000000000000a"
58
+ },
59
+ {
60
+ value: "0x5290",
61
+ expected: "0x000000000000000000000000005290"
62
+ },
63
+ {
64
+ value: "0x8617E3",
65
+ expected: "0x0000000000000000000000008617E3"
66
+ },
67
+ {
68
+ value: "0xde709f210",
69
+ expected: "0x000000000000000000000de709f210"
70
+ },
71
+ {
72
+ value: "0x27b",
73
+ expected: "0x00000000000000000000000000027b"
74
+ },
75
+ {
76
+ value: 0x0,
77
+ expected: "0x000000000000000000000000000000"
78
+ },
79
+ {
80
+ value: 0x5aaeb605,
81
+ expected: "0x00000000000000000000005aaeb605"
82
+ },
83
+ {
84
+ value: "0xfB6916095ca1df",
85
+ expected: "0x0000000000000000fB6916095ca1df"
86
+ },
87
+ {
88
+ value: "0xdbF03B407c01E7cD3CBea99509d93",
89
+ expected: "0x0dbF03B407c01E7cD3CBea99509d93"
90
+ },
91
+ {
92
+ value: 0xd1220a0cf4,
93
+ expected: "0x00000000000000000000d1220a0cf4"
94
+ }
57
95
  ];
58
- values.forEach(function(value) {
59
- expect(hexZeroPad(value, 30)).toStrictEqual(ethers.utils.hexZeroPad(value, 30));
96
+ testCases.forEach(function(testCase) {
97
+ expect(hexZeroPad(testCase.value, 15)).toStrictEqual(testCase.expected);
60
98
  });
61
99
  });
62
100
  });