Skip to content

Commit

Permalink
Apply nonce manager and parallel awaiting (#1398)
Browse files Browse the repository at this point in the history
  • Loading branch information
quasiyoke committed Jan 16, 2025
1 parent 1e7254d commit 6aeced9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 34 deletions.
3 changes: 2 additions & 1 deletion utils/e2e-tests/ts/lib/ethViem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
http,
webSocket,
} from "viem";
import { mnemonicToAccount } from "viem/accounts";
import { mnemonicToAccount, nonceManager } from "viem/accounts";
import { AddCleanup } from "./cleanup";

export type ExtraParams = {
Expand Down Expand Up @@ -89,6 +89,7 @@ export const publicClientFromNodeWebSocket = (
export const devAccounts = arrayMap(DEV_ACCOUNT_INDICES, (accountIndex) =>
mnemonicToAccount(SUBSTRATE_DEV_SEED_PHRASE, {
path: `${ROOT_DEV_ACCOUNT_DERIVATION_PATH}/${accountIndex}`,
nonceManager,
}),
);

Expand Down
69 changes: 36 additions & 33 deletions utils/e2e-tests/ts/tests/eth/contractsFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ describe("contracts factory", () => {
let publicClient: eth.PublicClientWebSocket;
let devClients: eth.DevClientsWebSocket;
beforeEachWithCleanup(async (cleanup) => {
node = runNode(
{ args: ["--dev", "--tmp"] /*, env: { RUST_LOG: "info,evm=debug" }*/ },
cleanup.push,
);
node = runNode({ args: ["--dev", "--tmp"] }, cleanup.push);

await node.waitForBoot;

Expand Down Expand Up @@ -46,39 +43,45 @@ describe("contracts factory", () => {
gas: 67_566n,
} as const;
// Contract factory's `CREATE` nonce for the 1st `build` will be 1.
const build1Tx = await alice.writeContract(buildParams);
const build1Receipt = await publicClient.waitForTransactionReceipt({
hash: build1Tx,
timeout: 18_000,
});
expect(build1Receipt.status).toBe("success");

// If there's a bug in the EVM, it will clear the contract state after `withdrawAll`.
const withdrawalTx = await alice.writeContract({
address: factoryAddress,
abi: contractsFactory.abi,
functionName: "withdrawAll",
gas: 30_585n,
});
const withdrawalReceipt = await publicClient.waitForTransactionReceipt({
hash: withdrawalTx,
timeout: 18_000,
});
expect(withdrawalReceipt.status).toBe("success");

// Contract factory's `CREATE` nonce for the 2nd `build` should be 2 (in the buggy EVM: 0).
const build2Tx = await alice.writeContract(buildParams);
const build2Receipt = await publicClient.waitForTransactionReceipt({
hash: build2Tx,
timeout: 18_000,
});
expect(build2Receipt.status).toBe("success");
const build1Promise = alice.writeContract(buildParams).then((txHash) =>
publicClient.waitForTransactionReceipt({
hash: txHash,
timeout: 18_000,
}),
);
// If there's a bug in the EVM execution, it will clear the contract state after `withdrawAll`.
const withdrawalPromise = alice
.writeContract({
address: factoryAddress,
abi: contractsFactory.abi,
functionName: "withdrawAll",
gas: 53_090n,
})
.then((txHash) =>
publicClient.waitForTransactionReceipt({
hash: txHash,
timeout: 18_000,
}),
);
// Contract factory's `CREATE` nonce for the 2nd `build` should be 2 (in the buggy EVM execution: 0).
const build2Promise = alice.writeContract(buildParams).then((txHash) =>
publicClient.waitForTransactionReceipt({
hash: txHash,
timeout: 18_000,
}),
);
const [build1Receipt, withdrawalReceipt, build2Receipt] = await Promise.all(
[build1Promise, withdrawalPromise, build2Promise],
);
expect(build1Receipt.status, "status of first `build`").toBe("success");
expect(withdrawalReceipt.status, "status of withdrawal").toBe("success");
expect(build2Receipt.status, "status of second `build`").toBe("success");

// Contract factory's `CREATE` nonce for the 3rd `build` should be 3.
// In the buggy EVM execution: nonce = 1, the same as for the 1st `build`; transaction will be reverted.
const build3 = await alice.writeContract(buildParams);
const build3Tx = await alice.writeContract(buildParams);
const build3Receipt = await publicClient.waitForTransactionReceipt({
hash: build3,
hash: build3Tx,
timeout: 18_000,
});
expect(build3Receipt.status, "status of third `build`").toBe("success");

Check failure on line 87 in utils/e2e-tests/ts/tests/eth/contractsFactory.ts

View workflow job for this annotation

GitHub Actions / End-to-end tests / base

tests/eth/contractsFactory.ts > contracts factory > builds contracts after emptying the wallet

AssertionError: status of third `build`: expected 'reverted' to be 'success' // Object.is equality Expected: "success" Received: "reverted" ❯ tests/eth/contractsFactory.ts:87:61
Expand Down

0 comments on commit 6aeced9

Please sign in to comment.