From 6b1926cf1eac1ad1850599d2753dd22bc21fd327 Mon Sep 17 00:00:00 2001 From: Jon Atack Date: Sat, 22 May 2021 22:09:28 +0200 Subject: [PATCH] test: addpeeraddress functional test coverage --- test/functional/rpc_net.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/functional/rpc_net.py b/test/functional/rpc_net.py index 2a58f8b3f7..9a2817a6ee 100755 --- a/test/functional/rpc_net.py +++ b/test/functional/rpc_net.py @@ -69,6 +69,7 @@ class NetTest(BitcoinTestFramework): self.test_getaddednodeinfo() self.test_service_flags() self.test_getnodeaddresses() + self.test_addpeeraddress() def test_connection_count(self): self.log.info("Test getconnectioncount") @@ -236,6 +237,30 @@ class NetTest(BitcoinTestFramework): assert_raises_rpc_error(-8, "Address count out of range", self.nodes[0].getnodeaddresses, -1) assert_raises_rpc_error(-8, "Network not recognized: Foo", self.nodes[0].getnodeaddresses, 1, "Foo") + def test_addpeeraddress(self): + self.log.info("Test addpeeraddress") + node = self.nodes[1] + + self.log.debug("Test that addpeerinfo is a hidden RPC") + # It is hidden from general help, but its detailed help may be called directly. + assert "addpeerinfo" not in node.help() + assert "addpeerinfo" in node.help("addpeerinfo") + + self.log.debug("Test that adding an empty address fails") + assert_equal(node.addpeeraddress(address="", port=8333), {"success": False}) + assert_equal(node.getnodeaddresses(count=0), []) + + self.log.debug("Test that adding a valid address succeeds") + assert_equal(node.addpeeraddress(address="1.2.3.4", port=8333), {"success": True}) + addrs = node.getnodeaddresses(count=0) + assert_equal(len(addrs), 1) + assert_equal(addrs[0]["address"], "1.2.3.4") + assert_equal(addrs[0]["port"], 8333) + + self.log.debug("Test that adding the same address again when already present fails") + assert_equal(node.addpeeraddress(address="1.2.3.4", port=8333), {"success": False}) + assert_equal(len(node.getnodeaddresses(count=0)), 1) + if __name__ == '__main__': NetTest().main()