I want to test a function that I have written for my smart contract with Forge from Foundry.
This is the function that allows to withdraw the Ether in this contract.
function withdraw() public onlyOwner {
address _owner = owner();
uint256 amount = address(this).balance;
(bool sent, ) = _owner.call{value: amount}(
"Revenue from NFT Sale"
);
require(sent, "Failed to send Ether");
}
When I write a test case it fails for the withdrawal part, but I cannot see why
function testWithdrawExample() public {
// owner of the contract is just the default account
// which is the deployer of the test contract
// => deployer = address(this);
// ... prepare state
// execute function
cryptoDevs.withdraw();
// ... assert state
}
All what I see when I use high verbosity (traces visible)
├─ [7845] CryptoDevs::withdraw()
│ ├─ [190] CryptoDevsTest::52657665{value: 200000000000000000}(6e75652066726f6d204e46542043727970746f20446576732053616c65)
│ │ └─ ← ()
│ └─ ← "Failed to send Ether"
└─ ← "Failed to send Ether"