Skip to content

Commit

Permalink
new: fxBase for tests; mock state sender/receiver
Browse files Browse the repository at this point in the history
  • Loading branch information
DhairyaSethi committed Apr 25, 2023
1 parent 2def179 commit ee27692
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
18 changes: 18 additions & 0 deletions contracts/mock/StateReceiver.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface IFxChild {
function onStateReceive(uint256 stateId, bytes calldata _data) external;
}

contract MockStateReceiver {
address public immutable fxChild;

constructor(address _fxChild) {
fxChild = _fxChild;
}

function receiveState(uint256 stateId, bytes calldata _data) external {
IFxChild(fxChild).onStateReceive(stateId, _data);
}
}
27 changes: 27 additions & 0 deletions contracts/mock/StateSender.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface IStateReceiver {
function receiveState(uint256 stateId, bytes calldata data) external;

function fxChild() external returns (address);
}

contract MockStateSender {
event StateSynced(uint256 indexed id, address indexed contractAddress, bytes data);
IStateReceiver public stateReceiver;

constructor(address _stateReceiver) {
stateReceiver = IStateReceiver(_stateReceiver);
}

function updateStateReceiver(address _where) public {
stateReceiver = IStateReceiver(_where);
}

function syncState(address /*receiver*/, bytes calldata data) external {
uint256 stateId = 1;
stateReceiver.receiveState(stateId, data);
emit StateSynced(stateId, stateReceiver.fxChild(), data);
}
}
39 changes: 39 additions & 0 deletions test/utils/FxBase.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@utils/Test.sol";
import {FxRoot} from "contracts/FxRoot.sol";
import {FxChild} from "contracts/FxChild.sol";
import {MockStateSender} from "contracts/mock/StateSender.sol";
import {MockStateReceiver} from "contracts/mock/StateReceiver.sol";

contract FxBase is Test {
FxRoot public fxRoot;
FxChild public fxChild;
MockStateSender public stateSender;
MockStateReceiver public stateReceiver;

address public MATIC = 0x0000000000000000000000000000000000001001;

function setUp() public virtual {
fxChild = new FxChild();

stateReceiver = new MockStateReceiver(address(fxChild));

vm.etch(MATIC, address(stateReceiver).code);

stateSender = new MockStateSender(MATIC);
fxRoot = new FxRoot(address(stateSender));

fxRoot.setFxChild(address(fxChild));
fxChild.setFxRoot(address(fxRoot));
}
}

contract MockMessageProcessor {
event MessageProcessed(uint256 indexed stateId, address rootMessageSender, bytes data);

function processMessageFromRoot(uint256 stateId, address rootMessageSender, bytes calldata data) public {
emit MessageProcessed(stateId, rootMessageSender, data);
}
}

0 comments on commit ee27692

Please sign in to comment.