From e691a209dcf9c8be4e5b83623fe81261d166a719 Mon Sep 17 00:00:00 2001 From: green Date: Thu, 12 Sep 2024 13:09:45 +0200 Subject: [PATCH] test(pool-monitor): increase test coverage --- .../monitors/PoolLiquidityMonitorTest.t.sol | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/packages/contracts/test/dollar/monitors/PoolLiquidityMonitorTest.t.sol b/packages/contracts/test/dollar/monitors/PoolLiquidityMonitorTest.t.sol index 33196781c..64b801ce7 100644 --- a/packages/contracts/test/dollar/monitors/PoolLiquidityMonitorTest.t.sol +++ b/packages/contracts/test/dollar/monitors/PoolLiquidityMonitorTest.t.sol @@ -8,6 +8,7 @@ import "../../helpers/LocalTestHelper.sol"; contract PoolLiquidityMonitorTest is LocalTestHelper { PoolLiquidityMonitor monitor; address defenderRelayer = address(0x456); + address unauthorized = address(0x123); function setUp() public override { super.setUp(); @@ -25,8 +26,54 @@ contract PoolLiquidityMonitorTest is LocalTestHelper { function testSetDefenderRelayer() public { address newRelayer = address(0x789); + vm.prank(monitor.owner()); monitor.setDefenderRelayer(newRelayer); assertEq(monitor.defenderRelayer(), newRelayer); } + + function testUnauthorizedCheckLiquidity() public { + vm.prank(unauthorized); + vm.expectRevert("Not authorized: Only Defender Relayer allowed"); + + monitor.checkLiquidity(); + } + + function testCheckLiquidity() public { + vm.prank(defenderRelayer); + monitor.checkLiquidity(); + } + + function testSetDefenderRelayerToZeroAddress() public { + vm.prank(owner); + vm.expectRevert(); + monitor.setDefenderRelayer(address(0)); + } + + function testCheckLiquidityWithDifferentValues() public { + uint256 mockedLiquidityHigh = 10000; + uint256 mockedLiquidityLow = 100; + + vm.mockCall( + address(ubiquityPoolFacet), + abi.encodeWithSelector( + UbiquityPoolFacet.collateralUsdBalance.selector + ), + abi.encode(mockedLiquidityHigh) + ); + + vm.prank(defenderRelayer); + monitor.checkLiquidity(); + + vm.mockCall( + address(ubiquityPoolFacet), + abi.encodeWithSelector( + UbiquityPoolFacet.collateralUsdBalance.selector + ), + abi.encode(mockedLiquidityLow) + ); + + vm.prank(defenderRelayer); + monitor.checkLiquidity(); + } }