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 f8ed7a9
Show file tree
Hide file tree
Showing 51 changed files with 642 additions and 110 deletions.
2 changes: 0 additions & 2 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
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
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"
Empty file.
@@ -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, deregistrationCertificate, 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,0 +1,124 @@
{-# LANGUAGE OverloadedStrings #-}

module Test.CLI.Shelley.TextEnvelope.Golden.Certificates.StakePoolCertificates
( golden_shelleyStakePoolCertificates
) where

import Cardano.Prelude

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

import Hedgehog (Property)
import qualified Hedgehog as H

import Test.OptParse

-- | 1. Create cold key pair.
-- 2. Create stake key pair.
-- 3. Create VRF key pair.
-- 4. Create stake pool registration certificate.
-- 5. Create stake pool deregistration/retirement certificate.
-- 6. Check the TextEnvelope serialization format has not changed.
golden_shelleyStakePoolCertificates :: Property
golden_shelleyStakePoolCertificates =
propertyOnce $ do

-- Reference files
let referenceRegistrationCertificate = "test/Test/golden/shelley/certificates/stake_pool_registration_certificate"
referenceDeregistrationCertificate = "test/Test/golden/shelley/certificates/stake_pool_deregistration_certificate"

-- Key filepaths
let coldVerKey = "cold-verification-key-file"
coldSignKey = "cold-signing-key-file"
operationalCertCounter = "operational-certificate-counter-file"
vrfVerKey = "vrf-verification-key-file"
vrfSignKey = "vrf-signing-key-file"
poolRewardAccountAndOwnerVerKey = "reward-account-verification-key-file"
poolRewardAccountSignKey = "reward-account-signing-key-file"
registrationCertificate = "stake-pool-registration-certificate"
deregistrationCertificate = "stake-pool-deregistration-certificate"
createdFiles = [ coldVerKey
, coldSignKey
, operationalCertCounter
, vrfVerKey
, vrfSignKey
, poolRewardAccountAndOwnerVerKey
, poolRewardAccountSignKey
, registrationCertificate
, deregistrationCertificate
]

-- 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 [coldSignKey, coldVerKey, operationalCertCounter]

-- Generate stake key pair
execCardanoCLIParser
createdFiles
$ evalCardanoCLIParser [ "shelley","stake-address","key-gen"
, "--verification-key-file", poolRewardAccountAndOwnerVerKey
, "--signing-key-file", poolRewardAccountSignKey
]

assertFilesExist [poolRewardAccountAndOwnerVerKey, poolRewardAccountSignKey]

-- Generate vrf verification key
execCardanoCLIParser
createdFiles
$ evalCardanoCLIParser [ "shelley","node","key-gen-VRF"
, "--verification-key-file", vrfVerKey
, "--signing-key-file", vrfSignKey
]


assertFilesExist [vrfSignKey, vrfVerKey]

-- Create stake pool registration certificate
execCardanoCLIParser
createdFiles
$ evalCardanoCLIParser [ "shelley","stake-pool","registration-certificate"
, "--cold-verification-key-file", coldVerKey
, "--vrf-verification-key-file", vrfVerKey
, "--mainnet"
, "--pool-cost", "1000"
, "--pool-pledge", "5000"
, "--pool-margin", "0.1"
, "--pool-reward-account-verification-key-file", poolRewardAccountAndOwnerVerKey
, "--pool-owner-stake-verification-key-file", poolRewardAccountAndOwnerVerKey
, "--out-file", registrationCertificate
]


assertFilesExist [registrationCertificate]

let registrationCertificateType = textEnvelopeType AsCertificate

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


-- Create stake pool deregistration certificate
execCardanoCLIParser
createdFiles
$ evalCardanoCLIParser [ "shelley", "stake-pool", "deregistration-certificate"
, "--cold-verification-key-file", coldVerKey
, "--epoch", "42"
, "--out-file", deregistrationCertificate
]

assertFilesExist [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 f8ed7a9

Please sign in to comment.