Skip to content

Commit b7960c3

Browse files
authored
Merge branch 'Python-Cardano:main' into feat_cert_script
2 parents 3161ef9 + 3034cd9 commit b7960c3

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

pycardano/backend/ogmios_v6.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ def _utxo_from_ogmios_result(self, utxo: OgmiosUtxo) -> UTxO:
263263
# TODO: Need to test with native scripts
264264
if script["language"] == "plutus:v3":
265265
script = PlutusV3Script(bytes.fromhex(script["cbor"]))
266-
if script["language"] == "plutus:v2":
266+
elif script["language"] == "plutus:v2":
267267
script = PlutusV2Script(bytes.fromhex(script["cbor"]))
268268
elif script["language"] == "plutus:v1":
269269
script = PlutusV1Script(bytes.fromhex(script["cbor"]))

pycardano/certificate.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ def __post_init__(self):
6161
def from_primitive(
6262
cls: Type[StakeRegistration], values: Union[list, tuple]
6363
) -> 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]}")
6568

6669

6770
@dataclass(repr=False)

test/pycardano/test_certificate.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import os
2+
3+
from pycardano import StakeSigningKey, TransactionBody
14
from pycardano.address import Address
25
from pycardano.certificate import (
36
PoolRegistration,
@@ -121,3 +124,28 @@ def test_pool_retirement():
121124
)
122125

123126
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

0 commit comments

Comments
 (0)