diff options
author | Fabian Jahr <fjahr@protonmail.com> | 2020-08-11 00:01:53 +0200 |
---|---|---|
committer | Fabian Jahr <fjahr@protonmail.com> | 2020-08-11 14:04:02 +0200 |
commit | a51d0ad2de89b9757d158df95ddeba2bfcb23935 (patch) | |
tree | c7dde24190e668e26b2e86cd88ca4d8f251e18d1 | |
parent | f306384f5a9006307eec7ace9fc8433aa1a8ed84 (diff) |
rpc: Improve addnode remove command error message
This also adds test coverage for the remove command which was uncovered before.
-rw-r--r-- | src/rpc/net.cpp | 2 | ||||
-rwxr-xr-x | test/functional/rpc_net.py | 7 |
2 files changed, 8 insertions, 1 deletions
diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp index 9981ea35df..7e9c78d2f2 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 3336246c8b..674e034809 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') |