-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1fcd91a
commit b83212f
Showing
4 changed files
with
101 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
pragma solidity >=0.8.9; | ||
|
||
/// library imports | ||
import {Vm, Test} from "forge-std/Test.sol"; | ||
|
||
/// local imports | ||
import "test/Setup.t.sol"; | ||
|
||
/// handler import | ||
import {AccessControlSenderHandler} from "test/invariant-tests/handlers/AccessControlSender.handler.sol"; | ||
|
||
contract AccessControlHandlerInvariant is Setup { | ||
AccessControlSenderHandler public handler; | ||
|
||
/// @notice nonce snapshot for assertions | ||
uint256 public localNonceState; | ||
|
||
function setUp() public override { | ||
/// @dev calls setup to spin up test contracts | ||
super.setUp(); | ||
|
||
/// @dev selects fork and deploy the handlers | ||
vm.selectFork(fork[SRC_CHAIN_ID]); | ||
handler = new AccessControlSenderHandler( | ||
contractAddress[SRC_CHAIN_ID]["GAC"], | ||
contractAddress[SRC_CHAIN_ID]["MMA_SENDER"] | ||
); | ||
|
||
/// @dev bind the handler as target for invariant | ||
targetContract(address(handler)); | ||
} | ||
|
||
function invariant_test_acess_control_src() public { | ||
if (handler.lastCaller() == MessageSenderGAC(contractAddress[SRC_CHAIN_ID]["GAC"]).authorisedCaller()) { | ||
++localNonceState; | ||
} | ||
assertEq(MultiBridgeMessageSender(contractAddress[SRC_CHAIN_ID]["MMA_SENDER"]).nonce(), localNonceState); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
test/invariant-tests/handlers/AccessControlSender.Handler.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
pragma solidity >=0.8.9; | ||
|
||
/// library imports | ||
import "forge-std/Test.sol"; | ||
|
||
/// local imports | ||
import {MessageSenderGAC} from "src/controllers/MessageSenderGAC.sol"; | ||
import {MultiBridgeMessageSender} from "src/MultiBridgeMessageSender.sol"; | ||
|
||
/// @notice handler for testing access control invariants | ||
contract AccessControlSenderHandler is Test { | ||
/// @notice local state | ||
MultiBridgeMessageSender public multiBridgeMessageSender; | ||
MessageSenderGAC public gac; | ||
|
||
/// @notice logs last caller for validations | ||
address public lastCaller; | ||
|
||
/// @notice modifier to prank caller | ||
modifier prank(address _prankster) { | ||
vm.startPrank(_prankster); | ||
_; | ||
vm.stopPrank(); | ||
} | ||
|
||
/// @notice initial setup contracts | ||
constructor(address _gac, address _multiBridge) { | ||
gac = MessageSenderGAC(_gac); | ||
multiBridgeMessageSender = MultiBridgeMessageSender(_multiBridge); | ||
} | ||
|
||
/// @notice helper for remote call | ||
function remoteCall( | ||
address simulatedCaller, | ||
uint256 _dstChainId, | ||
address _target, | ||
bytes memory _callData, | ||
uint256 _nativeValue, | ||
uint256 _expiration, | ||
address _refundAddress, | ||
uint256[] memory _fees, | ||
uint256 _successThreshold, | ||
address[] memory _excludedAdapters | ||
) external prank(simulatedCaller) { | ||
multiBridgeMessageSender.remoteCall( | ||
_dstChainId, | ||
_target, | ||
_callData, | ||
_nativeValue, | ||
_expiration, | ||
_refundAddress, | ||
_fees, | ||
_successThreshold, | ||
_excludedAdapters | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters