2

This is the simple function, how do I deploy the contract and send ether along with it?

    function setUp() public {
        test = new testContract(
            Owner;
        );
    }
2
  • where do you wanna send ethers and why? Commented Oct 26, 2023 at 14:38
  • @TalhaSajidChaudhary some use cases require users to send ether along with their contact during deployment.
    – Rohan Nero
    Commented Oct 26, 2023 at 14:48

1 Answer 1

2

As long as your constructor is marked payable, you can modify your test like this:

function setUp() public {
        test = new testContract{value: 777}(
            Owner;
        );
    }

You can ensure that the ETH was sent by adding a test like this:

function test_balance() public {
     uint bal = address(test).balance;
     assertEq(bal, 100);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.