Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- adding test, too little SD Collateral based on validator count #245

Merged
merged 1 commit into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contracts/PermissionedNodeRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import { ISDCollateral } from "./interfaces/SDCollateral/ISDCollateral.sol";
import { IPermissionedNodeRegistry } from "./interfaces/IPermissionedNodeRegistry.sol";

contract PermissionedNodeRegistry is

Check warning on line 21 in contracts/PermissionedNodeRegistry.sol

View workflow job for this annotation

GitHub Actions / Run linters

Contract has 19 states declarations but allowed no more than 15

Check warning on line 21 in contracts/PermissionedNodeRegistry.sol

View workflow job for this annotation

GitHub Actions / Run linters

Contract has 19 states declarations but allowed no more than 15
INodeRegistry,
IPermissionedNodeRegistry,
AccessControlUpgradeable,
Expand Down Expand Up @@ -624,7 +624,7 @@
}
}
// If the result array isn't full, resize it to remove the unused elements
assembly {

Check warning on line 627 in contracts/PermissionedNodeRegistry.sol

View workflow job for this annotation

GitHub Actions / Run linters

Avoid to use inline assembly. It is acceptable only in rare cases

Check warning on line 627 in contracts/PermissionedNodeRegistry.sol

View workflow job for this annotation

GitHub Actions / Run linters

Avoid to use inline assembly. It is acceptable only in rare cases
mstore(validators, validatorCount)
}

Expand Down Expand Up @@ -722,7 +722,7 @@
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 @@ -21,7 +21,7 @@
import { IPermissionlessNodeRegistry } from "./interfaces/IPermissionlessNodeRegistry.sol";
import { IOperatorRewardsCollector } from "./interfaces/IOperatorRewardsCollector.sol";

contract PermissionlessNodeRegistry is

Check warning on line 24 in contracts/PermissionlessNodeRegistry.sol

View workflow job for this annotation

GitHub Actions / Run linters

Contract has 18 states declarations but allowed no more than 15

Check warning on line 24 in contracts/PermissionlessNodeRegistry.sol

View workflow job for this annotation

GitHub Actions / Run linters

Contract has 18 states declarations but allowed no more than 15
INodeRegistry,
IPermissionlessNodeRegistry,
AccessControlUpgradeable,
Expand Down Expand Up @@ -555,7 +555,7 @@
}
}
// If the result array isn't full, resize it to remove the unused elements
assembly {

Check warning on line 558 in contracts/PermissionlessNodeRegistry.sol

View workflow job for this annotation

GitHub Actions / Run linters

Avoid to use inline assembly. It is acceptable only in rare cases

Check warning on line 558 in contracts/PermissionlessNodeRegistry.sol

View workflow job for this annotation

GitHub Actions / Run linters

Avoid to use inline assembly. It is acceptable only in rare cases
mstore(validators, validatorCount)
}

Expand Down Expand Up @@ -687,7 +687,7 @@
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
Loading