File tree 3 files changed +24
-0
lines changed
3 files changed +24
-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 ):
@@ -78,6 +81,13 @@ class Asset(DictCBORSerializable):
78
81
79
82
VALUE_TYPE = int
80
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
+
81
91
def union (self , other : Asset ) -> Asset :
82
92
return self + other
83
93
Original file line number Diff line number Diff line change @@ -469,3 +469,10 @@ 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
+ bad_asset = Asset ({AssetName (b"abc" ): 1 << 64 })
476
+
477
+ with pytest .raises (InvalidDataException ):
478
+ bad_asset .to_cbor_hex ()
You can’t perform that action at this time.
0 commit comments