-
function testWithdrawFromMultipleFunders() public funded skipZkSync {
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
@lc345 because we are using the funded modifier which prank the USER and send some funds to the contract modifier funded() {
vm.prank(USER);
fundMe.fund{value: SEND_VALUE}();
assert(address(fundMe).balance > 0);
_;
} so we need to count for that in the assertion. In fact if you log the amount of USER contribution you will see it does indeed exist. function testWithdrawFromMultipleFunders() public funded skipZkSync {
uint160 numberOfFunders = 10;
uint160 startingFunderIndex = 2;
console.log("USER contribution:", fundMe.getAddressToAmountFunded(USER));
for (uint160 i = startingFunderIndex; i < numberOfFunders + startingFunderIndex; i++) {
// we get hoax from stdcheats
// prank + deal
hoax(address(i), STARTING_USER_BALANCE);
fundMe.fund{value: SEND_VALUE}();
}
uint256 startingFundMeBalance = address(fundMe).balance;
uint256 startingOwnerBalance = fundMe.getOwner().balance;
vm.startPrank(fundMe.getOwner());
fundMe.withdraw();
vm.stopPrank();
assert(address(fundMe).balance == 0);
assert(startingFundMeBalance + startingOwnerBalance == fundMe.getOwner().balance);
assert((numberOfFunders + 1) * SEND_VALUE == fundMe.getOwner().balance - startingOwnerBalance);
} forge test --mt testWithdrawFromMultipleFunders -vvvv
[⠊] Compiling...
[⠢] Compiling 1 files with Solc 0.8.19
[⠆] Solc 0.8.19 finished in 1.10s
Compiler run successful!
Ran 1 test for test/unit/FundMeTest.t.sol:FundMeTest
[PASS] testWithdrawFromMultipleFunders() (gas: 601676)
Logs:
⚠️ You have deployed a mock contract!
Make sure this was intentional
USER contribution: 100000000000000000 |
Beta Was this translation helpful? Give feedback.
@lc345 because we are using the funded modifier which prank the USER and send some funds to the contract
so we need to count for that in the assertion. In fact if you log the amount of USER contribution you will see it does indeed exist.