-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement addNodes and getNode (#13022)
* implement add node * Fix the test * Use p2pId for node identification. * Revert if node exists * supportedCapabilityIds string[] => bytes32[] * Revert when adding node without capabilities * Verify that supported capabilities exist in the registry * Create a variable for a non-existent capability. * Undo a change * Add p2pId to the event * Remove redundant comment * Regen wrappers * Switch to using bytes32 instead of bytes for p2pId * Add a comment about allowing deprecated capabilities * Add signer address to Node * Move checks around * Regen wrappers --------- Co-authored-by: DeividasK <[email protected]>
- Loading branch information
Showing
9 changed files
with
411 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"chainlink": patch | ||
--- | ||
|
||
#internal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@chainlink/contracts": patch | ||
--- | ||
|
||
#internal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
contracts/src/v0.8/keystone/test/CapabilityRegistry_AddNodesTest.t.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.19; | ||
|
||
import {BaseTest} from "./BaseTest.t.sol"; | ||
import {CapabilityRegistry} from "../CapabilityRegistry.sol"; | ||
|
||
contract CapabilityRegistry_AddNodesTest is BaseTest { | ||
event NodeAdded(bytes32 p2pId, 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()); | ||
s_capabilityRegistry.addCapability(s_basicCapability); | ||
s_capabilityRegistry.addCapability(s_capabilityWithConfigurationContract); | ||
} | ||
|
||
function test_RevertWhen_CalledByNonNodeOperatorAdmin() public { | ||
changePrank(STRANGER); | ||
CapabilityRegistry.Node[] memory nodes = new CapabilityRegistry.Node[](1); | ||
|
||
bytes32[] memory capabilityIds = new bytes32[](1); | ||
capabilityIds[0] = s_basicCapabilityId; | ||
|
||
nodes[0] = CapabilityRegistry.Node({ | ||
nodeOperatorId: TEST_NODE_OPERATOR_ONE_ID, | ||
p2pId: P2P_ID, | ||
signer: NODE_OPERATOR_ONE_SIGNER_ADDRESS, | ||
supportedCapabilityIds: capabilityIds | ||
}); | ||
|
||
vm.expectRevert(CapabilityRegistry.AccessForbidden.selector); | ||
s_capabilityRegistry.addNodes(nodes); | ||
} | ||
|
||
function test_RevertWhen_AddingDuplicateP2PId() public { | ||
changePrank(NODE_OPERATOR_ONE_ADMIN); | ||
CapabilityRegistry.Node[] memory nodes = new CapabilityRegistry.Node[](1); | ||
|
||
bytes32[] memory capabilityIds = new bytes32[](1); | ||
capabilityIds[0] = s_basicCapabilityId; | ||
|
||
nodes[0] = CapabilityRegistry.Node({ | ||
nodeOperatorId: TEST_NODE_OPERATOR_ONE_ID, | ||
p2pId: P2P_ID, | ||
signer: NODE_OPERATOR_ONE_SIGNER_ADDRESS, | ||
supportedCapabilityIds: capabilityIds | ||
}); | ||
s_capabilityRegistry.addNodes(nodes); | ||
|
||
vm.expectRevert(abi.encodeWithSelector(CapabilityRegistry.InvalidNodeP2PId.selector, P2P_ID)); | ||
s_capabilityRegistry.addNodes(nodes); | ||
} | ||
|
||
function test_RevertWhen_P2PIDEmpty() public { | ||
changePrank(NODE_OPERATOR_ONE_ADMIN); | ||
CapabilityRegistry.Node[] memory nodes = new CapabilityRegistry.Node[](1); | ||
|
||
bytes32[] memory capabilityIds = new bytes32[](1); | ||
capabilityIds[0] = s_basicCapabilityId; | ||
|
||
nodes[0] = CapabilityRegistry.Node({ | ||
nodeOperatorId: TEST_NODE_OPERATOR_ONE_ID, | ||
p2pId: bytes32(""), | ||
signer: NODE_OPERATOR_ONE_SIGNER_ADDRESS, | ||
supportedCapabilityIds: capabilityIds | ||
}); | ||
|
||
vm.expectRevert(abi.encodeWithSelector(CapabilityRegistry.InvalidNodeP2PId.selector, bytes32(""))); | ||
s_capabilityRegistry.addNodes(nodes); | ||
} | ||
|
||
function test_RevertWhen_AddingNodeWithoutCapabilities() public { | ||
changePrank(NODE_OPERATOR_ONE_ADMIN); | ||
CapabilityRegistry.Node[] memory nodes = new CapabilityRegistry.Node[](1); | ||
|
||
bytes32[] memory capabilityIds = new bytes32[](0); | ||
|
||
nodes[0] = CapabilityRegistry.Node({ | ||
nodeOperatorId: TEST_NODE_OPERATOR_ONE_ID, | ||
p2pId: P2P_ID, | ||
signer: NODE_OPERATOR_ONE_SIGNER_ADDRESS, | ||
supportedCapabilityIds: capabilityIds | ||
}); | ||
vm.expectRevert(abi.encodeWithSelector(CapabilityRegistry.InvalidNodeCapabilities.selector, capabilityIds)); | ||
s_capabilityRegistry.addNodes(nodes); | ||
} | ||
|
||
function test_RevertWhen_AddingNodeWithInvalidCapability() public { | ||
changePrank(NODE_OPERATOR_ONE_ADMIN); | ||
CapabilityRegistry.Node[] memory nodes = new CapabilityRegistry.Node[](1); | ||
|
||
bytes32[] memory capabilityIds = new bytes32[](1); | ||
capabilityIds[0] = s_nonExistentCapabilityId; | ||
|
||
nodes[0] = CapabilityRegistry.Node({ | ||
nodeOperatorId: TEST_NODE_OPERATOR_ONE_ID, | ||
p2pId: P2P_ID, | ||
signer: NODE_OPERATOR_ONE_SIGNER_ADDRESS, | ||
supportedCapabilityIds: capabilityIds | ||
}); | ||
|
||
vm.expectRevert(abi.encodeWithSelector(CapabilityRegistry.InvalidNodeCapabilities.selector, capabilityIds)); | ||
s_capabilityRegistry.addNodes(nodes); | ||
} | ||
|
||
function test_AddsNode() public { | ||
changePrank(NODE_OPERATOR_ONE_ADMIN); | ||
|
||
CapabilityRegistry.Node[] memory nodes = new CapabilityRegistry.Node[](1); | ||
bytes32[] memory capabilityIds = new bytes32[](2); | ||
capabilityIds[0] = s_basicCapabilityId; | ||
capabilityIds[1] = s_capabilityWithConfigurationContractId; | ||
|
||
nodes[0] = CapabilityRegistry.Node({ | ||
nodeOperatorId: TEST_NODE_OPERATOR_ONE_ID, | ||
p2pId: P2P_ID, | ||
signer: NODE_OPERATOR_ONE_SIGNER_ADDRESS, | ||
supportedCapabilityIds: capabilityIds | ||
}); | ||
|
||
vm.expectEmit(address(s_capabilityRegistry)); | ||
emit NodeAdded(P2P_ID, TEST_NODE_OPERATOR_ONE_ID); | ||
s_capabilityRegistry.addNodes(nodes); | ||
|
||
CapabilityRegistry.Node memory node = s_capabilityRegistry.getNode(P2P_ID); | ||
assertEq(node.nodeOperatorId, TEST_NODE_OPERATOR_ONE_ID); | ||
assertEq(node.p2pId, P2P_ID); | ||
assertEq(node.supportedCapabilityIds.length, 2); | ||
assertEq(node.supportedCapabilityIds[0], s_basicCapabilityId); | ||
assertEq(node.supportedCapabilityIds[1], s_capabilityWithConfigurationContractId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
179 changes: 177 additions & 2 deletions
179
...hwrappers/keystone/generated/keystone_capability_registry/keystone_capability_registry.go
Large diffs are not rendered by default.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
core/gethwrappers/keystone/generation/generated-wrapper-dependency-versions-do-not-edit.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 28fb0e1c437b97271d999f3b028f7bd44558352ec83f89501aabf501fcc915f1 | ||
keystone_capability_registry: ../../../contracts/solc/v0.8.19/CapabilityRegistry/CapabilityRegistry.abi ../../../contracts/solc/v0.8.19/CapabilityRegistry/CapabilityRegistry.bin b7d748b585d7cf1cf91e268b609613f77a8390d119e03d724b49c25fd2ea75e7 | ||
ocr3_capability: ../../../contracts/solc/v0.8.19/OCR3Capability/OCR3Capability.abi ../../../contracts/solc/v0.8.19/OCR3Capability/OCR3Capability.bin 9dcbdf55bd5729ba266148da3f17733eb592c871c2108ccca546618628fd9ad2 |