@@ -35,12 +35,14 @@ import qualified Data.Map.Strict as M
3535import qualified Data.Text as Text
3636import GHC.Stack
3737import Lens.Micro
38+ import System.Directory (makeAbsolute )
3839import System.FilePath ((</>) )
3940
41+ import Test.Cardano.CLI.Hash (serveFilesWhile )
4042import Testnet.Components.Query
4143import Testnet.Defaults
4244import Testnet.Process.Cli.Keys (cliStakeAddressKeyGen )
43- import Testnet.Process.Run (execCli' , mkExecConfig )
45+ import Testnet.Process.Run (addEnvVarsToConfig , execCli' , mkExecConfig )
4446import Testnet.Property.Util (integrationRetryWorkspace )
4547import Testnet.Start.Types
4648import Testnet.Types
@@ -87,13 +89,14 @@ hprop_ledger_events_treasury_withdrawal = integrationRetryWorkspace 2 "treasury
8789 H. note_ $ " Foldblocks config file: " <> unFile configurationFile
8890
8991 gov <- H. createDirectoryIfMissing $ work </> " governance"
90- proposalAnchorFile <- H. note $ work </> gov </> " sample-proposal-anchor"
91- treasuryWithdrawalActionFp <- H. note $ work </> gov </> " treasury-withdrawal.action"
9292
93- H. writeFile proposalAnchorFile " dummy anchor data"
93+ let proposalAnchorDataIpfsHash = " QmexFJuEn5RtnHEqpxDcqrazdHPzAwe7zs2RxHLfMH5gBz"
94+ proposalAnchorFile <- H. noteM $ liftIO $ makeAbsolute $ " test" </> " cardano-testnet-test" </> " files" </> " sample-proposal-anchor"
95+
96+ treasuryWithdrawalActionFp <- H. note $ work </> gov </> " treasury-withdrawal.action"
9497
9598 proposalAnchorDataHash <- execCli' execConfig
96- [ " hash" , " anchor-data" , " --file-text " , proposalAnchorFile
99+ [ " hash" , " anchor-data" , " --file-binary " , proposalAnchorFile
97100 ]
98101
99102 txin2 <- findLargestUtxoForPaymentKey epochStateView sbe wallet1
@@ -145,35 +148,45 @@ hprop_ledger_events_treasury_withdrawal = integrationRetryWorkspace 2 "treasury
145148 -- {{{ Create treasury withdrawal
146149 let withdrawalAmount = 3_300_777 :: Integer
147150 govActionDeposit <- getMinDRepDeposit epochStateView ceo
148- void $ execCli' execConfig
149- [ eraName, " governance" , " action" , " create-treasury-withdrawal"
150- , " --testnet"
151- , " --anchor-url" , " https://tinyurl.com/3wrwb2as"
152- , " --anchor-data-hash" , proposalAnchorDataHash
153- , " --governance-action-deposit" , show govActionDeposit
154- , " --deposit-return-stake-verification-key-file" , stakeVkeyFp
155- , " --transfer" , show withdrawalAmount
156- , " --funds-receiving-stake-verification-key-file" , stakeVkeyFp
157- , " --out-file" , treasuryWithdrawalActionFp
158- ]
159151
152+ let relativeUrl = [" ipfs" , proposalAnchorDataIpfsHash]
160153
161154 txbodyFp <- H. note $ work </> " tx.body"
162155 txbodySignedFp <- H. note $ work </> " tx.body.signed"
163156
164- -- wait for one block before using wallet0 again
165- _ <- waitForBlocks epochStateView 1
166157
167- txin3 <- findLargestUtxoForPaymentKey epochStateView sbe wallet0
168-
169- void $ execCli' execConfig
170- [ eraName, " transaction" , " build"
171- , " --change-address" , Text. unpack $ paymentKeyInfoAddr wallet0
172- , " --tx-in" , Text. unpack $ renderTxIn txin3
173- , " --tx-out" , Text. unpack (paymentKeyInfoAddr wallet1) <> " +" <> show @ Int 5_000_000
174- , " --proposal-file" , treasuryWithdrawalActionFp
175- , " --out-file" , txbodyFp
176- ]
158+ -- Create temporary HTTP server with files required by the call to `cardano-cli`
159+ -- In this case, the server emulates an IPFS gateway
160+ serveFilesWhile
161+ [(relativeUrl, proposalAnchorFile)]
162+ ( \ port -> do
163+ let execConfig' = addEnvVarsToConfig execConfig [(" IPFS_GATEWAY_URI" , " http://localhost:" ++ show port ++ " /" )]
164+ void $ execCli' execConfig'
165+ [ eraName, " governance" , " action" , " create-treasury-withdrawal"
166+ , " --testnet"
167+ , " --anchor-url" , " ipfs://" ++ proposalAnchorDataIpfsHash
168+ , " --anchor-data-hash" , proposalAnchorDataHash
169+ , " --governance-action-deposit" , show govActionDeposit
170+ , " --deposit-return-stake-verification-key-file" , stakeVkeyFp
171+ , " --transfer" , show withdrawalAmount
172+ , " --funds-receiving-stake-verification-key-file" , stakeVkeyFp
173+ , " --out-file" , treasuryWithdrawalActionFp
174+ ]
175+
176+ -- wait for one block before using wallet0 again
177+ _ <- waitForBlocks epochStateView 1
178+
179+ txin3 <- findLargestUtxoForPaymentKey epochStateView sbe wallet0
180+
181+ void $ execCli' execConfig'
182+ [ eraName, " transaction" , " build"
183+ , " --change-address" , Text. unpack $ paymentKeyInfoAddr wallet0
184+ , " --tx-in" , Text. unpack $ renderTxIn txin3
185+ , " --tx-out" , Text. unpack (paymentKeyInfoAddr wallet1) <> " +" <> show @ Int 5_000_000
186+ , " --proposal-file" , treasuryWithdrawalActionFp
187+ , " --out-file" , txbodyFp
188+ ]
189+ )
177190
178191 void $ execCli' execConfig
179192 [ eraName, " transaction" , " sign"
0 commit comments