diff --git a/test/invariant-tests/AdapterList.Invariant.sol b/test/invariant-tests/AdapterList.Invariant.sol index aa214ed..9b17a18 100644 --- a/test/invariant-tests/AdapterList.Invariant.sol +++ b/test/invariant-tests/AdapterList.Invariant.sol @@ -9,11 +9,11 @@ import "test/Setup.t.sol"; import "test/contracts-mock/MockUniswapReceiver.sol"; /// handler import -import {SenderAdapterAddHandler} from "test/invariant-tests/handlers/SenderAdapterAdd.handler.sol"; +import {AdapterListHandler} from "test/invariant-tests/handlers/AdapterList.handler.sol"; -/// @notice invariants for adding adapters to multi bridge sender +/// @notice invariants for maintaining adapter list on `MultiBridgeMessageSender` contract AdapterListInvariant is Setup { - SenderAdapterAddHandler public handler; + AdapterListHandler public handler; /// @notice initializes the setup function setUp() public override { @@ -22,19 +22,25 @@ contract AdapterListInvariant is Setup { /// @dev selects fork and deploy the handlers vm.selectFork(fork[SRC_CHAIN_ID]); - handler = new SenderAdapterAddHandler( + handler = new AdapterListHandler( contractAddress[SRC_CHAIN_ID]["GAC"], contractAddress[SRC_CHAIN_ID]["MMA_SENDER"] ); + + /// @dev bind the handler as target for invariant targetContract(address(handler)); } /// @notice invariant-1: adding an adapter should always increase the length of the adapter list /// @notice invariant-2: once a trusted executor is added, its entry should exist in the adapter list /// @notice invariant-3: the adapter list should never contain duplicates - /// @notice invariant-4: the adapter list should always be in orde + /// @notice invariant-4: the adapter list should always be in order + + /// @notice invariant-5: removing an adapter should always decrease the length of the adapter list + /// @notice invariant-6: once a trusted executor is removed, it should not persist in the adapter list function invariant_test_adapter_additions() public { MultiBridgeMessageSender targetContract = MultiBridgeMessageSender(contractAddress[SRC_CHAIN_ID]["MMA_SENDER"]); + if (handler.success()) { uint256 currAdds = handler.currAdds(); @@ -42,12 +48,12 @@ contract AdapterListInvariant is Setup { /// @dev if this asset passes then invariant-2 holds assertTrue(newAddition != address(0)); - /// @dev if this revert then the final index is currAdds - 1 and the invariant-1 holds + /// @dev if this revert invariant-1 and invariant-5 holds try targetContract.senderAdapters(currAdds) { assertFalse(1 == 2); } catch {} - /// @dev assertions for invariant-3 and invariant-4 + /// @dev assertions for invariant-3, invariant-4, invariant-5, invariant-6 if (currAdds > 1) { for (uint256 i = currAdds; i > 0; i--) { assertTrue( diff --git a/test/invariant-tests/handlers/SenderAdapterAdd.handler.sol b/test/invariant-tests/handlers/AdapterList.Handler.sol similarity index 67% rename from test/invariant-tests/handlers/SenderAdapterAdd.handler.sol rename to test/invariant-tests/handlers/AdapterList.Handler.sol index 05024ae..3cf6746 100644 --- a/test/invariant-tests/handlers/SenderAdapterAdd.handler.sol +++ b/test/invariant-tests/handlers/AdapterList.Handler.sol @@ -8,9 +8,8 @@ import "forge-std/Test.sol"; import {MessageSenderGAC} from "src/controllers/MessageSenderGAC.sol"; import {MultiBridgeMessageSender} from "src/MultiBridgeMessageSender.sol"; -/// @notice handler for testing adding adapters to multi message sender -/// @dev simulates the ideal criteria for a successful adapter addition -contract SenderAdapterAddHandler is Test { +/// @notice handler for testing maintaining adapter list +contract AdapterListHandler is Test { /// @notice local state MultiBridgeMessageSender public multiBridgeMessageSender; MessageSenderGAC public gac; @@ -18,7 +17,7 @@ contract SenderAdapterAddHandler is Test { bool public success; uint256 public currAdds; - /// @notice modifier to prank the add sender adapter call + /// @notice modifier to prank caller modifier prank(address _prankster) { vm.startPrank(_prankster); _; @@ -34,6 +33,7 @@ contract SenderAdapterAddHandler is Test { /// @notice helper for adding new adapters function addSenderAdapters(address _newSenderAdapter) external prank(gac.getGlobalOwner()) { success = false; + vm.assume(_newSenderAdapter != address(0)); address[] memory _additions = new address[](1); @@ -44,4 +44,18 @@ contract SenderAdapterAddHandler is Test { currAdds++; } catch {} } + + /// @notice helper for removing existing adapters + function removeSenderAdapters() external prank(gac.getGlobalOwner()) { + vm.assume(currAdds > 0); + success = false; + + address[] memory _removals = new address[](1); + _removals[0] = multiBridgeMessageSender.senderAdapters(currAdds - 1); + + try multiBridgeMessageSender.removeSenderAdapters(_removals) { + success = true; + currAdds--; + } catch {} + } }