essential-eth 0.9.0 → 0.9.1-next.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.
Files changed (134) hide show
  1. package/dist/cjs/classes/Contract.js +66 -307
  2. package/dist/cjs/classes/test/Contract/crv-abi.js +256 -252
  3. package/dist/cjs/classes/test/Contract/ens-abi.d.ts +1 -1
  4. package/dist/cjs/classes/test/Contract/ens-abi.js +212 -497
  5. package/dist/cjs/classes/test/Contract/fei-abi.js +284 -605
  6. package/dist/cjs/classes/test/Contract/foo-abi.d.ts +1 -1
  7. package/dist/cjs/classes/test/Contract/foo-abi.js +21 -44
  8. package/dist/cjs/classes/test/Contract/uniswap-abi.js +68 -64
  9. package/dist/cjs/classes/utils/clean-block.js +30 -52
  10. package/dist/cjs/classes/utils/clean-log.js +20 -42
  11. package/dist/cjs/classes/utils/clean-transaction-receipt.js +30 -51
  12. package/dist/cjs/classes/utils/clean-transaction.js +30 -52
  13. package/dist/cjs/classes/utils/encode-decode-transaction.js +107 -148
  14. package/dist/cjs/classes/utils/fetchers.d.ts +8 -2
  15. package/dist/cjs/classes/utils/fetchers.js +52 -166
  16. package/dist/cjs/classes/utils/hex-to-decimal.js +6 -1
  17. package/dist/cjs/classes/utils/prepare-transaction.js +36 -59
  18. package/dist/cjs/index.d.ts +21 -22
  19. package/dist/cjs/index.js +56 -26
  20. package/dist/cjs/index.umd.js +1 -1
  21. package/dist/cjs/index.umd.js.map +1 -1
  22. package/dist/cjs/logger/logger.js +23 -79
  23. package/dist/cjs/logger/package-version.d.ts +1 -1
  24. package/dist/cjs/logger/package-version.js +4 -1
  25. package/dist/cjs/providers/AlchemyProvider.js +9 -82
  26. package/dist/cjs/providers/BaseProvider.js +511 -882
  27. package/dist/cjs/providers/FallthroughProvider.js +46 -123
  28. package/dist/cjs/providers/JsonRpcProvider.js +28 -93
  29. package/dist/cjs/providers/test/json-rpc-provider/get-logs/mocks.d.ts +14 -0
  30. package/dist/cjs/providers/test/json-rpc-provider/get-logs/mocks.js +152 -0
  31. package/dist/cjs/providers/test/mock-of.js +6 -8
  32. package/dist/cjs/providers/test/rpc-urls.d.ts +1 -0
  33. package/dist/cjs/providers/test/rpc-urls.js +23 -14
  34. package/dist/cjs/providers/utils/chains-info.d.ts +5 -448
  35. package/dist/cjs/providers/utils/chains-info.js +16 -1345
  36. package/dist/cjs/shared/tiny-big/helpers.js +42 -93
  37. package/dist/cjs/shared/tiny-big/tiny-big.js +72 -161
  38. package/dist/cjs/shared/validate-type.d.ts +1 -1
  39. package/dist/cjs/shared/validate-type.js +7 -7
  40. package/dist/cjs/types/Block.types.d.ts +3 -3
  41. package/dist/cjs/types/Block.types.js +2 -1
  42. package/dist/cjs/types/Contract.types.d.ts +4 -4
  43. package/dist/cjs/types/Contract.types.js +2 -1
  44. package/dist/cjs/types/FeeData.types.js +2 -1
  45. package/dist/cjs/types/Filter.types.js +2 -1
  46. package/dist/cjs/types/Network.types.js +2 -3
  47. package/dist/cjs/types/Transaction.types.d.ts +5 -5
  48. package/dist/cjs/types/Transaction.types.js +2 -1
  49. package/dist/cjs/utils/bytes.d.ts +4 -4
  50. package/dist/cjs/utils/bytes.js +318 -286
  51. package/dist/cjs/utils/compute-address.js +15 -8
  52. package/dist/cjs/utils/compute-public-key.js +10 -5
  53. package/dist/cjs/utils/ether-to-gwei.js +11 -10
  54. package/dist/cjs/utils/ether-to-wei.js +11 -10
  55. package/dist/cjs/utils/gwei-to-ether.js +11 -10
  56. package/dist/cjs/utils/hash-message.js +16 -11
  57. package/dist/cjs/utils/is-address.js +12 -8
  58. package/dist/cjs/utils/keccak256.js +14 -8
  59. package/dist/cjs/utils/solidity-keccak256.js +60 -49
  60. package/dist/cjs/utils/split-signature.js +73 -55
  61. package/dist/cjs/utils/to-checksum-address.js +20 -15
  62. package/dist/cjs/utils/to-utf8-bytes.js +6 -1
  63. package/dist/cjs/utils/wei-to-ether.js +15 -13
  64. package/dist/esm/classes/test/Contract/ens-abi.d.ts +1 -1
  65. package/dist/esm/classes/test/Contract/foo-abi.d.ts +1 -1
  66. package/dist/esm/classes/utils/fetchers.d.ts +8 -2
  67. package/dist/esm/classes/utils/fetchers.js +6 -3
  68. package/dist/esm/index.d.ts +21 -22
  69. package/dist/esm/index.js +16 -17
  70. package/dist/esm/logger/package-version.d.ts +1 -1
  71. package/dist/esm/logger/package-version.js +1 -1
  72. package/dist/esm/providers/FallthroughProvider.js +3 -3
  73. package/dist/esm/providers/test/json-rpc-provider/get-logs/mocks.d.ts +14 -0
  74. package/dist/esm/providers/test/json-rpc-provider/get-logs/mocks.js +142 -0
  75. package/dist/esm/providers/test/rpc-urls.d.ts +1 -0
  76. package/dist/esm/providers/test/rpc-urls.js +7 -4
  77. package/dist/esm/providers/utils/chains-info.d.ts +5 -448
  78. package/dist/esm/providers/utils/chains-info.js +13 -1344
  79. package/dist/esm/shared/validate-type.d.ts +1 -1
  80. package/dist/esm/types/Block.types.d.ts +3 -3
  81. package/dist/esm/types/Contract.types.d.ts +4 -4
  82. package/dist/esm/types/Transaction.types.d.ts +5 -5
  83. package/dist/esm/utils/bytes.d.ts +4 -4
  84. package/package.json +23 -51
  85. package/readme.md +15 -38
  86. package/dist/cjs/classes/test/Contract/crv.test.js +0 -690
  87. package/dist/cjs/classes/test/Contract/ens.test.js +0 -217
  88. package/dist/cjs/classes/test/Contract/fei.test.js +0 -224
  89. package/dist/cjs/classes/test/Contract/foo.test.js +0 -33
  90. package/dist/cjs/classes/test/Contract/uni.test.js +0 -387
  91. package/dist/cjs/providers/test/fallthrough-provider/get-gas-price.test.js +0 -228
  92. package/dist/cjs/providers/test/get-transaction-count.test.js +0 -276
  93. package/dist/cjs/providers/test/json-rpc-provider/call.test.js +0 -436
  94. package/dist/cjs/providers/test/json-rpc-provider/estimate-gas.test.js +0 -288
  95. package/dist/cjs/providers/test/json-rpc-provider/get-balance.test.js +0 -261
  96. package/dist/cjs/providers/test/json-rpc-provider/get-block-number.test.js +0 -159
  97. package/dist/cjs/providers/test/json-rpc-provider/get-block.test.js +0 -477
  98. package/dist/cjs/providers/test/json-rpc-provider/get-code.test.js +0 -311
  99. package/dist/cjs/providers/test/json-rpc-provider/get-fee-data.test.js +0 -212
  100. package/dist/cjs/providers/test/json-rpc-provider/get-gas-price.test.js +0 -164
  101. package/dist/cjs/providers/test/json-rpc-provider/get-logs.test.js +0 -361
  102. package/dist/cjs/providers/test/json-rpc-provider/get-network.test.js +0 -274
  103. package/dist/cjs/providers/test/json-rpc-provider/get-transaction-receipt.test.js +0 -301
  104. package/dist/cjs/providers/test/json-rpc-provider/get-transaction.test.js +0 -307
  105. package/dist/cjs/providers/test/test-alchemy-provider.test.js +0 -151
  106. package/dist/cjs/shared/tiny-big/helpers.test.js +0 -29
  107. package/dist/cjs/shared/tiny-big/tiny-big.test.js +0 -34
  108. package/dist/cjs/utils/tests/bytes/arrayify.test.js +0 -40
  109. package/dist/cjs/utils/tests/bytes/concat.test.js +0 -15
  110. package/dist/cjs/utils/tests/bytes/hex-concat.test.js +0 -63
  111. package/dist/cjs/utils/tests/bytes/hex-data-length.test.js +0 -49
  112. package/dist/cjs/utils/tests/bytes/hex-data-slice.test.js +0 -52
  113. package/dist/cjs/utils/tests/bytes/hex-strip-zeros.test.js +0 -58
  114. package/dist/cjs/utils/tests/bytes/hex-value.test.js +0 -85
  115. package/dist/cjs/utils/tests/bytes/hex-zero-pad.test.js +0 -62
  116. package/dist/cjs/utils/tests/bytes/hexlify.test.js +0 -62
  117. package/dist/cjs/utils/tests/bytes/is-bytes-like.test.js +0 -69
  118. package/dist/cjs/utils/tests/bytes/is-bytes.test.js +0 -33
  119. package/dist/cjs/utils/tests/bytes/is-hex-string.test.js +0 -88
  120. package/dist/cjs/utils/tests/bytes/strip-zeros.test.js +0 -57
  121. package/dist/cjs/utils/tests/bytes/zero-pad.test.js +0 -80
  122. package/dist/cjs/utils/tests/compute-address.test.js +0 -27
  123. package/dist/cjs/utils/tests/compute-public-key.test.js +0 -15
  124. package/dist/cjs/utils/tests/ether-to-gwei.test.js +0 -26
  125. package/dist/cjs/utils/tests/ether-to-wei.test.js +0 -44
  126. package/dist/cjs/utils/tests/gwei-to-ether.test.js +0 -28
  127. package/dist/cjs/utils/tests/hash-message.test.js +0 -21
  128. package/dist/cjs/utils/tests/is-address.test.js +0 -55
  129. package/dist/cjs/utils/tests/keccak256.test.js +0 -97
  130. package/dist/cjs/utils/tests/solidity-keccak256.test.js +0 -310
  131. package/dist/cjs/utils/tests/split-signature.test.js +0 -25
  132. package/dist/cjs/utils/tests/to-checksum-address.test.js +0 -42
  133. package/dist/cjs/utils/tests/to-utf8-bytes.test.js +0 -14
  134. package/dist/cjs/utils/tests/wei-to-ether.test.js +0 -51
@@ -1,151 +0,0 @@
1
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2
- try {
3
- var info = gen[key](arg);
4
- var value = info.value;
5
- } catch (error) {
6
- reject(error);
7
- return;
8
- }
9
- if (info.done) {
10
- resolve(value);
11
- } else {
12
- Promise.resolve(value).then(_next, _throw);
13
- }
14
- }
15
- function _asyncToGenerator(fn) {
16
- return function() {
17
- var self = this, args = arguments;
18
- return new Promise(function(resolve, reject) {
19
- var gen = fn.apply(self, args);
20
- function _next(value) {
21
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
22
- }
23
- function _throw(err) {
24
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
25
- }
26
- _next(undefined);
27
- });
28
- };
29
- }
30
- var __generator = this && this.__generator || function(thisArg, body) {
31
- var f, y, t, g, _ = {
32
- label: 0,
33
- sent: function() {
34
- if (t[0] & 1) throw t[1];
35
- return t[1];
36
- },
37
- trys: [],
38
- ops: []
39
- };
40
- return g = {
41
- next: verb(0),
42
- "throw": verb(1),
43
- "return": verb(2)
44
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
45
- return this;
46
- }), g;
47
- function verb(n) {
48
- return function(v) {
49
- return step([
50
- n,
51
- v
52
- ]);
53
- };
54
- }
55
- function step(op) {
56
- if (f) throw new TypeError("Generator is already executing.");
57
- while(_)try {
58
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
59
- if (y = 0, t) op = [
60
- op[0] & 2,
61
- t.value
62
- ];
63
- switch(op[0]){
64
- case 0:
65
- case 1:
66
- t = op;
67
- break;
68
- case 4:
69
- _.label++;
70
- return {
71
- value: op[1],
72
- done: false
73
- };
74
- case 5:
75
- _.label++;
76
- y = op[1];
77
- op = [
78
- 0
79
- ];
80
- continue;
81
- case 7:
82
- op = _.ops.pop();
83
- _.trys.pop();
84
- continue;
85
- default:
86
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
87
- _ = 0;
88
- continue;
89
- }
90
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
91
- _.label = op[1];
92
- break;
93
- }
94
- if (op[0] === 6 && _.label < t[1]) {
95
- _.label = t[1];
96
- t = op;
97
- break;
98
- }
99
- if (t && _.label < t[2]) {
100
- _.label = t[2];
101
- _.ops.push(op);
102
- break;
103
- }
104
- if (t[2]) _.ops.pop();
105
- _.trys.pop();
106
- continue;
107
- }
108
- op = body.call(thisArg, _);
109
- } catch (e) {
110
- op = [
111
- 6,
112
- e
113
- ];
114
- y = 0;
115
- } finally{
116
- f = t = 0;
117
- }
118
- if (op[0] & 5) throw op[1];
119
- return {
120
- value: op[0] ? op[1] : void 0,
121
- done: true
122
- };
123
- }
124
- };
125
- import { z } from "zod";
126
- import { AlchemyProvider, TinyBig } from "../../index";
127
- var ALCHEMY_API_KEY = process.env.ALCHEMY_API_KEY;
128
- if (!ALCHEMY_API_KEY) {
129
- throw new Error("ALCHEMY_API_KEY is not defined in the environment variables.");
130
- }
131
- var provider = new AlchemyProvider(ALCHEMY_API_KEY);
132
- describe("alchemyProvider.getGasPrice", function() {
133
- it("should return the current gas price", /*#__PURE__*/ _asyncToGenerator(function() {
134
- var gasPrice;
135
- return __generator(this, function(_state) {
136
- switch(_state.label){
137
- case 0:
138
- return [
139
- 4,
140
- provider.getGasPrice()
141
- ];
142
- case 1:
143
- gasPrice = _state.sent();
144
- expect(z.instanceof(TinyBig).safeParse(gasPrice).success).toBe(true);
145
- return [
146
- 2
147
- ];
148
- }
149
- });
150
- }));
151
- });
@@ -1,29 +0,0 @@
1
- import { scientificStrToDecimalStr } from "./helpers";
2
- describe("scientificStrToDecimalStr", function() {
3
- it("not even scientific", function() {
4
- expect(scientificStrToDecimalStr("010")).toBe("10");
5
- expect(scientificStrToDecimalStr("-010")).toBe("-10");
6
- });
7
- it("zero power", function() {
8
- expect(scientificStrToDecimalStr("10e0")).toBe("10");
9
- expect(scientificStrToDecimalStr("1.0e0")).toBe("1");
10
- expect(scientificStrToDecimalStr("-10e-0")).toBe("-10");
11
- expect(scientificStrToDecimalStr("-1.0e-0")).toBe("-1");
12
- expect(scientificStrToDecimalStr("-1.10e-0")).toBe("-1.1");
13
- expect(scientificStrToDecimalStr("-1.e-0")).toBe("-1");
14
- expect(scientificStrToDecimalStr(".10e-0")).toBe("0.1");
15
- expect(scientificStrToDecimalStr("00.0010e-0")).toBe("0.001");
16
- });
17
- it("negative power", function() {
18
- expect(scientificStrToDecimalStr("0100e-2")).toBe("1");
19
- expect(scientificStrToDecimalStr("0100e-4")).toBe("0.01");
20
- expect(scientificStrToDecimalStr("010.1e-3")).toBe("0.0101");
21
- expect(scientificStrToDecimalStr("-010.1e-3")).toBe("-0.0101");
22
- expect(scientificStrToDecimalStr("09.1e-51")).toBe("0.".concat("0".repeat(50), "91"));
23
- });
24
- it("positive power", function() {
25
- expect(scientificStrToDecimalStr("01e2")).toBe("100");
26
- expect(scientificStrToDecimalStr("-01e2")).toBe("-100");
27
- expect(scientificStrToDecimalStr("09.1e51")).toBe("91".concat("0".repeat(50)));
28
- });
29
- });
@@ -1,34 +0,0 @@
1
- import { BigNumber } from "ethers";
2
- import { tinyBig } from "./tiny-big";
3
- describe("tiny-big", function() {
4
- it("allows hex string input", function() {
5
- expect(tinyBig("0xa").toString()).toBe("10");
6
- expect(tinyBig("10").toString()).toBe("10");
7
- });
8
- it("performs toHexString properly", function() {
9
- expect(tinyBig(0).toHexString()).toBe("0x0");
10
- expect(tinyBig(1).toHexString()).toBe("0x1");
11
- expect(tinyBig(15).toHexString()).toBe("0xf");
12
- expect(tinyBig(16).toHexString()).toBe("0x10");
13
- });
14
- it("performs twosComplement", function() {
15
- var inputs = [
16
- {
17
- num: -3,
18
- bitCount: 3
19
- },
20
- {
21
- num: 0,
22
- bitCount: 3
23
- },
24
- {
25
- num: 3,
26
- bitCount: 3
27
- }
28
- ];
29
- inputs.forEach(function(param) {
30
- var num = param.num, bitCount = param.bitCount;
31
- expect(tinyBig(num).toTwos(bitCount).toString()).toBe(BigNumber.from(num).toTwos(bitCount).toString());
32
- });
33
- });
34
- });
@@ -1,40 +0,0 @@
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
- });
@@ -1,15 +0,0 @@
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
- });
@@ -1,63 +0,0 @@
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
- });
@@ -1,49 +0,0 @@
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
- });
@@ -1,52 +0,0 @@
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
- });
@@ -1,58 +0,0 @@
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
- });
@@ -1,85 +0,0 @@
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
- });
@@ -1,62 +0,0 @@
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
- });