Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cardano-cli/src/Cardano/CLI/EraBased/Common/Option.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1191,9 +1191,9 @@ pProposalReferencePlutusScriptWitness prefix autoBalanceExecUnits =
)

pCurrentTreasuryValueAndDonation
:: Parser (Maybe (TxCurrentTreasuryValue, TxTreasuryDonation))
:: Parser (Maybe (Maybe TxCurrentTreasuryValue, TxTreasuryDonation))
pCurrentTreasuryValueAndDonation =
optional ((,) <$> pCurrentTreasuryValue' <*> pTreasuryDonation')
optional ((,) <$> optional pCurrentTreasuryValue' <*> pTreasuryDonation')

pCurrentTreasuryValue' :: Parser TxCurrentTreasuryValue
pCurrentTreasuryValue' =
Expand Down
4 changes: 2 additions & 2 deletions cardano-cli/src/Cardano/CLI/EraBased/Transaction/Command.hs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ data TransactionBuildRawCmdArgs era = TransactionBuildRawCmdArgs
, mUpdateProprosalFile :: !(Maybe (Featured ShelleyToBabbageEra era (Maybe UpdateProposalFile)))
, voteFiles :: ![(VoteFile In, Maybe (ScriptRequirements Exp.VoterItem))]
, proposalFiles :: ![(ProposalFile In, Maybe (ScriptRequirements Exp.ProposalItem))]
, currentTreasuryValueAndDonation :: !(Maybe (TxCurrentTreasuryValue, TxTreasuryDonation))
, currentTreasuryValueAndDonation :: !(Maybe (Maybe TxCurrentTreasuryValue, TxTreasuryDonation))
, isCborOutCanonical :: !TxCborFormat
, txBodyOutFile :: !(TxBodyFile Out)
}
Expand Down Expand Up @@ -198,7 +198,7 @@ data TransactionBuildEstimateCmdArgs era = TransactionBuildEstimateCmdArgs
, metadataFiles :: ![MetadataFile]
, voteFiles :: ![(VoteFile In, Maybe (ScriptRequirements Exp.VoterItem))]
, proposalFiles :: ![(ProposalFile In, Maybe (ScriptRequirements Exp.ProposalItem))]
, currentTreasuryValueAndDonation :: !(Maybe (TxCurrentTreasuryValue, TxTreasuryDonation))
, currentTreasuryValueAndDonation :: !(Maybe (Maybe TxCurrentTreasuryValue, TxTreasuryDonation))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than having a nested Maybe convert it to a separate field instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can do that, but that would be lifting an additional restriction: that you can't have TxCurrentTreasuryValue without a TxTreasuryDonation. It wouldn't be equivalent

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, actually, it may be that we can lift that restriction too, @lehins says they are completely independent

, isCborOutCanonical :: !TxCborFormat
, txBodyOutFile :: !(TxBodyFile Out)
}
Expand Down
15 changes: 9 additions & 6 deletions cardano-cli/src/Cardano/CLI/EraBased/Transaction/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,11 @@ runTransactionBuildCmd
let currentTreasuryValueAndDonation =
case (treasuryDonation, unFeatured <$> featuredCurrentTreasuryValueM) of
(Nothing, _) -> Nothing -- We shouldn't specify the treasury value when no donation is being done
(Just _td, Nothing) -> Nothing -- TODO: Current treasury value couldn't be obtained but is required: we should fail suggesting that the node's version is too old
(Just td, Just ctv) -> Just (ctv, td)
(Just td, mctv) -> Just (mctv, td) -- Current treasury value is not mandatory for donations, see:
-- \* https://intersectmbo.github.io/formal-ledger-specifications/site/Ledger.Conway.Specification.Utxo.html#sec:the-utxo-transition-system
-- \* https://intersectmbo.github.io/formal-ledger-specifications/site/Notation.html#the-maybe-type
-- And discussion:
-- \* https://discord.com/channels/1136727663583698984/1239888777015590913/1364244737602879498

-- We need to construct the txBodycontent outside of runTxBuild
BalancedTxBody txBodyContent balancedTxBody _ _ <-
Expand Down Expand Up @@ -743,7 +746,7 @@ runTxBuildRaw
-> TxUpdateProposal era
-> [(VotingProcedures era, Maybe (VoteScriptWitness era))]
-> [(Proposal era, Maybe (ProposalScriptWitness era))]
-> Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
-> Maybe (Maybe TxCurrentTreasuryValue, TxTreasuryDonation)
-> Either TxCmdError (Exp.UnsignedTx era)
runTxBuildRaw
mScriptValidity
Expand Down Expand Up @@ -829,7 +832,7 @@ constructTxBodyContent
-> TxUpdateProposal era
-> [(VotingProcedures era, Maybe (VoteScriptWitness era))]
-> [(Proposal era, Maybe (ProposalScriptWitness era))]
-> Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
-> Maybe (Maybe TxCurrentTreasuryValue, TxTreasuryDonation)
-- ^ The current treasury value and the donation. This is a stop gap as the
-- semantics of the donation and treasury value depend on the script languages
-- being used.
Expand Down Expand Up @@ -891,7 +894,7 @@ constructTxBodyContent
[(prop, pswScriptWitness <$> mSwit) | (Proposal prop, mSwit) <- proposals]
Featured w txp

let validatedCurrentTreasuryValue = validateTxCurrentTreasuryValue @era (fst <$> mCurrentTreasuryValueAndDonation)
let validatedCurrentTreasuryValue = validateTxCurrentTreasuryValue @era (fst =<< mCurrentTreasuryValueAndDonation)
validatedTreasuryDonation = validateTxTreasuryDonation @era (snd <$> mCurrentTreasuryValueAndDonation)
return $
shelleyBasedEraConstraints
Expand Down Expand Up @@ -969,7 +972,7 @@ runTxBuild
-> Maybe Word
-> [(VotingProcedures era, Maybe (VoteScriptWitness era))]
-> [(Proposal era, Maybe (ProposalScriptWitness era))]
-> Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
-> Maybe (Maybe TxCurrentTreasuryValue, TxTreasuryDonation)
-- ^ The current treasury value and the donation.
-> ExceptT TxCmdError IO (BalancedTxBody era)
runTxBuild
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,38 +45,41 @@ hprop_golden_conway_build_raw_treasury_donation =

H.diffFileVsGoldenFile outFile goldenFile

-- Negative test: Missing --current-treasury-value
-- Current treasury value is not mandatory for donations, see formal spec:
-- \* https://intersectmbo.github.io/formal-ledger-specifications/site/Ledger.Conway.Specification.Utxo.html#sec:the-utxo-transition-system
-- \* https://intersectmbo.github.io/formal-ledger-specifications/site/Notation.html#the-maybe-type
-- And discussion:
-- \* https://discord.com/channels/1136727663583698984/1239888777015590913/1364244737602879498

-- | Execute me with:
-- @cabal test cardano-cli-golden --test-options '-p "/golden conway build raw donation no current treasury value/"'@
hprop_golden_conway_build_raw_donation_no_current_treasury_value :: Property
hprop_golden_conway_build_raw_donation_no_current_treasury_value =
watchdogProp . propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do
let goldenFile = "test/cardano-cli-golden/files/golden/conway/donation-no-current-val.tx"
-- Key filepaths
outFile <- noteTempFile tempDir "out.json"

(exitCode, _stdout, stderr) <-
H.noteShowM $
execDetailCardanoCLI
[ "conway"
, "transaction"
, "build-raw"
, "--tx-in"
, "f62cd7bc15d8c6d2c8519fb8d13c57c0157ab6bab50af62bc63706feb966393d#0"
, "--tx-out"
, "addr_test1qpmxr8d8jcl25kyz2tz9a9sxv7jxglhddyf475045y8j3zxjcg9vquzkljyfn3rasfwwlkwu7hhm59gzxmsyxf3w9dps8832xh+1199989833223"
, "--tx-out"
, "addr_test1vpqgspvmh6m2m5pwangvdg499srfzre2dd96qq57nlnw6yctpasy4+10000000"
, "--treasury-donation"
, "1000343"
, "--fee"
, "166777"
, "--out-file"
, outFile
]
void $
execCardanoCLI
[ "conway"
, "transaction"
, "build-raw"
, "--tx-in"
, "f62cd7bc15d8c6d2c8519fb8d13c57c0157ab6bab50af62bc63706feb966393d#0"
, "--tx-out"
, "addr_test1qpmxr8d8jcl25kyz2tz9a9sxv7jxglhddyf475045y8j3zxjcg9vquzkljyfn3rasfwwlkwu7hhm59gzxmsyxf3w9dps8832xh+1199989833223"
, "--tx-out"
, "addr_test1vpqgspvmh6m2m5pwangvdg499srfzre2dd96qq57nlnw6yctpasy4+10000000"
, "--treasury-donation"
, "1000343"
, "--fee"
, "166777"
, "--out-file"
, outFile
]

exitCode H.=== ExitFailure 1
H.assertWith stderr ("Missing: --current-treasury-value LOVELACE" `isInfixOf`)
H.diffFileVsGoldenFile outFile goldenFile

-- Negative test: Missing --treasury-donation

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "Tx ConwayEra",
"description": "Ledger Cddl Format",
"cborHex": "84a400d9010281825820f62cd7bc15d8c6d2c8519fb8d13c57c0157ab6bab50af62bc63706feb966393d0001828258390076619da7963eaa588252c45e960667a4647eed69135f51f5a10f2888d2c20ac07056fc8899c47d825cefd9dcf5efba150236e043262e2b431b0000011764f7be0782581d604088059bbeb6add02eecd0c6a2a52c06910f2a6b4ba0029e9fe6ed131a00989680021a00028b79161a000f4397a0f5f6"
}
12 changes: 8 additions & 4 deletions cardano-cli/test/cardano-cli-golden/files/golden/help.cli
Original file line number Diff line number Diff line change
Expand Up @@ -2750,7 +2750,8 @@ Usage: cardano-cli conway transaction build-raw
)
--proposal-reference-tx-in-execution-units (INT, INT)
]]
[--current-treasury-value LOVELACE
[
[--current-treasury-value LOVELACE]
--treasury-donation LOVELACE]
[--out-canonical-cbor]
--out-file FILEPATH
Expand Down Expand Up @@ -3069,7 +3070,8 @@ Usage: cardano-cli conway transaction build-estimate
)
--proposal-reference-tx-in-execution-units (INT, INT)
]]
[--current-treasury-value LOVELACE
[
[--current-treasury-value LOVELACE]
--treasury-donation LOVELACE]
[--out-canonical-cbor]
--out-file FILEPATH
Expand Down Expand Up @@ -5047,7 +5049,8 @@ Usage: cardano-cli latest transaction build-raw
)
--proposal-reference-tx-in-execution-units (INT, INT)
]]
[--current-treasury-value LOVELACE
[
[--current-treasury-value LOVELACE]
--treasury-donation LOVELACE]
[--out-canonical-cbor]
--out-file FILEPATH
Expand Down Expand Up @@ -5366,7 +5369,8 @@ Usage: cardano-cli latest transaction build-estimate
)
--proposal-reference-tx-in-execution-units (INT, INT)
]]
[--current-treasury-value LOVELACE
[
[--current-treasury-value LOVELACE]
--treasury-donation LOVELACE]
[--out-canonical-cbor]
--out-file FILEPATH
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ Usage: cardano-cli conway transaction build-estimate
)
--proposal-reference-tx-in-execution-units (INT, INT)
]]
[--current-treasury-value LOVELACE
[
[--current-treasury-value LOVELACE]
--treasury-donation LOVELACE]
[--out-canonical-cbor]
--out-file FILEPATH
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ Usage: cardano-cli conway transaction build-raw
)
--proposal-reference-tx-in-execution-units (INT, INT)
]]
[--current-treasury-value LOVELACE
[
[--current-treasury-value LOVELACE]
--treasury-donation LOVELACE]
[--out-canonical-cbor]
--out-file FILEPATH
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ Usage: cardano-cli latest transaction build-estimate
)
--proposal-reference-tx-in-execution-units (INT, INT)
]]
[--current-treasury-value LOVELACE
[
[--current-treasury-value LOVELACE]
--treasury-donation LOVELACE]
[--out-canonical-cbor]
--out-file FILEPATH
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ Usage: cardano-cli latest transaction build-raw
)
--proposal-reference-tx-in-execution-units (INT, INT)
]]
[--current-treasury-value LOVELACE
[
[--current-treasury-value LOVELACE]
--treasury-donation LOVELACE]
[--out-canonical-cbor]
--out-file FILEPATH
Expand Down
Loading