From e032f0cdcdbd8aa9941e17a78bbb55b67fe5a628 Mon Sep 17 00:00:00 2001 From: green Date: Sun, 15 Sep 2024 14:13:25 +0200 Subject: [PATCH] test(pool-monitor): increase pool-monitor test coverage --- .../contracts/test/diamond/DiamondTest.t.sol | 2 +- .../monitors/PoolLiquidityMonitorTest.t.sol | 62 ++++++++++++++----- 2 files changed, 48 insertions(+), 16 deletions(-) diff --git a/packages/contracts/test/diamond/DiamondTest.t.sol b/packages/contracts/test/diamond/DiamondTest.t.sol index f4b530683..2ad0a8790 100644 --- a/packages/contracts/test/diamond/DiamondTest.t.sol +++ b/packages/contracts/test/diamond/DiamondTest.t.sol @@ -19,7 +19,7 @@ contract TestDiamond is DiamondTestSetup { } function testHasMultipleFacets() public { - assertEq(facetAddressList.length, 19); + assertEq(facetAddressList.length, 20); } function testFacetsHaveCorrectSelectors() public { diff --git a/packages/contracts/test/dollar/monitors/PoolLiquidityMonitorTest.t.sol b/packages/contracts/test/dollar/monitors/PoolLiquidityMonitorTest.t.sol index 2025a23a0..724c0ec8c 100644 --- a/packages/contracts/test/dollar/monitors/PoolLiquidityMonitorTest.t.sol +++ b/packages/contracts/test/dollar/monitors/PoolLiquidityMonitorTest.t.sol @@ -14,40 +14,72 @@ contract PoolLiquidityMonitorTest is DiamondTestSetup { function setUp() public override { super.setUp(); + + vm.prank(admin); + poolLiquidityMonitor.setDefenderRelayer(defenderRelayer); } - function testUnauthorizedCheckLiquidity() public { - vm.prank(unauthorized); - vm.expectRevert("Not authorized: Only Defender Relayer allowed"); + function testSetThresholdPercentage() public { + uint256 newThresholdPercentage = 30; - poolLiquidityMonitor.checkLiquidityVertex(); + vm.prank(admin); + poolLiquidityMonitor.setThresholdPercentage(newThresholdPercentage); } - function testUnauthorizedSetDefenderRelayer() public { - address newRelayer = address(0x789); + function testUnauthorizedSetThresholdPercentage() public { + uint256 newThresholdPercentage = 30; vm.expectRevert("Manager: Caller is not admin"); - poolLiquidityMonitor.setDefenderRelayer(newRelayer); + poolLiquidityMonitor.setThresholdPercentage(newThresholdPercentage); } - function testSetDefenderRelayer() public { - address newRelayer = address(0x789); + function testDropLiquidityVertex() public { + vm.expectRevert("Insufficient liquidity"); vm.prank(admin); - poolLiquidityMonitor.setDefenderRelayer(newRelayer); + poolLiquidityMonitor.dropLiquidityVertex(); } - function testSetThresholdPercentage() public { - uint256 newThresholdPercentage = 30; + function testUnauthorizedDropLiquidityVertex() public { + vm.expectRevert("Manager: Caller is not admin"); + poolLiquidityMonitor.dropLiquidityVertex(); + } + function testTogglePaused() public { vm.prank(admin); - poolLiquidityMonitor.setThresholdPercentage(newThresholdPercentage); + poolLiquidityMonitor.togglePaused(); } - function testDropLiquidityVertex() public { + function testUnauthorizedTogglePaused() public { + vm.expectRevert("Manager: Caller is not admin"); + poolLiquidityMonitor.togglePaused(); + } + + function testUnauthorizedCheckLiquidity() public { + vm.prank(unauthorized); + vm.expectRevert("Not authorized: Only Defender Relayer allowed"); + + poolLiquidityMonitor.checkLiquidityVertex(); + } + + function testCheckLiquidity() public { vm.expectRevert("Insufficient liquidity"); + vm.prank(defenderRelayer); + poolLiquidityMonitor.checkLiquidityVertex(); + } + + function testSetDefenderRelayer() public { + address newRelayer = address(0x789); + vm.prank(admin); - poolLiquidityMonitor.dropLiquidityVertex(); + poolLiquidityMonitor.setDefenderRelayer(newRelayer); + } + + function testUnauthorizedSetDefenderRelayer() public { + address newRelayer = address(0x789); + + vm.expectRevert("Manager: Caller is not admin"); + poolLiquidityMonitor.setDefenderRelayer(newRelayer); } }