Skip to content

Commit 0ae5c17

Browse files
committed
Use a custom anvil sender during the recovery tests
1 parent f09f378 commit 0ae5c17

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

packages/wallet/wdk/test/recovery.test.ts

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, expect, it } from 'vitest'
22
import { QueuedRecoveryPayload, SignerReady, TransactionDefined } from '../src/sequence/index.js'
3-
import { Bytes, Hex, Mnemonic, Provider, RpcTransport } from 'ox'
3+
import { Address, Bytes, Hex, Mnemonic, Provider, RpcTransport, Secp256k1 } from 'ox'
44
import { Network, Payload } from '@0xsequence/wallet-primitives'
55
import { LOCAL_RPC_URL, newManager } from './constants.js'
66

@@ -102,11 +102,23 @@ describe('Recovery', () => {
102102
// Complete the recovery payload
103103
const { to, data } = await manager.recovery.completePayload(requestId2)
104104

105+
// Generate and fund a sender address to avoid race conditions with default Anvil account
106+
const senderAddress = Address.fromPublicKey(Secp256k1.getPublicKey({ privateKey: Secp256k1.randomPrivateKey() }))
107+
await provider.request({
108+
method: 'anvil_setBalance',
109+
params: [senderAddress, Hex.fromNumber(1000000000000000000n)],
110+
})
111+
await provider.request({
112+
method: 'anvil_impersonateAccount',
113+
params: [senderAddress],
114+
})
115+
105116
// Send this transaction to anvil so we queue the payload
106117
await provider.request({
107118
method: 'eth_sendTransaction',
108119
params: [
109120
{
121+
from: senderAddress,
110122
to,
111123
data,
112124
},
@@ -318,9 +330,21 @@ describe('Recovery', () => {
318330

319331
// Complete the recovery payload and send to blockchain
320332
const { to, data } = await manager.recovery.completePayload(requestId2)
333+
334+
// Generate and fund a sender address to avoid race conditions with default Anvil account
335+
const senderAddress = Address.fromPublicKey(Secp256k1.getPublicKey({ privateKey: Secp256k1.randomPrivateKey() }))
336+
await provider.request({
337+
method: 'anvil_setBalance',
338+
params: [senderAddress, Hex.fromNumber(1000000000000000000n)],
339+
})
340+
await provider.request({
341+
method: 'anvil_impersonateAccount',
342+
params: [senderAddress],
343+
})
344+
321345
await provider.request({
322346
method: 'eth_sendTransaction',
323-
params: [{ to, data }],
347+
params: [{ from: senderAddress, to, data }],
324348
})
325349

326350
// Wait for payload to become valid
@@ -463,10 +487,21 @@ describe('Recovery', () => {
463487

464488
const { to, data } = await manager.recovery.completePayload(requestId)
465489

490+
// Generate and fund a sender address to avoid race conditions with default Anvil account
491+
const senderAddress = Address.fromPublicKey(Secp256k1.getPublicKey({ privateKey: Secp256k1.randomPrivateKey() }))
492+
await provider.request({
493+
method: 'anvil_setBalance',
494+
params: [senderAddress, Hex.fromNumber(1000000000000000000n)],
495+
})
496+
await provider.request({
497+
method: 'anvil_impersonateAccount',
498+
params: [senderAddress],
499+
})
500+
466501
// Send transactions sequentially to avoid nonce conflicts
467502
await provider.request({
468503
method: 'eth_sendTransaction',
469-
params: [{ to, data }],
504+
params: [{ from: senderAddress, to, data }],
470505
})
471506

472507
// Small delay to ensure transaction ordering

0 commit comments

Comments
 (0)