diff --git a/contracts/ForkingManager.sol b/contracts/ForkingManager.sol index d18f6c0a..521c477d 100644 --- a/contracts/ForkingManager.sol +++ b/contracts/ForkingManager.sol @@ -63,6 +63,19 @@ contract ForkingManager is IForkingManager, ForkableStructure { ForkableStructure.initialize(address(this), _parentContract); } + function isForkingInitiated() external view returns (bool) { + return (executionTimeForProposal > 0); + } + + function isForkingExecuted() external view returns (bool) { + return (children[0] != address(0) || children[1] != address(0)); + } + + // TODO: If there is any other reason a fork can be prevented, eg the contract can be frozen by governance, add it here. + function canFork() external view returns (bool) { + return (executionTimeForProposal == 0); + } + /** * @notice function to initiate and schedule the fork * @param _disputeData the dispute contract and call to identify the dispute diff --git a/contracts/interfaces/IForkingManager.sol b/contracts/interfaces/IForkingManager.sol index 181faaa4..b3889904 100644 --- a/contracts/interfaces/IForkingManager.sol +++ b/contracts/interfaces/IForkingManager.sol @@ -30,6 +30,11 @@ interface IForkingManager is IForkableStructure { function globalExitRoot() external returns (address); function arbitrationFee() external returns (uint256); function disputeData() external returns (bool isL1, address disputeContract, bytes32 disputeContent); + function executionTimeForProposal() external returns (uint256); + + function isForkingInitiated() external returns (bool); + function isForkingExecuted() external returns (bool); + function canFork() external returns (bool); // Struct that holds an address pair used to store the new child contracts struct AddressPair { diff --git a/lib/zkevm-contracts b/lib/zkevm-contracts index 4c90c6a6..5d70866e 160000 --- a/lib/zkevm-contracts +++ b/lib/zkevm-contracts @@ -1 +1 @@ -Subproject commit 4c90c6a6ed347a049a2a50f0e94caba9471747e6 +Subproject commit 5d70866e1e4811df16d4c5fefb95100c962cc009 diff --git a/test/ForkingManager.t.sol b/test/ForkingManager.t.sol index b2b8814a..6bc3f742 100644 --- a/test/ForkingManager.t.sol +++ b/test/ForkingManager.t.sol @@ -197,6 +197,54 @@ contract ForkingManagerTest is Test { ); } + function testForkingStatusFunctions() public { + + assertFalse(forkmanager.isForkingInitiated()); + assertFalse(forkmanager.isForkingExecuted()); + assertTrue(forkmanager.canFork()); + + // Mint and approve the arbitration fee for the test contract + forkonomicToken.approve(address(forkmanager), arbitrationFee); + vm.prank(address(this)); + forkonomicToken.mint(address(this), arbitrationFee); + + vm.expectEmit(true, true, true, true, address(forkonomicToken)); + emit Transfer( + address(this), + address(forkmanager), + uint256(arbitrationFee) + ); + + forkmanager.initiateFork( + IForkingManager.DisputeData({ + disputeContract: disputeContract, + disputeContent: disputeContent, + isL1: isL1 + }), + IForkingManager.NewImplementations({ + bridgeImplementation: newBridgeImplementation, + zkEVMImplementation: newZkevmImplementation, + forkonomicTokenImplementation: newForkonomicTokenImplementation, + forkingManagerImplementation: newForkmanagerImplementation, + globalExitRootImplementation: newGlobalExitRootImplementation, + verifier: newVerifierImplementation, + forkID: newForkID + }) + ); + + assertTrue(forkmanager.isForkingInitiated()); + assertFalse(forkmanager.isForkingExecuted()); + assertFalse(forkmanager.canFork()); + + vm.warp(block.timestamp + forkmanager.forkPreparationTime() + 1); + forkmanager.executeFork(); + + assertTrue(forkmanager.isForkingInitiated()); + assertTrue(forkmanager.isForkingExecuted()); + assertFalse(forkmanager.canFork()); + + } + function testInitiateForkChargesFees() public { // Call the initiateFork function to create a new fork vm.expectRevert(bytes("ERC20: insufficient allowance"));