diff options
author | Jon Atack <jon@atack.com> | 2020-06-14 12:43:57 +0200 |
---|---|---|
committer | Jon Atack <jon@atack.com> | 2020-06-19 14:14:29 +0200 |
commit | 57960192a5362ff1a7b996995332535f4c2a25c3 (patch) | |
tree | ae52992f4c5cedb9ec7c2b4d9c9a247b01478cb6 /test | |
parent | e2b21d8a597c536a8617408d43958bfe9f98a442 (diff) |
test: refactor test_large_inv() into 3 tests with common method
Diffstat (limited to 'test')
-rwxr-xr-x | test/functional/p2p_invalid_messages.py | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/test/functional/p2p_invalid_messages.py b/test/functional/p2p_invalid_messages.py index 007613b300..387d266549 100755 --- a/test/functional/p2p_invalid_messages.py +++ b/test/functional/p2p_invalid_messages.py @@ -53,7 +53,9 @@ class InvalidMessagesTest(BitcoinTestFramework): self.test_checksum() self.test_size() self.test_msgtype() - self.test_large_inv() + self.test_oversized_inv_msg() + self.test_oversized_getdata_msg() + self.test_oversized_headers_msg() self.test_resource_exhaustion() def test_buffer(self): @@ -122,20 +124,22 @@ class InvalidMessagesTest(BitcoinTestFramework): conn.sync_with_ping(timeout=1) self.nodes[0].disconnect_p2ps() - def test_large_inv(self): - self.log.info("Test oversized inv/getdata/headers messages are logged as misbehaving") - conn = self.nodes[0].add_p2p_connection(P2PInterface()) - with self.nodes[0].assert_debug_log(['Misbehaving', '(0 -> 20): inv message size = 50001']): - msg = msg_inv([CInv(MSG_TX, 1)] * 50001) - conn.send_and_ping(msg) - with self.nodes[0].assert_debug_log(['Misbehaving', '(20 -> 40): getdata message size = 50001']): - msg = msg_getdata([CInv(MSG_TX, 1)] * 50001) - conn.send_and_ping(msg) - with self.nodes[0].assert_debug_log(['Misbehaving', '(40 -> 60): headers message size = 2001']): - msg = msg_headers([CBlockHeader()] * 2001) - conn.send_and_ping(msg) + def test_oversized_msg(self, msg, size): + msg_type = msg.msgtype.decode('ascii') + self.log.info("Test {} message of size {} is logged as misbehaving".format(msg_type, size)) + with self.nodes[0].assert_debug_log(['Misbehaving', '{} message size = {}'.format(msg_type, size)]): + self.nodes[0].add_p2p_connection(P2PInterface()).send_and_ping(msg) self.nodes[0].disconnect_p2ps() + def test_oversized_inv_msg(self): + self.test_oversized_msg(msg_inv([CInv(MSG_TX, 1)] * 50001), 50001) + + def test_oversized_getdata_msg(self): + self.test_oversized_msg(msg_getdata([CInv(MSG_TX, 1)] * 50001), 50001) + + def test_oversized_headers_msg(self): + self.test_oversized_msg(msg_headers([CBlockHeader()] * 2001), 2001) + def test_resource_exhaustion(self): self.log.info("Test node stays up despite many large junk messages") conn = self.nodes[0].add_p2p_connection(P2PDataStore()) |