@@ -21,24 +21,25 @@ import Cardano.Ledger.Alonzo.Core (
2121 pattern SpendingPurpose ,
2222 )
2323import Cardano.Ledger.Alonzo.Scripts (ExUnits (.. ))
24- import Cardano.Ledger.Alonzo.TxWits (Redeemers (.. ))
24+ import Cardano.Ledger.Alonzo.TxWits (Redeemers (.. ), unRedeemers )
2525import Cardano.Ledger.BaseTypes (Version )
2626import Cardano.Ledger.Binary (
2727 Annotator (.. ),
2828 DecCBOR (.. ),
2929 ToCBOR (.. ),
3030 decodeFullAnnotator ,
31- toStrictByteString ,
31+ toLazyByteString ,
3232 )
3333import Cardano.Ledger.Binary.Plain (DecoderError (.. ), Tokens (.. ))
3434import Cardano.Ledger.Plutus (Data (.. ))
35- import Data.ByteString (fromStrict )
3635import qualified Data.Map as Map
3736import Data.Typeable (Proxy (.. ), Typeable )
3837import PlutusLedgerApi.Common (Data (.. ))
3938import Test.Cardano.Ledger.Binary.Plain.Golden (Enc (.. ))
39+ import Test.Cardano.Ledger.Binary.RoundTrip (embedTripAnnExpectation )
4040import Test.Cardano.Ledger.Common (
4141 Expectation ,
42+ HasCallStack ,
4243 Spec ,
4344 ToExpr ,
4445 expectationFailure ,
@@ -51,7 +52,7 @@ import Test.Cardano.Ledger.Conway.Era (ConwayEraTest)
5152
5253expectDecoderFailure ::
5354 forall a .
54- (ToExpr a , DecCBOR (Annotator a ), Typeable a ) =>
55+ (ToExpr a , DecCBOR (Annotator a ), Typeable a , HasCallStack ) =>
5556 Version ->
5657 Enc ->
5758 DecoderError ->
@@ -64,20 +65,15 @@ expectDecoderFailure version enc expectedErr =
6465 " Expected a failure, but decoder succeeded:\n "
6566 <> showExpr x
6667 where
67- bytes = fromStrict . toStrictByteString $ toCBOR enc
68+ bytes = toLazyByteString $ toCBOR enc
6869 result = decodeFullAnnotator @ a version (label $ Proxy @ (Annotator a )) decCBOR bytes
6970
7071expectDecoderResultOn ::
7172 forall a b .
72- (ToExpr b , DecCBOR (Annotator a ), Typeable a , Eq b ) =>
73+ (ToExpr b , DecCBOR (Annotator a ), Eq b , HasCallStack ) =>
7374 Version -> Enc -> a -> (a -> b ) -> Expectation
7475expectDecoderResultOn version enc expected f =
75- case result of
76- Left err -> expectationFailure $ " Decoder failed with:\n " <> show err
77- Right x -> f x `shouldBeExpr` f expected
78- where
79- bytes = fromStrict . toStrictByteString $ toCBOR enc
80- result = decodeFullAnnotator @ a version (label $ Proxy @ (Annotator a )) decCBOR bytes
76+ embedTripAnnExpectation version version (\ x _ -> f x `shouldBeExpr` f expected) enc
8177
8278-- | A simple redeemer encoded as a list
8379listRedeemersEnc :: Enc
@@ -87,12 +83,12 @@ listRedeemersEnc =
8783 , mconcat
8884 [ E (TkListLen 4 )
8985 , E (0 :: Int )
90- , E (0 :: Int )
91- , E (0 :: Int )
86+ , E (10 :: Int )
87+ , E (20 :: Int )
9288 , mconcat
9389 [ E (TkListLen 2 )
94- , E (0 :: Int )
95- , E (0 :: Int )
90+ , E (30 :: Int )
91+ , E (40 :: Int )
9692 ]
9793 ]
9894 ]
@@ -103,5 +99,5 @@ goldenListRedeemers =
10399 expectDecoderResultOn @ (Redeemers era )
104100 (eraProtVerLow @ era )
105101 listRedeemersEnc
106- (Redeemers $ Map. singleton (SpendingPurpose $ AsIx 0 ) (Data $ I 0 , ExUnits 0 0 ))
107- ( \ ( Redeemers m) -> m)
102+ (Redeemers $ Map. singleton (SpendingPurpose $ AsIx 10 ) (Data $ I 20 , ExUnits 30 40 ))
103+ unRedeemers
0 commit comments