Skip to content
This repository has been archived by the owner on Jan 13, 2023. It is now read-only.

Commit

Permalink
Add tests for get_bundles_from_transactions_hashes util method
Browse files Browse the repository at this point in the history
  • Loading branch information
lzpap committed Feb 27, 2020
1 parent 29cf906 commit b80d360
Show file tree
Hide file tree
Showing 2 changed files with 575 additions and 5 deletions.
18 changes: 17 additions & 1 deletion iota/commands/extended/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
from typing import Generator, Iterable, List, Optional, Tuple

from iota import Address, Bundle, Transaction, \
TransactionHash
TransactionHash, TransactionTrytes, BadApiResponse
from iota.adapter import BaseAdapter
from iota.exceptions import with_context
from iota.commands.core.find_transactions import FindTransactionsCommand
from iota.commands.core.get_trytes import GetTrytesCommand
from iota.commands.core.were_addresses_spent_from import \
Expand Down Expand Up @@ -79,6 +80,21 @@ async def get_bundles_from_transaction_hashes(
non_tail_bundle_hashes = set()

gt_response = await GetTrytesCommand(adapter)(hashes=transaction_hashes)
for tx_hash, tx_trytes in zip(transaction_hashes, gt_response['trytes']):
# If no tx was found by the node for tx_hash, it returns 9s,
# so we check here if it returned all 9s trytes.
if tx_trytes == TransactionTrytes(''):
raise with_context(
exc=BadApiResponse(
'Could not get trytes of transaction {hash} from the Tangle. '
'(``exc.context`` has more info).'.format(hash=tx_hash),
),

context={
'transaction_hash': tx_hash,
'returned_transaction_trytes': tx_trytes,
},
)
all_transactions = list(map(
Transaction.from_tryte_string,
gt_response['trytes'],
Expand Down
Loading

0 comments on commit b80d360

Please sign in to comment.