essential-eth 0.8.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.
- package/dist/cjs/classes/Contract.js +38 -34
- package/dist/cjs/classes/test/Contract/crv.test.js +146 -339
- package/dist/cjs/classes/test/Contract/ens-abi.d.ts +1 -1
- package/dist/cjs/classes/test/Contract/ens.test.js +9 -66
- package/dist/cjs/classes/test/Contract/fei.test.js +11 -11
- package/dist/cjs/classes/test/Contract/foo-abi.d.ts +1 -1
- package/dist/cjs/classes/test/Contract/uni.test.js +66 -164
- package/dist/cjs/classes/utils/clean-block.js +4 -4
- package/dist/cjs/classes/utils/clean-log.js +4 -4
- package/dist/cjs/classes/utils/clean-transaction-receipt.js +4 -4
- package/dist/cjs/classes/utils/clean-transaction.js +4 -4
- package/dist/cjs/classes/utils/encode-decode-transaction.js +10 -10
- package/dist/cjs/classes/utils/fetchers.d.ts +8 -2
- package/dist/cjs/classes/utils/fetchers.js +20 -12
- package/dist/cjs/classes/utils/prepare-transaction.js +4 -4
- package/dist/cjs/index.d.ts +21 -21
- package/dist/cjs/index.js +21 -21
- package/dist/cjs/index.umd.js +1 -1
- package/dist/cjs/index.umd.js.map +1 -1
- package/dist/cjs/logger/logger.js +79 -41
- package/dist/cjs/logger/package-version.d.ts +1 -1
- package/dist/cjs/logger/package-version.js +1 -1
- package/dist/cjs/providers/AlchemyProvider.d.ts +4 -0
- package/dist/cjs/providers/AlchemyProvider.js +84 -0
- package/dist/cjs/providers/BaseProvider.js +471 -404
- package/dist/cjs/providers/FallthroughProvider.js +74 -38
- package/dist/cjs/providers/JsonRpcProvider.js +52 -31
- package/dist/cjs/providers/test/fallthrough-provider/get-gas-price.test.js +9 -9
- package/dist/cjs/providers/test/get-transaction-count.test.js +54 -91
- package/dist/cjs/providers/test/json-rpc-provider/call.test.js +87 -148
- package/dist/cjs/providers/test/json-rpc-provider/estimate-gas.test.js +45 -116
- package/dist/cjs/providers/test/json-rpc-provider/get-balance.test.js +36 -74
- package/dist/cjs/providers/test/json-rpc-provider/get-block-number.test.js +27 -94
- package/dist/cjs/providers/test/json-rpc-provider/get-block.test.js +191 -278
- package/dist/cjs/providers/test/json-rpc-provider/get-code.test.js +106 -135
- package/dist/cjs/providers/test/json-rpc-provider/get-fee-data.test.js +48 -73
- package/dist/cjs/providers/test/json-rpc-provider/get-gas-price.test.js +29 -64
- package/dist/cjs/providers/test/json-rpc-provider/get-logs/get-logs.test.js +219 -0
- package/dist/cjs/providers/test/json-rpc-provider/get-logs/mocks.d.ts +14 -0
- package/dist/cjs/providers/test/json-rpc-provider/get-logs/mocks.js +149 -0
- package/dist/cjs/providers/test/json-rpc-provider/get-network.test.js +37 -79
- package/dist/cjs/providers/test/json-rpc-provider/get-transaction-receipt.test.js +136 -157
- package/dist/cjs/providers/test/json-rpc-provider/get-transaction.test.js +121 -162
- package/dist/cjs/providers/test/mock-of.d.ts +2 -0
- package/dist/cjs/providers/test/mock-of.js +9 -0
- package/dist/cjs/providers/test/rpc-urls.d.ts +1 -0
- package/dist/cjs/providers/test/rpc-urls.js +12 -6
- package/dist/cjs/providers/test/test-alchemy-provider.test.js +151 -0
- package/dist/cjs/providers/utils/chains-info.d.ts +5 -448
- package/dist/cjs/providers/utils/chains-info.js +13 -1344
- package/dist/cjs/shared/tiny-big/helpers.js +18 -18
- package/dist/cjs/shared/tiny-big/tiny-big.js +96 -56
- package/dist/cjs/shared/tiny-big/tiny-big.test.js +2 -2
- package/dist/cjs/shared/validate-type.d.ts +1 -1
- package/dist/cjs/shared/validate-type.js +4 -4
- package/dist/cjs/types/Block.types.d.ts +3 -3
- package/dist/cjs/types/Contract.types.d.ts +4 -4
- package/dist/cjs/types/Transaction.types.d.ts +5 -5
- package/dist/cjs/utils/bytes.d.ts +4 -4
- package/dist/cjs/utils/bytes.js +3 -3
- package/dist/cjs/utils/tests/bytes/arrayify.test.js +48 -24
- package/dist/cjs/utils/tests/bytes/concat.test.js +5 -3
- package/dist/cjs/utils/tests/bytes/hex-concat.test.js +15 -13
- package/dist/cjs/utils/tests/bytes/hex-data-length.test.js +49 -32
- package/dist/cjs/utils/tests/bytes/hex-data-slice.test.js +15 -16
- package/dist/cjs/utils/tests/bytes/hex-strip-zeros.test.js +57 -40
- package/dist/cjs/utils/tests/bytes/hex-value.test.js +118 -62
- package/dist/cjs/utils/tests/bytes/hex-zero-pad.test.js +71 -33
- package/dist/cjs/utils/tests/bytes/hexlify.test.js +45 -29
- package/dist/cjs/utils/tests/bytes/is-bytes-like.test.js +10 -11
- package/dist/cjs/utils/tests/bytes/is-bytes.test.js +70 -27
- package/dist/cjs/utils/tests/bytes/is-hex-string.test.js +37 -28
- package/dist/cjs/utils/tests/bytes/strip-zeros.test.js +94 -45
- package/dist/cjs/utils/tests/bytes/zero-pad.test.js +98 -34
- package/dist/cjs/utils/tests/compute-address.test.js +42 -20
- package/dist/cjs/utils/tests/compute-public-key.test.js +20 -9
- package/dist/cjs/utils/tests/ether-to-wei.test.js +5 -13
- package/dist/cjs/utils/tests/hash-message.test.js +26 -15
- package/dist/cjs/utils/tests/is-address.test.js +2 -9
- package/dist/cjs/utils/tests/keccak256.test.js +36 -12
- package/dist/cjs/utils/tests/solidity-keccak256.test.js +43 -42
- package/dist/cjs/utils/tests/split-signature.test.js +29 -8
- package/dist/cjs/utils/tests/to-checksum-address.test.js +1 -4
- package/dist/cjs/utils/tests/to-utf8-bytes.test.js +28 -8
- package/dist/cjs/utils/tests/wei-to-ether.test.js +10 -20
- package/dist/esm/classes/test/Contract/ens-abi.d.ts +1 -1
- package/dist/esm/classes/test/Contract/foo-abi.d.ts +1 -1
- package/dist/esm/classes/utils/fetchers.d.ts +8 -2
- package/dist/esm/classes/utils/fetchers.js +6 -3
- package/dist/esm/index.d.ts +21 -21
- package/dist/esm/index.js +16 -16
- package/dist/esm/logger/package-version.d.ts +1 -1
- package/dist/esm/logger/package-version.js +1 -1
- package/dist/esm/providers/AlchemyProvider.d.ts +4 -0
- package/dist/esm/providers/AlchemyProvider.js +7 -0
- package/dist/esm/providers/FallthroughProvider.js +15 -7
- package/dist/esm/providers/test/json-rpc-provider/get-logs/mocks.d.ts +14 -0
- package/dist/esm/providers/test/json-rpc-provider/get-logs/mocks.js +142 -0
- package/dist/esm/providers/test/mock-of.d.ts +2 -0
- package/dist/esm/providers/test/mock-of.js +1 -0
- package/dist/esm/providers/test/rpc-urls.d.ts +1 -0
- package/dist/esm/providers/test/rpc-urls.js +14 -6
- package/dist/esm/providers/utils/chains-info.d.ts +5 -448
- package/dist/esm/providers/utils/chains-info.js +13 -1344
- package/dist/esm/shared/validate-type.d.ts +1 -1
- package/dist/esm/types/Block.types.d.ts +3 -3
- package/dist/esm/types/Contract.types.d.ts +4 -4
- package/dist/esm/types/Transaction.types.d.ts +5 -5
- package/dist/esm/utils/bytes.d.ts +4 -4
- package/package.json +23 -51
- package/readme.md +16 -38
- 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
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
11
|
-
expect(hexDataLength(value)).
|
|
18
|
+
testCases.forEach(function(testCase) {
|
|
19
|
+
expect(hexDataLength(testCase.value)).toStrictEqual(testCase.expected);
|
|
12
20
|
});
|
|
13
21
|
});
|
|
14
|
-
it("should match
|
|
15
|
-
var
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
37
|
-
expect(hexDataLength(value)).
|
|
53
|
+
testCases.forEach(function(testCase) {
|
|
54
|
+
expect(hexDataLength(testCase.value)).toStrictEqual(testCase.expected);
|
|
38
55
|
});
|
|
39
56
|
});
|
|
40
|
-
it("should return null -
|
|
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("
|
|
5
|
-
var
|
|
3
|
+
it("should match expected slice - hexadecimal strings", function() {
|
|
4
|
+
var hexValues = [
|
|
6
5
|
"0x123456"
|
|
7
6
|
];
|
|
8
|
-
|
|
9
|
-
expect(hexDataSlice(
|
|
7
|
+
hexValues.forEach(function(hexValue) {
|
|
8
|
+
expect(hexDataSlice(hexValue, 0, 2)).toBe("0x1234");
|
|
10
9
|
});
|
|
11
10
|
});
|
|
12
|
-
it("
|
|
13
|
-
var
|
|
11
|
+
it("should match expected slice - hexadecimal numbers", function() {
|
|
12
|
+
var hexValues = [
|
|
14
13
|
0x1234567891011
|
|
15
14
|
];
|
|
16
|
-
|
|
17
|
-
expect(hexDataSlice(
|
|
18
|
-
expect(hexDataSlice(
|
|
19
|
-
expect(hexDataSlice(
|
|
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("
|
|
23
|
-
var
|
|
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
|
-
|
|
38
|
-
expect(hexDataSlice(
|
|
36
|
+
decimalArrays.forEach(function(decimalArray) {
|
|
37
|
+
expect(hexDataSlice(decimalArray, 1, 2)).toBe("0x01");
|
|
39
38
|
});
|
|
40
39
|
});
|
|
41
|
-
it("should throw error - invalid
|
|
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
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
11
|
-
expect(hexStripZeros(value)).toBe(
|
|
18
|
+
testCases.forEach(function(testCase) {
|
|
19
|
+
expect(hexStripZeros(testCase.value)).toBe(testCase.expected);
|
|
12
20
|
});
|
|
13
21
|
});
|
|
14
|
-
it("should
|
|
15
|
-
var
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
|
|
45
|
-
expect(hexStripZeros(value)).toBe(
|
|
61
|
+
testCases.forEach(function(testCase) {
|
|
62
|
+
expect(hexStripZeros(testCase.value)).toBe(testCase.expected);
|
|
46
63
|
});
|
|
47
64
|
});
|
|
48
|
-
it("should throw error - invalid hex
|
|
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
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
12
|
-
expect(hexValue(value)).
|
|
19
|
+
testCases.forEach(function(testCase) {
|
|
20
|
+
expect(hexValue(testCase.value)).toStrictEqual(testCase.expected);
|
|
13
21
|
});
|
|
14
22
|
});
|
|
15
|
-
it("should
|
|
16
|
-
var
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
37
|
-
expect(hexValue(value)).
|
|
53
|
+
testCases.forEach(function(testCase) {
|
|
54
|
+
expect(hexValue(testCase.value)).toStrictEqual(testCase.expected);
|
|
38
55
|
});
|
|
39
56
|
});
|
|
40
|
-
it("should
|
|
41
|
-
var
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
|
|
47
|
-
expect(hexValue(value)).
|
|
72
|
+
testCases.forEach(function(testCase) {
|
|
73
|
+
expect(hexValue(testCase.value)).toStrictEqual(testCase.expected);
|
|
48
74
|
});
|
|
49
75
|
});
|
|
50
|
-
it("should
|
|
51
|
-
var
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
57
|
-
expect(hexValue(value)).
|
|
91
|
+
testCases.forEach(function(testCase) {
|
|
92
|
+
expect(hexValue(testCase.value)).toStrictEqual(testCase.expected);
|
|
58
93
|
});
|
|
59
94
|
});
|
|
60
|
-
it("should
|
|
61
|
-
var
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
|
|
67
|
-
expect(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
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
0,
|
|
78
|
-
|
|
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
|
-
|
|
82
|
-
expect(hexValue(value)).
|
|
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("
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
10
|
-
expect(hexZeroPad(
|
|
14
|
+
testCases.forEach(function(testCase) {
|
|
15
|
+
expect(hexZeroPad(testCase.value, 20)).toStrictEqual(testCase.expected);
|
|
11
16
|
});
|
|
12
17
|
});
|
|
13
|
-
it("
|
|
14
|
-
var
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
23
|
-
expect(hexZeroPad(
|
|
30
|
+
testCases.forEach(function(testCase) {
|
|
31
|
+
expect(hexZeroPad(testCase.value, 15)).toStrictEqual(testCase.expected);
|
|
24
32
|
});
|
|
25
33
|
});
|
|
26
|
-
it("should
|
|
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
|
|
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
|
|
46
|
-
var
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
-
|
|
59
|
-
expect(hexZeroPad(value,
|
|
96
|
+
testCases.forEach(function(testCase) {
|
|
97
|
+
expect(hexZeroPad(testCase.value, 15)).toStrictEqual(testCase.expected);
|
|
60
98
|
});
|
|
61
99
|
});
|
|
62
100
|
});
|