rpc: Improve addnode remove command error message
This also adds test coverage for the remove command which was uncovered before.
This commit is contained in:
parent
f306384f5a
commit
a51d0ad2de
2 changed files with 8 additions and 1 deletions
|
@ -276,7 +276,7 @@ static UniValue addnode(const JSONRPCRequest& request)
|
||||||
else if(strCommand == "remove")
|
else if(strCommand == "remove")
|
||||||
{
|
{
|
||||||
if(!node.connman->RemoveAddedNode(strNode))
|
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;
|
return NullUniValue;
|
||||||
|
|
|
@ -131,6 +131,13 @@ class NetTest(BitcoinTestFramework):
|
||||||
added_nodes = self.nodes[0].getaddednodeinfo(ip_port)
|
added_nodes = self.nodes[0].getaddednodeinfo(ip_port)
|
||||||
assert_equal(len(added_nodes), 1)
|
assert_equal(len(added_nodes), 1)
|
||||||
assert_equal(added_nodes[0]['addednode'], ip_port)
|
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
|
# 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')
|
assert_raises_rpc_error(-24, "Node has not been added", self.nodes[0].getaddednodeinfo, '1.1.1.1')
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue