1
+ import unittest
2
+
1
3
from dataclasses import dataclass
2
4
from test .pycardano .util import check_two_way_cbor
3
- from typing import Union
5
+ from typing import Union , List
4
6
5
7
import pytest
6
8
@@ -39,6 +41,11 @@ class LargestTest(PlutusData):
39
41
CONSTR_ID = 9
40
42
41
43
44
+ @dataclass
45
+ class ListTest (PlutusData ):
46
+ a : List [LargestTest ]
47
+
48
+
42
49
@dataclass
43
50
class VestingParam (PlutusData ):
44
51
CONSTR_ID = 1
@@ -72,6 +79,19 @@ def test_plutus_data():
72
79
check_two_way_cbor (my_vesting )
73
80
74
81
82
+ @unittest .skip (
83
+ "From CBOR is generally not correctly implemented for tags > 7, so this test fails"
84
+ )
85
+ def test_plutus_data_list_cbor ():
86
+ test = ListTest ([LargestTest (), LargestTest ()])
87
+
88
+ encoded_cbor = test .to_cbor ()
89
+
90
+ assert "d8799f82d9050280d9050280ff" == encoded_cbor
91
+
92
+ assert test == ListTest .from_cbor (encoded_cbor )
93
+
94
+
75
95
def test_plutus_data_json ():
76
96
key_hash = bytes .fromhex ("c2ff616e11299d9094ce0a7eb5b7284b705147a822f4ffbd471f971a" )
77
97
deadline = 1643235300000
@@ -95,6 +115,19 @@ def test_plutus_data_json():
95
115
assert my_vesting == VestingParam .from_json (encoded_json )
96
116
97
117
118
+ def test_plutus_data_list_json ():
119
+ test = ListTest ([LargestTest (), LargestTest ()])
120
+
121
+ encoded_json = test .to_json (separators = ("," , ":" ))
122
+
123
+ assert (
124
+ '{"constructor":0,"fields":[[{"constructor":9,"fields":[]},{"constructor":9,"fields":[]}]]}'
125
+ == encoded_json
126
+ )
127
+
128
+ assert test == ListTest .from_json (encoded_json )
129
+
130
+
98
131
def test_plutus_data_to_json_wrong_type ():
99
132
test = MyTest (123 , b"1234" , IndefiniteList ([4 , 5 , 6 ]), {1 : b"1" , 2 : b"2" })
100
133
test .a = "123"
0 commit comments