Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: chrismaree <[email protected]>
  • Loading branch information
chrismaree committed Oct 31, 2023
1 parent 3ee5280 commit 00f2161
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/HoneyPot.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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);
Expand Down
15 changes: 15 additions & 0 deletions test/HoneyPot.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

0 comments on commit 00f2161

Please sign in to comment.