Skip to content

Commit

Permalink
Fix StakeRegistration deser
Browse files Browse the repository at this point in the history
  • Loading branch information
cffls committed Oct 6, 2024
1 parent 8a44f92 commit 3ca745a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pycardano/certificate.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ def __post_init__(self):
def from_primitive(
cls: Type[StakeRegistration], values: Union[list, tuple]
) -> StakeRegistration:
return cls(stake_credential=StakeCredential.from_primitive(values[1]))
if values[0] == 0:
return cls(stake_credential=StakeCredential.from_primitive(values[1]))
else:
raise DeserializeException(f"Invalid StakeRegistration type {values[0]}")


@dataclass(repr=False)
Expand Down
28 changes: 28 additions & 0 deletions test/pycardano/test_certificate.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import os

from pycardano import StakeSigningKey, TransactionBody
from pycardano.address import Address
from pycardano.certificate import (
PoolRegistration,
Expand Down Expand Up @@ -121,3 +124,28 @@ def test_pool_retirement():
)

assert PoolRetirement.from_cbor(pool_retirement_cbor_hex) == pool_retirement


def test_staking_certificate_serdes():
staking_key = StakeSigningKey.generate()
stake_pool_key_hash = os.urandom(28)

transaction_body = TransactionBody(
certificates=[
StakeRegistration(
stake_credential=StakeCredential(
staking_key.to_verification_key().hash()
)
),
StakeDelegation(
stake_credential=StakeCredential(
staking_key.to_verification_key().hash()
),
pool_keyhash=PoolKeyHash(stake_pool_key_hash),
),
]
)

after_serdes = TransactionBody.from_cbor(transaction_body.to_cbor())

assert after_serdes == transaction_body

0 comments on commit 3ca745a

Please sign in to comment.