@ledgerhq/coin-evm 10.0.0 → 10.1.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/.oxlintrc.json +2 -6
- package/CHANGELOG.md +12 -0
- package/lib/abis/index.d.ts +8 -0
- package/lib/abis/index.d.ts.map +1 -1
- package/lib/abis/index.js +30 -0
- package/lib/abis/index.js.map +1 -1
- package/lib/adapters/blockOperations.js +2 -2
- package/lib/adapters/blockOperations.js.map +1 -1
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.js +2 -1
- package/lib/api/index.js.map +1 -1
- package/lib/internalTxSources.d.ts.map +1 -1
- package/lib/internalTxSources.js +21 -3
- package/lib/internalTxSources.js.map +1 -1
- package/lib/logic/common.d.ts.map +1 -1
- package/lib/logic/common.js +11 -3
- package/lib/logic/common.js.map +1 -1
- package/lib/logic/craftTransaction.d.ts.map +1 -1
- package/lib/logic/craftTransaction.js +4 -1
- package/lib/logic/craftTransaction.js.map +1 -1
- package/lib/logic/estimateFees.d.ts.map +1 -1
- package/lib/logic/estimateFees.js +4 -1
- package/lib/logic/estimateFees.js.map +1 -1
- package/lib/logic/internalTransactionsFetcher.js +1 -1
- package/lib/logic/internalTransactionsFetcher.js.map +1 -1
- package/lib/logic/predicates.d.ts +17 -0
- package/lib/logic/predicates.d.ts.map +1 -0
- package/lib/logic/predicates.js +126 -0
- package/lib/logic/predicates.js.map +1 -0
- package/lib/network/explorer/types.d.ts.map +1 -1
- package/lib/network/explorer/types.js +11 -1
- package/lib/network/explorer/types.js.map +1 -1
- package/lib/network/gasTracker/ledger.d.ts.map +1 -1
- package/lib/network/gasTracker/ledger.js +1 -3
- package/lib/network/gasTracker/ledger.js.map +1 -1
- package/lib/network/node/explorerProxy.d.ts.map +1 -1
- package/lib/network/node/explorerProxy.js +10 -5
- package/lib/network/node/explorerProxy.js.map +1 -1
- package/lib/network/node/gethCallTracerToTraceBlockItems.d.ts.map +1 -1
- package/lib/network/node/gethCallTracerToTraceBlockItems.js +10 -12
- package/lib/network/node/gethCallTracerToTraceBlockItems.js.map +1 -1
- package/lib/network/node/ledger.d.ts.map +1 -1
- package/lib/network/node/ledger.js +10 -5
- package/lib/network/node/ledger.js.map +1 -1
- package/lib/network/node/rpc.common.d.ts.map +1 -1
- package/lib/network/node/rpc.common.js +60 -70
- package/lib/network/node/rpc.common.js.map +1 -1
- package/lib/network/node/types.d.ts +6 -7
- package/lib/network/node/types.d.ts.map +1 -1
- package/lib/network/node/types.js +0 -27
- package/lib/network/node/types.js.map +1 -1
- package/lib/nodeSources.d.ts.map +1 -1
- package/lib/nodeSources.js +11 -3
- package/lib/nodeSources.js.map +1 -1
- package/lib/staking/contracts.d.ts.map +1 -1
- package/lib/staking/contracts.js +1 -3
- package/lib/staking/contracts.js.map +1 -1
- package/lib/staking/detectOperationType.d.ts +0 -3
- package/lib/staking/detectOperationType.d.ts.map +1 -1
- package/lib/staking/detectOperationType.js +15 -14
- package/lib/staking/detectOperationType.js.map +1 -1
- package/lib/staking/operations/index.d.ts.map +1 -1
- package/lib/staking/operations/index.js +18 -1
- package/lib/staking/operations/index.js.map +1 -1
- package/lib/staking/prepareIntents.d.ts.map +1 -1
- package/lib/staking/prepareIntents.js +4 -3
- package/lib/staking/prepareIntents.js.map +1 -1
- package/lib/staking/redelegations.d.ts.map +1 -1
- package/lib/staking/redelegations.js +4 -7
- package/lib/staking/redelegations.js.map +1 -1
- package/lib/staking/utils.d.ts.map +1 -1
- package/lib/staking/utils.js +22 -27
- package/lib/staking/utils.js.map +1 -1
- package/lib/staking/validators/monad.d.ts.map +1 -1
- package/lib/staking/validators/monad.js +15 -6
- package/lib/staking/validators/monad.js.map +1 -1
- package/lib/staking/validators/monadResolver.d.ts.map +1 -1
- package/lib/staking/validators/monadResolver.js +4 -3
- package/lib/staking/validators/monadResolver.js.map +1 -1
- package/lib/staking/validators/somnia.d.ts.map +1 -1
- package/lib/staking/validators/somnia.js +4 -3
- package/lib/staking/validators/somnia.js.map +1 -1
- package/lib/staking/validators/zero_gravity.d.ts.map +1 -1
- package/lib/staking/validators/zero_gravity.js +4 -3
- package/lib/staking/validators/zero_gravity.js.map +1 -1
- package/lib-es/abis/index.d.ts +8 -0
- package/lib-es/abis/index.d.ts.map +1 -1
- package/lib-es/abis/index.js +29 -0
- package/lib-es/abis/index.js.map +1 -1
- package/lib-es/adapters/blockOperations.js +1 -1
- package/lib-es/adapters/blockOperations.js.map +1 -1
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.js +2 -1
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/internalTxSources.d.ts.map +1 -1
- package/lib-es/internalTxSources.js +21 -3
- package/lib-es/internalTxSources.js.map +1 -1
- package/lib-es/logic/common.d.ts.map +1 -1
- package/lib-es/logic/common.js +11 -3
- package/lib-es/logic/common.js.map +1 -1
- package/lib-es/logic/craftTransaction.d.ts.map +1 -1
- package/lib-es/logic/craftTransaction.js +4 -1
- package/lib-es/logic/craftTransaction.js.map +1 -1
- package/lib-es/logic/estimateFees.d.ts.map +1 -1
- package/lib-es/logic/estimateFees.js +4 -1
- package/lib-es/logic/estimateFees.js.map +1 -1
- package/lib-es/logic/internalTransactionsFetcher.js +1 -1
- package/lib-es/logic/internalTransactionsFetcher.js.map +1 -1
- package/lib-es/logic/predicates.d.ts +17 -0
- package/lib-es/logic/predicates.d.ts.map +1 -0
- package/lib-es/logic/predicates.js +114 -0
- package/lib-es/logic/predicates.js.map +1 -0
- package/lib-es/network/explorer/types.d.ts.map +1 -1
- package/lib-es/network/explorer/types.js +11 -1
- package/lib-es/network/explorer/types.js.map +1 -1
- package/lib-es/network/gasTracker/ledger.d.ts.map +1 -1
- package/lib-es/network/gasTracker/ledger.js +1 -3
- package/lib-es/network/gasTracker/ledger.js.map +1 -1
- package/lib-es/network/node/explorerProxy.d.ts.map +1 -1
- package/lib-es/network/node/explorerProxy.js +10 -5
- package/lib-es/network/node/explorerProxy.js.map +1 -1
- package/lib-es/network/node/gethCallTracerToTraceBlockItems.d.ts.map +1 -1
- package/lib-es/network/node/gethCallTracerToTraceBlockItems.js +4 -6
- package/lib-es/network/node/gethCallTracerToTraceBlockItems.js.map +1 -1
- package/lib-es/network/node/ledger.d.ts.map +1 -1
- package/lib-es/network/node/ledger.js +10 -5
- package/lib-es/network/node/ledger.js.map +1 -1
- package/lib-es/network/node/rpc.common.d.ts.map +1 -1
- package/lib-es/network/node/rpc.common.js +58 -68
- package/lib-es/network/node/rpc.common.js.map +1 -1
- package/lib-es/network/node/types.d.ts +6 -7
- package/lib-es/network/node/types.d.ts.map +1 -1
- package/lib-es/network/node/types.js +0 -25
- package/lib-es/network/node/types.js.map +1 -1
- package/lib-es/nodeSources.d.ts.map +1 -1
- package/lib-es/nodeSources.js +11 -3
- package/lib-es/nodeSources.js.map +1 -1
- package/lib-es/staking/contracts.d.ts.map +1 -1
- package/lib-es/staking/contracts.js +1 -3
- package/lib-es/staking/contracts.js.map +1 -1
- package/lib-es/staking/detectOperationType.d.ts +0 -3
- package/lib-es/staking/detectOperationType.d.ts.map +1 -1
- package/lib-es/staking/detectOperationType.js +15 -14
- package/lib-es/staking/detectOperationType.js.map +1 -1
- package/lib-es/staking/operations/index.d.ts.map +1 -1
- package/lib-es/staking/operations/index.js +18 -1
- package/lib-es/staking/operations/index.js.map +1 -1
- package/lib-es/staking/prepareIntents.d.ts.map +1 -1
- package/lib-es/staking/prepareIntents.js +2 -1
- package/lib-es/staking/prepareIntents.js.map +1 -1
- package/lib-es/staking/redelegations.d.ts.map +1 -1
- package/lib-es/staking/redelegations.js +1 -4
- package/lib-es/staking/redelegations.js.map +1 -1
- package/lib-es/staking/utils.d.ts.map +1 -1
- package/lib-es/staking/utils.js +20 -25
- package/lib-es/staking/utils.js.map +1 -1
- package/lib-es/staking/validators/monad.d.ts.map +1 -1
- package/lib-es/staking/validators/monad.js +12 -3
- package/lib-es/staking/validators/monad.js.map +1 -1
- package/lib-es/staking/validators/monadResolver.d.ts.map +1 -1
- package/lib-es/staking/validators/monadResolver.js +2 -1
- package/lib-es/staking/validators/monadResolver.js.map +1 -1
- package/lib-es/staking/validators/somnia.d.ts.map +1 -1
- package/lib-es/staking/validators/somnia.js +2 -1
- package/lib-es/staking/validators/somnia.js.map +1 -1
- package/lib-es/staking/validators/zero_gravity.d.ts.map +1 -1
- package/lib-es/staking/validators/zero_gravity.js +2 -1
- package/lib-es/staking/validators/zero_gravity.js.map +1 -1
- package/package.json +2 -2
- package/src/abis/index.test.ts +36 -0
- package/src/abis/index.ts +30 -0
- package/src/adapters/blockOperations.ts +1 -1
- package/src/api/index.ts +3 -2
- package/src/internalTxSources.ts +20 -3
- package/src/logic/common.ts +13 -3
- package/src/logic/craftTransaction.ts +4 -2
- package/src/logic/estimateFees.ts +4 -2
- package/src/logic/internalTransactionsFetcher.ts +1 -1
- package/src/logic/predicates.ts +124 -0
- package/src/logic/tests/validateIntent.test.ts +4 -1
- package/src/network/explorer/ledger.test.ts +21 -15
- package/src/network/explorer/types.ts +12 -3
- package/src/network/gasTracker/ledger.ts +1 -4
- package/src/network/node/explorerProxy.ts +11 -8
- package/src/network/node/gethCallTracerToTraceBlockItems.test.ts +1 -1
- package/src/network/node/gethCallTracerToTraceBlockItems.ts +6 -9
- package/src/network/node/ledger.ts +14 -10
- package/src/network/node/rpc.common.ts +92 -88
- package/src/network/node/rpc.test.ts +119 -0
- package/src/network/node/types.ts +6 -35
- package/src/nodeSources.ts +11 -3
- package/src/staking/contracts.ts +1 -3
- package/src/staking/detectOperationType.ts +15 -14
- package/src/staking/operations/index.ts +26 -7
- package/src/staking/prepareIntents.ts +2 -1
- package/src/staking/redelegations.ts +1 -5
- package/src/staking/utils.ts +19 -26
- package/src/staking/validators/monad.ts +11 -3
- package/src/staking/validators/monadResolver.ts +2 -1
- package/src/staking/validators/somnia.ts +4 -3
- package/src/staking/validators/zero_gravity.ts +2 -1
|
@@ -5,6 +5,7 @@ import type { BlockByHeightResult, NodeApi, TransactionInfo } from './types'
|
|
|
5
5
|
import type { Logger } from '@ledgerhq/coin-module-framework/config'
|
|
6
6
|
import axios from 'axios'
|
|
7
7
|
import { isSmartContractInput, safeEncodeEIP55 } from '../../logic-public'
|
|
8
|
+
import { isRecord } from '../../logic/predicates'
|
|
8
9
|
import { ETHERSCAN_TIMEOUT } from '../explorer/etherscan'
|
|
9
10
|
import { withRetries } from '../withRetries'
|
|
10
11
|
import { parseERC20TransfersFromLogs } from './rpc.common'
|
|
@@ -89,8 +90,8 @@ export async function getBlockFromExplorerProxy(
|
|
|
89
90
|
explorerUri,
|
|
90
91
|
{ action: 'eth_getBlockByNumber', tag: hexHeight, boolean: 'false' },
|
|
91
92
|
(result) => {
|
|
92
|
-
|
|
93
|
-
|
|
93
|
+
if (!isRecord(result)) return null
|
|
94
|
+
const block = result
|
|
94
95
|
|
|
95
96
|
const hash = block.hash
|
|
96
97
|
if (typeof hash !== 'string' || !hash || /^0x0+$/.test(hash)) return null
|
|
@@ -142,8 +143,9 @@ export async function getTransactionFromExplorerProxy(
|
|
|
142
143
|
explorerUri,
|
|
143
144
|
{ action: 'eth_getTransactionByHash', txhash: hash },
|
|
144
145
|
(r) => {
|
|
145
|
-
|
|
146
|
-
|
|
146
|
+
if (!isRecord(r)) return null
|
|
147
|
+
const t = r
|
|
148
|
+
if (typeof t.hash !== 'string') return null
|
|
147
149
|
if (t.hash.toLowerCase() !== hash.toLowerCase()) return null
|
|
148
150
|
return t
|
|
149
151
|
},
|
|
@@ -154,8 +156,9 @@ export async function getTransactionFromExplorerProxy(
|
|
|
154
156
|
explorerUri,
|
|
155
157
|
{ action: 'eth_getTransactionReceipt', txhash: hash },
|
|
156
158
|
(r) => {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
+
if (!isRecord(r)) return null
|
|
160
|
+
const rec = r
|
|
161
|
+
if (typeof rec.transactionHash !== 'string') return null
|
|
159
162
|
if (rec.transactionHash.toLowerCase() !== hash.toLowerCase()) return null
|
|
160
163
|
return rec
|
|
161
164
|
},
|
|
@@ -196,8 +199,8 @@ export async function getTransactionFromExplorerProxy(
|
|
|
196
199
|
if (!Array.isArray(receipt.logs)) return null
|
|
197
200
|
const logs: { address: string; topics: string[]; data: string }[] = []
|
|
198
201
|
for (const l of receipt.logs) {
|
|
199
|
-
if (!l
|
|
200
|
-
const entry = l
|
|
202
|
+
if (!isRecord(l)) return null
|
|
203
|
+
const entry = l
|
|
201
204
|
if (typeof entry.address !== 'string') return null
|
|
202
205
|
if (typeof entry.data !== 'string') return null
|
|
203
206
|
if (
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import type { TraceBlockItem } from './types'
|
|
5
|
+
import { isTraceBlockItem } from '../../logic/predicates'
|
|
5
6
|
import { gethCallTracerToTraceBlockItems } from './gethCallTracerToTraceBlockItems'
|
|
6
7
|
import flareBlock0x36ffc39CallTracerTrace from './resources/flare-0x36ffc39-debug-trace-block-call-tracer.json'
|
|
7
|
-
import { isTraceBlockItem } from './types'
|
|
8
8
|
|
|
9
9
|
describe('gethCallTracerToTraceBlockItems', () => {
|
|
10
10
|
const blockNumber = 12345
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import type { TraceBlockItem, TraceBlockOtherAction, TraceBlockResult } from './types'
|
|
5
|
+
import { isRecord, isString } from '../../logic/predicates'
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Geth `debug_traceBlockByNumber` with `callTracer` returns one entry per transaction (same order as
|
|
@@ -39,10 +40,6 @@ export function gethCallTracerToTraceBlockItems(
|
|
|
39
40
|
.filter((item) => item !== null)
|
|
40
41
|
}
|
|
41
42
|
|
|
42
|
-
function isString(value: unknown): value is string {
|
|
43
|
-
return typeof value === 'string'
|
|
44
|
-
}
|
|
45
|
-
|
|
46
43
|
function stringValue(value: unknown, orDefault: string): string {
|
|
47
44
|
if (isString(value)) return value
|
|
48
45
|
return orDefault
|
|
@@ -64,8 +61,8 @@ function parseDebugTraceBlockEntry(
|
|
|
64
61
|
entry: unknown,
|
|
65
62
|
index: number
|
|
66
63
|
): { txHash: string; root: Record<string, unknown> } | null {
|
|
67
|
-
if (
|
|
68
|
-
const o = entry
|
|
64
|
+
if (!isRecord(entry)) return null
|
|
65
|
+
const o = entry
|
|
69
66
|
const txHash = extractTxHash(o)
|
|
70
67
|
|
|
71
68
|
if (txHash !== null) {
|
|
@@ -80,13 +77,13 @@ function parseDebugTraceBlockEntry(
|
|
|
80
77
|
`debug_traceBlockByNumber entry at index ${index} (tx ${txHash}) has null or undefined "result"`
|
|
81
78
|
)
|
|
82
79
|
}
|
|
83
|
-
if (
|
|
80
|
+
if (!isRecord(inner)) {
|
|
84
81
|
throw new TypeError(
|
|
85
82
|
`debug_traceBlockByNumber entry at index ${index} (tx ${txHash}) has invalid "result" (expected object)`
|
|
86
83
|
)
|
|
87
84
|
}
|
|
88
85
|
|
|
89
|
-
return { txHash, root: inner
|
|
86
|
+
return { txHash, root: inner }
|
|
90
87
|
}
|
|
91
88
|
|
|
92
89
|
if ('type' in o || 'from' in o || 'calls' in o) {
|
|
@@ -121,7 +118,7 @@ function flattenCallFrame(
|
|
|
121
118
|
|
|
122
119
|
for (let i = 0; i < calls.length; i++) {
|
|
123
120
|
const child = calls[i]
|
|
124
|
-
if (child
|
|
121
|
+
if (isRecord(child)) {
|
|
125
122
|
items.push(
|
|
126
123
|
...flattenCallFrame(
|
|
127
124
|
child,
|
|
@@ -11,6 +11,7 @@ import { makeBatcher } from '@ledgerhq/live-network/batcher/index'
|
|
|
11
11
|
import axios from 'axios'
|
|
12
12
|
import BigNumber from 'bignumber.js'
|
|
13
13
|
import { ethers } from 'ethers'
|
|
14
|
+
import { toInterfaceAbi } from '../../abis'
|
|
14
15
|
import ERC20Abi from '../../abis/erc20.abi.json'
|
|
15
16
|
import OptimismGasPriceOracleAbi from '../../abis/optimismGasPriceOracle.abi.json'
|
|
16
17
|
import { GasEstimationError } from '../../errors'
|
|
@@ -50,12 +51,12 @@ function makeFetchWithRetries(config: LedgerNodeApiConfig): LedgerFetch {
|
|
|
50
51
|
}
|
|
51
52
|
}
|
|
52
53
|
|
|
53
|
-
function make<
|
|
54
|
-
f: (fetch: LedgerFetch, config: LedgerNodeApiConfig, ...args:
|
|
54
|
+
function make<Args extends readonly unknown[], R>(
|
|
55
|
+
f: (fetch: LedgerFetch, config: LedgerNodeApiConfig, currencyId: string, ...args: Args) => R,
|
|
55
56
|
config: LedgerNodeApiConfig,
|
|
56
57
|
fetch: LedgerFetch
|
|
57
|
-
):
|
|
58
|
-
return (
|
|
58
|
+
): (currencyId: string, ...args: Args) => R {
|
|
59
|
+
return (currencyId, ...args) => f(fetch, config, currencyId, ...args)
|
|
59
60
|
}
|
|
60
61
|
|
|
61
62
|
async function getTransaction(
|
|
@@ -210,7 +211,11 @@ async function getFeeData(
|
|
|
210
211
|
overrideGasTracker: { type: 'ledger', explorerId: config.explorerId },
|
|
211
212
|
},
|
|
212
213
|
})
|
|
213
|
-
|
|
214
|
+
const strategy = transaction.feesStrategy
|
|
215
|
+
if (strategy === 'slow' || strategy === 'medium' || strategy === 'fast') {
|
|
216
|
+
return options[strategy]
|
|
217
|
+
}
|
|
218
|
+
return options.medium
|
|
214
219
|
}
|
|
215
220
|
|
|
216
221
|
async function broadcastTransaction(
|
|
@@ -368,7 +373,7 @@ function makeGetTokenAllowance(
|
|
|
368
373
|
config: LedgerNodeApiConfig,
|
|
369
374
|
fetch: LedgerFetch
|
|
370
375
|
): NodeApi['getTokenAllowance'] {
|
|
371
|
-
const iface = new ethers.Interface(ERC20Abi
|
|
376
|
+
const iface = new ethers.Interface(toInterfaceAbi(ERC20Abi))
|
|
372
377
|
return async (_currencyId, ownerAddress, contractAddress, spenderAddress) => {
|
|
373
378
|
const data = iface.encodeFunctionData('allowance', [
|
|
374
379
|
ethers.getAddress(ownerAddress),
|
|
@@ -433,13 +438,12 @@ export function createLedgerNodeApi(config: LedgerNodeApiConfig, logger: Logger)
|
|
|
433
438
|
getTokenBalance: makeGetTokenBalance(config, fetch, tokenBalancesBatchersMap),
|
|
434
439
|
getTokenAllowance: makeGetTokenAllowance(config, fetch),
|
|
435
440
|
getTransactionCount: make(getTransactionCount, config, fetch),
|
|
436
|
-
getTransaction: (
|
|
437
|
-
getTransaction(fetch, config, currencyId, hash, logger)) as NodeApi['getTransaction'],
|
|
441
|
+
getTransaction: (currencyId, hash) => getTransaction(fetch, config, currencyId, hash, logger),
|
|
438
442
|
getGasEstimation: makeGetGasEstimation(config, fetch, logger),
|
|
439
443
|
// getFeeData takes `config` (EvmConfigInfo) first, not `currency`, so it doesn't fit the
|
|
440
444
|
// currency-first `make` type bound; bind it directly (same fetch/config passthrough as `make`).
|
|
441
|
-
getFeeData: (
|
|
442
|
-
getFeeData(fetch, config,
|
|
445
|
+
getFeeData: (evmConfig, currencyId, transaction) =>
|
|
446
|
+
getFeeData(fetch, config, evmConfig, currencyId, transaction),
|
|
443
447
|
broadcastTransaction: make(broadcastTransaction, config, fetch),
|
|
444
448
|
getOptimismAdditionalFees: make(getOptimismAdditionalFees, config, fetch),
|
|
445
449
|
getScrollAdditionalFees: make(getScrollAdditionalFees, config, fetch),
|
|
@@ -6,7 +6,6 @@ import type { FeeHistory, FeeData } from '../../types'
|
|
|
6
6
|
import type {
|
|
7
7
|
NodeApi,
|
|
8
8
|
ERC20Transfer,
|
|
9
|
-
PrefetchedBlockTransaction,
|
|
10
9
|
LogWithAddress,
|
|
11
10
|
TransactionReceipt,
|
|
12
11
|
TraceBlockItem,
|
|
@@ -25,6 +24,15 @@ import OptimismGasPriceOracleAbi from '../../abis/optimismGasPriceOracle.abi.jso
|
|
|
25
24
|
import ScrollGasPriceOracleAbi from '../../abis/scrollGasPriceOracle.abi.json'
|
|
26
25
|
import { GasEstimationError, InsufficientFunds, UnsupportedRpcMethodError } from '../../errors'
|
|
27
26
|
import { isSmartContractInput, safeEncodeEIP55, normalizeAddress } from '../../logic-public'
|
|
27
|
+
import {
|
|
28
|
+
isOptionalQuantity,
|
|
29
|
+
isOptionalString,
|
|
30
|
+
isQuantity,
|
|
31
|
+
isRecord,
|
|
32
|
+
isString,
|
|
33
|
+
isTraceBlockItem,
|
|
34
|
+
isTransactionReceipt,
|
|
35
|
+
} from '../../logic/predicates'
|
|
28
36
|
import { withRetries } from '../withRetries'
|
|
29
37
|
import { gethCallTracerToTraceBlockItems } from './gethCallTracerToTraceBlockItems'
|
|
30
38
|
import {
|
|
@@ -34,7 +42,6 @@ import {
|
|
|
34
42
|
isUnsupportedRpcMethodErrorMsg,
|
|
35
43
|
isUnsupportedRpcMethodError,
|
|
36
44
|
} from './rpc.errors'
|
|
37
|
-
import { isTraceBlockItem } from './types'
|
|
38
45
|
|
|
39
46
|
/**
|
|
40
47
|
* ERC20 Transfer event topic: keccak256("Transfer(address,address,uint256)")
|
|
@@ -268,16 +275,17 @@ async function getTransaction(
|
|
|
268
275
|
// Note: raw RPC call is used to get transaction receipt, as ethers method drops extra fields. We need optimism's
|
|
269
276
|
// extra fields that contain L1 fees.
|
|
270
277
|
// A pull request for ethers is open to avoid this: https://github.com/ethers-io/ethers.js/pull/5189
|
|
271
|
-
const [tx,
|
|
278
|
+
const [tx, rawReceipt] = await Promise.all([
|
|
272
279
|
api.getTransaction(txHash),
|
|
273
|
-
api.send('eth_getTransactionReceipt', [txHash])
|
|
280
|
+
api.send('eth_getTransactionReceipt', [txHash]),
|
|
274
281
|
])
|
|
275
282
|
|
|
276
|
-
if (!tx || !
|
|
283
|
+
if (!tx || !isTransactionReceipt(rawReceipt)) {
|
|
277
284
|
throw new Error('Transaction or receipt not found')
|
|
278
285
|
}
|
|
279
286
|
|
|
280
|
-
const
|
|
287
|
+
const receipt = rawReceipt
|
|
288
|
+
const raw = recordOf(receipt)
|
|
281
289
|
const contractAddressRaw = raw.contractAddress
|
|
282
290
|
const contractAddress =
|
|
283
291
|
typeof contractAddressRaw === 'string' && contractAddressRaw.startsWith('0x')
|
|
@@ -285,19 +293,20 @@ async function getTransaction(
|
|
|
285
293
|
: undefined
|
|
286
294
|
|
|
287
295
|
const l1Fee = parseReceiptL1Fee(raw)
|
|
296
|
+
const envelopeType = receiptEnvelopeType(receipt.type)
|
|
288
297
|
|
|
289
298
|
return {
|
|
290
299
|
hash: tx.hash,
|
|
291
300
|
blockHeight: tx.blockNumber ?? undefined,
|
|
292
301
|
blockHash: tx.blockHash ?? undefined,
|
|
293
302
|
nonce: tx.nonce,
|
|
294
|
-
gasUsed:
|
|
295
|
-
gasPrice:
|
|
296
|
-
status:
|
|
303
|
+
gasUsed: quantityToDecimal(receipt.gasUsed),
|
|
304
|
+
gasPrice: receiptGasPrice(receipt),
|
|
305
|
+
status: receiptStatus(receipt.status),
|
|
297
306
|
value: tx.value.toString(),
|
|
298
307
|
from: tx.from,
|
|
299
308
|
to: tx.to ?? undefined,
|
|
300
|
-
type:
|
|
309
|
+
type: envelopeType !== undefined ? envelopeType : (tx.type ?? undefined),
|
|
301
310
|
...(tx.data !== null && tx.data !== undefined && isSmartContractInput(tx.data)
|
|
302
311
|
? { input: tx.data }
|
|
303
312
|
: {}),
|
|
@@ -597,23 +606,15 @@ async function getBlockByHeight(
|
|
|
597
606
|
`Block ${blockHeight} contains malformed prefetched transaction at index ${index}`
|
|
598
607
|
)
|
|
599
608
|
|
|
600
|
-
|
|
601
|
-
const rawTx = tx as unknown as {
|
|
602
|
-
data?: string
|
|
603
|
-
// ethers v6: gasPrice is null for EIP-1559 (type-2) transactions
|
|
604
|
-
gasPrice?: bigint | null
|
|
605
|
-
maxFeePerGas?: bigint | null
|
|
606
|
-
}
|
|
609
|
+
const data = tx.data
|
|
607
610
|
return {
|
|
608
611
|
hash: tx.hash,
|
|
609
612
|
value: tx.value.toString(),
|
|
610
613
|
from: tx.from,
|
|
611
614
|
to: tx.to ?? undefined,
|
|
612
|
-
...(
|
|
613
|
-
? { input: rawTx.data }
|
|
614
|
-
: {}),
|
|
615
|
+
...(typeof data === 'string' && isSmartContractInput(data) ? { input: data } : {}),
|
|
615
616
|
// EIP-1559 transactions have gasPrice: null; fall back to maxFeePerGas then 0
|
|
616
|
-
gasPrice: (
|
|
617
|
+
gasPrice: (tx.gasPrice ?? tx.maxFeePerGas ?? 0n).toString(),
|
|
617
618
|
}
|
|
618
619
|
})
|
|
619
620
|
|
|
@@ -631,11 +632,8 @@ async function getBlockByHeight(
|
|
|
631
632
|
/** Specific error thrown by ethers when handling zksync blocks with missing signature fields in prefetched transactions */
|
|
632
633
|
function isSignatureError(error: unknown): boolean {
|
|
633
634
|
if (!hasErrorCode(error, 'INVALID_ARGUMENT')) return false
|
|
634
|
-
if (
|
|
635
|
-
|
|
636
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
637
|
-
const ethersError = error as { argument?: unknown }
|
|
638
|
-
return ethersError.argument === 'signature'
|
|
635
|
+
if (!isRecord(error)) return false
|
|
636
|
+
return error.argument === 'signature'
|
|
639
637
|
}
|
|
640
638
|
|
|
641
639
|
/**
|
|
@@ -662,10 +660,9 @@ async function getBlockByHeightFromRawRpc(
|
|
|
662
660
|
): Promise<BlockByHeightResult> {
|
|
663
661
|
const blockTag = typeof blockHeight === 'number' ? ethers.toQuantity(blockHeight) : blockHeight
|
|
664
662
|
const rawBlock = await api.send('eth_getBlockByNumber', [blockTag, prefetchTxs])
|
|
665
|
-
if (
|
|
666
|
-
throw new Error('Invalid eth_getBlockByNumber response')
|
|
663
|
+
if (!isRecord(rawBlock)) throw new Error('Invalid eth_getBlockByNumber response')
|
|
667
664
|
|
|
668
|
-
const block = rawBlock
|
|
665
|
+
const block = rawBlock
|
|
669
666
|
if (typeof block.hash !== 'string')
|
|
670
667
|
throw new Error('Malformed block hash in eth_getBlockByNumber')
|
|
671
668
|
if (typeof block.parentHash !== 'string')
|
|
@@ -774,7 +771,7 @@ async function getBlockReceipts(
|
|
|
774
771
|
if (!isTransactionReceipt(receipt))
|
|
775
772
|
throw new Error(`Malformed eth_getBlockReceipts response at index ${index}`)
|
|
776
773
|
|
|
777
|
-
const raw = receipt
|
|
774
|
+
const raw = recordOf(receipt)
|
|
778
775
|
const contractAddressRaw = raw.contractAddress
|
|
779
776
|
const contractAddress =
|
|
780
777
|
typeof contractAddressRaw === 'string' && contractAddressRaw.startsWith('0x')
|
|
@@ -782,15 +779,16 @@ async function getBlockReceipts(
|
|
|
782
779
|
: undefined
|
|
783
780
|
|
|
784
781
|
const l1Fee = parseReceiptL1Fee(raw)
|
|
782
|
+
const envelopeType = receiptEnvelopeType(receipt.type)
|
|
785
783
|
|
|
786
784
|
return {
|
|
787
785
|
hash: receipt.transactionHash,
|
|
788
|
-
gasUsed:
|
|
789
|
-
gasPrice:
|
|
790
|
-
status:
|
|
786
|
+
gasUsed: quantityToDecimal(receipt.gasUsed),
|
|
787
|
+
gasPrice: receiptGasPrice(receipt),
|
|
788
|
+
status: receiptStatus(receipt.status),
|
|
791
789
|
erc20Transfers: parseERC20TransfersFromLogs(receipt.logs, logger),
|
|
792
790
|
...(contractAddress ? { contractAddress } : {}),
|
|
793
|
-
...(
|
|
791
|
+
...(envelopeType !== undefined ? { type: envelopeType } : {}),
|
|
794
792
|
...(l1Fee !== undefined ? { l1Fee } : {}),
|
|
795
793
|
}
|
|
796
794
|
})
|
|
@@ -853,30 +851,31 @@ function normalizeTraceBlockItems(traces: TraceBlockItem[]): TraceBlockItem[] {
|
|
|
853
851
|
})
|
|
854
852
|
}
|
|
855
853
|
|
|
856
|
-
|
|
854
|
+
type EthersPrefetchedTransaction = {
|
|
855
|
+
hash: string
|
|
856
|
+
value: string | bigint
|
|
857
|
+
from: string
|
|
858
|
+
to?: string | null
|
|
859
|
+
data?: string | null
|
|
860
|
+
gasPrice?: bigint | string | null
|
|
861
|
+
maxFeePerGas?: bigint | string | null
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
function recordOf(value: object): Record<string, unknown> {
|
|
865
|
+
if (isRecord(value)) return value
|
|
866
|
+
throw new Error('expected object')
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
function isPrefetchedBlockTransaction(value: unknown): value is EthersPrefetchedTransaction {
|
|
870
|
+
if (!isRecord(value)) return false
|
|
871
|
+
if (!isString(value.hash) || !isString(value.from) || !isQuantity(value.value)) return false
|
|
872
|
+
// gasPrice is intentionally not required: EIP-1559 (type-2) transactions have gasPrice: null
|
|
873
|
+
// in ethers v6, and the mapping falls back to maxFeePerGas ?? 0n
|
|
857
874
|
return (
|
|
858
|
-
|
|
859
|
-
value
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
'from' in value &&
|
|
863
|
-
// gasPrice is intentionally not required: EIP-1559 (type-2) transactions have gasPrice: null
|
|
864
|
-
// in ethers v6, and the mapping falls back to maxFeePerGas ?? 0n
|
|
865
|
-
('gasPrice' in value
|
|
866
|
-
? value.gasPrice === null ||
|
|
867
|
-
typeof value.gasPrice === 'bigint' ||
|
|
868
|
-
typeof value.gasPrice === 'string'
|
|
869
|
-
: true) &&
|
|
870
|
-
('to' in value
|
|
871
|
-
? typeof value.to === 'string' || value.to === null || value.to === undefined
|
|
872
|
-
: true) &&
|
|
873
|
-
typeof value.hash === 'string' &&
|
|
874
|
-
(typeof value.value === 'string' || typeof value.value === 'bigint') &&
|
|
875
|
-
typeof value.from === 'string' &&
|
|
876
|
-
(!('data' in value) ||
|
|
877
|
-
value.data === undefined ||
|
|
878
|
-
value.data === null ||
|
|
879
|
-
typeof value.data === 'string')
|
|
875
|
+
isOptionalString(value.to) &&
|
|
876
|
+
isOptionalQuantity(value.gasPrice) &&
|
|
877
|
+
isOptionalQuantity(value.maxFeePerGas) &&
|
|
878
|
+
isOptionalString(value.data)
|
|
880
879
|
)
|
|
881
880
|
}
|
|
882
881
|
|
|
@@ -892,18 +891,22 @@ function getPrefetchedBlockTransactions(block: ethers.Block): unknown[] | undefi
|
|
|
892
891
|
}
|
|
893
892
|
}
|
|
894
893
|
|
|
895
|
-
function
|
|
896
|
-
return (
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
894
|
+
function quantityToDecimal(value: string): string {
|
|
895
|
+
return BigInt(value).toString()
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
function receiptGasPrice(receipt: TransactionReceipt): string {
|
|
899
|
+
return quantityToDecimal(receipt.effectiveGasPrice ?? receipt.gasPrice ?? '0x0')
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
function receiptStatus(status: TransactionReceipt['status']): number | null {
|
|
903
|
+
if (status === null) return null
|
|
904
|
+
return Number(status)
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
function receiptEnvelopeType(type: TransactionReceipt['type']): number | undefined {
|
|
908
|
+
if (type === null || type === undefined) return undefined
|
|
909
|
+
return Number(type)
|
|
907
910
|
}
|
|
908
911
|
|
|
909
912
|
async function getOptimismAdditionalFees(
|
|
@@ -975,17 +978,15 @@ function cacheKeyOptimismL1Fees(
|
|
|
975
978
|
return 'getOptimismL1BaseFee_' + currencyId + '_' + transaction
|
|
976
979
|
}
|
|
977
980
|
|
|
978
|
-
function make<
|
|
979
|
-
f: (api: JsonRpcProvider, ...args:
|
|
981
|
+
function make<Args extends readonly unknown[], R>(
|
|
982
|
+
f: (api: JsonRpcProvider, currencyId: string, ...args: Args) => Promise<R>,
|
|
980
983
|
evmConfig: EvmConfigInfo,
|
|
981
984
|
nodeConfig: ExternalNodeConfig,
|
|
982
985
|
configOverride: Partial<ExternalNodeConfig> = {}
|
|
983
|
-
):
|
|
986
|
+
): (currencyId: string, ...args: Args) => Promise<R> {
|
|
984
987
|
const mergedConfig = { ...nodeConfig, ...configOverride }
|
|
985
|
-
return (
|
|
986
|
-
|
|
987
|
-
return withApi(evmConfig, currencyId, (api) => f(api, ...args), mergedConfig)
|
|
988
|
-
}) as F
|
|
988
|
+
return (currencyId, ...args) =>
|
|
989
|
+
withApi(evmConfig, currencyId, (api) => f(api, currencyId, ...args), mergedConfig)
|
|
989
990
|
}
|
|
990
991
|
|
|
991
992
|
export function createNodeApi(
|
|
@@ -995,47 +996,50 @@ export function createNodeApi(
|
|
|
995
996
|
): NodeApi {
|
|
996
997
|
return {
|
|
997
998
|
call: make(call, evmConfig, nodeConfig),
|
|
998
|
-
getBlockByHeight: (
|
|
999
|
+
getBlockByHeight: (currencyId, blockHeight, prefetchTxs) =>
|
|
999
1000
|
withApi(
|
|
1000
1001
|
evmConfig,
|
|
1001
1002
|
currencyId,
|
|
1002
1003
|
(api) => getBlockByHeight(api, currencyId, blockHeight, logger, prefetchTxs),
|
|
1003
1004
|
nodeConfig
|
|
1004
|
-
)
|
|
1005
|
+
),
|
|
1005
1006
|
getCoinBalance: make(getCoinBalance, evmConfig, nodeConfig),
|
|
1006
1007
|
getTokenBalance: make(getTokenBalance, evmConfig, nodeConfig),
|
|
1007
1008
|
getTokenAllowance: make(getTokenAllowance, evmConfig, nodeConfig),
|
|
1008
1009
|
getTransactionCount: make(getTransactionCount, evmConfig, nodeConfig),
|
|
1009
|
-
getTransaction: (
|
|
1010
|
+
getTransaction: (currencyId, txHash) =>
|
|
1010
1011
|
withApi(
|
|
1011
1012
|
evmConfig,
|
|
1012
1013
|
currencyId,
|
|
1013
1014
|
(api) => getTransaction(api, currencyId, txHash, logger),
|
|
1014
1015
|
nodeConfig
|
|
1015
|
-
)
|
|
1016
|
-
getBlockReceipts: (
|
|
1016
|
+
),
|
|
1017
|
+
getBlockReceipts: (currencyId, blockHeight) =>
|
|
1017
1018
|
withApi(
|
|
1018
1019
|
evmConfig,
|
|
1019
1020
|
currencyId,
|
|
1020
1021
|
(api) => getBlockReceipts(api, currencyId, blockHeight, logger),
|
|
1021
1022
|
nodeConfig
|
|
1022
|
-
)
|
|
1023
|
+
),
|
|
1023
1024
|
traceBlockErigon: make(traceBlockErigon, evmConfig, nodeConfig),
|
|
1024
1025
|
traceBlockGeth: make(traceBlockGeth, evmConfig, nodeConfig),
|
|
1025
1026
|
getGasEstimation: makeGetGasEstimation(evmConfig, nodeConfig, logger),
|
|
1026
1027
|
// getFeeData takes `config` first (not `currencyId`), so it can't use the currencyId-first
|
|
1027
1028
|
// `make` wrapper; bind it explicitly and pull `currencyId` from the second argument for `withApi`.
|
|
1028
|
-
getFeeData: (
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1029
|
+
getFeeData: (config, currencyId, transaction) =>
|
|
1030
|
+
withApi(
|
|
1031
|
+
evmConfig,
|
|
1032
|
+
currencyId,
|
|
1033
|
+
(api) => getFeeData(api, config, currencyId, transaction),
|
|
1034
|
+
nodeConfig
|
|
1035
|
+
),
|
|
1036
|
+
broadcastTransaction: (currencyId, signedTxHex) =>
|
|
1033
1037
|
withApi(
|
|
1034
1038
|
evmConfig,
|
|
1035
1039
|
currencyId,
|
|
1036
1040
|
(api) => broadcastTransaction(api, currencyId, signedTxHex, logger),
|
|
1037
1041
|
{ ...nodeConfig, retries: 0 }
|
|
1038
|
-
)
|
|
1042
|
+
),
|
|
1039
1043
|
getOptimismAdditionalFees: makeLRUCache(
|
|
1040
1044
|
make(getOptimismAdditionalFees, evmConfig, nodeConfig),
|
|
1041
1045
|
cacheKeyOptimismL1Fees,
|
|
@@ -326,6 +326,48 @@ describe('EVM Family', () => {
|
|
|
326
326
|
expect(tx.l1Fee).toBeUndefined()
|
|
327
327
|
})
|
|
328
328
|
|
|
329
|
+
it('should preserve a null pre-Byzantium status', async () => {
|
|
330
|
+
mockRawReceipt({ status: null, type: null })
|
|
331
|
+
|
|
332
|
+
const tx = await nodeApi.getTransaction(
|
|
333
|
+
currencyId,
|
|
334
|
+
'0x435b00d28a10febbcfefbdea080134d08ef843df122d5bc9174b09de7fce6a59'
|
|
335
|
+
)
|
|
336
|
+
|
|
337
|
+
expect(tx.status).toBeNull()
|
|
338
|
+
expect(tx.type).toBe(0)
|
|
339
|
+
})
|
|
340
|
+
|
|
341
|
+
it.each([
|
|
342
|
+
['status', { status: 'success' }],
|
|
343
|
+
['gasUsed', { gasUsed: 'lots' }],
|
|
344
|
+
['gasPrice', { gasPrice: {} }],
|
|
345
|
+
['type', { type: 'eip1559' }],
|
|
346
|
+
['logs', { logs: [42] }],
|
|
347
|
+
[
|
|
348
|
+
'log data',
|
|
349
|
+
{
|
|
350
|
+
logs: [
|
|
351
|
+
{
|
|
352
|
+
address: '0x1111111111111111111111111111111111111111',
|
|
353
|
+
topics: [],
|
|
354
|
+
data: 'not-hex',
|
|
355
|
+
},
|
|
356
|
+
],
|
|
357
|
+
},
|
|
358
|
+
],
|
|
359
|
+
['l1Fee', { l1Fee: 'nope' }],
|
|
360
|
+
])('should reject a receipt with invalid %s', async (_field, overrides) => {
|
|
361
|
+
mockRawReceipt(overrides)
|
|
362
|
+
|
|
363
|
+
await expect(
|
|
364
|
+
nodeApi.getTransaction(
|
|
365
|
+
currencyId,
|
|
366
|
+
'0x435b00d28a10febbcfefbdea080134d08ef843df122d5bc9174b09de7fce6a59'
|
|
367
|
+
)
|
|
368
|
+
).rejects.toThrow('Transaction or receipt not found')
|
|
369
|
+
})
|
|
370
|
+
|
|
329
371
|
it('should return the expected payload', async () => {
|
|
330
372
|
expect(
|
|
331
373
|
await nodeApi.getTransaction(
|
|
@@ -1448,6 +1490,83 @@ describe('EVM Family', () => {
|
|
|
1448
1490
|
])
|
|
1449
1491
|
})
|
|
1450
1492
|
|
|
1493
|
+
it('should map a validated receipt, including log data later passed to BigInt', async () => {
|
|
1494
|
+
jest.spyOn(JsonRpcProvider.prototype, 'send').mockImplementationOnce(async (method) => {
|
|
1495
|
+
if (method === 'eth_getBlockReceipts') {
|
|
1496
|
+
return [
|
|
1497
|
+
{
|
|
1498
|
+
transactionHash: '0x435b00d28a10febbcfefbdea080134d08ef843df122d5bc9174b09de7fce6a59',
|
|
1499
|
+
gasUsed: '0x5208',
|
|
1500
|
+
effectiveGasPrice: null,
|
|
1501
|
+
gasPrice: '0x3b9aca00',
|
|
1502
|
+
status: 1,
|
|
1503
|
+
type: '0x2',
|
|
1504
|
+
logs: [
|
|
1505
|
+
{
|
|
1506
|
+
address: '0xabf26902fd7b624e0db40d31171ea9dddf078351',
|
|
1507
|
+
topics: [
|
|
1508
|
+
'0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
|
|
1509
|
+
'0x000000000000000000000000534eef6db44fbeb71047ee3eb4cb16e572862af6',
|
|
1510
|
+
'0x000000000000000000000000970402b253733a1f6f4f3cd1d07420006be2882d',
|
|
1511
|
+
],
|
|
1512
|
+
data: '0x01',
|
|
1513
|
+
},
|
|
1514
|
+
],
|
|
1515
|
+
},
|
|
1516
|
+
]
|
|
1517
|
+
}
|
|
1518
|
+
throw new Error(`Method not mocked: ${method}`)
|
|
1519
|
+
})
|
|
1520
|
+
|
|
1521
|
+
expect(await nodeApi.getBlockReceipts!(currencyId, 1)).toEqual([
|
|
1522
|
+
{
|
|
1523
|
+
hash: '0x435b00d28a10febbcfefbdea080134d08ef843df122d5bc9174b09de7fce6a59',
|
|
1524
|
+
gasUsed: '21000',
|
|
1525
|
+
gasPrice: '1000000000',
|
|
1526
|
+
status: 1,
|
|
1527
|
+
type: 2,
|
|
1528
|
+
erc20Transfers: [
|
|
1529
|
+
{
|
|
1530
|
+
asset: {
|
|
1531
|
+
type: 'erc20',
|
|
1532
|
+
assetReference: '0xaBf26902Fd7B624e0db40D31171eA9ddDf078351',
|
|
1533
|
+
},
|
|
1534
|
+
from: '0x534eeF6Db44FBeB71047EE3eb4CB16E572862aF6',
|
|
1535
|
+
to: '0x970402B253733A1f6F4f3cd1d07420006be2882D',
|
|
1536
|
+
value: '1',
|
|
1537
|
+
},
|
|
1538
|
+
],
|
|
1539
|
+
},
|
|
1540
|
+
])
|
|
1541
|
+
})
|
|
1542
|
+
|
|
1543
|
+
it.each([
|
|
1544
|
+
['status', { status: 'success' }],
|
|
1545
|
+
['gasUsed', { gasUsed: '0x' }],
|
|
1546
|
+
['effectiveGasPrice', { effectiveGasPrice: 'nope' }],
|
|
1547
|
+
['type', { type: {} }],
|
|
1548
|
+
['logs', { logs: [null] }],
|
|
1549
|
+
])('should reject a receipt with invalid %s', async (_field, overrides) => {
|
|
1550
|
+
jest.spyOn(JsonRpcProvider.prototype, 'send').mockImplementation(async (method) => {
|
|
1551
|
+
if (method === 'eth_getBlockReceipts') {
|
|
1552
|
+
return [
|
|
1553
|
+
{
|
|
1554
|
+
transactionHash: '0x435b00d28a10febbcfefbdea080134d08ef843df122d5bc9174b09de7fce6a59',
|
|
1555
|
+
gasUsed: '0x5208',
|
|
1556
|
+
status: '0x1',
|
|
1557
|
+
logs: [],
|
|
1558
|
+
...overrides,
|
|
1559
|
+
},
|
|
1560
|
+
]
|
|
1561
|
+
}
|
|
1562
|
+
throw new Error(`Method not mocked: ${method}`)
|
|
1563
|
+
})
|
|
1564
|
+
|
|
1565
|
+
await expect(nodeApi.getBlockReceipts!(currencyId, 1)).rejects.toThrow(
|
|
1566
|
+
'Malformed eth_getBlockReceipts response at index 0'
|
|
1567
|
+
)
|
|
1568
|
+
})
|
|
1569
|
+
|
|
1451
1570
|
it('should throw UnsupportedRpcMethodError for RPC -32601', async () => {
|
|
1452
1571
|
jest.spyOn(JsonRpcProvider.prototype, 'send').mockImplementation(async (method) => {
|
|
1453
1572
|
if (method === 'eth_chainId') {
|