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.
- package/dist/cjs/classes/Contract.js +38 -34
- package/dist/cjs/classes/test/Contract/crv.test.js +146 -339
- package/dist/cjs/classes/test/Contract/ens-abi.d.ts +1 -1
- package/dist/cjs/classes/test/Contract/ens.test.js +9 -66
- package/dist/cjs/classes/test/Contract/fei.test.js +11 -11
- package/dist/cjs/classes/test/Contract/foo-abi.d.ts +1 -1
- package/dist/cjs/classes/test/Contract/uni.test.js +66 -164
- package/dist/cjs/classes/utils/clean-block.js +4 -4
- package/dist/cjs/classes/utils/clean-log.js +4 -4
- package/dist/cjs/classes/utils/clean-transaction-receipt.js +4 -4
- package/dist/cjs/classes/utils/clean-transaction.js +4 -4
- package/dist/cjs/classes/utils/encode-decode-transaction.js +10 -10
- package/dist/cjs/classes/utils/fetchers.d.ts +8 -2
- package/dist/cjs/classes/utils/fetchers.js +20 -12
- package/dist/cjs/classes/utils/prepare-transaction.js +4 -4
- package/dist/cjs/index.d.ts +21 -21
- package/dist/cjs/index.js +21 -21
- package/dist/cjs/index.umd.js +1 -1
- package/dist/cjs/index.umd.js.map +1 -1
- package/dist/cjs/logger/logger.js +79 -41
- package/dist/cjs/logger/package-version.d.ts +1 -1
- package/dist/cjs/logger/package-version.js +1 -1
- package/dist/cjs/providers/AlchemyProvider.d.ts +4 -0
- package/dist/cjs/providers/AlchemyProvider.js +84 -0
- package/dist/cjs/providers/BaseProvider.js +471 -404
- package/dist/cjs/providers/FallthroughProvider.js +74 -38
- package/dist/cjs/providers/JsonRpcProvider.js +52 -31
- package/dist/cjs/providers/test/fallthrough-provider/get-gas-price.test.js +9 -9
- package/dist/cjs/providers/test/get-transaction-count.test.js +54 -91
- package/dist/cjs/providers/test/json-rpc-provider/call.test.js +87 -148
- package/dist/cjs/providers/test/json-rpc-provider/estimate-gas.test.js +45 -116
- package/dist/cjs/providers/test/json-rpc-provider/get-balance.test.js +36 -74
- package/dist/cjs/providers/test/json-rpc-provider/get-block-number.test.js +27 -94
- package/dist/cjs/providers/test/json-rpc-provider/get-block.test.js +191 -278
- package/dist/cjs/providers/test/json-rpc-provider/get-code.test.js +106 -135
- package/dist/cjs/providers/test/json-rpc-provider/get-fee-data.test.js +48 -73
- package/dist/cjs/providers/test/json-rpc-provider/get-gas-price.test.js +29 -64
- package/dist/cjs/providers/test/json-rpc-provider/get-logs/get-logs.test.js +219 -0
- package/dist/cjs/providers/test/json-rpc-provider/get-logs/mocks.d.ts +14 -0
- package/dist/cjs/providers/test/json-rpc-provider/get-logs/mocks.js +149 -0
- package/dist/cjs/providers/test/json-rpc-provider/get-network.test.js +37 -79
- package/dist/cjs/providers/test/json-rpc-provider/get-transaction-receipt.test.js +136 -157
- package/dist/cjs/providers/test/json-rpc-provider/get-transaction.test.js +121 -162
- package/dist/cjs/providers/test/mock-of.d.ts +2 -0
- package/dist/cjs/providers/test/mock-of.js +9 -0
- package/dist/cjs/providers/test/rpc-urls.d.ts +1 -0
- package/dist/cjs/providers/test/rpc-urls.js +12 -6
- package/dist/cjs/providers/test/test-alchemy-provider.test.js +151 -0
- package/dist/cjs/providers/utils/chains-info.d.ts +5 -448
- package/dist/cjs/providers/utils/chains-info.js +13 -1344
- package/dist/cjs/shared/tiny-big/helpers.js +18 -18
- package/dist/cjs/shared/tiny-big/tiny-big.js +96 -56
- package/dist/cjs/shared/tiny-big/tiny-big.test.js +2 -2
- package/dist/cjs/shared/validate-type.d.ts +1 -1
- package/dist/cjs/shared/validate-type.js +4 -4
- package/dist/cjs/types/Block.types.d.ts +3 -3
- package/dist/cjs/types/Contract.types.d.ts +4 -4
- package/dist/cjs/types/Transaction.types.d.ts +5 -5
- package/dist/cjs/utils/bytes.d.ts +4 -4
- package/dist/cjs/utils/bytes.js +3 -3
- package/dist/cjs/utils/tests/bytes/arrayify.test.js +48 -24
- package/dist/cjs/utils/tests/bytes/concat.test.js +5 -3
- package/dist/cjs/utils/tests/bytes/hex-concat.test.js +15 -13
- package/dist/cjs/utils/tests/bytes/hex-data-length.test.js +49 -32
- package/dist/cjs/utils/tests/bytes/hex-data-slice.test.js +15 -16
- package/dist/cjs/utils/tests/bytes/hex-strip-zeros.test.js +57 -40
- package/dist/cjs/utils/tests/bytes/hex-value.test.js +118 -62
- package/dist/cjs/utils/tests/bytes/hex-zero-pad.test.js +71 -33
- package/dist/cjs/utils/tests/bytes/hexlify.test.js +45 -29
- package/dist/cjs/utils/tests/bytes/is-bytes-like.test.js +10 -11
- package/dist/cjs/utils/tests/bytes/is-bytes.test.js +70 -27
- package/dist/cjs/utils/tests/bytes/is-hex-string.test.js +37 -28
- package/dist/cjs/utils/tests/bytes/strip-zeros.test.js +94 -45
- package/dist/cjs/utils/tests/bytes/zero-pad.test.js +98 -34
- package/dist/cjs/utils/tests/compute-address.test.js +42 -20
- package/dist/cjs/utils/tests/compute-public-key.test.js +20 -9
- package/dist/cjs/utils/tests/ether-to-wei.test.js +5 -13
- package/dist/cjs/utils/tests/hash-message.test.js +26 -15
- package/dist/cjs/utils/tests/is-address.test.js +2 -9
- package/dist/cjs/utils/tests/keccak256.test.js +36 -12
- package/dist/cjs/utils/tests/solidity-keccak256.test.js +43 -42
- package/dist/cjs/utils/tests/split-signature.test.js +29 -8
- package/dist/cjs/utils/tests/to-checksum-address.test.js +1 -4
- package/dist/cjs/utils/tests/to-utf8-bytes.test.js +28 -8
- package/dist/cjs/utils/tests/wei-to-ether.test.js +10 -20
- package/dist/esm/classes/test/Contract/ens-abi.d.ts +1 -1
- package/dist/esm/classes/test/Contract/foo-abi.d.ts +1 -1
- package/dist/esm/classes/utils/fetchers.d.ts +8 -2
- package/dist/esm/classes/utils/fetchers.js +6 -3
- package/dist/esm/index.d.ts +21 -21
- package/dist/esm/index.js +16 -16
- package/dist/esm/logger/package-version.d.ts +1 -1
- package/dist/esm/logger/package-version.js +1 -1
- package/dist/esm/providers/AlchemyProvider.d.ts +4 -0
- package/dist/esm/providers/AlchemyProvider.js +7 -0
- package/dist/esm/providers/FallthroughProvider.js +15 -7
- package/dist/esm/providers/test/json-rpc-provider/get-logs/mocks.d.ts +14 -0
- package/dist/esm/providers/test/json-rpc-provider/get-logs/mocks.js +142 -0
- package/dist/esm/providers/test/mock-of.d.ts +2 -0
- package/dist/esm/providers/test/mock-of.js +1 -0
- package/dist/esm/providers/test/rpc-urls.d.ts +1 -0
- package/dist/esm/providers/test/rpc-urls.js +14 -6
- package/dist/esm/providers/utils/chains-info.d.ts +5 -448
- package/dist/esm/providers/utils/chains-info.js +13 -1344
- package/dist/esm/shared/validate-type.d.ts +1 -1
- package/dist/esm/types/Block.types.d.ts +3 -3
- package/dist/esm/types/Contract.types.d.ts +4 -4
- package/dist/esm/types/Transaction.types.d.ts +5 -5
- package/dist/esm/utils/bytes.d.ts +4 -4
- package/package.json +23 -51
- package/readme.md +16 -38
- package/dist/cjs/providers/test/json-rpc-provider/get-logs.test.js +0 -361
|
@@ -1,14 +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
|
-
function _arrayWithoutHoles(arr) {
|
|
10
|
-
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
|
|
11
|
-
}
|
|
12
1
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
13
2
|
try {
|
|
14
3
|
var info = gen[key](arg);
|
|
@@ -23,7 +12,7 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
|
23
12
|
Promise.resolve(value).then(_next, _throw);
|
|
24
13
|
}
|
|
25
14
|
}
|
|
26
|
-
function
|
|
15
|
+
function _async_to_generator(fn) {
|
|
27
16
|
return function() {
|
|
28
17
|
var self = this, args = arguments;
|
|
29
18
|
return new Promise(function(resolve, reject) {
|
|
@@ -38,54 +27,59 @@ function _asyncToGenerator(fn) {
|
|
|
38
27
|
});
|
|
39
28
|
};
|
|
40
29
|
}
|
|
41
|
-
function
|
|
42
|
-
if (
|
|
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;
|
|
43
42
|
}
|
|
44
|
-
function
|
|
45
|
-
var
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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;
|
|
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
|
+
}));
|
|
64
51
|
}
|
|
52
|
+
ownKeys.forEach(function(key) {
|
|
53
|
+
_define_property(target, key, source[key]);
|
|
54
|
+
});
|
|
65
55
|
}
|
|
66
|
-
return
|
|
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.");
|
|
56
|
+
return target;
|
|
70
57
|
}
|
|
71
|
-
function
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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;
|
|
79
70
|
}
|
|
80
|
-
function
|
|
81
|
-
|
|
82
|
-
if (
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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;
|
|
87
81
|
}
|
|
88
|
-
|
|
82
|
+
function _ts_generator(thisArg, body) {
|
|
89
83
|
var f, y, t, g, _ = {
|
|
90
84
|
label: 0,
|
|
91
85
|
sent: function() {
|
|
@@ -179,223 +173,136 @@ var __generator = this && this.__generator || function(thisArg, body) {
|
|
|
179
173
|
done: true
|
|
180
174
|
};
|
|
181
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: []
|
|
182
205
|
};
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
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);
|
|
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);
|
|
255
223
|
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
it("should match ethers.js -- latest", /*#__PURE__*/ _asyncToGenerator(function() {
|
|
261
|
-
var _ref, eeLatestBlock, ethersLatestBlock;
|
|
262
|
-
return __generator(this, function(_state) {
|
|
224
|
+
function _runTest() {
|
|
225
|
+
_runTest = _async_to_generator(function(method, params, responseIdentifier) {
|
|
226
|
+
var spy, result;
|
|
227
|
+
return _ts_generator(this, function(_state) {
|
|
263
228
|
switch(_state.label){
|
|
264
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");
|
|
265
237
|
return [
|
|
266
238
|
4,
|
|
267
|
-
|
|
268
|
-
essentialEthProvider.getBlock("latest"),
|
|
269
|
-
ethersProvider.getBlock("latest")
|
|
270
|
-
])
|
|
239
|
+
provider.getBlock(responseIdentifier)
|
|
271
240
|
];
|
|
272
241
|
case 1:
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
]), eeLatestBlock = _ref[0], ethersLatestBlock = _ref[1];
|
|
277
|
-
testBlockEquality(eeLatestBlock, ethersLatestBlock);
|
|
242
|
+
result = _state.sent();
|
|
243
|
+
expect(spy).toHaveBeenCalledWith(rpcUrl, buildFetchInit(buildRPCPostBody(method, params)));
|
|
244
|
+
expect(JSON.stringify(result)).toBe(JSON.stringify(mockBlock));
|
|
278
245
|
return [
|
|
279
246
|
2
|
|
280
247
|
];
|
|
281
248
|
}
|
|
282
249
|
});
|
|
283
|
-
})
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
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) {
|
|
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) {
|
|
335
256
|
switch(_state.label){
|
|
336
257
|
case 0:
|
|
337
258
|
return [
|
|
338
259
|
4,
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
])
|
|
260
|
+
runTest("eth_getBlockByNumber", [
|
|
261
|
+
"latest",
|
|
262
|
+
false
|
|
263
|
+
], "latest")
|
|
343
264
|
];
|
|
344
265
|
case 1:
|
|
345
|
-
|
|
346
|
-
_state.sent(),
|
|
347
|
-
2
|
|
348
|
-
]), eeEarliestBlock = _ref[0], web3EarliestBlock = _ref[1];
|
|
349
|
-
testBlockEquality(eeEarliestBlock, web3EarliestBlock);
|
|
266
|
+
_state.sent();
|
|
350
267
|
return [
|
|
351
268
|
2
|
|
352
269
|
];
|
|
353
270
|
}
|
|
354
271
|
});
|
|
355
272
|
}));
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
var _ref, eeRandomBlock, ethersRandomBlock;
|
|
359
|
-
return __generator(this, function(_state) {
|
|
273
|
+
it("should match mocked block -- earliest", /*#__PURE__*/ _async_to_generator(function() {
|
|
274
|
+
return _ts_generator(this, function(_state) {
|
|
360
275
|
switch(_state.label){
|
|
361
276
|
case 0:
|
|
362
277
|
return [
|
|
363
278
|
4,
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
])
|
|
279
|
+
runTest("eth_getBlockByNumber", [
|
|
280
|
+
"earliest",
|
|
281
|
+
false
|
|
282
|
+
], "earliest")
|
|
368
283
|
];
|
|
369
284
|
case 1:
|
|
370
|
-
|
|
371
|
-
_state.sent(),
|
|
372
|
-
2
|
|
373
|
-
]), eeRandomBlock = _ref[0], ethersRandomBlock = _ref[1];
|
|
374
|
-
testBlockEquality(eeRandomBlock, ethersRandomBlock);
|
|
285
|
+
_state.sent();
|
|
375
286
|
return [
|
|
376
287
|
2
|
|
377
288
|
];
|
|
378
289
|
}
|
|
379
290
|
});
|
|
380
291
|
}));
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
return
|
|
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) {
|
|
384
295
|
switch(_state.label){
|
|
385
296
|
case 0:
|
|
386
297
|
return [
|
|
387
298
|
4,
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
])
|
|
299
|
+
runTest("eth_getBlockByNumber", [
|
|
300
|
+
tinyBig(blockNumber).toHexString(),
|
|
301
|
+
false
|
|
302
|
+
], blockNumber)
|
|
392
303
|
];
|
|
393
304
|
case 1:
|
|
394
|
-
|
|
395
|
-
_state.sent(),
|
|
396
|
-
2
|
|
397
|
-
]), eeRandomBlock = _ref[0], web3RandomBlock = _ref[1];
|
|
398
|
-
testBlockEquality(eeRandomBlock, web3RandomBlock);
|
|
305
|
+
_state.sent();
|
|
399
306
|
return [
|
|
400
307
|
2
|
|
401
308
|
];
|
|
@@ -403,99 +310,105 @@ describe("provider.getBlock", function() {
|
|
|
403
310
|
});
|
|
404
311
|
}));
|
|
405
312
|
var blockHash = "0x4cbaa942e48a91108f38e2a250f6dbaff7fffe3027f5ebf76701929eed2b2970"; // Hash corresponds to block on RSK Mainnet
|
|
406
|
-
it("should match
|
|
407
|
-
|
|
408
|
-
return __generator(this, function(_state) {
|
|
313
|
+
it("should match mocked block -- block by hash. (hash = ".concat(blockHash, ")"), /*#__PURE__*/ _async_to_generator(function() {
|
|
314
|
+
return _ts_generator(this, function(_state) {
|
|
409
315
|
switch(_state.label){
|
|
410
316
|
case 0:
|
|
411
317
|
return [
|
|
412
318
|
4,
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
])
|
|
319
|
+
runTest("eth_getBlockByHash", [
|
|
320
|
+
blockHash,
|
|
321
|
+
false
|
|
322
|
+
], blockHash)
|
|
417
323
|
];
|
|
418
324
|
case 1:
|
|
419
|
-
|
|
420
|
-
_state.sent(),
|
|
421
|
-
2
|
|
422
|
-
]), eeBlockByHash = _ref[0], ethersBlockByHash = _ref[1];
|
|
423
|
-
testBlockEquality(eeBlockByHash, ethersBlockByHash);
|
|
325
|
+
_state.sent();
|
|
424
326
|
return [
|
|
425
327
|
2
|
|
426
328
|
];
|
|
427
329
|
}
|
|
428
330
|
});
|
|
429
331
|
}));
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
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) {
|
|
433
337
|
switch(_state.label){
|
|
434
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");
|
|
435
345
|
return [
|
|
436
346
|
4,
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
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
|
+
}())
|
|
441
361
|
];
|
|
442
362
|
case 1:
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
363
|
+
_state.sent();
|
|
364
|
+
expect(spy).toHaveBeenCalledWith(rpcUrl, buildFetchInit(buildRPCPostBody("eth_getBlockByNumber", [
|
|
365
|
+
"earliest",
|
|
366
|
+
false
|
|
367
|
+
])));
|
|
448
368
|
return [
|
|
449
369
|
2
|
|
450
370
|
];
|
|
451
371
|
}
|
|
452
372
|
});
|
|
453
373
|
}));
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
var essentialEth;
|
|
458
|
-
return __generator(this, function(_state) {
|
|
374
|
+
it("should handle empty JSON object", /*#__PURE__*/ _async_to_generator(function() {
|
|
375
|
+
var spy;
|
|
376
|
+
return _ts_generator(this, function(_state) {
|
|
459
377
|
switch(_state.label){
|
|
460
378
|
case 0:
|
|
461
|
-
|
|
462
|
-
|
|
379
|
+
mockOf(unfetch.default).mockResolvedValueOnce({
|
|
380
|
+
text: function() {
|
|
381
|
+
return Promise.resolve("{}");
|
|
382
|
+
}
|
|
383
|
+
});
|
|
384
|
+
spy = jest.spyOn(unfetch, "default");
|
|
463
385
|
return [
|
|
464
386
|
4,
|
|
465
|
-
|
|
466
|
-
var _ref =
|
|
467
|
-
return
|
|
468
|
-
// error message is Invalid JSON RPC response:
|
|
469
|
-
expect(
|
|
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: {}");
|
|
470
392
|
return [
|
|
471
393
|
2
|
|
472
394
|
];
|
|
473
395
|
});
|
|
474
396
|
});
|
|
475
|
-
return function(
|
|
397
|
+
return function(error) {
|
|
476
398
|
return _ref.apply(this, arguments);
|
|
477
399
|
};
|
|
478
400
|
}())
|
|
479
401
|
];
|
|
480
402
|
case 1:
|
|
481
403
|
_state.sent();
|
|
404
|
+
expect(spy).toHaveBeenCalledWith(rpcUrl, buildFetchInit(buildRPCPostBody("eth_getBlockByNumber", [
|
|
405
|
+
"earliest",
|
|
406
|
+
false
|
|
407
|
+
])));
|
|
482
408
|
return [
|
|
483
409
|
2
|
|
484
410
|
];
|
|
485
411
|
}
|
|
486
412
|
});
|
|
487
413
|
}));
|
|
488
|
-
// TODO: Make a mock http endpoint which returns an empty json object
|
|
489
|
-
// it.only('should handle json emptry object 200 http response', async () => {
|
|
490
|
-
// expect.assertions(1);
|
|
491
|
-
// const essentialEth = new JsonRpcProvider('http://localhost:51196/b.json');
|
|
492
|
-
// const web3 = new Web3('http://localhost:51196/b.json');
|
|
493
|
-
// await essentialEth.getBlock('earliest').catch(async (essentialEthError) => {
|
|
494
|
-
// await web3.eth.getBlock('earliest').catch((web3Error) => {
|
|
495
|
-
// console.log({ w3: web3Error.message, ee: essentialEthError.message });
|
|
496
|
-
// // error message is Invalid JSON RPC response: "200 OK"
|
|
497
|
-
// expect(web3Error.message).toBe(essentialEthError.message);
|
|
498
|
-
// });
|
|
499
|
-
// });
|
|
500
|
-
// });
|
|
501
414
|
});
|