@@ -19,7 +19,7 @@ import Cardano.Ledger.Alonzo.Rules (
1919 )
2020import Cardano.Ledger.Alonzo.Scripts (eraLanguages )
2121import Cardano.Ledger.Alonzo.TxWits (unTxDatsL )
22- import Cardano.Ledger.BaseTypes (StrictMaybe (.. ), natVersion )
22+ import Cardano.Ledger.BaseTypes (StrictMaybe (.. ), inject , natVersion )
2323import Cardano.Ledger.Coin (Coin (.. ))
2424import Cardano.Ledger.Credential (Credential (.. ), StakeReference (.. ))
2525import Cardano.Ledger.Mary.Value (AssetName (.. ), MaryValue (.. ), MultiAsset (.. ), PolicyID (.. ))
@@ -39,6 +39,7 @@ import GHC.Exts (fromList)
3939import Lens.Micro ((%~) , (&) , (.~) )
4040import Lens.Micro.Mtl (use )
4141import Test.Cardano.Ledger.Alonzo.ImpTest
42+ import Test.Cardano.Ledger.Core.Utils
4243import Test.Cardano.Ledger.Imp.Common
4344import Test.Cardano.Ledger.Plutus.Examples
4445
@@ -53,6 +54,21 @@ spec ::
5354 ) =>
5455 SpecWith (ImpInit (LedgerSpec era ))
5556spec = describe " Valid transactions" $ do
57+ it " Non-script output with datum" $ do
58+ -- Attach a datum (hash) to a non-script output and then spend it.
59+ -- Note that the datum cannot be supplied when spending the output,
60+ -- because it's considered extraneous.
61+ addr <- mkAddr <$> freshKeyHash @ 'Payment <*> pure StakeRefNull
62+ amount <- Coin <$> choose (2_000_000 , 8_000_000 )
63+ let
64+ datumHash = hashData @ era $ Data (P. I 123 )
65+ txOut = mkBasicTxOut addr (inject amount) & dataHashTxOutL .~ SJust datumHash
66+ tx1 = mkBasicTx mkBasicTxBody & bodyTxL . outputsTxBodyL .~ [txOut]
67+ txIn <- txInAt (0 :: Int ) <$> submitTx tx1
68+ let
69+ tx2 = mkBasicTx mkBasicTxBody & bodyTxL . inputsTxBodyL .~ [txIn]
70+ expectTxSuccess =<< submitTx tx2
71+
5672 forM_ (eraLanguages @ era ) $ \ lang ->
5773 withSLanguage lang $ \ slang ->
5874 describe (show lang) $ do
@@ -184,6 +200,3 @@ spec = describe "Valid transactions" $ do
184200 else
185201 -- Conway fixed the bug that was causing DELEG to fail
186202 expectTxSuccess =<< submitTx tx
187-
188- it " Non-script output with datum" $ do
189- const $ pendingWith " not implemented yet"
0 commit comments