@@ -4,6 +4,7 @@ import BotPlutusInterface.Server (app, initState)
44import BotPlutusInterface.Types (
55 HasDefinitions (.. ),
66 PABConfig (.. ),
7+ RawTx (.. ),
78 SomeBuiltin (.. ),
89 )
910
@@ -20,7 +21,8 @@ import Servant.API (Capture, Get, JSON, (:>))
2021import Servant.Client (ClientEnv , ClientError (.. ), client , mkClientEnv , responseStatusCode , runClientM )
2122import Servant.Client.Core.BaseUrl (BaseUrl (.. ), parseBaseUrl )
2223
23- import Data.Aeson (FromJSON , ToJSON )
24+ import Data.Aeson (FromJSON , ToJSON , encode )
25+ import Data.ByteString.Lazy qualified as LBS
2426import Data.Default (def )
2527import Data.Proxy (Proxy (.. ))
2628import Data.Text (Text , pack , unpack )
@@ -29,13 +31,13 @@ import System.FilePath ((</>))
2931import System.IO.Temp (withSystemTempDirectory )
3032import Prelude
3133
32- type RawTxEndpointResponse = Either ClientError Text
34+ type RawTxEndpointResponse = Either ClientError RawTx
3335type RawTxTest a = (Text -> IO RawTxEndpointResponse ) -> IO a
3436
3537tests :: TestTree
3638tests =
3739 testGroup
38- " Server"
40+ " BotPlutusInterface. Server"
3941 [ rawTxTests
4042 ]
4143
@@ -53,13 +55,13 @@ rawTxTests =
5355 fetchTx = do
5456 initServerAndClient enableTxEndpointConfig $ \ runRawTxClient -> do
5557 result <- runRawTxClient txHash
56- result @?= Right (pack txFileContents)
58+ result @?= Right rawTx
5759
5860 fetchSignedTx :: IO ()
5961 fetchSignedTx = do
6062 initServerAndClient enableTxEndpointConfig $ \ runRawTxClient -> do
6163 result <- runRawTxClient $ txHash <> " .signed"
62- result @?= Right (pack txFileContents)
64+ result @?= Right rawTx
6365
6466 fetchOutsideTxFolder :: IO ()
6567 fetchOutsideTxFolder = do
@@ -79,7 +81,7 @@ txProxy ::
7981 Proxy
8082 ( " rawTx"
8183 :> Capture " hash" Text
82- :> Get '[JSON ] Text
84+ :> Get '[JSON ] RawTx
8385 )
8486txProxy = Proxy
8587
@@ -89,7 +91,7 @@ initServerAndClient config test = do
8991 let pabConfig :: PABConfig
9092 pabConfig = config {pcTxFileDir = pack path}
9193 state <- initState
92- writeFile (path </> txFileName) txFileContents
94+ LBS. writeFile (path </> txFileName) txFileContents
9395 testWithApplication (pure $ app @ EmptyContract pabConfig state) (initClientOnPort test)
9496 where
9597 initClientOnPort :: RawTxTest a -> Int -> IO a
@@ -106,13 +108,21 @@ initServerAndClient config test = do
106108 testToRun runRawTxClient
107109
108110txHash :: Text
109- txHash = " aaaa "
111+ txHash = " test "
110112
111113txFileName :: FilePath
112114txFileName = " tx-" <> unpack txHash <> " .raw"
113115
114- txFileContents :: String
115- txFileContents = " test"
116+ rawTx :: RawTx
117+ rawTx =
118+ RawTx
119+ { rawType = " TxBodyAlonzo"
120+ , rawDescription = " description"
121+ , rawCborHex = " hex"
122+ }
123+
124+ txFileContents :: LBS. ByteString
125+ txFileContents = encode rawTx
116126
117127enableTxEndpointConfig :: PABConfig
118128enableTxEndpointConfig = def {pcEnableTxEndpoint = True }
0 commit comments