File tree Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -870,6 +870,13 @@ def __copy__(self):
870
870
def __deepcopy__ (self , memodict = {}):
871
871
return self .__class__ (deepcopy (self .data ))
872
872
873
+ def validate (self ):
874
+ for key , value in self .data .items ():
875
+ if isinstance (key , CBORSerializable ):
876
+ key .validate ()
877
+ if isinstance (value , CBORSerializable ):
878
+ value .validate ()
879
+
873
880
def to_shallow_primitive (self ) -> dict :
874
881
# Sort keys in a map according to https://datatracker.ietf.org/doc/html/rfc7049#section-3.9
875
882
def _get_sortable_val (key ):
Original file line number Diff line number Diff line change 54
54
"Withdrawals" ,
55
55
]
56
56
57
+ _MAX_INT64 = (1 << 63 ) - 1
58
+ _MIN_INT64 = - (1 << 63 )
59
+
57
60
58
61
@dataclass (repr = False )
59
62
class TransactionInput (ArrayCBORSerializable ):
@@ -561,6 +564,15 @@ class TransactionBody(MapCBORSerializable):
561
564
},
562
565
)
563
566
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
+
564
576
def hash (self ) -> bytes :
565
577
return blake2b (self .to_cbor (), TRANSACTION_HASH_SIZE , encoder = RawEncoder ) # type: ignore
566
578
Original file line number Diff line number Diff line change @@ -469,3 +469,15 @@ class TestDatum(PlutusData):
469
469
cbor = output .to_cbor_hex ()
470
470
471
471
assert cbor == TransactionOutput .from_cbor (cbor ).to_cbor_hex ()
472
+
473
+
474
+ def test_out_of_bound_asset ():
475
+ a = Asset ({AssetName (b"abc" ): 1 << 64 })
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
482
+ with pytest .raises (InvalidDataException ):
483
+ tx .to_cbor_hex ()
You can’t perform that action at this time.
0 commit comments