-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Extra library for tests * Add wst-poc-mock-server executable
- Loading branch information
Showing
11 changed files
with
183 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module Main where | ||
|
||
import Wst.Test.MockServer (runMockServer) | ||
|
||
main :: IO () | ||
main = runMockServer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{-| Generators for testing the POC | ||
-} | ||
module Wst.Test.Gen( | ||
genGlobalParams, | ||
genUTxODat, | ||
|
||
-- * Plutus types | ||
-- TODO: move to sc-tools? | ||
genCurrencySymbol, | ||
genCredential | ||
) where | ||
|
||
import Cardano.Api qualified as C | ||
import Convex.PlutusLedger.V1 qualified as PL | ||
import PlutusLedgerApi.V1.Credential (Credential) | ||
import PlutusLedgerApi.V1.Value (CurrencySymbol) | ||
import SmartTokens.Types.ProtocolParams (ProgrammableLogicGlobalParams (..)) | ||
import Test.Gen.Cardano.Api.Typed qualified as Gen | ||
import Test.QuickCheck.Gen (Gen) | ||
import Test.QuickCheck.Hedgehog (hedgehog) | ||
import Wst.Offchain.Query (UTxODat (..)) | ||
|
||
genGlobalParams :: Gen ProgrammableLogicGlobalParams | ||
genGlobalParams = | ||
ProgrammableLogicGlobalParams | ||
<$> genCurrencySymbol | ||
<*> genCredential | ||
|
||
genCurrencySymbol :: Gen CurrencySymbol | ||
genCurrencySymbol = PL.transPolicyId <$> hedgehog Gen.genPolicyId | ||
|
||
genCredential :: Gen Credential | ||
genCredential = PL.transCredential <$> hedgehog Gen.genPaymentCredential | ||
|
||
genUTxODat :: C.IsShelleyBasedEra era => Gen a -> Gen (UTxODat era a) | ||
genUTxODat a = | ||
UTxODat | ||
<$> hedgehog Gen.genTxIn | ||
<*> hedgehog (Gen.genTxOutUTxOContext C.shelleyBasedEra) | ||
<*> a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{-| Mock implementation of server API for testing / UI development | ||
-} | ||
module Wst.Test.MockServer( | ||
mockServer, | ||
runMockServer | ||
) where | ||
|
||
import Cardano.Api qualified as C | ||
import Control.Monad.IO.Class (MonadIO (..)) | ||
import Data.Proxy (Proxy (..)) | ||
import Network.Wai.Handler.Warp qualified as Warp | ||
import Servant (Server) | ||
import Servant.API (NoContent (..), (:<|>) (..)) | ||
import Servant.Server (serve) | ||
import Test.Gen.Cardano.Api.Typed qualified as Gen | ||
import Test.QuickCheck qualified as QC | ||
import Test.QuickCheck.Gen qualified as Gen | ||
import Test.QuickCheck.Hedgehog (hedgehog) | ||
import Wst.Server.Types (APIInEra, BuildTxAPI, QueryAPI, TextEnvelopeJSON (..)) | ||
import Wst.Test.Gen qualified as Gen | ||
|
||
mockServer :: Server APIInEra | ||
mockServer = | ||
pure NoContent | ||
:<|> mockQueryApi | ||
:<|> mockTxApi | ||
|
||
mockQueryApi :: Server (QueryAPI C.ConwayEra) | ||
mockQueryApi = | ||
liftIO (QC.generate $ Gen.genUTxODat Gen.genGlobalParams) | ||
:<|> (\_ -> liftIO $ QC.generate $ Gen.listOf (hedgehog $ Gen.genVerificationKeyHash (C.proxyToAsType Proxy))) | ||
:<|> (\_ -> liftIO $ fmap (C.fromLedgerValue C.ShelleyBasedEraConway) $ QC.generate $ hedgehog $ Gen.genValue C.MaryEraOnwardsConway Gen.genAssetId Gen.genPositiveQuantity) | ||
:<|> liftIO (fmap (C.fromLedgerValue C.ShelleyBasedEraConway) $ QC.generate $ hedgehog $ Gen.genValue C.MaryEraOnwardsConway Gen.genAssetId Gen.genPositiveQuantity) | ||
|
||
genTx :: MonadIO m => m (TextEnvelopeJSON (C.Tx C.ConwayEra)) | ||
genTx = liftIO $ fmap TextEnvelopeJSON $ QC.generate $ hedgehog $ Gen.genTx C.shelleyBasedEra | ||
|
||
mockTxApi :: Server (BuildTxAPI C.ConwayEra) | ||
mockTxApi = | ||
const genTx | ||
:<|> const genTx | ||
:<|> const genTx | ||
:<|> const genTx | ||
|
||
-- | Start the mock server | ||
runMockServer :: IO () | ||
runMockServer = do | ||
let app = serve (Proxy @APIInEra) mockServer | ||
port = 8080 | ||
putStrLn $ "Starting mock server on port " <> show port | ||
Warp.run port app |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters