-
Notifications
You must be signed in to change notification settings - Fork 721
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Write automated tests to cover newly introduced SPO on-chain poll com…
…mands Fixture keys were generated using the command-line itself. The set of tests cover quite extensively the various commands, as well as a few 'negative' test scenarios. It is more complicated to cover the interactive part of the 'answer-poll' command through those tests; and this is therefore left as manual test. Instructions for executing the sequence will also be provided with the introduction of the commands (e.g. in the description of [PR#5050](#5050).
- Loading branch information
Showing
18 changed files
with
498 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
cardano-cli/test/Test/Golden/Shelley/Governance/AnswerPoll.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
module Test.Golden.Shelley.Governance.AnswerPoll | ||
( golden_shelleyGovernanceAnswerPollVrf | ||
, golden_shelleyGovernanceAnswerPollCold | ||
, golden_shelleyGovernanceAnswerPollInvalidAnswer | ||
) where | ||
|
||
import Hedgehog (Property) | ||
import Test.OptParse | ||
|
||
import qualified Hedgehog as H | ||
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" | ||
|
||
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" | ||
>>= 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" | ||
|
||
result <- tryExecCardanoCLI | ||
[ "governance", "answer-poll" | ||
, "--poll-file", pollFile | ||
, "--signing-key-file", vrfKeyFile | ||
, "--answer", "3" | ||
] | ||
|
||
either (const H.success) (const H.failure) result |
56 changes: 56 additions & 0 deletions
56
cardano-cli/test/Test/Golden/Shelley/Governance/CreatePoll.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
module Test.Golden.Shelley.Governance.CreatePoll | ||
( golden_shelleyGovernanceCreatePoll | ||
, golden_shelleyGovernanceCreateLongPoll | ||
) where | ||
|
||
import Control.Monad (void) | ||
import Hedgehog (Property) | ||
import Test.OptParse | ||
|
||
import qualified Hedgehog as H | ||
import qualified Hedgehog.Extras.Test.Base as H | ||
import qualified Hedgehog.Extras.Test.File as H | ||
|
||
{- HLINT ignore "Use camelCase" -} | ||
|
||
golden_shelleyGovernanceCreatePoll :: Property | ||
golden_shelleyGovernanceCreatePoll = | ||
propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do | ||
pollFile <- noteTempFile tempDir "poll.json" | ||
|
||
stdout <- execCardanoCLI | ||
[ "governance", "create-poll" | ||
, "--question", "Pineapples on pizza?" | ||
, "--answer", "yes" | ||
, "--answer", "no" | ||
, "--out-file", pollFile | ||
] | ||
|
||
void $ H.readFile pollFile | ||
noteInputFile "test/data/golden/shelley/governance/create.json" | ||
>>= H.readFile | ||
>>= (H.===) stdout | ||
H.assertFileOccurences 1 "GovernancePoll" pollFile | ||
H.assertEndsWithSingleNewline pollFile | ||
|
||
golden_shelleyGovernanceCreateLongPoll :: Property | ||
golden_shelleyGovernanceCreateLongPoll = | ||
propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do | ||
pollFile <- noteTempFile tempDir "poll.json" | ||
|
||
stdout <- execCardanoCLI | ||
[ "governance", "create-poll" | ||
, "--question", "What is the most adequate topping to put on a pizza (please consider all possibilities and take time to answer)?" | ||
, "--answer", "pineapples" | ||
, "--answer", "only traditional topics should go on a pizza, this isn't room for jokes" | ||
, "--out-file", pollFile | ||
] | ||
|
||
void $ H.readFile pollFile | ||
noteInputFile "test/data/golden/shelley/governance/create-long.json" | ||
>>= H.readFile | ||
>>= (H.===) stdout | ||
H.assertFileOccurences 1 "GovernancePoll" pollFile | ||
H.assertEndsWithSingleNewline pollFile |
64 changes: 64 additions & 0 deletions
64
cardano-cli/test/Test/Golden/Shelley/Governance/VerifyPoll.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
module Test.Golden.Shelley.Governance.VerifyPoll | ||
( golden_shelleyGovernanceVerifyPollVrf | ||
, golden_shelleyGovernanceVerifyPollVrfTempered | ||
, golden_shelleyGovernanceVerifyPollCold | ||
, golden_shelleyGovernanceVerifyPollColdTempered | ||
) where | ||
|
||
import Control.Monad (void) | ||
import Hedgehog (Property) | ||
import Test.OptParse | ||
|
||
import qualified Hedgehog as H | ||
|
||
{- 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" | ||
|
||
void $ execCardanoCLI | ||
[ "governance", "verify-poll" | ||
, "--poll-file", pollFile | ||
, "--metadata-file", metadataFile | ||
] | ||
|
||
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" | ||
|
||
void $ execCardanoCLI | ||
[ "governance", "verify-poll" | ||
, "--poll-file", pollFile | ||
, "--metadata-file", metadataFile | ||
] | ||
|
||
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" | ||
|
||
result <- tryExecCardanoCLI | ||
[ "governance", "verify-poll" | ||
, "--poll-file", pollFile | ||
, "--metadata-file", metadataFile | ||
] | ||
|
||
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" | ||
|
||
result <- tryExecCardanoCLI | ||
[ "governance", "verify-poll" | ||
, "--poll-file", pollFile | ||
, "--metadata-file", metadataFile | ||
] | ||
|
||
either (const H.success) (const H.failure) result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
cardano-cli/test/data/golden/shelley/governance/answer-cold-tempered.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"94": { | ||
"map": [ | ||
{ | ||
"k": { | ||
"int": 2 | ||
}, | ||
"v": { | ||
"bytes": "820c311ced91f8c2bb9b5c7f446379063c9a077a1098d73498d17e9ea27045af" | ||
} | ||
}, | ||
{ | ||
"k": { | ||
"int": 3 | ||
}, | ||
"v": { | ||
"int": 1 | ||
} | ||
}, | ||
{ | ||
"k": { | ||
"int": 5 | ||
}, | ||
"v": { | ||
"list": [ | ||
{ | ||
"bytes": "29ade2115fbcbc17f063eec41ec0d358ccc5b52c2bccb47c0918727695619a68" | ||
}, | ||
{ | ||
"bytes": "6458ff100279aed89b0ea08a57ddbf3b77e7c6802b8c23840da7df80b60f37c0ddd445499d247d27d7e7adaa189db001d0f1eddc2229daa6be7509c43cc23501" | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
cardano-cli/test/data/golden/shelley/governance/answer-cold.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"94": { | ||
"map": [ | ||
{ | ||
"k": { | ||
"int": 2 | ||
}, | ||
"v": { | ||
"bytes": "29093fd43fc30ba31e306af06ce8537390e1668ae7496fe53d53684683c3762c" | ||
} | ||
}, | ||
{ | ||
"k": { | ||
"int": 3 | ||
}, | ||
"v": { | ||
"int": 1 | ||
} | ||
}, | ||
{ | ||
"k": { | ||
"int": 5 | ||
}, | ||
"v": { | ||
"list": [ | ||
{ | ||
"bytes": "29ade2115fbcbc17f063eec41ec0d358ccc5b52c2bccb47c0918727695619a68" | ||
}, | ||
{ | ||
"bytes": "6458ff100279aed89b0ea08a57ddbf3b77e7c6802b8c23840da7df80b60f37c0ddd445499d247d27d7e7adaa189db001d0f1eddc2229daa6be7509c43cc23501" | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
cardano-cli/test/data/golden/shelley/governance/answer-vrf-tempered.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{ | ||
"94": { | ||
"map": [ | ||
{ | ||
"k": { | ||
"int": 2 | ||
}, | ||
"v": { | ||
"bytes": "29093fd43fc30ba31e306af06ce8537390e1668ae7496fe53d53684683c3762c" | ||
} | ||
}, | ||
{ | ||
"k": { | ||
"int": 3 | ||
}, | ||
"v": { | ||
"int": 1 | ||
} | ||
}, | ||
{ | ||
"k": { | ||
"int": 4 | ||
}, | ||
"v": { | ||
"list": [ | ||
{ | ||
"bytes": "2dc2fa217af8b52251c4cdf538fa106cbf0b5beac3e74d05f97ceb33c0147a2c" | ||
}, | ||
{ | ||
"list": [ | ||
{ | ||
"bytes": "c1c4d0cf60529f091431c456bf528b23d384f641afc536d1347b0889e9fd45d47e422249ac4bb5bdd75c205ea35c1ef2d89d96c0f06070590a98db7dba659647" | ||
}, | ||
{ | ||
"bytes": "9a440df4e70830b22b86accbeab7bc07" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} | ||
} |
Oops, something went wrong.