From 15ae3b2a5cd7817b2882401ea025238b4d204911 Mon Sep 17 00:00:00 2001 From: Yuriy Syrovetskiy Date: Thu, 16 Sep 2021 18:35:26 +0300 Subject: [PATCH 1/3] cardano-cli: Fix metavars for rational CLI paramenters Because non-programmers don't know what DOUBLE is. --- cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs b/cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs index c7a7477f340..515fd1a8411 100644 --- a/cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs +++ b/cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs @@ -2401,7 +2401,7 @@ pPoolMargin :: Parser Rational pPoolMargin = Opt.option readRationalUnitInterval ( Opt.long "pool-margin" - <> Opt.metavar "DOUBLE" + <> Opt.metavar "RATIONAL" <> Opt.help "The stake pool's margin." ) @@ -2653,7 +2653,7 @@ pPoolInfluence :: Parser Rational pPoolInfluence = Opt.option readRational ( Opt.long "pool-influence" - <> Opt.metavar "DOUBLE" + <> Opt.metavar "RATIONAL" <> Opt.help "Pool influence." ) @@ -2661,7 +2661,7 @@ pTreasuryExpansion :: Parser Rational pTreasuryExpansion = Opt.option readRationalUnitInterval ( Opt.long "treasury-expansion" - <> Opt.metavar "DOUBLE" + <> Opt.metavar "RATIONAL" <> Opt.help "Treasury expansion." ) @@ -2669,7 +2669,7 @@ pMonetaryExpansion :: Parser Rational pMonetaryExpansion = Opt.option readRationalUnitInterval ( Opt.long "monetary-expansion" - <> Opt.metavar "DOUBLE" + <> Opt.metavar "RATIONAL" <> Opt.help "Monetary expansion." ) @@ -2677,7 +2677,7 @@ pDecentralParam :: Parser Rational pDecentralParam = Opt.option readRationalUnitInterval ( Opt.long "decentralization-parameter" - <> Opt.metavar "DOUBLE" + <> Opt.metavar "RATIONAL" <> Opt.help "Decentralization parameter." ) @@ -2686,7 +2686,7 @@ pExtraEntropy = Opt.option (Just <$> readerFromParsecParser parsePraosNonce) ( Opt.long "extra-entropy" <> Opt.metavar "HEX" - <> Opt.help "Praos extra entropy, as a hex byte string." + <> Opt.help "Praos extra entropy seed, as a hex byte string." ) <|> Opt.flag' Nothing ( Opt.long "reset-extra-entropy" From 64e8f4ec3f064cd6909ab31c7ebb87ec74ab4d7f Mon Sep 17 00:00:00 2001 From: Yuriy Syrovetskiy Date: Thu, 16 Sep 2021 18:36:49 +0300 Subject: [PATCH 2/3] Fix scripts/reconfigure-hlint.sh for MacOS The error was: sed: 1: "/^# BEGIN-GENERATED/,/^ ...": extra characters at the end of d command --- scripts/reconfigure-hlint.sh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/scripts/reconfigure-hlint.sh b/scripts/reconfigure-hlint.sh index 3159163b454..143371b09f3 100755 --- a/scripts/reconfigure-hlint.sh +++ b/scripts/reconfigure-hlint.sh @@ -7,11 +7,17 @@ # # To use, simply run the script from the project's top-level directory. +UNAME=$(uname -s) SED= +case $UNAME in + Darwin ) SED="gsed";; + Linux ) SED="sed";; +esac + extract_rules() { for x in $(find . -type f -name '*.hs' | grep -v dist); do module="$(grep '^module' $x | cut -d ' ' -f 2 | head -n 1)" grep '{- HLINT ignore "' $x | cut -d '"' -f 2 | \ - sed "s|^|$module,|g" + $SED "s|^|$module,|g" done } @@ -29,6 +35,6 @@ gen_rules() { echo "# This file is generated from .hlint.template.yaml by scripts/reconfigure-hlint.sh" echo "" cat .hlint.template.yaml \ - | sed '/^# BEGIN-GENERATED/,/^# END-GENERATED/{/^# BEGIN-GENERATED/!{/^# END-GENERATED/!d}}' \ - | gsed -e "/^# BEGIN-GENERATED/ r "<(gen_rules) + | $SED '/^# BEGIN-GENERATED/,/^# END-GENERATED/{/^# BEGIN-GENERATED/!{/^# END-GENERATED/!d}}' \ + | $SED -e "/^# BEGIN-GENERATED/ r "<(gen_rules) ) > ".hlint.yaml" From e6a21953b0db542948d5e39194f65688327cc042 Mon Sep 17 00:00:00 2001 From: Yuriy Syrovetskiy Date: Thu, 16 Sep 2021 18:37:36 +0300 Subject: [PATCH 3/3] cardano-cli: Add update proposal friendly rendering --- cardano-cli/src/Cardano/CLI/Run/Friendly.hs | 93 +++++++++++++++++- cardano-cli/test/Test/Golden/TxView.hs | 98 ++++++++++++++++++- .../data/golden/alonzo/transaction-view.out | 31 ++++++ .../data/golden/shelley/transaction-view.out | 23 ++++- .../test/data/golden/shelley/update-proposal | 5 + 5 files changed, 243 insertions(+), 7 deletions(-) create mode 100644 cardano-cli/test/data/golden/alonzo/transaction-view.out create mode 100644 cardano-cli/test/data/golden/shelley/update-proposal diff --git a/cardano-cli/src/Cardano/CLI/Run/Friendly.hs b/cardano-cli/src/Cardano/CLI/Run/Friendly.hs index 96e635bb512..ddcc6a1390c 100644 --- a/cardano-cli/src/Cardano/CLI/Run/Friendly.hs +++ b/cardano-cli/src/Cardano/CLI/Run/Friendly.hs @@ -150,13 +150,104 @@ friendlyStakeReference = \case friendlyUpdateProposal :: TxUpdateProposal era -> Aeson.Value friendlyUpdateProposal = \case TxUpdateProposalNone -> Null - TxUpdateProposal _ p -> String $ textShow p + TxUpdateProposal _ (UpdateProposal parameterUpdates epoch) -> + object + [ "epoch" .= epoch + , "updates" .= + [ object + [ "genesis key hash" .= serialiseToRawBytesHexText genesisKeyHash + , "update" .= friendlyProtocolParametersUpdate parameterUpdate + ] + | (genesisKeyHash, parameterUpdate) <- Map.assocs parameterUpdates + ] + ] + +friendlyProtocolParametersUpdate :: ProtocolParametersUpdate -> Aeson.Value +friendlyProtocolParametersUpdate + ProtocolParametersUpdate + { protocolUpdateProtocolVersion + , protocolUpdateDecentralization + , protocolUpdateExtraPraosEntropy + , protocolUpdateMaxBlockHeaderSize + , protocolUpdateMaxBlockBodySize + , protocolUpdateMaxTxSize + , protocolUpdateTxFeeFixed + , protocolUpdateTxFeePerByte + , protocolUpdateMinUTxOValue + , protocolUpdateStakeAddressDeposit + , protocolUpdateStakePoolDeposit + , protocolUpdateMinPoolCost + , protocolUpdatePoolRetireMaxEpoch + , protocolUpdateStakePoolTargetNum + , protocolUpdatePoolPledgeInfluence + , protocolUpdateMonetaryExpansion + , protocolUpdateTreasuryCut + , protocolUpdateUTxOCostPerWord + , protocolUpdateCollateralPercent + , protocolUpdateMaxBlockExUnits + , protocolUpdateMaxCollateralInputs + , protocolUpdateMaxTxExUnits + , protocolUpdateMaxValueSize + , protocolUpdatePrices + } = + object . catMaybes $ + [ protocolUpdateProtocolVersion <&> \(major, minor) -> + "protocol version" .= (textShow major <> "." <> textShow minor) + , protocolUpdateDecentralization <&> + ("decentralization parameter" .=) . friendlyRational + , protocolUpdateExtraPraosEntropy <&> + ("extra entropy" .=) . maybe "reset" toJSON + , protocolUpdateMaxBlockHeaderSize <&> ("max block header size" .=) + , protocolUpdateMaxBlockBodySize<&> ("max block body size" .=) + , protocolUpdateMaxTxSize <&> ("max transaction size" .=) + , protocolUpdateTxFeeFixed <&> ("transaction fee constant" .=) + , protocolUpdateTxFeePerByte <&> ("transaction fee linear per byte" .=) + , protocolUpdateMinUTxOValue <&> ("min UTxO value" .=) . friendlyLovelace + , protocolUpdateStakeAddressDeposit <&> + ("key registration deposit" .=) . friendlyLovelace + , protocolUpdateStakePoolDeposit <&> + ("pool registration deposit" .=) . friendlyLovelace + , protocolUpdateMinPoolCost <&> ("min pool cost" .=) . friendlyLovelace + , protocolUpdatePoolRetireMaxEpoch <&> ("pool retirement epoch boundary" .=) + , protocolUpdateStakePoolTargetNum <&> ("number of pools" .=) + , protocolUpdatePoolPledgeInfluence <&> + ("pool influence" .=) . friendlyRational + , protocolUpdateMonetaryExpansion <&> + ("monetary expansion" .=) . friendlyRational + , protocolUpdateTreasuryCut <&> ("treasury expansion" .=) . friendlyRational + , protocolUpdateUTxOCostPerWord <&> + ("UTxO storage cost per unit" .=) . friendlyLovelace + , protocolUpdateCollateralPercent <&> + ("collateral inputs share" .=) . (<> "%") . textShow + , protocolUpdateMaxBlockExUnits <&> ("max block execution units" .=) + , protocolUpdateMaxCollateralInputs <&> ("max collateral inputs" .=) + , protocolUpdateMaxTxExUnits <&> ("max transaction execution units" .=) + , protocolUpdateMaxValueSize <&> ("max value size" .=) + , protocolUpdatePrices <&> ("execution prices" .=) . friendlyPrices + ] + +friendlyPrices :: ExecutionUnitPrices -> Aeson.Value +friendlyPrices ExecutionUnitPrices{priceExecutionMemory, priceExecutionSteps} = + object + [ "memory" .= friendlyRational priceExecutionMemory + , "steps" .= friendlyRational priceExecutionSteps + ] friendlyCertificates :: TxCertificates ViewTx era -> Aeson.Value friendlyCertificates = \case TxCertificatesNone -> Null TxCertificates _ cs _ -> toJSON $ map textShow cs +friendlyRational :: Rational -> Aeson.Value +friendlyRational r = + String $ + case d of + 1 -> textShow n + _ -> textShow n <> "/" <> textShow d + where + n = numerator r + d = denominator r + friendlyFee :: TxFee era -> Aeson.Value friendlyFee = \case TxFeeImplicit _ -> "implicit" diff --git a/cardano-cli/test/Test/Golden/TxView.hs b/cardano-cli/test/Test/Golden/TxView.hs index e8da8252e2d..82835bae0a2 100644 --- a/cardano-cli/test/Test/Golden/TxView.hs +++ b/cardano-cli/test/Test/Golden/TxView.hs @@ -5,7 +5,7 @@ module Test.Golden.TxView (txViewTests) where import Cardano.Prelude import Hedgehog (Group (..), Property, checkSequential) -import Hedgehog.Extras.Test.Base (moduleWorkspace, propertyOnce) +import Hedgehog.Extras (moduleWorkspace, note_, propertyOnce) import Test.OptParse (execCardanoCLI, noteTempFile) import Test.Utilities (diffVsGoldenFile) @@ -16,11 +16,11 @@ txViewTests :: IO Bool txViewTests = checkSequential $ Group "`transaction view` Goldens" - [ ("golden_view_byron", golden_view_byron) + [ ("golden_view_byron", golden_view_byron) , ("golden_view_shelley", golden_view_shelley) , ("golden_view_allegra", golden_view_allegra) - , ("golden_view_mary", golden_view_mary) - -- , ("golden_view_alonzo", golden_view_alonzo) + , ("golden_view_mary", golden_view_mary) + , ("golden_view_alonzo", golden_view_alonzo) ] golden_view_byron :: Property @@ -53,7 +53,46 @@ golden_view_shelley :: Property golden_view_shelley = propertyOnce $ moduleWorkspace "tmp" $ \tempDir -> do - transactionBodyFile <- noteTempFile tempDir "transaction-body-file" + updateProposalFile <- noteTempFile tempDir "update-proposal" + transactionBodyFile <- noteTempFile tempDir "transaction-body" + + let extraEntropySeed = "c0ffee" + note_ $ "extra entropy seed: " ++ extraEntropySeed + note_ + "extra entropy hash:\ + \ 88f04f011dcded879039ae4b9b20219d9448e5c7b42c2d1f638fb8740e0ab8be" + + note_ + "genesis-verification-key-file hash:\ + \ 81cb0bc5b6fbba391e6f7ec3d9271cbea25bcbf907181b7c4d5f8c2f" + + -- Create update proposal + void $ + execCardanoCLI + [ "governance", "create-update-proposal" + , "--decentralization-parameter", "63/64" + , "--epoch", "64" + , "--extra-entropy", extraEntropySeed + , "--genesis-verification-key-file" + , "test/data/golden/shelley/keys/genesis_keys/verification_key" + , "--key-reg-deposit-amt", "71" + , "--max-block-body-size", "72" + , "--max-block-header-size", "73" + , "--max-tx-size", "74" + , "--min-fee-constant", "75" + , "--min-fee-linear", "76" + , "--min-pool-cost", "77" + , "--min-utxo-value", "78" + , "--monetary-expansion", "79/80" + , "--number-of-pools", "80" + , "--out-file", updateProposalFile + , "--pool-influence", "82/83" + , "--pool-reg-deposit", "83" + , "--pool-retirement-epoch-boundary", "84" + , "--protocol-major-version", "85" + , "--protocol-minor-version", "86" + , "--treasury-expansion", "87/88" + ] -- Create transaction body void $ @@ -70,6 +109,7 @@ golden_view_shelley = , "--withdrawal" , "stake_test1up00fz9lyqs5sjks82k22eqz7a9srym9vysjgp3h2ua2v2cm522kg\ \+42" + , "--update-proposal-file", updateProposalFile , "--out-file", transactionBodyFile ] @@ -173,3 +213,51 @@ golden_view_mary = execCardanoCLI ["transaction", "view", "--tx-body-file", transactionBodyFile] diffVsGoldenFile result "test/data/golden/mary/transaction-view.out" + +golden_view_alonzo :: Property +golden_view_alonzo = + propertyOnce $ + moduleWorkspace "tmp" $ \tempDir -> do + updateProposalFile <- noteTempFile tempDir "update-proposal" + transactionBodyFile <- noteTempFile tempDir "transaction-body" + + note_ + "genesis-verification-key-file hash:\ + \ 1bafa294233a5a7ffbf539ae798da0943aa83d2a19398c2d0e5af114" + + -- Create update proposal + void $ + execCardanoCLI + [ "governance", "create-update-proposal" + , "--epoch", "190" + , "--genesis-verification-key-file" + , "test/data/golden/shelley/keys/genesis_keys/verification_key" + , "--utxo-cost-per-word", "194" + , "--price-execution-steps", "195/196" + , "--price-execution-memory", "196/197" + , "--max-tx-execution-units", "(197, 198)" + , "--max-block-execution-units", "(198, 199)" + , "--max-value-size", "199" + , "--collateral-percent", "200" + , "--max-collateral-inputs", "201" + , "--out-file", updateProposalFile + ] + + -- Create transaction body + void $ + execCardanoCLI + [ "transaction", "build-raw" + , "--alonzo-era" + , "--tx-in" + , "ed7c8f68c194cc763ee65ad22ef0973e26481be058c65005fd39fb93f9c43a20\ + \#212" + , "--fee", "213" + , "--update-proposal-file", updateProposalFile + , "--out-file", transactionBodyFile + ] + + -- View transaction body + result <- + execCardanoCLI + ["transaction", "view", "--tx-body-file", transactionBodyFile] + diffVsGoldenFile result "test/data/golden/alonzo/transaction-view.out" diff --git a/cardano-cli/test/data/golden/alonzo/transaction-view.out b/cardano-cli/test/data/golden/alonzo/transaction-view.out new file mode 100644 index 00000000000..b371482206d --- /dev/null +++ b/cardano-cli/test/data/golden/alonzo/transaction-view.out @@ -0,0 +1,31 @@ +auxiliary scripts: null +certificates: null +era: Alonzo +fee: 213 Lovelace +inputs: +- ed7c8f68c194cc763ee65ad22ef0973e26481be058c65005fd39fb93f9c43a20#212 +metadata: null +mint: null +outputs: [] +update proposal: + epoch: 190 + updates: + - genesis key hash: 1bafa294233a5a7ffbf539ae798da0943aa83d2a19398c2d0e5af114 + update: + UTxO storage cost per unit: 194 Lovelace + collateral inputs share: 200% + execution prices: + memory: 196/197 + steps: 195/196 + max block execution units: + memory: 199 + steps: 198 + max collateral inputs: 201 + max transaction execution units: + memory: 198 + steps: 197 + max value size: 199 +validity range: + lower bound: null + upper bound: null +withdrawals: null diff --git a/cardano-cli/test/data/golden/shelley/transaction-view.out b/cardano-cli/test/data/golden/shelley/transaction-view.out index e655f683aa5..87b79e98b67 100644 --- a/cardano-cli/test/data/golden/shelley/transaction-view.out +++ b/cardano-cli/test/data/golden/shelley/transaction-view.out @@ -14,7 +14,28 @@ outputs: payment credential: key hash: bce78cb90f6da9ee778ef07ca881b489c38a188993e6870bd5a9ef77 stake reference: null -update proposal: null +update proposal: + epoch: 64 + updates: + - genesis key hash: 1bafa294233a5a7ffbf539ae798da0943aa83d2a19398c2d0e5af114 + update: + decentralization parameter: 63/64 + extra entropy: 88f04f011dcded879039ae4b9b20219d9448e5c7b42c2d1f638fb8740e0ab8be + key registration deposit: 71 Lovelace + max block body size: 72 + max block header size: 73 + max transaction size: 74 + min UTxO value: 78 Lovelace + min pool cost: 77 Lovelace + monetary expansion: 79/80 + number of pools: 80 + pool influence: 82/83 + pool registration deposit: 83 Lovelace + pool retirement epoch boundary: 84 + protocol version: '85.86' + transaction fee constant: 75 + transaction fee linear per byte: 76 + treasury expansion: 87/88 validity range: time to live: 33 withdrawals: diff --git a/cardano-cli/test/data/golden/shelley/update-proposal b/cardano-cli/test/data/golden/shelley/update-proposal new file mode 100644 index 00000000000..93e7aef6f35 --- /dev/null +++ b/cardano-cli/test/data/golden/shelley/update-proposal @@ -0,0 +1,5 @@ +{ + "type": "UpdateProposalShelley", + "description": "", + "cborHex": "82a1581ca2512fa96a5f51d7aa8b8558669561fdd905f505ad7e0f4047b15c9eb100197a6601197a6702197a6e03197a6804197a6d05197a6406197a6307197a6108197a6009d81e82197a5f1903e80ad81e82197a5b1a000186a00bd81e82197a591a000186a00cd81e82197a6f1a000186a00d82015820ee32869218e317d16b9cba9e8f0737e23a6c9328e71068f161e5cc3cf54c45be0e82197a6a197a6b0f197a6510197a62197a69" +}