From 2e7a59be746ff6632946e6a97bd08d98f1805594 Mon Sep 17 00:00:00 2001 From: Neil Rutledge Date: Fri, 3 Jun 2022 18:28:42 -0400 Subject: [PATCH 01/11] Switch to POST request for eval-ex-units --- server/README.md | 22 ++++++++++++++++------ server/dist/cabal-config-flags | Bin 0 -> 136 bytes server/src/Api.hs | 7 ++++--- server/src/Api/Handlers.hs | 8 +++++--- server/src/Types.hs | 18 ++++++++++++++++++ src/QueryM.purs | 4 ++-- 6 files changed, 45 insertions(+), 14 deletions(-) create mode 100644 server/dist/cabal-config-flags diff --git a/server/README.md b/server/README.md index a02b85e4d..60a3b9a37 100644 --- a/server/README.md +++ b/server/README.md @@ -14,7 +14,7 @@ We plan on supporting at least the following features: Run `nix develop .#hsDevShell` (or equivalently `nix develop .#package.x86_64-{linux|darwin}`; NB: not currently tested on macOS) in the repository root (i.e. up one level from `server`). This will place you in a development shell with `cabal`, `hoogle`, `haskell-language-server`, etc... -The server executable can be built with `nix build .#cardano-trasaction-lib-server:exe:cardano-trasaction-lib-server` and run with `./result/bin/cardano-trasaction-lib-server`. `cabal` can also be used once in the development shell. The server will run on port 8081. You can optionally pass the `--port`/`-p` flag to explicitly choose a port to run on +The server executable can be built with `nix build .#ctl-server:exe:ctl-server` and run with `./result/bin/ctl-server`. `cabal` can also be used once in the development shell. The server will run on port 8081. You can optionally pass the `--port`/`-p` flag to explicitly choose a port to run on --- @@ -51,14 +51,24 @@ The server executable can be built with `nix build .#cardano-trasaction-lib-serv "4d01000033222220051200120011" ``` -## GET /eval-ex-units +## POST /eval-ex-units -### GET Parameters: +### Request -- tx - - **Values**: *84a300818258205d677265fa5bb21ce6d8c7502aca70b9316d10e958611f3c6b758f65ad9599960001818258390030fb3b8539951e26f034910a5a37f22cb99d94d1d409f69ddbaea9711c12f03c1ef2e935acc35ec2e6f96c650fd3bfba3e96550504d5336100021a0002b569a0f5f6* - - **Description**: A CBOR-encoded `Tx AlonzoEra`; should be sent as a hexadecimal string +### Request: + +- Supported content types are: + - `application/json;charset=utf-8` + - `application/json` + +- The input should contain CBOR of tx (`application/json;charset=utf-8`, `application/json`): + +```javascript +{ + "tx": "84a300818258205d677265fa5bb21ce6d8c7502aca70b9316d10e958611f3c6b758f65ad9599960001818258390030fb3b8539951e26f034910a5a37f22cb99d94d1d409f69ddbaea9711c12f03c1ef2e935acc35ec2e6f96c650fd3bfba3e96550504d5336100021a0002b569a0f5f6" +} +``` ### Response: diff --git a/server/dist/cabal-config-flags b/server/dist/cabal-config-flags new file mode 100644 index 0000000000000000000000000000000000000000..04937fa22f092332fe4433c70c1d0bdc21ce4c5e GIT binary patch literal 136 zcmZ{d(G9~e2t>OOwK9N*ftbWdI7DDa8NV#hpL;s#oetn(Ckw9I2Y{AnYvQ#@%Lqr(@c7!i}^48x)c&?J&*jI;<^4{{b&HE};Mb literal 0 HcmV?d00001 diff --git a/server/src/Api.hs b/server/src/Api.hs index bdb4ee1e7..efe51fecb 100644 --- a/server/src/Api.hs +++ b/server/src/Api.hs @@ -41,6 +41,7 @@ import Types ( AppM (AppM), AppliedScript, ApplyArgsRequest, + EvalExUnitsRequest, CardanoError ( AcquireFailure, EraMismatchError, @@ -70,8 +71,8 @@ type Api = :> ReqBody '[JSON] ApplyArgsRequest :> Post '[JSON] AppliedScript :<|> "eval-ex-units" - :> QueryParam' '[Required] "tx" Cbor - :> Get '[JSON] ExecutionUnitsMap + :> ReqBody '[JSON] EvalExUnitsRequest + :> Post '[JSON] ExecutionUnitsMap :<|> "finalize" :> ReqBody '[JSON] FinalizeRequest :> Post '[JSON] FinalizedTransaction @@ -135,7 +136,7 @@ apiDocs = Docs.docs api estimateTxFees :: WitnessCount -> Cbor -> ClientM Fee applyArgs :: ApplyArgsRequest -> ClientM AppliedScript -evalTxExecutionUnits :: Cbor -> ClientM ExecutionUnitsMap +evalTxExecutionUnits :: EvalExUnitsRequest -> ClientM ExecutionUnitsMap finalizeTx :: FinalizeRequest -> ClientM FinalizedTransaction estimateTxFees :<|> applyArgs diff --git a/server/src/Api/Handlers.hs b/server/src/Api/Handlers.hs index 854f25062..4c471fa22 100644 --- a/server/src/Api/Handlers.hs +++ b/server/src/Api/Handlers.hs @@ -1,4 +1,5 @@ {-# LANGUAGE NamedFieldPuns #-} +{-# LANGUAGE DuplicateRecordFields #-} module Api.Handlers ( estimateTxFees, @@ -54,6 +55,7 @@ import Types ( CtlServerError (CardanoError, CborDecode), Env (protocolParams), ExecutionUnitsMap (ExecutionUnitsMap), + EvalExUnitsRequest (EvalExUnitsRequest, tx), Fee (Fee), FinalizeRequest (FinalizeRequest, datums, redeemers, tx), FinalizedTransaction (FinalizedTransaction), @@ -115,9 +117,9 @@ applyArgs ApplyArgsRequest {script, args} = {- | Computes the execution units needed for each script in the transaction. https://input-output-hk.github.io/cardano-node/cardano-api/src/Cardano.Api.Fees.html#evaluateTransactionExecutionUnits -} -evalTxExecutionUnits :: Cbor -> AppM ExecutionUnitsMap -evalTxExecutionUnits cbor = - case decodeCborTx cbor of +evalTxExecutionUnits :: EvalExUnitsRequest -> AppM ExecutionUnitsMap +evalTxExecutionUnits EvalExUnitsRequest {tx} = + case decodeCborTx tx of Left err -> throwM (CborDecode err) Right (C.Tx txBody@(C.TxBody txBodyContent) _) -> do diff --git a/server/src/Types.hs b/server/src/Types.hs index cf9602d7e..10e1fb8db 100644 --- a/server/src/Types.hs +++ b/server/src/Types.hs @@ -1,4 +1,5 @@ {-# LANGUAGE DerivingVia #-} +{-# LANGUAGE DuplicateRecordFields #-} module Types ( AppM (AppM), @@ -11,6 +12,7 @@ module Types ( WitnessCount (..), ApplyArgsRequest (..), AppliedScript (..), + EvalExUnitsRequest (..), FinalizeRequest (..), FinalizedTransaction (..), CardanoError (..), @@ -157,6 +159,12 @@ newtype AppliedScript = AppliedScript Ledger.Script deriving stock (Show, Generic) deriving newtype (Eq, FromJSON, ToJSON) +data EvalExUnitsRequest = EvalExUnitsRequest + { tx :: Cbor + } + deriving stock (Show, Generic, Eq) + deriving anyclass (FromJSON, ToJSON) + data FinalizeRequest = FinalizeRequest { tx :: Cbor , datums :: [Cbor] @@ -222,6 +230,14 @@ instance Docs.ToParam (QueryParam' '[Required] "count" WitnessCount) where \for the transaction" Docs.Normal +instance Docs.ToSample EvalExUnitsRequest where + toSamples _ = + [ + ( "The input should contain the CBOR of the tx" + , EvalExUnitsRequest (Cbor "00") + ) + ] + instance Docs.ToSample ExecutionUnitsMap where toSamples _ = [ @@ -262,6 +278,8 @@ instance Docs.ToSample AppliedScript where ) ] + + instance Docs.ToSample FinalizeRequest where toSamples _ = [ diff --git a/src/QueryM.purs b/src/QueryM.purs index 03bbfeccd..135cf68d9 100644 --- a/src/QueryM.purs +++ b/src/QueryM.purs @@ -442,8 +442,8 @@ evalTxExecutionUnits :: Transaction -> QueryM (Either ClientError (Array RdmrPtrExUnits)) evalTxExecutionUnits tx = do txHex <- liftEffect (txToHex tx) - url <- mkServerEndpointUrl ("eval-ex-units?tx=" <> txHex) - liftAff (Affjax.get Affjax.ResponseFormat.string url) + url <- mkServerEndpointUrl "eval-ex-units" + liftAff (postAeson url (encodeAeson { tx: txHex })) <#> either (Left <<< ClientHttpError) ( lmap ClientDecodeJsonError <<< (decodeAeson <=< parseJsonStringToAeson) From b95ab4a776746b7bc12a81996c6e70ab18f7c273 Mon Sep 17 00:00:00 2001 From: Neil Rutledge Date: Tue, 7 Jun 2022 03:03:34 -0400 Subject: [PATCH 02/11] Change fees endpoint from GET to POST --- server/README.md | 18 ++++++++++-------- server/src/Api.hs | 8 ++++---- server/src/Api/Handlers.hs | 12 +++++++----- server/src/Types.hs | 26 +++++++++++++++++--------- 4 files changed, 38 insertions(+), 26 deletions(-) diff --git a/server/README.md b/server/README.md index 60a3b9a37..a85eaa92c 100644 --- a/server/README.md +++ b/server/README.md @@ -86,18 +86,20 @@ The server executable can be built with `nix build .#ctl-server:exe:ctl-server` [{"exUnitsSteps":0,"rdmrPtrTag":0,"exUnitsMem":0,"rdmrPtrIdx":0}] ``` -## GET /fees +## POST /fees -### GET Parameters: +### Request: -- wit-count - - **Values**: *1* - - **Description**: A natural number representing the intended number of key witnessesfor the transaction +- Supported content types are: -- tx - - **Values**: *84a300818258205d677265fa5bb21ce6d8c7502aca70b9316d10e958611f3c6b758f65ad9599960001818258390030fb3b8539951e26f034910a5a37f22cb99d94d1d409f69ddbaea9711c12f03c1ef2e935acc35ec2e6f96c650fd3bfba3e96550504d5336100021a0002b569a0f5f6* - - **Description**: A CBOR-encoded `Tx AlonzoEra`; should be sent as a hexadecimal string + - `application/json;charset=utf-8` + - `application/json` +- The input should contain the intended witness count and CBOR of the tx (`application/json;charset=utf-8`, `application/json`): + +```javascript +{"count": 1, "tx":"00"} +``` ### Response: diff --git a/server/src/Api.hs b/server/src/Api.hs index efe51fecb..9a4cf8fa6 100644 --- a/server/src/Api.hs +++ b/server/src/Api.hs @@ -54,6 +54,7 @@ import Types ( Env, ExecutionUnitsMap, Fee, + FeesRequest, FinalizeRequest, FinalizedTransaction, WitnessCount, @@ -62,9 +63,8 @@ import Utils (lbshow) type Api = "fees" - :> QueryParam' '[Required] "count" WitnessCount - :> QueryParam' '[Required] "tx" Cbor - :> Get '[JSON] Fee + :> ReqBody '[JSON] FeesRequest + :> Post '[JSON] Fee -- Since @Script@ and @Data@ have @From/ToJSON@ instances, we can just -- accept them in the body of a POST request :<|> "apply-args" @@ -134,7 +134,7 @@ server = apiDocs :: Docs.API apiDocs = Docs.docs api -estimateTxFees :: WitnessCount -> Cbor -> ClientM Fee +estimateTxFees :: FeesRequest -> ClientM Fee applyArgs :: ApplyArgsRequest -> ClientM AppliedScript evalTxExecutionUnits :: EvalExUnitsRequest -> ClientM ExecutionUnitsMap finalizeTx :: FinalizeRequest -> ClientM FinalizedTransaction diff --git a/server/src/Api/Handlers.hs b/server/src/Api/Handlers.hs index 4c471fa22..3799e8e35 100644 --- a/server/src/Api/Handlers.hs +++ b/server/src/Api/Handlers.hs @@ -57,6 +57,7 @@ import Types ( ExecutionUnitsMap (ExecutionUnitsMap), EvalExUnitsRequest (EvalExUnitsRequest, tx), Fee (Fee), + FeesRequest (FeesRequest, count, tx), FinalizeRequest (FinalizeRequest, datums, redeemers, tx), FinalizedTransaction (FinalizedTransaction), RdmrPtrExUnits ( @@ -74,14 +75,15 @@ import Types ( -- Handlers -------------------------------------------------------------------------------- -estimateTxFees :: WitnessCount -> Cbor -> AppM Fee -estimateTxFees (WitnessCount numWits) cbor = do - decodeCborTx cbor & either (throwM . CborDecode) pure >>= \case +estimateTxFees :: FeesRequest -> AppM Fee +estimateTxFees FeesRequest { count, tx } = do + decodeCborTx tx & either (throwM . CborDecode) pure >>= \case C.Tx txBody' keyWits -> do pparams <- asks protocolParams -- calculate and set script integrity hash before estimating fees - let txBody = setScriptIntegrityHash pparams txBody' - fee = estimateFee pparams numWits (C.Tx txBody keyWits) + let WitnessCount witCount = count + txBody = setScriptIntegrityHash pparams txBody' + fee = estimateFee pparams witCount (C.Tx txBody keyWits) Fee <$> finalizeTxFee fee where -- `txfee` value must also be taken into account when calculating fees, diff --git a/server/src/Types.hs b/server/src/Types.hs index 10e1fb8db..f8ef86aea 100644 --- a/server/src/Types.hs +++ b/server/src/Types.hs @@ -10,6 +10,7 @@ module Types ( RdmrPtrExUnits (..), Fee (..), WitnessCount (..), + FeesRequest (..), ApplyArgsRequest (..), AppliedScript (..), EvalExUnitsRequest (..), @@ -126,13 +127,20 @@ data RdmrPtrExUnits = RdmrPtrExUnits deriving stock (Show, Generic) deriving anyclass (FromJSON, ToJSON) +data FeesRequest = FeesRequest + { count :: WitnessCount + , tx :: Cbor + } + deriving stock (Show, Eq, Generic) + deriving anyclass (FromJSON, ToJSON) + newtype Fee = Fee Integer deriving stock (Show, Generic) deriving newtype (Eq) newtype WitnessCount = WitnessCount Word deriving stock (Show, Generic) - deriving newtype (Eq, FromHttpApiData, ToHttpApiData) + deriving newtype (Eq, FromJSON, ToJSON) instance ToJSON Fee where -- to avoid issues with integer parsing in PS, we should probably return @@ -221,14 +229,14 @@ instance Docs.ToParam (QueryParam' '[Required] "tx" Cbor) where , "3e96550504d5336100021a0002b569a0f5f6" ] -instance Docs.ToParam (QueryParam' '[Required] "count" WitnessCount) where - toParam _ = - Docs.DocQueryParam - "wit-count" - ["1"] - "A natural number representing the intended number of key witnesses\ - \for the transaction" - Docs.Normal +instance Docs.ToSample FeesRequest where + toSamples _ = + [ + ( "The input should contain the intended number of witnesses and the\ + \CBOR of the tx" + , FeesRequest (WitnessCount 1) (Cbor "00") + ) + ] instance Docs.ToSample EvalExUnitsRequest where toSamples _ = From 0346e23d6018f97681bcfbc85fd29c8e995ab589 Mon Sep 17 00:00:00 2001 From: Neil Rutledge Date: Tue, 7 Jun 2022 03:13:31 -0400 Subject: [PATCH 03/11] Adjust QueryM logic to use post request for fees --- src/QueryM.purs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/QueryM.purs b/src/QueryM.purs index 135cf68d9..f7a160ae4 100644 --- a/src/QueryM.purs +++ b/src/QueryM.purs @@ -394,12 +394,8 @@ txToHex tx = calculateMinFee :: Transaction -> QueryM (Either ClientError Coin) calculateMinFee tx@(Transaction { body: Transaction.TxBody body }) = do txHex <- liftEffect (txToHex tx) - url <- mkServerEndpointUrl - $ "fees?tx=" - <> txHex - <> "&count=" - <> UInt.toString witCount - liftAff (Affjax.get Affjax.ResponseFormat.string url) + url <- mkServerEndpointUrl "fees" + liftAff (postAeson url (encodeAeson { count: witCount, tx: txHex })) <#> either (Left <<< ClientHttpError) ( bimap ClientDecodeJsonError (wrap <<< unwrap :: FeeEstimate -> Coin) From 307b06de6515a8215a21d00bd049836241419c92 Mon Sep 17 00:00:00 2001 From: Rory Tyler Hayford Date: Wed, 8 Jun 2022 13:30:02 +0700 Subject: [PATCH 04/11] Remove cabal-config-flags --- .gitignore | 1 + server/dist/cabal-config-flags | Bin 136 -> 0 bytes 2 files changed, 1 insertion(+) delete mode 100644 server/dist/cabal-config-flags diff --git a/.gitignore b/.gitignore index 287e34baf..77493652f 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,7 @@ result-* .node-cfg /server/dist-newstyle /server/dist-newstyle/ +/server/dist/ .projectile /dist/ output.js diff --git a/server/dist/cabal-config-flags b/server/dist/cabal-config-flags deleted file mode 100644 index 04937fa22f092332fe4433c70c1d0bdc21ce4c5e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 136 zcmZ{d(G9~e2t>OOwK9N*ftbWdI7DDa8NV#hpL;s#oetn(Ckw9I2Y{AnYvQ#@%Lqr(@c7!i}^48x)c&?J&*jI;<^4{{b&HE};Mb From ab3cdf37d2351df3e81876fe2887cf4ca2a1214b Mon Sep 17 00:00:00 2001 From: Rory Tyler Hayford Date: Wed, 8 Jun 2022 13:30:42 +0700 Subject: [PATCH 05/11] Formatting --- server/src/Api.hs | 2 +- server/src/Api/Handlers.hs | 6 +++--- server/src/Types.hs | 4 +--- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/server/src/Api.hs b/server/src/Api.hs index 9a4cf8fa6..405335b4c 100644 --- a/server/src/Api.hs +++ b/server/src/Api.hs @@ -41,7 +41,6 @@ import Types ( AppM (AppM), AppliedScript, ApplyArgsRequest, - EvalExUnitsRequest, CardanoError ( AcquireFailure, EraMismatchError, @@ -52,6 +51,7 @@ import Types ( CborDecodeError (InvalidCbor, InvalidHex, OtherDecodeError), CtlServerError (CardanoError, CborDecode), Env, + EvalExUnitsRequest, ExecutionUnitsMap, Fee, FeesRequest, diff --git a/server/src/Api/Handlers.hs b/server/src/Api/Handlers.hs index 3799e8e35..713a74934 100644 --- a/server/src/Api/Handlers.hs +++ b/server/src/Api/Handlers.hs @@ -1,5 +1,5 @@ -{-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE DuplicateRecordFields #-} +{-# LANGUAGE NamedFieldPuns #-} module Api.Handlers ( estimateTxFees, @@ -54,8 +54,8 @@ import Types ( CborDecodeError (InvalidCbor, InvalidHex, OtherDecodeError), CtlServerError (CardanoError, CborDecode), Env (protocolParams), - ExecutionUnitsMap (ExecutionUnitsMap), EvalExUnitsRequest (EvalExUnitsRequest, tx), + ExecutionUnitsMap (ExecutionUnitsMap), Fee (Fee), FeesRequest (FeesRequest, count, tx), FinalizeRequest (FinalizeRequest, datums, redeemers, tx), @@ -76,7 +76,7 @@ import Types ( -------------------------------------------------------------------------------- estimateTxFees :: FeesRequest -> AppM Fee -estimateTxFees FeesRequest { count, tx } = do +estimateTxFees FeesRequest {count, tx} = do decodeCborTx tx & either (throwM . CborDecode) pure >>= \case C.Tx txBody' keyWits -> do pparams <- asks protocolParams diff --git a/server/src/Types.hs b/server/src/Types.hs index f8ef86aea..2dca2ccf7 100644 --- a/server/src/Types.hs +++ b/server/src/Types.hs @@ -233,7 +233,7 @@ instance Docs.ToSample FeesRequest where toSamples _ = [ ( "The input should contain the intended number of witnesses and the\ - \CBOR of the tx" + \CBOR of the tx" , FeesRequest (WitnessCount 1) (Cbor "00") ) ] @@ -286,8 +286,6 @@ instance Docs.ToSample AppliedScript where ) ] - - instance Docs.ToSample FinalizeRequest where toSamples _ = [ From f3a20c5ce42e1e290cedb5e981ebab9fc8f52f70 Mon Sep 17 00:00:00 2001 From: Rory Tyler Hayford Date: Wed, 8 Jun 2022 13:31:28 +0700 Subject: [PATCH 06/11] Pragmas --- server/ctl-server.cabal | 2 ++ server/src/Api/Handlers.hs | 3 --- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/server/ctl-server.cabal b/server/ctl-server.cabal index 09c128c8f..9e21838ed 100644 --- a/server/ctl-server.cabal +++ b/server/ctl-server.cabal @@ -15,6 +15,7 @@ common common-language DeriveLift DeriveTraversable DerivingStrategies + DuplicateRecordFields ExplicitForAll FlexibleContexts FlexibleInstances @@ -23,6 +24,7 @@ common common-language LambdaCase MonoLocalBinds MultiParamTypeClasses + NamedFieldPuns NumericUnderscores OverloadedStrings QuasiQuotes diff --git a/server/src/Api/Handlers.hs b/server/src/Api/Handlers.hs index 713a74934..efdfb1d7b 100644 --- a/server/src/Api/Handlers.hs +++ b/server/src/Api/Handlers.hs @@ -1,6 +1,3 @@ -{-# LANGUAGE DuplicateRecordFields #-} -{-# LANGUAGE NamedFieldPuns #-} - module Api.Handlers ( estimateTxFees, applyArgs, From 4e6ec737af305c8db7883d076eaa8bfad2319a6f Mon Sep 17 00:00:00 2001 From: Rory Tyler Hayford Date: Wed, 8 Jun 2022 13:36:23 +0700 Subject: [PATCH 07/11] Redundant imports --- server/src/Api.hs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/server/src/Api.hs b/server/src/Api.hs index 405335b4c..19b7cd14c 100644 --- a/server/src/Api.hs +++ b/server/src/Api.hs @@ -19,14 +19,11 @@ import Data.Proxy (Proxy (Proxy)) import Network.Wai.Middleware.Cors qualified as Cors import Servant ( Application, - Get, Handler, HasServer (ServerT), JSON, Post, - QueryParam', ReqBody, - Required, Server, ServerError (errBody), err400, @@ -47,7 +44,6 @@ import Types ( ScriptExecutionError, TxValidityIntervalError ), - Cbor, CborDecodeError (InvalidCbor, InvalidHex, OtherDecodeError), CtlServerError (CardanoError, CborDecode), Env, @@ -57,7 +53,6 @@ import Types ( FeesRequest, FinalizeRequest, FinalizedTransaction, - WitnessCount, ) import Utils (lbshow) From a1e56cd44a99fedcbc0dee34c2815cf79003b7df Mon Sep 17 00:00:00 2001 From: Rory Tyler Hayford Date: Wed, 8 Jun 2022 13:40:44 +0700 Subject: [PATCH 08/11] Hlint --- server/src/Types.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/Types.hs b/server/src/Types.hs index 2dca2ccf7..157f207ea 100644 --- a/server/src/Types.hs +++ b/server/src/Types.hs @@ -167,7 +167,7 @@ newtype AppliedScript = AppliedScript Ledger.Script deriving stock (Show, Generic) deriving newtype (Eq, FromJSON, ToJSON) -data EvalExUnitsRequest = EvalExUnitsRequest +newtype EvalExUnitsRequest = EvalExUnitsRequest { tx :: Cbor } deriving stock (Show, Generic, Eq) From ffccd1f901c3bf3d7d946e795a5896e41b8a5b35 Mon Sep 17 00:00:00 2001 From: Rory Tyler Hayford Date: Wed, 8 Jun 2022 13:45:03 +0700 Subject: [PATCH 09/11] Fix tests --- server/test/Main.hs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/server/test/Main.hs b/server/test/Main.hs index 57c68a917..9fa02eeaa 100644 --- a/server/test/Main.hs +++ b/server/test/Main.hs @@ -40,8 +40,9 @@ import Cardano.Api.Shelley ( ), ) import Data.Bifunctor (second) -import Data.ByteString.Lazy qualified as ByteString +import Data.ByteString.Lazy qualified as LBS import Data.ByteString.Lazy.Char8 qualified as LC8 +import Data.Functor ((<&>)) import Data.Kind (Type) import Data.Map.Strict qualified as Map.Strict import Network.HTTP.Client (defaultManagerSettings, newManager) @@ -79,6 +80,7 @@ import Types ( Cbor (Cbor), Env (Env), Fee (Fee), + FeesRequest (FeesRequest), ServerOptions ( ServerOptions, networkId, @@ -130,21 +132,23 @@ feeEstimateSpec = around withTestApp $ do context "GET fees" $ do it "estimates the correct fee" $ \port -> do result <- - runClientM' (clientEnv port) $ - estimateTxFees (WitnessCount 1) cborTxFixture + runClientM' (clientEnv port) . estimateTxFees $ + FeesRequest (WitnessCount 1) cborTxFixture result `shouldBe` Right (Fee 168625) it "catches invalid hex strings" $ \port -> do result <- runClientM' (clientEnv port) - . estimateTxFees (WitnessCount 1) + . estimateTxFees + . FeesRequest (WitnessCount 1) $ Cbor "deadbeefq" result `shouldSatisfy` expectError 400 "invalid bytestring size" it "catches invalid CBOR-encoded transactions" $ \port -> do result <- runClientM' (clientEnv port) - . estimateTxFees (WitnessCount 1) + . estimateTxFees + . FeesRequest (WitnessCount 1) $ Cbor "deadbeef" result `shouldSatisfy` expectError @@ -284,7 +288,7 @@ fixedProtocolParameters :: ProtocolParameters fixedProtocolParameters = ProtocolParameters { protocolParamProtocolVersion = (6, 0) - , protocolParamDecentralization = 0 / 1 + , protocolParamDecentralization = 0 , protocolParamExtraPraosEntropy = Nothing , protocolParamMaxBlockHeaderSize = 1100 , protocolParamMaxBlockBodySize = 98304 @@ -327,8 +331,8 @@ fixedProtocolParameters = loadParametersFile :: IO (Either String ProtocolParameters) loadParametersFile = - ByteString.readFile "test/ogmios.json" - >>= pure . decodeProtocolParameters + LBS.readFile "test/ogmios.json" + <&> decodeProtocolParameters testParser :: Spec testParser = From acc4cd17ab691fee2b063bd50a07da6c10481ce4 Mon Sep 17 00:00:00 2001 From: Rory Tyler Hayford Date: Wed, 8 Jun 2022 13:48:21 +0700 Subject: [PATCH 10/11] Regenerate server readme --- server/README.md | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/server/README.md b/server/README.md index a85eaa92c..d61ed412c 100644 --- a/server/README.md +++ b/server/README.md @@ -53,8 +53,6 @@ The server executable can be built with `nix build .#ctl-server:exe:ctl-server` ## POST /eval-ex-units -### Request - ### Request: - Supported content types are: @@ -62,12 +60,10 @@ The server executable can be built with `nix build .#ctl-server:exe:ctl-server` - `application/json;charset=utf-8` - `application/json` -- The input should contain CBOR of tx (`application/json;charset=utf-8`, `application/json`): +- The input should contain the CBOR of the tx (`application/json;charset=utf-8`, `application/json`): ```javascript -{ - "tx": "84a300818258205d677265fa5bb21ce6d8c7502aca70b9316d10e958611f3c6b758f65ad9599960001818258390030fb3b8539951e26f034910a5a37f22cb99d94d1d409f69ddbaea9711c12f03c1ef2e935acc35ec2e6f96c650fd3bfba3e96550504d5336100021a0002b569a0f5f6" -} +{"tx":"00"} ``` ### Response: @@ -95,10 +91,10 @@ The server executable can be built with `nix build .#ctl-server:exe:ctl-server` - `application/json;charset=utf-8` - `application/json` -- The input should contain the intended witness count and CBOR of the tx (`application/json;charset=utf-8`, `application/json`): +- The input should contain the intended number of witnesses and theCBOR of the tx (`application/json;charset=utf-8`, `application/json`): ```javascript -{"count": 1, "tx":"00"} +{"tx":"00","count":1} ``` ### Response: From f3849c5eb3a1d8205ef53b0557cd1652e5c3acf5 Mon Sep 17 00:00:00 2001 From: Rory Tyler Hayford Date: Wed, 8 Jun 2022 14:46:25 +0700 Subject: [PATCH 11/11] Increase sleep time --- server/src/Ogmios/Query.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/Ogmios/Query.hs b/server/src/Ogmios/Query.hs index 3ca7afd1d..ca6fa8679 100644 --- a/server/src/Ogmios/Query.hs +++ b/server/src/Ogmios/Query.hs @@ -87,6 +87,6 @@ tryQueryUntilZero query remainAttempts putStrLn $ "Error : " <> show e putStrLn "Waiting for ogmios conection attempt" putStrLn $ "Attempts remain : " <> show (remainAttempts -1) - Time.Extra.sleep 0.5 + Time.Extra.sleep 3 hFlush stdout - tryQueryUntilZero query (remainAttempts - 1) + tryQueryUntilZero query $ remainAttempts - 1