@@ -108,7 +108,7 @@ sendAda = do
108108 Constraints. mustPayToPubKey paymentPkh2 (Ada. lovelaceValueOf 1000 )
109109 submitTx constraints
110110
111- assertContractWithTxId contract initState $ \ state _ ->
111+ assertContract contract initState $ \ state ->
112112 assertCommandHistory
113113 state
114114 [
@@ -189,7 +189,7 @@ sendAdaNoChange = do
189189 Constraints. mustPayToPubKey paymentPkh2 (Ada. lovelaceValueOf 1000 )
190190 submitTx constraints
191191
192- assertContractWithTxId contract initState $ \ state _ ->
192+ assertContract contract initState $ \ state ->
193193 assertCommandHistory
194194 state
195195 [
@@ -222,7 +222,7 @@ sendAdaStaking = do
222222 Constraints. mustPayToPubKeyAddress paymentPkh2 stakePkh3 (Ada. lovelaceValueOf 1000 )
223223 submitTx constraints
224224
225- assertContractWithTxId contract initState $ \ state _ ->
225+ assertContract contract initState $ \ state ->
226226 assertCommandHistory
227227 state
228228 [
@@ -303,7 +303,7 @@ multisigSupport = do
303303 submitTx constraints
304304
305305 -- Building and siging the tx should include both signing keys
306- assertContractWithTxId contract initState $ \ state _ ->
306+ assertContract contract initState $ \ state ->
307307 assertCommandHistory
308308 state
309309 [
@@ -366,7 +366,7 @@ withoutSigning = do
366366 submitTx constraints
367367
368368 -- Building and siging the tx should include both signing keys
369- assertContractWithTxId contract initState $ \ state _ -> do
369+ assertContract contract initState $ \ state -> do
370370 assertCommandHistory
371371 state
372372 [
@@ -411,7 +411,7 @@ sendTokens = do
411411 (Ada. lovelaceValueOf 1000 <> Value. singleton " abcd1234" " testToken" 5 )
412412 submitTx constraints
413413
414- assertContractWithTxId contract initState $ \ state _ ->
414+ assertContract contract initState $ \ state ->
415415 assertCommandHistory
416416 state
417417 [
@@ -455,7 +455,7 @@ sendTokensWithoutName = do
455455 (Ada. lovelaceValueOf 1000 <> Value. singleton " abcd1234" " " 5 )
456456 submitTx constraints
457457
458- assertContractWithTxId contract initState $ \ state _ ->
458+ assertContract contract initState $ \ state ->
459459 assertCommandHistory
460460 state
461461 [
@@ -506,7 +506,7 @@ mintTokens = do
506506 (Ada. lovelaceValueOf 1000 <> Value. singleton curSymbol " testToken" 5 )
507507 submitTxConstraintsWith @ Void lookups constraints
508508
509- assertContractWithTxId contract initState $ \ state _ -> do
509+ assertContract contract initState $ \ state -> do
510510 assertCommandHistory
511511 state
512512 [
@@ -600,7 +600,7 @@ spendToValidator = do
600600 Constraints. mustPayToOtherScript valHash datum (Ada. lovelaceValueOf 500 )
601601 submitTxConstraintsWith @ Void lookups constraints
602602
603- assertContractWithTxId contract initState $ \ state _ -> do
603+ assertContract contract initState $ \ state -> do
604604 assertCommandHistory
605605 state
606606 [
@@ -691,7 +691,7 @@ redeemFromValidator = do
691691 <> Constraints. mustPayToPubKey paymentPkh2 (Ada. lovelaceValueOf 500 )
692692 submitTxConstraintsWith @ Void lookups constraints
693693
694- assertContractWithTxId contract initState $ \ state _ -> do
694+ assertContract contract initState $ \ state -> do
695695 assertCommandHistory
696696 state
697697 [
@@ -782,7 +782,7 @@ withValidRange = do
782782 <> Constraints. mustValidateIn (interval (POSIXTime 1643636293000 ) (POSIXTime 1646314693000 ))
783783 submitTx constraints
784784
785- assertContractWithTxId contract initState $ \ state _ ->
785+ assertContract contract initState $ \ state ->
786786 assertCommandHistory
787787 state
788788 [
@@ -820,20 +820,17 @@ useWriter = do
820820 let txOutRef = TxOutRef " e406b0cf676fc2b1a9edb0617f259ad025c20ea6f0333820aa7cef1bfe7302e5" 0
821821 txOut = TxOut pkhAddr1 (Ada. lovelaceValueOf 1200 ) Nothing
822822 initState = def & utxos .~ [(txOutRef, txOut)]
823- test = " test"
824823
825824 contract :: Contract (Last Text ) (Endpoint " SendAda" () ) Text CardanoTx
826825 contract = do
827826 tell $ Last $ Just " Init contract"
828827 let constraints =
829828 Constraints. mustPayToPubKey paymentPkh2 (Ada. lovelaceValueOf 1000 )
830- txId <- submitTx constraints
831- tell $ Last $ Just test
832- pure txId
829+ submitTx constraints
833830
834- assertContractWithTxId contract initState $ \ state _ -> do
831+ assertContract contract initState $ \ state -> do
835832 (state ^. observableState)
836- @?= Last (Just test )
833+ @?= Last (Just " Init contract " )
837834
838835waitNextBlock :: Assertion
839836waitNextBlock = do
@@ -888,6 +885,20 @@ assertContractWithTxId contract initState assertion = do
888885 let outTxId = encodeByteString $ fromBuiltin $ TxId. getTxId $ Tx. getCardanoTxId tx
889886 in assertion state outTxId
890887
888+ assertContract ::
889+ forall (w :: Type ) (s :: Row Type ).
890+ (ToJSON w , Monoid w ) =>
891+ Contract w s Text CardanoTx ->
892+ MockContractState w ->
893+ (MockContractState w -> Assertion ) ->
894+ Assertion
895+ assertContract contract initState assertion = do
896+ let (result, state) = runContractPure contract initState
897+
898+ case result of
899+ Left errMsg -> assertFailure (show errMsg)
900+ Right _ -> assertion state
901+
891902assertCommandHistory :: forall (w :: Type ). MockContractState w -> [(Int , Text )] -> Assertion
892903assertCommandHistory state =
893904 mapM_
0 commit comments