essential-eth 0.9.1-next.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 (104) hide show
  1. package/dist/cjs/classes/Contract.js +66 -311
  2. package/dist/cjs/classes/test/Contract/crv-abi.js +256 -252
  3. package/dist/cjs/classes/test/Contract/ens-abi.js +212 -497
  4. package/dist/cjs/classes/test/Contract/fei-abi.js +284 -605
  5. package/dist/cjs/classes/test/Contract/foo-abi.js +21 -44
  6. package/dist/cjs/classes/test/Contract/uniswap-abi.js +68 -64
  7. package/dist/cjs/classes/utils/clean-block.js +30 -52
  8. package/dist/cjs/classes/utils/clean-log.js +20 -42
  9. package/dist/cjs/classes/utils/clean-transaction-receipt.js +30 -51
  10. package/dist/cjs/classes/utils/clean-transaction.js +30 -52
  11. package/dist/cjs/classes/utils/encode-decode-transaction.js +107 -148
  12. package/dist/cjs/classes/utils/fetchers.js +44 -166
  13. package/dist/cjs/classes/utils/hex-to-decimal.js +6 -1
  14. package/dist/cjs/classes/utils/prepare-transaction.js +36 -59
  15. package/dist/cjs/index.js +56 -25
  16. package/dist/cjs/index.umd.js +1 -1
  17. package/dist/cjs/index.umd.js.map +1 -1
  18. package/dist/cjs/logger/logger.js +29 -123
  19. package/dist/cjs/logger/package-version.d.ts +1 -1
  20. package/dist/cjs/logger/package-version.js +4 -1
  21. package/dist/cjs/providers/AlchemyProvider.js +9 -82
  22. package/dist/cjs/providers/BaseProvider.js +520 -958
  23. package/dist/cjs/providers/FallthroughProvider.js +47 -156
  24. package/dist/cjs/providers/JsonRpcProvider.js +28 -114
  25. package/dist/cjs/providers/test/json-rpc-provider/get-logs/mocks.js +104 -101
  26. package/dist/cjs/providers/test/mock-of.js +6 -3
  27. package/dist/cjs/providers/test/rpc-urls.js +23 -15
  28. package/dist/cjs/providers/utils/chains-info.js +3 -1
  29. package/dist/cjs/shared/tiny-big/helpers.js +42 -93
  30. package/dist/cjs/shared/tiny-big/tiny-big.js +81 -210
  31. package/dist/cjs/shared/validate-type.js +7 -7
  32. package/dist/cjs/types/Block.types.js +2 -1
  33. package/dist/cjs/types/Contract.types.js +2 -1
  34. package/dist/cjs/types/FeeData.types.js +2 -1
  35. package/dist/cjs/types/Filter.types.js +2 -1
  36. package/dist/cjs/types/Network.types.js +2 -3
  37. package/dist/cjs/types/Transaction.types.js +2 -1
  38. package/dist/cjs/utils/bytes.js +318 -286
  39. package/dist/cjs/utils/compute-address.js +15 -8
  40. package/dist/cjs/utils/compute-public-key.js +10 -5
  41. package/dist/cjs/utils/ether-to-gwei.js +11 -10
  42. package/dist/cjs/utils/ether-to-wei.js +11 -10
  43. package/dist/cjs/utils/gwei-to-ether.js +11 -10
  44. package/dist/cjs/utils/hash-message.js +16 -11
  45. package/dist/cjs/utils/is-address.js +12 -8
  46. package/dist/cjs/utils/keccak256.js +14 -8
  47. package/dist/cjs/utils/solidity-keccak256.js +60 -49
  48. package/dist/cjs/utils/split-signature.js +73 -55
  49. package/dist/cjs/utils/to-checksum-address.js +20 -15
  50. package/dist/cjs/utils/to-utf8-bytes.js +6 -1
  51. package/dist/cjs/utils/wei-to-ether.js +15 -13
  52. package/dist/esm/logger/package-version.d.ts +1 -1
  53. package/dist/esm/logger/package-version.js +1 -1
  54. package/package.json +2 -2
  55. package/readme.md +1 -1
  56. package/dist/cjs/classes/test/Contract/crv.test.js +0 -497
  57. package/dist/cjs/classes/test/Contract/ens.test.js +0 -160
  58. package/dist/cjs/classes/test/Contract/fei.test.js +0 -224
  59. package/dist/cjs/classes/test/Contract/foo.test.js +0 -33
  60. package/dist/cjs/classes/test/Contract/uni.test.js +0 -289
  61. package/dist/cjs/providers/test/fallthrough-provider/get-gas-price.test.js +0 -228
  62. package/dist/cjs/providers/test/get-transaction-count.test.js +0 -239
  63. package/dist/cjs/providers/test/json-rpc-provider/call.test.js +0 -375
  64. package/dist/cjs/providers/test/json-rpc-provider/estimate-gas.test.js +0 -217
  65. package/dist/cjs/providers/test/json-rpc-provider/get-balance.test.js +0 -223
  66. package/dist/cjs/providers/test/json-rpc-provider/get-block-number.test.js +0 -163
  67. package/dist/cjs/providers/test/json-rpc-provider/get-block.test.js +0 -414
  68. package/dist/cjs/providers/test/json-rpc-provider/get-code.test.js +0 -282
  69. package/dist/cjs/providers/test/json-rpc-provider/get-fee-data.test.js +0 -187
  70. package/dist/cjs/providers/test/json-rpc-provider/get-gas-price.test.js +0 -167
  71. package/dist/cjs/providers/test/json-rpc-provider/get-logs/get-logs.test.js +0 -219
  72. package/dist/cjs/providers/test/json-rpc-provider/get-network.test.js +0 -232
  73. package/dist/cjs/providers/test/json-rpc-provider/get-transaction-receipt.test.js +0 -280
  74. package/dist/cjs/providers/test/json-rpc-provider/get-transaction.test.js +0 -266
  75. package/dist/cjs/providers/test/test-alchemy-provider.test.js +0 -151
  76. package/dist/cjs/shared/tiny-big/helpers.test.js +0 -29
  77. package/dist/cjs/shared/tiny-big/tiny-big.test.js +0 -34
  78. package/dist/cjs/utils/tests/bytes/arrayify.test.js +0 -64
  79. package/dist/cjs/utils/tests/bytes/concat.test.js +0 -17
  80. package/dist/cjs/utils/tests/bytes/hex-concat.test.js +0 -65
  81. package/dist/cjs/utils/tests/bytes/hex-data-length.test.js +0 -66
  82. package/dist/cjs/utils/tests/bytes/hex-data-slice.test.js +0 -51
  83. package/dist/cjs/utils/tests/bytes/hex-strip-zeros.test.js +0 -75
  84. package/dist/cjs/utils/tests/bytes/hex-value.test.js +0 -141
  85. package/dist/cjs/utils/tests/bytes/hex-zero-pad.test.js +0 -100
  86. package/dist/cjs/utils/tests/bytes/hexlify.test.js +0 -78
  87. package/dist/cjs/utils/tests/bytes/is-bytes-like.test.js +0 -68
  88. package/dist/cjs/utils/tests/bytes/is-bytes.test.js +0 -76
  89. package/dist/cjs/utils/tests/bytes/is-hex-string.test.js +0 -97
  90. package/dist/cjs/utils/tests/bytes/strip-zeros.test.js +0 -106
  91. package/dist/cjs/utils/tests/bytes/zero-pad.test.js +0 -144
  92. package/dist/cjs/utils/tests/compute-address.test.js +0 -49
  93. package/dist/cjs/utils/tests/compute-public-key.test.js +0 -26
  94. package/dist/cjs/utils/tests/ether-to-gwei.test.js +0 -26
  95. package/dist/cjs/utils/tests/ether-to-wei.test.js +0 -36
  96. package/dist/cjs/utils/tests/gwei-to-ether.test.js +0 -28
  97. package/dist/cjs/utils/tests/hash-message.test.js +0 -32
  98. package/dist/cjs/utils/tests/is-address.test.js +0 -48
  99. package/dist/cjs/utils/tests/keccak256.test.js +0 -121
  100. package/dist/cjs/utils/tests/solidity-keccak256.test.js +0 -311
  101. package/dist/cjs/utils/tests/split-signature.test.js +0 -46
  102. package/dist/cjs/utils/tests/to-checksum-address.test.js +0 -39
  103. package/dist/cjs/utils/tests/to-utf8-bytes.test.js +0 -34
  104. package/dist/cjs/utils/tests/wei-to-ether.test.js +0 -41
@@ -1,375 +0,0 @@
1
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2
- try {
3
- var info = gen[key](arg);
4
- var value = info.value;
5
- } catch (error) {
6
- reject(error);
7
- return;
8
- }
9
- if (info.done) {
10
- resolve(value);
11
- } else {
12
- Promise.resolve(value).then(_next, _throw);
13
- }
14
- }
15
- function _async_to_generator(fn) {
16
- return function() {
17
- var self = this, args = arguments;
18
- return new Promise(function(resolve, reject) {
19
- var gen = fn.apply(self, args);
20
- function _next(value) {
21
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
22
- }
23
- function _throw(err) {
24
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
25
- }
26
- _next(undefined);
27
- });
28
- };
29
- }
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;
42
- }
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
- }));
51
- }
52
- ownKeys.forEach(function(key) {
53
- _define_property(target, key, source[key]);
54
- });
55
- }
56
- return target;
57
- }
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;
70
- }
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;
81
- }
82
- function _ts_generator(thisArg, body) {
83
- var f, y, t, g, _ = {
84
- label: 0,
85
- sent: function() {
86
- if (t[0] & 1) throw t[1];
87
- return t[1];
88
- },
89
- trys: [],
90
- ops: []
91
- };
92
- return g = {
93
- next: verb(0),
94
- "throw": verb(1),
95
- "return": verb(2)
96
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
97
- return this;
98
- }), g;
99
- function verb(n) {
100
- return function(v) {
101
- return step([
102
- n,
103
- v
104
- ]);
105
- };
106
- }
107
- function step(op) {
108
- if (f) throw new TypeError("Generator is already executing.");
109
- while(_)try {
110
- 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;
111
- if (y = 0, t) op = [
112
- op[0] & 2,
113
- t.value
114
- ];
115
- switch(op[0]){
116
- case 0:
117
- case 1:
118
- t = op;
119
- break;
120
- case 4:
121
- _.label++;
122
- return {
123
- value: op[1],
124
- done: false
125
- };
126
- case 5:
127
- _.label++;
128
- y = op[1];
129
- op = [
130
- 0
131
- ];
132
- continue;
133
- case 7:
134
- op = _.ops.pop();
135
- _.trys.pop();
136
- continue;
137
- default:
138
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
139
- _ = 0;
140
- continue;
141
- }
142
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
143
- _.label = op[1];
144
- break;
145
- }
146
- if (op[0] === 6 && _.label < t[1]) {
147
- _.label = t[1];
148
- t = op;
149
- break;
150
- }
151
- if (t && _.label < t[2]) {
152
- _.label = t[2];
153
- _.ops.push(op);
154
- break;
155
- }
156
- if (t[2]) _.ops.pop();
157
- _.trys.pop();
158
- continue;
159
- }
160
- op = body.call(thisArg, _);
161
- } catch (e) {
162
- op = [
163
- 6,
164
- e
165
- ];
166
- y = 0;
167
- } finally{
168
- f = t = 0;
169
- }
170
- if (op[0] & 5) throw op[1];
171
- return {
172
- value: op[0] ? op[1] : void 0,
173
- done: true
174
- };
175
- }
176
- }
177
- import Big from "big.js";
178
- import * as unfetch from "isomorphic-unfetch";
179
- import { JsonRpcProvider, tinyBig } from "../../..";
180
- import { buildFetchInit, buildRPCPostBody } from "../../../classes/utils/fetchers";
181
- import { hexToDecimal } from "../../../classes/utils/hex-to-decimal";
182
- import { prepareTransaction } from "../../../classes/utils/prepare-transaction";
183
- import { mockOf } from "../mock-of";
184
- import { rpcUrls } from "./../rpc-urls";
185
- var rpcUrl = rpcUrls.mainnet;
186
- jest.mock("isomorphic-unfetch");
187
- // Based on https://etherscan.io/tx/0x277c40de5bf1d4fa06e37dce8e1370dac7273a4b2a883515176f51abaa50d512
188
- var dataTo = {
189
- data: "0x70a082310000000000000000000000006E0d01A76C3Cf4288372a29124A26D4353EE51BE",
190
- to: "0x6b175474e89094c44da98b954eedeac495271d0f"
191
- };
192
- // Based on https://etherscan.io/tx/0xfc4a0544289c9eae2f94a9091208e3793ef8e9e93ea4dbaa80f70115be5e9813
193
- var dataFromGasTo = {
194
- to: "0x3d13c2224a1cdd661e4cc91091f83047750270c5",
195
- from: "0x0000000000000000000000000000000000000000",
196
- nonce: "0x1",
197
- gas: 999999,
198
- data: "0x1234",
199
- value: "0x123",
200
- // not sure how to get "chainId" into proper format
201
- // chainId: 1,
202
- type: 1,
203
- maxFeePerGas: "0xffffffffff"
204
- };
205
- describe("provider.call", function() {
206
- var provider = new JsonRpcProvider(rpcUrl);
207
- it("throws", /*#__PURE__*/ _async_to_generator(function() {
208
- return _ts_generator(this, function(_state) {
209
- switch(_state.label){
210
- case 0:
211
- return [
212
- 4,
213
- expect(provider.call(_object_spread_props(_object_spread({}, dataTo), {
214
- maxFeePerGas: "0x12",
215
- maxPriorityFeePerGas: "0x123"
216
- }))).rejects.toThrow()
217
- ];
218
- case 1:
219
- _state.sent();
220
- return [
221
- 4,
222
- expect(provider.call(_object_spread_props(_object_spread({}, dataTo), {
223
- gasPrice: "0xfffffff",
224
- maxFeePerGas: "0x12"
225
- }))).rejects.toThrow()
226
- ];
227
- case 2:
228
- _state.sent();
229
- return [
230
- 4,
231
- expect(provider.call(_object_spread_props(_object_spread({}, dataTo), {
232
- gasPrice: "0xfffffff",
233
- maxPriorityFeePerGas: "0x123"
234
- }))).rejects.toThrow()
235
- ];
236
- case 3:
237
- _state.sent();
238
- return [
239
- 2
240
- ];
241
- }
242
- });
243
- }));
244
- function testWithMockedResponse(data) {
245
- return _testWithMockedResponse.apply(this, arguments);
246
- }
247
- function _testWithMockedResponse() {
248
- _testWithMockedResponse = _async_to_generator(function(data) {
249
- var expectedResult, spy, callProvider;
250
- return _ts_generator(this, function(_state) {
251
- switch(_state.label){
252
- case 0:
253
- expectedResult = "0x0000000000000000000000000000000000000000000000000858898f93629000";
254
- mockOf(unfetch.default).mockResolvedValueOnce({
255
- text: function() {
256
- return Promise.resolve(JSON.stringify({
257
- jsonrpc: "2.0",
258
- id: 1,
259
- result: expectedResult
260
- }));
261
- }
262
- });
263
- spy = jest.spyOn(unfetch, "default");
264
- return [
265
- 4,
266
- provider.call(data)
267
- ];
268
- case 1:
269
- callProvider = _state.sent();
270
- expect(callProvider).toBe(expectedResult);
271
- expect(spy).toHaveBeenCalledWith(rpcUrl, buildFetchInit(buildRPCPostBody("eth_call", [
272
- prepareTransaction(data),
273
- "latest"
274
- ])));
275
- return [
276
- 2
277
- ];
278
- }
279
- });
280
- });
281
- return _testWithMockedResponse.apply(this, arguments);
282
- }
283
- it("should return a valid response for given input -- data, to", /*#__PURE__*/ _async_to_generator(function() {
284
- return _ts_generator(this, function(_state) {
285
- switch(_state.label){
286
- case 0:
287
- return [
288
- 4,
289
- testWithMockedResponse(dataTo)
290
- ];
291
- case 1:
292
- _state.sent();
293
- return [
294
- 2
295
- ];
296
- }
297
- });
298
- }));
299
- it("should return a valid response for given input -- data, to, gasPrice", /*#__PURE__*/ _async_to_generator(function() {
300
- var data;
301
- return _ts_generator(this, function(_state) {
302
- switch(_state.label){
303
- case 0:
304
- data = _object_spread_props(_object_spread({}, dataTo), {
305
- gasPrice: 99999999999
306
- });
307
- return [
308
- 4,
309
- testWithMockedResponse(data)
310
- ];
311
- case 1:
312
- _state.sent();
313
- return [
314
- 2
315
- ];
316
- }
317
- });
318
- }));
319
- it("should return a valid response for given input -- all mixed data as strings", /*#__PURE__*/ _async_to_generator(function() {
320
- return _ts_generator(this, function(_state) {
321
- switch(_state.label){
322
- case 0:
323
- return [
324
- 4,
325
- testWithMockedResponse(dataFromGasTo)
326
- ];
327
- case 1:
328
- _state.sent();
329
- return [
330
- 2
331
- ];
332
- }
333
- });
334
- }));
335
- it("should return a valid response for given input -- all mixed data as TinyBig", /*#__PURE__*/ _async_to_generator(function() {
336
- return _ts_generator(this, function(_state) {
337
- switch(_state.label){
338
- case 0:
339
- return [
340
- 4,
341
- testWithMockedResponse(_object_spread_props(_object_spread({}, dataFromGasTo), {
342
- nonce: tinyBig(dataFromGasTo.nonce),
343
- gas: tinyBig(dataFromGasTo.gas),
344
- value: tinyBig(dataFromGasTo.value)
345
- }))
346
- ];
347
- case 1:
348
- _state.sent();
349
- return [
350
- 2
351
- ];
352
- }
353
- });
354
- }));
355
- it("should return a valid response for given input -- all mixed data as Big", /*#__PURE__*/ _async_to_generator(function() {
356
- return _ts_generator(this, function(_state) {
357
- switch(_state.label){
358
- case 0:
359
- return [
360
- 4,
361
- testWithMockedResponse(_object_spread_props(_object_spread({}, dataFromGasTo), {
362
- nonce: new Big(hexToDecimal(dataFromGasTo.nonce)),
363
- gas: new Big(dataFromGasTo.gas),
364
- value: new Big(hexToDecimal(dataFromGasTo.value))
365
- }))
366
- ];
367
- case 1:
368
- _state.sent();
369
- return [
370
- 2
371
- ];
372
- }
373
- });
374
- }));
375
- });
@@ -1,217 +0,0 @@
1
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2
- try {
3
- var info = gen[key](arg);
4
- var value = info.value;
5
- } catch (error) {
6
- reject(error);
7
- return;
8
- }
9
- if (info.done) {
10
- resolve(value);
11
- } else {
12
- Promise.resolve(value).then(_next, _throw);
13
- }
14
- }
15
- function _async_to_generator(fn) {
16
- return function() {
17
- var self = this, args = arguments;
18
- return new Promise(function(resolve, reject) {
19
- var gen = fn.apply(self, args);
20
- function _next(value) {
21
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
22
- }
23
- function _throw(err) {
24
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
25
- }
26
- _next(undefined);
27
- });
28
- };
29
- }
30
- function _ts_generator(thisArg, body) {
31
- var f, y, t, g, _ = {
32
- label: 0,
33
- sent: function() {
34
- if (t[0] & 1) throw t[1];
35
- return t[1];
36
- },
37
- trys: [],
38
- ops: []
39
- };
40
- return g = {
41
- next: verb(0),
42
- "throw": verb(1),
43
- "return": verb(2)
44
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
45
- return this;
46
- }), g;
47
- function verb(n) {
48
- return function(v) {
49
- return step([
50
- n,
51
- v
52
- ]);
53
- };
54
- }
55
- function step(op) {
56
- if (f) throw new TypeError("Generator is already executing.");
57
- while(_)try {
58
- 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;
59
- if (y = 0, t) op = [
60
- op[0] & 2,
61
- t.value
62
- ];
63
- switch(op[0]){
64
- case 0:
65
- case 1:
66
- t = op;
67
- break;
68
- case 4:
69
- _.label++;
70
- return {
71
- value: op[1],
72
- done: false
73
- };
74
- case 5:
75
- _.label++;
76
- y = op[1];
77
- op = [
78
- 0
79
- ];
80
- continue;
81
- case 7:
82
- op = _.ops.pop();
83
- _.trys.pop();
84
- continue;
85
- default:
86
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
87
- _ = 0;
88
- continue;
89
- }
90
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
91
- _.label = op[1];
92
- break;
93
- }
94
- if (op[0] === 6 && _.label < t[1]) {
95
- _.label = t[1];
96
- t = op;
97
- break;
98
- }
99
- if (t && _.label < t[2]) {
100
- _.label = t[2];
101
- _.ops.push(op);
102
- break;
103
- }
104
- if (t[2]) _.ops.pop();
105
- _.trys.pop();
106
- continue;
107
- }
108
- op = body.call(thisArg, _);
109
- } catch (e) {
110
- op = [
111
- 6,
112
- e
113
- ];
114
- y = 0;
115
- } finally{
116
- f = t = 0;
117
- }
118
- if (op[0] & 5) throw op[1];
119
- return {
120
- value: op[0] ? op[1] : void 0,
121
- done: true
122
- };
123
- }
124
- }
125
- import * as unfetch from "isomorphic-unfetch";
126
- import { JsonRpcProvider } from "../../..";
127
- import { buildFetchInit, buildRPCPostBody } from "../../../classes/utils/fetchers";
128
- import { prepareTransaction } from "../../../classes/utils/prepare-transaction";
129
- import { etherToWei } from "../../../utils/ether-to-wei";
130
- import { mockOf } from "../mock-of";
131
- import { rpcUrls } from "../rpc-urls";
132
- jest.mock("isomorphic-unfetch");
133
- var rpcUrl = rpcUrls.mainnet;
134
- var dataTo = {
135
- to: "0x4976fb03C32e5B8cfe2b6cCB31c09Ba78EBaBa41",
136
- data: "0x3b3b57debf074faa138b72c65adbdcfb329847e4f2c04bde7f7dd7fcad5a52d2f395a558"
137
- };
138
- var dataToValue = {
139
- // Wrapped ETH address
140
- to: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
141
- // `function deposit() payable`
142
- data: "0xd0e30db0",
143
- value: etherToWei(0.001).toNumber()
144
- };
145
- function testEstimateGas(transaction) {
146
- return _testEstimateGas.apply(this, arguments);
147
- }
148
- function _testEstimateGas() {
149
- _testEstimateGas = _async_to_generator(function(transaction) {
150
- var provider, mockPostResponse, spy, estimatedGas;
151
- return _ts_generator(this, function(_state) {
152
- switch(_state.label){
153
- case 0:
154
- provider = new JsonRpcProvider(rpcUrl);
155
- mockPostResponse = JSON.stringify({
156
- jsonrpc: "2.0",
157
- id: 1,
158
- result: "0xa"
159
- });
160
- mockOf(unfetch.default).mockResolvedValueOnce({
161
- text: function() {
162
- return Promise.resolve(mockPostResponse);
163
- }
164
- });
165
- spy = jest.spyOn(unfetch, "default");
166
- return [
167
- 4,
168
- provider.estimateGas(transaction)
169
- ];
170
- case 1:
171
- estimatedGas = _state.sent();
172
- expect(estimatedGas.toString()).toBe("10");
173
- expect(spy).toHaveBeenCalledWith(rpcUrl, buildFetchInit(buildRPCPostBody("eth_estimateGas", [
174
- prepareTransaction(transaction)
175
- ])));
176
- return [
177
- 2
178
- ];
179
- }
180
- });
181
- });
182
- return _testEstimateGas.apply(this, arguments);
183
- }
184
- describe("provider.estimateGas", function() {
185
- it("should estimate gas with data and to", /*#__PURE__*/ _async_to_generator(function() {
186
- return _ts_generator(this, function(_state) {
187
- switch(_state.label){
188
- case 0:
189
- return [
190
- 4,
191
- testEstimateGas(dataTo)
192
- ];
193
- case 1:
194
- _state.sent();
195
- return [
196
- 2
197
- ];
198
- }
199
- });
200
- }));
201
- it("should estimate gas with data, to, and value", /*#__PURE__*/ _async_to_generator(function() {
202
- return _ts_generator(this, function(_state) {
203
- switch(_state.label){
204
- case 0:
205
- return [
206
- 4,
207
- testEstimateGas(dataToValue)
208
- ];
209
- case 1:
210
- _state.sent();
211
- return [
212
- 2
213
- ];
214
- }
215
- });
216
- }));
217
- });