Skip to content

Commit 66f911b

Browse files
committed
Add testcase for data list
1 parent e19efb5 commit 66f911b

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

test/pycardano/test_plutus.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import unittest
2+
13
from dataclasses import dataclass
24
from test.pycardano.util import check_two_way_cbor
3-
from typing import Union
5+
from typing import Union, List
46

57
import pytest
68

@@ -39,6 +41,11 @@ class LargestTest(PlutusData):
3941
CONSTR_ID = 9
4042

4143

44+
@dataclass
45+
class ListTest(PlutusData):
46+
a: List[LargestTest]
47+
48+
4249
@dataclass
4350
class VestingParam(PlutusData):
4451
CONSTR_ID = 1
@@ -72,6 +79,19 @@ def test_plutus_data():
7279
check_two_way_cbor(my_vesting)
7380

7481

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+
7595
def test_plutus_data_json():
7696
key_hash = bytes.fromhex("c2ff616e11299d9094ce0a7eb5b7284b705147a822f4ffbd471f971a")
7797
deadline = 1643235300000
@@ -95,6 +115,19 @@ def test_plutus_data_json():
95115
assert my_vesting == VestingParam.from_json(encoded_json)
96116

97117

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+
98131
def test_plutus_data_to_json_wrong_type():
99132
test = MyTest(123, b"1234", IndefiniteList([4, 5, 6]), {1: b"1", 2: b"2"})
100133
test.a = "123"

0 commit comments

Comments
 (0)