Skip to content

Commit

Permalink
Merge pull request #967 from input-output-hk/smoke-test-failed-to-rec…
Browse files Browse the repository at this point in the history
…ollect-funds

Smoke test failed to recollect funds
  • Loading branch information
abailly-iohk committed Jul 5, 2023
2 parents ef4780a + 2680d45 commit 69441d0
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions hydra-cluster/src/Hydra/Cluster/Faucet.hs
Expand Up @@ -127,18 +127,21 @@ returnFundsToFaucet tracer node@RunningNode{networkId, nodeSocket} sender = do
utxo <- queryUTxOFor networkId nodeSocket QueryTip senderVk

retryOnExceptions tracer $ do
let allLovelace = selectLovelace $ balance @Tx utxo
let utxoValue = balance @Tx utxo
let allLovelace = selectLovelace utxoValue
-- select tokens other than ADA here so we can burn it afterwards
let otherTokens = filterValue (/= AdaAssetId) utxoValue
-- XXX: Using a hard-coded high-enough value to satisfy the min utxo value.
-- NOTE: We use the faucet address as the change deliberately here.
fee <- calculateTxFee node senderSk utxo faucetAddress 1_000_000
let returnBalance = allLovelace - fee
tx <- sign senderSk <$> buildTxBody utxo faucetAddress returnBalance
tx <- sign senderSk <$> buildTxBody utxo faucetAddress returnBalance otherTokens
submitTransaction networkId nodeSocket tx
void $ awaitTransaction networkId nodeSocket tx
traceWith tracer $ ReturnedFunds{actor = actorName sender, returnAmount = returnBalance}
where
buildTxBody utxo faucetAddress lovelace =
let theOutput = TxOut faucetAddress (lovelaceToValue lovelace) TxOutDatumNone ReferenceScriptNone
buildTxBody utxo faucetAddress lovelace otherTokens =
let theOutput = TxOut faucetAddress (lovelaceToValue lovelace <> negateValue otherTokens) TxOutDatumNone ReferenceScriptNone
in buildTransaction networkId nodeSocket faucetAddress utxo [] [theOutput] >>= \case
Left e -> throwIO $ FaucetFailedToBuildTx{reason = e}
Right body -> pure body
Expand Down

0 comments on commit 69441d0

Please sign in to comment.