essential-eth 0.9.1-next.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 (104) hide show
  1. package/dist/cjs/classes/Contract.js +66 -311
  2. package/dist/cjs/classes/test/Contract/crv-abi.js +256 -252
  3. package/dist/cjs/classes/test/Contract/ens-abi.js +212 -497
  4. package/dist/cjs/classes/test/Contract/fei-abi.js +284 -605
  5. package/dist/cjs/classes/test/Contract/foo-abi.js +21 -44
  6. package/dist/cjs/classes/test/Contract/uniswap-abi.js +68 -64
  7. package/dist/cjs/classes/utils/clean-block.js +30 -52
  8. package/dist/cjs/classes/utils/clean-log.js +20 -42
  9. package/dist/cjs/classes/utils/clean-transaction-receipt.js +30 -51
  10. package/dist/cjs/classes/utils/clean-transaction.js +30 -52
  11. package/dist/cjs/classes/utils/encode-decode-transaction.js +107 -148
  12. package/dist/cjs/classes/utils/fetchers.js +44 -166
  13. package/dist/cjs/classes/utils/hex-to-decimal.js +6 -1
  14. package/dist/cjs/classes/utils/prepare-transaction.js +36 -59
  15. package/dist/cjs/index.js +56 -25
  16. package/dist/cjs/index.umd.js +1 -1
  17. package/dist/cjs/index.umd.js.map +1 -1
  18. package/dist/cjs/logger/logger.js +29 -123
  19. package/dist/cjs/logger/package-version.d.ts +1 -1
  20. package/dist/cjs/logger/package-version.js +4 -1
  21. package/dist/cjs/providers/AlchemyProvider.js +9 -82
  22. package/dist/cjs/providers/BaseProvider.js +520 -958
  23. package/dist/cjs/providers/FallthroughProvider.js +47 -156
  24. package/dist/cjs/providers/JsonRpcProvider.js +28 -114
  25. package/dist/cjs/providers/test/json-rpc-provider/get-logs/mocks.js +104 -101
  26. package/dist/cjs/providers/test/mock-of.js +6 -3
  27. package/dist/cjs/providers/test/rpc-urls.js +23 -15
  28. package/dist/cjs/providers/utils/chains-info.js +3 -1
  29. package/dist/cjs/shared/tiny-big/helpers.js +42 -93
  30. package/dist/cjs/shared/tiny-big/tiny-big.js +81 -210
  31. package/dist/cjs/shared/validate-type.js +7 -7
  32. package/dist/cjs/types/Block.types.js +2 -1
  33. package/dist/cjs/types/Contract.types.js +2 -1
  34. package/dist/cjs/types/FeeData.types.js +2 -1
  35. package/dist/cjs/types/Filter.types.js +2 -1
  36. package/dist/cjs/types/Network.types.js +2 -3
  37. package/dist/cjs/types/Transaction.types.js +2 -1
  38. package/dist/cjs/utils/bytes.js +318 -286
  39. package/dist/cjs/utils/compute-address.js +15 -8
  40. package/dist/cjs/utils/compute-public-key.js +10 -5
  41. package/dist/cjs/utils/ether-to-gwei.js +11 -10
  42. package/dist/cjs/utils/ether-to-wei.js +11 -10
  43. package/dist/cjs/utils/gwei-to-ether.js +11 -10
  44. package/dist/cjs/utils/hash-message.js +16 -11
  45. package/dist/cjs/utils/is-address.js +12 -8
  46. package/dist/cjs/utils/keccak256.js +14 -8
  47. package/dist/cjs/utils/solidity-keccak256.js +60 -49
  48. package/dist/cjs/utils/split-signature.js +73 -55
  49. package/dist/cjs/utils/to-checksum-address.js +20 -15
  50. package/dist/cjs/utils/to-utf8-bytes.js +6 -1
  51. package/dist/cjs/utils/wei-to-ether.js +15 -13
  52. package/dist/esm/logger/package-version.d.ts +1 -1
  53. package/dist/esm/logger/package-version.js +1 -1
  54. package/package.json +2 -2
  55. package/readme.md +1 -1
  56. package/dist/cjs/classes/test/Contract/crv.test.js +0 -497
  57. package/dist/cjs/classes/test/Contract/ens.test.js +0 -160
  58. package/dist/cjs/classes/test/Contract/fei.test.js +0 -224
  59. package/dist/cjs/classes/test/Contract/foo.test.js +0 -33
  60. package/dist/cjs/classes/test/Contract/uni.test.js +0 -289
  61. package/dist/cjs/providers/test/fallthrough-provider/get-gas-price.test.js +0 -228
  62. package/dist/cjs/providers/test/get-transaction-count.test.js +0 -239
  63. package/dist/cjs/providers/test/json-rpc-provider/call.test.js +0 -375
  64. package/dist/cjs/providers/test/json-rpc-provider/estimate-gas.test.js +0 -217
  65. package/dist/cjs/providers/test/json-rpc-provider/get-balance.test.js +0 -223
  66. package/dist/cjs/providers/test/json-rpc-provider/get-block-number.test.js +0 -163
  67. package/dist/cjs/providers/test/json-rpc-provider/get-block.test.js +0 -414
  68. package/dist/cjs/providers/test/json-rpc-provider/get-code.test.js +0 -282
  69. package/dist/cjs/providers/test/json-rpc-provider/get-fee-data.test.js +0 -187
  70. package/dist/cjs/providers/test/json-rpc-provider/get-gas-price.test.js +0 -167
  71. package/dist/cjs/providers/test/json-rpc-provider/get-logs/get-logs.test.js +0 -219
  72. package/dist/cjs/providers/test/json-rpc-provider/get-network.test.js +0 -232
  73. package/dist/cjs/providers/test/json-rpc-provider/get-transaction-receipt.test.js +0 -280
  74. package/dist/cjs/providers/test/json-rpc-provider/get-transaction.test.js +0 -266
  75. package/dist/cjs/providers/test/test-alchemy-provider.test.js +0 -151
  76. package/dist/cjs/shared/tiny-big/helpers.test.js +0 -29
  77. package/dist/cjs/shared/tiny-big/tiny-big.test.js +0 -34
  78. package/dist/cjs/utils/tests/bytes/arrayify.test.js +0 -64
  79. package/dist/cjs/utils/tests/bytes/concat.test.js +0 -17
  80. package/dist/cjs/utils/tests/bytes/hex-concat.test.js +0 -65
  81. package/dist/cjs/utils/tests/bytes/hex-data-length.test.js +0 -66
  82. package/dist/cjs/utils/tests/bytes/hex-data-slice.test.js +0 -51
  83. package/dist/cjs/utils/tests/bytes/hex-strip-zeros.test.js +0 -75
  84. package/dist/cjs/utils/tests/bytes/hex-value.test.js +0 -141
  85. package/dist/cjs/utils/tests/bytes/hex-zero-pad.test.js +0 -100
  86. package/dist/cjs/utils/tests/bytes/hexlify.test.js +0 -78
  87. package/dist/cjs/utils/tests/bytes/is-bytes-like.test.js +0 -68
  88. package/dist/cjs/utils/tests/bytes/is-bytes.test.js +0 -76
  89. package/dist/cjs/utils/tests/bytes/is-hex-string.test.js +0 -97
  90. package/dist/cjs/utils/tests/bytes/strip-zeros.test.js +0 -106
  91. package/dist/cjs/utils/tests/bytes/zero-pad.test.js +0 -144
  92. package/dist/cjs/utils/tests/compute-address.test.js +0 -49
  93. package/dist/cjs/utils/tests/compute-public-key.test.js +0 -26
  94. package/dist/cjs/utils/tests/ether-to-gwei.test.js +0 -26
  95. package/dist/cjs/utils/tests/ether-to-wei.test.js +0 -36
  96. package/dist/cjs/utils/tests/gwei-to-ether.test.js +0 -28
  97. package/dist/cjs/utils/tests/hash-message.test.js +0 -32
  98. package/dist/cjs/utils/tests/is-address.test.js +0 -48
  99. package/dist/cjs/utils/tests/keccak256.test.js +0 -121
  100. package/dist/cjs/utils/tests/solidity-keccak256.test.js +0 -311
  101. package/dist/cjs/utils/tests/split-signature.test.js +0 -46
  102. package/dist/cjs/utils/tests/to-checksum-address.test.js +0 -39
  103. package/dist/cjs/utils/tests/to-utf8-bytes.test.js +0 -34
  104. package/dist/cjs/utils/tests/wei-to-ether.test.js +0 -41
@@ -1,414 +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 _async_to_generator(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
- function _define_property(obj, key, value) {
31
- if (key in obj) {
32
- Object.defineProperty(obj, key, {
33
- value: value,
34
- enumerable: true,
35
- configurable: true,
36
- writable: true
37
- });
38
- } else {
39
- obj[key] = value;
40
- }
41
- return obj;
42
- }
43
- function _object_spread(target) {
44
- for(var i = 1; i < arguments.length; i++){
45
- var source = arguments[i] != null ? arguments[i] : {};
46
- var ownKeys = Object.keys(source);
47
- if (typeof Object.getOwnPropertySymbols === "function") {
48
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
49
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
50
- }));
51
- }
52
- ownKeys.forEach(function(key) {
53
- _define_property(target, key, source[key]);
54
- });
55
- }
56
- return target;
57
- }
58
- function ownKeys(object, enumerableOnly) {
59
- var keys = Object.keys(object);
60
- if (Object.getOwnPropertySymbols) {
61
- var symbols = Object.getOwnPropertySymbols(object);
62
- if (enumerableOnly) {
63
- symbols = symbols.filter(function(sym) {
64
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
65
- });
66
- }
67
- keys.push.apply(keys, symbols);
68
- }
69
- return keys;
70
- }
71
- function _object_spread_props(target, source) {
72
- source = source != null ? source : {};
73
- if (Object.getOwnPropertyDescriptors) {
74
- Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
75
- } else {
76
- ownKeys(Object(source)).forEach(function(key) {
77
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
78
- });
79
- }
80
- return target;
81
- }
82
- function _ts_generator(thisArg, body) {
83
- var f, y, t, g, _ = {
84
- label: 0,
85
- sent: function() {
86
- if (t[0] & 1) throw t[1];
87
- return t[1];
88
- },
89
- trys: [],
90
- ops: []
91
- };
92
- return(g = {
93
- next: verb(0),
94
- "throw": verb(1),
95
- "return": verb(2)
96
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
97
- return this;
98
- }), g);
99
- function verb(n) {
100
- return function(v) {
101
- return step([
102
- n,
103
- v
104
- ]);
105
- };
106
- }
107
- function step(op) {
108
- if (f) throw new TypeError("Generator is already executing.");
109
- while(_)try {
110
- 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;
111
- if (y = 0, t) op = [
112
- op[0] & 2,
113
- t.value
114
- ];
115
- switch(op[0]){
116
- case 0:
117
- case 1:
118
- t = op;
119
- break;
120
- case 4:
121
- _.label++;
122
- return {
123
- value: op[1],
124
- done: false
125
- };
126
- case 5:
127
- _.label++;
128
- y = op[1];
129
- op = [
130
- 0
131
- ];
132
- continue;
133
- case 7:
134
- op = _.ops.pop();
135
- _.trys.pop();
136
- continue;
137
- default:
138
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
139
- _ = 0;
140
- continue;
141
- }
142
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
143
- _.label = op[1];
144
- break;
145
- }
146
- if (op[0] === 6 && _.label < t[1]) {
147
- _.label = t[1];
148
- t = op;
149
- break;
150
- }
151
- if (t && _.label < t[2]) {
152
- _.label = t[2];
153
- _.ops.push(op);
154
- break;
155
- }
156
- if (t[2]) _.ops.pop();
157
- _.trys.pop();
158
- continue;
159
- }
160
- op = body.call(thisArg, _);
161
- } catch (e) {
162
- op = [
163
- 6,
164
- e
165
- ];
166
- y = 0;
167
- } finally{
168
- f = t = 0;
169
- }
170
- if (op[0] & 5) throw op[1];
171
- return {
172
- value: op[0] ? op[1] : void 0,
173
- done: true
174
- };
175
- }
176
- }
177
- import * as unfetch from "isomorphic-unfetch";
178
- import { JsonRpcProvider, tinyBig, toChecksumAddress } from "../../..";
179
- import { buildFetchInit, buildRPCPostBody } from "../../../classes/utils/fetchers";
180
- import { hexToDecimal } from "../../../classes/utils/hex-to-decimal";
181
- import { mockOf } from "../mock-of";
182
- import { rpcUrls } from "../rpc-urls";
183
- jest.mock("isomorphic-unfetch");
184
- var rpcUrl = rpcUrls.mainnet;
185
- var provider = new JsonRpcProvider(rpcUrl);
186
- var mockBlockResponse = {
187
- number: "0x1b4",
188
- hash: "0x5f6fb043528e9892679bce31e9e4a9c5773b3b1ebad1dc4c533ed6fe75ebe13d",
189
- parentHash: "0x4e61f7d8fc6253a08d0762dbb2d3d5f4a7e0a2394a2d29c4bbe7056aa13d48e8",
190
- nonce: "0xe04d296d2460cfb8472af2c5fd05b5a214109c25688d3704aed5484f9a7792f2",
191
- sha3Uncles: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
192
- logsBloom: "0x056e68544253...",
193
- transactionsRoot: "0x9156485c5d...",
194
- stateRoot: "0x2f8bde4d1b...",
195
- miner: "0x4e65fda2159562a496f9f3522f89122a3088497a",
196
- difficulty: "0x027f07",
197
- totalDifficulty: "0x027f07",
198
- extraData: "0x000000000000...",
199
- size: "0x027f07",
200
- gasLimit: "0x9f759",
201
- gasUsed: "0x9f759",
202
- timestamp: "0x54e34e8e",
203
- transactions: [],
204
- uncles: []
205
- };
206
- var mockRpcBlockResponse = JSON.stringify({
207
- jsonrpc: "2.0",
208
- id: 1,
209
- result: mockBlockResponse
210
- });
211
- var mockBlock = _object_spread_props(_object_spread({}, mockBlockResponse), {
212
- number: Number(hexToDecimal(mockBlockResponse.number)),
213
- miner: toChecksumAddress(mockBlockResponse.miner),
214
- totalDifficulty: tinyBig(mockBlockResponse.totalDifficulty),
215
- difficulty: tinyBig(mockBlockResponse.difficulty),
216
- gasLimit: tinyBig(mockBlockResponse.gasLimit),
217
- gasUsed: tinyBig(mockBlockResponse.gasUsed),
218
- size: tinyBig(mockBlockResponse.size),
219
- timestamp: tinyBig(mockBlockResponse.timestamp)
220
- });
221
- function runTest(method, params, responseIdentifier) {
222
- return _runTest.apply(this, arguments);
223
- }
224
- function _runTest() {
225
- _runTest = _async_to_generator(function(method, params, responseIdentifier) {
226
- var spy, result;
227
- return _ts_generator(this, function(_state) {
228
- switch(_state.label){
229
- case 0:
230
- jest.clearAllMocks();
231
- mockOf(unfetch.default).mockResolvedValueOnce({
232
- text: function() {
233
- return Promise.resolve(mockRpcBlockResponse);
234
- }
235
- });
236
- spy = jest.spyOn(unfetch, "default");
237
- return [
238
- 4,
239
- provider.getBlock(responseIdentifier)
240
- ];
241
- case 1:
242
- result = _state.sent();
243
- expect(spy).toHaveBeenCalledWith(rpcUrl, buildFetchInit(buildRPCPostBody(method, params)));
244
- expect(JSON.stringify(result)).toBe(JSON.stringify(mockBlock));
245
- return [
246
- 2
247
- ];
248
- }
249
- });
250
- });
251
- return _runTest.apply(this, arguments);
252
- }
253
- describe("provider.getBlock", function() {
254
- it("should match mocked -- latest", /*#__PURE__*/ _async_to_generator(function() {
255
- return _ts_generator(this, function(_state) {
256
- switch(_state.label){
257
- case 0:
258
- return [
259
- 4,
260
- runTest("eth_getBlockByNumber", [
261
- "latest",
262
- false
263
- ], "latest")
264
- ];
265
- case 1:
266
- _state.sent();
267
- return [
268
- 2
269
- ];
270
- }
271
- });
272
- }));
273
- it("should match mocked block -- earliest", /*#__PURE__*/ _async_to_generator(function() {
274
- return _ts_generator(this, function(_state) {
275
- switch(_state.label){
276
- case 0:
277
- return [
278
- 4,
279
- runTest("eth_getBlockByNumber", [
280
- "earliest",
281
- false
282
- ], "earliest")
283
- ];
284
- case 1:
285
- _state.sent();
286
- return [
287
- 2
288
- ];
289
- }
290
- });
291
- }));
292
- var blockNumber = 1000000; // a certain block number for testing
293
- it("should match mocked block -- specific block number as decimal integer. (block #".concat(blockNumber, ")"), /*#__PURE__*/ _async_to_generator(function() {
294
- return _ts_generator(this, function(_state) {
295
- switch(_state.label){
296
- case 0:
297
- return [
298
- 4,
299
- runTest("eth_getBlockByNumber", [
300
- tinyBig(blockNumber).toHexString(),
301
- false
302
- ], blockNumber)
303
- ];
304
- case 1:
305
- _state.sent();
306
- return [
307
- 2
308
- ];
309
- }
310
- });
311
- }));
312
- var blockHash = "0x4cbaa942e48a91108f38e2a250f6dbaff7fffe3027f5ebf76701929eed2b2970"; // Hash corresponds to block on RSK Mainnet
313
- it("should match mocked block -- block by hash. (hash = ".concat(blockHash, ")"), /*#__PURE__*/ _async_to_generator(function() {
314
- return _ts_generator(this, function(_state) {
315
- switch(_state.label){
316
- case 0:
317
- return [
318
- 4,
319
- runTest("eth_getBlockByHash", [
320
- blockHash,
321
- false
322
- ], blockHash)
323
- ];
324
- case 1:
325
- _state.sent();
326
- return [
327
- 2
328
- ];
329
- }
330
- });
331
- }));
332
- });
333
- describe("provider.getBlock error handling", function() {
334
- it("should handle empty 200 http response", /*#__PURE__*/ _async_to_generator(function() {
335
- var spy;
336
- return _ts_generator(this, function(_state) {
337
- switch(_state.label){
338
- case 0:
339
- mockOf(unfetch.default).mockResolvedValueOnce({
340
- text: function() {
341
- return Promise.resolve("200 OK");
342
- }
343
- });
344
- spy = jest.spyOn(unfetch, "default");
345
- return [
346
- 4,
347
- provider.getBlock("earliest").catch(function() {
348
- var _ref = _async_to_generator(function(error) {
349
- return _ts_generator(this, function(_state) {
350
- // error message is Invalid JSON RPC response: "200 OK"
351
- expect('Invalid JSON RPC response: "200 OK"').toBe(error.message);
352
- return [
353
- 2
354
- ];
355
- });
356
- });
357
- return function(error) {
358
- return _ref.apply(this, arguments);
359
- };
360
- }())
361
- ];
362
- case 1:
363
- _state.sent();
364
- expect(spy).toHaveBeenCalledWith(rpcUrl, buildFetchInit(buildRPCPostBody("eth_getBlockByNumber", [
365
- "earliest",
366
- false
367
- ])));
368
- return [
369
- 2
370
- ];
371
- }
372
- });
373
- }));
374
- it("should handle empty JSON object", /*#__PURE__*/ _async_to_generator(function() {
375
- var spy;
376
- return _ts_generator(this, function(_state) {
377
- switch(_state.label){
378
- case 0:
379
- mockOf(unfetch.default).mockResolvedValueOnce({
380
- text: function() {
381
- return Promise.resolve("{}");
382
- }
383
- });
384
- spy = jest.spyOn(unfetch, "default");
385
- return [
386
- 4,
387
- provider.getBlock("earliest").catch(function() {
388
- var _ref = _async_to_generator(function(error) {
389
- return _ts_generator(this, function(_state) {
390
- // error message is Invalid JSON RPC response: {}
391
- expect(error.message).toBe("Invalid JSON RPC response: {}");
392
- return [
393
- 2
394
- ];
395
- });
396
- });
397
- return function(error) {
398
- return _ref.apply(this, arguments);
399
- };
400
- }())
401
- ];
402
- case 1:
403
- _state.sent();
404
- expect(spy).toHaveBeenCalledWith(rpcUrl, buildFetchInit(buildRPCPostBody("eth_getBlockByNumber", [
405
- "earliest",
406
- false
407
- ])));
408
- return [
409
- 2
410
- ];
411
- }
412
- });
413
- }));
414
- });
@@ -1,282 +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 _async_to_generator(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
- function _ts_generator(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 * as unfetch from "isomorphic-unfetch";
126
- import { buildFetchInit, buildRPCPostBody } from "../../../classes/utils/fetchers";
127
- import { JsonRpcProvider, tinyBig } from "../../../index";
128
- import { rpcUrls } from "./../rpc-urls";
129
- // Using Polygon to be able to access archive blocks
130
- // Choosing to use Ethereum mainnet means that as new blocks are generated, block numbers used in testing may be inaccessible and cause tests to fail
131
- var rpcUrl = rpcUrls.matic;
132
- jest.mock("isomorphic-unfetch");
133
- var validInputs = [
134
- {
135
- address: "0x00153ab45951268d8813BCAb403152A059B99CB1",
136
- blockTag: undefined
137
- },
138
- {
139
- address: "0xF6c506F64Fa4bbF64a6b4539506abadF8C7f16b8",
140
- blockTag: "latest"
141
- },
142
- {
143
- address: "0x97f589D427c4DFA48e3F3F50Ff0C5b49334DdE22",
144
- blockTag: "0xe1e51d"
145
- },
146
- {
147
- address: "0x3c9D4Ea65b59BEa7178c62d403d560f938221f9d",
148
- blockTag: 28114328
149
- }
150
- ];
151
- var invalidInput = {
152
- address: "0xd31a02A126Bb7ACD359BD61E9a8276959408855E",
153
- blockTag: 28314328
154
- };
155
- var mockCodeResult = "0x06060060600606006060060600606006060";
156
- var mockInvalidResult = "0x";
157
- var provider = new JsonRpcProvider(rpcUrl);
158
- function testGetCode(input, mockResult) {
159
- return _testGetCode.apply(this, arguments);
160
- }
161
- function _testGetCode() {
162
- _testGetCode = _async_to_generator(function(input, mockResult) {
163
- var spy, code, _input_blockTag, expectedBlockTag;
164
- return _ts_generator(this, function(_state) {
165
- switch(_state.label){
166
- case 0:
167
- spy = jest.spyOn(unfetch, "default");
168
- spy.mockResolvedValueOnce({
169
- text: function() {
170
- return Promise.resolve(JSON.stringify({
171
- jsonrpc: "2.0",
172
- id: 1,
173
- result: mockResult
174
- }));
175
- }
176
- });
177
- return [
178
- 4,
179
- provider.getCode(input.address, input.blockTag)
180
- ];
181
- case 1:
182
- code = _state.sent();
183
- expect(code).toBe(mockResult);
184
- expectedBlockTag = typeof input.blockTag === "number" ? tinyBig(input.blockTag).toHexString() : (_input_blockTag = input.blockTag) !== null && _input_blockTag !== void 0 ? _input_blockTag : "latest";
185
- expect(spy).toHaveBeenCalledWith(rpcUrl, buildFetchInit(buildRPCPostBody("eth_getCode", [
186
- input.address,
187
- expectedBlockTag
188
- ])));
189
- return [
190
- 2
191
- ];
192
- }
193
- });
194
- });
195
- return _testGetCode.apply(this, arguments);
196
- }
197
- describe("provider.getCode with Mock", function() {
198
- it("should return the correct code for the given input", /*#__PURE__*/ _async_to_generator(function() {
199
- var _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, input, err;
200
- return _ts_generator(this, function(_state) {
201
- switch(_state.label){
202
- case 0:
203
- _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
204
- _state.label = 1;
205
- case 1:
206
- _state.trys.push([
207
- 1,
208
- 6,
209
- 7,
210
- 8
211
- ]);
212
- _iterator = validInputs[Symbol.iterator]();
213
- _state.label = 2;
214
- case 2:
215
- if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
216
- 3,
217
- 5
218
- ];
219
- input = _step.value;
220
- return [
221
- 4,
222
- testGetCode(input, mockCodeResult)
223
- ];
224
- case 3:
225
- _state.sent();
226
- _state.label = 4;
227
- case 4:
228
- _iteratorNormalCompletion = true;
229
- return [
230
- 3,
231
- 2
232
- ];
233
- case 5:
234
- return [
235
- 3,
236
- 8
237
- ];
238
- case 6:
239
- err = _state.sent();
240
- _didIteratorError = true;
241
- _iteratorError = err;
242
- return [
243
- 3,
244
- 8
245
- ];
246
- case 7:
247
- try {
248
- if (!_iteratorNormalCompletion && _iterator.return != null) {
249
- _iterator.return();
250
- }
251
- } finally{
252
- if (_didIteratorError) {
253
- throw _iteratorError;
254
- }
255
- }
256
- return [
257
- 7
258
- ];
259
- case 8:
260
- return [
261
- 2
262
- ];
263
- }
264
- });
265
- }));
266
- it("should return `0x` when a contract does not exist", /*#__PURE__*/ _async_to_generator(function() {
267
- return _ts_generator(this, function(_state) {
268
- switch(_state.label){
269
- case 0:
270
- return [
271
- 4,
272
- testGetCode(invalidInput, mockInvalidResult)
273
- ];
274
- case 1:
275
- _state.sent();
276
- return [
277
- 2
278
- ];
279
- }
280
- });
281
- }));
282
- });