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 #292 from lzpap/get_bundles_no_tx_found
Browse files Browse the repository at this point in the history
fix: traverse_bundle checks for zero trytes
  • Loading branch information
lzpap committed Jan 22, 2020
2 parents 6072a83 + bd28ba9 commit 7635bb9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
9 changes: 6 additions & 3 deletions iota/commands/extended/traverse_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import filters as f

from iota import BadApiResponse, BundleHash, Transaction, \
TransactionHash, TryteString, Bundle
TransactionHash, TryteString, Bundle, TransactionTrytes
from iota.commands import FilterCommand, RequestFilter
from iota.commands.core.get_trytes import GetTrytesCommand
from iota.exceptions import with_context
Expand Down Expand Up @@ -55,10 +55,13 @@ def _traverse_bundle(self, txn_hash, target_bundle_hash):
GetTrytesCommand(self.adapter)(hashes=[txn_hash])['trytes']
) # type: List[TryteString]

if not trytes:
# If no tx was found by the node for txn_hash, it returns 9s,
# so we check here if it returned all 9s trytes.
if not trytes or trytes == [TransactionTrytes('')]:
raise with_context(
exc=BadApiResponse(
'Bundle transactions not visible '
'Could not get trytes of bundle transaction from the Tangle. '
'Bundle transactions not visible.'
'(``exc.context`` has more info).',
),

Expand Down
17 changes: 17 additions & 0 deletions test/commands/extended/traverse_bundle_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,3 +451,20 @@ def test_missing_transaction(self):
b'ORYCRDX9TOMJPFCRB9R9KPUUGFPVOWYXFIWEW9999'
),
)

def test_missing_transaction_zero_trytes(self):
"""
Unable to find the requested transaction.
getTrytes returned only zeros, no tx was found.
"""
zero_trytes = TransactionTrytes('')
self.adapter.seed_response('getTrytes', {'trytes': [zero_trytes]})

with self.assertRaises(BadApiResponse):
self.command(
transaction =
TransactionHash(
b'FSEWUNJOEGNUI9QOCRFMYSIFAZLJHKZBPQZZYFG9'
b'ORYCRDX9TOMJPFCRB9R9KPUUGFPVOWYXFIWEW9999'
),
)

0 comments on commit 7635bb9

Please sign in to comment.