Skip to content

Commit e0cbb1a

Browse files
committed
Only raise exception when minting assets whose values are out of bound
1 parent 0daa16e commit e0cbb1a

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

pycardano/transaction.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,6 @@ class Asset(DictCBORSerializable):
8181

8282
VALUE_TYPE = int
8383

84-
def validate(self):
85-
for n in self:
86-
if self[n] < _MIN_INT64 or self[n] > _MAX_INT64:
87-
raise InvalidDataException(
88-
f"Asset amount must be between {_MIN_INT64} and {_MAX_INT64}: \n {self[n]}"
89-
)
90-
9184
def union(self, other: Asset) -> Asset:
9285
return self + other
9386

@@ -571,6 +564,15 @@ class TransactionBody(MapCBORSerializable):
571564
},
572565
)
573566

567+
def validate(self):
568+
if (
569+
self.mint
570+
and self.mint.count(lambda p, n, v: v < _MIN_INT64 or v > _MAX_INT64) > 0
571+
):
572+
raise InvalidDataException(
573+
f"Mint amount must be between {_MIN_INT64} and {_MAX_INT64}. \n Mint amount: {self.mint}"
574+
)
575+
574576
def hash(self) -> bytes:
575577
return blake2b(self.to_cbor(), TRANSACTION_HASH_SIZE, encoder=RawEncoder) # type: ignore
576578

test/pycardano/test_transaction.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,12 @@ class TestDatum(PlutusData):
472472

473473

474474
def test_out_of_bound_asset():
475-
bad_asset = Asset({AssetName(b"abc"): 1 << 64})
475+
a = Asset({AssetName(b"abc"): 1 << 64})
476476

477+
a.to_cbor_hex() # okay to have out of bound asset
478+
479+
tx = TransactionBody(mint=MultiAsset({ScriptHash(b"1" * SCRIPT_HASH_SIZE): a}))
480+
481+
# Not okay only when minting
477482
with pytest.raises(InvalidDataException):
478-
bad_asset.to_cbor_hex()
483+
tx.to_cbor_hex()

0 commit comments

Comments
 (0)