def test_maybe_schedule_ethereum_txreceipts(task_manager, ethereum_manager, database, one_receipt_in_db): # noqa: E501 task_manager.potential_tasks = [ task_manager._maybe_schedule_ethereum_txreceipts ] # pylint: disable=protected-member # noqa: E501 _, receipts = setup_ethereum_transactions_test( database=database, transaction_already_queried=True, one_receipt_in_db=one_receipt_in_db, ) dbethtx = DBEthTx(database) timeout = 10 tx_hash_1 = '0x692f9a6083e905bdeca4f0293f3473d7a287260547f8cbccc38c5cb01591fcda' tx_hash_2 = '0x6beab9409a8f3bd11f82081e99e856466a7daf5f04cca173192f79e78ed53a77' receipt_task_patch = patch.object( task_manager, '_run_ethereum_txreceipts_query', wraps=task_manager._run_ethereum_txreceipts_query) # pylint: disable=protected-member # noqa: E501 queried_receipts = set() try: with gevent.Timeout(timeout): with receipt_task_patch as receipt_task_mock: task_manager.schedule() while True: if len(queried_receipts) == 2: break for txhash in (tx_hash_1, tx_hash_2): if dbethtx.get_receipt( hexstring_to_bytes(txhash)) is not None: queried_receipts.add(txhash) gevent.sleep(.3) task_manager.schedule() gevent.sleep(.5) assert receipt_task_mock.call_count == 1, '2nd schedule should do nothing' except gevent.Timeout as e: raise AssertionError( f'receipts query was not completed within {timeout} seconds' ) from e # noqa: E501 txmodule = EthTransactions(ethereum=ethereum_manager, database=database) receipt1 = txmodule.get_or_query_transaction_receipt(tx_hash_1) assert receipt1 == receipts[0] receipt2 = txmodule.get_or_query_transaction_receipt(tx_hash_2) assert receipt2 == receipts[1]
def get_decoded_events_of_transaction( ethereum_manager: EthereumManager, database: DBHandler, msg_aggregator: MessagesAggregator, tx_hash: EVMTxHash, ) -> List[HistoryBaseEntry]: """A convenience function to ask get transaction, receipt and decoded event for a tx_hash""" transactions = EthTransactions(ethereum=ethereum_manager, database=database) transactions.get_or_query_transaction_receipt(tx_hash=tx_hash) decoder = EVMTransactionDecoder( database=database, ethereum_manager=ethereum_manager, eth_transactions=transactions, msg_aggregator=msg_aggregator, ) return decoder.decode_transaction_hashes(ignore_cache=True, tx_hashes=[tx_hash])
def test_get_transaction_receipt(database, ethereum_manager, call_order, transaction_already_queried): # pylint: disable=unused-argument # noqa: E501 """Test that getting a transaction receipt from the network and saving it in the DB works""" transactions, receipts = setup_ethereum_transactions_test( database=database, transaction_already_queried=transaction_already_queried, one_receipt_in_db=False, ) tx_hash = '0x' + transactions[0].tx_hash.hex() txmodule = EthTransactions(ethereum=ethereum_manager, database=database) receipt = txmodule.get_or_query_transaction_receipt(tx_hash) assert receipt == receipts[0] results, _ = txmodule.query( ETHTransactionsFilterQuery.make(tx_hash=tx_hash), only_cache=True) assert len(results) == 1 assert results[0] == transactions[0]