Skip to content

Commit a51d0ad

Browse files
committed
rpc: Improve addnode remove command error message
This also adds test coverage for the remove command which was uncovered before.
1 parent f306384 commit a51d0ad

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/rpc/net.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ static UniValue addnode(const JSONRPCRequest& request)
276276
else if(strCommand == "remove")
277277
{
278278
if(!node.connman->RemoveAddedNode(strNode))
279-
throw JSONRPCError(RPC_CLIENT_NODE_NOT_ADDED, "Error: Node has not been added.");
279+
throw JSONRPCError(RPC_CLIENT_NODE_NOT_ADDED, "Error: Node could not be removed. It has not been added previously.");
280280
}
281281

282282
return NullUniValue;

test/functional/rpc_net.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,13 @@ def _test_getaddednodeinfo(self):
131131
added_nodes = self.nodes[0].getaddednodeinfo(ip_port)
132132
assert_equal(len(added_nodes), 1)
133133
assert_equal(added_nodes[0]['addednode'], ip_port)
134+
# check that node cannot be added again
135+
assert_raises_rpc_error(-23, "Node already added", self.nodes[0].addnode, node=ip_port, command='add')
136+
# check that node can be removed
137+
self.nodes[0].addnode(node=ip_port, command='remove')
138+
assert_equal(self.nodes[0].getaddednodeinfo(), [])
139+
# check that trying to remove the node again returns an error
140+
assert_raises_rpc_error(-24, "Node could not be removed", self.nodes[0].addnode, node=ip_port, command='remove')
134141
# check that a non-existent node returns an error
135142
assert_raises_rpc_error(-24, "Node has not been added", self.nodes[0].getaddednodeinfo, '1.1.1.1')
136143

0 commit comments

Comments
 (0)