From 9a0fec2561694048920b7b34551337c5454d775c Mon Sep 17 00:00:00 2001 From: John Cairns Date: Thu, 27 Jun 2024 19:18:57 -0500 Subject: [PATCH] - adding test, too little SD Collateral based on validator count - amend maxKeyLimitReached is now MaxKeyLimitReached --- contracts/PermissionedNodeRegistry.sol | 2 +- contracts/PermissionlessNodeRegistry.sol | 2 +- contracts/interfaces/INodeRegistry.sol | 2 +- .../PermissionedNodeRegistry.t.sol | 20 ++++++++++++++++++- .../PermissionlessNodeRegistry.t.sol | 20 ++++++++++++++++++- 5 files changed, 41 insertions(+), 5 deletions(-) diff --git a/contracts/PermissionedNodeRegistry.sol b/contracts/PermissionedNodeRegistry.sol index 6d82e482..5b2f9b56 100644 --- a/contracts/PermissionedNodeRegistry.sol +++ b/contracts/PermissionedNodeRegistry.sol @@ -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 diff --git a/contracts/PermissionlessNodeRegistry.sol b/contracts/PermissionlessNodeRegistry.sol index 1565929e..e1605eea 100644 --- a/contracts/PermissionlessNodeRegistry.sol +++ b/contracts/PermissionlessNodeRegistry.sol @@ -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 diff --git a/contracts/interfaces/INodeRegistry.sol b/contracts/interfaces/INodeRegistry.sol index 639240ff..aea512ad 100644 --- a/contracts/interfaces/INodeRegistry.sol +++ b/contracts/interfaces/INodeRegistry.sol @@ -27,7 +27,7 @@ interface INodeRegistry { // Errors error DuplicatePoolIDOrPoolNotAdded(); error OperatorAlreadyOnBoardedInProtocol(); - error maxKeyLimitReached(); + error MaxKeyLimitReached(); error OperatorNotOnBoarded(); error InvalidKeyCount(); error InvalidStartAndEndIndex(); diff --git a/test/foundry_tests/PermissionedNodeRegistry.t.sol b/test/foundry_tests/PermissionedNodeRegistry.t.sol index c564c174..a0da00f0 100644 --- a/test/foundry_tests/PermissionedNodeRegistry.t.sol +++ b/test/foundry_tests/PermissionedNodeRegistry.t.sol @@ -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); @@ -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(); } diff --git a/test/foundry_tests/PermissionlessNodeRegistry.t.sol b/test/foundry_tests/PermissionlessNodeRegistry.t.sol index cb0aa869..3ba936e1 100644 --- a/test/foundry_tests/PermissionlessNodeRegistry.t.sol +++ b/test/foundry_tests/PermissionlessNodeRegistry.t.sol @@ -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); @@ -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(); }