File tree 2 files changed +16
-9
lines changed
2 files changed +16
-9
lines changed Original file line number Diff line number Diff line change @@ -81,13 +81,6 @@ class Asset(DictCBORSerializable):
81
81
82
82
VALUE_TYPE = int
83
83
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
-
91
84
def union (self , other : Asset ) -> Asset :
92
85
return self + other
93
86
@@ -570,6 +563,15 @@ class TransactionBody(MapCBORSerializable):
570
563
},
571
564
)
572
565
566
+ def validate (self ):
567
+ if (
568
+ self .mint
569
+ and self .mint .count (lambda p , n , v : v < _MIN_INT64 or v > _MAX_INT64 ) > 0
570
+ ):
571
+ raise InvalidDataException (
572
+ f"Mint amount must be between { _MIN_INT64 } and { _MAX_INT64 } . \n Mint amount: { self .mint } "
573
+ )
574
+
573
575
def hash (self ) -> bytes :
574
576
return blake2b (self .to_cbor (), TRANSACTION_HASH_SIZE , encoder = RawEncoder ) # type: ignore
575
577
Original file line number Diff line number Diff line change @@ -472,7 +472,12 @@ class TestDatum(PlutusData):
472
472
473
473
474
474
def test_out_of_bound_asset ():
475
- bad_asset = Asset ({AssetName (b"abc" ): 1 << 64 })
475
+ a = Asset ({AssetName (b"abc" ): 1 << 64 })
476
476
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
477
482
with pytest .raises (InvalidDataException ):
478
- bad_asset .to_cbor_hex ()
483
+ tx .to_cbor_hex ()
You can’t perform that action at this time.
0 commit comments