Skip to content

Commit 6afc707

Browse files
committed
Merge bitcoin/bitcoin#30339: test: add coverage for node field of getaddednodeinfo RPC
e38eadb test: change comments to `self.log.info` for `test_addnode_getaddednodeinfo` (brunoerg) c838e3b test: add coverage for `node` field of `getaddednodeinfo` RPC (brunoerg) Pull request description: We currently do not test a successful call to `getaddednodeinfo` filtering by `node`, we only test it with an unknown address and checks whether it fails. This PR adds coverage to it. ACKs for top commit: kevkevinpal: ACK [e38eadb](https://github.com/bitcoin/bitcoin/pull/30339/commits/e38eadb2c2d93d2ee3c9accb649b2de144b3732e)[e38eadb](https://github.com/bitcoin/bitcoin/pull/30339/commits/e38eadb2c2d93d2ee3c9accb649b2de144b3732e) achow101: ACK e38eadb tdb3: re ACK e38eadb BrandonOdiwuor: Code Review ACK e38eadb rkrux: tACK [e38eadb](bitcoin/bitcoin@e38eadb) Tree-SHA512: e9f768b7aa86e58b0b0ced089ead57040ff9a5204493da1ab99c8bc897b6dcdce7c856855f74c52010fceef19af1e12a39eee9f8f2e7294b42476b6f980fe754
2 parents d2c8d16 + e38eadb commit 6afc707

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

test/functional/rpc_net.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -237,28 +237,35 @@ def test_getnetworkinfo(self):
237237
def test_addnode_getaddednodeinfo(self):
238238
self.log.info("Test addnode and getaddednodeinfo")
239239
assert_equal(self.nodes[0].getaddednodeinfo(), [])
240-
# add a node (node2) to node0
240+
self.log.info("Add a node (node2) to node0")
241241
ip_port = "127.0.0.1:{}".format(p2p_port(2))
242242
self.nodes[0].addnode(node=ip_port, command='add')
243-
# try to add an equivalent ip
244-
# (note that OpenBSD doesn't support the IPv4 shorthand notation with omitted zero-bytes)
243+
self.log.info("Try to add an equivalent ip and check it fails")
244+
self.log.debug("(note that OpenBSD doesn't support the IPv4 shorthand notation with omitted zero-bytes)")
245245
if platform.system() != "OpenBSD":
246246
ip_port2 = "127.1:{}".format(p2p_port(2))
247247
assert_raises_rpc_error(-23, "Node already added", self.nodes[0].addnode, node=ip_port2, command='add')
248-
# check that the node has indeed been added
248+
self.log.info("Check that the node has indeed been added")
249249
added_nodes = self.nodes[0].getaddednodeinfo()
250250
assert_equal(len(added_nodes), 1)
251251
assert_equal(added_nodes[0]['addednode'], ip_port)
252-
# check that node cannot be added again
252+
self.log.info("Check that filtering by node works")
253+
self.nodes[0].addnode(node="11.22.33.44", command='add')
254+
first_added_node = self.nodes[0].getaddednodeinfo(node=ip_port)
255+
assert_equal(added_nodes, first_added_node)
256+
assert_equal(len(self.nodes[0].getaddednodeinfo()), 2)
257+
self.log.info("Check that node cannot be added again")
253258
assert_raises_rpc_error(-23, "Node already added", self.nodes[0].addnode, node=ip_port, command='add')
254-
# check that node can be removed
259+
self.log.info("Check that node can be removed")
255260
self.nodes[0].addnode(node=ip_port, command='remove')
256-
assert_equal(self.nodes[0].getaddednodeinfo(), [])
257-
# check that an invalid command returns an error
261+
added_nodes = self.nodes[0].getaddednodeinfo()
262+
assert_equal(len(added_nodes), 1)
263+
assert_equal(added_nodes[0]['addednode'], "11.22.33.44")
264+
self.log.info("Check that an invalid command returns an error")
258265
assert_raises_rpc_error(-1, 'addnode "node" "command"', self.nodes[0].addnode, node=ip_port, command='abc')
259-
# check that trying to remove the node again returns an error
266+
self.log.info("Check that trying to remove the node again returns an error")
260267
assert_raises_rpc_error(-24, "Node could not be removed", self.nodes[0].addnode, node=ip_port, command='remove')
261-
# check that a non-existent node returns an error
268+
self.log.info("Check that a non-existent node returns an error")
262269
assert_raises_rpc_error(-24, "Node has not been added", self.nodes[0].getaddednodeinfo, '1.1.1.1')
263270

264271
def test_service_flags(self):

0 commit comments

Comments
 (0)