essential-eth 0.6.2 → 0.8.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 +307 -66
- package/dist/cjs/classes/test/Contract/crv-abi.js +252 -256
- package/dist/cjs/classes/test/Contract/crv.test.js +690 -0
- package/dist/cjs/classes/test/Contract/ens-abi.js +497 -212
- package/dist/cjs/classes/test/Contract/ens.test.js +217 -0
- package/dist/cjs/classes/test/Contract/fei-abi.js +605 -284
- package/dist/cjs/classes/test/Contract/fei.test.js +224 -0
- package/dist/cjs/classes/test/Contract/foo-abi.js +44 -21
- package/dist/cjs/classes/test/Contract/foo.test.js +33 -0
- package/dist/cjs/classes/test/Contract/uni.test.js +387 -0
- package/dist/cjs/classes/test/Contract/uniswap-abi.js +64 -68
- package/dist/cjs/classes/utils/clean-block.d.ts +1 -2
- package/dist/cjs/classes/utils/clean-block.js +52 -30
- package/dist/cjs/classes/utils/clean-log.js +42 -20
- package/dist/cjs/classes/utils/clean-transaction-receipt.js +51 -29
- package/dist/cjs/classes/utils/clean-transaction.js +52 -29
- package/dist/cjs/classes/utils/encode-decode-transaction.d.ts +1 -1
- package/dist/cjs/classes/utils/encode-decode-transaction.js +163 -83
- package/dist/cjs/classes/utils/fetchers.js +165 -41
- package/dist/cjs/classes/utils/hex-to-decimal.js +1 -6
- package/dist/cjs/classes/utils/prepare-transaction.js +59 -36
- package/dist/cjs/index.js +25 -54
- package/dist/cjs/index.umd.js +1 -1
- package/dist/cjs/index.umd.js.map +1 -1
- package/dist/cjs/logger/logger.js +79 -23
- package/dist/cjs/logger/package-version.d.ts +1 -1
- package/dist/cjs/logger/package-version.js +1 -4
- package/dist/cjs/providers/BaseProvider.d.ts +2 -0
- package/dist/cjs/providers/BaseProvider.js +883 -475
- package/dist/cjs/providers/FallthroughProvider.js +118 -37
- package/dist/cjs/providers/JsonRpcProvider.js +93 -28
- package/dist/cjs/providers/test/fallthrough-provider/get-gas-price.test.js +228 -0
- package/dist/cjs/providers/test/get-transaction-count.test.js +276 -0
- package/dist/cjs/providers/test/json-rpc-provider/call.test.js +436 -0
- package/dist/cjs/providers/test/json-rpc-provider/estimate-gas.test.js +288 -0
- package/dist/cjs/providers/test/json-rpc-provider/get-balance.test.js +261 -0
- package/dist/cjs/providers/test/json-rpc-provider/get-block-number.test.js +230 -0
- package/dist/cjs/providers/test/json-rpc-provider/get-block.test.js +501 -0
- package/dist/cjs/providers/test/json-rpc-provider/get-code.test.js +311 -0
- package/dist/cjs/providers/test/json-rpc-provider/get-fee-data.test.js +212 -0
- package/dist/cjs/providers/test/json-rpc-provider/get-gas-price.test.js +202 -0
- package/dist/cjs/providers/test/json-rpc-provider/get-logs.test.js +361 -0
- package/dist/cjs/providers/test/json-rpc-provider/get-network.test.js +274 -0
- package/dist/cjs/providers/test/json-rpc-provider/get-transaction-receipt.test.js +301 -0
- package/dist/cjs/providers/test/json-rpc-provider/get-transaction.test.js +307 -0
- package/dist/cjs/providers/test/rpc-urls.js +9 -12
- package/dist/cjs/providers/utils/chains-info.js +1 -3
- package/dist/cjs/shared/tiny-big/helpers.js +93 -42
- package/dist/cjs/shared/tiny-big/helpers.test.js +29 -0
- package/dist/cjs/shared/tiny-big/tiny-big.js +161 -72
- package/dist/cjs/shared/tiny-big/tiny-big.test.js +34 -0
- package/dist/cjs/shared/validate-type.js +7 -7
- package/dist/cjs/types/Block.types.js +1 -2
- package/dist/cjs/types/Contract.types.js +1 -2
- package/dist/cjs/types/FeeData.types.d.ts +7 -0
- package/dist/cjs/types/FeeData.types.js +1 -0
- package/dist/cjs/types/Filter.types.js +1 -2
- package/dist/cjs/types/Network.types.js +3 -2
- package/dist/cjs/types/Transaction.types.js +1 -2
- package/dist/cjs/utils/bytes.js +286 -318
- package/dist/cjs/utils/compute-address.js +8 -14
- package/dist/cjs/utils/compute-public-key.js +5 -10
- package/dist/cjs/utils/ether-to-gwei.js +10 -11
- package/dist/cjs/utils/ether-to-wei.js +10 -11
- package/dist/cjs/utils/gwei-to-ether.js +10 -11
- package/dist/cjs/utils/hash-message.d.ts +1 -1
- package/dist/cjs/utils/hash-message.js +11 -14
- package/dist/cjs/utils/is-address.js +8 -12
- package/dist/cjs/utils/keccak256.js +8 -14
- package/dist/cjs/utils/solidity-keccak256.js +49 -60
- package/dist/cjs/utils/split-signature.js +55 -73
- package/dist/cjs/utils/tests/bytes/arrayify.test.js +40 -0
- package/dist/cjs/utils/tests/bytes/concat.test.js +15 -0
- package/dist/cjs/utils/tests/bytes/hex-concat.test.js +63 -0
- package/dist/cjs/utils/tests/bytes/hex-data-length.test.js +49 -0
- package/dist/cjs/utils/tests/bytes/hex-data-slice.test.js +52 -0
- package/dist/cjs/utils/tests/bytes/hex-strip-zeros.test.js +58 -0
- package/dist/cjs/utils/tests/bytes/hex-value.test.js +85 -0
- package/dist/cjs/utils/tests/bytes/hex-zero-pad.test.js +62 -0
- package/dist/cjs/utils/tests/bytes/hexlify.test.js +62 -0
- package/dist/cjs/utils/tests/bytes/is-bytes-like.test.js +69 -0
- package/dist/cjs/utils/tests/bytes/is-bytes.test.js +33 -0
- package/dist/cjs/utils/tests/bytes/is-hex-string.test.js +88 -0
- package/dist/cjs/utils/tests/bytes/strip-zeros.test.js +57 -0
- package/dist/cjs/utils/tests/bytes/zero-pad.test.js +80 -0
- package/dist/cjs/utils/tests/compute-address.test.js +27 -0
- package/dist/cjs/utils/tests/compute-public-key.test.js +15 -0
- package/dist/cjs/utils/tests/ether-to-gwei.test.js +26 -0
- package/dist/cjs/utils/tests/ether-to-wei.test.js +44 -0
- package/dist/cjs/utils/tests/gwei-to-ether.test.js +28 -0
- package/dist/cjs/utils/tests/hash-message.test.js +21 -0
- package/dist/cjs/utils/tests/is-address.test.js +55 -0
- package/dist/cjs/utils/tests/keccak256.test.js +97 -0
- package/dist/cjs/utils/tests/solidity-keccak256.test.js +310 -0
- package/dist/cjs/utils/tests/split-signature.test.js +25 -0
- package/dist/cjs/utils/tests/to-checksum-address.test.js +42 -0
- package/dist/cjs/utils/tests/to-utf8-bytes.test.js +14 -0
- package/dist/cjs/utils/tests/wei-to-ether.test.js +51 -0
- package/dist/cjs/utils/to-checksum-address.js +15 -20
- package/dist/cjs/utils/to-utf8-bytes.js +1 -6
- package/dist/cjs/utils/wei-to-ether.js +13 -15
- package/dist/esm/classes/utils/clean-block.d.ts +1 -2
- package/dist/esm/classes/utils/clean-block.js +1 -1
- package/dist/esm/classes/utils/clean-transaction-receipt.js +2 -1
- package/dist/esm/classes/utils/clean-transaction.js +2 -1
- package/dist/esm/classes/utils/encode-decode-transaction.d.ts +1 -1
- package/dist/esm/classes/utils/encode-decode-transaction.js +37 -2
- package/dist/esm/logger/package-version.d.ts +1 -1
- package/dist/esm/logger/package-version.js +1 -1
- package/dist/esm/providers/BaseProvider.d.ts +2 -0
- package/dist/esm/providers/BaseProvider.js +15 -0
- package/dist/esm/types/FeeData.types.d.ts +7 -0
- package/dist/esm/types/FeeData.types.js +1 -0
- package/dist/esm/utils/compute-address.js +2 -1
- package/dist/esm/utils/hash-message.d.ts +1 -1
- package/dist/esm/utils/hash-message.js +3 -1
- package/dist/esm/utils/is-address.js +1 -1
- package/package.json +10 -8
- package/readme.md +63 -3
|
@@ -0,0 +1,501 @@
|
|
|
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
|
+
it("should match web3.js -- random block as decimal integer & transactions. (block #".concat(blockNumber, ")"), /*#__PURE__*/ _asyncToGenerator(function() {
|
|
382
|
+
var _ref, eeRandomBlock, web3RandomBlock;
|
|
383
|
+
return __generator(this, function(_state) {
|
|
384
|
+
switch(_state.label){
|
|
385
|
+
case 0:
|
|
386
|
+
return [
|
|
387
|
+
4,
|
|
388
|
+
Promise.all([
|
|
389
|
+
essentialEthProvider.getBlock(blockNumber, true),
|
|
390
|
+
web3Provider.eth.getBlock(blockNumber, true)
|
|
391
|
+
])
|
|
392
|
+
];
|
|
393
|
+
case 1:
|
|
394
|
+
_ref = _slicedToArray.apply(void 0, [
|
|
395
|
+
_state.sent(),
|
|
396
|
+
2
|
|
397
|
+
]), eeRandomBlock = _ref[0], web3RandomBlock = _ref[1];
|
|
398
|
+
testBlockEquality(eeRandomBlock, web3RandomBlock);
|
|
399
|
+
return [
|
|
400
|
+
2
|
|
401
|
+
];
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
}));
|
|
405
|
+
var blockHash = "0x4cbaa942e48a91108f38e2a250f6dbaff7fffe3027f5ebf76701929eed2b2970"; // Hash corresponds to block on RSK Mainnet
|
|
406
|
+
it("should match ethers.js -- block by hash. (hash = ".concat(blockHash, ")"), /*#__PURE__*/ _asyncToGenerator(function() {
|
|
407
|
+
var _ref, eeBlockByHash, ethersBlockByHash;
|
|
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
|
+
ethersProvider.getBlock(blockHash)
|
|
416
|
+
])
|
|
417
|
+
];
|
|
418
|
+
case 1:
|
|
419
|
+
_ref = _slicedToArray.apply(void 0, [
|
|
420
|
+
_state.sent(),
|
|
421
|
+
2
|
|
422
|
+
]), eeBlockByHash = _ref[0], ethersBlockByHash = _ref[1];
|
|
423
|
+
testBlockEquality(eeBlockByHash, ethersBlockByHash);
|
|
424
|
+
return [
|
|
425
|
+
2
|
|
426
|
+
];
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
}));
|
|
430
|
+
it("should match web3.js -- block by hash. (hash = ".concat(blockHash, ")"), /*#__PURE__*/ _asyncToGenerator(function() {
|
|
431
|
+
var _ref, eeBlockByHash, web3BlockByHash;
|
|
432
|
+
return __generator(this, function(_state) {
|
|
433
|
+
switch(_state.label){
|
|
434
|
+
case 0:
|
|
435
|
+
return [
|
|
436
|
+
4,
|
|
437
|
+
Promise.all([
|
|
438
|
+
essentialEthProvider.getBlock(blockHash),
|
|
439
|
+
web3Provider.eth.getBlock(blockHash)
|
|
440
|
+
])
|
|
441
|
+
];
|
|
442
|
+
case 1:
|
|
443
|
+
_ref = _slicedToArray.apply(void 0, [
|
|
444
|
+
_state.sent(),
|
|
445
|
+
2
|
|
446
|
+
]), eeBlockByHash = _ref[0], web3BlockByHash = _ref[1];
|
|
447
|
+
testBlockEquality(eeBlockByHash, web3BlockByHash);
|
|
448
|
+
return [
|
|
449
|
+
2
|
|
450
|
+
];
|
|
451
|
+
}
|
|
452
|
+
});
|
|
453
|
+
}));
|
|
454
|
+
});
|
|
455
|
+
describe("provider.getBlock error handling", function() {
|
|
456
|
+
it("should handle empty 200 http response", /*#__PURE__*/ _asyncToGenerator(function() {
|
|
457
|
+
var essentialEth;
|
|
458
|
+
return __generator(this, function(_state) {
|
|
459
|
+
switch(_state.label){
|
|
460
|
+
case 0:
|
|
461
|
+
expect.assertions(1);
|
|
462
|
+
essentialEth = new JsonRpcProvider(fakeUrls.notRPCButRealHttp);
|
|
463
|
+
return [
|
|
464
|
+
4,
|
|
465
|
+
essentialEth.getBlock("earliest").catch(function() {
|
|
466
|
+
var _ref = _asyncToGenerator(function(essentialEthError) {
|
|
467
|
+
return __generator(this, function(_state) {
|
|
468
|
+
// error message is Invalid JSON RPC response: "200 OK"
|
|
469
|
+
expect('Invalid JSON RPC response: "200 OK"').toBe(essentialEthError.message);
|
|
470
|
+
return [
|
|
471
|
+
2
|
|
472
|
+
];
|
|
473
|
+
});
|
|
474
|
+
});
|
|
475
|
+
return function(essentialEthError) {
|
|
476
|
+
return _ref.apply(this, arguments);
|
|
477
|
+
};
|
|
478
|
+
}())
|
|
479
|
+
];
|
|
480
|
+
case 1:
|
|
481
|
+
_state.sent();
|
|
482
|
+
return [
|
|
483
|
+
2
|
|
484
|
+
];
|
|
485
|
+
}
|
|
486
|
+
});
|
|
487
|
+
}));
|
|
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
|
+
});
|