essential-eth 0.6.2 → 0.7.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.
- package/dist/cjs/classes/Contract.js +307 -66
- package/dist/cjs/classes/test/Contract/crv-abi.js +252 -256
- package/dist/cjs/classes/test/Contract/crv.test.js +690 -0
- package/dist/cjs/classes/test/Contract/ens-abi.js +497 -212
- package/dist/cjs/classes/test/Contract/ens.test.js +217 -0
- package/dist/cjs/classes/test/Contract/fei-abi.js +605 -284
- package/dist/cjs/classes/test/Contract/fei.test.js +224 -0
- package/dist/cjs/classes/test/Contract/foo-abi.js +44 -21
- package/dist/cjs/classes/test/Contract/foo.test.js +33 -0
- package/dist/cjs/classes/test/Contract/uni.test.js +387 -0
- package/dist/cjs/classes/test/Contract/uniswap-abi.js +64 -68
- package/dist/cjs/classes/utils/clean-block.d.ts +1 -2
- package/dist/cjs/classes/utils/clean-block.js +52 -30
- package/dist/cjs/classes/utils/clean-log.js +42 -20
- package/dist/cjs/classes/utils/clean-transaction-receipt.js +51 -29
- package/dist/cjs/classes/utils/clean-transaction.js +52 -29
- package/dist/cjs/classes/utils/encode-decode-transaction.d.ts +1 -1
- package/dist/cjs/classes/utils/encode-decode-transaction.js +163 -83
- package/dist/cjs/classes/utils/fetchers.js +165 -41
- package/dist/cjs/classes/utils/hex-to-decimal.js +1 -6
- package/dist/cjs/classes/utils/prepare-transaction.js +59 -36
- package/dist/cjs/index.js +25 -54
- package/dist/cjs/index.umd.js +1 -1
- package/dist/cjs/index.umd.js.map +1 -1
- package/dist/cjs/logger/logger.js +79 -23
- package/dist/cjs/logger/package-version.d.ts +1 -1
- package/dist/cjs/logger/package-version.js +1 -4
- package/dist/cjs/providers/BaseProvider.js +824 -475
- package/dist/cjs/providers/FallthroughProvider.js +118 -37
- package/dist/cjs/providers/JsonRpcProvider.js +93 -28
- package/dist/cjs/providers/test/fallthrough-provider/get-gas-price.test.js +228 -0
- package/dist/cjs/providers/test/get-transaction-count.test.js +276 -0
- package/dist/cjs/providers/test/json-rpc-provider/call.test.js +436 -0
- package/dist/cjs/providers/test/json-rpc-provider/estimate-gas.test.js +288 -0
- package/dist/cjs/providers/test/json-rpc-provider/get-balance.test.js +261 -0
- package/dist/cjs/providers/test/json-rpc-provider/get-block-number.test.js +230 -0
- package/dist/cjs/providers/test/json-rpc-provider/get-block.test.js +501 -0
- package/dist/cjs/providers/test/json-rpc-provider/get-code.test.js +311 -0
- package/dist/cjs/providers/test/json-rpc-provider/get-gas-price.test.js +202 -0
- package/dist/cjs/providers/test/json-rpc-provider/get-logs.test.js +361 -0
- package/dist/cjs/providers/test/json-rpc-provider/get-network.test.js +274 -0
- package/dist/cjs/providers/test/json-rpc-provider/get-transaction-receipt.test.js +301 -0
- package/dist/cjs/providers/test/json-rpc-provider/get-transaction.test.js +307 -0
- package/dist/cjs/providers/test/rpc-urls.js +9 -12
- package/dist/cjs/providers/utils/chains-info.js +1 -3
- package/dist/cjs/shared/tiny-big/helpers.js +93 -42
- package/dist/cjs/shared/tiny-big/helpers.test.js +29 -0
- package/dist/cjs/shared/tiny-big/tiny-big.js +161 -72
- package/dist/cjs/shared/tiny-big/tiny-big.test.js +34 -0
- package/dist/cjs/shared/validate-type.js +7 -7
- package/dist/cjs/types/Block.types.js +1 -2
- package/dist/cjs/types/Contract.types.js +1 -2
- package/dist/cjs/types/Filter.types.js +1 -2
- package/dist/cjs/types/Network.types.js +3 -2
- package/dist/cjs/types/Transaction.types.js +1 -2
- package/dist/cjs/utils/bytes.js +286 -318
- package/dist/cjs/utils/compute-address.js +8 -14
- package/dist/cjs/utils/compute-public-key.js +5 -10
- package/dist/cjs/utils/ether-to-gwei.js +10 -11
- package/dist/cjs/utils/ether-to-wei.js +10 -11
- package/dist/cjs/utils/gwei-to-ether.js +10 -11
- package/dist/cjs/utils/hash-message.d.ts +1 -1
- package/dist/cjs/utils/hash-message.js +11 -14
- package/dist/cjs/utils/is-address.js +8 -12
- package/dist/cjs/utils/keccak256.js +8 -14
- package/dist/cjs/utils/solidity-keccak256.js +49 -60
- package/dist/cjs/utils/split-signature.js +55 -73
- package/dist/cjs/utils/tests/bytes/arrayify.test.js +40 -0
- package/dist/cjs/utils/tests/bytes/concat.test.js +15 -0
- package/dist/cjs/utils/tests/bytes/hex-concat.test.js +63 -0
- package/dist/cjs/utils/tests/bytes/hex-data-length.test.js +49 -0
- package/dist/cjs/utils/tests/bytes/hex-data-slice.test.js +52 -0
- package/dist/cjs/utils/tests/bytes/hex-strip-zeros.test.js +58 -0
- package/dist/cjs/utils/tests/bytes/hex-value.test.js +85 -0
- package/dist/cjs/utils/tests/bytes/hex-zero-pad.test.js +62 -0
- package/dist/cjs/utils/tests/bytes/hexlify.test.js +62 -0
- package/dist/cjs/utils/tests/bytes/is-bytes-like.test.js +69 -0
- package/dist/cjs/utils/tests/bytes/is-bytes.test.js +33 -0
- package/dist/cjs/utils/tests/bytes/is-hex-string.test.js +88 -0
- package/dist/cjs/utils/tests/bytes/strip-zeros.test.js +57 -0
- package/dist/cjs/utils/tests/bytes/zero-pad.test.js +80 -0
- package/dist/cjs/utils/tests/compute-address.test.js +27 -0
- package/dist/cjs/utils/tests/compute-public-key.test.js +15 -0
- package/dist/cjs/utils/tests/ether-to-gwei.test.js +26 -0
- package/dist/cjs/utils/tests/ether-to-wei.test.js +44 -0
- package/dist/cjs/utils/tests/gwei-to-ether.test.js +28 -0
- package/dist/cjs/utils/tests/hash-message.test.js +21 -0
- package/dist/cjs/utils/tests/is-address.test.js +55 -0
- package/dist/cjs/utils/tests/keccak256.test.js +97 -0
- package/dist/cjs/utils/tests/solidity-keccak256.test.js +310 -0
- package/dist/cjs/utils/tests/split-signature.test.js +25 -0
- package/dist/cjs/utils/tests/to-checksum-address.test.js +42 -0
- package/dist/cjs/utils/tests/to-utf8-bytes.test.js +14 -0
- package/dist/cjs/utils/tests/wei-to-ether.test.js +51 -0
- package/dist/cjs/utils/to-checksum-address.js +15 -20
- package/dist/cjs/utils/to-utf8-bytes.js +1 -6
- package/dist/cjs/utils/wei-to-ether.js +13 -15
- package/dist/esm/classes/utils/clean-block.d.ts +1 -2
- package/dist/esm/classes/utils/clean-block.js +1 -1
- package/dist/esm/classes/utils/clean-transaction-receipt.js +2 -1
- package/dist/esm/classes/utils/clean-transaction.js +2 -1
- package/dist/esm/classes/utils/encode-decode-transaction.d.ts +1 -1
- package/dist/esm/classes/utils/encode-decode-transaction.js +37 -2
- package/dist/esm/logger/package-version.d.ts +1 -1
- package/dist/esm/logger/package-version.js +1 -1
- package/dist/esm/utils/compute-address.js +2 -1
- package/dist/esm/utils/hash-message.d.ts +1 -1
- package/dist/esm/utils/hash-message.js +3 -1
- package/dist/esm/utils/is-address.js +1 -1
- package/package.json +8 -6
- package/readme.md +34 -3
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { utils as ethers } from "ethers";
|
|
2
|
+
import { stripZeros } from "../../bytes";
|
|
3
|
+
describe("utils.stripZeros", function() {
|
|
4
|
+
it("should match ethers.js - hex string", function() {
|
|
5
|
+
var values = [
|
|
6
|
+
"0x00009347",
|
|
7
|
+
"0x00185754",
|
|
8
|
+
"0x00000000005823"
|
|
9
|
+
];
|
|
10
|
+
values.forEach(function(value) {
|
|
11
|
+
expect(stripZeros(value)).toStrictEqual(ethers.stripZeros(value));
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
it("should match ethers.js - UInt8Array", 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
|
+
]
|
|
43
|
+
];
|
|
44
|
+
values.forEach(function(value) {
|
|
45
|
+
expect(stripZeros(value)).toStrictEqual(ethers.stripZeros(value));
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
it("should match ethers.js - empty array", function() {
|
|
49
|
+
var values = [
|
|
50
|
+
[],
|
|
51
|
+
"0x"
|
|
52
|
+
];
|
|
53
|
+
values.forEach(function(value) {
|
|
54
|
+
expect(stripZeros(value)).toStrictEqual(ethers.stripZeros(value));
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { utils as ethers } from "ethers";
|
|
2
|
+
import { zeroPad } from "../../bytes";
|
|
3
|
+
describe("utils.zeroPad", function() {
|
|
4
|
+
it("should match ethers.js - hex string", function() {
|
|
5
|
+
var values = [
|
|
6
|
+
[
|
|
7
|
+
"0x9347",
|
|
8
|
+
10
|
|
9
|
+
],
|
|
10
|
+
[
|
|
11
|
+
"0x185754",
|
|
12
|
+
5
|
|
13
|
+
],
|
|
14
|
+
[
|
|
15
|
+
"0x00005823",
|
|
16
|
+
7
|
|
17
|
+
]
|
|
18
|
+
];
|
|
19
|
+
values.forEach(function(value) {
|
|
20
|
+
expect(zeroPad(value[0], value[1])).toStrictEqual(ethers.zeroPad(value[0], value[1]));
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
it("should match ethers.js - UInt8Array", function() {
|
|
24
|
+
var values = [
|
|
25
|
+
[
|
|
26
|
+
[
|
|
27
|
+
9,
|
|
28
|
+
58,
|
|
29
|
+
29,
|
|
30
|
+
24
|
|
31
|
+
],
|
|
32
|
+
5
|
|
33
|
+
],
|
|
34
|
+
[
|
|
35
|
+
[
|
|
36
|
+
185,
|
|
37
|
+
203
|
|
38
|
+
],
|
|
39
|
+
4
|
|
40
|
+
],
|
|
41
|
+
[
|
|
42
|
+
[
|
|
43
|
+
239,
|
|
44
|
+
30,
|
|
45
|
+
49,
|
|
46
|
+
41,
|
|
47
|
+
5,
|
|
48
|
+
10,
|
|
49
|
+
42
|
|
50
|
+
],
|
|
51
|
+
10
|
|
52
|
+
]
|
|
53
|
+
];
|
|
54
|
+
values.forEach(function(value) {
|
|
55
|
+
expect(zeroPad(value[0], value[1])).toStrictEqual(ethers.zeroPad(value[0], value[1]));
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
it("should throw error - value out of range", function() {
|
|
59
|
+
var values = [
|
|
60
|
+
[
|
|
61
|
+
[
|
|
62
|
+
9,
|
|
63
|
+
58,
|
|
64
|
+
29,
|
|
65
|
+
24
|
|
66
|
+
],
|
|
67
|
+
3
|
|
68
|
+
],
|
|
69
|
+
[
|
|
70
|
+
"0x185754",
|
|
71
|
+
1
|
|
72
|
+
]
|
|
73
|
+
];
|
|
74
|
+
values.forEach(function(value) {
|
|
75
|
+
expect(function() {
|
|
76
|
+
return zeroPad(value[0], value[1]);
|
|
77
|
+
}).toThrow("value out of range");
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { utils } from "ethers";
|
|
2
|
+
import { computeAddress } from "../../index";
|
|
3
|
+
function testComputeAddress(keys) {
|
|
4
|
+
keys.forEach(function(key) {
|
|
5
|
+
expect(computeAddress(key)).toBe(utils.computeAddress(key));
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
describe("computeAddress", function() {
|
|
9
|
+
it("should match ethers.js - public key", function() {
|
|
10
|
+
var publicKeys = [
|
|
11
|
+
"0x04aaa2abcf8d119ad68b2c190abf34355a0029197911e2446007d5b44e6fddfd54352326fedac51eca491d59937c592ecffff65c6941037babbe26edfdbb32a688",
|
|
12
|
+
"0x04e8aa3d196e3a785fb5b431265074c01f571a79231e0cc0fc28e67d9c648471aca8229cafcc6cd806cd1a679f538326577bf9485c68f7a1c90b5116b669f30473",
|
|
13
|
+
"0x04110dfa471c3f04a6c9dfd857705eb080542c9672cf0f30d95f5fca382181293d6e91320916dd649d03c76818af8e7ee173781888e42e2f00bda9a8f797e0fd61",
|
|
14
|
+
"0x04593bea29e692123fda1b6f8280b8414524c7838fd448abe6dd1e072bee5e2e9c66e19976b9310ce514d8612c5736201ddc3bb966412076cd4b24e7f649e779b3"
|
|
15
|
+
];
|
|
16
|
+
testComputeAddress(publicKeys);
|
|
17
|
+
});
|
|
18
|
+
it("should match ethers.js - private key", function() {
|
|
19
|
+
var privateKeys = [
|
|
20
|
+
"0x8da4ef21b864d2cc526dbdb2a120bd2874c36c9d0a1fb7f8c63d7f7a8b41de8f",
|
|
21
|
+
"0x42e12f76412f53de9d60df199a368699b6ec15d3798efb0b2a45b8c1b4f902a6",
|
|
22
|
+
"0x262f8fffb353d3e11be770dd4208dcab1fa5c205d574a78088829f45b1ac2487",
|
|
23
|
+
"0x1bcfb8b7a46e2f886ef61f8010426f70ce3c7fc1362973aa26d30b8f77711d93"
|
|
24
|
+
];
|
|
25
|
+
testComputeAddress(privateKeys);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { utils } from "ethers";
|
|
2
|
+
import { computePublicKey } from "../../index";
|
|
3
|
+
describe("computePublicKey", function() {
|
|
4
|
+
it("should match ethers.js", function() {
|
|
5
|
+
var privateKeys = [
|
|
6
|
+
"0x8da4ef21b864d2cc526dbdb2a120bd2874c36c9d0a1fb7f8c63d7f7a8b41de8f",
|
|
7
|
+
"0x38a3159d73cefd392d0176c29b3cc60ff43e81813f5ab5782571511df9bb16e2",
|
|
8
|
+
"0xb6d36857e1f9b68e413d2496bb588f3650cdcc2398b3941963c44db8108b8671",
|
|
9
|
+
"0xf237d9763445d41150f9a199ad93ad478dff29ad8fe6fa00149ed12f40f8eb6f"
|
|
10
|
+
];
|
|
11
|
+
privateKeys.forEach(function(key) {
|
|
12
|
+
expect(computePublicKey(key)).toBe(utils.computePublicKey(key));
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import Big from "big.js";
|
|
2
|
+
import * as ethers from "ethers";
|
|
3
|
+
import web3 from "web3";
|
|
4
|
+
import { etherToWei, tinyBig } from "../../index";
|
|
5
|
+
import { scientificStrToDecimalStr } from "../../shared/tiny-big/helpers";
|
|
6
|
+
describe("ether-to-wei", function() {
|
|
7
|
+
it("happy path", function() {
|
|
8
|
+
expect(etherToWei("100").toString()).toBe("100000000000000000000");
|
|
9
|
+
expect(etherToWei(100).toString()).toBe("100000000000000000000");
|
|
10
|
+
expect(etherToWei("1000.0").toString()).toBe("1000000000000000000000");
|
|
11
|
+
expect(etherToWei(1000).toString()).toBe("1000000000000000000000");
|
|
12
|
+
expect(etherToWei("1000.0").toNumber()).toBe(1000000000000000000000);
|
|
13
|
+
expect(etherToWei(tinyBig(1000)).toString()).toBe("1000000000000000000000");
|
|
14
|
+
expect(etherToWei(tinyBig("1000.0")).toNumber()).toBe(1000000000000000000000);
|
|
15
|
+
expect(etherToWei(Big(1000)).toString()).toBe("1000000000000000000000");
|
|
16
|
+
expect(etherToWei(Big("1000.0")).toNumber()).toBe(1000000000000000000000);
|
|
17
|
+
});
|
|
18
|
+
it("matches ethers and web3 toString", function() {
|
|
19
|
+
expect(etherToWei("-09999.0").toString()).toStrictEqual(ethers.utils.parseEther("-09999.0").toString());
|
|
20
|
+
expect(etherToWei("-09999.0").toString()).toStrictEqual(web3.utils.toWei("-09999.0", "ether"));
|
|
21
|
+
});
|
|
22
|
+
it("matches ethers and web3 toNumber", function() {
|
|
23
|
+
/* easy */ expect(etherToWei("9").toNumber()).toStrictEqual(Number(ethers.utils.parseEther("9")));
|
|
24
|
+
// web3 responds with scientific notation
|
|
25
|
+
expect(etherToWei("9").toNumber()).toStrictEqual(Number(web3.utils.toWei("9", "ether")));
|
|
26
|
+
/* harder */ expect(etherToWei("-0999999.90").toNumber()).toStrictEqual(Number(ethers.utils.parseEther("-0999999.90")));
|
|
27
|
+
// web3 responds with scientific notation
|
|
28
|
+
expect(etherToWei("-0999999.9").toNumber()).toStrictEqual(Number(scientificStrToDecimalStr(web3.utils.toWei("-0999999.9", "ether"))));
|
|
29
|
+
});
|
|
30
|
+
it("should throw for wrong types", function() {
|
|
31
|
+
expect(function() {
|
|
32
|
+
// @ts-expect-error should not accept boolean
|
|
33
|
+
etherToWei(false);
|
|
34
|
+
}).toThrow();
|
|
35
|
+
expect(function() {
|
|
36
|
+
// @ts-expect-error should not accept array
|
|
37
|
+
etherToWei([
|
|
38
|
+
1,
|
|
39
|
+
2,
|
|
40
|
+
3
|
|
41
|
+
]);
|
|
42
|
+
}).toThrow();
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { utils } from "ethers";
|
|
2
|
+
import { hashMessage } from "../../index";
|
|
3
|
+
describe("utils.hashMessage", function() {
|
|
4
|
+
it("should match ethers.js", function() {
|
|
5
|
+
var messages = [
|
|
6
|
+
"0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb",
|
|
7
|
+
"27b1fdb04752bbc536007a920d24acb045561c26" /* leading "0x" is not required */ ,
|
|
8
|
+
[
|
|
9
|
+
1,
|
|
10
|
+
2
|
|
11
|
+
],
|
|
12
|
+
[
|
|
13
|
+
0x1,
|
|
14
|
+
0x2
|
|
15
|
+
]
|
|
16
|
+
];
|
|
17
|
+
messages.forEach(function(message) {
|
|
18
|
+
expect(hashMessage(message)).toStrictEqual(utils.hashMessage(message));
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { utils } from "ethers";
|
|
2
|
+
import web3 from "web3";
|
|
3
|
+
import { isAddress } from "../../index";
|
|
4
|
+
describe("is-address", function() {
|
|
5
|
+
it("should validate real addresses", function() {
|
|
6
|
+
var addresses = [
|
|
7
|
+
"0x52908400098527886E0F7030069857D2E4169EE7",
|
|
8
|
+
"0x8617E340B3D01FA5F11F306F4090FD50E238070D",
|
|
9
|
+
"0xde709f2102306220921060314715629080e2fb77",
|
|
10
|
+
"0x27b1fdb04752bbc536007a920d24acb045561c26",
|
|
11
|
+
"0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed",
|
|
12
|
+
"0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359",
|
|
13
|
+
"0xdbF03B407c01E7cD3CBea99509d93f8DDDC8C6FB",
|
|
14
|
+
"0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb",
|
|
15
|
+
"27b1fdb04752bbc536007a920d24acb045561c26" /* leading "0x" is not required */
|
|
16
|
+
];
|
|
17
|
+
addresses.forEach(function(address) {
|
|
18
|
+
expect(isAddress(address)).toStrictEqual(utils.isAddress(address));
|
|
19
|
+
expect(isAddress(address)).toStrictEqual(web3.utils.isAddress(address));
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
it("should return false on invalid addresses", function() {
|
|
23
|
+
var addresses = [
|
|
24
|
+
"0x5290840009852",
|
|
25
|
+
"0x8617E340b3D01FA5F11F306F4090FD50E238070D",
|
|
26
|
+
"0x8617e340b3d01FA5F11F306F4090FD50E238070D" /* invalid checksum */ ,
|
|
27
|
+
" 0xde709f2102306220921060314715629080e2fb77",
|
|
28
|
+
"dawsbot.eth" /* ens invalid */ ,
|
|
29
|
+
"",
|
|
30
|
+
"xyz",
|
|
31
|
+
"0x123"
|
|
32
|
+
];
|
|
33
|
+
addresses.forEach(function(address) {
|
|
34
|
+
var essentialEthIsAddress = isAddress(address);
|
|
35
|
+
var ethersIsAddress = utils.isAddress(address);
|
|
36
|
+
var web3IsAddress = web3.utils.isAddress(address);
|
|
37
|
+
expect(essentialEthIsAddress).toStrictEqual(ethersIsAddress);
|
|
38
|
+
expect(essentialEthIsAddress).toStrictEqual(web3IsAddress);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
it("invalid type inputs", function() {
|
|
42
|
+
expect(function() {
|
|
43
|
+
// @ts-expect-error should not accept boolean
|
|
44
|
+
isAddress(false);
|
|
45
|
+
}).toThrow("string required. Received boolean");
|
|
46
|
+
expect(function() {
|
|
47
|
+
// @ts-expect-error should not accept array
|
|
48
|
+
isAddress([
|
|
49
|
+
1,
|
|
50
|
+
2,
|
|
51
|
+
3
|
|
52
|
+
]);
|
|
53
|
+
}).toThrow("string required. Received object");
|
|
54
|
+
});
|
|
55
|
+
});
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { utils } from "ethers";
|
|
2
|
+
import { keccak256 } from "./../keccak256";
|
|
3
|
+
import { toUtf8Bytes } from "./../to-utf8-bytes";
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @param inputs
|
|
7
|
+
*/ function testKeccak256(inputs) {
|
|
8
|
+
inputs.forEach(function(input) {
|
|
9
|
+
expect(keccak256(input)).toBe(utils.keccak256(input));
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
describe("keccak256", function() {
|
|
13
|
+
it("should match ethers.js hex strings", function() {
|
|
14
|
+
var inputs = [
|
|
15
|
+
"0x4d7F1790644Af787933c9fF0e2cff9a9B4299Abb",
|
|
16
|
+
"0xB5503a7db1A9105cd459D99153e69a76a8EF1530",
|
|
17
|
+
"0xaa0fc255b079e775f9307e5cfec472a555cebc3a"
|
|
18
|
+
];
|
|
19
|
+
testKeccak256(inputs);
|
|
20
|
+
});
|
|
21
|
+
it("should match ethers.js bytes", function() {
|
|
22
|
+
var inputs = [
|
|
23
|
+
[
|
|
24
|
+
2,
|
|
25
|
+
182,
|
|
26
|
+
145
|
|
27
|
+
],
|
|
28
|
+
[
|
|
29
|
+
0,
|
|
30
|
+
16,
|
|
31
|
+
255
|
|
32
|
+
],
|
|
33
|
+
[
|
|
34
|
+
0x12,
|
|
35
|
+
0x34
|
|
36
|
+
],
|
|
37
|
+
[
|
|
38
|
+
0x12
|
|
39
|
+
]
|
|
40
|
+
];
|
|
41
|
+
testKeccak256(inputs);
|
|
42
|
+
});
|
|
43
|
+
it("should match ethers.js numbers", function() {
|
|
44
|
+
var inputs = [
|
|
45
|
+
23874234,
|
|
46
|
+
123346,
|
|
47
|
+
12395712
|
|
48
|
+
].map(function(n) {
|
|
49
|
+
return toUtf8Bytes(n.toString());
|
|
50
|
+
});
|
|
51
|
+
testKeccak256(inputs);
|
|
52
|
+
});
|
|
53
|
+
it("should match ethers.js strings", function() {
|
|
54
|
+
var inputs = [
|
|
55
|
+
"essential-eth",
|
|
56
|
+
"firstText",
|
|
57
|
+
"secondString",
|
|
58
|
+
"example1",
|
|
59
|
+
"2934823",
|
|
60
|
+
"true"
|
|
61
|
+
].map(toUtf8Bytes);
|
|
62
|
+
testKeccak256(inputs);
|
|
63
|
+
});
|
|
64
|
+
// it('should match ethers.js bytes (dynamic size) & BytesLike', () => {
|
|
65
|
+
// const inputs = [
|
|
66
|
+
// [115, 101, 99, 114, 101, 116],
|
|
67
|
+
// ['0x62797465734c696b65'],
|
|
68
|
+
// '0x657373656e7469616c2d657468',
|
|
69
|
+
// [115, 109, 97, 108, 108, 101, 115, 116],
|
|
70
|
+
// ];
|
|
71
|
+
// testKeccak256(inputs);
|
|
72
|
+
// });
|
|
73
|
+
// it('should match ethers.js bytes (static size)', () => {
|
|
74
|
+
// const inputs = [
|
|
75
|
+
// { types: ['bytes4'], values: [[116, 101, 115, 116]] },
|
|
76
|
+
// {
|
|
77
|
+
// types: ['bytes13', 'bytes1', 'bytes2', 'bytes5', 'bytes1'],
|
|
78
|
+
// values: [
|
|
79
|
+
// [101, 115, 115, 101, 110, 116, 105, 97, 108, 45, 101, 116, 104],
|
|
80
|
+
// [32],
|
|
81
|
+
// [105, 115],
|
|
82
|
+
// [103, 114, 101, 97, 116],
|
|
83
|
+
// [33],
|
|
84
|
+
// ],
|
|
85
|
+
// },
|
|
86
|
+
// ];
|
|
87
|
+
// testKeccak256(inputs);
|
|
88
|
+
// });
|
|
89
|
+
// it('should match ethers.js (signed and unsigned) integers', () => {
|
|
90
|
+
// const inputs = [
|
|
91
|
+
// { types: ['int16'], values: [-1] },
|
|
92
|
+
// { types: ['uint48'], values: [12] },
|
|
93
|
+
// { types: ['int16', 'uint48'], values: [-1, 12] },
|
|
94
|
+
// ];
|
|
95
|
+
// testKeccak256(inputs);
|
|
96
|
+
// });
|
|
97
|
+
});
|