def test_get_transaction_history(self): """ Checks get_transaction_history() works as expected. """ address = ADDRESS m_transactions = M_TRANSACTIONS with patch_requests_get() as m_get: m_get.return_value.status_code = http.HTTPStatus.OK m_get.return_value.json.return_value = { 'status': '1', 'message': 'OK', 'result': m_transactions, } transactions = PyWalib.get_transaction_history(address) url = mock.ANY headers = REQUESTS_HEADERS self.assertEqual(m_get.call_args_list, [mock.call(url, headers=headers)]) self.helper_test_get_history(transactions) # value is stored in Wei self.assertEqual(transactions[1]['value'], '10000000000000000') # but converted to Ether is also accessible self.assertEqual(transactions[1]['extra_dict']['value_eth'], 0.01) # history contains all send or received transactions self.assertEqual(transactions[1]['extra_dict']['sent'], True) self.assertEqual(transactions[1]['extra_dict']['received'], False) self.assertEqual(transactions[2]['extra_dict']['sent'], True) self.assertEqual(transactions[2]['extra_dict']['received'], False)
def test_get_transaction_history(self): """ Checks get_transaction_history() works as expected. """ address = ADDRESS transactions = PyWalib.get_transaction_history(address) self.helper_get_history(transactions) # value is stored in Wei self.assertEqual(transactions[1]['value'], '200000000000000000') # but converted to Ether is also accessible self.assertEqual(transactions[1]['extra_dict']['value_eth'], 0.2) # history contains all send or received transactions self.assertEqual(transactions[1]['extra_dict']['sent'], False) self.assertEqual(transactions[1]['extra_dict']['received'], True) self.assertEqual(transactions[2]['extra_dict']['sent'], True) self.assertEqual(transactions[2]['extra_dict']['received'], False)
def _load_history(self): account = self.current_account address = '0x' + account.address.encode("hex") try: transactions = PyWalib.get_transaction_history(address) # new transactions first transactions.reverse() except ConnectionError: Controller.on_history_connection_error() return except NoTransactionFoundException: transactions = [] list_items = [] for transaction in transactions: list_item = History.create_item_from_dict(transaction) list_items.append(list_item) self.update_history_list(list_items)
def fetch_history(self): if self.current_account is None: return chain_id = Settings.get_stored_network() address = '0x' + self.current_account.address.hex() try: transactions = PyWalib.get_transaction_history(address, chain_id) except ConnectionError: Dialog.on_history_connection_error() Logger.warning('ConnectionError', exc_info=True) return except NoTransactionFoundException: transactions = [] except ValueError: # most likely the JSON object could not be decoded, refs #91 Dialog.on_history_value_error() # currently logged as an error, because we want more insight # in order to eventually handle it more specifically Logger.error('ValueError', exc_info=True) return # triggers accounts_history observers update self.controller.accounts_history[address] = transactions