The GivingThanks::donate
Ether transfer to a charity might fail without clear feedback.
The donate function performs a low-level call to send Ether to the charity but does not handle failures effectively. If the transfer fails, the contract currently does not log or revert in a way that informs users or donors. While the code includes a require(sent, "Failed to send Ether") check, adding an event to log failures would improve transparency.
This test confirms that a failure in the transfer to the charity address causes a revert with an appropriate error message, helping prevent silent failures in donation transfers.
Foundry
Log Success and Failure Events:
Create two events, one for successful transfers and one for failures, to notify donors of the donation outcome.
Emit a DonationSuccess event when the transfer is successful, and a DonationFailure event if the transfer fails.
Fallback Mechanism or Refund (Optional):
If a transfer fails, an optional fallback mechanism (like adding funds to a refund balance) could be implemented, allowing users to withdraw their donation if the initial transfer to the charity fails.
By logging both successful and failed attempts, donors are clearly informed of the status of their transactions, reducing the likelihood of confusion. This improves user experience and adds a layer of accountability and transparency.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.