function burnFaucetTokens(uint256 amountToBurn) public onlyOwner {
require(amountToBurn <= balanceOf(address(this)), "Faucet Token Balance: Insufficient");
_transfer(address(this), msg.sender, balanceOf(address(this)));
_burn(msg.sender, amountToBurn);
}
function testBurnFaucetTokensLogicBug() public {
uint256 initialContractBalance = raiseBoxFaucet.getFaucetTotalSupply();
uint256 initialOwnerBalance = raiseBoxFaucet.getBalance(owner);
console.log("=== Status before test ===");
console.log("Contract token balance:", initialContractBalance);
console.log("Owner token balance:", initialOwnerBalance));
uint256 amountToBurn = initialContractBalance / 2;
console.log("=== Ready to burn ===");
console.log("Amount of tokens to burn:", amountToBurn);
vm.prank(owner);
raiseBoxFaucet.burnFaucetTokens(amountToBurn);
uint256 finalContractBalance = raiseBoxFaucet.getFaucetTotalSupply();
uint256 finalOwnerBalance = raiseBoxFaucet.getBalance(owner);
uint256 totalSupply = raiseBoxFaucet.totalSupply();
console.log("=== Status after burn ===");
console.log("Contract token balance:", finalContractBalance);
console.log("Owner token balance:", finalOwnerBalance);
console.log("Total supply:", totalSupply);
assertEq(finalContractBalance, 0, "Contract balance should be 0 because it has all been transferred to the owner");
uint256 expectedOwnerBalance = initialContractBalance - amountToBurn;
assertEq(finalOwnerBalance, expectedOwnerBalance, "Owner balance should equal initial contract balance minus amount burned");
uint256 expectedTotalSupply = initialContractBalance - amountToBurn;
assertEq(totalSupply, expectedTotalSupply, "Total supply should decrease by amount burned");
console.log("=== Problem Analysis ===");
console.log("Problem 1: The entire contract balance was transferred to the owner, but only some of the tokens in the owner's wallet were burned");
console.log("Problem 2: This means the owner received additional tokens, but the total supply did not decrease as expected");
console.log("Actual number of tokens received by the owner:", finalOwnerBalance - initialOwnerBalance);
console.log("This equals the initial contract balance minus the burn amount, indicating that the owner receives all remaining tokens");
}
function burnFaucetTokens(uint256 amountToBurn) external onlyOwner {
uint256 faucetBalance = balanceOf(address(this));
require(amountToBurn <= faucetBalance, "Faucet: insufficient balance to burn");
_burn(address(this), amountToBurn);
emit BurnedFaucetTokens(address(this), amountToBurn);
}