Skip to content

Commit f69ddd5

Browse files
committed
cert test bugs fix
1 parent 0a81cc5 commit f69ddd5

File tree

3 files changed

+30
-27
lines changed

3 files changed

+30
-27
lines changed

integration-test/test/test_certificate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def test_stake_delegation(self):
5555

5656
anchor = Anchor(
5757
url="https://drep.com",
58-
data_hash=AnchorDataHash(bytes.fromhex("0" * 64)),
58+
data_hash=AnchorDataHash((bytes.fromhex("0" * 64))),
5959
)
6060

6161
drep_registration = RegDRepCert(

pycardano/certificate.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,6 @@ class Anchor(ArrayCBORSerializable):
4949
url: str
5050
data_hash: AnchorDataHash
5151

52-
@classmethod
53-
@limit_primitive_type(list)
54-
def from_primitive(cls: Type[Anchor], values: Union[list, tuple]) -> Anchor:
55-
return cls(url=values[0], data_hash=values[1])
56-
5752

5853
@dataclass(repr=False)
5954
class StakeCredential(ArrayCBORSerializable):

test/pycardano/test_certificate.py

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import pytest
44

5-
from pycardano import StakeSigningKey, TransactionBody
5+
from pycardano import AnchorDataHash, StakeSigningKey, TransactionBody
66
from pycardano.address import Address
77
from pycardano.certificate import (
88
Anchor,
@@ -171,51 +171,57 @@ def test_staking_certificate_serdes():
171171

172172
def test_anchor():
173173
url = "https://example.com"
174-
data_hash = bytes.fromhex("1234567890" * 6 + "12") # 32 bytes
174+
data_hash = AnchorDataHash(bytes.fromhex("0" * 64)) # 32 bytes
175175
anchor = Anchor(url=url, data_hash=data_hash)
176176

177177
anchor_cbor_hex = anchor.to_cbor_hex()
178178

179179
assert (
180180
anchor_cbor_hex
181-
== "827368747470733a2f2f6578616d706c652e636f6d581f12345678901234567890123456789012345678901234567890123456789012"
181+
== "827368747470733a2f2f6578616d706c652e636f6d58200000000000000000000000000000000000000000000000000000000000000000"
182182
)
183183

184184
assert Anchor.from_cbor(anchor_cbor_hex) == anchor
185185

186186

187187
def test_drep_credential():
188-
stake_credential = StakeCredential(TEST_ADDR.staking_part)
189-
drep_credential = DRepCredential(stake_credential, coin=0)
188+
staking_key = StakeSigningKey.from_cbor(
189+
"5820ff3a330df8859e4e5f42a97fcaee73f6a00d0cf864f4bca902bd106d423f02c0"
190+
)
191+
drep_credential = DRepCredential(staking_key.to_verification_key().hash())
190192
drep_credential_cbor_hex = drep_credential.to_cbor_hex()
191193
assert (
192194
drep_credential_cbor_hex
193-
== "84108200581c4828a2dadba97ca9fd0cdc99975899470c219bdc0d828cfa6ddf6d6900f6"
195+
== "8200581c4828a2dadba97ca9fd0cdc99975899470c219bdc0d828cfa6ddf6d69"
194196
)
195197
assert DRepCredential.from_cbor(drep_credential_cbor_hex) == drep_credential
196198

197199

198200
def test_unreg_drep_certificate():
199-
stake_credential = StakeCredential(TEST_ADDR.staking_part)
200-
drep_credential = DRepCredential(stake_credential, coin=0)
201+
staking_key = StakeSigningKey.from_cbor(
202+
"5820ff3a330df8859e4e5f42a97fcaee73f6a00d0cf864f4bca902bd106d423f02c0"
203+
)
204+
drep_credential = DRepCredential(staking_key.to_verification_key().hash())
201205
coin = 1000000
202206
unreg_drep_cert = UnregDRepCertificate(drep_credential=drep_credential, coin=coin)
203207

204208
unreg_drep_cert_cbor_hex = unreg_drep_cert.to_cbor_hex()
205209

206210
assert (
207211
unreg_drep_cert_cbor_hex
208-
== "831184108200581c4828a2dadba97ca9fd0cdc99975899470c219bdc0d828cfa6ddf6d6900f61a000f4240"
212+
== "83118200581c4828a2dadba97ca9fd0cdc99975899470c219bdc0d828cfa6ddf6d691a000f4240"
209213
)
210214

211215
assert UnregDRepCertificate.from_cbor(unreg_drep_cert_cbor_hex) == unreg_drep_cert
212216

213217

214218
def test_update_drep_certificate_with_anchor():
215-
stake_credential = StakeCredential(TEST_ADDR.staking_part)
216-
drep_credential = DRepCredential(stake_credential, coin=0)
219+
staking_key = StakeSigningKey.from_cbor(
220+
"5820ff3a330df8859e4e5f42a97fcaee73f6a00d0cf864f4bca902bd106d423f02c0"
221+
)
222+
drep_credential = DRepCredential(staking_key.to_verification_key().hash())
217223
url = "https://pycardano.com"
218-
data_hash = bytes.fromhex("1234567890" * 6 + "12") # 32 bytes
224+
data_hash = AnchorDataHash(bytes.fromhex("0" * 64)) # 32 bytes
219225
anchor = Anchor(url=url, data_hash=data_hash)
220226
update_drep_cert = UpdateDRepCertificate(
221227
drep_credential=drep_credential, anchor=anchor
@@ -225,7 +231,7 @@ def test_update_drep_certificate_with_anchor():
225231

226232
assert (
227233
update_drep_cert_cbor_hex
228-
== "831284108200581c4828a2dadba97ca9fd0cdc99975899470c219bdc0d828cfa6ddf6d6900f6827568747470733a2f2f707963617264616e6f2e636f6d581f12345678901234567890123456789012345678901234567890123456789012"
234+
== "83128200581c4828a2dadba97ca9fd0cdc99975899470c219bdc0d828cfa6ddf6d69827568747470733a2f2f707963617264616e6f2e636f6d58200000000000000000000000000000000000000000000000000000000000000000"
229235
)
230236

231237
assert (
@@ -234,16 +240,18 @@ def test_update_drep_certificate_with_anchor():
234240

235241

236242
def test_update_drep_certificate_without_anchor():
237-
stake_credential = StakeCredential(TEST_ADDR.staking_part)
238-
drep_credential = DRepCredential(stake_credential, coin=0)
243+
staking_key = StakeSigningKey.from_cbor(
244+
"5820ff3a330df8859e4e5f42a97fcaee73f6a00d0cf864f4bca902bd106d423f02c0"
245+
)
246+
drep_credential = DRepCredential(staking_key.to_verification_key().hash())
239247
update_drep_cert = UpdateDRepCertificate(
240248
drep_credential=drep_credential, anchor=None
241249
)
242250
update_drep_cert_cbor_hex = update_drep_cert.to_cbor_hex()
243251

244252
assert (
245253
update_drep_cert_cbor_hex
246-
== "831284108200581c4828a2dadba97ca9fd0cdc99975899470c219bdc0d828cfa6ddf6d6900f6f6"
254+
== "83128200581c4828a2dadba97ca9fd0cdc99975899470c219bdc0d828cfa6ddf6d69f6"
247255
)
248256

249257
assert (
@@ -275,7 +283,7 @@ def test_auth_committee_hot_certificate():
275283
def test_resign_committee_cold_certificate_with_anchor():
276284
committee_cold_credential = StakeCredential(TEST_ADDR.staking_part)
277285
url = "https://pycardano.com"
278-
data_hash = bytes.fromhex("1234567890" * 6 + "12")
286+
data_hash = AnchorDataHash(bytes.fromhex("0" * 64))
279287
anchor = Anchor(url=url, data_hash=data_hash)
280288
resign_committee_cold_cert = ResignCommitteeColdCertificate(
281289
committee_cold_credential=committee_cold_credential,
@@ -286,7 +294,7 @@ def test_resign_committee_cold_certificate_with_anchor():
286294

287295
assert (
288296
resign_committee_cold_cert_cbor_hex
289-
== "830f8200581c4828a2dadba97ca9fd0cdc99975899470c219bdc0d828cfa6ddf6d69827568747470733a2f2f707963617264616e6f2e636f6d581f12345678901234567890123456789012345678901234567890123456789012"
297+
== "830f8200581c4828a2dadba97ca9fd0cdc99975899470c219bdc0d828cfa6ddf6d69827568747470733a2f2f707963617264616e6f2e636f6d58200000000000000000000000000000000000000000000000000000000000000000"
290298
)
291299

292300
assert (
@@ -353,8 +361,8 @@ def test_invalid_certificate_types():
353361
)
354362
assert "Invalid ResignCommitteeColdCertificate type 14" in str(excinfo.value)
355363

356-
stake_credential = StakeCredential(TEST_ADDR.staking_part)
357-
drep_credential = DRepCredential(stake_credential, coin=0)
364+
staking_key = StakeSigningKey.generate()
365+
drep_credential = DRepCredential(staking_key.to_verification_key().hash())
358366

359367
with pytest.raises(DeserializeException) as excinfo:
360368
UnregDRepCertificate.from_primitive([18, drep_credential, 1000000])
@@ -378,7 +386,7 @@ def test_certificate_in_transaction():
378386
)
379387

380388
url = "https://example.com"
381-
data_hash = bytes.fromhex("1234567890" * 6 + "12") # 32 bytes
389+
data_hash = AnchorDataHash(bytes.fromhex("0" * 64)) # 32 bytes
382390
anchor = Anchor(url=url, data_hash=data_hash)
383391
resign_committee_cold_cert = ResignCommitteeColdCertificate(
384392
committee_cold_credential=committee_cold_credential,

0 commit comments

Comments
 (0)