Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix StakeRegistration deser #380

Merged
merged 1 commit into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading