@ledgerhq/coin-evm 5.3.2 → 5.3.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/.oxlintrc.json +1 -1
- package/CHANGELOG.md +7 -0
- package/package.json +2 -2
- package/src/adapters/blockOperations.test.ts +27 -29
- package/src/api/index.flare.integ.test.ts +1 -13
- package/src/api/index.integ.test.ts +86 -97
- package/src/fixtures/context.fixtures.ts +79 -1
- package/src/fixtures/ethers.fixtures.ts +26 -0
- package/src/logic/broadcast.integ.test.ts +6 -18
- package/src/logic/broadcast.test.ts +19 -31
- package/src/logic/broadcastSource.test.ts +6 -7
- package/src/logic/common.test.ts +120 -112
- package/src/logic/craftTransaction.test.ts +161 -199
- package/src/logic/craftTransactionData.test.ts +6 -6
- package/src/logic/estimateFees.test.ts +19 -15
- package/src/logic/getBalance.test.ts +15 -14
- package/src/logic/getBlock.test.ts +372 -382
- package/src/logic/getBlockInfo.test.ts +6 -6
- package/src/logic/getNextSequence.test.ts +5 -5
- package/src/logic/getStakes.test.ts +34 -34
- package/src/logic/internalTransactionsFetcher.test.ts +23 -19
- package/src/logic/lastBlock.test.ts +29 -21
- package/src/logic/listOperations.test.ts +43 -40
- package/src/logic/validateIntent.test.ts +151 -101
- package/src/logic.test.ts +13 -18
- package/src/network/explorer/etherscan.test.ts +5 -5
- package/src/network/explorer/index.test.ts +51 -21
- package/src/network/explorer/ledger.test.ts +15 -4
- package/src/network/gasTracker/index.test.ts +14 -8
- package/src/network/gasTracker/ledger.test.ts +25 -13
- package/src/network/node/index.memoization.test.ts +25 -31
- package/src/network/node/index.test.ts +14 -25
- package/src/network/node/ledger.test.ts +45 -60
- package/src/network/node/node.fixtures.ts +0 -2
- package/src/network/node/rpc.test.ts +152 -177
- package/src/staking/encoder.test.ts +13 -21
- package/src/staking/logic.test.ts +20 -14
- package/src/staking/operations/index.test.ts +28 -28
- package/src/staking/prepareIntents.test.ts +26 -20
- package/src/staking/redelegations.test.ts +27 -18
- package/src/staking/rewards.test.ts +23 -15
- package/src/staking/rewardsFromReceipt.test.ts +19 -20
- package/src/staking/transactionData.test.ts +22 -22
- package/src/staking/validators/monad.test.ts +65 -24
- package/src/staking/validators/somnia.test.ts +21 -13
- package/src/staking/validators/zero_gravity.test.ts +118 -48
- package/src/staking/validators.integ.test.ts +13 -25
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import type { EvmConfigInfo } from '../../config'
|
|
5
|
-
import type { TransactionReceipt, TransactionResponse, ethers } from 'ethers'
|
|
6
|
-
import { AssertionError, fail } from 'assert'
|
|
7
4
|
import { delay } from '@ledgerhq/coin-module-framework/promises'
|
|
8
5
|
import BigNumber from 'bignumber.js'
|
|
9
|
-
import { FetchRequest, JsonRpcProvider, Network, Transaction } from 'ethers'
|
|
6
|
+
import { FeeData, FetchRequest, JsonRpcProvider, Network, Transaction } from 'ethers'
|
|
10
7
|
import { getCoinConfig } from '../../config'
|
|
11
8
|
import { GasEstimationError, InsufficientFunds, UnsupportedRpcMethodError } from '../../errors'
|
|
9
|
+
import { createMockEvmConfigInfo, mkExternalNode } from '../../fixtures/context.fixtures'
|
|
10
|
+
import {
|
|
11
|
+
mkBlock,
|
|
12
|
+
mkTransactionReceipt,
|
|
13
|
+
mkTransactionResponse,
|
|
14
|
+
} from '../../fixtures/ethers.fixtures'
|
|
12
15
|
import {
|
|
13
16
|
createNodeApi,
|
|
14
17
|
DEFAULT_RETRIES_RPC_METHODS,
|
|
@@ -22,11 +25,11 @@ import {
|
|
|
22
25
|
|
|
23
26
|
const currencyId = 'my_new_chain'
|
|
24
27
|
|
|
25
|
-
const evmConfig = {
|
|
28
|
+
const evmConfig = createMockEvmConfigInfo({
|
|
26
29
|
chainId: 1,
|
|
27
30
|
name: 'My New Chain',
|
|
28
|
-
node: {
|
|
29
|
-
}
|
|
31
|
+
node: mkExternalNode({ uri: 'http://test' }),
|
|
32
|
+
})
|
|
30
33
|
|
|
31
34
|
const nodeApi = createNodeApi(evmConfig, {
|
|
32
35
|
type: 'external',
|
|
@@ -44,7 +47,7 @@ const now = Math.floor(Date.now() / 1000)
|
|
|
44
47
|
const address = '0x6cBCD73CD8e8a42844662f0A0e76D7F79Afd933d'
|
|
45
48
|
|
|
46
49
|
jest.mock('@ledgerhq/coin-module-framework/promises')
|
|
47
|
-
|
|
50
|
+
jest.mocked(delay).mockImplementation(
|
|
48
51
|
() => new Promise((resolve) => setTimeout(resolve, 1)) // mocking the delay supposed to happen after each try
|
|
49
52
|
)
|
|
50
53
|
|
|
@@ -55,9 +58,7 @@ describe('EVM Family', () => {
|
|
|
55
58
|
|
|
56
59
|
beforeEach(() => {
|
|
57
60
|
jest.resetAllMocks()
|
|
58
|
-
jest
|
|
59
|
-
.spyOn(JsonRpcProvider.prototype as any, '_detectNetwork')
|
|
60
|
-
.mockResolvedValue(Network.from(1))
|
|
61
|
+
jest.spyOn(JsonRpcProvider.prototype, '_detectNetwork').mockResolvedValue(Network.from(1))
|
|
61
62
|
|
|
62
63
|
mockGetConfig.mockImplementation((): any => {
|
|
63
64
|
return {
|
|
@@ -70,66 +71,66 @@ describe('EVM Family', () => {
|
|
|
70
71
|
}
|
|
71
72
|
})
|
|
72
73
|
|
|
73
|
-
jest
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
maxPriorityFeePerGas: 0n,
|
|
77
|
-
} as ethers.FeeData)
|
|
74
|
+
jest
|
|
75
|
+
.spyOn(JsonRpcProvider.prototype, 'getFeeData')
|
|
76
|
+
.mockResolvedValue(new FeeData(BigInt(666), 0n, 0n))
|
|
78
77
|
|
|
79
78
|
jest.spyOn(JsonRpcProvider.prototype, 'getBalance').mockResolvedValue(BigInt(420))
|
|
80
79
|
jest
|
|
81
80
|
.spyOn(JsonRpcProvider.prototype, 'call')
|
|
82
81
|
.mockResolvedValue('0x000000000000000000000000000000000000000000000000000000000000A455')
|
|
83
|
-
jest.spyOn(JsonRpcProvider.prototype, 'getBlock').mockResolvedValue(
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
82
|
+
jest.spyOn(JsonRpcProvider.prototype, 'getBlock').mockResolvedValue(
|
|
83
|
+
mkBlock({
|
|
84
|
+
hash: '0x474dee0136108e9412e9d84197b468bb057a8dad0f2024fc55adebc4a28fa8c5',
|
|
85
|
+
parentHash: '0xfc900c22725f9c0843c9cf7d2c47f4b61b246bd21e18e99f709aebaefc8aff14',
|
|
86
|
+
number: 1,
|
|
87
|
+
difficulty: 0n,
|
|
88
|
+
gasLimit: BigInt(1),
|
|
89
|
+
gasUsed: BigInt(2),
|
|
90
|
+
extraData: '0x',
|
|
91
|
+
baseFeePerGas: BigInt(123),
|
|
92
|
+
timestamp: now,
|
|
93
|
+
})
|
|
94
|
+
)
|
|
94
95
|
|
|
95
96
|
jest.spyOn(JsonRpcProvider.prototype, 'getTransactionCount').mockResolvedValue(5)
|
|
96
97
|
|
|
97
|
-
jest.spyOn(JsonRpcProvider.prototype, 'getTransaction').mockResolvedValue(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
98
|
+
jest.spyOn(JsonRpcProvider.prototype, 'getTransaction').mockResolvedValue(
|
|
99
|
+
mkTransactionResponse({
|
|
100
|
+
hash: '0x435b00d28a10febbcfefbdea080134d08ef843df122d5bc9174b09de7fce6a59',
|
|
101
|
+
blockNumber: 69,
|
|
102
|
+
blockHash: '0x474dee0136108e9412e9d84197b468bb057a8dad0f2024fc55adebc4a28fa8c5',
|
|
103
|
+
nonce: 123,
|
|
104
|
+
value: BigInt(456),
|
|
105
|
+
gasLimit: BigInt(123),
|
|
106
|
+
gasPrice: BigInt(789),
|
|
107
|
+
data: '0x',
|
|
108
|
+
to: '0xC2907EFccE4011C491BbedA8A0fA63BA7aab596C',
|
|
109
|
+
from: '0x6cbcd73cd8e8a42844662f0a0e76d7f79afd933d',
|
|
110
|
+
type: 0,
|
|
111
|
+
confirmations: jest.fn().mockResolvedValue(1),
|
|
112
|
+
})
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
jest.spyOn(JsonRpcProvider.prototype, 'getTransactionReceipt').mockResolvedValue(
|
|
116
|
+
mkTransactionReceipt({
|
|
117
|
+
blockHash: '0x8a179bc6cb299f936c4fd614995e62d597ec6108b579c23034fb220967ceaa94',
|
|
118
|
+
blockNumber: 69,
|
|
119
|
+
confirmations: jest.fn().mockResolvedValue(100),
|
|
120
|
+
contractAddress: null,
|
|
121
|
+
cumulativeGasUsed: BigInt(121),
|
|
122
|
+
from: '0x6cbcd73cd8e8a42844662f0a0e76d7f79afd933d',
|
|
123
|
+
gasUsed: BigInt(122),
|
|
124
|
+
gasPrice: BigInt(789),
|
|
125
|
+
logs: [],
|
|
126
|
+
logsBloom: '0x',
|
|
127
|
+
status: 1,
|
|
128
|
+
to: '0xC2907EFccE4011C491BbedA8A0fA63BA7aab596C',
|
|
129
|
+
hash: '0x435b00d28a10febbcfefbdea080134d08ef843df122d5bc9174b09de7fce6a59',
|
|
130
|
+
index: 123,
|
|
131
|
+
type: 0,
|
|
132
|
+
})
|
|
133
|
+
)
|
|
133
134
|
|
|
134
135
|
jest
|
|
135
136
|
.spyOn(JsonRpcProvider.prototype, 'broadcastTransaction')
|
|
@@ -192,15 +193,7 @@ describe('EVM Family', () => {
|
|
|
192
193
|
retries: DEFAULT_RETRIES_RPC_METHODS,
|
|
193
194
|
}
|
|
194
195
|
|
|
195
|
-
|
|
196
|
-
await withApi(evmConfig, currencyId, spy, nodeConfig)
|
|
197
|
-
fail('Promise should have been rejected')
|
|
198
|
-
} catch (e) {
|
|
199
|
-
if (e instanceof AssertionError) {
|
|
200
|
-
throw e
|
|
201
|
-
}
|
|
202
|
-
expect(e).toBeInstanceOf(SpyError)
|
|
203
|
-
}
|
|
196
|
+
await expect(withApi(evmConfig, currencyId, spy, nodeConfig)).rejects.toThrow(SpyError)
|
|
204
197
|
})
|
|
205
198
|
|
|
206
199
|
it('provider cache should reuse the same JsonRpcProvider for the same currency id and same uri', async () => {
|
|
@@ -695,14 +688,12 @@ describe('EVM Family', () => {
|
|
|
695
688
|
|
|
696
689
|
describe('getGasEstimation', () => {
|
|
697
690
|
it('should return the expected payload', async () => {
|
|
698
|
-
jest
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
return null
|
|
705
|
-
})
|
|
691
|
+
jest.spyOn(JsonRpcProvider.prototype, '_perform').mockImplementation(async (req: any) => {
|
|
692
|
+
if (req.method === 'estimateGas') {
|
|
693
|
+
return 5n
|
|
694
|
+
}
|
|
695
|
+
return null
|
|
696
|
+
})
|
|
706
697
|
expect(
|
|
707
698
|
await nodeApi.getGasEstimation(currencyId, address, {
|
|
708
699
|
recipient: '0x0000000000000000000000000000000000000000',
|
|
@@ -713,14 +704,12 @@ describe('EVM Family', () => {
|
|
|
713
704
|
})
|
|
714
705
|
|
|
715
706
|
it('should throw a GasEstimationError in case of error', async () => {
|
|
716
|
-
jest
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
return null
|
|
723
|
-
})
|
|
707
|
+
jest.spyOn(JsonRpcProvider.prototype, '_perform').mockImplementation(async (req: any) => {
|
|
708
|
+
if (req.method === 'estimateGas') {
|
|
709
|
+
throw new Error('fail')
|
|
710
|
+
}
|
|
711
|
+
return null
|
|
712
|
+
})
|
|
724
713
|
|
|
725
714
|
await expect(
|
|
726
715
|
nodeApi.getGasEstimation(currencyId, address, {
|
|
@@ -957,7 +946,7 @@ describe('EVM Family', () => {
|
|
|
957
946
|
},
|
|
958
947
|
}))
|
|
959
948
|
const sendSpy = jest
|
|
960
|
-
.spyOn(JsonRpcProvider.prototype
|
|
949
|
+
.spyOn(JsonRpcProvider.prototype, 'send')
|
|
961
950
|
.mockImplementation(async (method) => {
|
|
962
951
|
if (method === 'eth_getBlockByNumber') {
|
|
963
952
|
return {
|
|
@@ -1067,28 +1056,24 @@ describe('EVM Family', () => {
|
|
|
1067
1056
|
},
|
|
1068
1057
|
}))
|
|
1069
1058
|
|
|
1070
|
-
jest
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
gasUsed: 2n,
|
|
1081
|
-
extraData: '0x',
|
|
1082
|
-
}
|
|
1059
|
+
jest.spyOn(JsonRpcProvider.prototype, 'send').mockImplementationOnce(async (method) => {
|
|
1060
|
+
if (method === 'eth_getBlockByNumber') {
|
|
1061
|
+
return {
|
|
1062
|
+
parentHash: '0x0',
|
|
1063
|
+
number: 1,
|
|
1064
|
+
timestamp: 123,
|
|
1065
|
+
difficulty: 0n,
|
|
1066
|
+
gasLimit: 1n,
|
|
1067
|
+
gasUsed: 2n,
|
|
1068
|
+
extraData: '0x',
|
|
1083
1069
|
}
|
|
1084
|
-
}
|
|
1070
|
+
}
|
|
1071
|
+
})
|
|
1085
1072
|
// node reports 1 Gwei via the getFeeData mock at the top of the suite (666 wei), but
|
|
1086
1073
|
// we override here to assert the floor wins
|
|
1087
|
-
jest.spyOn(JsonRpcProvider.prototype, 'getFeeData').mockResolvedValueOnce(
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
maxPriorityFeePerGas: 0n,
|
|
1091
|
-
} as ethers.FeeData)
|
|
1074
|
+
jest.spyOn(JsonRpcProvider.prototype, 'getFeeData').mockResolvedValueOnce(
|
|
1075
|
+
new FeeData(BigInt('1000000000'), 0n, 0n) // 1 Gwei
|
|
1076
|
+
)
|
|
1092
1077
|
|
|
1093
1078
|
const result = await nodeApi.getFeeData(getCoinConfig(currencyId).info, currencyId, legacyTx)
|
|
1094
1079
|
|
|
@@ -1135,24 +1120,22 @@ describe('EVM Family', () => {
|
|
|
1135
1120
|
}
|
|
1136
1121
|
|
|
1137
1122
|
it('should return the expected payload for a legacy tx', async () => {
|
|
1138
|
-
jest
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
}
|
|
1155
|
-
})
|
|
1123
|
+
jest.spyOn(JsonRpcProvider.prototype, 'send').mockImplementationOnce(async (method) => {
|
|
1124
|
+
switch (method) {
|
|
1125
|
+
case 'eth_getBlockByNumber':
|
|
1126
|
+
return {
|
|
1127
|
+
parentHash: '0x474dee0136108e9412e9d84197b468bb057a8dad0f2024fc55adebc4a28fa8c5',
|
|
1128
|
+
number: 1,
|
|
1129
|
+
timestamp: 123,
|
|
1130
|
+
difficulty: 0n,
|
|
1131
|
+
gasLimit: 1n,
|
|
1132
|
+
gasUsed: 2n,
|
|
1133
|
+
extraData: '0x',
|
|
1134
|
+
}
|
|
1135
|
+
default:
|
|
1136
|
+
throw new Error(`Method not mocked: ${method}`)
|
|
1137
|
+
}
|
|
1138
|
+
})
|
|
1156
1139
|
|
|
1157
1140
|
expect(
|
|
1158
1141
|
await nodeApi.getFeeData(getCoinConfig('optimism').info, 'optimism', legacyTx)
|
|
@@ -1178,30 +1161,18 @@ describe('EVM Family', () => {
|
|
|
1178
1161
|
const serializedTransaction =
|
|
1179
1162
|
'0x02f873012d85010c388d0085077715912682520894c2907efcce4011c491bbeda8a0fa63ba7aab596c87038d7ea4c6800080c001a0bbffe7ba303ab03f697d64672c4a288ae863df8a62ffc67ba72872ce8c227f6fa01261e7c9f06af13631f03fad9b88d3c48931d353b6b41b4072fddcca5ec41628'
|
|
1180
1163
|
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
} catch (e) {
|
|
1185
|
-
if (e instanceof AssertionError) {
|
|
1186
|
-
throw e
|
|
1187
|
-
}
|
|
1188
|
-
expect(e).toBeInstanceOf(InsufficientFunds)
|
|
1189
|
-
}
|
|
1164
|
+
await expect(nodeApi.broadcastTransaction(currencyId, serializedTransaction)).rejects.toThrow(
|
|
1165
|
+
InsufficientFunds
|
|
1166
|
+
)
|
|
1190
1167
|
})
|
|
1191
1168
|
|
|
1192
1169
|
it('should throw any other error', async () => {
|
|
1193
1170
|
const serializedTransaction =
|
|
1194
1171
|
'0x02f873012d85010c388d0085077715912682520894c2907efcce4011c491bbeda8a0fa63ba7aab596c87038d7ea4c6800080c001a0bbffe7ba303ab03f697d64672c4a288ae863df8a62ffc67ba72872ce8c227f6fa01261e7c9f06af13631f03fad9b88d3c48931d353b6b41b4072fddcca5ec41625'
|
|
1195
1172
|
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
} catch (e) {
|
|
1200
|
-
if (e instanceof AssertionError) {
|
|
1201
|
-
throw e
|
|
1202
|
-
}
|
|
1203
|
-
expect((e as Error).message).toEqual('any error')
|
|
1204
|
-
}
|
|
1173
|
+
await expect(nodeApi.broadcastTransaction(currencyId, serializedTransaction)).rejects.toThrow(
|
|
1174
|
+
'any error'
|
|
1175
|
+
)
|
|
1205
1176
|
})
|
|
1206
1177
|
})
|
|
1207
1178
|
|
|
@@ -1219,22 +1190,24 @@ describe('EVM Family', () => {
|
|
|
1219
1190
|
})
|
|
1220
1191
|
|
|
1221
1192
|
it('should prefetch block transactions when requested', async () => {
|
|
1222
|
-
jest.spyOn(JsonRpcProvider.prototype, 'getBlock').mockResolvedValueOnce(
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1193
|
+
jest.spyOn(JsonRpcProvider.prototype, 'getBlock').mockResolvedValueOnce(
|
|
1194
|
+
mkBlock({
|
|
1195
|
+
hash: '0x474dee0136108e9412e9d84197b468bb057a8dad0f2024fc55adebc4a28fa8c5',
|
|
1196
|
+
parentHash: '0xfc900c22725f9c0843c9cf7d2c47f4b61b246bd21e18e99f709aebaefc8aff14',
|
|
1197
|
+
number: 1,
|
|
1198
|
+
timestamp: now,
|
|
1199
|
+
transactions: ['0xtx1'],
|
|
1200
|
+
prefetchedTransactions: [
|
|
1201
|
+
mkTransactionResponse({
|
|
1202
|
+
hash: '0xtx1',
|
|
1203
|
+
value: 1n,
|
|
1204
|
+
from: '0x6cbcd73cd8e8a42844662f0a0e76d7f79afd933d',
|
|
1205
|
+
to: '0xc2907efcce4011c491bbeda8a0fa63ba7aab596c',
|
|
1206
|
+
gasPrice: 0n,
|
|
1207
|
+
}),
|
|
1208
|
+
],
|
|
1209
|
+
})
|
|
1210
|
+
)
|
|
1238
1211
|
|
|
1239
1212
|
expect(await nodeApi.getBlockByHeight(currencyId, 1, true)).toEqual({
|
|
1240
1213
|
hash: '0x474dee0136108e9412e9d84197b468bb057a8dad0f2024fc55adebc4a28fa8c5',
|
|
@@ -1255,18 +1228,23 @@ describe('EVM Family', () => {
|
|
|
1255
1228
|
})
|
|
1256
1229
|
|
|
1257
1230
|
it('should fallback to transaction hashes when prefetched transactions are unavailable', async () => {
|
|
1258
|
-
|
|
1231
|
+
const blockWithThrowingGetter = mkBlock({
|
|
1259
1232
|
hash: '0x474dee0136108e9412e9d84197b468bb057a8dad0f2024fc55adebc4a28fa8c5',
|
|
1260
1233
|
parentHash: '0xfc900c22725f9c0843c9cf7d2c47f4b61b246bd21e18e99f709aebaefc8aff14',
|
|
1261
1234
|
number: 1,
|
|
1262
1235
|
timestamp: now,
|
|
1263
1236
|
transactions: ['0xtx1'],
|
|
1264
|
-
|
|
1237
|
+
})
|
|
1238
|
+
Object.defineProperty(blockWithThrowingGetter, 'prefetchedTransactions', {
|
|
1239
|
+
get() {
|
|
1265
1240
|
const error = new Error('transactions were not prefetched with block request')
|
|
1266
|
-
|
|
1241
|
+
Object.assign(error, { code: 'UNSUPPORTED_OPERATION' })
|
|
1267
1242
|
throw error
|
|
1268
1243
|
},
|
|
1269
|
-
}
|
|
1244
|
+
})
|
|
1245
|
+
jest
|
|
1246
|
+
.spyOn(JsonRpcProvider.prototype, 'getBlock')
|
|
1247
|
+
.mockResolvedValueOnce(blockWithThrowingGetter)
|
|
1270
1248
|
|
|
1271
1249
|
expect(await nodeApi.getBlockByHeight(currencyId, 1, true)).toEqual({
|
|
1272
1250
|
hash: '0x474dee0136108e9412e9d84197b468bb057a8dad0f2024fc55adebc4a28fa8c5',
|
|
@@ -1478,7 +1456,7 @@ describe('EVM Family', () => {
|
|
|
1478
1456
|
(e: unknown) => e
|
|
1479
1457
|
)
|
|
1480
1458
|
expect(err).toBeInstanceOf(UnsupportedRpcMethodError)
|
|
1481
|
-
expect((
|
|
1459
|
+
expect(err).toMatchObject({ method: 'trace_block' })
|
|
1482
1460
|
}
|
|
1483
1461
|
)
|
|
1484
1462
|
})
|
|
@@ -1548,7 +1526,7 @@ describe('EVM Family', () => {
|
|
|
1548
1526
|
(e: unknown) => e
|
|
1549
1527
|
)
|
|
1550
1528
|
expect(err).toBeInstanceOf(UnsupportedRpcMethodError)
|
|
1551
|
-
expect((
|
|
1529
|
+
expect(err).toMatchObject({ method: 'debug_traceBlockByNumber' })
|
|
1552
1530
|
}
|
|
1553
1531
|
)
|
|
1554
1532
|
|
|
@@ -1568,7 +1546,7 @@ describe('EVM Family', () => {
|
|
|
1568
1546
|
(e: unknown) => e
|
|
1569
1547
|
)
|
|
1570
1548
|
expect(err).toBeInstanceOf(UnsupportedRpcMethodError)
|
|
1571
|
-
expect((
|
|
1549
|
+
expect(err).toMatchObject({ method: 'debug_traceBlockByNumber' })
|
|
1572
1550
|
})
|
|
1573
1551
|
})
|
|
1574
1552
|
|
|
@@ -1747,16 +1725,13 @@ describe('EVM Family', () => {
|
|
|
1747
1725
|
const NORMALIZED_RECIPIENT = '0xc2907efcce4011c491bbeda8a0fa63ba7aab596c'
|
|
1748
1726
|
|
|
1749
1727
|
let capturedTransaction: { from?: string; to?: string } | undefined
|
|
1750
|
-
jest
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
}
|
|
1758
|
-
return null
|
|
1759
|
-
})
|
|
1728
|
+
jest.spyOn(JsonRpcProvider.prototype, '_perform').mockImplementation(async (arg) => {
|
|
1729
|
+
if (arg.method === 'estimateGas') {
|
|
1730
|
+
capturedTransaction = arg.transaction
|
|
1731
|
+
return 21000n
|
|
1732
|
+
}
|
|
1733
|
+
return null
|
|
1734
|
+
})
|
|
1760
1735
|
|
|
1761
1736
|
await nodeApi.getGasEstimation(currencyId, address, {
|
|
1762
1737
|
recipient: EIP1191_RECIPIENT,
|
|
@@ -18,7 +18,7 @@ describe('encodeStakingData', () => {
|
|
|
18
18
|
|
|
19
19
|
const encoded = encodeStakingData({
|
|
20
20
|
currencyId,
|
|
21
|
-
operation: 'delegate'
|
|
21
|
+
operation: 'delegate',
|
|
22
22
|
config,
|
|
23
23
|
params,
|
|
24
24
|
})
|
|
@@ -33,7 +33,7 @@ describe('encodeStakingData', () => {
|
|
|
33
33
|
|
|
34
34
|
const encoded = encodeStakingData({
|
|
35
35
|
currencyId,
|
|
36
|
-
operation: 'undelegate'
|
|
36
|
+
operation: 'undelegate',
|
|
37
37
|
config,
|
|
38
38
|
params,
|
|
39
39
|
})
|
|
@@ -49,7 +49,7 @@ describe('encodeStakingData', () => {
|
|
|
49
49
|
|
|
50
50
|
const encoded = encodeStakingData({
|
|
51
51
|
currencyId,
|
|
52
|
-
operation: 'redelegate'
|
|
52
|
+
operation: 'redelegate',
|
|
53
53
|
config,
|
|
54
54
|
params,
|
|
55
55
|
})
|
|
@@ -84,7 +84,7 @@ describe('encodeStakingData', () => {
|
|
|
84
84
|
|
|
85
85
|
const encoded = encodeStakingData({
|
|
86
86
|
currencyId,
|
|
87
|
-
operation: 'delegate'
|
|
87
|
+
operation: 'delegate',
|
|
88
88
|
config,
|
|
89
89
|
params,
|
|
90
90
|
})
|
|
@@ -99,7 +99,7 @@ describe('encodeStakingData', () => {
|
|
|
99
99
|
|
|
100
100
|
const encoded = encodeStakingData({
|
|
101
101
|
currencyId,
|
|
102
|
-
operation: 'undelegate'
|
|
102
|
+
operation: 'undelegate',
|
|
103
103
|
config,
|
|
104
104
|
params,
|
|
105
105
|
})
|
|
@@ -115,7 +115,7 @@ describe('encodeStakingData', () => {
|
|
|
115
115
|
expect(() => {
|
|
116
116
|
encodeStakingData({
|
|
117
117
|
currencyId: 'unsupported_currency',
|
|
118
|
-
operation: 'delegate'
|
|
118
|
+
operation: 'delegate',
|
|
119
119
|
config,
|
|
120
120
|
params: ['validator'],
|
|
121
121
|
})
|
|
@@ -126,7 +126,8 @@ describe('encodeStakingData', () => {
|
|
|
126
126
|
expect(() => {
|
|
127
127
|
encodeStakingData({
|
|
128
128
|
currencyId: 'sei_evm',
|
|
129
|
-
operation
|
|
129
|
+
// @ts-ignore — intentionally invalid operation to test error path
|
|
130
|
+
operation: 'invalidOperation',
|
|
130
131
|
config,
|
|
131
132
|
params: ['validator'],
|
|
132
133
|
})
|
|
@@ -197,12 +198,7 @@ describe('decodeStakingResult', () => {
|
|
|
197
198
|
[mockBalance, mockDelegation],
|
|
198
199
|
])
|
|
199
200
|
|
|
200
|
-
const decoded = decodeStakingResult(
|
|
201
|
-
currencyId,
|
|
202
|
-
'getStakedBalance' as StakingOperation,
|
|
203
|
-
config,
|
|
204
|
-
encodedResult
|
|
205
|
-
)
|
|
201
|
+
const decoded = decodeStakingResult(currencyId, 'getStakedBalance', config, encodedResult)
|
|
206
202
|
|
|
207
203
|
expect(decoded).toBeInstanceOf(Array)
|
|
208
204
|
expect(decoded.length).toBeGreaterThan(0)
|
|
@@ -265,7 +261,7 @@ describe('decodeStakingResult', () => {
|
|
|
265
261
|
|
|
266
262
|
const decoded = decodeStakingResult(
|
|
267
263
|
'sei_evm',
|
|
268
|
-
'getStakedBalance'
|
|
264
|
+
'getStakedBalance',
|
|
269
265
|
STAKING_CONTRACTS['sei_evm'],
|
|
270
266
|
encodedResult
|
|
271
267
|
)
|
|
@@ -283,18 +279,14 @@ describe('decodeStakingResult', () => {
|
|
|
283
279
|
|
|
284
280
|
it('should throw error for unsupported currency', () => {
|
|
285
281
|
expect(() => {
|
|
286
|
-
decodeStakingResult(
|
|
287
|
-
'unsupported_currency',
|
|
288
|
-
'getStakedBalance' as StakingOperation,
|
|
289
|
-
config,
|
|
290
|
-
'0x'
|
|
291
|
-
)
|
|
282
|
+
decodeStakingResult('unsupported_currency', 'getStakedBalance', config, '0x')
|
|
292
283
|
}).toThrow('No ABI found for staking currency: unsupported_currency')
|
|
293
284
|
})
|
|
294
285
|
|
|
295
286
|
it('should throw error for unsupported operation', () => {
|
|
296
287
|
expect(() => {
|
|
297
|
-
|
|
288
|
+
// @ts-ignore — intentionally invalid operation to test error path
|
|
289
|
+
decodeStakingResult('sei_evm', 'invalidOperation', config, '0x')
|
|
298
290
|
}).toThrow("Operation 'invalidOperation' not supported for currency: sei_evm")
|
|
299
291
|
})
|
|
300
292
|
})
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import type { EvmConfigInfo } from '../config'
|
|
5
4
|
import type { Stake } from '@ledgerhq/coin-module-framework/api/types'
|
|
5
|
+
import type { DeepPartialCtor } from '@ledgerhq/coin-module-framework/test/utils'
|
|
6
6
|
import { ethers } from 'ethers'
|
|
7
|
+
import { createMockEvmConfigInfo, mkExternalNode } from '../fixtures/context.fixtures'
|
|
7
8
|
import {
|
|
8
9
|
canCompound,
|
|
9
10
|
canRedelegate,
|
|
@@ -12,12 +13,23 @@ import {
|
|
|
12
13
|
isSeiAccountUnassociated,
|
|
13
14
|
} from './logic'
|
|
14
15
|
|
|
16
|
+
jest.mock('ethers', () => {
|
|
17
|
+
const actual = jest.requireActual('ethers')
|
|
18
|
+
const JsonRpcProvider = jest.fn()
|
|
19
|
+
const Contract = jest.fn()
|
|
20
|
+
return {
|
|
21
|
+
...actual,
|
|
22
|
+
ethers: { ...actual.ethers, JsonRpcProvider, Contract },
|
|
23
|
+
JsonRpcProvider,
|
|
24
|
+
Contract,
|
|
25
|
+
}
|
|
26
|
+
})
|
|
15
27
|
jest.mock('../network/node/types')
|
|
16
28
|
|
|
17
29
|
const mockIsExternalNodeConfig = jest.mocked(require('../network/node/types').isExternalNodeConfig)
|
|
18
30
|
|
|
19
|
-
const mockNode = {
|
|
20
|
-
const mockConfig = { node: mockNode }
|
|
31
|
+
const mockNode = mkExternalNode({ uri: 'https://sei-evm.coin.ledger.com' })
|
|
32
|
+
const mockConfig = createMockEvmConfigInfo({ chainId: 1, node: mockNode })
|
|
21
33
|
|
|
22
34
|
function makeStake(delegate: string, overrides: Partial<Stake> = {}): Stake {
|
|
23
35
|
return {
|
|
@@ -130,26 +142,20 @@ describe('evm staking logic', () => {
|
|
|
130
142
|
|
|
131
143
|
describe('isSeiAccountUnassociated', () => {
|
|
132
144
|
const SEI_ADDRESS = '0x1234567890abcdef1234567890abcdef12345678'
|
|
133
|
-
let contractSpy: jest.SpyInstance
|
|
134
|
-
let providerSpy: jest.SpyInstance
|
|
135
145
|
let mockGetSeiAddr: jest.Mock
|
|
136
146
|
|
|
137
147
|
beforeEach(() => {
|
|
138
148
|
jest.clearAllMocks()
|
|
139
149
|
mockGetSeiAddr = jest.fn().mockResolvedValue('sei1associatedcosmosaddress')
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
.
|
|
150
|
+
jest
|
|
151
|
+
.mocked<DeepPartialCtor<typeof ethers.JsonRpcProvider>>(ethers.JsonRpcProvider)
|
|
152
|
+
.mockImplementation(() => ({}))
|
|
153
|
+
jest
|
|
154
|
+
.mocked<DeepPartialCtor<typeof ethers.Contract>>(ethers.Contract)
|
|
143
155
|
.mockImplementation(() => ({ getSeiAddr: mockGetSeiAddr }))
|
|
144
|
-
|
|
145
156
|
mockIsExternalNodeConfig.mockImplementation((node: unknown) => node === mockNode)
|
|
146
157
|
})
|
|
147
158
|
|
|
148
|
-
afterEach(() => {
|
|
149
|
-
contractSpy.mockRestore()
|
|
150
|
-
providerSpy.mockRestore()
|
|
151
|
-
})
|
|
152
|
-
|
|
153
159
|
it('returns false for a non-sei_evm currency without querying the chain', async () => {
|
|
154
160
|
await expect(isSeiAccountUnassociated(mockConfig, 'ethereum', SEI_ADDRESS)).resolves.toBe(
|
|
155
161
|
false
|