Skip to content

Commit fbc27eb

Browse files
Merge branch 'master' into lc/cardano-api-8.40
2 parents 64d3ce2 + da73c47 commit fbc27eb

File tree

4 files changed

+28
-26
lines changed

4 files changed

+28
-26
lines changed

hydra-cluster/src/CardanoClient.hs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,23 +79,29 @@ submitTx :: RunningNode -> Tx -> IO ()
7979
submitTx RunningNode{networkId, nodeSocket} =
8080
submitTransaction networkId nodeSocket
8181

82-
waitForPayment ::
82+
-- | Wait until the specified Address has received payments, visible on-chain,
83+
-- for the specified Lovelace amount. Returns the UTxO set containing all payments
84+
-- with the same Lovelace amount at the given Address.
85+
--
86+
-- Note that this function loops indefinitely; therefore, it's recommended to use
87+
-- it with a surrounding timeout mechanism.
88+
waitForPayments ::
8389
NetworkId ->
8490
SocketPath ->
8591
Coin ->
8692
Address ShelleyAddr ->
8793
IO UTxO
88-
waitForPayment networkId socket amount addr =
94+
waitForPayments networkId socket amount addr =
8995
go
9096
where
9197
go = do
9298
utxo <- queryUTxO networkId socket QueryTip [addr]
93-
let expectedPayment = selectPayment utxo
94-
if expectedPayment /= mempty
95-
then pure $ UTxO expectedPayment
99+
let expectedPayments = selectPayments utxo
100+
if expectedPayments /= mempty
101+
then pure $ UTxO expectedPayments
96102
else threadDelay 1 >> go
97103

98-
selectPayment (UTxO utxo) =
104+
selectPayments (UTxO utxo) =
99105
Map.filter ((== amount) . selectLovelace . txOutValue) utxo
100106

101107
waitForUTxO ::
@@ -110,7 +116,7 @@ waitForUTxO networkId nodeSocket utxo =
110116
forEachUTxO = \case
111117
TxOut (ShelleyAddressInEra addr@ShelleyAddress{}) value _ _ -> do
112118
void $
113-
waitForPayment
119+
waitForPayments
114120
networkId
115121
nodeSocket
116122
(selectLovelace value)

hydra-cluster/src/Hydra/Cluster/Faucet.hs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import CardanoClient (
1616
queryUTxOFor,
1717
sign,
1818
submitTransaction,
19-
waitForPayment,
2019
)
2120
import Control.Exception (IOException)
2221
import Control.Monad.Class.MonadThrow (Handler (Handler), catches)
@@ -56,16 +55,19 @@ seedFromFaucet ::
5655
IO UTxO
5756
seedFromFaucet node@RunningNode{networkId, nodeSocket} receivingVerificationKey lovelace tracer = do
5857
(faucetVk, faucetSk) <- keysFor Faucet
59-
retryOnExceptions tracer $ submitSeedTx faucetVk faucetSk
60-
waitForPayment networkId nodeSocket lovelace receivingAddress
58+
seedTx <- retryOnExceptions tracer $ submitSeedTx faucetVk faucetSk
59+
producedUTxO <- awaitTransaction networkId nodeSocket seedTx
60+
pure $ UTxO.filter (== toUTxOContext theOutput) producedUTxO
6161
where
6262
submitSeedTx faucetVk faucetSk = do
6363
faucetUTxO <- findFaucetUTxO node lovelace
6464
let changeAddress = ShelleyAddressInEra (buildAddress faucetVk networkId)
6565
buildTransaction networkId nodeSocket changeAddress faucetUTxO [] [theOutput] >>= \case
6666
Left e -> throwIO $ FaucetFailedToBuildTx{reason = e}
6767
Right body -> do
68+
let signedTx = sign faucetSk body
6869
submitTransaction networkId nodeSocket (sign faucetSk body)
70+
pure signedTx
6971

7072
receivingAddress = buildAddress receivingVerificationKey networkId
7173

@@ -190,7 +192,7 @@ calculateTxFee RunningNode{networkId, nodeSocket} secretKey utxo addr lovelace =
190192
Right body -> pure $ txFee' (sign secretKey body)
191193

192194
-- | Try to submit tx and retry when some caught exception/s take place.
193-
retryOnExceptions :: (MonadCatch m, MonadDelay m) => Tracer m FaucetLog -> m () -> m ()
195+
retryOnExceptions :: (MonadCatch m, MonadDelay m) => Tracer m FaucetLog -> m a -> m a
194196
retryOnExceptions tracer action =
195197
action
196198
`catches` [ Handler $ \(_ :: SubmitTransactionException) -> do

hydra-cluster/test/Test/Hydra/Cluster/FaucetSpec.hs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import Test.Hydra.Prelude
55

66
import CardanoClient (RunningNode (..))
77
import CardanoNode (withCardanoNodeDevnet)
8-
import Control.Concurrent.Async (replicateConcurrently_)
8+
import Control.Concurrent.Async (replicateConcurrently)
99
import Hydra.Cardano.Api (AssetId (AdaAssetId), selectAsset, txOutValue)
1010
import Hydra.Chain.CardanoClient (QueryPoint (..), queryUTxOFor)
11-
import Hydra.Cluster.Faucet (returnFundsToFaucet, seedFromFaucet, seedFromFaucet_)
11+
import Hydra.Cluster.Faucet (returnFundsToFaucet, seedFromFaucet)
1212
import Hydra.Cluster.Fixture (Actor (..))
1313
import Hydra.Cluster.Scenarios (EndToEndLog (..))
1414
import Hydra.Cluster.Util (keysFor)
@@ -19,17 +19,18 @@ import Test.QuickCheck (elements, generate)
1919
spec :: Spec
2020
spec = do
2121
describe "seedFromFaucet" $
22-
it "should work concurrently" $
22+
it "should work concurrently when called multiple times with the same amount of lovelace" $
2323
showLogsOnFailure "FaucetSpec" $ \tracer ->
2424
failAfter 30 $
2525
withTempDir "hydra-cluster" $ \tmpDir ->
26-
withCardanoNodeDevnet (contramap FromCardanoNode tracer) tmpDir $ \node ->
27-
replicateConcurrently_ 10 $ do
26+
withCardanoNodeDevnet (contramap FromCardanoNode tracer) tmpDir $ \node -> do
27+
utxos <- replicateConcurrently 10 $ do
2828
vk <- generate genVerificationKey
29-
seedFromFaucet_ node vk 1_000_000 (contramap FromFaucet tracer)
30-
29+
seedFromFaucet node vk 1_000_000 (contramap FromFaucet tracer)
30+
-- 10 unique outputs
31+
length (fold utxos) `shouldBe` 10
3132
describe "returnFundsToFaucet" $
32-
it "seedFromFaucet and returnFundsToFaucet work together" $ do
33+
it "seedFromFaucet and returnFundsToFaucet should work together" $ do
3334
showLogsOnFailure "FaucetSpec" $ \tracer ->
3435
withTempDir "hydra-cluster" $ \tmpDir ->
3536
withCardanoNodeDevnet (contramap FromCardanoNode tracer) tmpDir $ \node@RunningNode{networkId, nodeSocket} -> do

hydra-tui/src/Hydra/TUI/Handlers.hs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ handleEvent ::
4343
BrickEvent Name (HydraEvent Tx) ->
4444
EventM Name RootState ()
4545
handleEvent cardanoClient client e = do
46-
handleVtyEventVia (handleExtraHotkeys (handleEvent cardanoClient client)) () e
4746
zoom logStateL $ handleVtyEventVia handleVtyEventsLogState () e
4847
handleAppEventVia handleTick () e
4948
zoom connectedStateL $ do
@@ -55,12 +54,6 @@ handleEvent cardanoClient client e = do
5554
-- Any `EventM` that decides to `Continue` would override the `Halt` decision.
5655
handleGlobalEvents e
5756

58-
handleExtraHotkeys :: (BrickEvent w e -> EventM n s ()) -> Vty.Event -> EventM n s ()
59-
handleExtraHotkeys f = \case
60-
EvKey KDown [] -> f $ VtyEvent $ EvKey (KChar '\t') []
61-
EvKey KUp [] -> f $ VtyEvent $ EvKey KBackTab []
62-
_ -> pure ()
63-
6457
handleTick :: HydraEvent Tx -> EventM Name RootState ()
6558
handleTick = \case
6659
Tick now -> nowL .= now

0 commit comments

Comments
 (0)