Skip to content

Commit

Permalink
- adding test, too little SD Collateral based on validator count
Browse files Browse the repository at this point in the history
- amend maxKeyLimitReached is now MaxKeyLimitReached
  • Loading branch information
jac18281828 committed Jul 1, 2024
1 parent 1b0f058 commit 9a0fec2
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
2 changes: 1 addition & 1 deletion contracts/PermissionedNodeRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ contract PermissionedNodeRegistry is
totalKeys = getOperatorTotalKeys(_operatorId);
uint256 totalNonTerminalKeys = getOperatorTotalNonTerminalKeys(msg.sender, 0, totalKeys);
if ((totalNonTerminalKeys + keyCount) > maxNonTerminalKeyPerOperator) {
revert maxKeyLimitReached();
revert MaxKeyLimitReached();
}

//checks if operator has enough SD collateral for adding `keyCount` keys
Expand Down
2 changes: 1 addition & 1 deletion contracts/PermissionlessNodeRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ contract PermissionlessNodeRegistry is
totalKeys = getOperatorTotalKeys(_operatorId);
uint256 totalNonTerminalKeys = getOperatorTotalNonTerminalKeys(msg.sender, 0, totalKeys);
if ((totalNonTerminalKeys + keyCount) > maxNonTerminalKeyPerOperator) {
revert maxKeyLimitReached();
revert MaxKeyLimitReached();
}

// check for collateral ETH for adding keys
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/INodeRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ interface INodeRegistry {
// Errors
error DuplicatePoolIDOrPoolNotAdded();
error OperatorAlreadyOnBoardedInProtocol();
error maxKeyLimitReached();
error MaxKeyLimitReached();
error OperatorNotOnBoarded();
error InvalidKeyCount();
error InvalidStartAndEndIndex();
Expand Down
20 changes: 19 additions & 1 deletion test/foundry_tests/PermissionedNodeRegistry.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,24 @@ contract PermissionedNodeRegistryTest is Test {
assertEq(nodeRegistry.isExistingPubkey(pubkeys[0]), true);
}

function testAddValidatorKeysNotEnoughSDCollateral() public {
(
bytes[] memory pubkeys,
bytes[] memory preDepositSignature,
bytes[] memory depositSignature
) = getValidatorKeys();
vm.startPrank(permissionedNO);
nodeRegistry.onboardNodeOperator("testOP", payable(address(this)));
vm.mockCall(
address(sdCollateral),
abi.encodeWithSelector(ISDCollateral.hasEnoughSDCollateral.selector),
abi.encode(false)
);
vm.expectRevert(INodeRegistry.NotEnoughSDCollateral.selector);
nodeRegistry.addValidatorKeys(pubkeys, preDepositSignature, depositSignature);
vm.stopPrank();
}

function test_addValidatorKeysWithMisMatchingInputs() public {
bytes[] memory pubkeys = new bytes[](1);
bytes[] memory preDepositSignature = new bytes[](1);
Expand Down Expand Up @@ -263,7 +281,7 @@ contract PermissionedNodeRegistryTest is Test {
nodeRegistry.updateMaxNonTerminalKeyPerOperator(2);
vm.startPrank(permissionedNO);
nodeRegistry.onboardNodeOperator("testOP", payable(address(this)));
vm.expectRevert(INodeRegistry.maxKeyLimitReached.selector);
vm.expectRevert(INodeRegistry.MaxKeyLimitReached.selector);
nodeRegistry.addValidatorKeys(pubkeys, preDepositSignature, depositSignature);
vm.stopPrank();
}
Expand Down
20 changes: 19 additions & 1 deletion test/foundry_tests/PermissionlessNodeRegistry.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,24 @@ contract PermissionlessNodeRegistryTest is Test {
assertEq(nodeRegistry.isExistingPubkey(pubkeys[0]), true);
}

function testAddValidatorKeysNotEnoughSDCollateral() public {
(
bytes[] memory pubkeys,
bytes[] memory preDepositSignature,
bytes[] memory depositSignature
) = getValidatorKeys();
startHoax(address(this));
nodeRegistry.onboardNodeOperator(true, "testOP", payable(address(this)));
vm.mockCall(
address(sdCollateral),
abi.encodeWithSelector(ISDCollateral.hasEnoughSDCollateral.selector),
abi.encode(false)
);
vm.expectRevert(INodeRegistry.NotEnoughSDCollateral.selector);
nodeRegistry.addValidatorKeys{ value: 12 ether }(pubkeys, preDepositSignature, depositSignature);
vm.stopPrank();
}

function test_addValidatorKeysWithMisMatchingInputs() public {
bytes[] memory pubkeys = new bytes[](1);
bytes[] memory preDepositSignature = new bytes[](1);
Expand Down Expand Up @@ -290,7 +308,7 @@ contract PermissionlessNodeRegistryTest is Test {
nodeRegistry.updateMaxNonTerminalKeyPerOperator(2);
startHoax(address(this));
nodeRegistry.onboardNodeOperator(true, "testOP", payable(address(this)));
vm.expectRevert(INodeRegistry.maxKeyLimitReached.selector);
vm.expectRevert(INodeRegistry.MaxKeyLimitReached.selector);
nodeRegistry.addValidatorKeys{ value: 12 ether }(pubkeys, preDepositSignature, depositSignature);
vm.stopPrank();
}
Expand Down

0 comments on commit 9a0fec2

Please sign in to comment.