Add reference to tx in OneTimeOutput; add exception

pull/93/head
Michał Sałaban 3 years ago
parent 646ae2ba2e
commit 7d3ec1a2e5

@ -59,3 +59,6 @@ class TransactionIncomplete(MoneroException):
class TransactionWithoutBlob(TransactionIncomplete):
pass
class TransactionWithoutJSON(TransactionIncomplete):
pass

@ -88,7 +88,8 @@ class Transaction(object):
@property
def outputs(self):
if not self.json:
raise ValueError('.json attribute not set')
raise exceptions.TransactionWithoutJSON(
'Tx {:s} has no .json attribute'.format(self.hash))
outs = []
for i, vout in enumerate(self.json['vout']):
@ -97,7 +98,7 @@ class Transaction(object):
amount=from_atomic(vout['amount']),
index=self.output_indices[i] if self.output_indices else None,
height=self.height,
txid=self.hash))
transaction=self))
return outs
@ -129,7 +130,7 @@ class OneTimeOutput(object):
index = None
height = None
mask = None
txid = None
transaction = None
unlocked = None
def __init__(self, **kwargs):
@ -138,7 +139,7 @@ class OneTimeOutput(object):
self.index = kwargs.get('index', self.index)
self.height = kwargs.get('height', self.height)
self.mask = kwargs.get('mask', self.mask)
self.txid = kwargs.get('txid', self.txid)
self.transaction = kwargs.get('transaction', self.transaction)
self.unlocked = kwargs.get('unlocked', self.unlocked)
def __repr__(self):
@ -156,7 +157,7 @@ class OneTimeOutput(object):
elif None not in (self.index, other.index, self.amount, other.amount):
return self.index == other.index and self.amount == other.amount
else:
raise TypeError('one-time outputs are not comparable')
raise TypeError('Given one-time outputs (%r,%r) are not comparable'.format(self, other))
def __ne__(self, other):
return not(self == other)

@ -7,6 +7,7 @@ import unittest
from monero.address import address
from monero.numbers import PaymentID
from monero.transaction import IncomingPayment, Transaction, OneTimeOutput, _ByHeight
from monero import exceptions
class FiltersTestCase(unittest.TestCase):
def setUp(self):
@ -48,13 +49,15 @@ class FiltersTestCase(unittest.TestCase):
def test_outputs(self):
out1, out2 = self.tx2.outputs
self.assertEqual(out1.transaction, self.tx2)
self.assertEqual(out2.transaction, self.tx2)
self.assertIn(self.json1['vout'][0]['target']['key'], repr(out1))
self.assertFalse(out2 != OneTimeOutput(pubkey=self.json1['vout'][1]['target']['key']))
self.assertIn('(index=25973289,amount=0E-12)', repr(self.oto1))
self.assertEqual(self.oto1, OneTimeOutput(index=25973289, amount=Decimal('0.000000000000')))
with self.assertRaises(ValueError):
failed_outs = self.tx1.outputs
with self.assertRaises(exceptions.TransactionWithoutJSON):
self.tx1.outputs
with self.assertRaises(TypeError):
self.oto1 == self.oto2

Loading…
Cancel
Save