From 4153eed7cfd5af1d146d5640d4a3cdb601d65368 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hurlin?= Date: Tue, 12 Nov 2024 14:57:29 +0100 Subject: [PATCH 1/5] Update API version to 10.2.0.0 --- cardano-cli/cardano-cli.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cardano-cli/cardano-cli.cabal b/cardano-cli/cardano-cli.cabal index 012438b1cb..4255145725 100644 --- a/cardano-cli/cardano-cli.cabal +++ b/cardano-cli/cardano-cli.cabal @@ -202,7 +202,7 @@ library binary, bytestring, canonical-json, - cardano-api ^>=10.1, + cardano-api ^>=10.2, cardano-binary, cardano-crypto, cardano-crypto-class ^>=2.1.2, From 2fca47dacf9d78b56cf6104bfe95a8c779cba1ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hurlin?= Date: Wed, 13 Nov 2024 16:27:06 +0100 Subject: [PATCH 2/5] Update CHaP (intentionally not hackage) --- cabal.project | 2 +- flake.lock | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cabal.project b/cabal.project index 9eb1804dcc..1864d105fa 100644 --- a/cabal.project +++ b/cabal.project @@ -14,7 +14,7 @@ repository cardano-haskell-packages -- you need to run if you change them index-state: , hackage.haskell.org 2024-10-11T15:49:11Z - , cardano-haskell-packages 2024-10-21T23:08:22Z + , cardano-haskell-packages 2024-11-12T08:40:13Z packages: cardano-cli diff --git a/flake.lock b/flake.lock index f49c5dc1ac..8a0d9daf9e 100644 --- a/flake.lock +++ b/flake.lock @@ -3,11 +3,11 @@ "CHaP": { "flake": false, "locked": { - "lastModified": 1729560667, - "narHash": "sha256-tHDAxN8erb23MIy7zH6VV6mCspKBstj2R1LkeBgZt28=", + "lastModified": 1731401651, + "narHash": "sha256-tXaUck9+0Ob4h6GBlbhYMI4ekW5e8biVJU5jPT/rjus=", "owner": "intersectmbo", "repo": "cardano-haskell-packages", - "rev": "7f24768c3a2f42a15fef889d5b415100d8082c16", + "rev": "82b295d6147a566c28dbcf038c54040f06f7e6b4", "type": "github" }, "original": { From 9e3192d3c497042c77e5ad8ff075acd3d30ff534 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hurlin?= Date: Wed, 30 Oct 2024 16:25:44 +0100 Subject: [PATCH 3/5] Adapt to API Value Parser change --- cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs b/cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs index a84a573e6a..433840263a 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs @@ -2044,7 +2044,7 @@ pNumberOfByronKeyWitnesses = pTotalUTxOValue :: Parser Value pTotalUTxOValue = - Opt.option (readerFromParsecParser parseValue) $ + Opt.option (readerFromParsecParser $ parseValue RoleUTxO) $ mconcat [ Opt.long "total-utxo-value" , Opt.metavar "VALUE" @@ -2136,7 +2136,7 @@ pMintMultiAsset pMintMultiAsset sbe balanceExecUnits = (,) <$> Opt.option - (readerFromParsecParser parseValue) + (readerFromParsecParser $ parseValue RoleMint) ( Opt.long "mint" <> Opt.metavar "VALUE" <> Opt.help helpText @@ -2194,7 +2194,7 @@ pMintMultiAsset sbe balanceExecUnits = pPolicyId :: Parser PolicyId pPolicyId = - Opt.option (readerFromParsecParser policyId) $ + Opt.option (readerFromParsecParser parsePolicyId) $ mconcat [ Opt.long "policy-id" , Opt.metavar "HASH" @@ -3308,7 +3308,7 @@ parseTxOutShelleyBasedEra = do -- Accept the old style of separating the address and value in a -- transaction output: Parsec.option () (Parsec.char '+' >> Parsec.spaces) - val <- parseValue + val <- parseValue RoleUTxO -- UTxO role works for transaction output return (TxOutShelleyBasedEra addr val) parseShelleyAddress :: Parsec.Parser (Address ShelleyAddr) @@ -3326,7 +3326,7 @@ parseTxOutAnyEra = do -- Accept the old style of separating the address and value in a -- transaction output: Parsec.option () (Parsec.char '+' >> Parsec.spaces) - val <- parseValue + val <- parseValue RoleUTxO -- UTxO role works for transaction output return (TxOutAnyEra addr val) -------------------------------------------------------------------------------- From a85bc65e2bea57b07910f95adc26ce8838b9a277 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hurlin?= Date: Wed, 30 Oct 2024 17:29:22 +0100 Subject: [PATCH 4/5] Add tests using the new behavior of API's Value parser --- .../Test/Cli/Shelley/Transaction/Build.hs | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/cardano-cli/test/cardano-cli-test/Test/Cli/Shelley/Transaction/Build.hs b/cardano-cli/test/cardano-cli-test/Test/Cli/Shelley/Transaction/Build.hs index 9270456a8e..e6b4a88188 100644 --- a/cardano-cli/test/cardano-cli-test/Test/Cli/Shelley/Transaction/Build.hs +++ b/cardano-cli/test/cardano-cli-test/Test/Cli/Shelley/Transaction/Build.hs @@ -44,3 +44,52 @@ hprop_conway_transaction_build_one_voter_many_votes = propertyOnce $ H.moduleWor exitCode H.=== ExitFailure 1 H.assertWith stderr ("This would cause ignoring some of the votes" `isInfixOf`) + +-- | This is a test of https://github.com/IntersectMBO/cardano-cli/issues/904 +-- Execute me with: +-- @cabal test cardano-cli-test --test-options '-p "/conway transaction build raw negative txout/"'@ +hprop_conway_transaction_build_raw_negative_txout :: Property +hprop_conway_transaction_build_raw_negative_txout = propertyOnce $ H.moduleWorkspace "tmp" $ \tempDir -> do + outFile <- H.noteTempFile tempDir "tx.traw" + + (exitCode, _stdout, stderr) <- + H.noteShowM $ + execDetailCardanoCLI + [ "conway" + , "transaction" + , "build-raw" + , "--fee" + , "200000" + , "--tx-in" + , "e25450233e4bedd00c8bda15c48c2d4018223bd88271e194052294c4e5be7d55#0" + , "--tx-out" + , "addr_test1vqfxq2s8yce3tuhjq9ulu2awuk623hzvtft9z8fh6qelzts49vuqw+-1" -- This is the negative txout + , "--out-file" + , outFile + ] + + exitCode H.=== ExitFailure 1 + H.assertWith stderr ("Value must be positive in UTxO (or transaction output)" `isInfixOf`) + +-- | This is a test that we allow transaction outputs to contain negative bits, if +-- the grand total is positive. +-- @cabal test cardano-cli-test --test-options '-p "/conway transaction build raw negative bits positive total txout/"'@ +hprop_conway_transaction_build_raw_negative_bits_positive_total_txout :: Property +hprop_conway_transaction_build_raw_negative_bits_positive_total_txout = propertyOnce $ H.moduleWorkspace "tmp" $ \tempDir -> do + outFile <- H.noteTempFile tempDir "tx.traw" + + -- This checks that the command succeeds + H.noteShowM_ $ + execCardanoCLI + [ "conway" + , "transaction" + , "build-raw" + , "--fee" + , "200000" + , "--tx-in" + , "e25450233e4bedd00c8bda15c48c2d4018223bd88271e194052294c4e5be7d55#0" + , "--tx-out" + , "addr_test1vqfxq2s8yce3tuhjq9ulu2awuk623hzvtft9z8fh6qelzts49vuqw+-1+3" -- Negative txout (-1) summed with positive txout (+3), so total is positive + , "--out-file" + , outFile + ] From cb2f488841348a53e3bba1c3f6a9222c2bd6e78c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hurlin?= Date: Wed, 13 Nov 2024 17:36:02 +0100 Subject: [PATCH 5/5] Adapt to tx supplemental data changes --- .../src/Cardano/CLI/EraBased/Run/Transaction.hs | 2 +- cardano-cli/src/Cardano/CLI/Json/Friendly.hs | 17 +---------------- 2 files changed, 2 insertions(+), 17 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs index c59ace374a..e4b1018e75 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs @@ -1313,7 +1313,7 @@ toTxAlonzoDatum supp cliDatum = pure (TxOutDatumHash supp $ hashScriptDataBytes sData) TxOutDatumByValue sDataOrFile -> do sData <- firstExceptT TxCmdScriptDataError $ readScriptDataOrFile sDataOrFile - pure (TxOutDatumInTx supp sData) + pure (TxOutSupplementalDatum supp sData) TxOutInlineDatumByValue sDataOrFile -> do let cEra = toCardanoEra supp forEraInEon cEra (txFeatureMismatch cEra TxFeatureInlineDatums) $ \babbageOnwards -> do diff --git a/cardano-cli/src/Cardano/CLI/Json/Friendly.hs b/cardano-cli/src/Cardano/CLI/Json/Friendly.hs index 8549ae2a25..8c95c4bf3f 100644 --- a/cardano-cli/src/Cardano/CLI/Json/Friendly.hs +++ b/cardano-cli/src/Cardano/CLI/Json/Friendly.hs @@ -212,7 +212,6 @@ friendlyTxBodyImpl txValidityUpperBound txMetadata txAuxScripts - txSupplementalData txExtraKeyWits _txProtocolParams txWithdrawals @@ -252,10 +251,6 @@ friendlyTxBodyImpl era (`getRedeemerDetails` tb) ) - ++ ( monoidForEraInEon @AlonzoEraOnwards - era - (`friendlySupplementalDatums` txSupplementalData) - ) ++ ( monoidForEraInEon @ConwayEraOnwards era ( \cOnwards -> @@ -293,16 +288,6 @@ friendlyTxBodyImpl friendlyLedgerProposals cOnwards proposalProcedures = Array $ fromList $ map (friendlyLedgerProposal cOnwards) proposalProcedures --- | API doesn't yet show that supplemental datums are alonzo onwards. So we do it in this function prototype, --- even if we don't use the witness. -friendlySupplementalDatums - :: AlonzoEraOnwards era -> BuildTxWith build (TxSupplementalDatums era) -> [Aeson.Pair] -friendlySupplementalDatums _era = \case - ViewTx -> [] - BuildTxWith TxSupplementalDataNone -> [] - BuildTxWith (TxSupplementalDatums hashableScriptDatas) -> - ["supplemental datums" .= toJSON hashableScriptDatas] - friendlyLedgerProposal :: ConwayEraOnwards era -> L.ProposalProcedure (ShelleyLedgerEra era) -> Aeson.Value friendlyLedgerProposal cOnwards proposalProcedure = object $ friendlyProposalImpl cOnwards (Proposal proposalProcedure) @@ -483,7 +468,7 @@ friendlyTxOut era (TxOut addr amount mdatum script) = renderDatum = \case TxOutDatumNone -> Nothing TxOutDatumHash _ h -> Just $ toJSON h - TxOutDatumInTx _ sData -> Just $ scriptDataToJson ScriptDataJsonDetailedSchema sData + TxOutSupplementalDatum _ sData -> Just $ scriptDataToJson ScriptDataJsonDetailedSchema sData TxOutDatumInline _ sData -> Just $ scriptDataToJson ScriptDataJsonDetailedSchema sData friendlyStakeReference :: StakeAddressReference -> Aeson.Value