def test_block_bodies_eth_message(self): self._test_msg_serialization( BlockBodiesEthProtocolMessage, False, # passing randomly generated hashes [ mock_eth_messages.get_dummy_transient_block_body(1), mock_eth_messages.get_dummy_transient_block_body(2), mock_eth_messages.get_dummy_transient_block_body(3) ])
def test_request_block_bodies(self): self.cleanup_service.clean_block_transactions_by_block_components = ( MagicMock() ) block_hashes_sets = [ [helpers.generate_object_hash(), helpers.generate_object_hash()], [helpers.generate_object_hash()], [helpers.generate_object_hash()], ] block_bodies_messages = [ BlockBodiesEthProtocolMessage( None, [ mock_eth_messages.get_dummy_transient_block_body(1), mock_eth_messages.get_dummy_transient_block_body(2), ], ), BlockBodiesEthProtocolMessage( None, [mock_eth_messages.get_dummy_transient_block_body(3)] ), BlockBodiesEthProtocolMessage( None, [mock_eth_messages.get_dummy_transient_block_body(4)] ), ] transactions = [ [ [ tx.hash() for tx in BlockBodiesEthProtocolMessage.from_body_bytes( block_body_bytes ) .get_blocks()[0] .transactions ] for block_body_bytes in msg.get_block_bodies_bytes() ] for msg in block_bodies_messages ] for block_bodies_message in block_bodies_messages: block_bodies_message.serialize() for block_hashes_set in block_hashes_sets: for block_hash in block_hashes_set: self.node.block_cleanup_service._block_hash_marked_for_cleanup.add( block_hash ) self.sut.request_block_body(block_hashes_set) self.sut.msg_block_bodies(block_bodies_messages[0]) call_args_list = ( self.cleanup_service.clean_block_transactions_by_block_components.call_args_list ) first_call = call_args_list[0] first_kwargs = first_call[1] self.assertEqual( first_kwargs["transaction_service"], self.node.get_tx_service() ) self.assertEqual(first_kwargs["block_hash"], block_hashes_sets[0][0]) self.assertEqual( list(first_kwargs["transactions_list"]), transactions[0][0] ) second_call = call_args_list[1] second_kwargs = second_call[1] self.assertEqual( second_kwargs["transaction_service"], self.node.get_tx_service() ) self.assertEqual(second_kwargs["block_hash"], block_hashes_sets[0][1]) self.assertEqual( list(second_kwargs["transactions_list"]), transactions[0][1] ) self.cleanup_service.clean_block_transactions_by_block_components.reset_mock() self.sut.msg_block_bodies(block_bodies_messages[1]) call_args_list = ( self.cleanup_service.clean_block_transactions_by_block_components.call_args_list ) first_call = call_args_list[0] first_kwargs = first_call[1] self.assertEqual( first_kwargs["transaction_service"], self.node.get_tx_service() ) self.assertEqual(first_kwargs["block_hash"], block_hashes_sets[1][0]) self.assertEqual( list(first_kwargs["transactions_list"]), transactions[1][0] ) self.cleanup_service.clean_block_transactions_by_block_components.reset_mock() self.sut.msg_block_bodies(block_bodies_messages[2]) call_args_list = ( self.cleanup_service.clean_block_transactions_by_block_components.call_args_list ) first_call = call_args_list[0] first_kwargs = first_call[1] self.assertEqual( first_kwargs["transaction_service"], self.node.get_tx_service() ) self.assertEqual(first_kwargs["block_hash"], block_hashes_sets[2][0]) self.assertEqual( list(first_kwargs["transactions_list"]), transactions[2][0] )