async def test_no_raw_tx(): """Test no raw tx returned.""" dispatcher = LedgerApiRequestDispatcher(ConnectionStatus()) mock_api = Mock() contract_api_dialogues = ContractApiDialogues() message = LedgerApiMessage( performative=LedgerApiMessage.Performative.GET_RAW_TRANSACTION, dialogue_reference=contract_api_dialogues. new_self_initiated_dialogue_reference(), terms=Terms( ledger_id=EthereumCrypto.identifier, sender_address="1111", counterparty_address="22222", amount_by_currency_id={"ETH": -1}, quantities_by_good_id={"some_service_id": 1}, is_sender_payable_tx_fee=True, nonce="", fee_by_currency_id={"ETH": 10}, chain_id=3, ), ) message.counterparty = "test" dialogue = contract_api_dialogues.update(message) mock_api.get_transfer_transaction.return_value = None msg = dispatcher.get_raw_transaction(mock_api, message, dialogue) assert msg.performative == LedgerApiMessage.Performative.ERROR
async def test_no_balance(): """Test no balance.""" dispatcher = LedgerApiRequestDispatcher(AsyncState()) mock_api = Mock() message = LedgerApiMessage( performative=LedgerApiMessage.Performative.GET_BALANCE, dialogue_reference=dispatcher.dialogues. new_self_initiated_dialogue_reference(), ledger_id=ETHEREUM, address="test", ) message.counterparty = "test" dialogue = dispatcher.dialogues.update(message) mock_api.get_balance.return_value = None msg = dispatcher.get_balance(mock_api, message, dialogue) assert msg.performative == LedgerApiMessage.Performative.ERROR
async def test_no_balance(): """Test no balance.""" dispatcher = LedgerApiRequestDispatcher(ConnectionStatus()) mock_api = Mock() contract_api_dialogues = ContractApiDialogues() message = LedgerApiMessage( performative=LedgerApiMessage.Performative.GET_BALANCE, dialogue_reference=contract_api_dialogues. new_self_initiated_dialogue_reference(), ledger_id=EthereumCrypto.identifier, address="test", ) message.counterparty = "test" dialogue = contract_api_dialogues.update(message) mock_api.get_balance.return_value = None msg = dispatcher.get_balance(mock_api, message, dialogue) assert msg.performative == LedgerApiMessage.Performative.ERROR
async def connect(self) -> None: """Set up the connection.""" self._ledger_dispatcher = LedgerApiRequestDispatcher( self.connection_status, loop=self.loop, api_configs=self.api_configs) self._contract_dispatcher = ContractApiRequestDispatcher( self.connection_status, loop=self.loop, api_configs=self.api_configs) self._event_new_receiving_task = asyncio.Event(loop=self.loop) self.connection_status.is_connected = True
async def test_attempts_get_transaction_receipt(): """Test retry and sleep.""" dispatcher = LedgerApiRequestDispatcher(ConnectionStatus()) dispatcher.connection_status.is_connected = True mock_api = Mock() contract_api_dialogues = ContractApiDialogues() message = LedgerApiMessage( performative=LedgerApiMessage.Performative.GET_TRANSACTION_RECEIPT, dialogue_reference=contract_api_dialogues. new_self_initiated_dialogue_reference(), transaction_digest=TransactionDigest("asdad", "sdfdsf"), ) message.counterparty = "test" dialogue = contract_api_dialogues.update(message) mock_api.get_transaction.return_value = None mock_api.is_transaction_settled.return_value = True with patch.object(dispatcher, "MAX_ATTEMPTS", 2): with patch.object(dispatcher, "TIMEOUT", 0.001): msg = dispatcher.get_transaction_receipt(mock_api, message, dialogue) assert msg.performative == LedgerApiMessage.Performative.ERROR
async def connect(self) -> None: """Set up the connection.""" if self.is_connected: # pragma: nocover return self._state.set(ConnectionStates.connecting) self._ledger_dispatcher = LedgerApiRequestDispatcher( self._state, loop=self.loop, api_configs=self.api_configs, logger=self.logger, ) self._contract_dispatcher = ContractApiRequestDispatcher( self._state, loop=self.loop, api_configs=self.api_configs, logger=self.logger, ) self._event_new_receiving_task = asyncio.Event(loop=self.loop) self._state.set(ConnectionStates.connected)