class BtcBlockQueuingServiceTest(AbstractTestCase):
    def setUp(self):
        self.node = MockGatewayNode(
            gateway_helpers.get_gateway_opts(8000, max_block_interval=0)
        )

        self.node_connection = Mock()
        self.node_connection.is_active = MagicMock(return_value=True)
        self.node.set_known_total_difficulty = MagicMock()

        self.node.node_conn = self.node_connection

        self.block_queuing_service = BtcBlockQueuingService(self.node)
        self.node.block_queuing_service = self.block_queuing_service
        self.node.block_cleanup_service = BtcNormalBlockCleanupService(self.node, 1)
        self.block_hashes = []
        self.block_msg = self._get_sample_block()
        self.block_queuing_service.store_block_data(self.block_msg.block_hash(), self.block_msg)
        self.node.get_tx_service().track_seen_short_ids(self.block_msg.block_hash(), [])

    def _get_sample_block(self, file_path=__file__):
        root_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(file_path))))
        with open(os.path.join(root_dir, "btc_sample_block.txt")) as sample_file:
            btc_block = sample_file.read().strip("\n")
        buf = bytearray(convert.hex_to_bytes(btc_block))
        parsed_block = BlockBtcMessage(buf=buf)
        return parsed_block

    def test_tracked_block_cleanup(self):
        tx_service = self.node.get_tx_service()
        self.assertEqual(1, len(tx_service.get_tracked_blocks()))
        self.node.block_cleanup_service.block_cleanup_request(self.block_msg.block_hash())
        time.time = MagicMock(return_value=time.time() + constants.MIN_SLEEP_TIMEOUT)
        self.node.alarm_queue.fire_alarms()
        self.assertEqual(0, len(tx_service.get_tracked_blocks()))
    def setUp(self):
        self.node = MockGatewayNode(
            gateway_helpers.get_gateway_opts(8000, max_block_interval=0)
        )

        self.node_connection = Mock()
        self.node_connection.is_active = MagicMock(return_value=True)
        self.node.set_known_total_difficulty = MagicMock()

        self.node.node_conn = self.node_connection

        self.block_queuing_service = BtcBlockQueuingService(self.node)
        self.node.block_queuing_service = self.block_queuing_service
        self.node.block_cleanup_service = BtcNormalBlockCleanupService(self.node, 1)
        self.block_hashes = []
        self.block_msg = self._get_sample_block()
        self.block_queuing_service.store_block_data(self.block_msg.block_hash(), self.block_msg)
        self.node.get_tx_service().track_seen_short_ids(self.block_msg.block_hash(), [])
Ejemplo n.º 3
0
 def build_block_queuing_service(
     self, connection: AbstractGatewayBlockchainConnection
 ) -> PushBlockQueuingService:
     return BtcBlockQueuingService(self, connection)
Ejemplo n.º 4
0
 def build_block_queuing_service(self) -> PushBlockQueuingService:
     return BtcBlockQueuingService(self)