essential-eth 0.9.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 -22
- package/dist/cjs/index.js +21 -22
- 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.js +22 -22
- package/dist/cjs/providers/BaseProvider.js +471 -404
- package/dist/cjs/providers/FallthroughProvider.js +62 -30
- 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 +13 -9
- package/dist/cjs/providers/test/json-rpc-provider/get-block.test.js +191 -254
- 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 +11 -8
- 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.js +0 -5
- package/dist/cjs/providers/test/rpc-urls.d.ts +1 -0
- package/dist/cjs/providers/test/rpc-urls.js +5 -4
- package/dist/cjs/providers/test/test-alchemy-provider.test.js +5 -5
- 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 -22
- package/dist/esm/index.js +16 -17
- package/dist/esm/logger/package-version.d.ts +1 -1
- package/dist/esm/logger/package-version.js +1 -1
- package/dist/esm/providers/FallthroughProvider.js +3 -3
- 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/rpc-urls.d.ts +1 -0
- package/dist/esm/providers/test/rpc-urls.js +7 -4
- 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 +22 -50
- package/readme.md +15 -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.");
|
|
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.");
|
|
56
|
+
return target;
|
|
73
57
|
}
|
|
74
|
-
function
|
|
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,199 +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) {
|
|
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) {
|
|
224
|
+
function _runTest() {
|
|
225
|
+
_runTest = _async_to_generator(function(method, params, responseIdentifier) {
|
|
226
|
+
var spy, result;
|
|
227
|
+
return _ts_generator(this, function(_state) {
|
|
287
228
|
switch(_state.label){
|
|
288
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");
|
|
289
237
|
return [
|
|
290
238
|
4,
|
|
291
|
-
|
|
292
|
-
essentialEthProvider.getBlock("latest"),
|
|
293
|
-
web3Provider.eth.getBlock("latest")
|
|
294
|
-
])
|
|
239
|
+
provider.getBlock(responseIdentifier)
|
|
295
240
|
];
|
|
296
241
|
case 1:
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
]), eeLatestBlock = _ref[0], web3LatestBlock = _ref[1];
|
|
301
|
-
testBlockEquality(eeLatestBlock, web3LatestBlock);
|
|
242
|
+
result = _state.sent();
|
|
243
|
+
expect(spy).toHaveBeenCalledWith(rpcUrl, buildFetchInit(buildRPCPostBody(method, params)));
|
|
244
|
+
expect(JSON.stringify(result)).toBe(JSON.stringify(mockBlock));
|
|
302
245
|
return [
|
|
303
246
|
2
|
|
304
247
|
];
|
|
305
248
|
}
|
|
306
249
|
});
|
|
307
|
-
})
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
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) {
|
|
311
256
|
switch(_state.label){
|
|
312
257
|
case 0:
|
|
313
258
|
return [
|
|
314
259
|
4,
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
])
|
|
260
|
+
runTest("eth_getBlockByNumber", [
|
|
261
|
+
"latest",
|
|
262
|
+
false
|
|
263
|
+
], "latest")
|
|
319
264
|
];
|
|
320
265
|
case 1:
|
|
321
|
-
|
|
322
|
-
_state.sent(),
|
|
323
|
-
2
|
|
324
|
-
]), eeEarliestBlock = _ref[0], ethersEarliestBlock = _ref[1];
|
|
325
|
-
testBlockEquality(eeEarliestBlock, ethersEarliestBlock);
|
|
266
|
+
_state.sent();
|
|
326
267
|
return [
|
|
327
268
|
2
|
|
328
269
|
];
|
|
329
270
|
}
|
|
330
271
|
});
|
|
331
272
|
}));
|
|
332
|
-
it("should match
|
|
333
|
-
|
|
334
|
-
return __generator(this, function(_state) {
|
|
273
|
+
it("should match mocked block -- earliest", /*#__PURE__*/ _async_to_generator(function() {
|
|
274
|
+
return _ts_generator(this, function(_state) {
|
|
335
275
|
switch(_state.label){
|
|
336
276
|
case 0:
|
|
337
277
|
return [
|
|
338
278
|
4,
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
])
|
|
279
|
+
runTest("eth_getBlockByNumber", [
|
|
280
|
+
"earliest",
|
|
281
|
+
false
|
|
282
|
+
], "earliest")
|
|
343
283
|
];
|
|
344
284
|
case 1:
|
|
345
|
-
|
|
346
|
-
_state.sent(),
|
|
347
|
-
2
|
|
348
|
-
]), eeEarliestBlock = _ref[0], web3EarliestBlock = _ref[1];
|
|
349
|
-
testBlockEquality(eeEarliestBlock, web3EarliestBlock);
|
|
285
|
+
_state.sent();
|
|
350
286
|
return [
|
|
351
287
|
2
|
|
352
288
|
];
|
|
353
289
|
}
|
|
354
290
|
});
|
|
355
291
|
}));
|
|
356
|
-
var blockNumber =
|
|
357
|
-
it("should match
|
|
358
|
-
|
|
359
|
-
return __generator(this, function(_state) {
|
|
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) {
|
|
360
295
|
switch(_state.label){
|
|
361
296
|
case 0:
|
|
362
297
|
return [
|
|
363
298
|
4,
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
])
|
|
299
|
+
runTest("eth_getBlockByNumber", [
|
|
300
|
+
tinyBig(blockNumber).toHexString(),
|
|
301
|
+
false
|
|
302
|
+
], blockNumber)
|
|
368
303
|
];
|
|
369
304
|
case 1:
|
|
370
|
-
|
|
371
|
-
_state.sent(),
|
|
372
|
-
2
|
|
373
|
-
]), eeRandomBlock = _ref[0], ethersRandomBlock = _ref[1];
|
|
374
|
-
testBlockEquality(eeRandomBlock, ethersRandomBlock);
|
|
305
|
+
_state.sent();
|
|
375
306
|
return [
|
|
376
307
|
2
|
|
377
308
|
];
|
|
@@ -379,99 +310,105 @@ describe("provider.getBlock", function() {
|
|
|
379
310
|
});
|
|
380
311
|
}));
|
|
381
312
|
var blockHash = "0x4cbaa942e48a91108f38e2a250f6dbaff7fffe3027f5ebf76701929eed2b2970"; // Hash corresponds to block on RSK Mainnet
|
|
382
|
-
it("should match
|
|
383
|
-
|
|
384
|
-
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) {
|
|
385
315
|
switch(_state.label){
|
|
386
316
|
case 0:
|
|
387
317
|
return [
|
|
388
318
|
4,
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
])
|
|
319
|
+
runTest("eth_getBlockByHash", [
|
|
320
|
+
blockHash,
|
|
321
|
+
false
|
|
322
|
+
], blockHash)
|
|
393
323
|
];
|
|
394
324
|
case 1:
|
|
395
|
-
|
|
396
|
-
_state.sent(),
|
|
397
|
-
2
|
|
398
|
-
]), eeBlockByHash = _ref[0], ethersBlockByHash = _ref[1];
|
|
399
|
-
testBlockEquality(eeBlockByHash, ethersBlockByHash);
|
|
325
|
+
_state.sent();
|
|
400
326
|
return [
|
|
401
327
|
2
|
|
402
328
|
];
|
|
403
329
|
}
|
|
404
330
|
});
|
|
405
331
|
}));
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
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) {
|
|
409
337
|
switch(_state.label){
|
|
410
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");
|
|
411
345
|
return [
|
|
412
346
|
4,
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
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
|
+
}())
|
|
417
361
|
];
|
|
418
362
|
case 1:
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
363
|
+
_state.sent();
|
|
364
|
+
expect(spy).toHaveBeenCalledWith(rpcUrl, buildFetchInit(buildRPCPostBody("eth_getBlockByNumber", [
|
|
365
|
+
"earliest",
|
|
366
|
+
false
|
|
367
|
+
])));
|
|
424
368
|
return [
|
|
425
369
|
2
|
|
426
370
|
];
|
|
427
371
|
}
|
|
428
372
|
});
|
|
429
373
|
}));
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
var essentialEth;
|
|
434
|
-
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) {
|
|
435
377
|
switch(_state.label){
|
|
436
378
|
case 0:
|
|
437
|
-
|
|
438
|
-
|
|
379
|
+
mockOf(unfetch.default).mockResolvedValueOnce({
|
|
380
|
+
text: function() {
|
|
381
|
+
return Promise.resolve("{}");
|
|
382
|
+
}
|
|
383
|
+
});
|
|
384
|
+
spy = jest.spyOn(unfetch, "default");
|
|
439
385
|
return [
|
|
440
386
|
4,
|
|
441
|
-
|
|
442
|
-
var _ref =
|
|
443
|
-
return
|
|
444
|
-
// error message is Invalid JSON RPC response:
|
|
445
|
-
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: {}");
|
|
446
392
|
return [
|
|
447
393
|
2
|
|
448
394
|
];
|
|
449
395
|
});
|
|
450
396
|
});
|
|
451
|
-
return function(
|
|
397
|
+
return function(error) {
|
|
452
398
|
return _ref.apply(this, arguments);
|
|
453
399
|
};
|
|
454
400
|
}())
|
|
455
401
|
];
|
|
456
402
|
case 1:
|
|
457
403
|
_state.sent();
|
|
404
|
+
expect(spy).toHaveBeenCalledWith(rpcUrl, buildFetchInit(buildRPCPostBody("eth_getBlockByNumber", [
|
|
405
|
+
"earliest",
|
|
406
|
+
false
|
|
407
|
+
])));
|
|
458
408
|
return [
|
|
459
409
|
2
|
|
460
410
|
];
|
|
461
411
|
}
|
|
462
412
|
});
|
|
463
413
|
}));
|
|
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
414
|
});
|