-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new: fxBase for tests; mock state sender/receiver
- Loading branch information
1 parent
2def179
commit ee27692
Showing
3 changed files
with
84 additions
and
0 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,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); | ||
} | ||
} |
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,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); | ||
} | ||
} |
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,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); | ||
} | ||
} |