From 88944bed29246e90d3a8312d1e7a8387ad942a59 Mon Sep 17 00:00:00 2001 From: Alexander Burkut Date: Wed, 22 Jan 2025 14:27:52 +0300 Subject: [PATCH] add fixes for executeStateOverrides --- tests/tenderly-simulation.ts | 42 +++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/tests/tenderly-simulation.ts b/tests/tenderly-simulation.ts index 26e7ddb1f..401ef5a38 100644 --- a/tests/tenderly-simulation.ts +++ b/tests/tenderly-simulation.ts @@ -232,24 +232,32 @@ export class TenderlySimulation implements TransactionSimulator { async executeStateOverrides( stateOverridesParams: Record, ) { + if (!this.rpcURL) { + throw new Error( + `rpcURL is not defined for testnet: ${this.vnetId} (https://dashboard.tenderly.co/${TENDERLY_ACCOUNT_ID}/${TENDERLY_PROJECT}/testnet/${this.vnetId}`, + ); + } + const testNetRPC = new StaticJsonRpcProvider(this.rpcURL); + await Promise.all( + Object.keys(stateOverridesParams).map(async addr => { + const storage = stateOverridesParams[addr].storage; - // need to execute promises sequentially here - for await (const addr of Object.keys(stateOverridesParams)) { - const storage = stateOverridesParams[addr].storage; - - for await (const slot of Object.keys(storage)) { - const txHash = await testNetRPC!.send('tenderly_setStorageAt', [ - addr, - slot, - storage[slot], - ]); - - const transaction = await testNetRPC!.waitForTransaction(txHash); - if (!transaction.status) { - console.log(`Transaction failed: ${txHash}`); - } - } - } + await Promise.all( + Object.keys(storage).map(async slot => { + const txHash = await testNetRPC!.send('tenderly_setStorageAt', [ + addr, + slot, + storage[slot], + ]); + + const transaction = await testNetRPC!.waitForTransaction(txHash); + if (!transaction.status) { + console.log(`Transaction failed: ${txHash}`); + } + }), + ); + }), + ); } }