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.
Files changed (112) hide show
  1. package/dist/cjs/classes/Contract.js +38 -34
  2. package/dist/cjs/classes/test/Contract/crv.test.js +146 -339
  3. package/dist/cjs/classes/test/Contract/ens-abi.d.ts +1 -1
  4. package/dist/cjs/classes/test/Contract/ens.test.js +9 -66
  5. package/dist/cjs/classes/test/Contract/fei.test.js +11 -11
  6. package/dist/cjs/classes/test/Contract/foo-abi.d.ts +1 -1
  7. package/dist/cjs/classes/test/Contract/uni.test.js +66 -164
  8. package/dist/cjs/classes/utils/clean-block.js +4 -4
  9. package/dist/cjs/classes/utils/clean-log.js +4 -4
  10. package/dist/cjs/classes/utils/clean-transaction-receipt.js +4 -4
  11. package/dist/cjs/classes/utils/clean-transaction.js +4 -4
  12. package/dist/cjs/classes/utils/encode-decode-transaction.js +10 -10
  13. package/dist/cjs/classes/utils/fetchers.d.ts +8 -2
  14. package/dist/cjs/classes/utils/fetchers.js +20 -12
  15. package/dist/cjs/classes/utils/prepare-transaction.js +4 -4
  16. package/dist/cjs/index.d.ts +21 -21
  17. package/dist/cjs/index.js +21 -21
  18. package/dist/cjs/index.umd.js +1 -1
  19. package/dist/cjs/index.umd.js.map +1 -1
  20. package/dist/cjs/logger/logger.js +79 -41
  21. package/dist/cjs/logger/package-version.d.ts +1 -1
  22. package/dist/cjs/logger/package-version.js +1 -1
  23. package/dist/cjs/providers/AlchemyProvider.d.ts +4 -0
  24. package/dist/cjs/providers/AlchemyProvider.js +84 -0
  25. package/dist/cjs/providers/BaseProvider.js +471 -404
  26. package/dist/cjs/providers/FallthroughProvider.js +74 -38
  27. package/dist/cjs/providers/JsonRpcProvider.js +52 -31
  28. package/dist/cjs/providers/test/fallthrough-provider/get-gas-price.test.js +9 -9
  29. package/dist/cjs/providers/test/get-transaction-count.test.js +54 -91
  30. package/dist/cjs/providers/test/json-rpc-provider/call.test.js +87 -148
  31. package/dist/cjs/providers/test/json-rpc-provider/estimate-gas.test.js +45 -116
  32. package/dist/cjs/providers/test/json-rpc-provider/get-balance.test.js +36 -74
  33. package/dist/cjs/providers/test/json-rpc-provider/get-block-number.test.js +27 -94
  34. package/dist/cjs/providers/test/json-rpc-provider/get-block.test.js +191 -278
  35. package/dist/cjs/providers/test/json-rpc-provider/get-code.test.js +106 -135
  36. package/dist/cjs/providers/test/json-rpc-provider/get-fee-data.test.js +48 -73
  37. package/dist/cjs/providers/test/json-rpc-provider/get-gas-price.test.js +29 -64
  38. package/dist/cjs/providers/test/json-rpc-provider/get-logs/get-logs.test.js +219 -0
  39. package/dist/cjs/providers/test/json-rpc-provider/get-logs/mocks.d.ts +14 -0
  40. package/dist/cjs/providers/test/json-rpc-provider/get-logs/mocks.js +149 -0
  41. package/dist/cjs/providers/test/json-rpc-provider/get-network.test.js +37 -79
  42. package/dist/cjs/providers/test/json-rpc-provider/get-transaction-receipt.test.js +136 -157
  43. package/dist/cjs/providers/test/json-rpc-provider/get-transaction.test.js +121 -162
  44. package/dist/cjs/providers/test/mock-of.d.ts +2 -0
  45. package/dist/cjs/providers/test/mock-of.js +9 -0
  46. package/dist/cjs/providers/test/rpc-urls.d.ts +1 -0
  47. package/dist/cjs/providers/test/rpc-urls.js +12 -6
  48. package/dist/cjs/providers/test/test-alchemy-provider.test.js +151 -0
  49. package/dist/cjs/providers/utils/chains-info.d.ts +5 -448
  50. package/dist/cjs/providers/utils/chains-info.js +13 -1344
  51. package/dist/cjs/shared/tiny-big/helpers.js +18 -18
  52. package/dist/cjs/shared/tiny-big/tiny-big.js +96 -56
  53. package/dist/cjs/shared/tiny-big/tiny-big.test.js +2 -2
  54. package/dist/cjs/shared/validate-type.d.ts +1 -1
  55. package/dist/cjs/shared/validate-type.js +4 -4
  56. package/dist/cjs/types/Block.types.d.ts +3 -3
  57. package/dist/cjs/types/Contract.types.d.ts +4 -4
  58. package/dist/cjs/types/Transaction.types.d.ts +5 -5
  59. package/dist/cjs/utils/bytes.d.ts +4 -4
  60. package/dist/cjs/utils/bytes.js +3 -3
  61. package/dist/cjs/utils/tests/bytes/arrayify.test.js +48 -24
  62. package/dist/cjs/utils/tests/bytes/concat.test.js +5 -3
  63. package/dist/cjs/utils/tests/bytes/hex-concat.test.js +15 -13
  64. package/dist/cjs/utils/tests/bytes/hex-data-length.test.js +49 -32
  65. package/dist/cjs/utils/tests/bytes/hex-data-slice.test.js +15 -16
  66. package/dist/cjs/utils/tests/bytes/hex-strip-zeros.test.js +57 -40
  67. package/dist/cjs/utils/tests/bytes/hex-value.test.js +118 -62
  68. package/dist/cjs/utils/tests/bytes/hex-zero-pad.test.js +71 -33
  69. package/dist/cjs/utils/tests/bytes/hexlify.test.js +45 -29
  70. package/dist/cjs/utils/tests/bytes/is-bytes-like.test.js +10 -11
  71. package/dist/cjs/utils/tests/bytes/is-bytes.test.js +70 -27
  72. package/dist/cjs/utils/tests/bytes/is-hex-string.test.js +37 -28
  73. package/dist/cjs/utils/tests/bytes/strip-zeros.test.js +94 -45
  74. package/dist/cjs/utils/tests/bytes/zero-pad.test.js +98 -34
  75. package/dist/cjs/utils/tests/compute-address.test.js +42 -20
  76. package/dist/cjs/utils/tests/compute-public-key.test.js +20 -9
  77. package/dist/cjs/utils/tests/ether-to-wei.test.js +5 -13
  78. package/dist/cjs/utils/tests/hash-message.test.js +26 -15
  79. package/dist/cjs/utils/tests/is-address.test.js +2 -9
  80. package/dist/cjs/utils/tests/keccak256.test.js +36 -12
  81. package/dist/cjs/utils/tests/solidity-keccak256.test.js +43 -42
  82. package/dist/cjs/utils/tests/split-signature.test.js +29 -8
  83. package/dist/cjs/utils/tests/to-checksum-address.test.js +1 -4
  84. package/dist/cjs/utils/tests/to-utf8-bytes.test.js +28 -8
  85. package/dist/cjs/utils/tests/wei-to-ether.test.js +10 -20
  86. package/dist/esm/classes/test/Contract/ens-abi.d.ts +1 -1
  87. package/dist/esm/classes/test/Contract/foo-abi.d.ts +1 -1
  88. package/dist/esm/classes/utils/fetchers.d.ts +8 -2
  89. package/dist/esm/classes/utils/fetchers.js +6 -3
  90. package/dist/esm/index.d.ts +21 -21
  91. package/dist/esm/index.js +16 -16
  92. package/dist/esm/logger/package-version.d.ts +1 -1
  93. package/dist/esm/logger/package-version.js +1 -1
  94. package/dist/esm/providers/AlchemyProvider.d.ts +4 -0
  95. package/dist/esm/providers/AlchemyProvider.js +7 -0
  96. package/dist/esm/providers/FallthroughProvider.js +15 -7
  97. package/dist/esm/providers/test/json-rpc-provider/get-logs/mocks.d.ts +14 -0
  98. package/dist/esm/providers/test/json-rpc-provider/get-logs/mocks.js +142 -0
  99. package/dist/esm/providers/test/mock-of.d.ts +2 -0
  100. package/dist/esm/providers/test/mock-of.js +1 -0
  101. package/dist/esm/providers/test/rpc-urls.d.ts +1 -0
  102. package/dist/esm/providers/test/rpc-urls.js +14 -6
  103. package/dist/esm/providers/utils/chains-info.d.ts +5 -448
  104. package/dist/esm/providers/utils/chains-info.js +13 -1344
  105. package/dist/esm/shared/validate-type.d.ts +1 -1
  106. package/dist/esm/types/Block.types.d.ts +3 -3
  107. package/dist/esm/types/Contract.types.d.ts +4 -4
  108. package/dist/esm/types/Transaction.types.d.ts +5 -5
  109. package/dist/esm/utils/bytes.d.ts +4 -4
  110. package/package.json +23 -51
  111. package/readme.md +16 -38
  112. package/dist/cjs/providers/test/json-rpc-provider/get-logs.test.js +0 -361
@@ -1,40 +1,55 @@
1
- import { utils as ethers } from "ethers";
2
1
  import { hexlify } from "../../bytes";
3
2
  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)
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
+ }
12
29
  ];
13
- decimalValues.forEach(function(decimalValue) {
14
- expect(hexlify(decimalValue)).toBe(ethers.hexlify(decimalValue));
30
+ testCases.forEach(function(testCase) {
31
+ expect(hexlify(testCase.value)).toBe(testCase.expected);
15
32
  });
16
- var opts = {
17
- allowMissingPrefix: true
18
- };
19
- expect(hexlify("22", opts)).toBe(ethers.hexlify("22", opts));
20
33
  });
21
- it("should match ethers.js - hexPad options", function() {
22
- var values = [
23
- [
24
- "0x3342e95",
25
- {
34
+ it("should hexlify with options - hexPad", function() {
35
+ var testCases = [
36
+ {
37
+ value: "0x3342e95",
38
+ options: {
26
39
  hexPad: "left"
27
- }
28
- ],
29
- [
30
- "0x41c942c42",
31
- {
40
+ },
41
+ expected: "0x03342e95"
42
+ },
43
+ {
44
+ value: "0x41c942c42",
45
+ options: {
32
46
  hexPad: "right"
33
- }
34
- ]
47
+ },
48
+ expected: "0x41c942c420"
49
+ }
35
50
  ];
36
- values.forEach(function(value) {
37
- expect(hexlify(value[0], value[1])).toBe(ethers.hexlify(value[0], value[1]));
51
+ testCases.forEach(function(testCase) {
52
+ expect(hexlify(testCase.value, testCase.options)).toBe(testCase.expected);
38
53
  });
39
54
  });
40
55
  it("should throw error - hex data is odd-length", function() {
@@ -49,6 +64,7 @@ describe("utils.hexlify", function() {
49
64
  });
50
65
  });
51
66
  it("should throw error - invalid hexlify value", function() {
67
+ // @ts-expect-error
52
68
  var values = [
53
69
  "non-hex string",
54
70
  false
@@ -1,17 +1,16 @@
1
- import { utils as ethers } from "ethers";
2
1
  import { isBytesLike } from "../../bytes";
3
2
  describe("utils.isBytesLike", function() {
4
- it("should match ethers.js - hex string", function() {
3
+ it("should return true - hex string", function() {
5
4
  var values = [
6
5
  "0x9347",
7
6
  "0x185754",
8
7
  "0x00005823"
9
8
  ];
10
9
  values.forEach(function(value) {
11
- expect(isBytesLike(value)).toBe(ethers.isBytesLike(value));
10
+ expect(isBytesLike(value)).toBe(true);
12
11
  });
13
12
  });
14
- it("should match ethers.js - UInt8Array", function() {
13
+ it("should return true - UInt8Array", function() {
15
14
  var values = [
16
15
  [
17
16
  9,
@@ -34,36 +33,36 @@ describe("utils.isBytesLike", function() {
34
33
  ]
35
34
  ];
36
35
  values.forEach(function(value) {
37
- expect(isBytesLike(value)).toBe(ethers.isBytesLike(value));
36
+ expect(isBytesLike(value)).toBe(true);
38
37
  });
39
38
  });
40
- it("should match ethers.js - number", function() {
39
+ it("should return false - number", function() {
41
40
  var values = [
42
41
  152,
43
42
  513,
44
43
  2354
45
44
  ];
46
45
  values.forEach(function(value) {
47
- expect(isBytesLike(value)).toBe(ethers.isBytesLike(value));
46
+ expect(isBytesLike(value)).toBe(false);
48
47
  });
49
48
  });
50
- it("should match ethers.js - non-hex string", function() {
49
+ it("should return false - non-hex string", function() {
51
50
  var values = [
52
51
  "essential-eth",
53
52
  "ethers.js",
54
53
  "ethereum"
55
54
  ];
56
55
  values.forEach(function(value) {
57
- expect(isBytesLike(value)).toBe(ethers.isBytesLike(value));
56
+ expect(isBytesLike(value)).toBe(false);
58
57
  });
59
58
  });
60
- it("should match ethers.js - boolean", function() {
59
+ it("should return false - boolean", function() {
61
60
  var values = [
62
61
  false,
63
62
  true
64
63
  ];
65
64
  values.forEach(function(value) {
66
- expect(isBytesLike(value)).toBe(ethers.isBytesLike(value));
65
+ expect(isBytesLike(value)).toBe(false);
67
66
  });
68
67
  });
69
68
  });
@@ -1,33 +1,76 @@
1
- import * as ethers from "ethers";
2
1
  import { isBytes, isBytesLike } from "../../..";
3
2
  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)
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
+ }
27
70
  ];
28
- inputs.forEach(function(input) {
29
- expect(isBytesLike(input)).toBe(ethers.utils.isBytesLike(input));
30
- expect(isBytes(input)).toBe(ethers.utils.isBytes(input));
71
+ testCases.forEach(function(testCase) {
72
+ expect(isBytesLike(testCase.value)).toBe(testCase.isBytesLike);
73
+ expect(isBytes(testCase.value)).toBe(testCase.isBytes);
31
74
  });
32
75
  });
33
76
  });
@@ -1,36 +1,45 @@
1
- import { utils as ethers } from "ethers";
2
1
  import { isHexString } from "../../bytes";
3
2
  describe("utils.isHexString", function() {
4
- it("should match ethers.js - hex string", function() {
3
+ it("should return true - hex string", function() {
5
4
  var values = [
6
5
  "0x9347",
7
6
  "0x185754",
8
7
  "0x00005823"
9
8
  ];
10
9
  values.forEach(function(value) {
11
- expect(isHexString(value)).toBe(ethers.isHexString(value));
10
+ expect(isHexString(value)).toBe(true);
12
11
  });
13
12
  });
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
- ]
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
+ }
28
37
  ];
29
- values.forEach(function(value) {
30
- expect(isHexString(value[0], value[1])).toBe(ethers.isHexString(value[0], value[1]));
38
+ testCases.forEach(function(testCase) {
39
+ expect(isHexString(testCase.value[0], testCase.value[1])).toBe(testCase.expected);
31
40
  });
32
41
  });
33
- it("should match ethers.js - UInt8Array", function() {
42
+ it("should return false - UInt8Array", function() {
34
43
  var values = [
35
44
  [
36
45
  9,
@@ -53,36 +62,36 @@ describe("utils.isHexString", function() {
53
62
  ]
54
63
  ];
55
64
  values.forEach(function(value) {
56
- expect(isHexString(value)).toBe(ethers.isHexString(value));
65
+ expect(isHexString(value)).toBe(false);
57
66
  });
58
67
  });
59
- it("should match ethers.js - number", function() {
68
+ it("should return false - number", function() {
60
69
  var values = [
61
70
  152,
62
71
  513,
63
72
  2354
64
73
  ];
65
74
  values.forEach(function(value) {
66
- expect(isHexString(value)).toBe(ethers.isHexString(value));
75
+ expect(isHexString(value)).toBe(false);
67
76
  });
68
77
  });
69
- it("should match ethers.js - non-hex string", function() {
78
+ it("should return false - non-hex string", function() {
70
79
  var values = [
71
80
  "essential-eth",
72
81
  "ethers.js",
73
- "ethereum"
82
+ "\uD83D\uDC4B firek.eth was here hehe"
74
83
  ];
75
84
  values.forEach(function(value) {
76
- expect(isHexString(value)).toBe(ethers.isHexString(value));
85
+ expect(isHexString(value)).toBe(false);
77
86
  });
78
87
  });
79
- it("should match ethers.js - boolean", function() {
88
+ it("should return false - boolean", function() {
80
89
  var values = [
81
90
  false,
82
91
  true
83
92
  ];
84
93
  values.forEach(function(value) {
85
- expect(isHexString(value)).toBe(ethers.isHexString(value));
94
+ expect(isHexString(value)).toBe(false);
86
95
  });
87
96
  });
88
97
  });
@@ -1,57 +1,106 @@
1
- import { utils as ethers } from "ethers";
2
1
  import { stripZeros } from "../../bytes";
3
2
  describe("utils.stripZeros", function() {
4
- it("should match ethers.js - hex string", function() {
5
- var values = [
6
- "0x00009347",
7
- "0x00185754",
8
- "0x00000000005823"
3
+ it("should match expected result - hex string", function() {
4
+ var testCases = [
5
+ {
6
+ value: "0x00009347",
7
+ expected: new Uint8Array([
8
+ 147,
9
+ 71
10
+ ])
11
+ },
12
+ {
13
+ value: "0x00185754",
14
+ expected: new Uint8Array([
15
+ 24,
16
+ 87,
17
+ 84
18
+ ])
19
+ },
20
+ {
21
+ value: "0x00000000005823",
22
+ expected: new Uint8Array([
23
+ 88,
24
+ 35
25
+ ])
26
+ }
9
27
  ];
10
- values.forEach(function(value) {
11
- expect(stripZeros(value)).toStrictEqual(ethers.stripZeros(value));
28
+ testCases.forEach(function(testCase) {
29
+ expect(stripZeros(testCase.value)).toStrictEqual(testCase.expected);
12
30
  });
13
31
  });
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
- ]
32
+ it("should match expected result - UInt8Array", function() {
33
+ var testCases = [
34
+ {
35
+ value: [
36
+ 0,
37
+ 0,
38
+ 0,
39
+ 9,
40
+ 58,
41
+ 29,
42
+ 24
43
+ ],
44
+ expected: new Uint8Array([
45
+ 9,
46
+ 58,
47
+ 29,
48
+ 24
49
+ ])
50
+ },
51
+ {
52
+ value: [
53
+ 0,
54
+ 185,
55
+ 203
56
+ ],
57
+ expected: new Uint8Array([
58
+ 185,
59
+ 203
60
+ ])
61
+ },
62
+ {
63
+ value: [
64
+ 0,
65
+ 0,
66
+ 0,
67
+ 0,
68
+ 239,
69
+ 30,
70
+ 49,
71
+ 41,
72
+ 5,
73
+ 10,
74
+ 42
75
+ ],
76
+ expected: new Uint8Array([
77
+ 239,
78
+ 30,
79
+ 49,
80
+ 41,
81
+ 5,
82
+ 10,
83
+ 42
84
+ ])
85
+ }
43
86
  ];
44
- values.forEach(function(value) {
45
- expect(stripZeros(value)).toStrictEqual(ethers.stripZeros(value));
87
+ testCases.forEach(function(testCase) {
88
+ expect(stripZeros(testCase.value)).toStrictEqual(testCase.expected);
46
89
  });
47
90
  });
48
- it("should match ethers.js - empty array", function() {
49
- var values = [
50
- [],
51
- "0x"
91
+ it("should match expected result - empty array", function() {
92
+ var testCases = [
93
+ {
94
+ value: [],
95
+ expected: new Uint8Array([])
96
+ },
97
+ {
98
+ value: "0x",
99
+ expected: new Uint8Array([])
100
+ }
52
101
  ];
53
- values.forEach(function(value) {
54
- expect(stripZeros(value)).toStrictEqual(ethers.stripZeros(value));
102
+ testCases.forEach(function(testCase) {
103
+ expect(stripZeros(testCase.value)).toStrictEqual(testCase.expected);
55
104
  });
56
105
  });
57
106
  });
@@ -1,45 +1,110 @@
1
- import { utils as ethers } from "ethers";
2
1
  import { zeroPad } from "../../bytes";
3
2
  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
- ]
3
+ it("should match expected result - hex string", function() {
4
+ var testCases = [
5
+ {
6
+ value: [
7
+ "0x9347",
8
+ 10
9
+ ],
10
+ expected: new Uint8Array([
11
+ 0,
12
+ 0,
13
+ 0,
14
+ 0,
15
+ 0,
16
+ 0,
17
+ 0,
18
+ 0,
19
+ 147,
20
+ 71
21
+ ])
22
+ },
23
+ {
24
+ value: [
25
+ "0x185754",
26
+ 5
27
+ ],
28
+ expected: new Uint8Array([
29
+ 0,
30
+ 0,
31
+ 24,
32
+ 87,
33
+ 84
34
+ ])
35
+ },
36
+ {
37
+ value: [
38
+ "0x00005823",
39
+ 7
40
+ ],
41
+ expected: new Uint8Array([
42
+ 0,
43
+ 0,
44
+ 0,
45
+ 0,
46
+ 0,
47
+ 88,
48
+ 35
49
+ ])
50
+ }
18
51
  ];
19
- values.forEach(function(value) {
20
- expect(zeroPad(value[0], value[1])).toStrictEqual(ethers.zeroPad(value[0], value[1]));
52
+ testCases.forEach(function(testCase) {
53
+ expect(zeroPad(testCase.value[0], testCase.value[1])).toStrictEqual(testCase.expected);
21
54
  });
22
55
  });
23
- it("should match ethers.js - UInt8Array", function() {
24
- var values = [
25
- [
26
- [
56
+ it("should match expected result - UInt8Array", function() {
57
+ var testCases = [
58
+ {
59
+ value: [
60
+ [
61
+ 9,
62
+ 58,
63
+ 29,
64
+ 24
65
+ ],
66
+ 5
67
+ ],
68
+ expected: new Uint8Array([
69
+ 0,
27
70
  9,
28
71
  58,
29
72
  29,
30
73
  24
74
+ ])
75
+ },
76
+ {
77
+ value: [
78
+ [
79
+ 185,
80
+ 203
81
+ ],
82
+ 4
31
83
  ],
32
- 5
33
- ],
34
- [
35
- [
84
+ expected: new Uint8Array([
85
+ 0,
86
+ 0,
36
87
  185,
37
88
  203
89
+ ])
90
+ },
91
+ {
92
+ value: [
93
+ [
94
+ 239,
95
+ 30,
96
+ 49,
97
+ 41,
98
+ 5,
99
+ 10,
100
+ 42
101
+ ],
102
+ 10
38
103
  ],
39
- 4
40
- ],
41
- [
42
- [
104
+ expected: new Uint8Array([
105
+ 0,
106
+ 0,
107
+ 0,
43
108
  239,
44
109
  30,
45
110
  49,
@@ -47,12 +112,11 @@ describe("utils.zeroPad", function() {
47
112
  5,
48
113
  10,
49
114
  42
50
- ],
51
- 10
52
- ]
115
+ ])
116
+ }
53
117
  ];
54
- values.forEach(function(value) {
55
- expect(zeroPad(value[0], value[1])).toStrictEqual(ethers.zeroPad(value[0], value[1]));
118
+ testCases.forEach(function(testCase) {
119
+ expect(zeroPad(testCase.value[0], testCase.value[1])).toStrictEqual(testCase.expected);
56
120
  });
57
121
  });
58
122
  it("should throw error - value out of range", function() {