Skip to content

Commit

Permalink
Introduce a requestedAmount field to NotEnoughFunds to observe errors…
Browse files Browse the repository at this point in the history
… better

- When returning funds use queryUTxOFor instead of queryMarkedUTxo
  • Loading branch information
v0d1ch committed Mar 10, 2023
1 parent 669e209 commit f86c30e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions hydra-cluster/src/Hydra/Cluster/Faucet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import Hydra.Ledger.Cardano ()
data Marked = Fuel | Normal

data FaucetException
= NotEnoughFunds {utxo :: UTxO}
= NotEnoughFunds {utxos :: UTxO, requestedAmount :: Lovelace}
| FailedToBuildTx {reason :: TxBodyErrorAutoBalance}
deriving (Show)

Expand Down Expand Up @@ -144,10 +144,10 @@ retryOnExceptions tracer action =
-- We expect proper utxo to have more 'Lovelace' than the @lovelace@ argument
findUTxO :: RunningNode -> Lovelace -> VerificationKey PaymentKey -> IO UTxO
findUTxO RunningNode{networkId, nodeSocket} lovelace faucetVk = do
utxo <- queryUTxO networkId nodeSocket QueryTip [buildAddress faucetVk networkId]
let foundUTxO = UTxO.filter (\o -> txOutLovelace o >= lovelace) utxo
utxos <- queryUTxO networkId nodeSocket QueryTip [buildAddress faucetVk networkId]
let foundUTxO = UTxO.filter (\o -> txOutLovelace o >= lovelace) utxos
when (null foundUTxO) $
throwIO $ NotEnoughFunds{utxo}
throwIO $ NotEnoughFunds{utxos, requestedAmount = lovelace}
pure foundUTxO

-- | Like 'seedFromFaucet', but without returning the seeded 'UTxO'.
Expand Down
8 changes: 4 additions & 4 deletions hydra-cluster/src/Hydra/Cluster/Scenarios.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Hydra.Cluster.Scenarios where

import Hydra.Prelude

import CardanoClient (queryTip)
import CardanoClient (QueryPoint (..), queryTip, queryUTxOFor)
import CardanoNode (RunningNode (..))
import Control.Lens ((^?))
import Data.Aeson (Value, object, (.=))
Expand Down Expand Up @@ -205,11 +205,11 @@ returnAssetsToFaucet ::
RunningNode ->
Actor ->
IO ()
returnAssetsToFaucet tracer node sender = do
returnAssetsToFaucet tracer node@RunningNode{networkId, nodeSocket} sender = do
(receivingVk, _) <- keysFor Faucet
(senderVk, senderSk) <- keysFor sender
(fuelUTxO, otherUTxO) <- queryMarkedUTxO node senderVk
let returnBalance = selectLovelace $ balance @Tx (otherUTxO <> fuelUTxO)
utxo <- queryUTxOFor networkId nodeSocket QueryTip senderVk
let returnBalance = selectLovelace $ balance @Tx utxo
void $ sendFundsTo node (senderVk, senderSk) receivingVk returnBalance Normal (contramap FromFaucet tracer)
traceWith tracer $ ReturningToFaucet{actor = actorName sender, returnAmount = returnBalance}

Expand Down

0 comments on commit f86c30e

Please sign in to comment.