Skip to content

Commit

Permalink
Merge pull request #53 from onchainification/issue/52
Browse files Browse the repository at this point in the history
test: close pool
  • Loading branch information
gosuto-inzasheru authored Jun 11, 2024
2 parents cf8b273 + 3e9b560 commit 0c11ba3
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/forge-std
Submodule forge-std updated 2 files
+3 −0 src/Vm.sol
+1 −1 test/Vm.t.sol
6 changes: 0 additions & 6 deletions test/CheckerTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,4 @@ contract CheckerTest is BaseFixture {
assertEq(uint8(_action), uint8(RoboSaverVirtualModule.PoolAction.EXEC_QUEUE_POOL_ACTION));
assertEq(_amount, 0);
}

function testChecker_When_PoolClose() public {
_assertCheckerFalseNoDeficitNorSurplus();

/// @todo: implement test case for when pool should be closed
}
}
41 changes: 41 additions & 0 deletions test/ClosePoolTest.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;

import {IERC20} from "@gnosispay-kit/interfaces/IERC20.sol";

import {BaseFixture} from "./BaseFixture.sol";

import {RoboSaverVirtualModule} from "../src/RoboSaverVirtualModule.sol";

contract ClosePoolTest is BaseFixture {
function testClosePool() public {
_assertCheckerFalseNoDeficitNorSurplus();

// balance=240, dailyAllowance=200, buffer=50
// deposit 100
vm.startPrank(KEEPER);
roboModule.adjustPool(RoboSaverVirtualModule.PoolAction.DEPOSIT, 100e18);
vm.warp(block.timestamp + COOLDOWN_PERIOD);
roboModule.adjustPool(RoboSaverVirtualModule.PoolAction.EXEC_QUEUE_POOL_ACTION, 1);
vm.stopPrank();

// // set buffer to > dailyAllowance + ~poolBalance
vm.prank(GNOSIS_SAFE);
roboModule.setBuffer(500e18);

// this should now trigger a pool close
(bool canExec, bytes memory execPayload) = roboModule.checker();
assertTrue(canExec);
(bytes memory dataWithoutSelector,) = _extractEncodeDataWithoutSelector(execPayload);
(RoboSaverVirtualModule.PoolAction _action, uint256 _amount) =
abi.decode(dataWithoutSelector, (RoboSaverVirtualModule.PoolAction, uint256));
assertEq(uint8(_action), uint8(RoboSaverVirtualModule.PoolAction.CLOSE));

// exec it and check if pool is closed
vm.startPrank(KEEPER);
roboModule.adjustPool(_action, _amount);
vm.warp(block.timestamp + COOLDOWN_PERIOD);
roboModule.adjustPool(RoboSaverVirtualModule.PoolAction.EXEC_QUEUE_POOL_ACTION, 0);
assertEq(IERC20(BPT_STEUR_EURE).balanceOf(GNOSIS_SAFE), 0);
}
}

0 comments on commit 0c11ba3

Please sign in to comment.