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,477 +0,0 @@
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
- function _arrayWithoutHoles(arr) {
10
- if (Array.isArray(arr)) return _arrayLikeToArray(arr);
11
- }
12
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
13
- try {
14
- var info = gen[key](arg);
15
- var value = info.value;
16
- } catch (error) {
17
- reject(error);
18
- return;
19
- }
20
- if (info.done) {
21
- resolve(value);
22
- } else {
23
- Promise.resolve(value).then(_next, _throw);
24
- }
25
- }
26
- function _asyncToGenerator(fn) {
27
- return function() {
28
- var self = this, args = arguments;
29
- return new Promise(function(resolve, reject) {
30
- var gen = fn.apply(self, args);
31
- function _next(value) {
32
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
33
- }
34
- function _throw(err) {
35
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
36
- }
37
- _next(undefined);
38
- });
39
- };
40
- }
41
- function _iterableToArray(iter) {
42
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
43
- }
44
- function _iterableToArrayLimit(arr, i) {
45
- var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
46
- if (_i == null) return;
47
- var _arr = [];
48
- var _n = true;
49
- var _d = false;
50
- var _s, _e;
51
- try {
52
- for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
53
- _arr.push(_s.value);
54
- if (i && _arr.length === i) break;
55
- }
56
- } catch (err) {
57
- _d = true;
58
- _e = err;
59
- } finally{
60
- try {
61
- if (!_n && _i["return"] != null) _i["return"]();
62
- } finally{
63
- if (_d) throw _e;
64
- }
65
- }
66
- return _arr;
67
- }
68
- function _nonIterableRest() {
69
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
70
- }
71
- function _nonIterableSpread() {
72
- throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
73
- }
74
- function _slicedToArray(arr, i) {
75
- return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
76
- }
77
- function _toConsumableArray(arr) {
78
- return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
79
- }
80
- function _unsupportedIterableToArray(o, minLen) {
81
- if (!o) return;
82
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
83
- var n = Object.prototype.toString.call(o).slice(8, -1);
84
- if (n === "Object" && o.constructor) n = o.constructor.name;
85
- if (n === "Map" || n === "Set") return Array.from(n);
86
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
87
- }
88
- var __generator = this && this.__generator || function(thisArg, body) {
89
- var f, y, t, g, _ = {
90
- label: 0,
91
- sent: function() {
92
- if (t[0] & 1) throw t[1];
93
- return t[1];
94
- },
95
- trys: [],
96
- ops: []
97
- };
98
- return(g = {
99
- next: verb(0),
100
- "throw": verb(1),
101
- "return": verb(2)
102
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
103
- return this;
104
- }), g);
105
- function verb(n) {
106
- return function(v) {
107
- return step([
108
- n,
109
- v
110
- ]);
111
- };
112
- }
113
- function step(op) {
114
- if (f) throw new TypeError("Generator is already executing.");
115
- while(_)try {
116
- 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;
117
- if (y = 0, t) op = [
118
- op[0] & 2,
119
- t.value
120
- ];
121
- switch(op[0]){
122
- case 0:
123
- case 1:
124
- t = op;
125
- break;
126
- case 4:
127
- _.label++;
128
- return {
129
- value: op[1],
130
- done: false
131
- };
132
- case 5:
133
- _.label++;
134
- y = op[1];
135
- op = [
136
- 0
137
- ];
138
- continue;
139
- case 7:
140
- op = _.ops.pop();
141
- _.trys.pop();
142
- continue;
143
- default:
144
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
145
- _ = 0;
146
- continue;
147
- }
148
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
149
- _.label = op[1];
150
- break;
151
- }
152
- if (op[0] === 6 && _.label < t[1]) {
153
- _.label = t[1];
154
- t = op;
155
- break;
156
- }
157
- if (t && _.label < t[2]) {
158
- _.label = t[2];
159
- _.ops.push(op);
160
- break;
161
- }
162
- if (t[2]) _.ops.pop();
163
- _.trys.pop();
164
- continue;
165
- }
166
- op = body.call(thisArg, _);
167
- } catch (e) {
168
- op = [
169
- 6,
170
- e
171
- ];
172
- y = 0;
173
- } finally{
174
- f = t = 0;
175
- }
176
- if (op[0] & 5) throw op[1];
177
- return {
178
- value: op[0] ? op[1] : void 0,
179
- done: true
180
- };
181
- }
182
- };
183
- import { ethers } from "ethers";
184
- import omit from "just-omit";
185
- import Web3 from "web3";
186
- import { JsonRpcProvider } from "../../..";
187
- import { fakeUrls } from "./../rpc-urls";
188
- // RSK has 30 second block times so tests pass more often
189
- var rpcUrl = "https://public-node.rsk.co";
190
- function testBlockEquality(eeBlock, otherBlock) {
191
- var typeCheckKeys = [
192
- "difficulty",
193
- "gasLimit",
194
- "gasUsed",
195
- "number",
196
- "timestamp"
197
- ];
198
- var omittableEE = [];
199
- var omittableOther = [];
200
- if (typeof otherBlock.gasLimit === "number") {
201
- // web3.js returns gasLimit as number, ethers returns as BigNum
202
- if (eeBlock.transactions && typeof eeBlock.transactions[0] !== "string") {
203
- eeBlock.transactions.forEach(function(transaction) {
204
- if (transaction.gas) transaction.gas = transaction.gas.toString();
205
- if (transaction.value) transaction.value = transaction.value.toString();
206
- if (transaction.gasPrice) transaction.gasPrice = transaction.gasPrice.toString();
207
- if (transaction.nonce) transaction.nonce = transaction.nonce.toString();
208
- if (transaction.v) transaction.v = "0x".concat(transaction.v.toString(16));
209
- });
210
- otherBlock.transactions.forEach(function(transaction) {
211
- if (transaction.gas) transaction.gas = transaction.gas.toString();
212
- else if (transaction.gas == 0) transaction.gas = "0"; // won't go to string when zero??
213
- if (transaction.nonce) transaction.nonce = transaction.nonce.toString();
214
- });
215
- }
216
- typeCheckKeys.push("totalDifficulty", "size");
217
- omittableEE = typeCheckKeys;
218
- omittableOther = typeCheckKeys;
219
- typeCheckKeys.forEach(function(key) {
220
- expect(eeBlock[key].toString()).toBe(otherBlock[key].toString());
221
- });
222
- } else {
223
- // rename _difficulty to difficulty
224
- delete otherBlock.difficulty;
225
- otherBlock.difficulty = otherBlock._difficulty;
226
- delete otherBlock._difficulty;
227
- omittableEE = // ethers.js doesn't return all these values that essential-eth does, some specific to RSK node
228
- _toConsumableArray(typeCheckKeys).concat([
229
- "bitcoinMergedMiningCoinbaseTransaction",
230
- "bitcoinMergedMiningCoinbaseTransaction",
231
- "bitcoinMergedMiningHeader",
232
- "bitcoinMergedMiningHeader",
233
- "bitcoinMergedMiningMerkleProof",
234
- "cumulativeDifficulty",
235
- "hashForMergedMining",
236
- "logsBloom",
237
- "minimumGasPrice",
238
- "paidFees",
239
- "receiptsRoot",
240
- "sha3Uncles",
241
- "size",
242
- "stateRoot",
243
- "totalDifficulty",
244
- "transactionsRoot",
245
- "uncles"
246
- ]);
247
- omittableOther = _toConsumableArray(typeCheckKeys);
248
- }
249
- typeCheckKeys.forEach(function(key) {
250
- expect(eeBlock[key].toString()).toBe(otherBlock[key].toString());
251
- });
252
- var omittedEEBlock = omit(eeBlock, omittableEE);
253
- var omittedOtherBlock = omit(otherBlock, omittableOther);
254
- expect(omittedEEBlock).toMatchObject(omittedOtherBlock);
255
- }
256
- describe("provider.getBlock", function() {
257
- var essentialEthProvider = new JsonRpcProvider(rpcUrl);
258
- var web3Provider = new Web3(rpcUrl);
259
- var ethersProvider = new ethers.providers.StaticJsonRpcProvider(rpcUrl);
260
- it("should match ethers.js -- latest", /*#__PURE__*/ _asyncToGenerator(function() {
261
- var _ref, eeLatestBlock, ethersLatestBlock;
262
- return __generator(this, function(_state) {
263
- switch(_state.label){
264
- case 0:
265
- return [
266
- 4,
267
- Promise.all([
268
- essentialEthProvider.getBlock("latest"),
269
- ethersProvider.getBlock("latest")
270
- ])
271
- ];
272
- case 1:
273
- _ref = _slicedToArray.apply(void 0, [
274
- _state.sent(),
275
- 2
276
- ]), eeLatestBlock = _ref[0], ethersLatestBlock = _ref[1];
277
- testBlockEquality(eeLatestBlock, ethersLatestBlock);
278
- return [
279
- 2
280
- ];
281
- }
282
- });
283
- }));
284
- it("should match web3.js -- latest", /*#__PURE__*/ _asyncToGenerator(function() {
285
- var _ref, eeLatestBlock, web3LatestBlock;
286
- return __generator(this, function(_state) {
287
- switch(_state.label){
288
- case 0:
289
- return [
290
- 4,
291
- Promise.all([
292
- essentialEthProvider.getBlock("latest"),
293
- web3Provider.eth.getBlock("latest")
294
- ])
295
- ];
296
- case 1:
297
- _ref = _slicedToArray.apply(void 0, [
298
- _state.sent(),
299
- 2
300
- ]), eeLatestBlock = _ref[0], web3LatestBlock = _ref[1];
301
- testBlockEquality(eeLatestBlock, web3LatestBlock);
302
- return [
303
- 2
304
- ];
305
- }
306
- });
307
- }));
308
- it("should match ethers.js -- earliest", /*#__PURE__*/ _asyncToGenerator(function() {
309
- var _ref, eeEarliestBlock, ethersEarliestBlock;
310
- return __generator(this, function(_state) {
311
- switch(_state.label){
312
- case 0:
313
- return [
314
- 4,
315
- Promise.all([
316
- essentialEthProvider.getBlock("earliest"),
317
- ethersProvider.getBlock("earliest")
318
- ])
319
- ];
320
- case 1:
321
- _ref = _slicedToArray.apply(void 0, [
322
- _state.sent(),
323
- 2
324
- ]), eeEarliestBlock = _ref[0], ethersEarliestBlock = _ref[1];
325
- testBlockEquality(eeEarliestBlock, ethersEarliestBlock);
326
- return [
327
- 2
328
- ];
329
- }
330
- });
331
- }));
332
- it("should match web3.js -- earliest", /*#__PURE__*/ _asyncToGenerator(function() {
333
- var _ref, eeEarliestBlock, web3EarliestBlock;
334
- return __generator(this, function(_state) {
335
- switch(_state.label){
336
- case 0:
337
- return [
338
- 4,
339
- Promise.all([
340
- essentialEthProvider.getBlock("earliest"),
341
- web3Provider.eth.getBlock("earliest")
342
- ])
343
- ];
344
- case 1:
345
- _ref = _slicedToArray.apply(void 0, [
346
- _state.sent(),
347
- 2
348
- ]), eeEarliestBlock = _ref[0], web3EarliestBlock = _ref[1];
349
- testBlockEquality(eeEarliestBlock, web3EarliestBlock);
350
- return [
351
- 2
352
- ];
353
- }
354
- });
355
- }));
356
- var blockNumber = Math.floor(Math.random() * 4202460 /* latest block */ );
357
- it("should match ethers.js -- random block as decimal integer. (block #".concat(blockNumber, ")"), /*#__PURE__*/ _asyncToGenerator(function() {
358
- var _ref, eeRandomBlock, ethersRandomBlock;
359
- return __generator(this, function(_state) {
360
- switch(_state.label){
361
- case 0:
362
- return [
363
- 4,
364
- Promise.all([
365
- essentialEthProvider.getBlock(blockNumber),
366
- ethersProvider.getBlock(blockNumber)
367
- ])
368
- ];
369
- case 1:
370
- _ref = _slicedToArray.apply(void 0, [
371
- _state.sent(),
372
- 2
373
- ]), eeRandomBlock = _ref[0], ethersRandomBlock = _ref[1];
374
- testBlockEquality(eeRandomBlock, ethersRandomBlock);
375
- return [
376
- 2
377
- ];
378
- }
379
- });
380
- }));
381
- var blockHash = "0x4cbaa942e48a91108f38e2a250f6dbaff7fffe3027f5ebf76701929eed2b2970"; // Hash corresponds to block on RSK Mainnet
382
- it("should match ethers.js -- block by hash. (hash = ".concat(blockHash, ")"), /*#__PURE__*/ _asyncToGenerator(function() {
383
- var _ref, eeBlockByHash, ethersBlockByHash;
384
- return __generator(this, function(_state) {
385
- switch(_state.label){
386
- case 0:
387
- return [
388
- 4,
389
- Promise.all([
390
- essentialEthProvider.getBlock(blockHash),
391
- ethersProvider.getBlock(blockHash)
392
- ])
393
- ];
394
- case 1:
395
- _ref = _slicedToArray.apply(void 0, [
396
- _state.sent(),
397
- 2
398
- ]), eeBlockByHash = _ref[0], ethersBlockByHash = _ref[1];
399
- testBlockEquality(eeBlockByHash, ethersBlockByHash);
400
- return [
401
- 2
402
- ];
403
- }
404
- });
405
- }));
406
- it("should match web3.js -- block by hash. (hash = ".concat(blockHash, ")"), /*#__PURE__*/ _asyncToGenerator(function() {
407
- var _ref, eeBlockByHash, web3BlockByHash;
408
- return __generator(this, function(_state) {
409
- switch(_state.label){
410
- case 0:
411
- return [
412
- 4,
413
- Promise.all([
414
- essentialEthProvider.getBlock(blockHash),
415
- web3Provider.eth.getBlock(blockHash)
416
- ])
417
- ];
418
- case 1:
419
- _ref = _slicedToArray.apply(void 0, [
420
- _state.sent(),
421
- 2
422
- ]), eeBlockByHash = _ref[0], web3BlockByHash = _ref[1];
423
- testBlockEquality(eeBlockByHash, web3BlockByHash);
424
- return [
425
- 2
426
- ];
427
- }
428
- });
429
- }));
430
- });
431
- describe("provider.getBlock error handling", function() {
432
- it("should handle empty 200 http response", /*#__PURE__*/ _asyncToGenerator(function() {
433
- var essentialEth;
434
- return __generator(this, function(_state) {
435
- switch(_state.label){
436
- case 0:
437
- expect.assertions(1);
438
- essentialEth = new JsonRpcProvider(fakeUrls.notRPCButRealHttp);
439
- return [
440
- 4,
441
- essentialEth.getBlock("earliest").catch(function() {
442
- var _ref = _asyncToGenerator(function(essentialEthError) {
443
- return __generator(this, function(_state) {
444
- // error message is Invalid JSON RPC response: "200 OK"
445
- expect('Invalid JSON RPC response: "200 OK"').toBe(essentialEthError.message);
446
- return [
447
- 2
448
- ];
449
- });
450
- });
451
- return function(essentialEthError) {
452
- return _ref.apply(this, arguments);
453
- };
454
- }())
455
- ];
456
- case 1:
457
- _state.sent();
458
- return [
459
- 2
460
- ];
461
- }
462
- });
463
- }));
464
- // TODO: Make a mock http endpoint which returns an empty json object
465
- // it.only('should handle json emptry object 200 http response', async () => {
466
- // expect.assertions(1);
467
- // const essentialEth = new JsonRpcProvider('http://localhost:51196/b.json');
468
- // const web3 = new Web3('http://localhost:51196/b.json');
469
- // await essentialEth.getBlock('earliest').catch(async (essentialEthError) => {
470
- // await web3.eth.getBlock('earliest').catch((web3Error) => {
471
- // console.log({ w3: web3Error.message, ee: essentialEthError.message });
472
- // // error message is Invalid JSON RPC response: "200 OK"
473
- // expect(web3Error.message).toBe(essentialEthError.message);
474
- // });
475
- // });
476
- // });
477
- });