essential-eth 0.6.2 → 0.8.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.d.ts +2 -0
- package/dist/cjs/providers/BaseProvider.js +883 -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-fee-data.test.js +212 -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/FeeData.types.d.ts +7 -0
- package/dist/cjs/types/FeeData.types.js +1 -0
- 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/providers/BaseProvider.d.ts +2 -0
- package/dist/esm/providers/BaseProvider.js +15 -0
- package/dist/esm/types/FeeData.types.d.ts +7 -0
- package/dist/esm/types/FeeData.types.js +1 -0
- 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 +10 -8
- package/readme.md +63 -3
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import * as ethers from "ethers";
|
|
2
|
+
import { arrayify, tinyBig } from "../../..";
|
|
3
|
+
describe("arrayify", function() {
|
|
4
|
+
it("matches ethers", function() {
|
|
5
|
+
var inputs = [
|
|
6
|
+
0,
|
|
7
|
+
1,
|
|
8
|
+
"0x1234",
|
|
9
|
+
new Uint8Array(2),
|
|
10
|
+
tinyBig(17)
|
|
11
|
+
];
|
|
12
|
+
inputs.forEach(function(input) {
|
|
13
|
+
// console.log({ input, arr: arrayify(input as any) });
|
|
14
|
+
expect(arrayify(input)).toStrictEqual(ethers.utils.arrayify(input));
|
|
15
|
+
});
|
|
16
|
+
expect(arrayify("12", {
|
|
17
|
+
allowMissingPrefix: true
|
|
18
|
+
})).toStrictEqual(ethers.utils.arrayify("12", {
|
|
19
|
+
allowMissingPrefix: true
|
|
20
|
+
}));
|
|
21
|
+
expect(arrayify("0x1", {
|
|
22
|
+
hexPad: "left"
|
|
23
|
+
})).toStrictEqual(ethers.utils.arrayify("0x1", {
|
|
24
|
+
hexPad: "left"
|
|
25
|
+
}));
|
|
26
|
+
expect(arrayify("0x1", {
|
|
27
|
+
hexPad: "right"
|
|
28
|
+
})).toStrictEqual(ethers.utils.arrayify("0x1", {
|
|
29
|
+
hexPad: "right"
|
|
30
|
+
}));
|
|
31
|
+
// hex data is odd length
|
|
32
|
+
expect(function() {
|
|
33
|
+
return arrayify(tinyBig(15));
|
|
34
|
+
}).toThrow();
|
|
35
|
+
// invalid arrayify value
|
|
36
|
+
expect(function() {
|
|
37
|
+
return arrayify(false);
|
|
38
|
+
}).toThrow();
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as ethers from "ethers";
|
|
2
|
+
import { concat } from "../../..";
|
|
3
|
+
describe("concat", function() {
|
|
4
|
+
it("matches ethers", function() {
|
|
5
|
+
var inputs = [
|
|
6
|
+
[
|
|
7
|
+
0,
|
|
8
|
+
1
|
|
9
|
+
]
|
|
10
|
+
];
|
|
11
|
+
inputs.forEach(function(input) {
|
|
12
|
+
expect(concat(input)).toStrictEqual(ethers.utils.concat(input));
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
});
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { utils as ethers } from "ethers";
|
|
2
|
+
import { hexConcat } from "../../bytes";
|
|
3
|
+
describe("utils.hexConcat", function() {
|
|
4
|
+
it("should match ethers.js - hex values", function() {
|
|
5
|
+
var values = [
|
|
6
|
+
"0x2048",
|
|
7
|
+
"0x6917",
|
|
8
|
+
"0x85616379"
|
|
9
|
+
];
|
|
10
|
+
expect(hexConcat(values)).toBe(ethers.hexConcat(values));
|
|
11
|
+
});
|
|
12
|
+
it("should match ethers.js - UInt8Array values", function() {
|
|
13
|
+
var values = [
|
|
14
|
+
[
|
|
15
|
+
5,
|
|
16
|
+
10,
|
|
17
|
+
247,
|
|
18
|
+
22
|
|
19
|
+
],
|
|
20
|
+
[
|
|
21
|
+
50,
|
|
22
|
+
255,
|
|
23
|
+
3
|
|
24
|
+
],
|
|
25
|
+
[
|
|
26
|
+
59,
|
|
27
|
+
36,
|
|
28
|
+
18,
|
|
29
|
+
46,
|
|
30
|
+
198,
|
|
31
|
+
234
|
|
32
|
+
]
|
|
33
|
+
];
|
|
34
|
+
expect(hexConcat(values)).toBe(ethers.hexConcat(values));
|
|
35
|
+
});
|
|
36
|
+
it("should match ethers.js - hex & UInt8Array values", function() {
|
|
37
|
+
var values = [
|
|
38
|
+
"0x2048",
|
|
39
|
+
[
|
|
40
|
+
5,
|
|
41
|
+
10,
|
|
42
|
+
247,
|
|
43
|
+
22
|
|
44
|
+
],
|
|
45
|
+
"0x6917",
|
|
46
|
+
[
|
|
47
|
+
50,
|
|
48
|
+
255,
|
|
49
|
+
3
|
|
50
|
+
],
|
|
51
|
+
"0x85616379",
|
|
52
|
+
[
|
|
53
|
+
59,
|
|
54
|
+
36,
|
|
55
|
+
18,
|
|
56
|
+
46,
|
|
57
|
+
198,
|
|
58
|
+
234
|
|
59
|
+
]
|
|
60
|
+
];
|
|
61
|
+
expect(hexConcat(values)).toBe(ethers.hexConcat(values));
|
|
62
|
+
});
|
|
63
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { utils as ethers } from "ethers";
|
|
2
|
+
import { hexDataLength } from "../../bytes";
|
|
3
|
+
describe("utils.hexDataLength", function() {
|
|
4
|
+
it("should match ethers.js - hex values", function() {
|
|
5
|
+
var values = [
|
|
6
|
+
"0x9347",
|
|
7
|
+
"0x185754",
|
|
8
|
+
"0x00005823"
|
|
9
|
+
];
|
|
10
|
+
values.forEach(function(value) {
|
|
11
|
+
expect(hexDataLength(value)).toBe(ethers.hexDataLength(value));
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
it("should match ethers.js - UInt8Array values", function() {
|
|
15
|
+
var values = [
|
|
16
|
+
[
|
|
17
|
+
9,
|
|
18
|
+
58,
|
|
19
|
+
29,
|
|
20
|
+
24
|
|
21
|
+
],
|
|
22
|
+
[
|
|
23
|
+
185,
|
|
24
|
+
203
|
|
25
|
+
],
|
|
26
|
+
[
|
|
27
|
+
239,
|
|
28
|
+
30,
|
|
29
|
+
49,
|
|
30
|
+
41,
|
|
31
|
+
5,
|
|
32
|
+
10,
|
|
33
|
+
42
|
|
34
|
+
]
|
|
35
|
+
];
|
|
36
|
+
values.forEach(function(value) {
|
|
37
|
+
expect(hexDataLength(value)).toBe(ethers.hexDataLength(value));
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
it("should return null - not hex value or not divisible by 2", function() {
|
|
41
|
+
var values = [
|
|
42
|
+
"0x383",
|
|
43
|
+
"non-hex string"
|
|
44
|
+
];
|
|
45
|
+
values.forEach(function(value) {
|
|
46
|
+
expect(hexDataLength(value)).toBeNull();
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { utils as ethers } from "ethers";
|
|
2
|
+
import { hexDataSlice } from "../../bytes";
|
|
3
|
+
describe("utils.hexDataSlice", function() {
|
|
4
|
+
it("numbers - matches ethers strings", function() {
|
|
5
|
+
var decimalValues = [
|
|
6
|
+
"0x123456"
|
|
7
|
+
];
|
|
8
|
+
decimalValues.forEach(function(decimalValue) {
|
|
9
|
+
expect(hexDataSlice(decimalValue, 0, 2)).toStrictEqual(ethers.hexDataSlice(decimalValue, 0, 2));
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
it("numbers - matches ethers hex numbers", function() {
|
|
13
|
+
var decimalValues = [
|
|
14
|
+
0x1234567891011
|
|
15
|
+
];
|
|
16
|
+
decimalValues.forEach(function(decimalValue) {
|
|
17
|
+
expect(hexDataSlice(decimalValue, 3)).toStrictEqual(ethers.hexDataSlice(decimalValue, 3));
|
|
18
|
+
expect(hexDataSlice(decimalValue, 2, 4)).toStrictEqual(ethers.hexDataSlice(decimalValue, 2, 4));
|
|
19
|
+
expect(hexDataSlice(decimalValue, 100)).toStrictEqual(ethers.hexDataSlice(decimalValue, 100));
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
it("numbers - matches ethers decimals", function() {
|
|
23
|
+
var decimalValues = [
|
|
24
|
+
[
|
|
25
|
+
0,
|
|
26
|
+
1,
|
|
27
|
+
2,
|
|
28
|
+
3,
|
|
29
|
+
4,
|
|
30
|
+
5,
|
|
31
|
+
6,
|
|
32
|
+
7,
|
|
33
|
+
8,
|
|
34
|
+
9
|
|
35
|
+
]
|
|
36
|
+
];
|
|
37
|
+
decimalValues.forEach(function(decimalValue) {
|
|
38
|
+
expect(hexDataSlice(decimalValue, 1, 2)).toStrictEqual(ethers.hexDataSlice(decimalValue, 1, 2));
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
it("should throw error - invalid hexData", function() {
|
|
42
|
+
var values = [
|
|
43
|
+
"non-hex string",
|
|
44
|
+
"0x938"
|
|
45
|
+
];
|
|
46
|
+
values.forEach(function(value) {
|
|
47
|
+
expect(function() {
|
|
48
|
+
return hexDataSlice(value, 1, 3);
|
|
49
|
+
}).toThrow("invalid hexData");
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { utils as ethers } from "ethers";
|
|
2
|
+
import { hexStripZeros } from "../../bytes";
|
|
3
|
+
describe("utils.hexStripZeros", function() {
|
|
4
|
+
it("should match ethers.js - hex values", function() {
|
|
5
|
+
var values = [
|
|
6
|
+
"0x00009347",
|
|
7
|
+
"0x00185754",
|
|
8
|
+
"0x00000000005823"
|
|
9
|
+
];
|
|
10
|
+
values.forEach(function(value) {
|
|
11
|
+
expect(hexStripZeros(value)).toBe(ethers.hexStripZeros(value));
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
it("should match ethers.js - UInt8Array values", function() {
|
|
15
|
+
var values = [
|
|
16
|
+
[
|
|
17
|
+
0,
|
|
18
|
+
0,
|
|
19
|
+
0,
|
|
20
|
+
9,
|
|
21
|
+
58,
|
|
22
|
+
29,
|
|
23
|
+
24
|
|
24
|
+
],
|
|
25
|
+
[
|
|
26
|
+
0,
|
|
27
|
+
185,
|
|
28
|
+
203
|
|
29
|
+
],
|
|
30
|
+
[
|
|
31
|
+
0,
|
|
32
|
+
0,
|
|
33
|
+
0,
|
|
34
|
+
0,
|
|
35
|
+
239,
|
|
36
|
+
30,
|
|
37
|
+
49,
|
|
38
|
+
41,
|
|
39
|
+
5,
|
|
40
|
+
10,
|
|
41
|
+
42
|
|
42
|
+
]
|
|
43
|
+
];
|
|
44
|
+
values.forEach(function(value) {
|
|
45
|
+
expect(hexStripZeros(value)).toBe(ethers.hexStripZeros(value));
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
it("should throw error - invalid hex string", function() {
|
|
49
|
+
var values = [
|
|
50
|
+
"non-hex string"
|
|
51
|
+
];
|
|
52
|
+
values.forEach(function(value) {
|
|
53
|
+
expect(function() {
|
|
54
|
+
return hexStripZeros(value);
|
|
55
|
+
}).toThrow("invalid hex string");
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { utils as ethers } from "ethers";
|
|
2
|
+
import { hexValue } from "../../bytes";
|
|
3
|
+
import { tinyBig } from "./../../../shared/tiny-big/tiny-big";
|
|
4
|
+
describe("utils.hexValue", function() {
|
|
5
|
+
it("should match ethers.js - hex string", function() {
|
|
6
|
+
var values = [
|
|
7
|
+
"0x9347",
|
|
8
|
+
"0x185754",
|
|
9
|
+
"0x00005823"
|
|
10
|
+
];
|
|
11
|
+
values.forEach(function(value) {
|
|
12
|
+
expect(hexValue(value)).toBe(ethers.hexValue(value));
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
it("should match ethers.js - UInt8Array", function() {
|
|
16
|
+
var values = [
|
|
17
|
+
[
|
|
18
|
+
4,
|
|
19
|
+
50,
|
|
20
|
+
2
|
|
21
|
+
],
|
|
22
|
+
[
|
|
23
|
+
231,
|
|
24
|
+
49,
|
|
25
|
+
40,
|
|
26
|
+
70,
|
|
27
|
+
19
|
|
28
|
+
],
|
|
29
|
+
[
|
|
30
|
+
10,
|
|
31
|
+
68,
|
|
32
|
+
20,
|
|
33
|
+
98
|
|
34
|
+
]
|
|
35
|
+
];
|
|
36
|
+
values.forEach(function(value) {
|
|
37
|
+
expect(hexValue(value)).toBe(ethers.hexValue(value));
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
it("should match ethers.js - TinyBig (hexable)", function() {
|
|
41
|
+
var values = [
|
|
42
|
+
tinyBig("29389"),
|
|
43
|
+
tinyBig(2834),
|
|
44
|
+
tinyBig(402)
|
|
45
|
+
];
|
|
46
|
+
values.forEach(function(value) {
|
|
47
|
+
expect(hexValue(value)).toBe(ethers.hexValue(value));
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
it("should match ethers.js - number", function() {
|
|
51
|
+
var values = [
|
|
52
|
+
624,
|
|
53
|
+
457,
|
|
54
|
+
23451
|
|
55
|
+
];
|
|
56
|
+
values.forEach(function(value) {
|
|
57
|
+
expect(hexValue(value)).toBe(ethers.hexValue(value));
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
it("should match ethers.js - BigInt", function() {
|
|
61
|
+
var values = [
|
|
62
|
+
BigInt(204),
|
|
63
|
+
BigInt("23491"),
|
|
64
|
+
BigInt(4183459235723491)
|
|
65
|
+
];
|
|
66
|
+
values.forEach(function(value) {
|
|
67
|
+
expect(hexValue(value)).toBe(ethers.hexValue(value));
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
it("should return 0x0 - only zero data given", function() {
|
|
71
|
+
var values = [
|
|
72
|
+
BigInt(0),
|
|
73
|
+
0,
|
|
74
|
+
"0x0000",
|
|
75
|
+
[
|
|
76
|
+
0,
|
|
77
|
+
0,
|
|
78
|
+
0
|
|
79
|
+
]
|
|
80
|
+
];
|
|
81
|
+
values.forEach(function(value) {
|
|
82
|
+
expect(hexValue(value)).toBe("0x0");
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import * as ethers from "ethers";
|
|
2
|
+
import { hexZeroPad } from "../../../";
|
|
3
|
+
describe("hexZeroPad", function() {
|
|
4
|
+
it("numbers - matches ethers", function() {
|
|
5
|
+
var decimalValues = [
|
|
6
|
+
123,
|
|
7
|
+
0
|
|
8
|
+
];
|
|
9
|
+
decimalValues.forEach(function(decimalValue) {
|
|
10
|
+
expect(hexZeroPad(decimalValue, 30)).toStrictEqual(ethers.utils.hexZeroPad(decimalValue, 30));
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
it("arrays of numbers - matches ethers", function() {
|
|
14
|
+
var decimalValues = [
|
|
15
|
+
[
|
|
16
|
+
1,
|
|
17
|
+
2,
|
|
18
|
+
3,
|
|
19
|
+
4
|
|
20
|
+
]
|
|
21
|
+
];
|
|
22
|
+
decimalValues.forEach(function(decimalValue) {
|
|
23
|
+
expect(hexZeroPad(decimalValue, 30)).toStrictEqual(ethers.utils.hexZeroPad(decimalValue, 30));
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
it("should reject strings passed in which are not hex strings", function() {
|
|
27
|
+
var value = "52908";
|
|
28
|
+
expect(function() {
|
|
29
|
+
hexZeroPad(value, 23);
|
|
30
|
+
}).toThrow();
|
|
31
|
+
});
|
|
32
|
+
it("should throw error when value is already longer than desired length", function() {
|
|
33
|
+
var hexValues = [
|
|
34
|
+
0x123456,
|
|
35
|
+
"0x5aAebAd",
|
|
36
|
+
"0xfB691",
|
|
37
|
+
"0xD1220ab"
|
|
38
|
+
];
|
|
39
|
+
hexValues.forEach(function(hexValue) {
|
|
40
|
+
expect(function() {
|
|
41
|
+
return hexZeroPad(hexValue, 2);
|
|
42
|
+
}).toThrow();
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
it("should match ethers.js when padding can be applied", function() {
|
|
46
|
+
var values = [
|
|
47
|
+
10,
|
|
48
|
+
"0x5290",
|
|
49
|
+
"0x8617E3",
|
|
50
|
+
"0xde709f210",
|
|
51
|
+
"0x27b",
|
|
52
|
+
0x0,
|
|
53
|
+
0x5aaeb605,
|
|
54
|
+
"0xfB6916095ca1df",
|
|
55
|
+
"0xdbF03B407c01E7cD3CBea99509d93",
|
|
56
|
+
0xd1220a0cf4
|
|
57
|
+
];
|
|
58
|
+
values.forEach(function(value) {
|
|
59
|
+
expect(hexZeroPad(value, 30)).toStrictEqual(ethers.utils.hexZeroPad(value, 30));
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { utils as ethers } from "ethers";
|
|
2
|
+
import { hexlify } from "../../bytes";
|
|
3
|
+
describe("utils.hexlify", function() {
|
|
4
|
+
it("numbers - matches ethers strings", function() {
|
|
5
|
+
var decimalValues = [
|
|
6
|
+
0,
|
|
7
|
+
4,
|
|
8
|
+
5,
|
|
9
|
+
16,
|
|
10
|
+
BigInt(0),
|
|
11
|
+
BigInt(16)
|
|
12
|
+
];
|
|
13
|
+
decimalValues.forEach(function(decimalValue) {
|
|
14
|
+
expect(hexlify(decimalValue)).toBe(ethers.hexlify(decimalValue));
|
|
15
|
+
});
|
|
16
|
+
var opts = {
|
|
17
|
+
allowMissingPrefix: true
|
|
18
|
+
};
|
|
19
|
+
expect(hexlify("22", opts)).toBe(ethers.hexlify("22", opts));
|
|
20
|
+
});
|
|
21
|
+
it("should match ethers.js - hexPad options", function() {
|
|
22
|
+
var values = [
|
|
23
|
+
[
|
|
24
|
+
"0x3342e95",
|
|
25
|
+
{
|
|
26
|
+
hexPad: "left"
|
|
27
|
+
}
|
|
28
|
+
],
|
|
29
|
+
[
|
|
30
|
+
"0x41c942c42",
|
|
31
|
+
{
|
|
32
|
+
hexPad: "right"
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
];
|
|
36
|
+
values.forEach(function(value) {
|
|
37
|
+
expect(hexlify(value[0], value[1])).toBe(ethers.hexlify(value[0], value[1]));
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
it("should throw error - hex data is odd-length", function() {
|
|
41
|
+
var values = [
|
|
42
|
+
"0x931",
|
|
43
|
+
"0x34414"
|
|
44
|
+
];
|
|
45
|
+
values.forEach(function(value) {
|
|
46
|
+
expect(function() {
|
|
47
|
+
return hexlify(value);
|
|
48
|
+
}).toThrow("hex data is odd-length");
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
it("should throw error - invalid hexlify value", function() {
|
|
52
|
+
var values = [
|
|
53
|
+
"non-hex string",
|
|
54
|
+
false
|
|
55
|
+
];
|
|
56
|
+
values.forEach(function(value) {
|
|
57
|
+
expect(function() {
|
|
58
|
+
return hexlify(value);
|
|
59
|
+
}).toThrow("invalid hexlify value");
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
});
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { utils as ethers } from "ethers";
|
|
2
|
+
import { isBytesLike } from "../../bytes";
|
|
3
|
+
describe("utils.isBytesLike", function() {
|
|
4
|
+
it("should match ethers.js - hex string", function() {
|
|
5
|
+
var values = [
|
|
6
|
+
"0x9347",
|
|
7
|
+
"0x185754",
|
|
8
|
+
"0x00005823"
|
|
9
|
+
];
|
|
10
|
+
values.forEach(function(value) {
|
|
11
|
+
expect(isBytesLike(value)).toBe(ethers.isBytesLike(value));
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
it("should match ethers.js - UInt8Array", function() {
|
|
15
|
+
var values = [
|
|
16
|
+
[
|
|
17
|
+
9,
|
|
18
|
+
58,
|
|
19
|
+
29,
|
|
20
|
+
24
|
|
21
|
+
],
|
|
22
|
+
[
|
|
23
|
+
185,
|
|
24
|
+
203
|
|
25
|
+
],
|
|
26
|
+
[
|
|
27
|
+
239,
|
|
28
|
+
30,
|
|
29
|
+
49,
|
|
30
|
+
41,
|
|
31
|
+
5,
|
|
32
|
+
10,
|
|
33
|
+
42
|
|
34
|
+
]
|
|
35
|
+
];
|
|
36
|
+
values.forEach(function(value) {
|
|
37
|
+
expect(isBytesLike(value)).toBe(ethers.isBytesLike(value));
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
it("should match ethers.js - number", function() {
|
|
41
|
+
var values = [
|
|
42
|
+
152,
|
|
43
|
+
513,
|
|
44
|
+
2354
|
|
45
|
+
];
|
|
46
|
+
values.forEach(function(value) {
|
|
47
|
+
expect(isBytesLike(value)).toBe(ethers.isBytesLike(value));
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
it("should match ethers.js - non-hex string", function() {
|
|
51
|
+
var values = [
|
|
52
|
+
"essential-eth",
|
|
53
|
+
"ethers.js",
|
|
54
|
+
"ethereum"
|
|
55
|
+
];
|
|
56
|
+
values.forEach(function(value) {
|
|
57
|
+
expect(isBytesLike(value)).toBe(ethers.isBytesLike(value));
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
it("should match ethers.js - boolean", function() {
|
|
61
|
+
var values = [
|
|
62
|
+
false,
|
|
63
|
+
true
|
|
64
|
+
];
|
|
65
|
+
values.forEach(function(value) {
|
|
66
|
+
expect(isBytesLike(value)).toBe(ethers.isBytesLike(value));
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import * as ethers from "ethers";
|
|
2
|
+
import { isBytes, isBytesLike } from "../../..";
|
|
3
|
+
describe("isBytesLike", function() {
|
|
4
|
+
it("matches ethers", function() {
|
|
5
|
+
var inputs = [
|
|
6
|
+
[
|
|
7
|
+
"1",
|
|
8
|
+
"2",
|
|
9
|
+
"3"
|
|
10
|
+
],
|
|
11
|
+
[
|
|
12
|
+
1,
|
|
13
|
+
2,
|
|
14
|
+
3
|
|
15
|
+
],
|
|
16
|
+
"0x123",
|
|
17
|
+
123,
|
|
18
|
+
0x123,
|
|
19
|
+
"bad",
|
|
20
|
+
false,
|
|
21
|
+
{
|
|
22
|
+
test: "bad"
|
|
23
|
+
},
|
|
24
|
+
null,
|
|
25
|
+
new Uint8Array(),
|
|
26
|
+
new Uint8Array(1)
|
|
27
|
+
];
|
|
28
|
+
inputs.forEach(function(input) {
|
|
29
|
+
expect(isBytesLike(input)).toBe(ethers.utils.isBytesLike(input));
|
|
30
|
+
expect(isBytes(input)).toBe(ethers.utils.isBytes(input));
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { utils as ethers } from "ethers";
|
|
2
|
+
import { isHexString } from "../../bytes";
|
|
3
|
+
describe("utils.isHexString", function() {
|
|
4
|
+
it("should match ethers.js - hex string", function() {
|
|
5
|
+
var values = [
|
|
6
|
+
"0x9347",
|
|
7
|
+
"0x185754",
|
|
8
|
+
"0x00005823"
|
|
9
|
+
];
|
|
10
|
+
values.forEach(function(value) {
|
|
11
|
+
expect(isHexString(value)).toBe(ethers.isHexString(value));
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
it("should match ethers.js - hex string of specific length", function() {
|
|
15
|
+
var values = [
|
|
16
|
+
[
|
|
17
|
+
"0x9347",
|
|
18
|
+
2
|
|
19
|
+
],
|
|
20
|
+
[
|
|
21
|
+
"0x185754",
|
|
22
|
+
5
|
|
23
|
+
],
|
|
24
|
+
[
|
|
25
|
+
"0x00005823",
|
|
26
|
+
4
|
|
27
|
+
]
|
|
28
|
+
];
|
|
29
|
+
values.forEach(function(value) {
|
|
30
|
+
expect(isHexString(value[0], value[1])).toBe(ethers.isHexString(value[0], value[1]));
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
it("should match ethers.js - UInt8Array", function() {
|
|
34
|
+
var values = [
|
|
35
|
+
[
|
|
36
|
+
9,
|
|
37
|
+
58,
|
|
38
|
+
29,
|
|
39
|
+
24
|
|
40
|
+
],
|
|
41
|
+
[
|
|
42
|
+
185,
|
|
43
|
+
203
|
|
44
|
+
],
|
|
45
|
+
[
|
|
46
|
+
239,
|
|
47
|
+
30,
|
|
48
|
+
49,
|
|
49
|
+
41,
|
|
50
|
+
5,
|
|
51
|
+
10,
|
|
52
|
+
42
|
|
53
|
+
]
|
|
54
|
+
];
|
|
55
|
+
values.forEach(function(value) {
|
|
56
|
+
expect(isHexString(value)).toBe(ethers.isHexString(value));
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
it("should match ethers.js - number", function() {
|
|
60
|
+
var values = [
|
|
61
|
+
152,
|
|
62
|
+
513,
|
|
63
|
+
2354
|
|
64
|
+
];
|
|
65
|
+
values.forEach(function(value) {
|
|
66
|
+
expect(isHexString(value)).toBe(ethers.isHexString(value));
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
it("should match ethers.js - non-hex string", function() {
|
|
70
|
+
var values = [
|
|
71
|
+
"essential-eth",
|
|
72
|
+
"ethers.js",
|
|
73
|
+
"ethereum"
|
|
74
|
+
];
|
|
75
|
+
values.forEach(function(value) {
|
|
76
|
+
expect(isHexString(value)).toBe(ethers.isHexString(value));
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
it("should match ethers.js - boolean", function() {
|
|
80
|
+
var values = [
|
|
81
|
+
false,
|
|
82
|
+
true
|
|
83
|
+
];
|
|
84
|
+
values.forEach(function(value) {
|
|
85
|
+
expect(isHexString(value)).toBe(ethers.isHexString(value));
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
});
|