essential-eth 0.9.1-next.0 → 0.9.1-next.1

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 (104) hide show
  1. package/dist/cjs/classes/Contract.js +66 -311
  2. package/dist/cjs/classes/test/Contract/crv-abi.js +256 -252
  3. package/dist/cjs/classes/test/Contract/ens-abi.js +212 -497
  4. package/dist/cjs/classes/test/Contract/fei-abi.js +284 -605
  5. package/dist/cjs/classes/test/Contract/foo-abi.js +21 -44
  6. package/dist/cjs/classes/test/Contract/uniswap-abi.js +68 -64
  7. package/dist/cjs/classes/utils/clean-block.js +30 -52
  8. package/dist/cjs/classes/utils/clean-log.js +20 -42
  9. package/dist/cjs/classes/utils/clean-transaction-receipt.js +30 -51
  10. package/dist/cjs/classes/utils/clean-transaction.js +30 -52
  11. package/dist/cjs/classes/utils/encode-decode-transaction.js +107 -148
  12. package/dist/cjs/classes/utils/fetchers.js +44 -166
  13. package/dist/cjs/classes/utils/hex-to-decimal.js +6 -1
  14. package/dist/cjs/classes/utils/prepare-transaction.js +36 -59
  15. package/dist/cjs/index.js +56 -25
  16. package/dist/cjs/index.umd.js +1 -1
  17. package/dist/cjs/index.umd.js.map +1 -1
  18. package/dist/cjs/logger/logger.js +29 -123
  19. package/dist/cjs/logger/package-version.d.ts +1 -1
  20. package/dist/cjs/logger/package-version.js +4 -1
  21. package/dist/cjs/providers/AlchemyProvider.js +9 -82
  22. package/dist/cjs/providers/BaseProvider.js +520 -958
  23. package/dist/cjs/providers/FallthroughProvider.js +47 -156
  24. package/dist/cjs/providers/JsonRpcProvider.js +28 -114
  25. package/dist/cjs/providers/test/json-rpc-provider/get-logs/mocks.js +104 -101
  26. package/dist/cjs/providers/test/mock-of.js +6 -3
  27. package/dist/cjs/providers/test/rpc-urls.js +23 -15
  28. package/dist/cjs/providers/utils/chains-info.js +3 -1
  29. package/dist/cjs/shared/tiny-big/helpers.js +42 -93
  30. package/dist/cjs/shared/tiny-big/tiny-big.js +81 -210
  31. package/dist/cjs/shared/validate-type.js +7 -7
  32. package/dist/cjs/types/Block.types.js +2 -1
  33. package/dist/cjs/types/Contract.types.js +2 -1
  34. package/dist/cjs/types/FeeData.types.js +2 -1
  35. package/dist/cjs/types/Filter.types.js +2 -1
  36. package/dist/cjs/types/Network.types.js +2 -3
  37. package/dist/cjs/types/Transaction.types.js +2 -1
  38. package/dist/cjs/utils/bytes.js +318 -286
  39. package/dist/cjs/utils/compute-address.js +15 -8
  40. package/dist/cjs/utils/compute-public-key.js +10 -5
  41. package/dist/cjs/utils/ether-to-gwei.js +11 -10
  42. package/dist/cjs/utils/ether-to-wei.js +11 -10
  43. package/dist/cjs/utils/gwei-to-ether.js +11 -10
  44. package/dist/cjs/utils/hash-message.js +16 -11
  45. package/dist/cjs/utils/is-address.js +12 -8
  46. package/dist/cjs/utils/keccak256.js +14 -8
  47. package/dist/cjs/utils/solidity-keccak256.js +60 -49
  48. package/dist/cjs/utils/split-signature.js +73 -55
  49. package/dist/cjs/utils/to-checksum-address.js +20 -15
  50. package/dist/cjs/utils/to-utf8-bytes.js +6 -1
  51. package/dist/cjs/utils/wei-to-ether.js +15 -13
  52. package/dist/esm/logger/package-version.d.ts +1 -1
  53. package/dist/esm/logger/package-version.js +1 -1
  54. package/package.json +2 -2
  55. package/readme.md +1 -1
  56. package/dist/cjs/classes/test/Contract/crv.test.js +0 -497
  57. package/dist/cjs/classes/test/Contract/ens.test.js +0 -160
  58. package/dist/cjs/classes/test/Contract/fei.test.js +0 -224
  59. package/dist/cjs/classes/test/Contract/foo.test.js +0 -33
  60. package/dist/cjs/classes/test/Contract/uni.test.js +0 -289
  61. package/dist/cjs/providers/test/fallthrough-provider/get-gas-price.test.js +0 -228
  62. package/dist/cjs/providers/test/get-transaction-count.test.js +0 -239
  63. package/dist/cjs/providers/test/json-rpc-provider/call.test.js +0 -375
  64. package/dist/cjs/providers/test/json-rpc-provider/estimate-gas.test.js +0 -217
  65. package/dist/cjs/providers/test/json-rpc-provider/get-balance.test.js +0 -223
  66. package/dist/cjs/providers/test/json-rpc-provider/get-block-number.test.js +0 -163
  67. package/dist/cjs/providers/test/json-rpc-provider/get-block.test.js +0 -414
  68. package/dist/cjs/providers/test/json-rpc-provider/get-code.test.js +0 -282
  69. package/dist/cjs/providers/test/json-rpc-provider/get-fee-data.test.js +0 -187
  70. package/dist/cjs/providers/test/json-rpc-provider/get-gas-price.test.js +0 -167
  71. package/dist/cjs/providers/test/json-rpc-provider/get-logs/get-logs.test.js +0 -219
  72. package/dist/cjs/providers/test/json-rpc-provider/get-network.test.js +0 -232
  73. package/dist/cjs/providers/test/json-rpc-provider/get-transaction-receipt.test.js +0 -280
  74. package/dist/cjs/providers/test/json-rpc-provider/get-transaction.test.js +0 -266
  75. package/dist/cjs/providers/test/test-alchemy-provider.test.js +0 -151
  76. package/dist/cjs/shared/tiny-big/helpers.test.js +0 -29
  77. package/dist/cjs/shared/tiny-big/tiny-big.test.js +0 -34
  78. package/dist/cjs/utils/tests/bytes/arrayify.test.js +0 -64
  79. package/dist/cjs/utils/tests/bytes/concat.test.js +0 -17
  80. package/dist/cjs/utils/tests/bytes/hex-concat.test.js +0 -65
  81. package/dist/cjs/utils/tests/bytes/hex-data-length.test.js +0 -66
  82. package/dist/cjs/utils/tests/bytes/hex-data-slice.test.js +0 -51
  83. package/dist/cjs/utils/tests/bytes/hex-strip-zeros.test.js +0 -75
  84. package/dist/cjs/utils/tests/bytes/hex-value.test.js +0 -141
  85. package/dist/cjs/utils/tests/bytes/hex-zero-pad.test.js +0 -100
  86. package/dist/cjs/utils/tests/bytes/hexlify.test.js +0 -78
  87. package/dist/cjs/utils/tests/bytes/is-bytes-like.test.js +0 -68
  88. package/dist/cjs/utils/tests/bytes/is-bytes.test.js +0 -76
  89. package/dist/cjs/utils/tests/bytes/is-hex-string.test.js +0 -97
  90. package/dist/cjs/utils/tests/bytes/strip-zeros.test.js +0 -106
  91. package/dist/cjs/utils/tests/bytes/zero-pad.test.js +0 -144
  92. package/dist/cjs/utils/tests/compute-address.test.js +0 -49
  93. package/dist/cjs/utils/tests/compute-public-key.test.js +0 -26
  94. package/dist/cjs/utils/tests/ether-to-gwei.test.js +0 -26
  95. package/dist/cjs/utils/tests/ether-to-wei.test.js +0 -36
  96. package/dist/cjs/utils/tests/gwei-to-ether.test.js +0 -28
  97. package/dist/cjs/utils/tests/hash-message.test.js +0 -32
  98. package/dist/cjs/utils/tests/is-address.test.js +0 -48
  99. package/dist/cjs/utils/tests/keccak256.test.js +0 -121
  100. package/dist/cjs/utils/tests/solidity-keccak256.test.js +0 -311
  101. package/dist/cjs/utils/tests/split-signature.test.js +0 -46
  102. package/dist/cjs/utils/tests/to-checksum-address.test.js +0 -39
  103. package/dist/cjs/utils/tests/to-utf8-bytes.test.js +0 -34
  104. package/dist/cjs/utils/tests/wei-to-ether.test.js +0 -41
@@ -1,106 +0,0 @@
1
- import { stripZeros } from "../../bytes";
2
- describe("utils.stripZeros", function() {
3
- it("should match expected result - hex string", function() {
4
- var testCases = [
5
- {
6
- value: "0x00009347",
7
- expected: new Uint8Array([
8
- 147,
9
- 71
10
- ])
11
- },
12
- {
13
- value: "0x00185754",
14
- expected: new Uint8Array([
15
- 24,
16
- 87,
17
- 84
18
- ])
19
- },
20
- {
21
- value: "0x00000000005823",
22
- expected: new Uint8Array([
23
- 88,
24
- 35
25
- ])
26
- }
27
- ];
28
- testCases.forEach(function(testCase) {
29
- expect(stripZeros(testCase.value)).toStrictEqual(testCase.expected);
30
- });
31
- });
32
- it("should match expected result - UInt8Array", function() {
33
- var testCases = [
34
- {
35
- value: [
36
- 0,
37
- 0,
38
- 0,
39
- 9,
40
- 58,
41
- 29,
42
- 24
43
- ],
44
- expected: new Uint8Array([
45
- 9,
46
- 58,
47
- 29,
48
- 24
49
- ])
50
- },
51
- {
52
- value: [
53
- 0,
54
- 185,
55
- 203
56
- ],
57
- expected: new Uint8Array([
58
- 185,
59
- 203
60
- ])
61
- },
62
- {
63
- value: [
64
- 0,
65
- 0,
66
- 0,
67
- 0,
68
- 239,
69
- 30,
70
- 49,
71
- 41,
72
- 5,
73
- 10,
74
- 42
75
- ],
76
- expected: new Uint8Array([
77
- 239,
78
- 30,
79
- 49,
80
- 41,
81
- 5,
82
- 10,
83
- 42
84
- ])
85
- }
86
- ];
87
- testCases.forEach(function(testCase) {
88
- expect(stripZeros(testCase.value)).toStrictEqual(testCase.expected);
89
- });
90
- });
91
- it("should match expected result - empty array", function() {
92
- var testCases = [
93
- {
94
- value: [],
95
- expected: new Uint8Array([])
96
- },
97
- {
98
- value: "0x",
99
- expected: new Uint8Array([])
100
- }
101
- ];
102
- testCases.forEach(function(testCase) {
103
- expect(stripZeros(testCase.value)).toStrictEqual(testCase.expected);
104
- });
105
- });
106
- });
@@ -1,144 +0,0 @@
1
- import { zeroPad } from "../../bytes";
2
- describe("utils.zeroPad", function() {
3
- it("should match expected result - hex string", function() {
4
- var testCases = [
5
- {
6
- value: [
7
- "0x9347",
8
- 10
9
- ],
10
- expected: new Uint8Array([
11
- 0,
12
- 0,
13
- 0,
14
- 0,
15
- 0,
16
- 0,
17
- 0,
18
- 0,
19
- 147,
20
- 71
21
- ])
22
- },
23
- {
24
- value: [
25
- "0x185754",
26
- 5
27
- ],
28
- expected: new Uint8Array([
29
- 0,
30
- 0,
31
- 24,
32
- 87,
33
- 84
34
- ])
35
- },
36
- {
37
- value: [
38
- "0x00005823",
39
- 7
40
- ],
41
- expected: new Uint8Array([
42
- 0,
43
- 0,
44
- 0,
45
- 0,
46
- 0,
47
- 88,
48
- 35
49
- ])
50
- }
51
- ];
52
- testCases.forEach(function(testCase) {
53
- expect(zeroPad(testCase.value[0], testCase.value[1])).toStrictEqual(testCase.expected);
54
- });
55
- });
56
- it("should match expected result - UInt8Array", function() {
57
- var testCases = [
58
- {
59
- value: [
60
- [
61
- 9,
62
- 58,
63
- 29,
64
- 24
65
- ],
66
- 5
67
- ],
68
- expected: new Uint8Array([
69
- 0,
70
- 9,
71
- 58,
72
- 29,
73
- 24
74
- ])
75
- },
76
- {
77
- value: [
78
- [
79
- 185,
80
- 203
81
- ],
82
- 4
83
- ],
84
- expected: new Uint8Array([
85
- 0,
86
- 0,
87
- 185,
88
- 203
89
- ])
90
- },
91
- {
92
- value: [
93
- [
94
- 239,
95
- 30,
96
- 49,
97
- 41,
98
- 5,
99
- 10,
100
- 42
101
- ],
102
- 10
103
- ],
104
- expected: new Uint8Array([
105
- 0,
106
- 0,
107
- 0,
108
- 239,
109
- 30,
110
- 49,
111
- 41,
112
- 5,
113
- 10,
114
- 42
115
- ])
116
- }
117
- ];
118
- testCases.forEach(function(testCase) {
119
- expect(zeroPad(testCase.value[0], testCase.value[1])).toStrictEqual(testCase.expected);
120
- });
121
- });
122
- it("should throw error - value out of range", function() {
123
- var values = [
124
- [
125
- [
126
- 9,
127
- 58,
128
- 29,
129
- 24
130
- ],
131
- 3
132
- ],
133
- [
134
- "0x185754",
135
- 1
136
- ]
137
- ];
138
- values.forEach(function(value) {
139
- expect(function() {
140
- return zeroPad(value[0], value[1]);
141
- }).toThrow("value out of range");
142
- });
143
- });
144
- });
@@ -1,49 +0,0 @@
1
- import { computeAddress } from "../../index";
2
- describe("computeAddress", function() {
3
- it("should compute correct address - public key", function() {
4
- var testCases = [
5
- {
6
- key: "0x04aaa2abcf8d119ad68b2c190abf34355a0029197911e2446007d5b44e6fddfd54352326fedac51eca491d59937c592ecffff65c6941037babbe26edfdbb32a688",
7
- expected: "0xeC46DEeFE5e342801A5ab221471B0f934bd04404"
8
- },
9
- {
10
- key: "0x04e8aa3d196e3a785fb5b431265074c01f571a79231e0cc0fc28e67d9c648471aca8229cafcc6cd806cd1a679f538326577bf9485c68f7a1c90b5116b669f30473",
11
- expected: "0xb17351DB661e7D40723B1ADA46B43586F2358b7A"
12
- },
13
- {
14
- key: "0x04110dfa471c3f04a6c9dfd857705eb080542c9672cf0f30d95f5fca382181293d6e91320916dd649d03c76818af8e7ee173781888e42e2f00bda9a8f797e0fd61",
15
- expected: "0x93a76f1B186A97A3EBd0E1f94Ec52a82FfFD646B"
16
- },
17
- {
18
- key: "0x04593bea29e692123fda1b6f8280b8414524c7838fd448abe6dd1e072bee5e2e9c66e19976b9310ce514d8612c5736201ddc3bb966412076cd4b24e7f649e779b3",
19
- expected: "0x9eb71738aaf20F659156535b13df2b809FC8aB26"
20
- }
21
- ];
22
- testCases.forEach(function(testCase) {
23
- expect(computeAddress(testCase.key)).toBe(testCase.expected);
24
- });
25
- });
26
- it("should compute correct address - private key", function() {
27
- var testCases = [
28
- {
29
- key: "0x8da4ef21b864d2cc526dbdb2a120bd2874c36c9d0a1fb7f8c63d7f7a8b41de8f",
30
- expected: "0x63FaC9201494f0bd17B9892B9fae4d52fe3BD377"
31
- },
32
- {
33
- key: "0x42e12f76412f53de9d60df199a368699b6ec15d3798efb0b2a45b8c1b4f902a6",
34
- expected: "0xE21C7F8e28058931C5aa0e36C42d0C40Daf7A698"
35
- },
36
- {
37
- key: "0x262f8fffb353d3e11be770dd4208dcab1fa5c205d574a78088829f45b1ac2487",
38
- expected: "0xE17826AC425D19b0531F4B99a243b9Cfb42219dd"
39
- },
40
- {
41
- key: "0x1bcfb8b7a46e2f886ef61f8010426f70ce3c7fc1362973aa26d30b8f77711d93",
42
- expected: "0xb17351DB661e7D40723B1ADA46B43586F2358b7A"
43
- }
44
- ];
45
- testCases.forEach(function(testCase) {
46
- expect(computeAddress(testCase.key)).toBe(testCase.expected);
47
- });
48
- });
49
- });
@@ -1,26 +0,0 @@
1
- import { computePublicKey } from "../../index";
2
- describe("computePublicKey", function() {
3
- it("should compute correct public key", function() {
4
- var testCases = [
5
- {
6
- privateKey: "0x8da4ef21b864d2cc526dbdb2a120bd2874c36c9d0a1fb7f8c63d7f7a8b41de8f",
7
- expectedPublicKey: "0x04d11e94912283d217fd98be5ad59c659aede69bbef0e72a2213edf0fbd8de3cc95030d006b137e22b89e738e5565766b83d12c438fe970e3e729532fcfafad2a7"
8
- },
9
- {
10
- privateKey: "0x38a3159d73cefd392d0176c29b3cc60ff43e81813f5ab5782571511df9bb16e2",
11
- expectedPublicKey: "0x04d8c5ec2308fdec8535411b8f7eb0251b53f53bcdda3f49bc7959a5dc1e12d2fe721bdd212b20fdbfa770c56af2da1bcf3b77dd46d742b65154c80aac7d44adf1"
12
- },
13
- {
14
- privateKey: "0xb6d36857e1f9b68e413d2496bb588f3650cdcc2398b3941963c44db8108b8671",
15
- expectedPublicKey: "0x04dab3b4d14577ec72a25c5b4dc7b404052263ccde860bff23b8e68efa215de0f119ed4540cd230d5c84d8a13a8c2105aefba78f342a423893489ae69c3c8a8cfb"
16
- },
17
- {
18
- privateKey: "0xf237d9763445d41150f9a199ad93ad478dff29ad8fe6fa00149ed12f40f8eb6f",
19
- expectedPublicKey: "0x042b9627d5b5e187bcc9e4155c65f986091f76e379a9fe031a7f9797ec74ad70d399e3655e20d3c6b6ca63ef691fe558c1794d78199b697f28697cf44e150dcfb1"
20
- }
21
- ];
22
- testCases.forEach(function(testCase) {
23
- expect(computePublicKey(testCase.privateKey)).toBe(testCase.expectedPublicKey);
24
- });
25
- });
26
- });
@@ -1,26 +0,0 @@
1
- import Big from "big.js";
2
- import { etherToGwei, tinyBig } from "../../index";
3
- describe("gweiToEther", function() {
4
- it("happy path", function() {
5
- expect(etherToGwei("100.0").toString()).toBe("100000000000");
6
- expect(etherToGwei(100.0).toString()).toBe("100000000000");
7
- expect(etherToGwei("0.000000001").toNumber()).toBe(1);
8
- expect(etherToGwei(0.000000001).toNumber()).toBe(1);
9
- expect(etherToGwei(tinyBig(1000)).toNumber()).toBe(1000000000000);
10
- expect(etherToGwei(Big(0.000000001)).toNumber()).toBe(1);
11
- });
12
- it("wrong types", function() {
13
- expect(function() {
14
- // @ts-expect-error should not accept boolean
15
- etherToGwei(false);
16
- }).toThrow();
17
- expect(function() {
18
- // @ts-expect-error should not accept array
19
- etherToGwei([
20
- 1,
21
- 2,
22
- 3
23
- ]);
24
- }).toThrow();
25
- });
26
- });
@@ -1,36 +0,0 @@
1
- import Big from "big.js";
2
- import { etherToWei, tinyBig } from "../../index";
3
- describe("ether-to-wei", function() {
4
- it("happy path", function() {
5
- expect(etherToWei("100").toString()).toBe("100000000000000000000");
6
- expect(etherToWei(100).toString()).toBe("100000000000000000000");
7
- expect(etherToWei("1000.0").toString()).toBe("1000000000000000000000");
8
- expect(etherToWei(1000).toString()).toBe("1000000000000000000000");
9
- expect(etherToWei("1000.0").toNumber()).toBe(1000000000000000000000);
10
- expect(etherToWei(tinyBig(1000)).toString()).toBe("1000000000000000000000");
11
- expect(etherToWei(tinyBig("1000.0")).toNumber()).toBe(1000000000000000000000);
12
- expect(etherToWei(Big(1000)).toString()).toBe("1000000000000000000000");
13
- expect(etherToWei(Big("1000.0")).toNumber()).toBe(1000000000000000000000);
14
- });
15
- it("matches expected toString", function() {
16
- expect(etherToWei("-09999.0").toString()).toBe("-9999000000000000000000");
17
- });
18
- it("matches expected toNumber", function() {
19
- /* easy */ expect(etherToWei("9").toNumber()).toBe(9000000000000000000);
20
- /* harder */ expect(etherToWei("-0999999.90").toNumber()).toStrictEqual(-9.999999e23);
21
- });
22
- it("should throw for wrong types", function() {
23
- expect(function() {
24
- // @ts-expect-error should not accept boolean
25
- etherToWei(false);
26
- }).toThrow();
27
- expect(function() {
28
- // @ts-expect-error should not accept array
29
- etherToWei([
30
- 1,
31
- 2,
32
- 3
33
- ]);
34
- }).toThrow();
35
- });
36
- });
@@ -1,28 +0,0 @@
1
- import Big from "big.js";
2
- import { gweiToEther, tinyBig } from "../../index";
3
- describe("gweiToEther", function() {
4
- it("happy path", function() {
5
- expect(gweiToEther("100000000000.0").toString()).toBe("100");
6
- expect(gweiToEther(100000000000.0).toString()).toBe("100");
7
- expect(gweiToEther("1000000000000.0").toNumber()).toBe(1000);
8
- expect(gweiToEther(1000000000000.0).toNumber()).toBe(1000);
9
- expect(gweiToEther(tinyBig("1000000000000.0")).toNumber()).toBe(1000);
10
- expect(gweiToEther(tinyBig(1000000000000.0)).toNumber()).toBe(1000);
11
- expect(gweiToEther(Big("1000000000000.0")).toNumber()).toBe(1000);
12
- expect(gweiToEther(Big(1000000000000.0)).toNumber()).toBe(1000);
13
- });
14
- it("wrong types", function() {
15
- expect(function() {
16
- // @ts-expect-error should not accept boolean
17
- gweiToEther(false);
18
- }).toThrow();
19
- expect(function() {
20
- // @ts-expect-error should not accept array
21
- gweiToEther([
22
- 1,
23
- 2,
24
- 3
25
- ]);
26
- }).toThrow();
27
- });
28
- });
@@ -1,32 +0,0 @@
1
- import { hashMessage } from "../../index";
2
- describe("utils.hashMessage", function() {
3
- it("should compute correct hash", function() {
4
- var testCases = [
5
- {
6
- message: "0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb",
7
- expectedHash: "0x053af31bc24e13e344973ab25910ff8da04a8acdd63a04187f84b7a340e9d663"
8
- },
9
- {
10
- message: "27b1fdb04752bbc536007a920d24acb045561c26",
11
- expectedHash: "0xd8141e0ec15afbf98a6f93d51e1b8bb8d988be77bca76a5692b73493d232f4f1"
12
- },
13
- {
14
- message: [
15
- 1,
16
- 2
17
- ],
18
- expectedHash: "0xd87309a295607439d67ad5243462242d36775fa665de60f4e26895808e01389b"
19
- },
20
- {
21
- message: [
22
- 0x1,
23
- 0x2
24
- ],
25
- expectedHash: "0xd87309a295607439d67ad5243462242d36775fa665de60f4e26895808e01389b"
26
- }
27
- ];
28
- testCases.forEach(function(testCase) {
29
- expect(hashMessage(testCase.message)).toBe(testCase.expectedHash);
30
- });
31
- });
32
- });
@@ -1,48 +0,0 @@
1
- import { isAddress } from "../../index";
2
- describe("is-address", function() {
3
- it("should validate real addresses", function() {
4
- var addresses = [
5
- "0x52908400098527886E0F7030069857D2E4169EE7",
6
- "0x8617E340B3D01FA5F11F306F4090FD50E238070D",
7
- "0xde709f2102306220921060314715629080e2fb77",
8
- "0x27b1fdb04752bbc536007a920d24acb045561c26",
9
- "0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed",
10
- "0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359",
11
- "0xdbF03B407c01E7cD3CBea99509d93f8DDDC8C6FB",
12
- "0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb",
13
- "27b1fdb04752bbc536007a920d24acb045561c26" /* leading "0x" is not required */
14
- ];
15
- addresses.forEach(function(address) {
16
- expect(isAddress(address)).toBe(true);
17
- });
18
- });
19
- it("should return false on invalid addresses", function() {
20
- var addresses = [
21
- "0x5290840009852",
22
- "0x8617E340b3D01FA5F11F306F4090FD50E238070D",
23
- "0x8617e340b3d01FA5F11F306F4090FD50E238070D" /* invalid checksum */ ,
24
- " 0xde709f2102306220921060314715629080e2fb77",
25
- "dawsbot.eth" /* ens invalid */ ,
26
- "",
27
- "xyz",
28
- "0x123"
29
- ];
30
- addresses.forEach(function(address) {
31
- expect(isAddress(address)).toBe(false);
32
- });
33
- });
34
- it("invalid type inputs", function() {
35
- expect(function() {
36
- // @ts-expect-error should not accept boolean
37
- isAddress(false);
38
- }).toThrow("string required. Received boolean");
39
- expect(function() {
40
- // @ts-expect-error should not accept array
41
- isAddress([
42
- 1,
43
- 2,
44
- 3
45
- ]);
46
- }).toThrow("string required. Received object");
47
- });
48
- });
@@ -1,121 +0,0 @@
1
- import { keccak256 } from "./../keccak256";
2
- import { toUtf8Bytes } from "./../to-utf8-bytes";
3
- /**
4
- *
5
- * @param inputs
6
- * @param expected
7
- */ function testKeccak256(inputs, expected) {
8
- inputs.forEach(function(input, index) {
9
- expect(keccak256(input)).toBe(expected[index]);
10
- });
11
- }
12
- describe("keccak256", function() {
13
- it("should match expected - hex strings", function() {
14
- var inputs = [
15
- "0x4d7F1790644Af787933c9fF0e2cff9a9B4299Abb",
16
- "0xB5503a7db1A9105cd459D99153e69a76a8EF1530",
17
- "0xaa0fc255b079e775f9307e5cfec472a555cebc3a"
18
- ];
19
- var expected = [
20
- "0x72fe4a1287bb827ec8d04e045f7559955a8e694063af513008f111670674178a",
21
- "0x012d02a94561e140985a0382377e7676eec97a73007e188ffd1d0a0c01b1eb4d",
22
- "0xfe9ee1df3c10848ed968a46ced4a0bb9674195ece0cfc63959d8058d77700d84"
23
- ];
24
- testKeccak256(inputs, expected);
25
- });
26
- it("should match expected - bytes", function() {
27
- var inputs = [
28
- [
29
- 2,
30
- 182,
31
- 145
32
- ],
33
- [
34
- 0,
35
- 16,
36
- 255
37
- ],
38
- [
39
- 0x12,
40
- 0x34
41
- ],
42
- [
43
- 0x12
44
- ]
45
- ];
46
- var expected = [
47
- "0x324544acf03f9c2ac85ab3a820ab3371bf7965a342bcdd5f74e28eb6d1f60050",
48
- "0xfe10bfcde301e8b760615ba65ba2a0c7fb72f9bcdea7c45841ef7b355a443e51",
49
- "0x56570de287d73cd1cb6092bb8fdee6173974955fdef345ae579ee9f475ea7432",
50
- "0x5fa2358263196dbbf23d1ca7a509451f7a2f64c15837bfbb81298b1e3e24e4fa"
51
- ];
52
- testKeccak256(inputs, expected);
53
- });
54
- it("should match expected - numbers", function() {
55
- var inputs = [
56
- 23874234,
57
- 123346,
58
- 12395712
59
- ].map(function(n) {
60
- return toUtf8Bytes(n.toString());
61
- });
62
- var expected = [
63
- "0x6cc5c464579b7e93f9e3192ecad21e933e5497d24a067546a264874a1cdbe48d",
64
- "0xf54c8ff9e4afcd296f686a15dda3b8f9f2da621866842b2427ab578e0aaa7344",
65
- "0xd9ba3a9f9b521946abbae91c3799ac03a3ec95d2a69a5ab5974242d36e3c6f32"
66
- ];
67
- testKeccak256(inputs, expected);
68
- });
69
- it("should match expected - strings", function() {
70
- var inputs = [
71
- "essential-eth",
72
- "firstText",
73
- "secondString",
74
- "example1",
75
- "2934823",
76
- "true"
77
- ].map(toUtf8Bytes);
78
- var expected = [
79
- "0xd5b027dc2bddae7475604f19ca210363f0a3c63a32d79c2fff540b9c21249f2c",
80
- "0x3b0c4ce69832f4f4036e87bf56b9062018040b5b0f031062bd9667fb579c844f",
81
- "0x2f33a7c2165d73854f66613815214ba5812046579723927d001cabe696078ae7",
82
- "0xf5590342e9e60df9335478edb075a7c323b2e11d690d18d35eaa32f13e48788d",
83
- "0x0517ce0ae90a6a7f7f4770d867e1fc57e38e7f1d133942fdbcbabe53c98d3761",
84
- "0x6273151f959616268004b58dbb21e5c851b7b8d04498b4aabee12291d22fc034"
85
- ];
86
- testKeccak256(inputs, expected);
87
- });
88
- // it('should match ethers.js bytes (dynamic size) & BytesLike', () => {
89
- // const inputs = [
90
- // [115, 101, 99, 114, 101, 116],
91
- // ['0x62797465734c696b65'],
92
- // '0x657373656e7469616c2d657468',
93
- // [115, 109, 97, 108, 108, 101, 115, 116],
94
- // ];
95
- // testKeccak256(inputs);
96
- // });
97
- // it('should match ethers.js bytes (static size)', () => {
98
- // const inputs = [
99
- // { types: ['bytes4'], values: [[116, 101, 115, 116]] },
100
- // {
101
- // types: ['bytes13', 'bytes1', 'bytes2', 'bytes5', 'bytes1'],
102
- // values: [
103
- // [101, 115, 115, 101, 110, 116, 105, 97, 108, 45, 101, 116, 104],
104
- // [32],
105
- // [105, 115],
106
- // [103, 114, 101, 97, 116],
107
- // [33],
108
- // ],
109
- // },
110
- // ];
111
- // testKeccak256(inputs);
112
- // });
113
- // it('should match ethers.js (signed and unsigned) integers', () => {
114
- // const inputs = [
115
- // { types: ['int16'], values: [-1] },
116
- // { types: ['uint48'], values: [12] },
117
- // { types: ['int16', 'uint48'], values: [-1, 12] },
118
- // ];
119
- // testKeccak256(inputs);
120
- // });
121
- });