Skip to content

Commit

Permalink
Reimplement seahorses minting via local-cluster client
Browse files Browse the repository at this point in the history
  • Loading branch information
paolino committed Apr 18, 2024
1 parent 49dd8e5 commit 1119ada
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 29 deletions.
Expand Up @@ -233,7 +233,7 @@ withLocalCluster
-- ^ Configuration for the cluster.
-> FaucetFunds
-- ^ Initial faucet funds.
-> (RunningNode -> IO a)
-> (RunQuery IO -> RunningNode -> IO a)
-- ^ Action to run once when all pools have started.
-> IO a
withLocalCluster
Expand All @@ -248,7 +248,7 @@ withLocalCluster
clusterControl = Nothing
nodeToClientSocket = cfgNodeToClientSocket
evalContT $ do
(monitoring, RunQuery queryMonitor) <-
(monitoring, rq@(RunQuery queryMonitor)) <-
withHttpMonitoring $ MsgHttpMonitoring >$< cfgTracer
faucetFundsFile <- withFaucetFunds faucetFunds
socketPath <- withSocketPath nodeToClientSocket
Expand All @@ -259,7 +259,7 @@ withLocalCluster
liftIO $ withLocalClusterReady queryMonitor
genesisData <- withGenesisData shelleyGenesis
lift
$ action
$ action rq
$ RunningNode
{ runningNodeSocketPath = socketPath
, runningNodeShelleyGenesis = genesisData
Expand Down
58 changes: 32 additions & 26 deletions lib/integration/framework/Test/Integration/Framework/Setup.hs
Expand Up @@ -18,6 +18,7 @@ import Prelude

import Cardano.Address
( NetworkTag (..)
, unAddress
)
import Cardano.Address.Style.Shelley
( shelleyTestnet
Expand All @@ -37,9 +38,6 @@ import Cardano.CLI
import Cardano.Launcher
( ProcessHasExited (..)
)
import Cardano.Launcher.Node
( CardanoNodeConn
)
import Cardano.Ledger.Shelley.Genesis
( sgNetworkMagic
)
Expand All @@ -65,8 +63,6 @@ import Cardano.Wallet.Launch.Cluster
, LogFileConfig (..)
, RunningNode (..)
, clusterEraFromEnv
, runClusterM
, sendFaucetAssetsTo
, withFaucet
, withSMASH
)
Expand All @@ -77,6 +73,10 @@ import Cardano.Wallet.Launch.Cluster.FileOf
( AbsDirOf
, absolutize
)
import Cardano.Wallet.Launch.Cluster.Monitoring.Http.Client
( Query (SendFaucetAssetsQ)
, RunQuery (..)
)
import Cardano.Wallet.Network.Implementation.Ouroboros
( tunedForMainnetPipeliningStrategy
)
Expand All @@ -99,6 +99,9 @@ import Cardano.Wallet.Primitive.SyncProgress
import Cardano.Wallet.Primitive.Types
( NetworkParameters
)
import Cardano.Wallet.Primitive.Types.Address
( Address (Address)
)
import Cardano.Wallet.Primitive.Types.Coin
( Coin (..)
)
Expand Down Expand Up @@ -131,6 +134,9 @@ import Control.Tracer
import Data.Either.Combinators
( whenLeft
)
import Data.Functor
( (<&>)
)
import Data.IORef
( IORef
, atomicModifyIORef'
Expand Down Expand Up @@ -164,6 +170,9 @@ import Path
, relfile
, (</>)
)
import Path.IO
( withSystemTempFile
)
import Servant.Client
( ClientEnv
)
Expand Down Expand Up @@ -229,9 +238,6 @@ import qualified Cardano.Wallet.Api.Link as Link
import qualified Cardano.Wallet.Faucet as Faucet
import qualified Cardano.Wallet.Launch.Cluster as Cluster
import qualified Data.Text as T
import Path.IO
( withSystemTempFile
)

-- | Do all the program setup required for integration tests, create a temporary
-- directory, and pass this info to the main hspec action.
Expand Down Expand Up @@ -346,7 +352,7 @@ withServer
-> FaucetFunds
-> Pool.DBDecorator IO
-> ( T.Text
-> CardanoNodeConn
-> RunQuery IO
-> NetworkParameters
-> URI
-> IO ()
Expand All @@ -364,14 +370,15 @@ withServer
withSMASH tr' (fromAbsDir testDir) $ \smashUrl -> do
traceWith tr $ MsgInfo "Starting local cluster ..."
withLocalCluster clusterConfig faucetFunds
$ onClusterStart
ctx
(onReady (T.pack smashUrl))
dbDecorator
$ \rq ->
onClusterStart
ctx
(onReady (T.pack smashUrl) rq)
dbDecorator

onClusterStart
:: TestingCtx
-> (CardanoNodeConn -> NetworkParameters -> URI -> IO ())
-> (NetworkParameters -> URI -> IO ())
-> Pool.DBDecorator IO
-> RunningNode
-> IO ExitCode
Expand Down Expand Up @@ -411,7 +418,7 @@ onClusterStart
block0
$ \uri -> do
traceWith tr $ MsgInfo "Wallet ready"
callback nodeConnection networkParameters uri
callback networkParameters uri

-- threadDelay $ 3 * 60 * 1_000_000 -- Wait 3 minutes for the node to start
-- exitSuccess
Expand All @@ -433,26 +440,25 @@ httpManager = do

setupContext
:: TestingCtx
-> Cluster.Config
-> MVar Context
-> ClientEnv
-- ^ Faucet client environment
-> IORef [PoolGarbageCollectionEvent]
-> T.Text
-> CardanoNodeConn
-> RunQuery IO
-> NetworkParameters
-> URI
-> IO ()
setupContext
TestingCtx{..}
clusterConfig
ctx
faucetClientEnv
poolGarbageCollectionEvents
smashUrl
nodeConnection
(RunQuery query)
networkParameters
baseUrl =
baseUrl
=
bracketTracer' tr "setupContext" $ do
faucet <- Faucet.initFaucet faucetClientEnv
prometheusUrl <-
Expand Down Expand Up @@ -482,11 +488,12 @@ setupContext
, _smashUrl = smashUrl
, _mintSeaHorseAssets = \nPerAddr batchSize c addrs ->
withMVar mintSeaHorseAssetsLock $ \() ->
runClusterM clusterConfig
$ sendFaucetAssetsTo
nodeConnection
batchSize
(Faucet.seaHorseTestAssets nPerAddr c addrs)
query
$ SendFaucetAssetsQ batchSize
$ (Faucet.seaHorseTestAssets nPerAddr c addrs)
<&> ( \(addr, (bundle, metadata)) ->
(Address $ unAddress addr, (bundle, metadata))
)
}

withContext :: TestingCtx -> (Context -> IO ()) -> IO ()
Expand Down Expand Up @@ -531,7 +538,6 @@ withContext testingCtx@TestingCtx{..} action = do
dbEventRecorder
$ setupContext
testingCtx
clusterConfig
ctx
faucetClientEnv
poolGarbageCollectionEvents
Expand Down

0 comments on commit 1119ada

Please sign in to comment.