Skip to content

Commit

Permalink
Add some convenience functions for checking forking status etc withou…
Browse files Browse the repository at this point in the history
…t peeking at implementation details
  • Loading branch information
edmundedgar committed Nov 28, 2023
1 parent b8c183d commit 950492c
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 1 deletion.
13 changes: 13 additions & 0 deletions contracts/ForkingManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions contracts/interfaces/IForkingManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
48 changes: 48 additions & 0 deletions test/ForkingManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down

0 comments on commit 950492c

Please sign in to comment.