Skip to content

Commit afcb7d8

Browse files
committed
Implement "Non-script output with datum" Alonzo UTxOW test
1 parent 957370a commit afcb7d8

File tree

1 file changed

+17
-4
lines changed
  • eras/alonzo/impl/testlib/Test/Cardano/Ledger/Alonzo/Imp/UtxowSpec

1 file changed

+17
-4
lines changed

eras/alonzo/impl/testlib/Test/Cardano/Ledger/Alonzo/Imp/UtxowSpec/Valid.hs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import Cardano.Ledger.Alonzo.Rules (
1919
)
2020
import Cardano.Ledger.Alonzo.Scripts (eraLanguages)
2121
import Cardano.Ledger.Alonzo.TxWits (unTxDatsL)
22-
import Cardano.Ledger.BaseTypes (StrictMaybe (..), natVersion)
22+
import Cardano.Ledger.BaseTypes (StrictMaybe (..), inject, natVersion)
2323
import Cardano.Ledger.Coin (Coin (..))
2424
import Cardano.Ledger.Credential (Credential (..), StakeReference (..))
2525
import Cardano.Ledger.Mary.Value (AssetName (..), MaryValue (..), MultiAsset (..), PolicyID (..))
@@ -39,6 +39,7 @@ import GHC.Exts (fromList)
3939
import Lens.Micro ((%~), (&), (.~))
4040
import Lens.Micro.Mtl (use)
4141
import Test.Cardano.Ledger.Alonzo.ImpTest
42+
import Test.Cardano.Ledger.Core.Utils
4243
import Test.Cardano.Ledger.Imp.Common
4344
import Test.Cardano.Ledger.Plutus.Examples
4445

@@ -53,6 +54,21 @@ spec ::
5354
) =>
5455
SpecWith (ImpInit (LedgerSpec era))
5556
spec = 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

Comments
 (0)