Skip to content

Commit

Permalink
rpc: Fix addnode remove command error
Browse files Browse the repository at this point in the history
This also adds test coverage for the remove command which was uncovered before.
  • Loading branch information
fjahr committed Aug 10, 2020
1 parent f306384 commit 9795d93
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/rpc/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ static UniValue addnode(const JSONRPCRequest& request)
else if(strCommand == "remove")
{
if(!node.connman->RemoveAddedNode(strNode))
throw JSONRPCError(RPC_CLIENT_NODE_NOT_ADDED, "Error: Node has not been added.");
throw JSONRPCError(RPC_CLIENT_NODE_NOT_REMOVED, "Error: Node could not be removed.");
}

return NullUniValue;
Expand Down
1 change: 1 addition & 0 deletions src/rpc/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ enum RPCErrorCode
RPC_CLIENT_IN_INITIAL_DOWNLOAD = -10, //!< Still downloading initial blocks
RPC_CLIENT_NODE_ALREADY_ADDED = -23, //!< Node is already added
RPC_CLIENT_NODE_NOT_ADDED = -24, //!< Node has not been added before
RPC_CLIENT_NODE_NOT_REMOVED = -25, //!< Node could not be removed from added nodes
RPC_CLIENT_NODE_NOT_CONNECTED = -29, //!< Node to disconnect not found in connected nodes
RPC_CLIENT_INVALID_IP_OR_SUBNET = -30, //!< Invalid IP/Subnet
RPC_CLIENT_P2P_DISABLED = -31, //!< No valid connection manager instance found
Expand Down
7 changes: 7 additions & 0 deletions test/functional/rpc_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ def _test_getaddednodeinfo(self):
assert_equal(added_nodes[0]['addednode'], ip_port)
# check that a non-existent node returns an error
assert_raises_rpc_error(-24, "Node has not been added", self.nodes[0].getaddednodeinfo, '1.1.1.1')
# check that node can not be added again
assert_raises_rpc_error(-23, "Node already added", self.nodes[0].addnode, node=ip_port, command='add')
# check that node can be removed
self.nodes[0].addnode(node=ip_port, command='remove')
assert_equal(self.nodes[0].getaddednodeinfo(), [])
# check that trying to remove the node again returns an error
assert_raises_rpc_error(-25, "Node could not be removed", self.nodes[0].addnode, node=ip_port, command='remove')

def _test_getpeerinfo(self):
peer_info = [x.getpeerinfo() for x in self.nodes]
Expand Down

0 comments on commit 9795d93

Please sign in to comment.