Mystery Box

First Flight #25
Beginner FriendlyFoundry
100 EXP
View results
Submission Details
Severity: low
Invalid

`TestMysteryBox.t.sol` in test file, there are some missing causes the test run failed.

Summary

I am not sure if test file should be audited or not, but with these missing or mistakes, the test cases will not pass.

Tools Used

foundry test

Recommendations

1 . TestMysteryBox::setUp forget to deal owner some ETH.

function setUp() public {
owner = makeAddr("owner");
user1 = address(0x1);
user2 = address(0x2);
+ vm.prank(owner);
deal(owner, 0.1 ether);
mysteryBox = new MysteryBox{value: 0.1 ether}();
console.log("Reward Pool Length:", mysteryBox.getRewardPool().length);
}

2 . TestMysteryBox::testSetBoxPrice forget to prank as owner for calling this function.

function testSetBoxPrice() public {
uint256 newPrice = 0.2 ether;
+ vm.prank(owner);
mysteryBox.setBoxPrice(newPrice);
assertEq(mysteryBox.boxPrice(), newPrice);
}

3 . TestMysteryBox::testAddReward forget to prank as owner for calling this function.
4 . TestMysteryBox::testAddReward the assertions has wrong index for the latest reward.

function testAddReward() public {
+ vm.prank(owner);
mysteryBox.addReward("Diamond Coin", 2 ether);
MysteryBox.Reward[] memory rewards = mysteryBox.getRewardPool();
assertEq(rewards.length, 5);
- assertEq(rewards[3].name, "Diamond Coin");
+ assertEq(rewards[rewards.length - 1].value, 2 ether);
- assertEq(rewards[3].name, "Diamond Coin");
+ assertEq(rewards[rewards.length - 1].value, 2 ether);
}

5 . TestMysteryBox::testWithdrawFunds forget to add contract's starting balance.

function testWithdrawFunds() public {
+ uint256 startingBalanceOfContract = address(mysteryBox).balance;
vm.deal(user1, 1 ether);
vm.prank(user1);
mysteryBox.buyBox{value: 0.1 ether}();
uint256 ownerBalanceBefore = owner.balance;
console.log("Owner Balance Before:", ownerBalanceBefore);
vm.prank(owner);
mysteryBox.withdrawFunds();
uint256 ownerBalanceAfter = owner.balance;
console.log("Owner Balance After:", ownerBalanceAfter);
- assertEq(ownerBalanceAfter - ownerBalanceBefore, 0.1 ether);
+ assertEq(ownerBalanceAfter - ownerBalanceBefore, 0.1 ether + startingBalanceOfContract);
}
Updates

Appeal created

inallhonesty Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Out of scope

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.

Give us feedback!