Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expand offline mode e2e test to ensure it persists
Browse files Browse the repository at this point in the history
This was not entirely clear from the previous test and ensures we do not
break anything when simplifying the implementation.
ch1bo committed Dec 20, 2023
1 parent cd03a66 commit e680ad0
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions hydra-cluster/test/Test/EndToEndSpec.hs
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@ import Data.Aeson (Result (..), Value (Null, Object, String), fromJSON, object,
import Data.Aeson qualified as Aeson
import Data.Aeson.Lens (key, values, _JSON)
import Data.ByteString qualified as BS
import Data.List ((!!))
import Data.Map qualified as Map
import Data.Set qualified as Set
import Data.Time (secondsToDiffTime)
@@ -26,15 +27,18 @@ import Hydra.Cardano.Api (
NetworkMagic (NetworkMagic),
PaymentKey,
SlotNo (..),
ToUTxOContext (toUTxOContext),
TxId,
TxIn (..),
VerificationKey,
isVkTxOut,
lovelaceToValue,
mkTxIn,
mkVkAddress,
serialiseAddress,
signTx,
txOutValue,
txOuts',
pattern TxValidityLowerBound,
)
import Hydra.Chain.Direct.Fixture (testNetworkId)
@@ -128,14 +132,30 @@ spec = around (showLogsOnFailure "EndToEndSpec") $ do
{ initialUTxOFile = tmpDir </> "utxo.json"
, ledgerGenesisFile = Nothing
}
withHydraNode (contramap FromHydraNode tracer) offlineConfig tmpDir 0 aliceSk [] [1] $ \node -> do

-- Start a hydra-node in offline mode and submit a transaction from alice to bob
aliceToBob <- withHydraNode (contramap FromHydraNode tracer) offlineConfig tmpDir 0 aliceSk [] [1] $ \node -> do
let Just (aliceSeedTxIn, aliceSeedTxOut) = UTxO.find (isVkTxOut aliceCardanoVk) initialUTxO
let Right tx =
let Right aliceToBob =
mkSimpleTx
(aliceSeedTxIn, aliceSeedTxOut)
(mkVkAddress testNetworkId bobCardanoVk, txOutValue aliceSeedTxOut)
aliceCardanoSk
send node $ input "NewTx" ["transaction" .= tx]
send node $ input "NewTx" ["transaction" .= aliceToBob]
waitMatch 10 node $ \v -> do
guard $ v ^? key "tag" == Just "SnapshotConfirmed"
pure aliceToBob

-- Restart a hydra-node in offline mode expect we can reverse the transaction (it retains state)
withHydraNode (contramap FromHydraNode tracer) offlineConfig tmpDir 0 aliceSk [] [1] $ \node -> do
let
bobTxOut = toUTxOContext $ txOuts' aliceToBob !! 0
Right bobToAlice =
mkSimpleTx
(mkTxIn aliceToBob 0, bobTxOut)
(mkVkAddress testNetworkId bobCardanoVk, txOutValue bobTxOut)
aliceCardanoSk
send node $ input "NewTx" ["transaction" .= bobToAlice]
waitMatch 10 node $ \v -> do
guard $ v ^? key "tag" == Just "SnapshotConfirmed"

0 comments on commit e680ad0

Please sign in to comment.