Skip to content

Commit

Permalink
Merge #1369
Browse files Browse the repository at this point in the history
1369: More typed api golden tests for certificates and tx r=Jimbo4350 a=Jimbo4350

Depends on #1360

Co-authored-by: Jordan Millar <jordan.millar@iohk.io>
  • Loading branch information
iohk-bors[bot] and Jimbo4350 committed Jul 2, 2020
2 parents 09968c5 + 3e2996c commit 588f13a
Show file tree
Hide file tree
Showing 52 changed files with 726 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
24 changes: 17 additions & 7 deletions cardano-cli/cardano-cli.cabal
Expand Up @@ -186,14 +186,24 @@ 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.MIRCertificate
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"
@@ -0,0 +1,17 @@
{-# LANGUAGE OverloadedStrings #-}

module Test.CLI.Shelley.TextEnvelope.Golden.Certificates.GenesisDelegation
( golden_shelleyGenesisDelegationCertificate
) where

import Cardano.Prelude

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

import Hedgehog (Property)
--import qualified Hedgehog as H

--import Test.OptParse

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

module Test.CLI.Shelley.TextEnvelope.Golden.Certificates.MIRCertificate
( golden_shelleyMIRCertificate
) where

import Cardano.Prelude

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

import Hedgehog (Property)
import qualified Hedgehog as H

import Test.OptParse

-- | 1. Generate stake key pair
-- 2. Create MIR certificate
-- s. Check the TextEnvelope serialization format has not changed.
golden_shelleyMIRCertificate :: Property
golden_shelleyMIRCertificate =
propertyOnce $ do
-- Reference keys
let referenceMIRCertificate = "test/Test/golden/shelley/certificates/mir_certificate"

-- Key filepaths
let verKey = "stake-verification-key-file"
signKey = "stake-signing-key-file"
mirCertificate = "mir-certificate-file"
createdFiles = [verKey, signKey, mirCertificate]

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

assertFilesExist [verKey, signKey]

-- Create MIR certificate
execCardanoCLIParser
createdFiles
$ evalCardanoCLIParser [ "shelley","governance","create-mir-certificate"
, "--reserves" --TODO: Should also do "--reserves"
, "--stake-verification-key-file", verKey
, "--reward", "1000"
, "--out-file", mirCertificate
]

assertFilesExist [mirCertificate]

let registrationCertificateType = textEnvelopeType AsCertificate

checkTextEnvelopeFormat createdFiles registrationCertificateType referenceMIRCertificate mirCertificate

liftIO $ fileCleanup createdFiles
H.success
@@ -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 comments on commit 588f13a

Please sign in to comment.