diff options
author | Martin Zumsande <mzumsande@gmail.com> | 2023-08-22 13:15:14 -0400 |
---|---|---|
committer | Martin Zumsande <mzumsande@gmail.com> | 2023-08-22 13:28:15 -0400 |
commit | 3557aa4d0ab59c18807661a49070b0e5cbfecde3 (patch) | |
tree | 50222699f5e881175a9cb26e84d505d83bb43e7b /test/functional/rpc_net.py | |
parent | a9a1d69391596f57851f545fae12f8851149d2c3 (diff) | |
download | bitcoin-3557aa4d0ab59c18807661a49070b0e5cbfecde3.tar.xz |
test: add basic tests for sendmsgtopeer to rpc_net.py
Diffstat (limited to 'test/functional/rpc_net.py')
-rwxr-xr-x | test/functional/rpc_net.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/test/functional/rpc_net.py b/test/functional/rpc_net.py index 5fdd5daddf..255f5108a2 100755 --- a/test/functional/rpc_net.py +++ b/test/functional/rpc_net.py @@ -65,6 +65,7 @@ class NetTest(BitcoinTestFramework): self.test_service_flags() self.test_getnodeaddresses() self.test_addpeeraddress() + self.test_sendmsgtopeer() def test_connection_count(self): self.log.info("Test getconnectioncount") @@ -328,6 +329,37 @@ class NetTest(BitcoinTestFramework): addrs = node.getnodeaddresses(count=0) # getnodeaddresses re-runs the addrman checks assert_equal(len(addrs), 2) + def test_sendmsgtopeer(self): + node = self.nodes[0] + + self.restart_node(0) + self.connect_nodes(0, 1) + + self.log.info("Test sendmsgtopeer") + self.log.debug("Send a valid message") + with self.nodes[1].assert_debug_log(expected_msgs=["received: addr"]): + node.sendmsgtopeer(peer_id=0, msg_type="addr", msg="FFFFFF") + + self.log.debug("Test error for sending to non-existing peer") + assert_raises_rpc_error(-1, "Error: Could not send message to peer", node.sendmsgtopeer, peer_id=100, msg_type="addr", msg="FF") + + self.log.debug("Test that zero-length msg_type is allowed") + node.sendmsgtopeer(peer_id=0, msg_type="addr", msg="") + + self.log.debug("Test error for msg_type that is too long") + assert_raises_rpc_error(-8, "Error: msg_type too long, max length is 12", node.sendmsgtopeer, peer_id=0, msg_type="long_msg_type", msg="FF") + + self.log.debug("Test that unknown msg_type is allowed") + node.sendmsgtopeer(peer_id=0, msg_type="unknown", msg="FF") + + self.log.debug("Test that empty msg is allowed") + node.sendmsgtopeer(peer_id=0, msg_type="addr", msg="FF") + + self.log.debug("Test that oversized messages are allowed, but get us disconnected") + zero_byte_string = b'\x00' * 4000001 + node.sendmsgtopeer(peer_id=0, msg_type="addr", msg=zero_byte_string.hex()) + self.wait_until(lambda: len(self.nodes[0].getpeerinfo()) == 0, timeout=10) + if __name__ == '__main__': NetTest().main() |