def test_export_blocks_job(tmpdir, start_block, end_block, batch_size, resource_group, provider_type, chain): blocks_output_file = str(tmpdir.join('actual_block.json')) transactions_output_file = str(tmpdir.join("actual_transactions.json")) job = ExportBlocksJob( start_block=start_block, end_block=end_block, batch_size=batch_size, bitcoin_rpc=ThreadLocalProxy( lambda: get_bitcoin_rpc(provider_type, read_resource_lambda=lambda file: read_resource(resource_group, file), chain=chain)), max_workers=5, item_exporter=blocks_and_transactions_item_exporter( blocks_output_file, transactions_output_file), chain=chain, export_blocks=blocks_output_file is not None, export_transactions=transactions_output_file is not None) job.run() print('=====================') print(read_file(blocks_output_file)) compare_lines_ignore_order( read_resource(resource_group, 'expected_blocks.json'), read_file(blocks_output_file)) print('=====================') print(read_file(transactions_output_file)) compare_lines_ignore_order( read_resource(resource_group, 'expected_transactions.json'), read_file(transactions_output_file))
def test_stream(tmpdir, start_block, end_block, batch_size, resource_group, provider_type, chain): try: os.remove('last_synced_block.txt') except OSError: pass blocks_output_file = str(tmpdir.join('actual_block.json')) transactions_output_file = str(tmpdir.join("actual_transactions.json")) stream( bitcoin_rpc=ThreadLocalProxy( lambda: get_bitcoin_rpc( provider_type, read_resource_lambda=lambda file: read_resource(resource_group, file), chain=chain)), start_block=start_block, end_block=end_block, batch_size=batch_size, item_exporter=blocks_and_transactions_item_exporter(blocks_output_file, transactions_output_file) ) print('=====================') print(read_file(blocks_output_file)) compare_lines_ignore_order( read_resource(resource_group, 'expected_blocks.json'), read_file(blocks_output_file) ) print('=====================') print(read_file(transactions_output_file)) compare_lines_ignore_order( read_resource(resource_group, 'expected_transactions.json'), read_file(transactions_output_file) )
def test_stream(tmpdir, start_block, end_block, batch_size, resource_group, provider_type, chain): try: os.remove('last_synced_block.txt') except OSError: pass blocks_output_file = str(tmpdir.join('actual_block.json')) transactions_output_file = str(tmpdir.join("actual_transactions.json")) streamer_adapter = BtcStreamerAdapter( bitcoin_rpc=ThreadLocalProxy( lambda: get_bitcoin_rpc(provider_type, read_resource_lambda=lambda file: read_resource(resource_group, file), chain=chain)), batch_size=batch_size, item_exporter=CompositeItemExporter( filename_mapping={ 'block': blocks_output_file, 'transaction': transactions_output_file, }), ) streamer = Streamer(blockchain_streamer_adapter=streamer_adapter, start_block=start_block, end_block=end_block, retry_errors=False) streamer.stream() print('=====================') print(read_file(blocks_output_file)) compare_lines_ignore_order( read_resource(resource_group, 'expected_blocks.json'), read_file(blocks_output_file)) print('=====================') print(read_file(transactions_output_file)) compare_lines_ignore_order( read_resource(resource_group, 'expected_transactions.json'), read_file(transactions_output_file))
def get_new_btc_block_range_service(chain): rpc = get_bitcoin_rpc("online", chain=chain) return BtcBlockRangeService(rpc)