@ledgerhq/coin-evm 16.5.2 → 16.5.3
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/CHANGELOG.md +6 -0
- package/lib/config.d.ts +9 -0
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js +4 -0
- package/lib/config.js.map +1 -1
- package/lib/errors.d.ts +15 -0
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +31 -1
- package/lib/errors.js.map +1 -1
- package/lib/logic/feeCollectorOperations.d.ts +61 -0
- package/lib/logic/feeCollectorOperations.d.ts.map +1 -0
- package/lib/logic/feeCollectorOperations.js +206 -0
- package/lib/logic/feeCollectorOperations.js.map +1 -0
- package/lib/logic/listOperations.d.ts.map +1 -1
- package/lib/logic/listOperations.js +4 -1
- package/lib/logic/listOperations.js.map +1 -1
- package/lib/network/node/rpc.common.d.ts.map +1 -1
- package/lib/network/node/rpc.common.js +84 -29
- package/lib/network/node/rpc.common.js.map +1 -1
- package/lib-es/config.d.ts +9 -0
- package/lib-es/config.d.ts.map +1 -1
- package/lib-es/config.js +4 -0
- package/lib-es/config.js.map +1 -1
- package/lib-es/errors.d.ts +15 -0
- package/lib-es/errors.d.ts.map +1 -1
- package/lib-es/errors.js +27 -0
- package/lib-es/errors.js.map +1 -1
- package/lib-es/logic/feeCollectorOperations.d.ts +61 -0
- package/lib-es/logic/feeCollectorOperations.d.ts.map +1 -0
- package/lib-es/logic/feeCollectorOperations.js +201 -0
- package/lib-es/logic/feeCollectorOperations.js.map +1 -0
- package/lib-es/logic/listOperations.d.ts.map +1 -1
- package/lib-es/logic/listOperations.js +4 -1
- package/lib-es/logic/listOperations.js.map +1 -1
- package/lib-es/network/node/rpc.common.d.ts.map +1 -1
- package/lib-es/network/node/rpc.common.js +85 -30
- package/lib-es/network/node/rpc.common.js.map +1 -1
- package/package.json +1 -1
- package/src/api/tests/getBlock.integ.test.ts +3 -32
- package/src/api/tests/index.alpen_testnet.integ.test.ts +2 -7
- package/src/api/tests/index.arbitrum.integ.test.ts +2 -12
- package/src/api/tests/index.arc.integ.test.ts +2 -13
- package/src/api/tests/index.avalanche_c_chain_fuji.integ.test.ts +2 -12
- package/src/api/tests/index.cronos.integ.test.ts +2 -12
- package/src/api/tests/index.flare.integ.test.ts +2 -8
- package/src/api/tests/index.integ.test.ts +5 -35
- package/src/api/tests/index.linea.integ.test.ts +2 -15
- package/src/api/tests/index.monad_testnet.integ.test.ts +5 -13
- package/src/api/tests/index.optimism.integ.test.ts +2 -12
- package/src/api/tests/index.rsk.integ.test.ts +2 -12
- package/src/api/tests/index.scroll.integ.test.ts +4 -7
- package/src/api/tests/index.shape.integ.test.ts +3 -27
- package/src/api/tests/index.somnia.integ.test.ts +2 -6
- package/src/api/tests/index.unichain.integ.test.ts +2 -12
- package/src/api/tests/index.zksync.integ.test.ts +5 -8
- package/src/config.ts +11 -0
- package/src/errors.ts +27 -0
- package/src/logic/feeCollectorOperations.ts +272 -0
- package/src/logic/listOperations.ts +20 -1
- package/src/logic/tests/broadcast.integ.test.ts +4 -15
- package/src/logic/tests/listOperations.test.ts +563 -0
- package/src/network/node/rpc.common.ts +128 -30
- package/src/network/tests/node/rpc.test.ts +79 -7
- package/src/staking/validators.integ.test.ts +5 -22
|
@@ -23,7 +23,14 @@ import ERC20Abi from '../../abis/erc20.abi.json'
|
|
|
23
23
|
import OptimismGasPriceOracleAbi from '../../abis/optimismGasPriceOracle.abi.json'
|
|
24
24
|
import ScrollGasPriceOracleAbi from '../../abis/scrollGasPriceOracle.abi.json'
|
|
25
25
|
import { CHAIN_ID, OP_STACK_L1_FEE_CHAIN_IDS } from '../../config'
|
|
26
|
-
import {
|
|
26
|
+
import {
|
|
27
|
+
GasEstimationError,
|
|
28
|
+
InsufficientFunds,
|
|
29
|
+
MalformedNodeResponse,
|
|
30
|
+
NodeBlockNotFound,
|
|
31
|
+
NodeTransactionNotFound,
|
|
32
|
+
UnsupportedRpcMethodError,
|
|
33
|
+
} from '../../errors'
|
|
27
34
|
import { isSmartContractInput, safeEncodeEIP55, normalizeAddress } from '../../logic-public'
|
|
28
35
|
import {
|
|
29
36
|
isOptionalQuantity,
|
|
@@ -306,6 +313,82 @@ function parseReceiptL1Fee(raw: Record<string, unknown>): string | undefined {
|
|
|
306
313
|
return typeof l1Fee === 'string' ? BigInt(l1Fee).toString() : undefined
|
|
307
314
|
}
|
|
308
315
|
|
|
316
|
+
/** The fields of a transaction {@link getTransaction} reads, as ethers or the raw RPC gives them. */
|
|
317
|
+
type TransactionFields = {
|
|
318
|
+
hash: string
|
|
319
|
+
blockNumber: number | null
|
|
320
|
+
blockHash: string | null
|
|
321
|
+
nonce: number
|
|
322
|
+
gasLimit: bigint
|
|
323
|
+
value: bigint
|
|
324
|
+
from: string
|
|
325
|
+
to: string | null
|
|
326
|
+
type: number
|
|
327
|
+
data: string
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
function rawQuantity(value: unknown, fieldName: string): bigint {
|
|
331
|
+
if (typeof value === 'string' || typeof value === 'number') return BigInt(value)
|
|
332
|
+
throw new MalformedNodeResponse(`Malformed ${fieldName} in eth_getTransactionByHash response`)
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
function rawString(value: unknown, fieldName: string): string {
|
|
336
|
+
if (typeof value === 'string') return value
|
|
337
|
+
throw new MalformedNodeResponse(`Malformed ${fieldName} in eth_getTransactionByHash response`)
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* Reads a transaction with the raw `eth_getTransactionByHash`, for a transaction ethers cannot
|
|
342
|
+
* format: zkSync L1→L2 deposits (type `0xff`) have no signature fields.
|
|
343
|
+
*/
|
|
344
|
+
async function getTransactionFromRawRpc(
|
|
345
|
+
api: JsonRpcProvider,
|
|
346
|
+
txHash: string
|
|
347
|
+
): Promise<TransactionFields | null> {
|
|
348
|
+
const raw: unknown = await api.send('eth_getTransactionByHash', [txHash])
|
|
349
|
+
if (raw === null || raw === undefined) return null
|
|
350
|
+
if (!isRecord(raw)) throw new MalformedNodeResponse('Invalid eth_getTransactionByHash response')
|
|
351
|
+
|
|
352
|
+
const blockNumber = raw.blockNumber
|
|
353
|
+
return {
|
|
354
|
+
hash: rawString(raw.hash, 'hash'),
|
|
355
|
+
blockNumber:
|
|
356
|
+
blockNumber === null || blockNumber === undefined
|
|
357
|
+
? null
|
|
358
|
+
: Number(rawQuantity(blockNumber, 'blockNumber')),
|
|
359
|
+
blockHash: typeof raw.blockHash === 'string' ? raw.blockHash : null,
|
|
360
|
+
nonce: Number(rawQuantity(raw.nonce, 'nonce')),
|
|
361
|
+
gasLimit: rawQuantity(raw.gas, 'gas'),
|
|
362
|
+
value: rawQuantity(raw.value, 'value'),
|
|
363
|
+
// Checksummed, as ethers gives them
|
|
364
|
+
from: ethers.getAddress(rawString(raw.from, 'from')),
|
|
365
|
+
to: typeof raw.to === 'string' ? ethers.getAddress(raw.to) : null,
|
|
366
|
+
type: Number(rawQuantity(raw.type ?? 0, 'type')),
|
|
367
|
+
data: typeof raw.input === 'string' ? raw.input : '0x',
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* Reads a transaction with ethers, or with the raw RPC when ethers cannot format it for missing
|
|
373
|
+
* signature fields, as {@link getBlockByHeight} does for a block.
|
|
374
|
+
*/
|
|
375
|
+
async function readTransaction(
|
|
376
|
+
api: JsonRpcProvider,
|
|
377
|
+
txHash: string,
|
|
378
|
+
logger: Logger
|
|
379
|
+
): Promise<TransactionFields | null> {
|
|
380
|
+
try {
|
|
381
|
+
return await api.getTransaction(txHash)
|
|
382
|
+
} catch (error) {
|
|
383
|
+
if (!isSignatureError(error)) throw error
|
|
384
|
+
logger('warn', 'EVM getTransaction fallback: using raw eth_getTransactionByHash response', {
|
|
385
|
+
txHash,
|
|
386
|
+
error: String(error),
|
|
387
|
+
})
|
|
388
|
+
return getTransactionFromRawRpc(api, txHash)
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
309
392
|
async function getTransaction(
|
|
310
393
|
api: JsonRpcProvider,
|
|
311
394
|
txHash: string,
|
|
@@ -315,12 +398,12 @@ async function getTransaction(
|
|
|
315
398
|
// extra fields that contain L1 fees.
|
|
316
399
|
// A pull request for ethers is open to avoid this: https://github.com/ethers-io/ethers.js/pull/5189
|
|
317
400
|
const [tx, rawReceipt] = await Promise.all([
|
|
318
|
-
api
|
|
401
|
+
readTransaction(api, txHash, logger),
|
|
319
402
|
api.send('eth_getTransactionReceipt', [txHash]),
|
|
320
403
|
])
|
|
321
404
|
|
|
322
405
|
if (!tx || !isTransactionReceipt(rawReceipt)) {
|
|
323
|
-
throw new
|
|
406
|
+
throw new NodeTransactionNotFound('Transaction or receipt not found', { txHash })
|
|
324
407
|
}
|
|
325
408
|
|
|
326
409
|
const receipt = rawReceipt
|
|
@@ -575,7 +658,10 @@ function assertNotStubBlock(
|
|
|
575
658
|
timestampInSeconds: number
|
|
576
659
|
): void {
|
|
577
660
|
if (height > 0 && timestampInSeconds === 0) {
|
|
578
|
-
throw new
|
|
661
|
+
throw new NodeBlockNotFound(
|
|
662
|
+
`Block ${blockHeight} not found (the node returned an empty stub block)`,
|
|
663
|
+
{ blockHeight }
|
|
664
|
+
)
|
|
579
665
|
}
|
|
580
666
|
}
|
|
581
667
|
|
|
@@ -602,12 +688,12 @@ async function getBlockByHeight(
|
|
|
602
688
|
}
|
|
603
689
|
|
|
604
690
|
if (!block) {
|
|
605
|
-
throw new
|
|
691
|
+
throw new NodeBlockNotFound(`Block ${blockHeight} not found`, { blockHeight })
|
|
606
692
|
}
|
|
607
693
|
assertNotStubBlock(blockHeight, block.number, block.timestamp)
|
|
608
694
|
|
|
609
695
|
if (!block.hash) {
|
|
610
|
-
throw new
|
|
696
|
+
throw new MalformedNodeResponse(`Block ${blockHeight} is missing hash`)
|
|
611
697
|
}
|
|
612
698
|
|
|
613
699
|
const transactionHashes =
|
|
@@ -625,7 +711,7 @@ async function getBlockByHeight(
|
|
|
625
711
|
const prefetchedTransactions = prefetchTxs ? getPrefetchedBlockTransactions(block) : undefined
|
|
626
712
|
const transactions = prefetchedTransactions?.map((tx, index) => {
|
|
627
713
|
if (!isPrefetchedBlockTransaction(tx))
|
|
628
|
-
throw new
|
|
714
|
+
throw new MalformedNodeResponse(
|
|
629
715
|
`Block ${blockHeight} contains malformed prefetched transaction at index ${index}`
|
|
630
716
|
)
|
|
631
717
|
|
|
@@ -656,7 +742,7 @@ async function getBlockByHeight(
|
|
|
656
742
|
}
|
|
657
743
|
}
|
|
658
744
|
|
|
659
|
-
/** Specific error thrown by ethers when
|
|
745
|
+
/** Specific error thrown by ethers when formatting zkSync transactions with missing signature fields */
|
|
660
746
|
function isSignatureError(error: unknown): boolean {
|
|
661
747
|
if (!hasErrorCode(error, 'INVALID_ARGUMENT')) return false
|
|
662
748
|
if (!isRecord(error)) return false
|
|
@@ -672,7 +758,7 @@ function isSignatureError(error: unknown): boolean {
|
|
|
672
758
|
function parseRpcHexQuantity(value: unknown, fieldName: string): number {
|
|
673
759
|
if (typeof value === 'number') return value
|
|
674
760
|
if (typeof value === 'string') return Number(BigInt(value))
|
|
675
|
-
throw new
|
|
761
|
+
throw new MalformedNodeResponse(`Malformed ${fieldName} in eth_getBlockByNumber response`)
|
|
676
762
|
}
|
|
677
763
|
|
|
678
764
|
/**
|
|
@@ -687,26 +773,26 @@ async function getBlockByHeightFromRawRpc(
|
|
|
687
773
|
): Promise<BlockByHeightResult> {
|
|
688
774
|
const blockTag = typeof blockHeight === 'number' ? ethers.toQuantity(blockHeight) : blockHeight
|
|
689
775
|
const rawBlock = await api.send('eth_getBlockByNumber', [blockTag, prefetchTxs])
|
|
690
|
-
if (!isRecord(rawBlock)) throw new
|
|
776
|
+
if (!isRecord(rawBlock)) throw new MalformedNodeResponse('Invalid eth_getBlockByNumber response')
|
|
691
777
|
|
|
692
778
|
const block = rawBlock
|
|
693
779
|
if (typeof block.hash !== 'string')
|
|
694
|
-
throw new
|
|
780
|
+
throw new MalformedNodeResponse('Malformed block hash in eth_getBlockByNumber')
|
|
695
781
|
if (typeof block.parentHash !== 'string')
|
|
696
|
-
throw new
|
|
782
|
+
throw new MalformedNodeResponse('Malformed block parentHash in eth_getBlockByNumber')
|
|
697
783
|
|
|
698
784
|
const height = parseRpcHexQuantity(block.number, 'block.number')
|
|
699
785
|
const timestampInSeconds = parseRpcHexQuantity(block.timestamp, 'block.timestamp')
|
|
700
786
|
assertNotStubBlock(blockHeight, height, timestampInSeconds)
|
|
701
787
|
const rawTransactions = block.transactions
|
|
702
788
|
if (rawTransactions !== undefined && !Array.isArray(rawTransactions))
|
|
703
|
-
throw new
|
|
789
|
+
throw new MalformedNodeResponse('Malformed block.transactions in eth_getBlockByNumber response')
|
|
704
790
|
|
|
705
791
|
const transactionHashes = rawTransactions?.map((tx, index) => {
|
|
706
792
|
if (typeof tx === 'string') return tx
|
|
707
793
|
if (typeof tx === 'object' && tx !== null && 'hash' in tx && typeof tx.hash === 'string')
|
|
708
794
|
return tx.hash
|
|
709
|
-
throw new
|
|
795
|
+
throw new MalformedNodeResponse(
|
|
710
796
|
`Malformed block transaction at index ${index} in eth_getBlockByNumber response`
|
|
711
797
|
)
|
|
712
798
|
})
|
|
@@ -715,31 +801,39 @@ async function getBlockByHeightFromRawRpc(
|
|
|
715
801
|
prefetchTxs && rawTransactions
|
|
716
802
|
? rawTransactions.map((tx) => {
|
|
717
803
|
if (typeof tx === 'string')
|
|
718
|
-
throw new
|
|
804
|
+
throw new MalformedNodeResponse(
|
|
805
|
+
'Expected prefetched transaction object, got hash string'
|
|
806
|
+
)
|
|
719
807
|
if (typeof tx !== 'object' || tx === null)
|
|
720
|
-
throw new
|
|
808
|
+
throw new MalformedNodeResponse(
|
|
809
|
+
'Malformed prefetched transaction in eth_getBlockByNumber response'
|
|
810
|
+
)
|
|
721
811
|
if (!('hash' in tx) || typeof tx.hash !== 'string')
|
|
722
|
-
throw new
|
|
812
|
+
throw new MalformedNodeResponse(
|
|
723
813
|
'Malformed prefetched transaction hash in eth_getBlockByNumber response'
|
|
724
814
|
)
|
|
725
815
|
if (!('from' in tx) || typeof tx.from !== 'string')
|
|
726
|
-
throw new
|
|
816
|
+
throw new MalformedNodeResponse(
|
|
727
817
|
'Malformed prefetched transaction from in eth_getBlockByNumber response'
|
|
728
818
|
)
|
|
729
819
|
if ('to' in tx && tx.to !== null && tx.to !== undefined && typeof tx.to !== 'string')
|
|
730
|
-
throw new
|
|
820
|
+
throw new MalformedNodeResponse(
|
|
821
|
+
'Malformed prefetched transaction to in eth_getBlockByNumber response'
|
|
822
|
+
)
|
|
731
823
|
if ('value' in tx && tx.value !== undefined && typeof tx.value !== 'string')
|
|
732
|
-
throw new
|
|
824
|
+
throw new MalformedNodeResponse(
|
|
733
825
|
'Malformed prefetched transaction value in eth_getBlockByNumber response'
|
|
734
826
|
)
|
|
735
827
|
if ('gasPrice' in tx && tx.gasPrice !== undefined && typeof tx.gasPrice !== 'string')
|
|
736
|
-
throw new
|
|
828
|
+
throw new MalformedNodeResponse(
|
|
737
829
|
'Malformed prefetched transaction gasPrice in eth_getBlockByNumber response'
|
|
738
830
|
)
|
|
739
831
|
if ('gas' in tx && tx.gas !== undefined && typeof tx.gas !== 'string')
|
|
740
|
-
throw new
|
|
832
|
+
throw new MalformedNodeResponse(
|
|
833
|
+
'Malformed prefetched transaction gas in eth_getBlockByNumber response'
|
|
834
|
+
)
|
|
741
835
|
if ('nonce' in tx && tx.nonce !== undefined && typeof tx.nonce !== 'string')
|
|
742
|
-
throw new
|
|
836
|
+
throw new MalformedNodeResponse(
|
|
743
837
|
'Malformed prefetched transaction nonce in eth_getBlockByNumber response'
|
|
744
838
|
)
|
|
745
839
|
if (
|
|
@@ -748,7 +842,7 @@ async function getBlockByHeightFromRawRpc(
|
|
|
748
842
|
tx.input !== null &&
|
|
749
843
|
typeof tx.input !== 'string'
|
|
750
844
|
)
|
|
751
|
-
throw new
|
|
845
|
+
throw new MalformedNodeResponse(
|
|
752
846
|
'Malformed prefetched transaction input in eth_getBlockByNumber response'
|
|
753
847
|
)
|
|
754
848
|
|
|
@@ -803,11 +897,12 @@ async function getBlockReceipts(
|
|
|
803
897
|
throw error
|
|
804
898
|
}
|
|
805
899
|
|
|
806
|
-
if (!Array.isArray(receipts))
|
|
900
|
+
if (!Array.isArray(receipts))
|
|
901
|
+
throw new MalformedNodeResponse('Invalid eth_getBlockReceipts response')
|
|
807
902
|
|
|
808
903
|
return receipts.map((receipt, index) => {
|
|
809
904
|
if (!isTransactionReceipt(receipt))
|
|
810
|
-
throw new
|
|
905
|
+
throw new MalformedNodeResponse(`Malformed eth_getBlockReceipts response at index ${index}`)
|
|
811
906
|
|
|
812
907
|
const raw = recordOf(receipt)
|
|
813
908
|
const contractAddressRaw = raw.contractAddress
|
|
@@ -855,7 +950,8 @@ async function traceBlockGeth(
|
|
|
855
950
|
}
|
|
856
951
|
throw error
|
|
857
952
|
})
|
|
858
|
-
if (!Array.isArray(debugResults))
|
|
953
|
+
if (!Array.isArray(debugResults))
|
|
954
|
+
throw new MalformedNodeResponse('Invalid debug_traceBlockByNumber response')
|
|
859
955
|
return normalizeTraceBlockItems(gethCallTracerToTraceBlockItems(blockHeight, debugResults))
|
|
860
956
|
}
|
|
861
957
|
|
|
@@ -877,11 +973,13 @@ async function traceBlockErigon(
|
|
|
877
973
|
}
|
|
878
974
|
|
|
879
975
|
function normalizeTraceBlockItems(traces: TraceBlockItem[]): TraceBlockItem[] {
|
|
880
|
-
if (!Array.isArray(traces)) throw new
|
|
976
|
+
if (!Array.isArray(traces)) throw new MalformedNodeResponse('Invalid trace block response')
|
|
881
977
|
|
|
882
978
|
return traces.map((trace, index) => {
|
|
883
979
|
if (!isTraceBlockItem(trace)) {
|
|
884
|
-
throw new
|
|
980
|
+
throw new MalformedNodeResponse(
|
|
981
|
+
`Malformed trace block response at index ${index} ${JSON.stringify(trace)}`
|
|
982
|
+
)
|
|
885
983
|
}
|
|
886
984
|
return trace
|
|
887
985
|
})
|
|
@@ -901,7 +999,7 @@ type EthersPrefetchedTransaction = {
|
|
|
901
999
|
|
|
902
1000
|
function recordOf(value: object): Record<string, unknown> {
|
|
903
1001
|
if (isRecord(value)) return value
|
|
904
|
-
throw new
|
|
1002
|
+
throw new MalformedNodeResponse('expected object')
|
|
905
1003
|
}
|
|
906
1004
|
|
|
907
1005
|
function isPrefetchedBlockTransaction(value: unknown): value is EthersPrefetchedTransaction {
|
|
@@ -306,6 +306,73 @@ describe('EVM Family', () => {
|
|
|
306
306
|
expect(tx.type).toBe(0)
|
|
307
307
|
})
|
|
308
308
|
|
|
309
|
+
it('should read a zkSync deposit, which ethers cannot format for its missing signature, from the raw RPC', async () => {
|
|
310
|
+
// tx 0xe63e66c9…1ee4 on zkSync Era: an L1→L2 deposit (type 0xff), with no r, s, v
|
|
311
|
+
const hash = '0xe63e66c987d3b8e8b8621e0fde174055687289594d5955e9b97615cc7feb1ee4'
|
|
312
|
+
const account = '0xbeb30f27e61efff46aa27dce18e23ee8d5a7c6a4'
|
|
313
|
+
jest.spyOn(JsonRpcProvider.prototype, 'getTransaction').mockImplementationOnce(async () => {
|
|
314
|
+
throw Object.assign(new TypeError('missing r'), {
|
|
315
|
+
code: 'INVALID_ARGUMENT',
|
|
316
|
+
argument: 'signature',
|
|
317
|
+
})
|
|
318
|
+
})
|
|
319
|
+
jest.spyOn(JsonRpcProvider.prototype, 'send').mockImplementation(async (method) => {
|
|
320
|
+
if (method === 'eth_getTransactionByHash') {
|
|
321
|
+
return {
|
|
322
|
+
hash,
|
|
323
|
+
blockNumber: '0x436128',
|
|
324
|
+
blockHash: '0xb8f0774c03f5f8a4a998fcc30037286d93277efd904e6c096a7124d998dc01a0',
|
|
325
|
+
nonce: '0x0',
|
|
326
|
+
gas: '0xb54a3',
|
|
327
|
+
value: '0x3bf3b91c95b0000',
|
|
328
|
+
from: account,
|
|
329
|
+
to: account,
|
|
330
|
+
type: '0xff',
|
|
331
|
+
input: '0x',
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
if (method === 'eth_getTransactionReceipt') {
|
|
335
|
+
return {
|
|
336
|
+
transactionHash: hash,
|
|
337
|
+
gasUsed: '0x7a',
|
|
338
|
+
gasPrice: '0x211f3840',
|
|
339
|
+
status: '0x1',
|
|
340
|
+
logs: [],
|
|
341
|
+
type: '0xff',
|
|
342
|
+
contractAddress: null,
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
return null
|
|
346
|
+
})
|
|
347
|
+
|
|
348
|
+
const tx = await nodeApi.getTransaction(hash)
|
|
349
|
+
|
|
350
|
+
expect(tx).toMatchObject({
|
|
351
|
+
hash,
|
|
352
|
+
blockHeight: 4415784,
|
|
353
|
+
nonce: 0,
|
|
354
|
+
gasLimit: '742563',
|
|
355
|
+
value: '270000000000000000',
|
|
356
|
+
from: '0xbEB30f27e61eFFF46Aa27dcE18E23ee8D5A7c6a4',
|
|
357
|
+
to: '0xbEB30f27e61eFFF46Aa27dcE18E23ee8D5A7c6a4',
|
|
358
|
+
type: 255,
|
|
359
|
+
})
|
|
360
|
+
})
|
|
361
|
+
|
|
362
|
+
it('should not fall back to the raw RPC for another ethers error', async () => {
|
|
363
|
+
jest
|
|
364
|
+
.spyOn(JsonRpcProvider.prototype, 'getTransaction')
|
|
365
|
+
.mockRejectedValueOnce(new Error('connection reset'))
|
|
366
|
+
const send = jest.spyOn(JsonRpcProvider.prototype, 'send')
|
|
367
|
+
|
|
368
|
+
// withRetries reads it again, from ethers
|
|
369
|
+
await nodeApi.getTransaction(
|
|
370
|
+
'0x435b00d28a10febbcfefbdea080134d08ef843df122d5bc9174b09de7fce6a59'
|
|
371
|
+
)
|
|
372
|
+
|
|
373
|
+
expect(send).not.toHaveBeenCalledWith('eth_getTransactionByHash', expect.anything())
|
|
374
|
+
})
|
|
375
|
+
|
|
309
376
|
it.each([
|
|
310
377
|
['status', { status: 'success' }],
|
|
311
378
|
['gasUsed', { gasUsed: 'lots' }],
|
|
@@ -332,7 +399,10 @@ describe('EVM Family', () => {
|
|
|
332
399
|
nodeApi.getTransaction(
|
|
333
400
|
'0x435b00d28a10febbcfefbdea080134d08ef843df122d5bc9174b09de7fce6a59'
|
|
334
401
|
)
|
|
335
|
-
).rejects.
|
|
402
|
+
).rejects.toMatchObject({
|
|
403
|
+
name: 'NodeTransactionNotFound',
|
|
404
|
+
message: 'Transaction or receipt not found',
|
|
405
|
+
})
|
|
336
406
|
})
|
|
337
407
|
|
|
338
408
|
it('should return the expected payload', async () => {
|
|
@@ -1333,9 +1403,10 @@ describe('EVM Family', () => {
|
|
|
1333
1403
|
})
|
|
1334
1404
|
)
|
|
1335
1405
|
|
|
1336
|
-
await expect(nodeApi.getBlockByHeight(956855)).rejects.
|
|
1337
|
-
|
|
1338
|
-
|
|
1406
|
+
await expect(nodeApi.getBlockByHeight(956855)).rejects.toMatchObject({
|
|
1407
|
+
name: 'NodeBlockNotFound',
|
|
1408
|
+
message: 'Block 956855 not found (the node returned an empty stub block)',
|
|
1409
|
+
})
|
|
1339
1410
|
})
|
|
1340
1411
|
|
|
1341
1412
|
it('should accept a zero timestamp on the genesis block', async () => {
|
|
@@ -1632,9 +1703,10 @@ describe('EVM Family', () => {
|
|
|
1632
1703
|
throw new Error(`Method not mocked: ${method}`)
|
|
1633
1704
|
})
|
|
1634
1705
|
|
|
1635
|
-
await expect(nodeApi.getBlockReceipts!(1)).rejects.
|
|
1636
|
-
|
|
1637
|
-
|
|
1706
|
+
await expect(nodeApi.getBlockReceipts!(1)).rejects.toMatchObject({
|
|
1707
|
+
name: 'MalformedNodeResponse',
|
|
1708
|
+
message: 'Malformed eth_getBlockReceipts response at index 0',
|
|
1709
|
+
})
|
|
1638
1710
|
})
|
|
1639
1711
|
|
|
1640
1712
|
it('should throw UnsupportedRpcMethodError for RPC -32601', async () => {
|
|
@@ -1,32 +1,15 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { evmDefaults } from '../config'
|
|
5
|
+
import { testLogger } from '../fixtures/context.fixtures'
|
|
5
6
|
import { getValidators } from './validators'
|
|
6
7
|
|
|
7
8
|
describe('getValidators', () => {
|
|
8
9
|
it.each([
|
|
9
|
-
[
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
chainId: 143,
|
|
13
|
-
node: mkExternalNode({ uri: 'https://monad.coin.ledger.com' }),
|
|
14
|
-
}),
|
|
15
|
-
],
|
|
16
|
-
[
|
|
17
|
-
'zero_gravity',
|
|
18
|
-
createMockEvmCoinConfig({
|
|
19
|
-
chainId: 16661,
|
|
20
|
-
node: mkExternalNode({ uri: 'https://zero-gravity.coin.ledger.com' }),
|
|
21
|
-
}),
|
|
22
|
-
],
|
|
23
|
-
[
|
|
24
|
-
'somnia',
|
|
25
|
-
createMockEvmCoinConfig({
|
|
26
|
-
chainId: 5031,
|
|
27
|
-
node: mkExternalNode({ uri: 'https://api.infra.mainnet.somnia.network' }),
|
|
28
|
-
}),
|
|
29
|
-
],
|
|
10
|
+
['monad', { info: evmDefaults.monad }],
|
|
11
|
+
['zero_gravity', { info: evmDefaults.zero_gravity }],
|
|
12
|
+
['somnia', { info: evmDefaults.somnia }],
|
|
30
13
|
])("fetches validators on '%s'", async (_chainName, config) => {
|
|
31
14
|
const firstPage = await getValidators(config.info, testLogger)
|
|
32
15
|
expect(firstPage.items.length).toBeGreaterThan(0)
|