Skip to content

Commit

Permalink
Add tx & certificate related golden tests using hedgehog
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimbo4350 committed Jul 1, 2020
1 parent 0f10d1a commit d89f36b
Show file tree
Hide file tree
Showing 50 changed files with 647 additions and 111 deletions.
4 changes: 1 addition & 3 deletions cardano-api/src/Cardano/Api/Typed.hs
Expand Up @@ -843,7 +843,6 @@ instance SerialiseAsCBOR (TxBody Shelley) where
fromCBOR
(LBS.fromStrict bs)


instance HasTextEnvelope (TxBody Byron) where
textEnvelopeType _ = "TxUnsignedByron"

Expand Down Expand Up @@ -970,7 +969,6 @@ instance SerialiseAsCBOR (Tx Shelley) where
ShelleyTx <$>
CBOR.decodeAnnotator "Shelley Tx" fromCBOR (LBS.fromStrict bs)


instance HasTextEnvelope (Tx Byron) where
textEnvelopeType _ = "TxSignedByron"

Expand Down Expand Up @@ -1343,7 +1341,7 @@ newtype Certificate = Certificate (Shelley.DCert ShelleyCrypto)
instance HasTypeProxy Certificate where
data AsType Certificate = AsCertificate
proxyToAsType _ = AsCertificate

-- TODO: Golden tests certificates
instance HasTextEnvelope Certificate where
textEnvelopeType _ = "Certificate"
textEnvelopeDefaultDescr (Certificate cert) = case cert of
Expand Down
23 changes: 16 additions & 7 deletions cardano-cli/cardano-cli.cabal
Expand Up @@ -186,14 +186,23 @@ test-suite cardano-cli-pioneers
, transformers-except

other-modules: Test.CLI.Byron.TextEnvelope.Golden.PaymentKeys
Test.CLI.Shelley.TextEnvelope.Golden.GenesisDelegateKeys
Test.CLI.Shelley.TextEnvelope.Golden.GenesisKeys
Test.CLI.Shelley.TextEnvelope.Golden.GenesisUTxOKeys
Test.CLI.Shelley.TextEnvelope.Golden.KESKeys
Test.CLI.Shelley.TextEnvelope.Golden.PaymentKeys
Test.CLI.Shelley.TextEnvelope.Golden.StakeKeys
Test.CLI.Byron.TextEnvelope.Golden.Tx
Test.CLI.Byron.TextEnvelope.Golden.TxBody
Test.CLI.Byron.TextEnvelope.Golden.Witness
Test.CLI.Shelley.TextEnvelope.Golden.Certificates.OperationalCertificate
Test.CLI.Shelley.TextEnvelope.Golden.Certificates.StakeAddressCertificates
Test.CLI.Shelley.TextEnvelope.Golden.Certificates.StakePoolCertificates
Test.CLI.Shelley.TextEnvelope.Golden.Keys.GenesisDelegateKeys
Test.CLI.Shelley.TextEnvelope.Golden.Keys.GenesisKeys
Test.CLI.Shelley.TextEnvelope.Golden.Keys.GenesisUTxOKeys
Test.CLI.Shelley.TextEnvelope.Golden.Keys.KESKeys
Test.CLI.Shelley.TextEnvelope.Golden.Keys.PaymentKeys
Test.CLI.Shelley.TextEnvelope.Golden.Keys.StakeKeys
Test.CLI.Shelley.TextEnvelope.Golden.Keys.VRFKeys
Test.CLI.Shelley.TextEnvelope.Golden.Tests
Test.CLI.Shelley.TextEnvelope.Golden.VRFKeys
Test.CLI.Shelley.TextEnvelope.Golden.Tx.Tx
Test.CLI.Shelley.TextEnvelope.Golden.Tx.TxBody
Test.CLI.Shelley.TextEnvelope.Golden.Tx.Witness
Test.ITN
Test.OptParse
Test.Pioneers.Exercise1
Expand Down
4 changes: 4 additions & 0 deletions cardano-cli/stake-address-deregistration-certificate
@@ -0,0 +1,4 @@
type: Certificate
title: Stake Address Deregistration Certificate
cbor-hex:
82018200581c58b57f6f7f11182cb0670bab031a56dfb4bb2945a5ccf3a99106b8ab
Expand Up @@ -10,8 +10,8 @@ import Hedgehog (Property)



-- | 1. We generate a key pair
-- 2. We check for the existence of the key pair
-- 3. We check the TextEnvelope serialization format has not changed.
-- | 1. Generate a key pair
-- 2. Check for the existence of the key pair
-- 3. Check the TextEnvelope serialization format has not changed.
golden_byronPaymentKeys :: Property
golden_byronPaymentKeys = panic "TODO"
13 changes: 13 additions & 0 deletions cardano-cli/test/Test/CLI/Byron/TextEnvelope/Golden/Tx.hs
@@ -0,0 +1,13 @@
{-# LANGUAGE OverloadedStrings #-}

module Test.CLI.Byron.TextEnvelope.Golden.Tx
( golden_byronTx
) where

import Cardano.Prelude

import Hedgehog (Property)


golden_byronTx :: Property
golden_byronTx = panic "TODO"
13 changes: 13 additions & 0 deletions cardano-cli/test/Test/CLI/Byron/TextEnvelope/Golden/TxBody.hs
@@ -0,0 +1,13 @@
{-# LANGUAGE OverloadedStrings #-}

module Test.CLI.Byron.TextEnvelope.Golden.TxBody
( golden_byronTxBody
) where

import Cardano.Prelude

import Hedgehog (Property)


golden_byronTxBody :: Property
golden_byronTxBody = panic "TODO"
13 changes: 13 additions & 0 deletions cardano-cli/test/Test/CLI/Byron/TextEnvelope/Golden/Witness.hs
@@ -0,0 +1,13 @@
{-# LANGUAGE OverloadedStrings #-}

module Test.CLI.Byron.TextEnvelope.Golden.Witness
( golden_byronWitness
) where

import Cardano.Prelude

import Hedgehog (Property)


golden_byronWitness :: Property
golden_byronWitness = panic "TODO"
@@ -0,0 +1,76 @@
{-# LANGUAGE OverloadedStrings #-}

module Test.CLI.Shelley.TextEnvelope.Golden.Certificates.OperationalCertificate
( golden_shelleyOperationalCertificate
) where

import Cardano.Prelude

import Cardano.Api.Typed (AsType(..), HasTextEnvelope (..))

import Hedgehog (Property)
import qualified Hedgehog as H

import Test.OptParse

-- | 1. Create KES key pair.
-- 2. Create cold keys.
-- 3. Create operational certificate.
-- 4. Check the TextEnvelope serialization format has not changed.
golden_shelleyOperationalCertificate :: Property
golden_shelleyOperationalCertificate =
propertyOnce $ do

-- Reference keys
let referenceOperationalCertificate = "test/Test/golden/shelley/certificates/operational_certificate"

-- Key filepaths
let kesVerKey = "KES-verification-key-file"
kesSignKey = "KES-signing-key-file"
coldVerKey = "cold-verification-key-file"
coldSignKey = "cold-signing-key-file"
operationalCertCounter = "operational-certificate-counter-file"
operationalCert = "operational-certificate-file"
createdFiles = [kesVerKey, kesSignKey, coldVerKey, coldSignKey, operationalCertCounter, operationalCert]

-- Create KES key pair
execCardanoCLIParser
createdFiles
$ evalCardanoCLIParser [ "shelley","node","key-gen-KES"
, "--verification-key-file", kesVerKey
, "--signing-key-file", kesSignKey
]

assertFilesExist [kesSignKey, kesVerKey]

-- Create cold key pair
execCardanoCLIParser
createdFiles
$ evalCardanoCLIParser [ "shelley","node","key-gen"
, "--cold-verification-key-file", coldVerKey
, "--cold-signing-key-file", coldSignKey
, "--operational-certificate-issue-counter", operationalCertCounter
]

assertFilesExist [coldVerKey, coldSignKey, operationalCertCounter]

-- Create operational certificate
execCardanoCLIParser
createdFiles
$ evalCardanoCLIParser [ "shelley","node","issue-op-cert"
, "--kes-verification-key-file", kesVerKey
, "--cold-signing-key-file", coldSignKey
, "--operational-certificate-issue-counter", operationalCertCounter
, "--kes-period", "1000"
, "--out-file", operationalCert
]

assertFilesExist createdFiles
let operationalCertificateType = textEnvelopeType AsOperationalCertificate

-- Check the newly created files have not deviated from the
-- golden files
checkTextEnvelopeFormat createdFiles operationalCertificateType referenceOperationalCertificate operationalCert

liftIO $ fileCleanup createdFiles
H.success
@@ -0,0 +1,88 @@
{-# LANGUAGE OverloadedStrings #-}

module Test.CLI.Shelley.TextEnvelope.Golden.Certificates.StakeAddressCertificates
( golden_shelleyStakeAddressCertificates
) where

import Cardano.Prelude

import Cardano.Api.Typed (AsType(..), HasTextEnvelope (..))

import Hedgehog (Property)
import qualified Hedgehog as H

import Test.OptParse

-- | 1. Generate a stake verification key
-- 2. Create a stake address registration certificate
-- 3. Check the TextEnvelope serialization format has not changed.
golden_shelleyStakeAddressCertificates :: Property
golden_shelleyStakeAddressCertificates =
propertyOnce $ do

-- Reference files
let referenceRegistrationCertificate = "test/Test/golden/shelley/certificates/stake_address_registration_certificate"
referenceDeregistrationCertificate = "test/Test/golden/shelley/certificates/stake_address_deregistration_certificate"

-- Key filepaths
let verKey = "stake-verification-key-file"
signKey = "stake-signing-key-file"
deregistrationCertificate = "stake-address-deregistration-certificate"
registrationCertificate = "stake-address-registration-certificate"
createdFiles = [verKey, signKey, registrationCertificate]

-- Generate stake verification key
execCardanoCLIParser
createdFiles
$ evalCardanoCLIParser [ "shelley","stake-address","key-gen"
, "--verification-key-file", verKey
, "--signing-key-file", signKey
]
assertFilesExist [verKey, signKey]

-- Create stake address registration certificate
execCardanoCLIParser
createdFiles
$ evalCardanoCLIParser [ "shelley","stake-address","registration-certificate"
, "--stake-verification-key-file", verKey
, "--out-file", registrationCertificate
]

let registrationCertificateType = textEnvelopeType AsCertificate

-- Check the newly created files have not deviated from the
-- golden files
checkTextEnvelopeFormat createdFiles registrationCertificateType referenceRegistrationCertificate registrationCertificate


-- Create stake address deregistration certificate
execCardanoCLIParser
createdFiles
$ evalCardanoCLIParser [ "shelley","stake-address","deregistration-certificate"
, "--stake-verification-key-file", verKey
, "--out-file", deregistrationCertificate
]

-- Check the newly created files have not deviated from the
-- golden files
checkTextEnvelopeFormat createdFiles registrationCertificateType referenceDeregistrationCertificate deregistrationCertificate

-- TODO: After delegation-certificate command is fixed to take a hash instead of a verfication key
{-
-- Create stake address delegation certificate
execCardanoCLIParser
createdFiles
$ evalCardanoCLIParser [ "shelley","stake-address","delegation-certificate"
, "--stake-verification-key-file", verKey
, "--cold-verification-key-file", verKey --TODO: Should be stake pool's hash
, "--out-file", deregistrationCertificate
]
-- Check the newly created files have not deviated from the
-- golden files
checkTextEnvelopeFormat createdFiles registrationCertificateType referenceDeregistrationCertificate deregistrationCertificate
-}

liftIO $ fileCleanup createdFiles
H.success

0 comments on commit d89f36b

Please sign in to comment.