From b0507e929fb38e66a9a44a341c02a2e59ff72551 Mon Sep 17 00:00:00 2001 From: Chris Maree Date: Tue, 7 Nov 2023 10:33:34 +0100 Subject: [PATCH] Address ability to create empty pots (#6) Signed-off-by: chrismaree --- src/HoneyPot.sol | 2 ++ test/HoneyPot.sol | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/HoneyPot.sol b/src/HoneyPot.sol index 4cb1863..6f715ca 100644 --- a/src/HoneyPot.sol +++ b/src/HoneyPot.sol @@ -30,6 +30,7 @@ contract HoneyPot is Ownable { function createHoneyPot() external payable { require(honeyPots[msg.sender].liquidationPrice == 0, "Liquidation price already set for this user"); + require(msg.value > 0, "No value sent"); (, int256 currentPrice,,,) = oracle.latestRoundData(); @@ -55,6 +56,7 @@ contract HoneyPot is Ownable { HoneyPotDetails storage userPot = honeyPots[honeyPotCreator]; require(currentPrice != userPot.liquidationPrice, "Liquidation price reached for this user"); + require(userPot.balance > 0, "No balance to withdraw"); _emptyPotForUser(honeyPotCreator, msg.sender); emit HoneyPotEmptied(honeyPotCreator, msg.sender, userPot.balance); diff --git a/test/HoneyPot.sol b/test/HoneyPot.sol index 7ef0df7..ac9fd82 100644 --- a/test/HoneyPot.sol +++ b/test/HoneyPot.sol @@ -171,4 +171,19 @@ contract HoneyPotTest is CommonTest { assertTrue(liquidatorBalanceAfter == liquidatorBalanceBefore + honeyPotBalance); } + + function testCreateHoneyPotWithNoValue() public { + vm.expectRevert("No value sent"); + honeyPot.createHoneyPot{value: 0}(); + } + + function testEmptyHoneyPotWithZeroBalance() public { + // Assuming honeyPot has been created before + // Reset HoneyPot for the caller to ensure balance is 0 + honeyPot.resetPot(); + + vm.prank(liquidator); + vm.expectRevert("No balance to withdraw"); + honeyPot.emptyHoneyPot(address(this)); + } }