|
| 1 | +// SPDX-License-Identifier: UNLICENSED |
| 2 | +pragma solidity =0.8.15; |
| 3 | + |
| 4 | +import {console} from "forge-std/Test.sol"; |
| 5 | +import {TickHelpers} from "@src/lib/TickHelpers.sol"; |
| 6 | + |
| 7 | +import {FailSafe} from "@src/FailSafe.sol"; |
| 8 | +import {Pausable} from "@src/custom/Pausable.sol"; |
| 9 | + |
| 10 | +import {TestBase} from "@test/TestBase.sol"; |
| 11 | + |
| 12 | +contract FailSafeTests is TestBase { |
| 13 | + FailSafe failsafe; |
| 14 | + |
| 15 | + uint256 constant INVENTORY_LOCK_ID_DEPOSIT = 0; |
| 16 | + uint256 constant INVENTORY_LOCK_ID_DEPOSIT_WITH_NFT = 1; |
| 17 | + uint256 constant INVENTORY_LOCK_ID_WITHDRAW = 2; |
| 18 | + uint256 constant INVENTORY_LOCK_ID_COLLECT_WETH_FEES = 3; |
| 19 | + uint256 constant INVENTORY_LOCK_ID_INCREASE_POSITION = 4; |
| 20 | + |
| 21 | + uint256 constant VAULT_FACTORY_LOCK_ID_CREATE_VAULT = 0; |
| 22 | + |
| 23 | + uint256 constant FEE_DISTRIBUTOR_LOCK_ID_DISTRIBUTE = 0; |
| 24 | + uint256 constant FEE_DISTRIBUTOR_LOCK_ID_DISTRIBUTE_VTOKENS = 1; |
| 25 | + |
| 26 | + uint256 constant NFTX_ROUTER_LOCK_ID_ADDLIQ = 0; |
| 27 | + uint256 constant NFTX_ROUTER_LOCK_ID_INCREASELIQ = 1; |
| 28 | + uint256 constant NFTX_ROUTER_LOCK_ID_REMOVELIQ = 2; |
| 29 | + uint256 constant NFTX_ROUTER_LOCK_ID_SELLNFTS = 3; |
| 30 | + uint256 constant NFTX_ROUTER_LOCK_ID_BUYNFTS = 4; |
| 31 | + |
| 32 | + function setUp() public override { |
| 33 | + super.setUp(); |
| 34 | + |
| 35 | + FailSafe.Contract[] memory contracts = new FailSafe.Contract[](4); |
| 36 | + contracts[0] = FailSafe.Contract({ |
| 37 | + addr: address(inventoryStaking), |
| 38 | + lastLockId: 4 |
| 39 | + }); |
| 40 | + contracts[1] = FailSafe.Contract({ |
| 41 | + addr: address(vaultFactory), |
| 42 | + lastLockId: 0 |
| 43 | + }); |
| 44 | + contracts[2] = FailSafe.Contract({ |
| 45 | + addr: address(feeDistributor), |
| 46 | + lastLockId: 1 |
| 47 | + }); |
| 48 | + contracts[3] = FailSafe.Contract({ |
| 49 | + addr: address(nftxRouter), |
| 50 | + lastLockId: 4 |
| 51 | + }); |
| 52 | + |
| 53 | + failsafe = new FailSafe(contracts); |
| 54 | + |
| 55 | + // add the failsafe as guardian |
| 56 | + for (uint256 i; i < contracts.length; i++) { |
| 57 | + Pausable(contracts[i].addr).setIsGuardian(address(failsafe), true); |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + function test_FailSafe_pauseAll_RevertsForNonOwner() external { |
| 62 | + hoax(makeAddr("nonOwner")); |
| 63 | + vm.expectRevert("Ownable: caller is not the owner"); |
| 64 | + failsafe.pauseAll(); |
| 65 | + } |
| 66 | + |
| 67 | + function test_FailSafe_pauseAll_Success() external { |
| 68 | + failsafe.pauseAll(); |
| 69 | + |
| 70 | + // check if all operations are paused |
| 71 | + assertTrue(inventoryStaking.isPaused(INVENTORY_LOCK_ID_DEPOSIT)); |
| 72 | + assertTrue( |
| 73 | + inventoryStaking.isPaused(INVENTORY_LOCK_ID_DEPOSIT_WITH_NFT) |
| 74 | + ); |
| 75 | + assertTrue(inventoryStaking.isPaused(INVENTORY_LOCK_ID_WITHDRAW)); |
| 76 | + assertTrue( |
| 77 | + inventoryStaking.isPaused(INVENTORY_LOCK_ID_COLLECT_WETH_FEES) |
| 78 | + ); |
| 79 | + assertTrue( |
| 80 | + inventoryStaking.isPaused(INVENTORY_LOCK_ID_INCREASE_POSITION) |
| 81 | + ); |
| 82 | + |
| 83 | + assertTrue(vaultFactory.isPaused(VAULT_FACTORY_LOCK_ID_CREATE_VAULT)); |
| 84 | + |
| 85 | + assertTrue(feeDistributor.isPaused(FEE_DISTRIBUTOR_LOCK_ID_DISTRIBUTE)); |
| 86 | + assertTrue( |
| 87 | + feeDistributor.isPaused(FEE_DISTRIBUTOR_LOCK_ID_DISTRIBUTE_VTOKENS) |
| 88 | + ); |
| 89 | + |
| 90 | + assertTrue(nftxRouter.isPaused(NFTX_ROUTER_LOCK_ID_ADDLIQ)); |
| 91 | + assertTrue(nftxRouter.isPaused(NFTX_ROUTER_LOCK_ID_INCREASELIQ)); |
| 92 | + assertTrue(nftxRouter.isPaused(NFTX_ROUTER_LOCK_ID_REMOVELIQ)); |
| 93 | + assertTrue(nftxRouter.isPaused(NFTX_ROUTER_LOCK_ID_SELLNFTS)); |
| 94 | + assertTrue(nftxRouter.isPaused(NFTX_ROUTER_LOCK_ID_BUYNFTS)); |
| 95 | + } |
| 96 | +} |
0 commit comments