Changeset View
Changeset View
Standalone View
Standalone View
test/functional/p2p_filter.py
Show First 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | def set_test_params(self): | ||||
self.extra_args = [[ | self.extra_args = [[ | ||||
'-peerbloomfilters', | '-peerbloomfilters', | ||||
'-whitelist=noban@127.0.0.1', # immediate tx relay | '-whitelist=noban@127.0.0.1', # immediate tx relay | ||||
]] | ]] | ||||
def skip_test_if_missing_module(self): | def skip_test_if_missing_module(self): | ||||
self.skip_if_no_wallet() | self.skip_if_no_wallet() | ||||
def run_test(self): | def test_size_limits(self, filter_node): | ||||
filter_node = self.nodes[0].add_p2p_connection(FilterNode()) | |||||
self.log.info('Check that too large filter is rejected') | self.log.info('Check that too large filter is rejected') | ||||
with self.nodes[0].assert_debug_log(['Misbehaving']): | with self.nodes[0].assert_debug_log(['Misbehaving']): | ||||
filter_node.send_and_ping(msg_filterload( | |||||
data=b'\xbb' * (MAX_BLOOM_FILTER_SIZE + 1))) | |||||
self.log.info('Check that max size filter is accepted') | |||||
with self.nodes[0].assert_debug_log([""], unexpected_msgs=['Misbehaving']): | |||||
filter_node.send_and_ping( | |||||
msg_filterload( | |||||
data=b'\xbb' * | |||||
(MAX_BLOOM_FILTER_SIZE))) | |||||
filter_node.send_and_ping(msg_filterclear()) | |||||
self.log.info( | |||||
'Check that filter with too many hash functions is rejected') | |||||
with self.nodes[0].assert_debug_log(['Misbehaving']): | |||||
filter_node.send_and_ping( | filter_node.send_and_ping( | ||||
msg_filterload( | msg_filterload( | ||||
data=b'\xaa', | data=b'\xaa', | ||||
nHashFuncs=MAX_BLOOM_HASH_FUNCS + 1)) | nHashFuncs=MAX_BLOOM_HASH_FUNCS + 1)) | ||||
with self.nodes[0].assert_debug_log(['Misbehaving']): | |||||
filter_node.send_and_ping(msg_filterload( | self.log.info('Check that filter with max hash functions is accepted') | ||||
data=b'\xbb' * (MAX_BLOOM_FILTER_SIZE + 1))) | with self.nodes[0].assert_debug_log([""], unexpected_msgs=['Misbehaving']): | ||||
filter_node.send_and_ping( | |||||
msg_filterload( | |||||
data=b'\xaa', | |||||
nHashFuncs=MAX_BLOOM_HASH_FUNCS)) | |||||
# Don't send filterclear until next two filteradd checks are done | |||||
self.log.info( | |||||
'Check that max size data element to add to the filter is accepted') | |||||
with self.nodes[0].assert_debug_log([""], unexpected_msgs=['Misbehaving']): | |||||
filter_node.send_and_ping( | |||||
msg_filteradd( | |||||
data=b'\xcc' * | |||||
(MAX_SCRIPT_ELEMENT_SIZE))) | |||||
self.log.info( | self.log.info( | ||||
'Check that too large data element to add to the filter is rejected') | 'Check that too large data element to add to the filter is rejected') | ||||
with self.nodes[0].assert_debug_log(['Misbehaving']): | with self.nodes[0].assert_debug_log(['Misbehaving']): | ||||
filter_node.send_and_ping(msg_filteradd( | filter_node.send_and_ping(msg_filteradd( | ||||
data=b'\xcc' * (MAX_SCRIPT_ELEMENT_SIZE + 1))) | data=b'\xcc' * (MAX_SCRIPT_ELEMENT_SIZE + 1))) | ||||
filter_node.send_and_ping(msg_filterclear()) | |||||
def run_test(self): | |||||
filter_node = self.nodes[0].add_p2p_connection(FilterNode()) | |||||
self.test_size_limits(filter_node) | |||||
self.log.info('Add filtered P2P connection to the node') | self.log.info('Add filtered P2P connection to the node') | ||||
filter_node.send_and_ping(filter_node.watch_filter_init) | filter_node.send_and_ping(filter_node.watch_filter_init) | ||||
filter_address = self.nodes[0].decodescript( | filter_address = self.nodes[0].decodescript( | ||||
filter_node.watch_script_pubkey)['addresses'][0] | filter_node.watch_script_pubkey)['addresses'][0] | ||||
self.log.info( | self.log.info( | ||||
'Check that we receive merkleblock and tx if the filter matches a tx in a block') | 'Check that we receive merkleblock and tx if the filter matches a tx in a block') | ||||
block_hash = self.nodes[0].generatetoaddress(1, filter_address)[0] | block_hash = self.nodes[0].generatetoaddress(1, filter_address)[0] | ||||
▲ Show 20 Lines • Show All 67 Lines • Show Last 20 Lines |