Skip to content

Commit

Permalink
Add function to remove operators in Capability Registry (#12979)
Browse files Browse the repository at this point in the history
* update remove operators function

* address PR feedback
  • Loading branch information
cds95 authored Apr 26, 2024
1 parent 1d9dd46 commit 0c4c24a
Show file tree
Hide file tree
Showing 6 changed files with 216 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/smooth-comics-love.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": patch
---

update keystone gethwrapper with remove operator function #internal
5 changes: 5 additions & 0 deletions contracts/.changeset/hot-weeks-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@chainlink/contracts": patch
---

add function to remove node operators from capability registry
14 changes: 14 additions & 0 deletions contracts/src/v0.8/keystone/CapabilityRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ contract CapabilityRegistry is OwnerIsCreator, TypeAndVersionInterface {
/// @param name The human readable name of the node operator
event NodeOperatorAdded(uint256 nodeOperatorId, address indexed admin, string name);

/// @notice This event is emitted when a node operator is removed
/// @param nodeOperatorId The ID of the node operator that was removed
event NodeOperatorRemoved(uint256 nodeOperatorId);

/// @notice This event is emitted when a new capability is added
/// @param capabilityId The ID of the newly added capability
event CapabilityAdded(bytes32 indexed capabilityId);
Expand Down Expand Up @@ -64,6 +68,16 @@ contract CapabilityRegistry is OwnerIsCreator, TypeAndVersionInterface {
}
}

/// @notice Removes a node operator
/// @param nodeOperatorIds The IDs of the node operators to remove
function removeNodeOperators(uint256[] calldata nodeOperatorIds) external onlyOwner {
for (uint256 i; i < nodeOperatorIds.length; ++i) {
uint256 nodeOperatorId = nodeOperatorIds[i];
delete s_nodeOperators[nodeOperatorId];
emit NodeOperatorRemoved(nodeOperatorId);
}
}

/// @notice Gets a node operator's data
/// @param nodeOperatorId The ID of the node operator to query for
/// @return NodeOperator The node operator data
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import {BaseTest} from "./BaseTest.t.sol";
import {CapabilityRegistry} from "../CapabilityRegistry.sol";

contract CapabilityRegistry_RemoveNodeOperatorsTest is BaseTest {
event NodeOperatorRemoved(uint256 nodeOperatorId);

uint256 private constant TEST_NODE_OPERATOR_ONE_ID = 0;
uint256 private constant TEST_NODE_OPERATOR_TWO_ID = 1;

function setUp() public override {
BaseTest.setUp();
changePrank(ADMIN);
s_capabilityRegistry.addNodeOperators(_getNodeOperators());
}

function test_RevertWhen_CalledByNonOwner() public {
changePrank(STRANGER);
vm.expectRevert("Only callable by owner");
uint256[] memory nodeOperatorsToRemove = new uint256[](2);
nodeOperatorsToRemove[1] = 1;
s_capabilityRegistry.removeNodeOperators(nodeOperatorsToRemove);
}

function test_RemovesNodeOperator() public {
changePrank(ADMIN);

vm.expectEmit(true, true, true, true, address(s_capabilityRegistry));
emit NodeOperatorRemoved(TEST_NODE_OPERATOR_ONE_ID);
vm.expectEmit(true, true, true, true, address(s_capabilityRegistry));
emit NodeOperatorRemoved(TEST_NODE_OPERATOR_TWO_ID);
uint256[] memory nodeOperatorsToRemove = new uint256[](2);
nodeOperatorsToRemove[1] = 1;
s_capabilityRegistry.removeNodeOperators(nodeOperatorsToRemove);

CapabilityRegistry.NodeOperator memory nodeOperatorOne = s_capabilityRegistry.getNodeOperator(0);
assertEq(nodeOperatorOne.admin, address(0));
assertEq(nodeOperatorOne.name, "");

CapabilityRegistry.NodeOperator memory nodeOperatorTwo = s_capabilityRegistry.getNodeOperator(1);
assertEq(nodeOperatorTwo.admin, address(0));
assertEq(nodeOperatorTwo.name, "");
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
GETH_VERSION: 1.13.8
forwarder: ../../../contracts/solc/v0.8.19/KeystoneForwarder/KeystoneForwarder.abi ../../../contracts/solc/v0.8.19/KeystoneForwarder/KeystoneForwarder.bin b4c900aae9e022f01abbac7993d41f93912247613ac6270b0c4da4ef6f2016e3
keystone_capability_registry: ../../../contracts/solc/v0.8.19/CapabilityRegistry/CapabilityRegistry.abi ../../../contracts/solc/v0.8.19/CapabilityRegistry/CapabilityRegistry.bin 579334dfcb59da4221823735dc815116745b488ddde327199367e04457aac808
keystone_capability_registry: ../../../contracts/solc/v0.8.19/CapabilityRegistry/CapabilityRegistry.abi ../../../contracts/solc/v0.8.19/CapabilityRegistry/CapabilityRegistry.bin 9eaa36e45c1b33c1fa72b7e25d6d1ca351413225611abb84ae053270b569cca4
ocr3_capability: ../../../contracts/solc/v0.8.19/OCR3Capability/OCR3Capability.abi ../../../contracts/solc/v0.8.19/OCR3Capability/OCR3Capability.bin 9dcbdf55bd5729ba266148da3f17733eb592c871c2108ccca546618628fd9ad2

0 comments on commit 0c4c24a

Please sign in to comment.