From a51d0ad2de89b9757d158df95ddeba2bfcb23935 Mon Sep 17 00:00:00 2001 From: Fabian Jahr Date: Tue, 11 Aug 2020 00:01:53 +0200 Subject: [PATCH] rpc: Improve addnode remove command error message This also adds test coverage for the remove command which was uncovered before. --- src/rpc/net.cpp | 2 +- test/functional/rpc_net.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp index 9981ea35dff..7e9c78d2f2a 100644 --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -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_ADDED, "Error: Node could not be removed. It has not been added previously."); } return NullUniValue; diff --git a/test/functional/rpc_net.py b/test/functional/rpc_net.py index 3336246c8b4..674e034809a 100755 --- a/test/functional/rpc_net.py +++ b/test/functional/rpc_net.py @@ -131,6 +131,13 @@ class NetTest(BitcoinTestFramework): added_nodes = self.nodes[0].getaddednodeinfo(ip_port) assert_equal(len(added_nodes), 1) assert_equal(added_nodes[0]['addednode'], ip_port) + # check that node cannot 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(-24, "Node could not be removed", self.nodes[0].addnode, node=ip_port, command='remove') # 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')