Skip to content

Commit 36c0abd

Browse files
author
MarcoFalke
committed
Merge #18726: test: check misbehavior more independently in p2p_filter.py
cd543d9 test: check misbehavior more independently in p2p_filter.py (Danny Lee) Pull request description: This expands on #18672 in two ways: - Check positive cases (`filterload` accepted, `filteradd` accepted) in addition to the negative cases added in #18672 - Address MarcoFalke 's [suggestion](bitcoin/bitcoin#18672 (comment)) to successfully load a filter before testing `filteradd` ACKs for top commit: theStack: re-ACK bitcoin/bitcoin@cd543d9 Tree-SHA512: f82402f6287ccddf08b38b6432d5e2b2b2ef528802a981d04c24bac459022f732d9090d4849d72d3d1eb2c757161dcb18c4c036b6e11dc80114e9cd49f21c3bd
2 parents 95a9165 + cd543d9 commit 36c0abd

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

test/functional/p2p_filter.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,40 @@ def set_test_params(self):
6464
def skip_test_if_missing_module(self):
6565
self.skip_if_no_wallet()
6666

67-
def run_test(self):
68-
filter_node = self.nodes[0].add_p2p_connection(FilterNode())
69-
67+
def test_size_limits(self, filter_node):
7068
self.log.info('Check that too large filter is rejected')
71-
with self.nodes[0].assert_debug_log(['Misbehaving']):
72-
filter_node.send_and_ping(msg_filterload(data=b'\xaa', nHashFuncs=MAX_BLOOM_HASH_FUNCS+1))
7369
with self.nodes[0].assert_debug_log(['Misbehaving']):
7470
filter_node.send_and_ping(msg_filterload(data=b'\xbb'*(MAX_BLOOM_FILTER_SIZE+1)))
7571

72+
self.log.info('Check that max size filter is accepted')
73+
with self.nodes[0].assert_debug_log([], unexpected_msgs=['Misbehaving']):
74+
filter_node.send_and_ping(msg_filterload(data=b'\xbb'*(MAX_BLOOM_FILTER_SIZE)))
75+
filter_node.send_and_ping(msg_filterclear())
76+
77+
self.log.info('Check that filter with too many hash functions is rejected')
78+
with self.nodes[0].assert_debug_log(['Misbehaving']):
79+
filter_node.send_and_ping(msg_filterload(data=b'\xaa', nHashFuncs=MAX_BLOOM_HASH_FUNCS+1))
80+
81+
self.log.info('Check that filter with max hash functions is accepted')
82+
with self.nodes[0].assert_debug_log([], unexpected_msgs=['Misbehaving']):
83+
filter_node.send_and_ping(msg_filterload(data=b'\xaa', nHashFuncs=MAX_BLOOM_HASH_FUNCS))
84+
# Don't send filterclear until next two filteradd checks are done
85+
86+
self.log.info('Check that max size data element to add to the filter is accepted')
87+
with self.nodes[0].assert_debug_log([], unexpected_msgs=['Misbehaving']):
88+
filter_node.send_and_ping(msg_filteradd(data=b'\xcc'*(MAX_SCRIPT_ELEMENT_SIZE)))
89+
7690
self.log.info('Check that too large data element to add to the filter is rejected')
7791
with self.nodes[0].assert_debug_log(['Misbehaving']):
7892
filter_node.send_and_ping(msg_filteradd(data=b'\xcc'*(MAX_SCRIPT_ELEMENT_SIZE+1)))
7993

94+
filter_node.send_and_ping(msg_filterclear())
95+
96+
def run_test(self):
97+
filter_node = self.nodes[0].add_p2p_connection(FilterNode())
98+
99+
self.test_size_limits(filter_node)
100+
80101
self.log.info('Add filtered P2P connection to the node')
81102
filter_node.send_and_ping(filter_node.watch_filter_init)
82103
filter_address = self.nodes[0].decodescript(filter_node.watch_script_pubkey)['addresses'][0]

0 commit comments

Comments
 (0)