diff --git a/test/invariant/MockAdaptor.sol b/test/invariant/MockAdaptor.sol new file mode 100644 index 00000000..d774342c --- /dev/null +++ b/test/invariant/MockAdaptor.sol @@ -0,0 +1,35 @@ +// SPDX-License-Identifier: Apache 2.0 +pragma solidity 0.8.19; + +import {Test} from "forge-std/Test.sol"; +import {IChildBridgeAdaptor} from "../../src/interfaces/child/IChildBridgeAdaptor.sol"; +import {IRootBridgeAdaptor} from "../../src/interfaces/root/IRootBridgeAdaptor.sol"; + +interface MessageReceiver { + function onMessageReceive(bytes calldata data) external; +} + +contract MockAdaptor is Test, IChildBridgeAdaptor, IRootBridgeAdaptor { + + uint256 chainId; + MessageReceiver messageReceiver; + MockAdaptor otherAdaptor; + + constructor() {} + + function initialize(uint256 _chainId, address _messageReceiver, address _otherAdaptor) public { + chainId = _chainId; + messageReceiver = MessageReceiver(_messageReceiver); + otherAdaptor = MockAdaptor(_otherAdaptor); + } + + function sendMessage(bytes calldata payload, address /*refundRecipient*/) external payable override(IChildBridgeAdaptor, IRootBridgeAdaptor) { + otherAdaptor.onMessageReceive(payload); + vm.selectFork(chainId); + } + + function onMessageReceive(bytes calldata data) external { + vm.selectFork(chainId); + messageReceiver.onMessageReceive(data); + } +} \ No newline at end of file