22{-# LANGUAGE NumericUnderscores #-}
33{-# LANGUAGE OverloadedLists #-}
44{-# LANGUAGE ScopedTypeVariables #-}
5+ {-# LANGUAGE TypeApplications #-}
56{-# LANGUAGE TypeFamilies #-}
67
78module Test.Cardano.Api.Experimental
1213import Cardano.Api qualified as Api
1314import Cardano.Api.Experimental qualified as Exp
1415import Cardano.Api.Experimental.Era (convert )
16+ import Cardano.Api.Experimental.Tx qualified as Exp
1517import Cardano.Api.Genesis qualified as Genesis
1618import Cardano.Api.Ledger qualified as Ledger
1719import Cardano.Api.Plutus qualified as Script
@@ -73,7 +75,7 @@ prop_created_transaction_with_both_apis_are_the_same = H.propertyOnce $ do
7375 let sbe = Api. convert era
7476
7577 signedTxTraditional <- exampleTransactionTraditionalWay sbe
76- signedTxExperimental <- exampleTransactionExperimentalWay era sbe
78+ signedTxExperimental <- exampleTransactionExperimentalWay era
7779
7880 let oldStyleTx :: Api. Tx Api. ConwayEra = ShelleyTx sbe signedTxExperimental
7981
@@ -84,7 +86,7 @@ prop_created_transaction_with_both_apis_are_the_same = H.propertyOnce $ do
8486 => Api. ShelleyBasedEra Exp. ConwayEra
8587 -> m (Tx Exp. ConwayEra )
8688 exampleTransactionTraditionalWay sbe = do
87- txBodyContent <- exampleTxBodyContent Api. AsConwayEra sbe
89+ txBodyContent <- exampleTxBodyContent sbe
8890 signingKey <- exampleSigningKey
8991
9092 txBody <- H. evalEither $ Api. createTransactionBody sbe txBodyContent
@@ -96,10 +98,9 @@ prop_created_transaction_with_both_apis_are_the_same = H.propertyOnce $ do
9698 exampleTransactionExperimentalWay
9799 :: H. MonadTest m
98100 => Exp. Era Exp. ConwayEra
99- -> Api. ShelleyBasedEra Exp. ConwayEra
100101 -> m (Ledger. Tx (Exp. LedgerEra Exp. ConwayEra ))
101- exampleTransactionExperimentalWay era sbe = do
102- txBodyContent <- exampleTxBodyContent Api. AsConwayEra sbe
102+ exampleTransactionExperimentalWay era = do
103+ txBodyContent <- exampleTxBodyContentExperimental era
103104 signingKey <- exampleSigningKey
104105
105106 unsignedTx <- H. evalEither $ Exp. makeUnsignedTx era txBodyContent
@@ -119,7 +120,7 @@ prop_balance_transaction_two_ways = H.propertyOnce $ do
119120
120121 changeAddress <- getExampleChangeAddress sbe
121122
122- txBodyContent <- exampleTxBodyContent Api. AsConwayEra sbe
123+ txBodyContent <- exampleTxBodyContent sbe
123124 txBody <- H. evalEither $ Api. createTransactionBody sbe txBodyContent
124125
125126 -- Simple way (fee calculation)
@@ -244,13 +245,23 @@ getExampleSrcTxId = do
244245 return $ Api. TxIn srcTxId srcTxIx
245246
246247getExampleDestAddress
247- :: (H. MonadTest m , Api. IsCardanoEra era ) => Script. AsType era - > m (Api. AddressInEra era )
248- getExampleDestAddress eraAsType = do
248+ :: forall m era . (H. MonadTest m , Api. IsCardanoEra era ) => m (Api. AddressInEra era )
249+ getExampleDestAddress = do
249250 H. evalMaybe $
250251 Api. deserialiseAddress
251- (Api. AsAddressInEra eraAsType )
252+ (Api. AsAddressInEra ( Api. proxyToAsType ( Api. Proxy @ era )) )
252253 " addr_test1vzpfxhjyjdlgk5c0xt8xw26avqxs52rtf69993j4tajehpcue4v2v"
253254
255+ getExampleDestAddressExp
256+ :: H. MonadTest m => m Ledger. Addr
257+ getExampleDestAddressExp = do
258+ Api. toShelleyAddr
259+ <$> H. evalMaybe
260+ ( Api. deserialiseAddress
261+ (Api. AsAddressInEra (Api. proxyToAsType (Api. Proxy @ Api. ConwayEra )))
262+ " addr_test1vzpfxhjyjdlgk5c0xt8xw26avqxs52rtf69993j4tajehpcue4v2v"
263+ )
264+
254265getExampleChangeAddress :: H. MonadTest m => Api. ShelleyBasedEra era -> m (Api. AddressInEra era )
255266getExampleChangeAddress sbe = do
256267 signingKey <- exampleSigningKey
@@ -261,14 +272,40 @@ getExampleChangeAddress sbe = do
261272 (Api. PaymentCredentialByKey $ Api. verificationKeyHash $ Api. getVerificationKey signingKey)
262273 Api. NoStakeAddress
263274
275+ exampleTxBodyContentExperimental
276+ :: forall m era
277+ . H. MonadTest m
278+ => Exp. Era era
279+ -> m (Exp. TxBodyContent (Exp. LedgerEra era ))
280+ exampleTxBodyContentExperimental era = do
281+ srcTxIn <- getExampleSrcTxId
282+ addr <- getExampleDestAddressExp
283+ let value = Ledger. valueFromList 10_000_000 []
284+ out :: Ledger. TxOut (Exp. LedgerEra era )
285+ out = Exp. obtainCommonConstraints era $ Ledger. mkBasicTxOut addr value
286+ let txBodyContent =
287+ Exp. defaultTxBodyContent
288+ & Exp. setTxIns
289+ [
290+ ( srcTxIn
291+ , Exp. AnyKeyWitnessPlaceholder
292+ )
293+ ]
294+ & Exp. setTxOuts
295+ [ Exp. obtainCommonConstraints era $ Exp. TxOut out Nothing
296+ ]
297+ & Exp. setTxFee 2_000_000
298+ return txBodyContent
299+
264300exampleTxBodyContent
265- :: (Api. ShelleyBasedEraConstraints era , H. MonadTest m )
266- => Api. AsType era
267- -> Api. ShelleyBasedEra era
301+ :: forall m era
302+ . H. MonadTest m
303+ => Api. IsCardanoEra era
304+ => Api. ShelleyBasedEra era
268305 -> m (Api. TxBodyContent Api. BuildTx era )
269- exampleTxBodyContent eraAsType sbe = do
306+ exampleTxBodyContent sbe = do
270307 srcTxIn <- getExampleSrcTxId
271- destAddress <- getExampleDestAddress eraAsType
308+ destAddress <- getExampleDestAddress @ _ @ era
272309 let txBodyContent =
273310 Api. defaultTxBodyContent sbe
274311 & Api. setTxIns
0 commit comments