From 0712366b9e540d366d63bf6fd95c787158128637 Mon Sep 17 00:00:00 2001 From: Pablo Lamela Date: Thu, 24 Oct 2024 13:28:44 +0200 Subject: [PATCH] Update `hprop_ledger_events_treasury_withdrawal` to work with the new checks --- .../Testnet/Test/Gov/TreasuryWithdrawal.hs | 69 +++++++++++-------- 1 file changed, 41 insertions(+), 28 deletions(-) diff --git a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/TreasuryWithdrawal.hs b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/TreasuryWithdrawal.hs index 881c2519b0b..1df6538a0c4 100644 --- a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/TreasuryWithdrawal.hs +++ b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/TreasuryWithdrawal.hs @@ -35,12 +35,14 @@ import qualified Data.Map.Strict as M import qualified Data.Text as Text import GHC.Stack import Lens.Micro +import System.Directory (makeAbsolute) import System.FilePath (()) +import Test.Cardano.CLI.Hash (serveFilesWhile) import Testnet.Components.Query import Testnet.Defaults import Testnet.Process.Cli.Keys (cliStakeAddressKeyGen) -import Testnet.Process.Run (execCli', mkExecConfig) +import Testnet.Process.Run (addEnvVarsToConfig, execCli', mkExecConfig) import Testnet.Property.Util (integrationRetryWorkspace) import Testnet.Start.Types import Testnet.Types @@ -87,13 +89,14 @@ hprop_ledger_events_treasury_withdrawal = integrationRetryWorkspace 2 "treasury H.note_ $ "Foldblocks config file: " <> unFile configurationFile gov <- H.createDirectoryIfMissing $ work "governance" - proposalAnchorFile <- H.note $ work gov "sample-proposal-anchor" - treasuryWithdrawalActionFp <- H.note $ work gov "treasury-withdrawal.action" - H.writeFile proposalAnchorFile "dummy anchor data" + let proposalAnchorDataIpfsHash = "QmexFJuEn5RtnHEqpxDcqrazdHPzAwe7zs2RxHLfMH5gBz" + proposalAnchorFile <- H.noteM $ liftIO $ makeAbsolute $ "test" "cardano-testnet-test" "files" "sample-proposal-anchor" + + treasuryWithdrawalActionFp <- H.note $ work gov "treasury-withdrawal.action" proposalAnchorDataHash <- execCli' execConfig - [ "hash", "anchor-data", "--file-text", proposalAnchorFile + [ "hash", "anchor-data", "--file-binary", proposalAnchorFile ] txin2 <- findLargestUtxoForPaymentKey epochStateView sbe wallet1 @@ -145,35 +148,45 @@ hprop_ledger_events_treasury_withdrawal = integrationRetryWorkspace 2 "treasury -- {{{ Create treasury withdrawal let withdrawalAmount = 3_300_777 :: Integer govActionDeposit <- getMinDRepDeposit epochStateView ceo - void $ execCli' execConfig - [ eraName, "governance", "action", "create-treasury-withdrawal" - , "--testnet" - , "--anchor-url", "https://tinyurl.com/3wrwb2as" - , "--anchor-data-hash", proposalAnchorDataHash - , "--governance-action-deposit", show govActionDeposit - , "--deposit-return-stake-verification-key-file", stakeVkeyFp - , "--transfer", show withdrawalAmount - , "--funds-receiving-stake-verification-key-file", stakeVkeyFp - , "--out-file", treasuryWithdrawalActionFp - ] + let relativeUrl = ["ipfs", proposalAnchorDataIpfsHash] txbodyFp <- H.note $ work "tx.body" txbodySignedFp <- H.note $ work "tx.body.signed" - -- wait for one block before using wallet0 again - _ <- waitForBlocks epochStateView 1 - txin3 <- findLargestUtxoForPaymentKey epochStateView sbe wallet0 - - void $ execCli' execConfig - [ eraName, "transaction", "build" - , "--change-address", Text.unpack $ paymentKeyInfoAddr wallet0 - , "--tx-in", Text.unpack $ renderTxIn txin3 - , "--tx-out", Text.unpack (paymentKeyInfoAddr wallet1) <> "+" <> show @Int 5_000_000 - , "--proposal-file", treasuryWithdrawalActionFp - , "--out-file", txbodyFp - ] + -- Create temporary HTTP server with files required by the call to `cardano-cli` + -- In this case, the server emulates an IPFS gateway + serveFilesWhile + [(relativeUrl, proposalAnchorFile)] + ( \port -> do + let execConfig' = addEnvVarsToConfig execConfig [("IPFS_GATEWAY_URI", "http://localhost:" ++ show port ++ "/")] + void $ execCli' execConfig' + [ eraName, "governance", "action", "create-treasury-withdrawal" + , "--testnet" + , "--anchor-url", "ipfs://" ++ proposalAnchorDataIpfsHash + , "--anchor-data-hash", proposalAnchorDataHash + , "--governance-action-deposit", show govActionDeposit + , "--deposit-return-stake-verification-key-file", stakeVkeyFp + , "--transfer", show withdrawalAmount + , "--funds-receiving-stake-verification-key-file", stakeVkeyFp + , "--out-file", treasuryWithdrawalActionFp + ] + + -- wait for one block before using wallet0 again + _ <- waitForBlocks epochStateView 1 + + txin3 <- findLargestUtxoForPaymentKey epochStateView sbe wallet0 + + void $ execCli' execConfig' + [ eraName, "transaction", "build" + , "--change-address", Text.unpack $ paymentKeyInfoAddr wallet0 + , "--tx-in", Text.unpack $ renderTxIn txin3 + , "--tx-out", Text.unpack (paymentKeyInfoAddr wallet1) <> "+" <> show @Int 5_000_000 + , "--proposal-file", treasuryWithdrawalActionFp + , "--out-file", txbodyFp + ] + ) void $ execCli' execConfig [ eraName, "transaction", "sign"