fix: deterministic direct deploys (#4555)

## Problem solved

Short description of the bug fixed or feature added

<!-- start pr-codex -->

---

## PR-Codex overview
This PR updates contract deployment logic to include salt and adds a check for contract deployment status in tests.

### Detailed summary
- Updated contract deployment to include salt for CREATE2 deployment
- Added check for contract deployment status in tests using `isContractDeployed` function

> ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}`

<!-- end pr-codex -->
This commit is contained in:
joaquim-verges
2024-09-12 10:16:25 +00:00
parent edce1bf2f7
commit df42167f94
2 changed files with 16 additions and 2 deletions
@@ -122,7 +122,7 @@ export async function deployContract(
if (options.salt !== undefined) {
// Deploy with CREATE2 if salt is provided
const info = await computeDeploymentInfoFromBytecode(options);
sendAndConfirmTransaction({
await sendAndConfirmTransaction({
account: options.account,
transaction: prepareTransaction({
chain: options.chain,
@@ -135,6 +135,7 @@ export async function deployContract(
bytecode: options.bytecode,
encodedArgs: info.encodedArgs,
create2FactoryAddress: info.create2FactoryAddress,
salt: options.salt,
});
}
@@ -2,6 +2,7 @@ import { describe, expect, it } from "vitest";
import { ANVIL_CHAIN } from "../../../test/src/chains.js";
import { TEST_CLIENT } from "../../../test/src/test-clients.js";
import { TEST_ACCOUNT_A } from "../../../test/src/test-wallets.js";
import { isContractDeployed } from "../../utils/bytecode/is-contract-deployed.js";
import { ENTRYPOINT_ADDRESS_v0_6 } from "../../wallets/smart/lib/constants.js";
import { deployPublishedContract } from "./deploy-published.js";
@@ -38,7 +39,13 @@ describe.runIf(process.env.TW_SECRET_KEY)(
},
salt: "test",
});
expect(address).toBe("0x75fc461544723c0dac7b46256027878e82ddc2cb");
expect(address).toBe("0x8a9e25cbf6daa2b56cc0df4669195b8c8c20cda8");
const isDeployed = await isContractDeployed({
client: TEST_CLIENT,
chain: ANVIL_CHAIN,
address,
});
expect(isDeployed).toBe(true);
});
it("should deploy a published autofactory contract", async () => {
@@ -69,6 +76,12 @@ describe.runIf(process.env.TW_SECRET_KEY)(
salt: "test",
});
expect(address).toBe("0x777151741260F8d4098dD492e45FdB536F442672");
const isDeployed = await isContractDeployed({
client: TEST_CLIENT,
chain: ANVIL_CHAIN,
address,
});
expect(isDeployed).toBe(true);
});
// TODO: Replace these tests' live contracts with mocks