File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -61,7 +61,10 @@ def __post_init__(self):
61
61
def from_primitive (
62
62
cls : Type [StakeRegistration ], values : Union [list , tuple ]
63
63
) -> StakeRegistration :
64
- return cls (stake_credential = StakeCredential .from_primitive (values [1 ]))
64
+ if values [0 ] == 0 :
65
+ return cls (stake_credential = StakeCredential .from_primitive (values [1 ]))
66
+ else :
67
+ raise DeserializeException (f"Invalid StakeRegistration type { values [0 ]} " )
65
68
66
69
67
70
@dataclass (repr = False )
Original file line number Diff line number Diff line change
1
+ import os
2
+
3
+ from pycardano import StakeSigningKey , TransactionBody
1
4
from pycardano .address import Address
2
5
from pycardano .certificate import (
3
6
PoolRegistration ,
@@ -121,3 +124,28 @@ def test_pool_retirement():
121
124
)
122
125
123
126
assert PoolRetirement .from_cbor (pool_retirement_cbor_hex ) == pool_retirement
127
+
128
+
129
+ def test_staking_certificate_serdes ():
130
+ staking_key = StakeSigningKey .generate ()
131
+ stake_pool_key_hash = os .urandom (28 )
132
+
133
+ transaction_body = TransactionBody (
134
+ certificates = [
135
+ StakeRegistration (
136
+ stake_credential = StakeCredential (
137
+ staking_key .to_verification_key ().hash ()
138
+ )
139
+ ),
140
+ StakeDelegation (
141
+ stake_credential = StakeCredential (
142
+ staking_key .to_verification_key ().hash ()
143
+ ),
144
+ pool_keyhash = PoolKeyHash (stake_pool_key_hash ),
145
+ ),
146
+ ]
147
+ )
148
+
149
+ after_serdes = TransactionBody .from_cbor (transaction_body .to_cbor ())
150
+
151
+ assert after_serdes == transaction_body
You can’t perform that action at this time.
0 commit comments