Skip to content

Commit

Permalink
Update hydra clients with new field names
Browse files Browse the repository at this point in the history
  • Loading branch information
ch1bo committed Oct 7, 2024
1 parent 7d1c76c commit 2c97e77
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 24 deletions.
22 changes: 10 additions & 12 deletions hydra-cluster/bench/Bench/EndToEnd.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import Control.Concurrent.Class.MonadSTM (
tryReadTBQueue,
writeTBQueue,
)
import Control.Lens (to, (^?))
import Control.Lens (to, (^..), (^?))
import Control.Monad.Class.MonadAsync (mapConcurrently)
import Data.Aeson (Result (Error, Success), Value, encode, fromJSON, (.=))
import Data.Aeson.Lens (key, _Array, _JSON, _Number, _String)
import Data.Aeson.Lens (key, values, _JSON, _Number, _String)
import Data.Aeson.Types (parseMaybe)
import Data.List qualified as List
import Data.Map qualified as Map
Expand Down Expand Up @@ -424,7 +424,7 @@ newTx registry client tx = do
data WaitResult
= TxInvalid {transactionId :: TxId, reason :: Text}
| TxValid {transactionId :: TxId}
| SnapshotConfirmed {txIds :: [Value], snapshotNumber :: Scientific}
| SnapshotConfirmed {txIds :: [Value], number :: Scientific}

data Registry tx = Registry
{ processedTxs :: TVar IO (Map.Map TxId Event)
Expand Down Expand Up @@ -486,7 +486,7 @@ waitForAllConfirmations n1 Registry{processedTxs} allIds = do
maybeTxValid v = do
guard (v ^? key "tag" == Just "TxValid")
v
^? key "transaction" . key "txId" . to fromJSON >>= \case
^? key "transactionId" . to fromJSON >>= \case
Error _ -> Nothing
Success txid -> pure $ TxValid txid

Expand All @@ -501,14 +501,12 @@ waitForAllConfirmations n1 Registry{processedTxs} allIds = do
maybeSnapshotConfirmed v = do
guard (v ^? key "tag" == Just "SnapshotConfirmed")
snapshot <- v ^? key "snapshot"
SnapshotConfirmed
<$> snapshot
^? key "confirmedTransactions"
. _Array
. to toList
<*> snapshot
^? key "snapshotNumber"
. _Number
number <- snapshot ^? key "number" . _Number
pure $
SnapshotConfirmed
{ txIds = snapshot ^.. key "confirmed" . values . key "txId"
, number
}

confirmTx ::
TVar IO (Map.Map TxId Event) ->
Expand Down
4 changes: 2 additions & 2 deletions hydra-cluster/src/Hydra/Cluster/Scenarios.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1025,8 +1025,8 @@ respendUTxO client sk delay = do
waitMatch 10 client $ \v -> do
guard $ v ^? key "tag" == Just "SnapshotConfirmed"
guard $
toJSON (txId tx)
`elem` (v ^.. key "snapshot" . key "confirmedTransactions" . values)
toJSON tx
`elem` (v ^.. key "snapshot" . key "confirmed" . values)
v ^? key "snapshot" . key "utxo" >>= parseMaybe parseJSON

-- * Utilities
Expand Down
20 changes: 10 additions & 10 deletions hydra-cluster/test/Test/EndToEndSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ spec = around (showLogsOnFailure "EndToEndSpec") $ do
deadline <- waitMatch 3 n1 $ \v -> do
guard $ v ^? key "tag" == Just "HeadIsClosed"
guard $ v ^? key "headId" == Just (toJSON headId)
snapshotNumber <- v ^? key "snapshotNumber"
snapshotNumber <- v ^? key "number"
guard $ snapshotNumber == Aeson.Number 0
v ^? key "contestationDeadline" . _JSON

Expand Down Expand Up @@ -416,7 +416,7 @@ spec = around (showLogsOnFailure "EndToEndSpec") $ do
let isHeadClosedWith0 v = do
guard $ v ^? key "tag" == Just "HeadIsClosed"
guard $ v ^? key "headId" == Just (toJSON headId)
snapshotNumber <- v ^? key "snapshotNumber"
snapshotNumber <- v ^? key "number"
guard $ snapshotNumber == toJSON (0 :: Word)

waitMatch 10 n1 isHeadClosedWith0
Expand Down Expand Up @@ -632,12 +632,12 @@ timedTx tmpDir tracer node@RunningNode{networkId, nodeSocket} hydraScriptsTxId =
-- Second submission: now valid
send n1 $ input "NewTx" ["transaction" .= tx]
waitFor hydraTracer 3 [n1] $
output "TxValid" ["transaction" .= tx, "headId" .= headId]
output "TxValid" ["transactionId" .= txId tx, "headId" .= headId]

confirmedTransactions <- waitMatch 3 n1 $ \v -> do
guard $ v ^? key "tag" == Just "SnapshotConfirmed"
v ^? key "snapshot" . key "confirmedTransactions"
confirmedTransactions ^.. values `shouldBe` [toJSON $ txId tx]
v ^? key "snapshot" . key "confirmed"
confirmedTransactions ^.. values `shouldBe` [toJSON tx]

initAndClose :: FilePath -> Tracer IO EndToEndLog -> Int -> TxId -> RunningNode -> IO ()
initAndClose tmpDir tracer clusterIx hydraScriptsTxId node@RunningNode{nodeSocket} = do
Expand Down Expand Up @@ -687,7 +687,7 @@ initAndClose tmpDir tracer clusterIx hydraScriptsTxId node@RunningNode{nodeSocke
aliceExternalSk
send n1 $ input "NewTx" ["transaction" .= tx]
waitFor hydraTracer 10 [n1, n2, n3] $
output "TxValid" ["transaction" .= tx, "headId" .= headId]
output "TxValid" ["transactionId" .= txId tx, "headId" .= headId]

-- The expected new utxo set is the created payment to bob,
-- alice's remaining utxo in head and whatever bot has
Expand Down Expand Up @@ -724,20 +724,20 @@ initAndClose tmpDir tracer clusterIx hydraScriptsTxId node@RunningNode{nodeSocke
waitMatch 10 n1 $ \v -> do
guard $ v ^? key "tag" == Just "SnapshotConfirmed"
guard $ v ^? key "headId" == Just (toJSON headId)
snapshotNumber <- v ^? key "snapshot" . key "snapshotNumber"
snapshotNumber <- v ^? key "snapshot" . key "number"
guard $ snapshotNumber == toJSON expectedSnapshotNumber
utxo <- v ^? key "snapshot" . key "utxo"
guard $ utxo == toJSON newUTxO
confirmedTransactions <- v ^? key "snapshot" . key "confirmedTransactions"
guard $ confirmedTransactions == toJSON [txId tx]
confirmedTransactions <- v ^? key "snapshot" . key "confirmed"
guard $ confirmedTransactions == toJSON [tx]

(toJSON <$> getSnapshotUTxO n1) `shouldReturn` toJSON newUTxO

send n1 $ input "Close" []
deadline <- waitMatch 3 n1 $ \v -> do
guard $ v ^? key "tag" == Just "HeadIsClosed"
guard $ v ^? key "headId" == Just (toJSON headId)
snapshotNumber <- v ^? key "snapshotNumber"
snapshotNumber <- v ^? key "number"
guard $ snapshotNumber == toJSON expectedSnapshotNumber
v ^? key "contestationDeadline" . _JSON

Expand Down

0 comments on commit 2c97e77

Please sign in to comment.