message: test: check misbehavior more independently in p2p_filter.py
diff: @@ -64,19 +64,40 @@ class FilterTest(BitcoinTestFramework):
  def skip_test_if_missing_module(self):
  self.skip_if_no_wallet()
  - def run_test(self):
  - filter_node = self.nodes[0].add_p2p_connection(FilterNode())
  -
  + def test_size_limits(self, filter_node):
  self.log.info('Check that too large filter is rejected')
  - with self.nodes[0].assert_debug_log(['Misbehaving']):
  - filter_node.send_and_ping(msg_filterload(data=b'\xaa', nHashFuncs=MAX_BLOOM_HASH_FUNCS+1))
  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(msg_filterload(data=b'\xaa', nHashFuncs=MAX_BLOOM_HASH_FUNCS+1))
  +
  + self.log.info('Check that filter with max hash functions is accepted')
  + 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('Check that too large data element to add to the filter is rejected')
  with self.nodes[0].assert_debug_log(['Misbehaving']):
  filter_node.send_and_ping(msg_filteradd(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')
  filter_node.send_and_ping(filter_node.watch_filter_init)
  filter_address = self.nodes[0].decodescript(filter_node.watch_script_pubkey)['addresses'][0]
  