rpc, test: addnode improv + add test coverage for invalid command#26366
rpc, test: addnode improv + add test coverage for invalid command#26366achow101 merged 3 commits intobitcoin:masterfrom
addnode improv + add test coverage for invalid command#26366Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
getpeerinfo clean-ups + add test coverage for invalid commandgetpeerinfo improv + add test coverage for invalid command
theStack
left a comment
There was a problem hiding this comment.
Code-review ACK 40660d517022b30e3ab4dcf852a6c86502fa97f3
|
CI failure seems unrelated to these changes. |
Thanks, fixed in #27777 |
getpeerinfo improv + add test coverage for invalid commandaddnode improv + add test coverage for invalid command
40660d5 to
c2349d6
Compare
theStack
left a comment
There was a problem hiding this comment.
re-ACK c2349d6a04832d9c96a8746fc588bae8fc85376d
The only change since my last ACK was adapting the first commit's subject (s/getpeerinfo/addnode/). Sorry for late re-review, I must have missed the force-push two months ago.
1. Use const where possible; 2. Rename variables to make them clearer; 3. There is no need to check whether `command` is null since it's a non-optional field.
c2349d6 to
f52cb02
Compare
addnode improv + add test coverage for invalid commandaddnode improv + add test coverage for invalid command
|
Force-pushed addressing @jonatack's review. Addressed: |
| self.nodes[0].addnode(node=ip_port, command='remove') | ||
| assert_equal(self.nodes[0].getaddednodeinfo(), []) | ||
| # check that an invalid command returns an error | ||
| assert_raises_rpc_error(-1, 'addnode "node" "command"', self.nodes[0].addnode, node=ip_port, command='abc') |
There was a problem hiding this comment.
"remove the check for nullance for command since it's a non-optional field"
while here, maybe test that assertion
- # check that an invalid command returns an error
+ # check that an invalid or missing command returns an error
assert_raises_rpc_error(-1, 'addnode "node" "command"', self.nodes[0].addnode, node=ip_port, command='abc')
+ assert_raises_rpc_error(-1, 'addnode "node" "command"', self.nodes[0].addnode, node=ip_port)| if (!connman.RemoveAddedNode(strNode)) { | ||
| if (!connman.RemoveAddedNode(node_arg)) { | ||
| throw JSONRPCError(RPC_CLIENT_NODE_NOT_ADDED, "Error: Node could not be removed. It has not been added previously."); | ||
| } |
There was a problem hiding this comment.
suggestion while touching this
- if (command == "onetry")
- {
+ if (command == "onetry") {
CAddress addr;
connman.OpenNetworkConnection(addr, /*fCountFailure=*/false, /*grantOutbound=*/nullptr, node_arg.c_str(), ConnectionType::MANUAL);
return UniValue::VNULL;
- }
-
- if (command == "add")
- {
+ } elsif (command == "add") {
if (!connman.AddNode(node_arg)) {
throw JSONRPCError(RPC_CLIENT_NODE_ALREADY_ADDED, "Error: Node already added");
}
- }
- else if (command == "remove")
- {
+ } else if (command == "remove") {
if (!connman.RemoveAddedNode(node_arg)) {
throw JSONRPCError(RPC_CLIENT_NODE_NOT_ADDED, "Error: Node could not be removed. It has not been added previously.");
}|
ACK f52cb02 |
…for invalid command f52cb02 doc: make it clear that `node` in `addnode` refers to the node's address (brunoerg) effd1ef test: `addnode` with an invalid command should throw an error (brunoerg) 56b27b8 rpc, refactor: clean-up `addnode` (brunoerg) Pull request description: This PR: - Adds test coverage for an invalid `command` in `addnode`. - Rename `test_getaddednodeinfo` to `test_addnode_getaddednodeinfo` and its log since this function also tests `addnode` and it doesn't worth to split into 2 ones. - Makes it clear in docs that `node` in `addnode` refers to the node's address. It seemed a little weird for me "The node (see getpeerinfo for nodes)", it could mean a lot of things e.g. the node id. - Some small improv/clean-up: use `const` where possible, rename some vars, and remove the check for nullance for `command` since it's a non-optional field. ACKs for top commit: achow101: ACK f52cb02 jonatack: ACK f52cb02 theStack: re-ACK f52cb02 Tree-SHA512: e4a69e58b784e233463945b4d55a401957f9fe4562c129f59216a44f44fb3221d3449ac578fb35e665ca654c6ade2e741b72c3df78040f7527229c77b6c5b82e
…for invalid command f52cb02 doc: make it clear that `node` in `addnode` refers to the node's address (brunoerg) effd1ef test: `addnode` with an invalid command should throw an error (brunoerg) 56b27b8 rpc, refactor: clean-up `addnode` (brunoerg) Pull request description: This PR: - Adds test coverage for an invalid `command` in `addnode`. - Rename `test_getaddednodeinfo` to `test_addnode_getaddednodeinfo` and its log since this function also tests `addnode` and it doesn't worth to split into 2 ones. - Makes it clear in docs that `node` in `addnode` refers to the node's address. It seemed a little weird for me "The node (see getpeerinfo for nodes)", it could mean a lot of things e.g. the node id. - Some small improv/clean-up: use `const` where possible, rename some vars, and remove the check for nullance for `command` since it's a non-optional field. ACKs for top commit: achow101: ACK f52cb02 jonatack: ACK f52cb02 theStack: re-ACK f52cb02 Tree-SHA512: e4a69e58b784e233463945b4d55a401957f9fe4562c129f59216a44f44fb3221d3449ac578fb35e665ca654c6ade2e741b72c3df78040f7527229c77b6c5b82e
This PR:
commandinaddnode.test_getaddednodeinfototest_addnode_getaddednodeinfoand its log since this function also testsaddnodeand it doesn't worth to split into 2 ones.nodeinaddnoderefers to the node's address. It seemed a little weird for me "The node (see getpeerinfo for nodes)", it could mean a lot of things e.g. the node id.constwhere possible, rename some vars, and remove the check for nullance forcommandsince it's a non-optional field.