Skip to content

Commit

Permalink
feat(cardano): add vote delegation certificate unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jaskp committed Nov 20, 2023
1 parent d084894 commit 98ed741
Showing 1 changed file with 205 additions and 2 deletions.
207 changes: 205 additions & 2 deletions core/tests/test_apps.cardano.certificate.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from common import *
from trezor import wire
from trezor.enums import CardanoCertificateType
from trezor.messages import CardanoTxCertificate, CardanoPoolParametersType
from trezor.enums import CardanoCertificateType, CardanoDRepType
from trezor.messages import CardanoTxCertificate, CardanoPoolParametersType, CardanoDRep

from apps.common.paths import HARDENED

Expand Down Expand Up @@ -129,6 +129,44 @@ def test_validate_certificate(self):
metadata=None,
),
),
CardanoTxCertificate(
type=CardanoCertificateType.VOTE_DELEGATION,
key_hash=unhexlify(
"29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd"
),
drep=CardanoDRep(
type=CardanoDRepType.KEY_HASH,
key_hash=unhexlify(
"29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd"
),
),
),
CardanoTxCertificate(
type=CardanoCertificateType.VOTE_DELEGATION,
key_hash=unhexlify(
"29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd"
),
drep=CardanoDRep(
type=CardanoDRepType.SCRIPT_HASH,
script_hash=unhexlify(
"29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd"
),
),
),
CardanoTxCertificate(
type=CardanoCertificateType.VOTE_DELEGATION,
key_hash=unhexlify(
"29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd"
),
drep=CardanoDRep(type=CardanoDRepType.ALWAYS_ABSTAIN),
),
CardanoTxCertificate(
type=CardanoCertificateType.VOTE_DELEGATION,
key_hash=unhexlify(
"29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd"
),
drep=CardanoDRep(type=CardanoDRepType.ALWAYS_NO_CONFIDENCE),
),
]

invalid_test_vectors = [
Expand Down Expand Up @@ -511,6 +549,171 @@ def test_validate_certificate(self):
relays_count=1,
),
),
# VOTE_REGISTRATION missing drep
CardanoTxCertificate(
type=CardanoCertificateType.VOTE_DELEGATION,
key_hash=unhexlify(
"29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd"
),
),
# VOTE_REGISTRATION missing key hash
CardanoTxCertificate(
type=CardanoCertificateType.VOTE_DELEGATION,
key_hash=unhexlify(
"29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd"
),
drep=CardanoDRep(type=CardanoDRepType.KEY_HASH),
),
# VOTE_REGISTRATION missing script hash
CardanoTxCertificate(
type=CardanoCertificateType.VOTE_DELEGATION,
script_hash=unhexlify(
"29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd"
),
drep=CardanoDRep(type=CardanoDRepType.SCRIPT_HASH),
),
# VOTE_REGISTRATION unexpected script hash set instead of key hash
CardanoTxCertificate(
type=CardanoCertificateType.VOTE_DELEGATION,
script_hash=unhexlify(
"29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd"
),
drep=CardanoDRep(
type=CardanoDRepType.KEY_HASH,
script_hash=unhexlify(
"29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd"
),
),
),
# VOTE_REGISTRATION unexpected key hash set instead of script hash
CardanoTxCertificate(
type=CardanoCertificateType.VOTE_DELEGATION,
script_hash=unhexlify(
"29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd"
),
drep=CardanoDRep(
type=CardanoDRepType.SCRIPT_HASH,
key_hash=unhexlify(
"29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd"
),
),
),
# VOTE_REGISTRATION key hash set but unexpected script hash
CardanoTxCertificate(
type=CardanoCertificateType.VOTE_DELEGATION,
script_hash=unhexlify(
"29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd"
),
drep=CardanoDRep(
type=CardanoDRepType.KEY_HASH,
key_hash=unhexlify(
"29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd"
),
script_hash=unhexlify(
"29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd"
),
),
),
# VOTE_REGISTRATION script hash set but unexpected key hash
CardanoTxCertificate(
type=CardanoCertificateType.VOTE_DELEGATION,
script_hash=unhexlify(
"29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd"
),
drep=CardanoDRep(
type=CardanoDRepType.SCRIPT_HASH,
key_hash=unhexlify(
"29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd"
),
script_hash=unhexlify(
"29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd"
),
),
),
# VOTE_REGISTRATION unexpected key hash
CardanoTxCertificate(
type=CardanoCertificateType.VOTE_DELEGATION,
key_hash=unhexlify(
"29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd"
),
drep=CardanoDRep(
type=CardanoDRepType.ALWAYS_ABSTAIN,
key_hash=unhexlify(
"29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd"
),
),
),
# VOTE_REGISTRATION unexpected key hash
CardanoTxCertificate(
type=CardanoCertificateType.VOTE_DELEGATION,
key_hash=unhexlify(
"29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd"
),
drep=CardanoDRep(
type=CardanoDRepType.ALWAYS_NO_CONFIDENCE,
key_hash=unhexlify(
"29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd"
),
),
),
# VOTE_REGISTRATION unexpected script hash
CardanoTxCertificate(
type=CardanoCertificateType.VOTE_DELEGATION,
key_hash=unhexlify(
"29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd"
),
drep=CardanoDRep(
type=CardanoDRepType.ALWAYS_ABSTAIN,
script_hash=unhexlify(
"29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd"
),
),
),
# VOTE_REGISTRATION unexpected script hash
CardanoTxCertificate(
type=CardanoCertificateType.VOTE_DELEGATION,
key_hash=unhexlify(
"29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd"
),
drep=CardanoDRep(
type=CardanoDRepType.ALWAYS_NO_CONFIDENCE,
script_hash=unhexlify(
"29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd"
),
),
),
# VOTE_REGISTRATION unexpected script hash and key hash
CardanoTxCertificate(
type=CardanoCertificateType.VOTE_DELEGATION,
key_hash=unhexlify(
"29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd"
),
drep=CardanoDRep(
type=CardanoDRepType.ALWAYS_ABSTAIN,
key_hash=unhexlify(
"29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd"
),
script_hash=unhexlify(
"29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd"
),
),
),
# VOTE_REGISTRATION unexpected script hash and key hash
CardanoTxCertificate(
type=CardanoCertificateType.VOTE_DELEGATION,
key_hash=unhexlify(
"29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd"
),
drep=CardanoDRep(
type=CardanoDRepType.ALWAYS_NO_CONFIDENCE,
key_hash=unhexlify(
"29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd"
),
script_hash=unhexlify(
"29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd"
),
),
),
]

for certificate in valid_test_vectors:
Expand Down

0 comments on commit 98ed741

Please sign in to comment.