Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dantaik committed Jan 24, 2025
1 parent 9b94d55 commit 38b917f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
9 changes: 7 additions & 2 deletions packages/protocol/contracts/layer1/based/ForkRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ contract ForkRouter is UUPSUpgradeable, Ownable2StepUpgradeable {
address public immutable newFork;

error InvalidParams();
error NewForkInvalid();
error NewForkNotActive();
error ZeroAddress();

Expand All @@ -39,8 +40,12 @@ contract ForkRouter is UUPSUpgradeable, Ownable2StepUpgradeable {
_fallback();
}

function currentFork() public view returns (address) {
return IFork(newFork).isForkActive() ? newFork : oldFork;
function currentFork() public returns (address) {
(bool success, bytes memory isActive) =
newFork.delegatecall(abi.encodeCall(IFork.isForkActive, ()));

require(success, NewForkInvalid());
return abi.decode(isActive, (bool)) ? newFork : oldFork;
}

function isForkRouter() public pure returns (bool) {
Expand Down
20 changes: 12 additions & 8 deletions packages/protocol/test/layer1/based/ForkRouter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ contract ForkFooA is EssentialContract, IFork {

function init() external initializer {
__Essential_init(address(0));
_state.a = 100;
_state.a = 1;
}

function setCounter(uint64 _a) external returns (uint64) {
Expand Down Expand Up @@ -77,7 +77,6 @@ contract ForkFooB is EssentialContract, IFork {
}

function isForkActive() external view override returns (bool) {
console.log("isForkActive in ForkFooB:", _state.b);
return _state.b >= 10;
}
}
Expand Down Expand Up @@ -137,12 +136,17 @@ contract TestForkRouter is Layer1Test {
});

assertEq(ForkRouter(payable(router)).currentFork(), fork1);
// assertEq(ForkFooA(router).counter(), 1);
// assertEq(ForkFooA(router).setCounter(2), 2);
// assertEq(ForkFooA(router).counter(), 2);
// assertEq(ForkRouter(payable(router)).currentFork(), fork1);
assertEq(ForkFooA(router).counter(), 1);
assertEq(ForkFooA(router).setCounter(2), 2);
assertEq(ForkFooA(router).counter(), 2);
assertEq(ForkRouter(payable(router)).currentFork(), fork1);

assertEq(ForkFooA(router).setCounter(10), 10);
assertEq(ForkRouter(payable(router)).currentFork(), fork2);
assertEq(ForkFooA(router).setCounter(11), 11);
assertEq(ForkRouter(payable(router)).currentFork(), fork2);

// assertEq(ForkFooA(router).setCounter(10), 10);
// assertEq(ForkRouter(payable(router)).currentFork(), fork2);
assertEq(ForkFooA(router).setCounter(9), 9);
assertEq(ForkRouter(payable(router)).currentFork(), fork1);
}
}

0 comments on commit 38b917f

Please sign in to comment.