Skip to content

Commit

Permalink
add fixes for executeStateOverrides
Browse files Browse the repository at this point in the history
  • Loading branch information
aburkut committed Jan 22, 2025
1 parent a5cdf56 commit 88944be
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions tests/tenderly-simulation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,24 +232,32 @@ export class TenderlySimulation implements TransactionSimulator {
async executeStateOverrides(
stateOverridesParams: Record<string, StateSimulateApiOverride>,
) {
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}`);
}
}),
);
}),
);
}
}

0 comments on commit 88944be

Please sign in to comment.