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

Commit

Permalink
Merge pull request #314 from lzpap/get_bundle_from_transaction_hashes…
Browse files Browse the repository at this point in the history
…_tests

Add tests for `get_bundles_from_transactions_hashes` util method
  • Loading branch information
lzpap authored Feb 28, 2020
2 parents 0f15772 + b80d360 commit 202c811
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 202c811

Please sign in to comment.