-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Offline mode implementation #1118
Changes from all commits
98dbb39
6424b29
299bfb2
54ab84a
5e7595d
8d8ae6e
2227368
96e7beb
e55a1cf
50ce846
fa1308b
615b95c
97f64c2
67e8139
842f2b9
6414da2
e322bb9
681202a
5adfe59
ecb26de
dcfc0bf
f641a98
a7ad53a
1228373
f81761a
c730f27
2c2f4f9
65b2357
510d4ef
7f283ae
e2438b3
b4d21c4
a892dd3
266fc0a
b860d64
f0a8489
6880688
3500d51
a10c492
e373bce
bd68a8e
0306ce8
6a54f77
bea0b76
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ import Hydra.Cardano.Api ( | |
mkVkAddress, | ||
serialiseAddress, | ||
signTx, | ||
pattern TxOut, | ||
pattern TxValidityLowerBound, | ||
) | ||
import Hydra.Chain.Direct.State () | ||
|
@@ -74,7 +75,7 @@ import Hydra.Cluster.Util (chainConfigFor, keysFor) | |
import Hydra.ContestationPeriod (ContestationPeriod (UnsafeContestationPeriod)) | ||
import Hydra.Crypto (generateSigningKey) | ||
import Hydra.Ledger (txId) | ||
import Hydra.Ledger.Cardano (genKeyPair, mkRangedTx, mkSimpleTx) | ||
import Hydra.Ledger.Cardano (genKeyPair, genUTxOFor, mkRangedTx, mkSimpleTx) | ||
import Hydra.Logging (Tracer, showLogsOnFailure) | ||
import Hydra.Options | ||
import Hydra.Party (deriveParty) | ||
|
@@ -92,6 +93,7 @@ import HydraNode ( | |
withHydraCluster, | ||
withHydraNode, | ||
withHydraNode', | ||
withOfflineHydraNode, | ||
) | ||
import System.Directory (removeDirectoryRecursive) | ||
import System.FilePath ((</>)) | ||
|
@@ -112,7 +114,37 @@ withClusterTempDir name = | |
withTempDir ("hydra-cluster-e2e-" <> name) | ||
|
||
spec :: Spec | ||
spec = around (showLogsOnFailure "EndToEndSpec") $ | ||
spec = around (showLogsOnFailure "EndToEndSpec") $ do | ||
it "End-to-end offline mode" $ \tracer -> do | ||
withTempDir ("offline-mode-e2e") $ \tmpDir -> do | ||
let networkId = Testnet (NetworkMagic 42) -- from defaultChainConfig | ||
(aliceCardanoVk, aliceCardanoSk) <- keysFor Alice | ||
(bobCardanoVk, _) <- keysFor Bob | ||
initialUtxo <- generate $ do | ||
a <- genUTxOFor aliceCardanoVk | ||
b <- genUTxOFor bobCardanoVk | ||
pure $ a <> b | ||
Aeson.encodeFile (tmpDir </> "utxo.json") initialUtxo | ||
let offlineConfig = | ||
OfflineConfig | ||
{ initialUTxOFile = tmpDir </> "utxo.json" | ||
, ledgerGenesisFile = Nothing | ||
} | ||
|
||
let Just (aliceSeedTxIn, aliceSeedTxOut) = UTxO.find (\(TxOut addr _ _ _) -> addr == mkVkAddress networkId aliceCardanoVk) initialUtxo | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could: use scenario values instead of loading/inferring them again here. For example given my comment above, this could be simplified by just keeping |
||
|
||
withOfflineHydraNode (contramap FromHydraNode tracer) offlineConfig tmpDir 0 aliceSk $ \node -> do | ||
let Right tx = | ||
mkSimpleTx | ||
(aliceSeedTxIn, aliceSeedTxOut) | ||
(mkVkAddress networkId bobCardanoVk, lovelaceToValue paymentFromAliceToBob) | ||
aliceCardanoSk | ||
|
||
send node $ input "NewTx" ["transaction" .= tx] | ||
|
||
waitMatch 10 node $ \v -> do | ||
guard $ v ^? key "tag" == Just "SnapshotConfirmed" | ||
|
||
describe "End-to-end on Cardano devnet" $ do | ||
describe "single party hydra head" $ do | ||
it "full head life-cycle" $ \tracer -> do | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need this separation as
withOfflineHydraNode'
is used in only one place. And even the other 2 functions are clunky and should be refactored.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll cover this in a refactor PR.