Skip to content

Commit cd543d9

Browse files
committed
test: check misbehavior more independently in p2p_filter.py
1 parent 65276c7 commit cd543d9

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)