Skip to content

Commit

Permalink
Rework integration tests for governance commands
Browse files Browse the repository at this point in the history
  - [x] Cover new error cases for 'verify'
  - [x] Create full-blown test transactions for 'verify'
  - [x] Slightly re-organised and re-structure data folder
  - [x] Remove now-unnecessary old files

  ```
  ❯ tree cardano-cli/test/data/golden/shelley/governance
  .
  ├── answer
  │   └── basic.json
  ├── cold.sk
  ├── cold.vk
  ├── create
  │   ├── basic.json
  │   └── long-text.json
  ├── polls
  │   ├── basic.json
  │   └── long-text.json
  └── verify
      ├── invalid
      ├── malformed
      ├── mismatch
      ├── none
      └── valid
  ```
  • Loading branch information
KtorZ committed Apr 20, 2023
1 parent 5849055 commit 88ed753
Show file tree
Hide file tree
Showing 20 changed files with 128 additions and 242 deletions.
28 changes: 14 additions & 14 deletions cardano-cli/test/Test/Golden/Shelley.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ import Test.Golden.Shelley.Genesis.KeyGenUtxo (golden_shelleyGenesisKe
import Test.Golden.Shelley.Genesis.KeyHash (golden_shelleyGenesisKeyHash)

import Test.Golden.Shelley.Governance.AnswerPoll
(golden_shelleyGovernanceAnswerPollCold,
golden_shelleyGovernanceAnswerPollInvalidAnswer,
golden_shelleyGovernanceAnswerPollVrf)
(golden_shelleyGovernanceAnswerPoll,
golden_shelleyGovernanceAnswerPollInvalidAnswer)
import Test.Golden.Shelley.Governance.CreatePoll
(golden_shelleyGovernanceCreatePoll,
golden_shelleyGovernanceCreateLongPoll)
import Test.Golden.Shelley.Governance.VerifyPoll
(golden_shelleyGovernanceVerifyPollCold,
golden_shelleyGovernanceVerifyPollColdTempered,
golden_shelleyGovernanceVerifyPollVrf,
golden_shelleyGovernanceVerifyPollVrfTempered)
(golden_shelleyGovernanceVerifyPoll,
golden_shelleyGovernanceVerifyPollMismatch,
golden_shelleyGovernanceVerifyPollNoAnswer,
golden_shelleyGovernanceVerifyPollMalformedAnswer,
golden_shelleyGovernanceVerifyPollInvalidAnswer)

import Test.Golden.Shelley.Key.ConvertCardanoAddressKey
(golden_convertCardanoAddressByronSigningKey,
Expand Down Expand Up @@ -190,12 +190,12 @@ governancePollTests =
$ H.Group "Governance Poll Goldens"
[ ("golden_shelleyGovernanceCreatePoll", golden_shelleyGovernanceCreatePoll)
, ("golden_shelleyGovernanceCreateLongPoll", golden_shelleyGovernanceCreateLongPoll)
, ("golden_shelleyGovernanceAnswerPoll(VRF)", golden_shelleyGovernanceAnswerPollVrf)
, ("golden_shelleyGovernanceAnswerPoll(Cold key)", golden_shelleyGovernanceAnswerPollCold)
, ("golden_shelleyGovernanceAnswerPoll(Invalid)", golden_shelleyGovernanceAnswerPollInvalidAnswer)
, ("golden_shelleyGovernanceVerifyPoll(VRF)", golden_shelleyGovernanceVerifyPollVrf)
, ("golden_shelleyGovernanceVerifyPoll(VRF, tempered)", golden_shelleyGovernanceVerifyPollVrfTempered)
, ("golden_shelleyGovernanceVerifyPoll(Cold Key)", golden_shelleyGovernanceVerifyPollCold)
, ("golden_shelleyGovernanceVerifyPoll(Cold Key, tempered)", golden_shelleyGovernanceVerifyPollColdTempered)
, ("golden_shelleyGovernanceAnswerPoll", golden_shelleyGovernanceAnswerPoll)
, ("golden_shelleyGovernanceAnswerPoll (invalid)", golden_shelleyGovernanceAnswerPollInvalidAnswer)
, ("golden_shelleyGovernanceVerifyPoll", golden_shelleyGovernanceVerifyPoll)
, ("golden_shelleyGovernanceVerifyPoll (mismatch)", golden_shelleyGovernanceVerifyPollMismatch)
, ("golden_shelleyGovernanceVerifyPoll (no answer)", golden_shelleyGovernanceVerifyPollNoAnswer)
, ("golden_shelleyGovernanceVerifyPoll (malformed)", golden_shelleyGovernanceVerifyPollMalformedAnswer)
, ("golden_shelleyGovernanceVerifyPoll (invalid)", golden_shelleyGovernanceVerifyPollInvalidAnswer)
]

33 changes: 6 additions & 27 deletions cardano-cli/test/Test/Golden/Shelley/Governance/AnswerPoll.hs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{-# LANGUAGE OverloadedStrings #-}

module Test.Golden.Shelley.Governance.AnswerPoll
( golden_shelleyGovernanceAnswerPollVrf
, golden_shelleyGovernanceAnswerPollCold
( golden_shelleyGovernanceAnswerPoll
, golden_shelleyGovernanceAnswerPollInvalidAnswer
) where

Expand All @@ -14,47 +13,27 @@ import qualified Hedgehog.Extras.Test.File as H

{- HLINT ignore "Use camelCase" -}

golden_shelleyGovernanceAnswerPollVrf :: Property
golden_shelleyGovernanceAnswerPollVrf = propertyOnce $ do
pollFile <- noteInputFile "test/data/golden/shelley/governance/poll.json"
vrfKeyFile <- noteInputFile "test/data/golden/shelley/governance/vrf.sk"
golden_shelleyGovernanceAnswerPoll :: Property
golden_shelleyGovernanceAnswerPoll = propertyOnce $ do
pollFile <- noteInputFile "test/data/golden/shelley/governance/polls/basic.json"

stdout <- execCardanoCLI
[ "governance", "answer-poll"
, "--poll-file", pollFile
, "--signing-key-file", vrfKeyFile
, "--answer", "0"
]

noteInputFile "test/data/golden/shelley/governance/answer-vrf.json"
>>= H.readFile
>>= (H.===) stdout

golden_shelleyGovernanceAnswerPollCold :: Property
golden_shelleyGovernanceAnswerPollCold = propertyOnce $ do
pollFile <- noteInputFile "test/data/golden/shelley/governance/poll.json"
coldKeyFile <- noteInputFile "test/data/golden/shelley/governance/cold.sk"

stdout <- execCardanoCLI
[ "governance", "answer-poll"
, "--poll-file", pollFile
, "--signing-key-file", coldKeyFile
, "--answer", "1"
]

noteInputFile "test/data/golden/shelley/governance/answer-cold.json"
noteInputFile "test/data/golden/shelley/governance/answer/basic.json"
>>= H.readFile
>>= (H.===) stdout

golden_shelleyGovernanceAnswerPollInvalidAnswer :: Property
golden_shelleyGovernanceAnswerPollInvalidAnswer = propertyOnce $ do
pollFile <- noteInputFile "test/data/golden/shelley/governance/poll.json"
vrfKeyFile <- noteInputFile "test/data/golden/shelley/governance/vrf.sk"
pollFile <- noteInputFile "test/data/golden/shelley/governance/polls/basic.json"

result <- tryExecCardanoCLI
[ "governance", "answer-poll"
, "--poll-file", pollFile
, "--signing-key-file", vrfKeyFile
, "--answer", "3"
]

Expand Down
4 changes: 2 additions & 2 deletions cardano-cli/test/Test/Golden/Shelley/Governance/CreatePoll.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ golden_shelleyGovernanceCreatePoll =
]

void $ H.readFile pollFile
noteInputFile "test/data/golden/shelley/governance/create.json"
noteInputFile "test/data/golden/shelley/governance/create/basic.json"
>>= H.readFile
>>= (H.===) stdout
H.assertFileOccurences 1 "GovernancePoll" pollFile
Expand All @@ -49,7 +49,7 @@ golden_shelleyGovernanceCreateLongPoll =
]

void $ H.readFile pollFile
noteInputFile "test/data/golden/shelley/governance/create-long.json"
noteInputFile "test/data/golden/shelley/governance/create/long-text.json"
>>= H.readFile
>>= (H.===) stdout
H.assertFileOccurences 1 "GovernancePoll" pollFile
Expand Down
86 changes: 59 additions & 27 deletions cardano-cli/test/Test/Golden/Shelley/Governance/VerifyPoll.hs
Original file line number Diff line number Diff line change
@@ -1,64 +1,96 @@
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}

module Test.Golden.Shelley.Governance.VerifyPoll
( golden_shelleyGovernanceVerifyPollVrf
, golden_shelleyGovernanceVerifyPollVrfTempered
, golden_shelleyGovernanceVerifyPollCold
, golden_shelleyGovernanceVerifyPollColdTempered
( golden_shelleyGovernanceVerifyPoll
, golden_shelleyGovernanceVerifyPollMismatch
, golden_shelleyGovernanceVerifyPollNoAnswer
, golden_shelleyGovernanceVerifyPollMalformedAnswer
, golden_shelleyGovernanceVerifyPollInvalidAnswer
) where

import Control.Monad (void)
import Control.Monad.IO.Class (liftIO)
import Hedgehog (Property)
import Test.OptParse

import Cardano.Api
import Cardano.CLI.Shelley.Key
(VerificationKeyOrFile (..),
readVerificationKeyOrTextEnvFile)

import qualified Hedgehog as H
import qualified Data.ByteString.Char8 as BSC

{- HLINT ignore "Use camelCase" -}

golden_shelleyGovernanceVerifyPollVrf :: Property
golden_shelleyGovernanceVerifyPollVrf = propertyOnce $ do
pollFile <- noteInputFile "test/data/golden/shelley/governance/poll.json"
metadataFile <- noteInputFile "test/data/golden/shelley/governance/answer-vrf.json"
golden_shelleyGovernanceVerifyPoll :: Property
golden_shelleyGovernanceVerifyPoll = propertyOnce $ do
pollFile <- noteInputFile "test/data/golden/shelley/governance/polls/basic.json"
txFile <- noteInputFile "test/data/golden/shelley/governance/verify/valid"
vkFile <- VerificationKeyFilePath . File <$>
noteInputFile "test/data/golden/shelley/governance/cold.vk"

void $ execCardanoCLI
stdout <- BSC.pack <$> execCardanoCLI
[ "governance", "verify-poll"
, "--poll-file", pollFile
, "--metadata-file", metadataFile
, "--tx-file", txFile
]

golden_shelleyGovernanceVerifyPollCold :: Property
golden_shelleyGovernanceVerifyPollCold = propertyOnce $ do
pollFile <- noteInputFile "test/data/golden/shelley/governance/poll.json"
metadataFile <- noteInputFile "test/data/golden/shelley/governance/answer-cold.json"
liftIO (readVerificationKeyOrTextEnvFile AsStakePoolKey vkFile) >>= \case
Left{} ->
H.failure
Right vk -> do
let expected = prettyPrintJSON $ serialiseToRawBytesHexText <$> [verificationKeyHash vk]
H.assert $ expected `BSC.isInfixOf` stdout

golden_shelleyGovernanceVerifyPollMismatch :: Property
golden_shelleyGovernanceVerifyPollMismatch = propertyOnce $ do
pollFile <- noteInputFile "test/data/golden/shelley/governance/polls/basic.json"
txFile <- noteInputFile "test/data/golden/shelley/governance/verify/mismatch"

void $ execCardanoCLI
result <- tryExecCardanoCLI
[ "governance", "verify-poll"
, "--poll-file", pollFile
, "--metadata-file", metadataFile
, "--tx-file", txFile
]

golden_shelleyGovernanceVerifyPollVrfTempered :: Property
golden_shelleyGovernanceVerifyPollVrfTempered = propertyOnce $ do
pollFile <- noteInputFile "test/data/golden/shelley/governance/poll.json"
metadataFile <- noteInputFile "test/data/golden/shelley/governance/answer-vrf-tempered.json"
either (const H.success) (const H.failure) result

golden_shelleyGovernanceVerifyPollNoAnswer :: Property
golden_shelleyGovernanceVerifyPollNoAnswer = propertyOnce $ do
pollFile <- noteInputFile "test/data/golden/shelley/governance/polls/basic.json"
txFile <- noteInputFile "test/data/golden/shelley/governance/verify/none"

result <- tryExecCardanoCLI
[ "governance", "verify-poll"
, "--poll-file", pollFile
, "--tx-file", txFile
]

either (const H.success) (const H.failure) result

golden_shelleyGovernanceVerifyPollMalformedAnswer :: Property
golden_shelleyGovernanceVerifyPollMalformedAnswer = propertyOnce $ do
pollFile <- noteInputFile "test/data/golden/shelley/governance/polls/basic.json"
txFile <- noteInputFile "test/data/golden/shelley/governance/verify/malformed"

result <- tryExecCardanoCLI
[ "governance", "verify-poll"
, "--poll-file", pollFile
, "--metadata-file", metadataFile
, "--tx-file", txFile
]

either (const H.success) (const H.failure) result

golden_shelleyGovernanceVerifyPollColdTempered :: Property
golden_shelleyGovernanceVerifyPollColdTempered = propertyOnce $ do
pollFile <- noteInputFile "test/data/golden/shelley/governance/poll.json"
metadataFile <- noteInputFile "test/data/golden/shelley/governance/answer-cold-tempered.json"
golden_shelleyGovernanceVerifyPollInvalidAnswer :: Property
golden_shelleyGovernanceVerifyPollInvalidAnswer = propertyOnce $ do
pollFile <- noteInputFile "test/data/golden/shelley/governance/polls/basic.json"
txFile <- noteInputFile "test/data/golden/shelley/governance/verify/invalid"

result <- tryExecCardanoCLI
[ "governance", "verify-poll"
, "--poll-file", pollFile
, "--metadata-file", metadataFile
, "--tx-file", txFile
]

either (const H.success) (const H.failure) result

This file was deleted.

37 changes: 0 additions & 37 deletions cardano-cli/test/data/golden/shelley/governance/answer-cold.json

This file was deleted.

This file was deleted.

Loading

0 comments on commit 88ed753

Please sign in to comment.