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,11 +1,3 @@
1
- function _arrayLikeToArray(arr, len) {
2
- if (len == null || len > arr.length) len = arr.length;
3
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
- return arr2;
5
- }
6
- function _arrayWithHoles(arr) {
7
- if (Array.isArray(arr)) return arr;
8
- }
9
1
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
10
2
  try {
11
3
  var info = gen[key](arg);
@@ -20,7 +12,7 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
20
12
  Promise.resolve(value).then(_next, _throw);
21
13
  }
22
14
  }
23
- function _asyncToGenerator(fn) {
15
+ function _async_to_generator(fn) {
24
16
  return function() {
25
17
  var self = this, args = arguments;
26
18
  return new Promise(function(resolve, reject) {
@@ -35,7 +27,7 @@ function _asyncToGenerator(fn) {
35
27
  });
36
28
  };
37
29
  }
38
- function _defineProperty(obj, key, value) {
30
+ function _define_property(obj, key, value) {
39
31
  if (key in obj) {
40
32
  Object.defineProperty(obj, key, {
41
33
  value: value,
@@ -48,34 +40,7 @@ function _defineProperty(obj, key, value) {
48
40
  }
49
41
  return obj;
50
42
  }
51
- function _iterableToArrayLimit(arr, i) {
52
- var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
53
- if (_i == null) return;
54
- var _arr = [];
55
- var _n = true;
56
- var _d = false;
57
- var _s, _e;
58
- try {
59
- for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
60
- _arr.push(_s.value);
61
- if (i && _arr.length === i) break;
62
- }
63
- } catch (err) {
64
- _d = true;
65
- _e = err;
66
- } finally{
67
- try {
68
- if (!_n && _i["return"] != null) _i["return"]();
69
- } finally{
70
- if (_d) throw _e;
71
- }
72
- }
73
- return _arr;
74
- }
75
- function _nonIterableRest() {
76
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
77
- }
78
- function _objectSpread(target) {
43
+ function _object_spread(target) {
79
44
  for(var i = 1; i < arguments.length; i++){
80
45
  var source = arguments[i] != null ? arguments[i] : {};
81
46
  var ownKeys = Object.keys(source);
@@ -85,7 +50,7 @@ function _objectSpread(target) {
85
50
  }));
86
51
  }
87
52
  ownKeys.forEach(function(key) {
88
- _defineProperty(target, key, source[key]);
53
+ _define_property(target, key, source[key]);
89
54
  });
90
55
  }
91
56
  return target;
@@ -103,7 +68,7 @@ function ownKeys(object, enumerableOnly) {
103
68
  }
104
69
  return keys;
105
70
  }
106
- function _objectSpreadProps(target, source) {
71
+ function _object_spread_props(target, source) {
107
72
  source = source != null ? source : {};
108
73
  if (Object.getOwnPropertyDescriptors) {
109
74
  Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
@@ -114,18 +79,7 @@ function _objectSpreadProps(target, source) {
114
79
  }
115
80
  return target;
116
81
  }
117
- function _slicedToArray(arr, i) {
118
- return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
119
- }
120
- function _unsupportedIterableToArray(o, minLen) {
121
- if (!o) return;
122
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
123
- var n = Object.prototype.toString.call(o).slice(8, -1);
124
- if (n === "Object" && o.constructor) n = o.constructor.name;
125
- if (n === "Map" || n === "Set") return Array.from(n);
126
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
127
- }
128
- var __generator = this && this.__generator || function(thisArg, body) {
82
+ function _ts_generator(thisArg, body) {
129
83
  var f, y, t, g, _ = {
130
84
  label: 0,
131
85
  sent: function() {
@@ -219,14 +173,17 @@ var __generator = this && this.__generator || function(thisArg, body) {
219
173
  done: true
220
174
  };
221
175
  }
222
- };
176
+ }
223
177
  import Big from "big.js";
224
- import { ethers } from "ethers";
225
- import Web3 from "web3";
178
+ import * as unfetch from "isomorphic-unfetch";
226
179
  import { JsonRpcProvider, tinyBig } from "../../..";
180
+ import { buildFetchInit, buildRPCPostBody } from "../../../classes/utils/fetchers";
227
181
  import { hexToDecimal } from "../../../classes/utils/hex-to-decimal";
182
+ import { prepareTransaction } from "../../../classes/utils/prepare-transaction";
183
+ import { mockOf } from "../mock-of";
228
184
  import { rpcUrls } from "./../rpc-urls";
229
185
  var rpcUrl = rpcUrls.mainnet;
186
+ jest.mock("isomorphic-unfetch");
230
187
  // Based on https://etherscan.io/tx/0x277c40de5bf1d4fa06e37dce8e1370dac7273a4b2a883515176f51abaa50d512
231
188
  var dataTo = {
232
189
  data: "0x70a082310000000000000000000000006E0d01A76C3Cf4288372a29124A26D4353EE51BE",
@@ -246,16 +203,14 @@ var dataFromGasTo = {
246
203
  maxFeePerGas: "0xffffffffff"
247
204
  };
248
205
  describe("provider.call", function() {
249
- var essentialEthProvider = new JsonRpcProvider(rpcUrl);
250
- var web3Provider = new Web3(rpcUrl);
251
- var ethersProvider = new ethers.providers.StaticJsonRpcProvider(rpcUrl);
252
- it("throws", /*#__PURE__*/ _asyncToGenerator(function() {
253
- return __generator(this, function(_state) {
206
+ var provider = new JsonRpcProvider(rpcUrl);
207
+ it("throws", /*#__PURE__*/ _async_to_generator(function() {
208
+ return _ts_generator(this, function(_state) {
254
209
  switch(_state.label){
255
210
  case 0:
256
211
  return [
257
212
  4,
258
- expect(essentialEthProvider.call(_objectSpreadProps(_objectSpread({}, dataTo), {
213
+ expect(provider.call(_object_spread_props(_object_spread({}, dataTo), {
259
214
  maxFeePerGas: "0x12",
260
215
  maxPriorityFeePerGas: "0x123"
261
216
  }))).rejects.toThrow()
@@ -264,7 +219,7 @@ describe("provider.call", function() {
264
219
  _state.sent();
265
220
  return [
266
221
  4,
267
- expect(essentialEthProvider.call(_objectSpreadProps(_objectSpread({}, dataTo), {
222
+ expect(provider.call(_object_spread_props(_object_spread({}, dataTo), {
268
223
  gasPrice: "0xfffffff",
269
224
  maxFeePerGas: "0x12"
270
225
  }))).rejects.toThrow()
@@ -273,7 +228,7 @@ describe("provider.call", function() {
273
228
  _state.sent();
274
229
  return [
275
230
  4,
276
- expect(essentialEthProvider.call(_objectSpreadProps(_objectSpread({}, dataTo), {
231
+ expect(provider.call(_object_spread_props(_object_spread({}, dataTo), {
277
232
  gasPrice: "0xfffffff",
278
233
  maxPriorityFeePerGas: "0x123"
279
234
  }))).rejects.toThrow()
@@ -286,147 +241,131 @@ describe("provider.call", function() {
286
241
  }
287
242
  });
288
243
  }));
289
- it("should match ethers.js -- data, to", /*#__PURE__*/ _asyncToGenerator(function() {
290
- var _ref, eeCall, ethersCall, web3Call;
291
- return __generator(this, function(_state) {
244
+ function testWithMockedResponse(data) {
245
+ return _testWithMockedResponse.apply(this, arguments);
246
+ }
247
+ function _testWithMockedResponse() {
248
+ _testWithMockedResponse = _async_to_generator(function(data) {
249
+ var expectedResult, spy, callProvider;
250
+ return _ts_generator(this, function(_state) {
251
+ switch(_state.label){
252
+ case 0:
253
+ expectedResult = "0x0000000000000000000000000000000000000000000000000858898f93629000";
254
+ mockOf(unfetch.default).mockResolvedValueOnce({
255
+ text: function() {
256
+ return Promise.resolve(JSON.stringify({
257
+ jsonrpc: "2.0",
258
+ id: 1,
259
+ result: expectedResult
260
+ }));
261
+ }
262
+ });
263
+ spy = jest.spyOn(unfetch, "default");
264
+ return [
265
+ 4,
266
+ provider.call(data)
267
+ ];
268
+ case 1:
269
+ callProvider = _state.sent();
270
+ expect(callProvider).toBe(expectedResult);
271
+ expect(spy).toHaveBeenCalledWith(rpcUrl, buildFetchInit(buildRPCPostBody("eth_call", [
272
+ prepareTransaction(data),
273
+ "latest"
274
+ ])));
275
+ return [
276
+ 2
277
+ ];
278
+ }
279
+ });
280
+ });
281
+ return _testWithMockedResponse.apply(this, arguments);
282
+ }
283
+ it("should return a valid response for given input -- data, to", /*#__PURE__*/ _async_to_generator(function() {
284
+ return _ts_generator(this, function(_state) {
292
285
  switch(_state.label){
293
286
  case 0:
294
287
  return [
295
288
  4,
296
- Promise.all([
297
- essentialEthProvider.call(dataTo),
298
- ethersProvider.call(dataTo),
299
- web3Provider.eth.call(dataTo)
300
- ])
289
+ testWithMockedResponse(dataTo)
301
290
  ];
302
291
  case 1:
303
- _ref = _slicedToArray.apply(void 0, [
304
- _state.sent(),
305
- 3
306
- ]), eeCall = _ref[0], ethersCall = _ref[1], web3Call = _ref[2];
307
- expect(eeCall).toBe(ethersCall);
308
- expect(eeCall).toBe(web3Call);
292
+ _state.sent();
309
293
  return [
310
294
  2
311
295
  ];
312
296
  }
313
297
  });
314
298
  }));
315
- it("should match ethers.js -- data, to, gasPrice", /*#__PURE__*/ _asyncToGenerator(function() {
316
- var data, _ref, eeCall, ethersCall, web3Call;
317
- return __generator(this, function(_state) {
299
+ it("should return a valid response for given input -- data, to, gasPrice", /*#__PURE__*/ _async_to_generator(function() {
300
+ var data;
301
+ return _ts_generator(this, function(_state) {
318
302
  switch(_state.label){
319
303
  case 0:
320
- data = _objectSpreadProps(_objectSpread({}, dataTo), {
304
+ data = _object_spread_props(_object_spread({}, dataTo), {
321
305
  gasPrice: 99999999999
322
306
  });
323
307
  return [
324
308
  4,
325
- Promise.all([
326
- essentialEthProvider.call(data),
327
- ethersProvider.call(data),
328
- web3Provider.eth.call(data)
329
- ])
309
+ testWithMockedResponse(data)
330
310
  ];
331
311
  case 1:
332
- _ref = _slicedToArray.apply(void 0, [
333
- _state.sent(),
334
- 3
335
- ]), eeCall = _ref[0], ethersCall = _ref[1], web3Call = _ref[2];
336
- expect(eeCall).toBe(ethersCall);
337
- expect(eeCall).toBe(web3Call);
312
+ _state.sent();
338
313
  return [
339
314
  2
340
315
  ];
341
316
  }
342
317
  });
343
318
  }));
344
- it("should match ethers.js -- all mixed data as strings", /*#__PURE__*/ _asyncToGenerator(function() {
345
- var _ref, eeCall, ethersCall, web3Call;
346
- return __generator(this, function(_state) {
319
+ it("should return a valid response for given input -- all mixed data as strings", /*#__PURE__*/ _async_to_generator(function() {
320
+ return _ts_generator(this, function(_state) {
347
321
  switch(_state.label){
348
322
  case 0:
349
323
  return [
350
324
  4,
351
- Promise.all([
352
- essentialEthProvider.call(dataFromGasTo),
353
- ethersProvider.call(dataFromGasTo),
354
- web3Provider.eth.call(_objectSpreadProps(_objectSpread({}, dataFromGasTo), {
355
- nonce: Number(hexToDecimal(dataFromGasTo.nonce))
356
- }))
357
- ])
325
+ testWithMockedResponse(dataFromGasTo)
358
326
  ];
359
327
  case 1:
360
- _ref = _slicedToArray.apply(void 0, [
361
- _state.sent(),
362
- 3
363
- ]), eeCall = _ref[0], ethersCall = _ref[1], web3Call = _ref[2];
364
- expect(eeCall).toBe(ethersCall);
365
- expect(eeCall).toBe(web3Call);
328
+ _state.sent();
366
329
  return [
367
330
  2
368
331
  ];
369
332
  }
370
333
  });
371
334
  }));
372
- it("should match ethers.js -- all mixed data as TinyBig", /*#__PURE__*/ _asyncToGenerator(function() {
373
- var _ref, eeCall, ethersCall, web3Call;
374
- return __generator(this, function(_state) {
335
+ it("should return a valid response for given input -- all mixed data as TinyBig", /*#__PURE__*/ _async_to_generator(function() {
336
+ return _ts_generator(this, function(_state) {
375
337
  switch(_state.label){
376
338
  case 0:
377
339
  return [
378
340
  4,
379
- Promise.all([
380
- essentialEthProvider.call(_objectSpreadProps(_objectSpread({}, dataFromGasTo), {
381
- nonce: tinyBig(dataFromGasTo.nonce),
382
- gas: tinyBig(dataFromGasTo.gas),
383
- value: tinyBig(dataFromGasTo.value)
384
- })),
385
- ethersProvider.call(dataFromGasTo),
386
- web3Provider.eth.call(_objectSpreadProps(_objectSpread({}, dataFromGasTo), {
387
- nonce: Number(hexToDecimal(dataFromGasTo.nonce))
388
- }))
389
- ])
341
+ testWithMockedResponse(_object_spread_props(_object_spread({}, dataFromGasTo), {
342
+ nonce: tinyBig(dataFromGasTo.nonce),
343
+ gas: tinyBig(dataFromGasTo.gas),
344
+ value: tinyBig(dataFromGasTo.value)
345
+ }))
390
346
  ];
391
347
  case 1:
392
- _ref = _slicedToArray.apply(void 0, [
393
- _state.sent(),
394
- 3
395
- ]), eeCall = _ref[0], ethersCall = _ref[1], web3Call = _ref[2];
396
- expect(eeCall).toBe(ethersCall);
397
- expect(eeCall).toBe(web3Call);
348
+ _state.sent();
398
349
  return [
399
350
  2
400
351
  ];
401
352
  }
402
353
  });
403
354
  }));
404
- it("should match ethers.js -- all mixeddata as Big", /*#__PURE__*/ _asyncToGenerator(function() {
405
- var _ref, eeCall, ethersCall, web3Call;
406
- return __generator(this, function(_state) {
355
+ it("should return a valid response for given input -- all mixed data as Big", /*#__PURE__*/ _async_to_generator(function() {
356
+ return _ts_generator(this, function(_state) {
407
357
  switch(_state.label){
408
358
  case 0:
409
359
  return [
410
360
  4,
411
- Promise.all([
412
- essentialEthProvider.call(_objectSpreadProps(_objectSpread({}, dataFromGasTo), {
413
- nonce: new Big(hexToDecimal(dataFromGasTo.nonce)),
414
- gas: new Big(dataFromGasTo.gas),
415
- value: new Big(hexToDecimal(dataFromGasTo.value))
416
- })),
417
- ethersProvider.call(dataFromGasTo),
418
- web3Provider.eth.call(_objectSpreadProps(_objectSpread({}, dataFromGasTo), {
419
- nonce: Number(hexToDecimal(dataFromGasTo.nonce))
420
- }))
421
- ])
361
+ testWithMockedResponse(_object_spread_props(_object_spread({}, dataFromGasTo), {
362
+ nonce: new Big(hexToDecimal(dataFromGasTo.nonce)),
363
+ gas: new Big(dataFromGasTo.gas),
364
+ value: new Big(hexToDecimal(dataFromGasTo.value))
365
+ }))
422
366
  ];
423
367
  case 1:
424
- _ref = _slicedToArray.apply(void 0, [
425
- _state.sent(),
426
- 3
427
- ]), eeCall = _ref[0], ethersCall = _ref[1], web3Call = _ref[2];
428
- expect(eeCall).toBe(ethersCall);
429
- expect(eeCall).toBe(web3Call);
368
+ _state.sent();
430
369
  return [
431
370
  2
432
371
  ];
@@ -1,11 +1,3 @@
1
- function _arrayLikeToArray(arr, len) {
2
- if (len == null || len > arr.length) len = arr.length;
3
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
- return arr2;
5
- }
6
- function _arrayWithHoles(arr) {
7
- if (Array.isArray(arr)) return arr;
8
- }
9
1
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
10
2
  try {
11
3
  var info = gen[key](arg);
@@ -20,7 +12,7 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
20
12
  Promise.resolve(value).then(_next, _throw);
21
13
  }
22
14
  }
23
- function _asyncToGenerator(fn) {
15
+ function _async_to_generator(fn) {
24
16
  return function() {
25
17
  var self = this, args = arguments;
26
18
  return new Promise(function(resolve, reject) {
@@ -35,45 +27,7 @@ function _asyncToGenerator(fn) {
35
27
  });
36
28
  };
37
29
  }
38
- function _iterableToArrayLimit(arr, i) {
39
- var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
40
- if (_i == null) return;
41
- var _arr = [];
42
- var _n = true;
43
- var _d = false;
44
- var _s, _e;
45
- try {
46
- for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
47
- _arr.push(_s.value);
48
- if (i && _arr.length === i) break;
49
- }
50
- } catch (err) {
51
- _d = true;
52
- _e = err;
53
- } finally{
54
- try {
55
- if (!_n && _i["return"] != null) _i["return"]();
56
- } finally{
57
- if (_d) throw _e;
58
- }
59
- }
60
- return _arr;
61
- }
62
- function _nonIterableRest() {
63
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
64
- }
65
- function _slicedToArray(arr, i) {
66
- return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
67
- }
68
- function _unsupportedIterableToArray(o, minLen) {
69
- if (!o) return;
70
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
71
- var n = Object.prototype.toString.call(o).slice(8, -1);
72
- if (n === "Object" && o.constructor) n = o.constructor.name;
73
- if (n === "Map" || n === "Set") return Array.from(n);
74
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
75
- }
76
- var __generator = this && this.__generator || function(thisArg, body) {
30
+ function _ts_generator(thisArg, body) {
77
31
  var f, y, t, g, _ = {
78
32
  label: 0,
79
33
  sent: function() {
@@ -167,12 +121,15 @@ var __generator = this && this.__generator || function(thisArg, body) {
167
121
  done: true
168
122
  };
169
123
  }
170
- };
171
- import { ethers } from "ethers";
172
- import Web3 from "web3";
124
+ }
125
+ import * as unfetch from "isomorphic-unfetch";
173
126
  import { JsonRpcProvider } from "../../..";
127
+ import { buildFetchInit, buildRPCPostBody } from "../../../classes/utils/fetchers";
128
+ import { prepareTransaction } from "../../../classes/utils/prepare-transaction";
174
129
  import { etherToWei } from "../../../utils/ether-to-wei";
130
+ import { mockOf } from "../mock-of";
175
131
  import { rpcUrls } from "../rpc-urls";
132
+ jest.mock("isomorphic-unfetch");
176
133
  var rpcUrl = rpcUrls.mainnet;
177
134
  var dataTo = {
178
135
  to: "0x4976fb03C32e5B8cfe2b6cCB31c09Ba78EBaBa41",
@@ -185,100 +142,72 @@ var dataToValue = {
185
142
  data: "0xd0e30db0",
186
143
  value: etherToWei(0.001).toNumber()
187
144
  };
188
- describe("provider.estimateGas", function() {
189
- var essentialEthProvider = new JsonRpcProvider(rpcUrl);
190
- var web3Provider = new Web3(rpcUrl);
191
- var ethersProvider = new ethers.providers.StaticJsonRpcProvider(rpcUrl);
192
- it("should match ethers.js -- data, to", /*#__PURE__*/ _asyncToGenerator(function() {
193
- var _ref, eeEstimateGas, ethersEstimateGas;
194
- return __generator(this, function(_state) {
195
- switch(_state.label){
196
- case 0:
197
- return [
198
- 4,
199
- Promise.all([
200
- essentialEthProvider.estimateGas(dataTo),
201
- ethersProvider.estimateGas(dataTo)
202
- ])
203
- ];
204
- case 1:
205
- _ref = _slicedToArray.apply(void 0, [
206
- _state.sent(),
207
- 2
208
- ]), eeEstimateGas = _ref[0], ethersEstimateGas = _ref[1];
209
- expect(eeEstimateGas.toString()).toBe(ethersEstimateGas.toString());
210
- return [
211
- 2
212
- ];
213
- }
214
- });
215
- }));
216
- it("should match web3.js -- data, to", /*#__PURE__*/ _asyncToGenerator(function() {
217
- var _ref, eeEstimateGas, web3EstimateGas;
218
- return __generator(this, function(_state) {
145
+ function testEstimateGas(transaction) {
146
+ return _testEstimateGas.apply(this, arguments);
147
+ }
148
+ function _testEstimateGas() {
149
+ _testEstimateGas = _async_to_generator(function(transaction) {
150
+ var provider, mockPostResponse, spy, estimatedGas;
151
+ return _ts_generator(this, function(_state) {
219
152
  switch(_state.label){
220
153
  case 0:
154
+ provider = new JsonRpcProvider(rpcUrl);
155
+ mockPostResponse = JSON.stringify({
156
+ jsonrpc: "2.0",
157
+ id: 1,
158
+ result: "0xa"
159
+ });
160
+ mockOf(unfetch.default).mockResolvedValueOnce({
161
+ text: function() {
162
+ return Promise.resolve(mockPostResponse);
163
+ }
164
+ });
165
+ spy = jest.spyOn(unfetch, "default");
221
166
  return [
222
167
  4,
223
- Promise.all([
224
- essentialEthProvider.estimateGas(dataTo),
225
- web3Provider.eth.estimateGas(dataTo)
226
- ])
168
+ provider.estimateGas(transaction)
227
169
  ];
228
170
  case 1:
229
- _ref = _slicedToArray.apply(void 0, [
230
- _state.sent(),
231
- 2
232
- ]), eeEstimateGas = _ref[0], web3EstimateGas = _ref[1];
233
- expect(eeEstimateGas.toString()).toBe(web3EstimateGas.toString());
171
+ estimatedGas = _state.sent();
172
+ expect(estimatedGas.toString()).toBe("10");
173
+ expect(spy).toHaveBeenCalledWith(rpcUrl, buildFetchInit(buildRPCPostBody("eth_estimateGas", [
174
+ prepareTransaction(transaction)
175
+ ])));
234
176
  return [
235
177
  2
236
178
  ];
237
179
  }
238
180
  });
239
- }));
240
- it("should match ethers.js -- data, to, value", /*#__PURE__*/ _asyncToGenerator(function() {
241
- var _ref, eeEstimateGas, ethersEstimateGas;
242
- return __generator(this, function(_state) {
181
+ });
182
+ return _testEstimateGas.apply(this, arguments);
183
+ }
184
+ describe("provider.estimateGas", function() {
185
+ it("should estimate gas with data and to", /*#__PURE__*/ _async_to_generator(function() {
186
+ return _ts_generator(this, function(_state) {
243
187
  switch(_state.label){
244
188
  case 0:
245
189
  return [
246
190
  4,
247
- Promise.all([
248
- essentialEthProvider.estimateGas(dataToValue),
249
- ethersProvider.estimateGas(dataToValue)
250
- ])
191
+ testEstimateGas(dataTo)
251
192
  ];
252
193
  case 1:
253
- _ref = _slicedToArray.apply(void 0, [
254
- _state.sent(),
255
- 2
256
- ]), eeEstimateGas = _ref[0], ethersEstimateGas = _ref[1];
257
- expect(eeEstimateGas.toString()).toBe(ethersEstimateGas.toString());
194
+ _state.sent();
258
195
  return [
259
196
  2
260
197
  ];
261
198
  }
262
199
  });
263
200
  }));
264
- it("should match web3.js -- data, to, value", /*#__PURE__*/ _asyncToGenerator(function() {
265
- var _ref, eeEstimateGas, web3EstimateGas;
266
- return __generator(this, function(_state) {
201
+ it("should estimate gas with data, to, and value", /*#__PURE__*/ _async_to_generator(function() {
202
+ return _ts_generator(this, function(_state) {
267
203
  switch(_state.label){
268
204
  case 0:
269
205
  return [
270
206
  4,
271
- Promise.all([
272
- essentialEthProvider.estimateGas(dataToValue),
273
- web3Provider.eth.estimateGas(dataToValue)
274
- ])
207
+ testEstimateGas(dataToValue)
275
208
  ];
276
209
  case 1:
277
- _ref = _slicedToArray.apply(void 0, [
278
- _state.sent(),
279
- 2
280
- ]), eeEstimateGas = _ref[0], web3EstimateGas = _ref[1];
281
- expect(eeEstimateGas.toString()).toBe(web3EstimateGas.toString());
210
+ _state.sent();
282
211
  return [
283
212
  2
284
213
  ];