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

Commit bd28ba9

Browse files
committed
fix: traverse_bundle checks for zero trytes
If no tx was found, getTrytes returns all '9's. Detecting such cases in traverse_bundle.
1 parent 6072a83 commit bd28ba9

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

iota/commands/extended/traverse_bundle.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import filters as f
88

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

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

test/commands/extended/traverse_bundle_test.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,3 +451,20 @@ def test_missing_transaction(self):
451451
b'ORYCRDX9TOMJPFCRB9R9KPUUGFPVOWYXFIWEW9999'
452452
),
453453
)
454+
455+
def test_missing_transaction_zero_trytes(self):
456+
"""
457+
Unable to find the requested transaction.
458+
getTrytes returned only zeros, no tx was found.
459+
"""
460+
zero_trytes = TransactionTrytes('')
461+
self.adapter.seed_response('getTrytes', {'trytes': [zero_trytes]})
462+
463+
with self.assertRaises(BadApiResponse):
464+
self.command(
465+
transaction =
466+
TransactionHash(
467+
b'FSEWUNJOEGNUI9QOCRFMYSIFAZLJHKZBPQZZYFG9'
468+
b'ORYCRDX9TOMJPFCRB9R9KPUUGFPVOWYXFIWEW9999'
469+
),
470+
)

0 commit comments

Comments
 (0)