Skip to content

Commit

Permalink
Validation for arguments in initialize function inside L2Claim (#66)
Browse files Browse the repository at this point in the history
Arguments validation for initialize function inside L2Claim was added
  • Loading branch information
matjazv committed Mar 21, 2024
1 parent ea850a5 commit e4082e5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/L2/L2Claim.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
30 changes: 30 additions & 0 deletions test/L2/L2Claim.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit e4082e5

Please sign in to comment.