@ledgerhq/coin-evm 5.3.1 → 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 +3 -13
- package/CHANGELOG.md +13 -0
- package/lib/adapters/blockOperations.d.ts +2 -2
- package/lib/adapters/blockOperations.d.ts.map +1 -1
- package/lib/adapters/blockOperations.js.map +1 -1
- package/lib/api/index.d.ts +1 -1
- package/lib/api/index.d.ts.map +1 -1
- package/lib/config.d.ts +1 -1
- package/lib/config.d.ts.map +1 -1
- package/lib/logic/combine.d.ts +2 -1
- package/lib/logic/combine.d.ts.map +1 -1
- package/lib/logic/combine.js.map +1 -1
- package/lib/logic/common.d.ts +2 -1
- package/lib/logic/common.d.ts.map +1 -1
- package/lib/logic/common.js.map +1 -1
- package/lib/logic/craftTransaction.d.ts +1 -1
- package/lib/logic/craftTransaction.d.ts.map +1 -1
- package/lib/logic/craftTransaction.js.map +1 -1
- package/lib/logic/craftTransactionData.d.ts +1 -1
- package/lib/logic/craftTransactionData.d.ts.map +1 -1
- package/lib/logic/estimateFees.d.ts +1 -1
- package/lib/logic/estimateFees.d.ts.map +1 -1
- package/lib/logic/estimateFees.js.map +1 -1
- package/lib/logic/getBalance.d.ts +1 -1
- package/lib/logic/getBalance.d.ts.map +1 -1
- package/lib/logic/getBalance.js.map +1 -1
- package/lib/logic/getBlock.d.ts +1 -1
- package/lib/logic/getBlock.d.ts.map +1 -1
- package/lib/logic/getBlock.js.map +1 -1
- package/lib/logic/getStakes.d.ts +1 -1
- package/lib/logic/getStakes.d.ts.map +1 -1
- package/lib/logic/internalTransactionsFetcher.d.ts +1 -1
- package/lib/logic/internalTransactionsFetcher.d.ts.map +1 -1
- package/lib/logic/internalTransactionsFetcher.js.map +1 -1
- package/lib/logic/validateIntent.d.ts +1 -1
- package/lib/logic/validateIntent.d.ts.map +1 -1
- package/lib/logic/validateIntent.js.map +1 -1
- package/lib/logic.d.ts +1 -1
- package/lib/logic.d.ts.map +1 -1
- package/lib/network/explorer/etherscan.d.ts +4 -4
- package/lib/network/explorer/etherscan.d.ts.map +1 -1
- package/lib/network/explorer/etherscan.js.map +1 -1
- package/lib/network/explorer/index.d.ts +2 -2
- package/lib/network/explorer/index.d.ts.map +1 -1
- package/lib/network/explorer/index.js.map +1 -1
- package/lib/network/explorer/ledger.d.ts +2 -2
- package/lib/network/explorer/ledger.d.ts.map +1 -1
- package/lib/network/explorer/ledger.js.map +1 -1
- package/lib/network/explorer/none.d.ts +1 -1
- package/lib/network/explorer/none.d.ts.map +1 -1
- package/lib/network/explorer/none.js.map +1 -1
- package/lib/network/explorer/types.d.ts +1 -1
- package/lib/network/explorer/types.d.ts.map +1 -1
- package/lib/network/gasTracker/index.d.ts +2 -2
- package/lib/network/gasTracker/index.d.ts.map +1 -1
- package/lib/network/gasTracker/index.js.map +1 -1
- package/lib/network/gasTracker/ledger.d.ts +3 -3
- package/lib/network/gasTracker/ledger.d.ts.map +1 -1
- package/lib/network/gasTracker/ledger.js.map +1 -1
- package/lib/network/gasTracker/types.d.ts +2 -2
- package/lib/network/gasTracker/types.d.ts.map +1 -1
- package/lib/network/node/ledger.d.ts +2 -2
- package/lib/network/node/ledger.d.ts.map +1 -1
- package/lib/network/node/ledger.js.map +1 -1
- package/lib/network/node/rpc.common.d.ts +1 -1
- package/lib/network/node/rpc.common.d.ts.map +1 -1
- package/lib/network/node/rpc.common.js.map +1 -1
- package/lib/network/node/types.d.ts +3 -3
- package/lib/network/node/types.d.ts.map +1 -1
- package/lib/staking/validators/monad.d.ts +2 -1
- package/lib/staking/validators/monad.d.ts.map +1 -1
- package/lib/staking/validators/monad.js.map +1 -1
- package/lib/staking/validators/monadResolver.d.ts +2 -1
- package/lib/staking/validators/monadResolver.d.ts.map +1 -1
- 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.map +1 -1
- package/lib/staking/validators/zero_gravity.d.ts.map +1 -1
- package/lib/staking/validators/zero_gravity.js.map +1 -1
- package/lib/types/assets.d.ts +1 -1
- package/lib/types/assets.d.ts.map +1 -1
- package/lib/types/transaction.d.ts +1 -1
- package/lib/types/transaction.d.ts.map +1 -1
- package/lib-es/adapters/blockOperations.d.ts +2 -2
- package/lib-es/adapters/blockOperations.d.ts.map +1 -1
- package/lib-es/adapters/blockOperations.js.map +1 -1
- package/lib-es/api/index.d.ts +1 -1
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/config.d.ts +1 -1
- package/lib-es/config.d.ts.map +1 -1
- package/lib-es/logic/combine.d.ts +2 -1
- package/lib-es/logic/combine.d.ts.map +1 -1
- package/lib-es/logic/combine.js.map +1 -1
- package/lib-es/logic/common.d.ts +2 -1
- package/lib-es/logic/common.d.ts.map +1 -1
- package/lib-es/logic/common.js +1 -1
- package/lib-es/logic/common.js.map +1 -1
- package/lib-es/logic/craftTransaction.d.ts +1 -1
- package/lib-es/logic/craftTransaction.d.ts.map +1 -1
- package/lib-es/logic/craftTransaction.js.map +1 -1
- package/lib-es/logic/craftTransactionData.d.ts +1 -1
- package/lib-es/logic/craftTransactionData.d.ts.map +1 -1
- package/lib-es/logic/estimateFees.d.ts +1 -1
- package/lib-es/logic/estimateFees.d.ts.map +1 -1
- package/lib-es/logic/estimateFees.js.map +1 -1
- package/lib-es/logic/getBalance.d.ts +1 -1
- package/lib-es/logic/getBalance.d.ts.map +1 -1
- package/lib-es/logic/getBalance.js.map +1 -1
- package/lib-es/logic/getBlock.d.ts +1 -1
- package/lib-es/logic/getBlock.d.ts.map +1 -1
- package/lib-es/logic/getBlock.js.map +1 -1
- package/lib-es/logic/getStakes.d.ts +1 -1
- package/lib-es/logic/getStakes.d.ts.map +1 -1
- package/lib-es/logic/internalTransactionsFetcher.d.ts +1 -1
- package/lib-es/logic/internalTransactionsFetcher.d.ts.map +1 -1
- package/lib-es/logic/internalTransactionsFetcher.js.map +1 -1
- package/lib-es/logic/validateIntent.d.ts +1 -1
- package/lib-es/logic/validateIntent.d.ts.map +1 -1
- package/lib-es/logic/validateIntent.js.map +1 -1
- package/lib-es/logic.d.ts +1 -1
- package/lib-es/logic.d.ts.map +1 -1
- package/lib-es/network/explorer/etherscan.d.ts +4 -4
- package/lib-es/network/explorer/etherscan.d.ts.map +1 -1
- package/lib-es/network/explorer/etherscan.js.map +1 -1
- package/lib-es/network/explorer/index.d.ts +2 -2
- package/lib-es/network/explorer/index.d.ts.map +1 -1
- package/lib-es/network/explorer/index.js.map +1 -1
- package/lib-es/network/explorer/ledger.d.ts +2 -2
- package/lib-es/network/explorer/ledger.d.ts.map +1 -1
- package/lib-es/network/explorer/ledger.js.map +1 -1
- package/lib-es/network/explorer/none.d.ts +1 -1
- package/lib-es/network/explorer/none.d.ts.map +1 -1
- package/lib-es/network/explorer/none.js.map +1 -1
- package/lib-es/network/explorer/types.d.ts +1 -1
- package/lib-es/network/explorer/types.d.ts.map +1 -1
- package/lib-es/network/gasTracker/index.d.ts +2 -2
- package/lib-es/network/gasTracker/index.d.ts.map +1 -1
- package/lib-es/network/gasTracker/index.js.map +1 -1
- package/lib-es/network/gasTracker/ledger.d.ts +3 -3
- package/lib-es/network/gasTracker/ledger.d.ts.map +1 -1
- package/lib-es/network/gasTracker/ledger.js +1 -1
- package/lib-es/network/gasTracker/ledger.js.map +1 -1
- package/lib-es/network/gasTracker/types.d.ts +2 -2
- package/lib-es/network/gasTracker/types.d.ts.map +1 -1
- package/lib-es/network/node/ledger.d.ts +2 -2
- package/lib-es/network/node/ledger.d.ts.map +1 -1
- package/lib-es/network/node/ledger.js.map +1 -1
- package/lib-es/network/node/rpc.common.d.ts +1 -1
- package/lib-es/network/node/rpc.common.d.ts.map +1 -1
- package/lib-es/network/node/rpc.common.js +1 -1
- package/lib-es/network/node/rpc.common.js.map +1 -1
- package/lib-es/network/node/types.d.ts +3 -3
- package/lib-es/network/node/types.d.ts.map +1 -1
- package/lib-es/staking/validators/monad.d.ts +2 -1
- package/lib-es/staking/validators/monad.d.ts.map +1 -1
- package/lib-es/staking/validators/monad.js.map +1 -1
- package/lib-es/staking/validators/monadResolver.d.ts +2 -1
- package/lib-es/staking/validators/monadResolver.d.ts.map +1 -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.map +1 -1
- package/lib-es/staking/validators/zero_gravity.d.ts.map +1 -1
- package/lib-es/staking/validators/zero_gravity.js.map +1 -1
- package/lib-es/types/assets.d.ts +1 -1
- package/lib-es/types/assets.d.ts.map +1 -1
- package/lib-es/types/transaction.d.ts +1 -1
- package/lib-es/types/transaction.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/adapters/blockOperations.test.ts +29 -31
- package/src/adapters/blockOperations.ts +3 -2
- package/src/adapters/etherscan.test.ts +7 -7
- package/src/adapters/ledger.test.ts +2 -2
- package/src/api/getBlock.integ.test.ts +1 -1
- package/src/api/index.fantom.integ.test.ts +1 -1
- package/src/api/index.flare.integ.test.ts +2 -14
- package/src/api/index.integ.test.ts +330 -246
- package/src/api/index.linea.integ.test.ts +1 -1
- package/src/api/index.optimism.integ.test.ts +1 -1
- package/src/api/index.shape.integ.test.ts +1 -1
- package/src/api/index.ts +1 -1
- package/src/config.ts +1 -1
- package/src/fixtures/context.fixtures.ts +79 -1
- package/src/fixtures/ethers.fixtures.ts +26 -0
- package/src/fixtures/ledger.fixtures.ts +1 -1
- package/src/internalTxSources.test.ts +3 -6
- 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/combine.test.ts +2 -2
- package/src/logic/combine.ts +2 -1
- package/src/logic/common.test.ts +120 -112
- package/src/logic/common.ts +2 -7
- package/src/logic/craftTransaction.test.ts +163 -200
- package/src/logic/craftTransaction.ts +3 -2
- package/src/logic/craftTransactionData.test.ts +6 -6
- package/src/logic/craftTransactionData.ts +1 -1
- package/src/logic/estimateFees.test.ts +19 -15
- package/src/logic/estimateFees.ts +6 -3
- package/src/logic/getBalance.test.ts +16 -15
- package/src/logic/getBalance.ts +4 -3
- package/src/logic/getBlock.test.ts +379 -388
- package/src/logic/getBlock.ts +3 -2
- package/src/logic/getBlockInfo.test.ts +7 -9
- package/src/logic/getNextSequence.test.ts +5 -5
- package/src/logic/getStakes.test.ts +35 -35
- package/src/logic/getStakes.ts +1 -1
- package/src/logic/internalTransactionsFetcher.test.ts +26 -24
- package/src/logic/internalTransactionsFetcher.ts +1 -1
- package/src/logic/lastBlock.test.ts +29 -20
- package/src/logic/listOperations.test.ts +44 -40
- package/src/logic/validateIntent.test.ts +152 -101
- package/src/logic/validateIntent.ts +4 -2
- package/src/logic.test.ts +13 -18
- package/src/logic.ts +1 -1
- package/src/network/explorer/etherscan.test.ts +6 -6
- package/src/network/explorer/etherscan.ts +12 -10
- package/src/network/explorer/index.test.ts +52 -22
- package/src/network/explorer/index.ts +2 -2
- package/src/network/explorer/ledger.test.ts +17 -5
- package/src/network/explorer/ledger.ts +3 -2
- package/src/network/explorer/none.ts +2 -1
- package/src/network/explorer/types.ts +1 -1
- package/src/network/gasTracker/index.test.ts +14 -8
- package/src/network/gasTracker/index.ts +2 -2
- package/src/network/gasTracker/ledger.test.ts +34 -29
- package/src/network/gasTracker/ledger.ts +5 -7
- package/src/network/gasTracker/types.ts +2 -2
- 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/ledger.ts +6 -5
- package/src/network/node/node.fixtures.ts +0 -2
- package/src/network/node/rpc.common.ts +14 -14
- package/src/network/node/rpc.test.ts +153 -184
- package/src/network/node/types.ts +3 -3
- package/src/staking/detectOperationType.test.ts +1 -1
- package/src/staking/encoder.test.ts +14 -22
- package/src/staking/logic.test.ts +20 -14
- package/src/staking/operations/index.test.ts +29 -29
- package/src/staking/prepareIntents.test.ts +26 -20
- package/src/staking/redelegations.test.ts +50 -33
- package/src/staking/rewards.test.ts +29 -17
- package/src/staking/rewardsFromReceipt.test.ts +20 -21
- package/src/staking/transactionData.test.ts +23 -23
- package/src/staking/validators/monad.test.ts +65 -24
- package/src/staking/validators/monad.ts +2 -1
- package/src/staking/validators/monadResolver.ts +2 -1
- package/src/staking/validators/somnia.test.ts +21 -13
- package/src/staking/validators/somnia.ts +2 -1
- package/src/staking/validators/zero_gravity.test.ts +118 -48
- package/src/staking/validators/zero_gravity.ts +2 -1
- package/src/staking/validators.integ.test.ts +13 -25
- package/src/staking/validators.test.ts +7 -2
- package/src/types/assets.ts +1 -1
- package/src/types/transaction.ts +1 -1
|
@@ -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
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { StakingOperation } from '../../types/staking'
|
|
4
|
+
import type { StakingOperation } from '../../types/staking'
|
|
5
5
|
import { buildTransactionParams } from '.'
|
|
6
6
|
|
|
7
7
|
describe('buildTransactionParams', () => {
|
|
@@ -18,7 +18,7 @@ describe('buildTransactionParams', () => {
|
|
|
18
18
|
const currencyId = 'sei_evm'
|
|
19
19
|
|
|
20
20
|
it('should build params for delegate operation', () => {
|
|
21
|
-
const params = buildTransactionParams(currencyId, 'delegate'
|
|
21
|
+
const params = buildTransactionParams(currencyId, 'delegate', {
|
|
22
22
|
valAddress: validatorAddress,
|
|
23
23
|
amount,
|
|
24
24
|
})
|
|
@@ -27,7 +27,7 @@ describe('buildTransactionParams', () => {
|
|
|
27
27
|
})
|
|
28
28
|
|
|
29
29
|
it('should build params for undelegate operation (amount converted from 18-dec EVM to 6-dec usei)', () => {
|
|
30
|
-
const params = buildTransactionParams(currencyId, 'undelegate'
|
|
30
|
+
const params = buildTransactionParams(currencyId, 'undelegate', {
|
|
31
31
|
valAddress: validatorAddress,
|
|
32
32
|
amount,
|
|
33
33
|
})
|
|
@@ -36,7 +36,7 @@ describe('buildTransactionParams', () => {
|
|
|
36
36
|
})
|
|
37
37
|
|
|
38
38
|
it('should build params for redelegate operation (amount converted from 18-dec EVM to 6-dec usei)', () => {
|
|
39
|
-
const params = buildTransactionParams(currencyId, 'redelegate'
|
|
39
|
+
const params = buildTransactionParams(currencyId, 'redelegate', {
|
|
40
40
|
valAddress: validatorAddress,
|
|
41
41
|
amount,
|
|
42
42
|
dstValAddress: dstValidatorAddress,
|
|
@@ -47,7 +47,7 @@ describe('buildTransactionParams', () => {
|
|
|
47
47
|
|
|
48
48
|
it('should truncate sub-usei precision on undelegate (precompile has 6-decimal precision)', () => {
|
|
49
49
|
// 1.234567891 SEI -> truncated to 1.234567 uSEI (9th and later decimals dropped)
|
|
50
|
-
const params = buildTransactionParams(currencyId, 'undelegate'
|
|
50
|
+
const params = buildTransactionParams(currencyId, 'undelegate', {
|
|
51
51
|
valAddress: validatorAddress,
|
|
52
52
|
amount: 1234567891000000000n,
|
|
53
53
|
})
|
|
@@ -57,7 +57,7 @@ describe('buildTransactionParams', () => {
|
|
|
57
57
|
|
|
58
58
|
it('should throw error for redelegate without dstValAddress', () => {
|
|
59
59
|
expect(() => {
|
|
60
|
-
buildTransactionParams(currencyId, 'redelegate'
|
|
60
|
+
buildTransactionParams(currencyId, 'redelegate', {
|
|
61
61
|
valAddress: validatorAddress,
|
|
62
62
|
amount,
|
|
63
63
|
})
|
|
@@ -65,7 +65,7 @@ describe('buildTransactionParams', () => {
|
|
|
65
65
|
})
|
|
66
66
|
|
|
67
67
|
it('should build params for getStakedBalance operation', () => {
|
|
68
|
-
const params = buildTransactionParams(currencyId, 'getStakedBalance'
|
|
68
|
+
const params = buildTransactionParams(currencyId, 'getStakedBalance', {
|
|
69
69
|
valAddress: validatorAddress,
|
|
70
70
|
amount,
|
|
71
71
|
dstValAddress: validatorAddress,
|
|
@@ -77,7 +77,7 @@ describe('buildTransactionParams', () => {
|
|
|
77
77
|
|
|
78
78
|
it('should throw error for getStakedBalance without required params', () => {
|
|
79
79
|
expect(() => {
|
|
80
|
-
buildTransactionParams(currencyId, 'getStakedBalance'
|
|
80
|
+
buildTransactionParams(currencyId, 'getStakedBalance', {
|
|
81
81
|
valAddress: validatorAddress,
|
|
82
82
|
amount,
|
|
83
83
|
})
|
|
@@ -97,7 +97,7 @@ describe('buildTransactionParams', () => {
|
|
|
97
97
|
|
|
98
98
|
describe('Monad', () => {
|
|
99
99
|
it('builds params for delegate operation (valId as bigint, amount carried by msg.value)', () => {
|
|
100
|
-
const params = buildTransactionParams('monad', 'delegate'
|
|
100
|
+
const params = buildTransactionParams('monad', 'delegate', {
|
|
101
101
|
valId: '42',
|
|
102
102
|
amount: 1000000000000000000n,
|
|
103
103
|
})
|
|
@@ -106,7 +106,7 @@ describe('buildTransactionParams', () => {
|
|
|
106
106
|
})
|
|
107
107
|
|
|
108
108
|
it('builds params for claimReward operation (valId as bigint)', () => {
|
|
109
|
-
const params = buildTransactionParams('monad', 'claimReward'
|
|
109
|
+
const params = buildTransactionParams('monad', 'claimReward', {
|
|
110
110
|
valId: '42',
|
|
111
111
|
amount: 0n,
|
|
112
112
|
})
|
|
@@ -115,7 +115,7 @@ describe('buildTransactionParams', () => {
|
|
|
115
115
|
})
|
|
116
116
|
|
|
117
117
|
it('builds params for compoundReward operation (valId as bigint)', () => {
|
|
118
|
-
const params = buildTransactionParams('monad', 'compoundReward'
|
|
118
|
+
const params = buildTransactionParams('monad', 'compoundReward', {
|
|
119
119
|
valId: '42',
|
|
120
120
|
amount: 0n,
|
|
121
121
|
})
|
|
@@ -125,14 +125,14 @@ describe('buildTransactionParams', () => {
|
|
|
125
125
|
|
|
126
126
|
it('throws when monad staking is missing valId', () => {
|
|
127
127
|
expect(() => {
|
|
128
|
-
buildTransactionParams('monad', 'delegate'
|
|
128
|
+
buildTransactionParams('monad', 'delegate', {
|
|
129
129
|
amount: 1000000000000000000n,
|
|
130
130
|
})
|
|
131
131
|
}).toThrow('monad staking requires valId')
|
|
132
132
|
})
|
|
133
133
|
|
|
134
134
|
it('builds params for undelegate operation (valId, amount, withdrawId as bigints)', () => {
|
|
135
|
-
const params = buildTransactionParams('monad', 'undelegate'
|
|
135
|
+
const params = buildTransactionParams('monad', 'undelegate', {
|
|
136
136
|
valId: '42',
|
|
137
137
|
amount: 1000000000000000000n,
|
|
138
138
|
withdrawId: '7',
|
|
@@ -143,7 +143,7 @@ describe('buildTransactionParams', () => {
|
|
|
143
143
|
|
|
144
144
|
it('throws when monad undelegate is missing withdrawId', () => {
|
|
145
145
|
expect(() => {
|
|
146
|
-
buildTransactionParams('monad', 'undelegate'
|
|
146
|
+
buildTransactionParams('monad', 'undelegate', {
|
|
147
147
|
valId: '42',
|
|
148
148
|
amount: 1000000000000000000n,
|
|
149
149
|
})
|
|
@@ -151,7 +151,7 @@ describe('buildTransactionParams', () => {
|
|
|
151
151
|
})
|
|
152
152
|
|
|
153
153
|
it('builds params for withdraw operation (valId, withdrawId as bigints)', () => {
|
|
154
|
-
const params = buildTransactionParams('monad', 'withdraw'
|
|
154
|
+
const params = buildTransactionParams('monad', 'withdraw', {
|
|
155
155
|
valId: '42',
|
|
156
156
|
amount: 0n,
|
|
157
157
|
withdrawId: '7',
|
|
@@ -162,7 +162,7 @@ describe('buildTransactionParams', () => {
|
|
|
162
162
|
|
|
163
163
|
it('throws when monad withdraw is missing withdrawId', () => {
|
|
164
164
|
expect(() => {
|
|
165
|
-
buildTransactionParams('monad', 'withdraw'
|
|
165
|
+
buildTransactionParams('monad', 'withdraw', {
|
|
166
166
|
valId: '42',
|
|
167
167
|
amount: 0n,
|
|
168
168
|
})
|
|
@@ -175,7 +175,7 @@ describe('buildTransactionParams', () => {
|
|
|
175
175
|
const celoValidatorAddress = '0x123456789abcdef'
|
|
176
176
|
|
|
177
177
|
it('should build params for delegate operation', () => {
|
|
178
|
-
const params = buildTransactionParams(currencyId, 'delegate'
|
|
178
|
+
const params = buildTransactionParams(currencyId, 'delegate', {
|
|
179
179
|
valAddress: celoValidatorAddress,
|
|
180
180
|
amount,
|
|
181
181
|
})
|
|
@@ -184,7 +184,7 @@ describe('buildTransactionParams', () => {
|
|
|
184
184
|
})
|
|
185
185
|
|
|
186
186
|
it('should build params for undelegate operation', () => {
|
|
187
|
-
const params = buildTransactionParams(currencyId, 'undelegate'
|
|
187
|
+
const params = buildTransactionParams(currencyId, 'undelegate', {
|
|
188
188
|
valAddress: celoValidatorAddress,
|
|
189
189
|
amount,
|
|
190
190
|
})
|
|
@@ -194,7 +194,7 @@ describe('buildTransactionParams', () => {
|
|
|
194
194
|
|
|
195
195
|
it('should throw error for redelegate operation (not supported)', () => {
|
|
196
196
|
expect(() => {
|
|
197
|
-
buildTransactionParams(currencyId, 'redelegate'
|
|
197
|
+
buildTransactionParams(currencyId, 'redelegate', {
|
|
198
198
|
valAddress: celoValidatorAddress,
|
|
199
199
|
amount,
|
|
200
200
|
})
|
|
@@ -202,7 +202,7 @@ describe('buildTransactionParams', () => {
|
|
|
202
202
|
})
|
|
203
203
|
|
|
204
204
|
it('should build params for getStakedBalance operation', () => {
|
|
205
|
-
const params = buildTransactionParams(currencyId, 'getStakedBalance'
|
|
205
|
+
const params = buildTransactionParams(currencyId, 'getStakedBalance', {
|
|
206
206
|
valAddress: celoValidatorAddress,
|
|
207
207
|
amount,
|
|
208
208
|
})
|
|
@@ -211,7 +211,7 @@ describe('buildTransactionParams', () => {
|
|
|
211
211
|
})
|
|
212
212
|
|
|
213
213
|
it('should build params for getUnstakedBalance operation', () => {
|
|
214
|
-
const params = buildTransactionParams(currencyId, 'getUnstakedBalance'
|
|
214
|
+
const params = buildTransactionParams(currencyId, 'getUnstakedBalance', {
|
|
215
215
|
valAddress: celoValidatorAddress,
|
|
216
216
|
amount,
|
|
217
217
|
})
|
|
@@ -225,7 +225,7 @@ describe('buildTransactionParams', () => {
|
|
|
225
225
|
const somniaValidatorAddress = '0x1234567890abcdef1234567890abcdef12345678'
|
|
226
226
|
|
|
227
227
|
it('builds params for delegate operation', () => {
|
|
228
|
-
const params = buildTransactionParams(currencyId, 'delegate'
|
|
228
|
+
const params = buildTransactionParams(currencyId, 'delegate', {
|
|
229
229
|
valAddress: somniaValidatorAddress,
|
|
230
230
|
amount,
|
|
231
231
|
})
|
|
@@ -234,7 +234,7 @@ describe('buildTransactionParams', () => {
|
|
|
234
234
|
})
|
|
235
235
|
|
|
236
236
|
it('builds params for undelegate operation', () => {
|
|
237
|
-
const params = buildTransactionParams(currencyId, 'undelegate'
|
|
237
|
+
const params = buildTransactionParams(currencyId, 'undelegate', {
|
|
238
238
|
valAddress: somniaValidatorAddress,
|
|
239
239
|
amount,
|
|
240
240
|
})
|
|
@@ -243,7 +243,7 @@ describe('buildTransactionParams', () => {
|
|
|
243
243
|
})
|
|
244
244
|
|
|
245
245
|
it('builds params for claimReward operation', () => {
|
|
246
|
-
const params = buildTransactionParams(currencyId, 'claimReward'
|
|
246
|
+
const params = buildTransactionParams(currencyId, 'claimReward', {
|
|
247
247
|
valAddress: somniaValidatorAddress,
|
|
248
248
|
amount: 0n,
|
|
249
249
|
})
|
|
@@ -252,7 +252,7 @@ describe('buildTransactionParams', () => {
|
|
|
252
252
|
})
|
|
253
253
|
|
|
254
254
|
it('builds params for getStakedBalance operation', () => {
|
|
255
|
-
const params = buildTransactionParams(currencyId, 'getStakedBalance'
|
|
255
|
+
const params = buildTransactionParams(currencyId, 'getStakedBalance', {
|
|
256
256
|
valAddress: somniaValidatorAddress,
|
|
257
257
|
amount: 0n,
|
|
258
258
|
delegator: delegatorAddress,
|
|
@@ -263,7 +263,7 @@ describe('buildTransactionParams', () => {
|
|
|
263
263
|
|
|
264
264
|
it('throws when getStakedBalance is missing delegator', () => {
|
|
265
265
|
expect(() => {
|
|
266
|
-
buildTransactionParams(currencyId, 'getStakedBalance'
|
|
266
|
+
buildTransactionParams(currencyId, 'getStakedBalance', {
|
|
267
267
|
valAddress: somniaValidatorAddress,
|
|
268
268
|
amount: 0n,
|
|
269
269
|
})
|
|
@@ -274,7 +274,7 @@ describe('buildTransactionParams', () => {
|
|
|
274
274
|
describe('Error handling', () => {
|
|
275
275
|
it('should throw error for unsupported currency', () => {
|
|
276
276
|
expect(() => {
|
|
277
|
-
buildTransactionParams('unsupported_currency', 'delegate'
|
|
277
|
+
buildTransactionParams('unsupported_currency', 'delegate', {
|
|
278
278
|
valAddress: validatorAddress,
|
|
279
279
|
amount,
|
|
280
280
|
})
|
|
@@ -283,7 +283,7 @@ describe('buildTransactionParams', () => {
|
|
|
283
283
|
|
|
284
284
|
it('should throw error for unsupported operation type', () => {
|
|
285
285
|
expect(() => {
|
|
286
|
-
buildTransactionParams('sei_evm', 'invalidOperation'
|
|
286
|
+
buildTransactionParams('sei_evm', 'invalidOperation', {
|
|
287
287
|
valAddress: validatorAddress,
|
|
288
288
|
amount,
|
|
289
289
|
})
|
|
@@ -294,7 +294,7 @@ describe('buildTransactionParams', () => {
|
|
|
294
294
|
'throws when %s staking is missing valAddress',
|
|
295
295
|
(currencyId) => {
|
|
296
296
|
expect(() => {
|
|
297
|
-
buildTransactionParams(currencyId, 'delegate'
|
|
297
|
+
buildTransactionParams(currencyId, 'delegate', { amount })
|
|
298
298
|
}).toThrow(`${currencyId} staking requires valAddress`)
|
|
299
299
|
}
|
|
300
300
|
)
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import type {
|
|
4
|
+
import type { MemoNotSupported } from '@ledgerhq/coin-module-framework/api/index'
|
|
5
|
+
import type { BufferTxData } from '@ledgerhq/coin-module-framework/api/types'
|
|
6
|
+
import type { TransactionRequest } from 'ethers'
|
|
7
|
+
import { createStakingTransactionIntentMockData } from '@ledgerhq/coin-module-framework/test-utils'
|
|
5
8
|
import { ethers } from 'ethers'
|
|
6
9
|
import zeroGravityAbi from '../abis/zero_gravity-validator.abi.json'
|
|
10
|
+
import { createMockEvmConfigInfo, mkExternalNode } from '../fixtures/context.fixtures'
|
|
7
11
|
import { withApi } from '../network/node/rpc.common'
|
|
8
12
|
import { isExternalNodeConfig } from '../network/node/types'
|
|
9
13
|
import { prepareStakingIntent } from './prepareIntents'
|
|
@@ -15,32 +19,34 @@ jest.mock('./validators/monad', () => ({ __esModule: true, findFirstFreeWithdraw
|
|
|
15
19
|
const mockedWithApi = jest.mocked(withApi)
|
|
16
20
|
const mockedIsExternalNodeConfig = jest.mocked(isExternalNodeConfig)
|
|
17
21
|
|
|
18
|
-
const mockConfig = {
|
|
19
|
-
|
|
20
|
-
|
|
22
|
+
const mockConfig = createMockEvmConfigInfo({
|
|
23
|
+
chainId: 1,
|
|
24
|
+
node: mkExternalNode({ uri: 'https://zero-gravity.coin.ledger.com' }),
|
|
25
|
+
})
|
|
21
26
|
|
|
22
27
|
const makeIntent = (overrides: Record<string, unknown> = {}) =>
|
|
23
|
-
(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
28
|
+
Object.assign(
|
|
29
|
+
createStakingTransactionIntentMockData<MemoNotSupported, BufferTxData>({
|
|
30
|
+
type: 'staking-legacy',
|
|
31
|
+
mode: 'undelegate',
|
|
32
|
+
amount: 1_000_000_000_000_000_000n,
|
|
33
|
+
asset: { type: 'native' },
|
|
34
|
+
recipient: '0x0000000000000000000000000000000000000001',
|
|
35
|
+
sender: '0x0000000000000000000000000000000000000002',
|
|
36
|
+
valAddress: '0x0000000000000000000000000000000000000001',
|
|
37
|
+
data: { type: 'buffer', value: Buffer.from([]) },
|
|
38
|
+
useAllAmount: false,
|
|
39
|
+
}),
|
|
40
|
+
overrides
|
|
41
|
+
)
|
|
36
42
|
|
|
37
43
|
function makeCallHandler(options: {
|
|
38
44
|
getDelegationShares?: bigint
|
|
39
45
|
convertToSharesResult?: bigint
|
|
40
46
|
withdrawalFeeGwei?: bigint
|
|
41
47
|
}) {
|
|
42
|
-
const iface = new ethers.Interface(zeroGravityAbi
|
|
43
|
-
return jest.fn(async ({ data }:
|
|
48
|
+
const iface = new ethers.Interface(zeroGravityAbi)
|
|
49
|
+
return jest.fn(async ({ data }: TransactionRequest) => {
|
|
44
50
|
const desc = iface.parseTransaction({ data: data ?? '0x' })
|
|
45
51
|
if (desc?.name === 'getDelegation') {
|
|
46
52
|
return iface.encodeFunctionResult('getDelegation', [
|
|
@@ -60,7 +66,7 @@ function makeCallHandler(options: {
|
|
|
60
66
|
|
|
61
67
|
function setupProvider(callHandler: ReturnType<typeof jest.fn>) {
|
|
62
68
|
mockedWithApi.mockImplementation(async (_config, _currencyId, fn) =>
|
|
63
|
-
fn({ call: callHandler }
|
|
69
|
+
fn(Object.assign(Object.create(null), { call: callHandler }))
|
|
64
70
|
)
|
|
65
71
|
}
|
|
66
72
|
|
|
@@ -1,6 +1,9 @@
|
|
|
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 { OperationLike } from './redelegations'
|
|
6
|
+
import type { DeepPartialCtor } from '@ledgerhq/coin-module-framework/test/utils'
|
|
4
7
|
import { BigNumber } from 'bignumber.js'
|
|
5
8
|
import { ethers } from 'ethers'
|
|
6
9
|
import { USEI_TO_EVM_SCALE } from '../utils'
|
|
@@ -11,9 +14,19 @@ import {
|
|
|
11
14
|
resolveRedelegationValidators,
|
|
12
15
|
resolveStakingValidator,
|
|
13
16
|
buildRedelegationsFromOps,
|
|
14
|
-
type OperationLike,
|
|
15
17
|
} from './redelegations'
|
|
16
18
|
|
|
19
|
+
jest.mock('ethers', () => {
|
|
20
|
+
const actual = jest.requireActual('ethers')
|
|
21
|
+
const JsonRpcProvider = jest.fn()
|
|
22
|
+
const Contract = jest.fn()
|
|
23
|
+
return {
|
|
24
|
+
...actual,
|
|
25
|
+
ethers: { ...actual.ethers, JsonRpcProvider, Contract },
|
|
26
|
+
JsonRpcProvider,
|
|
27
|
+
Contract,
|
|
28
|
+
}
|
|
29
|
+
})
|
|
17
30
|
jest.mock('@ledgerhq/live-network', () => jest.fn())
|
|
18
31
|
jest.mock('../network/node/rpc.common')
|
|
19
32
|
jest.mock('../network/node/types')
|
|
@@ -22,8 +35,14 @@ const mockNetwork = jest.mocked(require('@ledgerhq/live-network'))
|
|
|
22
35
|
const mockWithApi = jest.mocked(require('../network/node/rpc.common').withApi)
|
|
23
36
|
const mockIsExternalNodeConfig = jest.mocked(require('../network/node/types').isExternalNodeConfig)
|
|
24
37
|
|
|
25
|
-
const mockNode = { type: 'external', uri: 'https://sei-evm.coin.ledger.com' }
|
|
26
|
-
const mockConfig = {
|
|
38
|
+
const mockNode: EvmConfigInfo['node'] = { type: 'external', uri: 'https://sei-evm.coin.ledger.com' }
|
|
39
|
+
const mockConfig: EvmConfigInfo = {
|
|
40
|
+
status: { type: 'active' },
|
|
41
|
+
chainId: 1,
|
|
42
|
+
name: 'Test EVM',
|
|
43
|
+
node: mockNode,
|
|
44
|
+
explorer: { type: 'none' },
|
|
45
|
+
}
|
|
27
46
|
|
|
28
47
|
const SEI_CURRENCY = 'sei_evm'
|
|
29
48
|
|
|
@@ -56,30 +75,22 @@ function makeOperation(overrides: Partial<OperationLike> = {}): OperationLike {
|
|
|
56
75
|
|
|
57
76
|
describe('redelegations', () => {
|
|
58
77
|
describe('fetchRedelegations', () => {
|
|
59
|
-
//
|
|
60
|
-
// real network request during tests.
|
|
61
|
-
// dummy Cosmos address so the REST API call is reached in most tests.
|
|
62
|
-
// Individual tests that want to verify failure behaviour override it.
|
|
63
|
-
let contractSpy: jest.SpyInstance
|
|
64
|
-
let providerSpy: jest.SpyInstance
|
|
78
|
+
// ethers.JsonRpcProvider and ethers.Contract are module-mocked at the top of
|
|
79
|
+
// this file so no real network request is made during tests.
|
|
65
80
|
let mockGetSeiAddr: jest.Mock
|
|
66
81
|
|
|
67
82
|
beforeEach(() => {
|
|
68
83
|
jest.clearAllMocks()
|
|
69
84
|
mockGetSeiAddr = jest.fn().mockResolvedValue('sei1defaultcosmosaddressfortest')
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
.
|
|
85
|
+
jest
|
|
86
|
+
.mocked<DeepPartialCtor<typeof ethers.JsonRpcProvider>>(ethers.JsonRpcProvider)
|
|
87
|
+
.mockImplementation(() => ({}))
|
|
88
|
+
jest
|
|
89
|
+
.mocked<DeepPartialCtor<typeof ethers.Contract>>(ethers.Contract)
|
|
73
90
|
.mockImplementation(() => ({ getSeiAddr: mockGetSeiAddr }))
|
|
74
|
-
|
|
75
91
|
mockIsExternalNodeConfig.mockImplementation((node: unknown) => node === mockNode)
|
|
76
92
|
})
|
|
77
93
|
|
|
78
|
-
afterEach(() => {
|
|
79
|
-
contractSpy.mockRestore()
|
|
80
|
-
providerSpy.mockRestore()
|
|
81
|
-
})
|
|
82
|
-
|
|
83
94
|
it('should return [] for an unknown currencyId', async () => {
|
|
84
95
|
expect(await fetchRedelegations(mockConfig, 'unknown_chain', '0xabc')).toEqual([])
|
|
85
96
|
})
|
|
@@ -192,9 +203,14 @@ describe('redelegations', () => {
|
|
|
192
203
|
await fetchRedelegations(mockConfig, 'sei_evm', evmAddress)
|
|
193
204
|
|
|
194
205
|
expect(mockNetwork).toHaveBeenCalledTimes(1)
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
206
|
+
expect(mockNetwork).toHaveBeenCalledWith(
|
|
207
|
+
expect.objectContaining({ url: expect.stringContaining(canonicalCosmosAddress) })
|
|
208
|
+
)
|
|
209
|
+
expect(mockNetwork).not.toHaveBeenCalledWith(
|
|
210
|
+
expect.objectContaining({
|
|
211
|
+
url: expect.stringContaining('sei1vmzrwxhgllkjaswzawaue7m7f9qcrc0rww3ccn'),
|
|
212
|
+
})
|
|
213
|
+
)
|
|
198
214
|
})
|
|
199
215
|
|
|
200
216
|
it('should return [] when the precompile call fails (address not associated)', async () => {
|
|
@@ -369,8 +385,14 @@ describe('redelegations', () => {
|
|
|
369
385
|
},
|
|
370
386
|
})
|
|
371
387
|
|
|
372
|
-
const zgNode = { type: 'external', uri: 'https://0g.rpc' }
|
|
373
|
-
const zgConfig = {
|
|
388
|
+
const zgNode: EvmConfigInfo['node'] = { type: 'external', uri: 'https://0g.rpc' }
|
|
389
|
+
const zgConfig: EvmConfigInfo = {
|
|
390
|
+
status: { type: 'active' },
|
|
391
|
+
chainId: 1,
|
|
392
|
+
name: 'Test EVM',
|
|
393
|
+
node: zgNode,
|
|
394
|
+
explorer: { type: 'none' },
|
|
395
|
+
}
|
|
374
396
|
mockIsExternalNodeConfig.mockImplementation((node: unknown) => node === zgNode)
|
|
375
397
|
mockWithApi.mockImplementation(
|
|
376
398
|
(_config: unknown, _currencyId: unknown, fn: (p: unknown) => unknown) =>
|
|
@@ -398,8 +420,7 @@ describe('redelegations', () => {
|
|
|
398
420
|
|
|
399
421
|
const result = await resolveStakingValidator(mockConfig, SEI_CURRENCY, op, 'delegate')
|
|
400
422
|
|
|
401
|
-
expect(result).
|
|
402
|
-
expect(result!.validatorAddress).toBe(VALIDATOR)
|
|
423
|
+
expect(result).toMatchObject({ validatorAddress: VALIDATOR })
|
|
403
424
|
})
|
|
404
425
|
|
|
405
426
|
it('should fall back to RPC when contractPayload is absent', async () => {
|
|
@@ -416,8 +437,7 @@ describe('redelegations', () => {
|
|
|
416
437
|
'delegate'
|
|
417
438
|
)
|
|
418
439
|
|
|
419
|
-
expect(result).
|
|
420
|
-
expect(result!.validatorAddress).toBe(VALIDATOR)
|
|
440
|
+
expect(result).toMatchObject({ validatorAddress: VALIDATOR })
|
|
421
441
|
})
|
|
422
442
|
|
|
423
443
|
it('should return null when no payload is available', async () => {
|
|
@@ -443,10 +463,8 @@ describe('redelegations', () => {
|
|
|
443
463
|
|
|
444
464
|
const result = await resolveStakingValidator(mockConfig, SEI_CURRENCY, op, 'undelegate')
|
|
445
465
|
|
|
446
|
-
expect(result).
|
|
447
|
-
expect(result!.
|
|
448
|
-
expect(result!.amount).not.toBeNull()
|
|
449
|
-
expect(result!.amount!.isEqualTo(EXPECTED_WEI.toString())).toBe(true)
|
|
466
|
+
expect(result).toMatchObject({ validatorAddress: VALIDATOR })
|
|
467
|
+
expect(result!.amount?.isEqualTo(EXPECTED_WEI.toString())).toBe(true)
|
|
450
468
|
})
|
|
451
469
|
|
|
452
470
|
it('should fall back to RPC when contractPayload is absent', async () => {
|
|
@@ -467,8 +485,7 @@ describe('redelegations', () => {
|
|
|
467
485
|
'undelegate'
|
|
468
486
|
)
|
|
469
487
|
|
|
470
|
-
expect(result).
|
|
471
|
-
expect(result!.validatorAddress).toBe(VALIDATOR)
|
|
488
|
+
expect(result).toMatchObject({ validatorAddress: VALIDATOR })
|
|
472
489
|
})
|
|
473
490
|
|
|
474
491
|
it('should return null for malformed calldata', async () => {
|
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import type {
|
|
4
|
+
import type { DeepPartialCtor } from '@ledgerhq/coin-module-framework/test/utils'
|
|
5
5
|
import { ethers } from 'ethers'
|
|
6
|
+
import { createMockEvmConfigInfo, mkExternalNode } from '../fixtures/context.fixtures'
|
|
6
7
|
import { USEI_TO_EVM_SCALE } from '../utils'
|
|
7
8
|
import { fetchRewards } from './rewards'
|
|
8
9
|
|
|
10
|
+
jest.mock('ethers', () => {
|
|
11
|
+
const actual = jest.requireActual('ethers')
|
|
12
|
+
const JsonRpcProvider = jest.fn()
|
|
13
|
+
const Contract = jest.fn()
|
|
14
|
+
return {
|
|
15
|
+
...actual,
|
|
16
|
+
ethers: { ...actual.ethers, JsonRpcProvider, Contract },
|
|
17
|
+
JsonRpcProvider,
|
|
18
|
+
Contract,
|
|
19
|
+
}
|
|
20
|
+
})
|
|
9
21
|
jest.mock('@ledgerhq/live-network', () => jest.fn())
|
|
10
22
|
jest.mock('../network/node/types')
|
|
11
23
|
|
|
@@ -15,8 +27,8 @@ const mockIsExternalNodeConfig = jest.mocked(require('../network/node/types').is
|
|
|
15
27
|
const EVM_ADDRESS = '0x1234567890abcdef1234567890abcdef12345678'
|
|
16
28
|
const COSMOS_ADDRESS = 'sei1defaultcosmosaddressfortest'
|
|
17
29
|
|
|
18
|
-
const mockNode = {
|
|
19
|
-
const mockConfig = { node: mockNode }
|
|
30
|
+
const mockNode = mkExternalNode({ uri: 'https://sei-evm.coin.ledger.com' })
|
|
31
|
+
const mockConfig = createMockEvmConfigInfo({ chainId: 1, node: mockNode })
|
|
20
32
|
|
|
21
33
|
type RewardCoin = { denom: string; amount: string }
|
|
22
34
|
const restResponse = (rewards: Array<{ validator_address: string; reward: RewardCoin[] }>) => ({
|
|
@@ -24,29 +36,27 @@ const restResponse = (rewards: Array<{ validator_address: string; reward: Reward
|
|
|
24
36
|
})
|
|
25
37
|
|
|
26
38
|
describe('fetchRewards', () => {
|
|
27
|
-
let contractSpy: jest.SpyInstance
|
|
28
|
-
let providerSpy: jest.SpyInstance
|
|
29
39
|
let mockGetSeiAddr: jest.Mock
|
|
30
40
|
|
|
31
41
|
beforeEach(() => {
|
|
32
42
|
jest.clearAllMocks()
|
|
33
43
|
mockGetSeiAddr = jest.fn().mockResolvedValue(COSMOS_ADDRESS)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
.
|
|
44
|
+
jest
|
|
45
|
+
.mocked<DeepPartialCtor<typeof ethers.JsonRpcProvider>>(ethers.JsonRpcProvider)
|
|
46
|
+
.mockReturnValue({})
|
|
47
|
+
jest
|
|
48
|
+
.mocked<DeepPartialCtor<typeof ethers.Contract>>(ethers.Contract)
|
|
37
49
|
.mockReturnValue({ getSeiAddr: mockGetSeiAddr })
|
|
38
|
-
|
|
39
50
|
mockIsExternalNodeConfig.mockImplementation((node: unknown) => node === mockNode)
|
|
40
51
|
})
|
|
41
52
|
|
|
42
|
-
afterEach(() => {
|
|
43
|
-
contractSpy.mockRestore()
|
|
44
|
-
providerSpy.mockRestore()
|
|
45
|
-
})
|
|
46
|
-
|
|
47
53
|
it.each([
|
|
48
|
-
{ case: 'unknown currencyId', currencyId: 'unknown_chain', setup: () =>
|
|
49
|
-
{
|
|
54
|
+
{ case: 'unknown currencyId', currencyId: 'unknown_chain', setup: () => undefined },
|
|
55
|
+
{
|
|
56
|
+
case: 'chain has no rewardsStrategy (e.g. Celo)',
|
|
57
|
+
currencyId: 'celo',
|
|
58
|
+
setup: () => undefined,
|
|
59
|
+
},
|
|
50
60
|
{
|
|
51
61
|
case: 'REST call fails',
|
|
52
62
|
currencyId: 'sei_evm',
|
|
@@ -74,7 +84,9 @@ describe('fetchRewards', () => {
|
|
|
74
84
|
|
|
75
85
|
await fetchRewards(mockConfig, 'sei_evm', '0x66c4371aE8FFeD2ec1c2EBbbcCfb7E494181E1E3')
|
|
76
86
|
|
|
77
|
-
expect(
|
|
87
|
+
expect(mockNetwork.mock.calls[0][0]).toMatchObject({
|
|
88
|
+
url: expect.stringContaining(canonicalCosmosAddress),
|
|
89
|
+
})
|
|
78
90
|
})
|
|
79
91
|
|
|
80
92
|
it('scales the integer usei portion to wei (drops sub-usei sdk.Dec precision)', async () => {
|