From 5407697f6389f24b923ec95b92c45a02350c23ca Mon Sep 17 00:00:00 2001 From: Petr Ermishkin Date: Mon, 13 Jan 2025 17:59:18 +0300 Subject: [PATCH] Use payable constructor instead of `deposit` (#1398) --- .../e2e-tests/ts/lib/abis/contractsFactory.ts | 15 +++---------- .../ts/tests/eth/contractsFactory.ts | 22 ++----------------- 2 files changed, 5 insertions(+), 32 deletions(-) diff --git a/utils/e2e-tests/ts/lib/abis/contractsFactory.ts b/utils/e2e-tests/ts/lib/abis/contractsFactory.ts index fd5e7d61f..c79e29350 100644 --- a/utils/e2e-tests/ts/lib/abis/contractsFactory.ts +++ b/utils/e2e-tests/ts/lib/abis/contractsFactory.ts @@ -6,7 +6,7 @@ // /** // * Sets contract deployer as owner. // */ -// constructor() { +// constructor() payable { // owner = msg.sender; // 'msg.sender' is sender of current call, contract deployer for a constructor // } // @@ -17,8 +17,6 @@ // return new Item(); // } // -// function deposit() external payable {} -// // function withdrawAll() external isOwner { // (bool success,) = owner.call{value:address(this).balance}(""); // require(success, "Transfer failed!"); @@ -40,7 +38,7 @@ export default { { type: "constructor", inputs: [], - stateMutability: "nonpayable", + stateMutability: "payable", }, { type: "function", @@ -55,13 +53,6 @@ export default { ], stateMutability: "nonpayable", }, - { - type: "function", - name: "deposit", - inputs: [], - outputs: [], - stateMutability: "payable", - }, { type: "function", name: "withdrawAll", @@ -71,5 +62,5 @@ export default { }, ], bytecode: - "0x6080604052348015600e575f5ffd5b505f80546001600160a01b0319163317905561022d8061002d5f395ff3fe608060405260043610610033575f3560e01c8063853828b6146100375780638e1a55fc1461004d578063d0e30db01461004b575b5f5ffd5b348015610042575f5ffd5b5061004b61007d565b005b348015610058575f5ffd5b50610061610167565b6040516001600160a01b03909116815260200160405180910390f35b5f546001600160a01b031633146100d15760405162461bcd60e51b815260206004820152601360248201527221b0b63632b91034b9903737ba1037bbb732b960691b60448201526064015b60405180910390fd5b5f80546040516001600160a01b039091169047908381818185875af1925050503d805f811461011b576040519150601f19603f3d011682016040523d82523d5f602084013e610120565b606091505b50509050806101645760405162461bcd60e51b815260206004820152601060248201526f5472616e73666572206661696c65642160801b60448201526064016100c8565b50565b5f60405161017490610193565b604051809103905ff08015801561018d573d5f5f3e3d5ffd5b50905090565b6058806101a08339019056fe6080604052348015600e575f5ffd5b50603e80601a5f395ff3fe60806040525f5ffdfea2646970667358221220d3bdf3d2bfc6fbce1d0d2d42bf9323942c2a6cd1a0e747494d15f535449b35db64736f6c634300081c0033a26469706673582212202a42ba32ac9354cd2dbd675ca2ba09c51d4b8fdcc3ef5bd015da91685e8c113b64736f6c634300081c0033", + "0x60806040525f80546001600160a01b03191633179055610216806100225f395ff3fe608060405234801561000f575f5ffd5b5060043610610034575f3560e01c8063853828b6146100385780638e1a55fc14610042575b5f5ffd5b610040610066565b005b61004a610150565b6040516001600160a01b03909116815260200160405180910390f35b5f546001600160a01b031633146100ba5760405162461bcd60e51b815260206004820152601360248201527221b0b63632b91034b9903737ba1037bbb732b960691b60448201526064015b60405180910390fd5b5f80546040516001600160a01b039091169047908381818185875af1925050503d805f8114610104576040519150601f19603f3d011682016040523d82523d5f602084013e610109565b606091505b505090508061014d5760405162461bcd60e51b815260206004820152601060248201526f5472616e73666572206661696c65642160801b60448201526064016100b1565b50565b5f60405161015d9061017c565b604051809103905ff080158015610176573d5f5f3e3d5ffd5b50905090565b6058806101898339019056fe6080604052348015600e575f5ffd5b50603e80601a5f395ff3fe60806040525f5ffdfea26469706673582212205b805df397effd81fac6da3aaca5e17656240493717a9d8af48b1834ed60974964736f6c634300081c0033a2646970667358221220d09615e692fa242f639400bccc3a539415c571f8d26c76da4c90437f6e7ef43964736f6c634300081c0033", } as const; diff --git a/utils/e2e-tests/ts/tests/eth/contractsFactory.ts b/utils/e2e-tests/ts/tests/eth/contractsFactory.ts index cfcd2144d..e47b76148 100644 --- a/utils/e2e-tests/ts/tests/eth/contractsFactory.ts +++ b/utils/e2e-tests/ts/tests/eth/contractsFactory.ts @@ -24,6 +24,7 @@ describe("contracts factory", () => { const deployContractTxHash = await alice.deployContract({ abi: contractsFactory.abi, bytecode: contractsFactory.bytecode, + value: 1n, }); const deployContractTxReceipt = await publicClient.waitForTransactionReceipt({ @@ -32,27 +33,8 @@ describe("contracts factory", () => { }); const factoryAddress = deployContractTxReceipt.contractAddress!; - const depositPromise = alice - .writeContract({ - address: factoryAddress, - abi: contractsFactory.abi, - functionName: "deposit", - value: 1n, // Even the smallest deposit is enough - }) - .then((depositTx) => - publicClient.waitForTransactionReceipt({ - hash: depositTx, - timeout: 18_000, - }), - ); - const item1AddressPromise = build(factoryAddress, bob, publicClient); - // Trying to wait for responses in parallel is worth it, since the test is already too long. - // Ordering between `deposit` and 1st `build` doesn't matter. // Contract factory's `CREATE` nonce for the 1st `build` will be 1. - const [item1Address] = await Promise.all([ - item1AddressPromise, - depositPromise, - ]); + const item1Address = await build(factoryAddress, bob, publicClient); // If there's a bug in the EVM, it will clear the contract state after `withdrawAll`. const withdrawalTx = await alice.writeContract({