File tree Expand file tree Collapse file tree 4 files changed +24
-4
lines changed Expand file tree Collapse file tree 4 files changed +24
-4
lines changed Original file line number Diff line number Diff line change @@ -1204,14 +1204,16 @@ def build_witness_set(
1204
1204
f"Unsupported script type: { type (script )} "
1205
1205
)
1206
1206
1207
- return TransactionWitnessSet (
1207
+ witness_set = TransactionWitnessSet (
1208
1208
native_scripts = native_scripts if native_scripts else None ,
1209
1209
plutus_v1_script = plutus_v1_scripts if plutus_v1_scripts else None ,
1210
1210
plutus_v2_script = plutus_v2_scripts if plutus_v2_scripts else None ,
1211
1211
plutus_v3_script = plutus_v3_scripts if plutus_v3_scripts else None ,
1212
1212
redeemer = self .redeemers () if self ._redeemer_list else None ,
1213
1213
plutus_data = plutus_data if plutus_data else None ,
1214
1214
)
1215
+ witness_set .convert_to_latest_spec ()
1216
+ return witness_set
1215
1217
1216
1218
def _ensure_no_input_exclusion_conflict (self ):
1217
1219
intersection = set (self .inputs ).intersection (set (self .excluded_inputs ))
Original file line number Diff line number Diff line change @@ -108,7 +108,7 @@ class TransactionWitnessSet(MapCBORSerializable):
108
108
},
109
109
)
110
110
111
- plutus_data : Optional [Union [IndefiniteList , List [Any ], NonEmptyOrderedSet [Any ]]] = (
111
+ plutus_data : Optional [Union [List [Any ], IndefiniteList , NonEmptyOrderedSet [Any ]]] = (
112
112
field (
113
113
default = None ,
114
114
metadata = {"optional" : True , "key" : 4 },
@@ -140,7 +140,7 @@ class TransactionWitnessSet(MapCBORSerializable):
140
140
},
141
141
)
142
142
143
- def __post_init__ (self ):
143
+ def convert_to_latest_spec (self ):
144
144
# Convert lists to NonEmptyOrderedSet for fields that should use NonEmptyOrderedSet
145
145
if isinstance (self .vkey_witnesses , list ):
146
146
self .vkey_witnesses = NonEmptyOrderedSet (self .vkey_witnesses )
Original file line number Diff line number Diff line change @@ -761,6 +761,7 @@ def test_transaction_witness_set_with_ordered_sets():
761
761
762
762
# Test conversion from list to NonEmptyOrderedSet
763
763
witness_set = TransactionWitnessSet (vkey_witnesses = [witness ])
764
+ witness_set .convert_to_latest_spec ()
764
765
assert isinstance (witness_set .vkey_witnesses , NonEmptyOrderedSet )
765
766
assert witness in witness_set .vkey_witnesses
766
767
@@ -772,11 +773,13 @@ def test_transaction_witness_set_with_ordered_sets():
772
773
773
774
# Test empty list conversion
774
775
witness_set = TransactionWitnessSet (vkey_witnesses = [])
776
+ witness_set .convert_to_latest_spec ()
775
777
with pytest .raises (ValueError , match = "NonEmptyOrderedSet cannot be empty" ):
776
778
witness_set .to_validated_primitive ()
777
779
778
780
# Test None value
779
781
witness_set = TransactionWitnessSet (vkey_witnesses = None )
782
+ witness_set .convert_to_latest_spec ()
780
783
primitive = witness_set .to_primitive ()
781
784
restored = TransactionWitnessSet .from_primitive (primitive )
782
785
assert restored .vkey_witnesses is None
Original file line number Diff line number Diff line change
1
+ import json
1
2
import tempfile
2
3
3
- from pycardano import PaymentSigningKey , PaymentVerificationKey , VerificationKeyWitness
4
+ from pycardano import (
5
+ PaymentSigningKey ,
6
+ PaymentVerificationKey ,
7
+ Transaction ,
8
+ TransactionWitnessSet ,
9
+ Unit ,
10
+ VerificationKeyWitness ,
11
+ )
4
12
5
13
6
14
def test_witness_save_load ():
@@ -17,3 +25,10 @@ def test_witness_save_load():
17
25
assert witness == loaded_witness
18
26
19
27
assert witness != vk
28
+
29
+
30
+ def test_redeemer_decode ():
31
+ witness = TransactionWitnessSet (plutus_data = [Unit ()])
32
+ encoded = witness .to_cbor ()
33
+ decoded = TransactionWitnessSet .from_cbor (encoded )
34
+ assert isinstance (decoded .plutus_data , list )
You can’t perform that action at this time.
0 commit comments