essential-eth 0.9.1-next.0 → 0.9.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.
- package/dist/cjs/classes/Contract.js +66 -311
- package/dist/cjs/classes/test/Contract/crv-abi.js +256 -252
- package/dist/cjs/classes/test/Contract/ens-abi.js +212 -497
- package/dist/cjs/classes/test/Contract/fei-abi.js +284 -605
- package/dist/cjs/classes/test/Contract/foo-abi.js +21 -44
- package/dist/cjs/classes/test/Contract/uniswap-abi.js +68 -64
- package/dist/cjs/classes/utils/clean-block.js +30 -52
- package/dist/cjs/classes/utils/clean-log.js +20 -42
- package/dist/cjs/classes/utils/clean-transaction-receipt.js +30 -51
- package/dist/cjs/classes/utils/clean-transaction.js +30 -52
- package/dist/cjs/classes/utils/encode-decode-transaction.js +107 -148
- package/dist/cjs/classes/utils/fetchers.js +44 -166
- package/dist/cjs/classes/utils/hex-to-decimal.js +6 -1
- package/dist/cjs/classes/utils/prepare-transaction.js +36 -59
- package/dist/cjs/index.js +56 -25
- package/dist/cjs/index.umd.js +1 -1
- package/dist/cjs/index.umd.js.map +1 -1
- package/dist/cjs/logger/logger.js +29 -123
- package/dist/cjs/logger/package-version.d.ts +1 -1
- package/dist/cjs/logger/package-version.js +4 -1
- package/dist/cjs/providers/AlchemyProvider.js +9 -82
- package/dist/cjs/providers/BaseProvider.js +520 -958
- package/dist/cjs/providers/FallthroughProvider.js +47 -156
- package/dist/cjs/providers/JsonRpcProvider.js +28 -114
- package/dist/cjs/providers/test/json-rpc-provider/get-logs/mocks.js +104 -101
- package/dist/cjs/providers/test/mock-of.js +6 -3
- package/dist/cjs/providers/test/rpc-urls.js +23 -15
- package/dist/cjs/providers/utils/chains-info.js +3 -1
- package/dist/cjs/shared/tiny-big/helpers.js +42 -93
- package/dist/cjs/shared/tiny-big/tiny-big.js +81 -210
- package/dist/cjs/shared/validate-type.js +7 -7
- package/dist/cjs/types/Block.types.js +2 -1
- package/dist/cjs/types/Contract.types.js +2 -1
- package/dist/cjs/types/FeeData.types.js +2 -1
- package/dist/cjs/types/Filter.types.js +2 -1
- package/dist/cjs/types/Network.types.js +2 -3
- package/dist/cjs/types/Transaction.types.js +2 -1
- package/dist/cjs/utils/bytes.js +318 -286
- package/dist/cjs/utils/compute-address.js +15 -8
- package/dist/cjs/utils/compute-public-key.js +10 -5
- package/dist/cjs/utils/ether-to-gwei.js +11 -10
- package/dist/cjs/utils/ether-to-wei.js +11 -10
- package/dist/cjs/utils/gwei-to-ether.js +11 -10
- package/dist/cjs/utils/hash-message.js +16 -11
- package/dist/cjs/utils/is-address.js +12 -8
- package/dist/cjs/utils/keccak256.js +14 -8
- package/dist/cjs/utils/solidity-keccak256.js +60 -49
- package/dist/cjs/utils/split-signature.js +73 -55
- package/dist/cjs/utils/to-checksum-address.js +20 -15
- package/dist/cjs/utils/to-utf8-bytes.js +6 -1
- package/dist/cjs/utils/wei-to-ether.js +15 -13
- package/dist/esm/logger/package-version.d.ts +1 -1
- package/dist/esm/logger/package-version.js +1 -1
- package/package.json +2 -2
- package/readme.md +1 -1
- package/dist/cjs/classes/test/Contract/crv.test.js +0 -497
- package/dist/cjs/classes/test/Contract/ens.test.js +0 -160
- package/dist/cjs/classes/test/Contract/fei.test.js +0 -224
- package/dist/cjs/classes/test/Contract/foo.test.js +0 -33
- package/dist/cjs/classes/test/Contract/uni.test.js +0 -289
- package/dist/cjs/providers/test/fallthrough-provider/get-gas-price.test.js +0 -228
- package/dist/cjs/providers/test/get-transaction-count.test.js +0 -239
- package/dist/cjs/providers/test/json-rpc-provider/call.test.js +0 -375
- package/dist/cjs/providers/test/json-rpc-provider/estimate-gas.test.js +0 -217
- package/dist/cjs/providers/test/json-rpc-provider/get-balance.test.js +0 -223
- package/dist/cjs/providers/test/json-rpc-provider/get-block-number.test.js +0 -163
- package/dist/cjs/providers/test/json-rpc-provider/get-block.test.js +0 -414
- package/dist/cjs/providers/test/json-rpc-provider/get-code.test.js +0 -282
- package/dist/cjs/providers/test/json-rpc-provider/get-fee-data.test.js +0 -187
- package/dist/cjs/providers/test/json-rpc-provider/get-gas-price.test.js +0 -167
- package/dist/cjs/providers/test/json-rpc-provider/get-logs/get-logs.test.js +0 -219
- package/dist/cjs/providers/test/json-rpc-provider/get-network.test.js +0 -232
- package/dist/cjs/providers/test/json-rpc-provider/get-transaction-receipt.test.js +0 -280
- package/dist/cjs/providers/test/json-rpc-provider/get-transaction.test.js +0 -266
- package/dist/cjs/providers/test/test-alchemy-provider.test.js +0 -151
- package/dist/cjs/shared/tiny-big/helpers.test.js +0 -29
- package/dist/cjs/shared/tiny-big/tiny-big.test.js +0 -34
- package/dist/cjs/utils/tests/bytes/arrayify.test.js +0 -64
- package/dist/cjs/utils/tests/bytes/concat.test.js +0 -17
- package/dist/cjs/utils/tests/bytes/hex-concat.test.js +0 -65
- package/dist/cjs/utils/tests/bytes/hex-data-length.test.js +0 -66
- package/dist/cjs/utils/tests/bytes/hex-data-slice.test.js +0 -51
- package/dist/cjs/utils/tests/bytes/hex-strip-zeros.test.js +0 -75
- package/dist/cjs/utils/tests/bytes/hex-value.test.js +0 -141
- package/dist/cjs/utils/tests/bytes/hex-zero-pad.test.js +0 -100
- package/dist/cjs/utils/tests/bytes/hexlify.test.js +0 -78
- package/dist/cjs/utils/tests/bytes/is-bytes-like.test.js +0 -68
- package/dist/cjs/utils/tests/bytes/is-bytes.test.js +0 -76
- package/dist/cjs/utils/tests/bytes/is-hex-string.test.js +0 -97
- package/dist/cjs/utils/tests/bytes/strip-zeros.test.js +0 -106
- package/dist/cjs/utils/tests/bytes/zero-pad.test.js +0 -144
- package/dist/cjs/utils/tests/compute-address.test.js +0 -49
- package/dist/cjs/utils/tests/compute-public-key.test.js +0 -26
- package/dist/cjs/utils/tests/ether-to-gwei.test.js +0 -26
- package/dist/cjs/utils/tests/ether-to-wei.test.js +0 -36
- package/dist/cjs/utils/tests/gwei-to-ether.test.js +0 -28
- package/dist/cjs/utils/tests/hash-message.test.js +0 -32
- package/dist/cjs/utils/tests/is-address.test.js +0 -48
- package/dist/cjs/utils/tests/keccak256.test.js +0 -121
- package/dist/cjs/utils/tests/solidity-keccak256.test.js +0 -311
- package/dist/cjs/utils/tests/split-signature.test.js +0 -46
- package/dist/cjs/utils/tests/to-checksum-address.test.js +0 -39
- package/dist/cjs/utils/tests/to-utf8-bytes.test.js +0 -34
- package/dist/cjs/utils/tests/wei-to-ether.test.js +0 -41
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { hexDataSlice } from "../../bytes";
|
|
2
|
-
describe("utils.hexDataSlice", function() {
|
|
3
|
-
it("should match expected slice - hexadecimal strings", function() {
|
|
4
|
-
var hexValues = [
|
|
5
|
-
"0x123456"
|
|
6
|
-
];
|
|
7
|
-
hexValues.forEach(function(hexValue) {
|
|
8
|
-
expect(hexDataSlice(hexValue, 0, 2)).toBe("0x1234");
|
|
9
|
-
});
|
|
10
|
-
});
|
|
11
|
-
it("should match expected slice - hexadecimal numbers", function() {
|
|
12
|
-
var hexValues = [
|
|
13
|
-
0x1234567891011
|
|
14
|
-
];
|
|
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");
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
it("should match expected slice - arrays of decimal numbers", function() {
|
|
22
|
-
var decimalArrays = [
|
|
23
|
-
[
|
|
24
|
-
0,
|
|
25
|
-
1,
|
|
26
|
-
2,
|
|
27
|
-
3,
|
|
28
|
-
4,
|
|
29
|
-
5,
|
|
30
|
-
6,
|
|
31
|
-
7,
|
|
32
|
-
8,
|
|
33
|
-
9
|
|
34
|
-
]
|
|
35
|
-
];
|
|
36
|
-
decimalArrays.forEach(function(decimalArray) {
|
|
37
|
-
expect(hexDataSlice(decimalArray, 1, 2)).toBe("0x01");
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
it("should throw error - invalid hex data", function() {
|
|
41
|
-
var values = [
|
|
42
|
-
"non-hex string",
|
|
43
|
-
"0x938"
|
|
44
|
-
];
|
|
45
|
-
values.forEach(function(value) {
|
|
46
|
-
expect(function() {
|
|
47
|
-
return hexDataSlice(value, 1, 3);
|
|
48
|
-
}).toThrow("invalid hexData");
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
});
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { hexStripZeros } from "../../bytes";
|
|
2
|
-
describe("utils.hexStripZeros", function() {
|
|
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
|
-
}
|
|
17
|
-
];
|
|
18
|
-
testCases.forEach(function(testCase) {
|
|
19
|
-
expect(hexStripZeros(testCase.value)).toBe(testCase.expected);
|
|
20
|
-
});
|
|
21
|
-
});
|
|
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
|
-
}
|
|
60
|
-
];
|
|
61
|
-
testCases.forEach(function(testCase) {
|
|
62
|
-
expect(hexStripZeros(testCase.value)).toBe(testCase.expected);
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
it("should throw error - invalid hex strings", function() {
|
|
66
|
-
var values = [
|
|
67
|
-
"non-hex string"
|
|
68
|
-
];
|
|
69
|
-
values.forEach(function(value) {
|
|
70
|
-
expect(function() {
|
|
71
|
-
return hexStripZeros(value);
|
|
72
|
-
}).toThrow("invalid hex string");
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
});
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import { hexValue } from "../../bytes";
|
|
2
|
-
import { tinyBig } from "./../../../shared/tiny-big/tiny-big";
|
|
3
|
-
describe("utils.hexValue", function() {
|
|
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
|
-
}
|
|
18
|
-
];
|
|
19
|
-
testCases.forEach(function(testCase) {
|
|
20
|
-
expect(hexValue(testCase.value)).toStrictEqual(testCase.expected);
|
|
21
|
-
});
|
|
22
|
-
});
|
|
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
|
-
}
|
|
52
|
-
];
|
|
53
|
-
testCases.forEach(function(testCase) {
|
|
54
|
-
expect(hexValue(testCase.value)).toStrictEqual(testCase.expected);
|
|
55
|
-
});
|
|
56
|
-
});
|
|
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
|
-
}
|
|
71
|
-
];
|
|
72
|
-
testCases.forEach(function(testCase) {
|
|
73
|
-
expect(hexValue(testCase.value)).toStrictEqual(testCase.expected);
|
|
74
|
-
});
|
|
75
|
-
});
|
|
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
|
-
}
|
|
90
|
-
];
|
|
91
|
-
testCases.forEach(function(testCase) {
|
|
92
|
-
expect(hexValue(testCase.value)).toStrictEqual(testCase.expected);
|
|
93
|
-
});
|
|
94
|
-
});
|
|
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
|
-
}
|
|
109
|
-
];
|
|
110
|
-
testCases.forEach(function(testCase) {
|
|
111
|
-
expect(hexValue(testCase.value)).toStrictEqual(testCase.expected);
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
it("should return 0x0 - only zero data given", function() {
|
|
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
|
-
}
|
|
136
|
-
];
|
|
137
|
-
testCases.forEach(function(testCase) {
|
|
138
|
-
expect(hexValue(testCase.value)).toStrictEqual(testCase.expected);
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
});
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { hexZeroPad } from "../../../";
|
|
2
|
-
describe("hexZeroPad", function() {
|
|
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
|
-
}
|
|
13
|
-
];
|
|
14
|
-
testCases.forEach(function(testCase) {
|
|
15
|
-
expect(hexZeroPad(testCase.value, 20)).toStrictEqual(testCase.expected);
|
|
16
|
-
});
|
|
17
|
-
});
|
|
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
|
-
}
|
|
29
|
-
];
|
|
30
|
-
testCases.forEach(function(testCase) {
|
|
31
|
-
expect(hexZeroPad(testCase.value, 15)).toStrictEqual(testCase.expected);
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
it("should throw error - non-hex string", function() {
|
|
35
|
-
var value = "52908";
|
|
36
|
-
expect(function() {
|
|
37
|
-
hexZeroPad(value, 23);
|
|
38
|
-
}).toThrow();
|
|
39
|
-
});
|
|
40
|
-
it("should throw error - values longer than desired length", function() {
|
|
41
|
-
var hexValues = [
|
|
42
|
-
0x123456,
|
|
43
|
-
"0x5aAebAd",
|
|
44
|
-
"0xfB691",
|
|
45
|
-
"0xD1220ab"
|
|
46
|
-
];
|
|
47
|
-
hexValues.forEach(function(hexValue) {
|
|
48
|
-
expect(function() {
|
|
49
|
-
return hexZeroPad(hexValue, 2);
|
|
50
|
-
}).toThrow();
|
|
51
|
-
});
|
|
52
|
-
});
|
|
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
|
-
}
|
|
95
|
-
];
|
|
96
|
-
testCases.forEach(function(testCase) {
|
|
97
|
-
expect(hexZeroPad(testCase.value, 15)).toStrictEqual(testCase.expected);
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
});
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { hexlify } from "../../bytes";
|
|
2
|
-
describe("utils.hexlify", function() {
|
|
3
|
-
it("matches expected strings - numbers", function() {
|
|
4
|
-
var testCases = [
|
|
5
|
-
{
|
|
6
|
-
value: 0,
|
|
7
|
-
expected: "0x00"
|
|
8
|
-
},
|
|
9
|
-
{
|
|
10
|
-
value: 4,
|
|
11
|
-
expected: "0x04"
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
value: 5,
|
|
15
|
-
expected: "0x05"
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
value: 16,
|
|
19
|
-
expected: "0x10"
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
value: BigInt(0),
|
|
23
|
-
expected: "0x00"
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
value: BigInt(16),
|
|
27
|
-
expected: "0x10"
|
|
28
|
-
}
|
|
29
|
-
];
|
|
30
|
-
testCases.forEach(function(testCase) {
|
|
31
|
-
expect(hexlify(testCase.value)).toBe(testCase.expected);
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
it("should hexlify with options - hexPad", function() {
|
|
35
|
-
var testCases = [
|
|
36
|
-
{
|
|
37
|
-
value: "0x3342e95",
|
|
38
|
-
options: {
|
|
39
|
-
hexPad: "left"
|
|
40
|
-
},
|
|
41
|
-
expected: "0x03342e95"
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
value: "0x41c942c42",
|
|
45
|
-
options: {
|
|
46
|
-
hexPad: "right"
|
|
47
|
-
},
|
|
48
|
-
expected: "0x41c942c420"
|
|
49
|
-
}
|
|
50
|
-
];
|
|
51
|
-
testCases.forEach(function(testCase) {
|
|
52
|
-
expect(hexlify(testCase.value, testCase.options)).toBe(testCase.expected);
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
it("should throw error - hex data is odd-length", function() {
|
|
56
|
-
var values = [
|
|
57
|
-
"0x931",
|
|
58
|
-
"0x34414"
|
|
59
|
-
];
|
|
60
|
-
values.forEach(function(value) {
|
|
61
|
-
expect(function() {
|
|
62
|
-
return hexlify(value);
|
|
63
|
-
}).toThrow("hex data is odd-length");
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
it("should throw error - invalid hexlify value", function() {
|
|
67
|
-
// @ts-expect-error
|
|
68
|
-
var values = [
|
|
69
|
-
"non-hex string",
|
|
70
|
-
false
|
|
71
|
-
];
|
|
72
|
-
values.forEach(function(value) {
|
|
73
|
-
expect(function() {
|
|
74
|
-
return hexlify(value);
|
|
75
|
-
}).toThrow("invalid hexlify value");
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
});
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { isBytesLike } from "../../bytes";
|
|
2
|
-
describe("utils.isBytesLike", function() {
|
|
3
|
-
it("should return true - hex string", function() {
|
|
4
|
-
var values = [
|
|
5
|
-
"0x9347",
|
|
6
|
-
"0x185754",
|
|
7
|
-
"0x00005823"
|
|
8
|
-
];
|
|
9
|
-
values.forEach(function(value) {
|
|
10
|
-
expect(isBytesLike(value)).toBe(true);
|
|
11
|
-
});
|
|
12
|
-
});
|
|
13
|
-
it("should return true - UInt8Array", function() {
|
|
14
|
-
var values = [
|
|
15
|
-
[
|
|
16
|
-
9,
|
|
17
|
-
58,
|
|
18
|
-
29,
|
|
19
|
-
24
|
|
20
|
-
],
|
|
21
|
-
[
|
|
22
|
-
185,
|
|
23
|
-
203
|
|
24
|
-
],
|
|
25
|
-
[
|
|
26
|
-
239,
|
|
27
|
-
30,
|
|
28
|
-
49,
|
|
29
|
-
41,
|
|
30
|
-
5,
|
|
31
|
-
10,
|
|
32
|
-
42
|
|
33
|
-
]
|
|
34
|
-
];
|
|
35
|
-
values.forEach(function(value) {
|
|
36
|
-
expect(isBytesLike(value)).toBe(true);
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
it("should return false - number", function() {
|
|
40
|
-
var values = [
|
|
41
|
-
152,
|
|
42
|
-
513,
|
|
43
|
-
2354
|
|
44
|
-
];
|
|
45
|
-
values.forEach(function(value) {
|
|
46
|
-
expect(isBytesLike(value)).toBe(false);
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
it("should return false - non-hex string", function() {
|
|
50
|
-
var values = [
|
|
51
|
-
"essential-eth",
|
|
52
|
-
"ethers.js",
|
|
53
|
-
"ethereum"
|
|
54
|
-
];
|
|
55
|
-
values.forEach(function(value) {
|
|
56
|
-
expect(isBytesLike(value)).toBe(false);
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
it("should return false - boolean", function() {
|
|
60
|
-
var values = [
|
|
61
|
-
false,
|
|
62
|
-
true
|
|
63
|
-
];
|
|
64
|
-
values.forEach(function(value) {
|
|
65
|
-
expect(isBytesLike(value)).toBe(false);
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
});
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { isBytes, isBytesLike } from "../../..";
|
|
2
|
-
describe("isBytesLike", function() {
|
|
3
|
-
it("matches expected", function() {
|
|
4
|
-
var testCases = [
|
|
5
|
-
{
|
|
6
|
-
value: [
|
|
7
|
-
"1",
|
|
8
|
-
"2",
|
|
9
|
-
"3"
|
|
10
|
-
],
|
|
11
|
-
isBytesLike: false,
|
|
12
|
-
isBytes: false
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
value: [
|
|
16
|
-
1,
|
|
17
|
-
2,
|
|
18
|
-
3
|
|
19
|
-
],
|
|
20
|
-
isBytesLike: true,
|
|
21
|
-
isBytes: true
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
value: "0x123",
|
|
25
|
-
isBytesLike: false,
|
|
26
|
-
isBytes: false
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
value: 123,
|
|
30
|
-
isBytesLike: false,
|
|
31
|
-
isBytes: false
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
value: 0x123,
|
|
35
|
-
isBytesLike: false,
|
|
36
|
-
isBytes: false
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
value: "bad",
|
|
40
|
-
isBytesLike: false,
|
|
41
|
-
isBytes: false
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
value: false,
|
|
45
|
-
isBytesLike: false,
|
|
46
|
-
isBytes: false
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
value: {
|
|
50
|
-
test: "bad"
|
|
51
|
-
},
|
|
52
|
-
isBytesLike: false,
|
|
53
|
-
isBytes: false
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
value: null,
|
|
57
|
-
isBytesLike: false,
|
|
58
|
-
isBytes: false
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
value: new Uint8Array(),
|
|
62
|
-
isBytesLike: true,
|
|
63
|
-
isBytes: true
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
value: new Uint8Array(1),
|
|
67
|
-
isBytesLike: true,
|
|
68
|
-
isBytes: true
|
|
69
|
-
}
|
|
70
|
-
];
|
|
71
|
-
testCases.forEach(function(testCase) {
|
|
72
|
-
expect(isBytesLike(testCase.value)).toBe(testCase.isBytesLike);
|
|
73
|
-
expect(isBytes(testCase.value)).toBe(testCase.isBytes);
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
});
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { isHexString } from "../../bytes";
|
|
2
|
-
describe("utils.isHexString", function() {
|
|
3
|
-
it("should return true - hex string", function() {
|
|
4
|
-
var values = [
|
|
5
|
-
"0x9347",
|
|
6
|
-
"0x185754",
|
|
7
|
-
"0x00005823"
|
|
8
|
-
];
|
|
9
|
-
values.forEach(function(value) {
|
|
10
|
-
expect(isHexString(value)).toBe(true);
|
|
11
|
-
});
|
|
12
|
-
});
|
|
13
|
-
it("should match expected result- hex string of specific length", function() {
|
|
14
|
-
var testCases = [
|
|
15
|
-
{
|
|
16
|
-
value: [
|
|
17
|
-
"0x9347",
|
|
18
|
-
2
|
|
19
|
-
],
|
|
20
|
-
expected: true
|
|
21
|
-
},
|
|
22
|
-
// False because '0x185754' is 3 bytes long, not 5.
|
|
23
|
-
{
|
|
24
|
-
value: [
|
|
25
|
-
"0x185754",
|
|
26
|
-
5
|
|
27
|
-
],
|
|
28
|
-
expected: false
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
value: [
|
|
32
|
-
"0x00005823",
|
|
33
|
-
4
|
|
34
|
-
],
|
|
35
|
-
expected: true
|
|
36
|
-
}
|
|
37
|
-
];
|
|
38
|
-
testCases.forEach(function(testCase) {
|
|
39
|
-
expect(isHexString(testCase.value[0], testCase.value[1])).toBe(testCase.expected);
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
it("should return false - UInt8Array", function() {
|
|
43
|
-
var values = [
|
|
44
|
-
[
|
|
45
|
-
9,
|
|
46
|
-
58,
|
|
47
|
-
29,
|
|
48
|
-
24
|
|
49
|
-
],
|
|
50
|
-
[
|
|
51
|
-
185,
|
|
52
|
-
203
|
|
53
|
-
],
|
|
54
|
-
[
|
|
55
|
-
239,
|
|
56
|
-
30,
|
|
57
|
-
49,
|
|
58
|
-
41,
|
|
59
|
-
5,
|
|
60
|
-
10,
|
|
61
|
-
42
|
|
62
|
-
]
|
|
63
|
-
];
|
|
64
|
-
values.forEach(function(value) {
|
|
65
|
-
expect(isHexString(value)).toBe(false);
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
it("should return false - number", function() {
|
|
69
|
-
var values = [
|
|
70
|
-
152,
|
|
71
|
-
513,
|
|
72
|
-
2354
|
|
73
|
-
];
|
|
74
|
-
values.forEach(function(value) {
|
|
75
|
-
expect(isHexString(value)).toBe(false);
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
it("should return false - non-hex string", function() {
|
|
79
|
-
var values = [
|
|
80
|
-
"essential-eth",
|
|
81
|
-
"ethers.js",
|
|
82
|
-
"\uD83D\uDC4B firek.eth was here hehe"
|
|
83
|
-
];
|
|
84
|
-
values.forEach(function(value) {
|
|
85
|
-
expect(isHexString(value)).toBe(false);
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
it("should return false - boolean", function() {
|
|
89
|
-
var values = [
|
|
90
|
-
false,
|
|
91
|
-
true
|
|
92
|
-
];
|
|
93
|
-
values.forEach(function(value) {
|
|
94
|
-
expect(isHexString(value)).toBe(false);
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
});
|