From e4082e5f6fc4f82da1985df2b009d2d8bc03830c Mon Sep 17 00:00:00 2001 From: Matjaz Verbole Date: Thu, 21 Mar 2024 11:50:01 +0100 Subject: [PATCH] Validation for arguments in `initialize` function inside `L2Claim` (#66) Arguments validation for initialize function inside L2Claim was added --- src/L2/L2Claim.sol | 4 ++++ test/L2/L2Claim.t.sol | 30 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/L2/L2Claim.sol b/src/L2/L2Claim.sol index 042f244e..a375fd9b 100644 --- a/src/L2/L2Claim.sol +++ b/src/L2/L2Claim.sol @@ -74,6 +74,10 @@ contract L2Claim is Initializable, Ownable2StepUpgradeable, UUPSUpgradeable, ISe public initializer { + require(_l2LiskToken != address(0), "L2Claim: L2 Lisk Token address cannot be zero"); + require(_merkleRoot != bytes32(0), "L2Claim: Merkle Root cannot be zero"); + require(_recoverPeriodTimestamp >= block.timestamp, "L2Claim: recover period must be in the future"); + __Ownable2Step_init(); __Ownable_init(msg.sender); l2LiskToken = IERC20(_l2LiskToken); diff --git a/test/L2/L2Claim.t.sol b/test/L2/L2Claim.t.sol index 835eea21..d366ac6d 100644 --- a/test/L2/L2Claim.t.sol +++ b/test/L2/L2Claim.t.sol @@ -152,6 +152,36 @@ contract L2ClaimTest is Test { lsk.transfer(address(l2Claim), lsk.balanceOf(address(this))); } + function test_Initialize_RevertWhenL2LiskTokenIsZero() public { + l2Claim = L2Claim(address(new ERC1967Proxy(address(l2ClaimImplementation), ""))); + Utils.MerkleRoot memory merkleRoot = getMerkleRoot(); + + vm.expectRevert("L2Claim: L2 Lisk Token address cannot be zero"); + l2Claim.initialize(address(0), merkleRoot.merkleRoot, block.timestamp + RECOVER_PERIOD); + } + + function test_Initialize_RevertWhenMerkleRootIsZero() public { + l2Claim = L2Claim(address(new ERC1967Proxy(address(l2ClaimImplementation), ""))); + + vm.expectRevert("L2Claim: Merkle Root cannot be zero"); + l2Claim.initialize(address(lsk), bytes32(0), block.timestamp + RECOVER_PERIOD); + } + + function test_Initialize_RevertWhenRecoveredPeriodIsNotInFuture() public { + l2Claim = L2Claim(address(new ERC1967Proxy(address(l2ClaimImplementation), ""))); + Utils.MerkleRoot memory merkleRoot = getMerkleRoot(); + + // recover period is now, hence it should still pass + l2Claim.initialize(address(lsk), merkleRoot.merkleRoot, block.timestamp); + assertEq(l2Claim.recoverPeriodTimestamp(), block.timestamp); + + l2Claim = L2Claim(address(new ERC1967Proxy(address(l2ClaimImplementation), ""))); + + // recover period is in the past, hence it should revert + vm.expectRevert("L2Claim: recover period must be in the future"); + l2Claim.initialize(address(lsk), merkleRoot.merkleRoot, block.timestamp - 1); + } + function test_Initialize_RevertWhenCalledAtImplementationContract() public { vm.expectRevert(); l2ClaimImplementation.initialize(address(lsk), bytes32(0), block.timestamp + RECOVER_PERIOD);