|
1 | 1 | import { describe, expect, it } from 'vitest' |
2 | 2 | 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' |
4 | 4 | import { Network, Payload } from '@0xsequence/wallet-primitives' |
5 | 5 | import { LOCAL_RPC_URL, newManager } from './constants.js' |
6 | 6 |
|
@@ -102,11 +102,23 @@ describe('Recovery', () => { |
102 | 102 | // Complete the recovery payload |
103 | 103 | const { to, data } = await manager.recovery.completePayload(requestId2) |
104 | 104 |
|
| 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 | + |
105 | 116 | // Send this transaction to anvil so we queue the payload |
106 | 117 | await provider.request({ |
107 | 118 | method: 'eth_sendTransaction', |
108 | 119 | params: [ |
109 | 120 | { |
| 121 | + from: senderAddress, |
110 | 122 | to, |
111 | 123 | data, |
112 | 124 | }, |
@@ -318,9 +330,21 @@ describe('Recovery', () => { |
318 | 330 |
|
319 | 331 | // Complete the recovery payload and send to blockchain |
320 | 332 | 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 | + |
321 | 345 | await provider.request({ |
322 | 346 | method: 'eth_sendTransaction', |
323 | | - params: [{ to, data }], |
| 347 | + params: [{ from: senderAddress, to, data }], |
324 | 348 | }) |
325 | 349 |
|
326 | 350 | // Wait for payload to become valid |
@@ -463,10 +487,21 @@ describe('Recovery', () => { |
463 | 487 |
|
464 | 488 | const { to, data } = await manager.recovery.completePayload(requestId) |
465 | 489 |
|
| 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 | + |
466 | 501 | // Send transactions sequentially to avoid nonce conflicts |
467 | 502 | await provider.request({ |
468 | 503 | method: 'eth_sendTransaction', |
469 | | - params: [{ to, data }], |
| 504 | + params: [{ from: senderAddress, to, data }], |
470 | 505 | }) |
471 | 506 |
|
472 | 507 | // Small delay to ensure transaction ordering |
|
0 commit comments