Skip to content

Commit 3a83422

Browse files
Soupstrawlehins
andcommitted
Review
Co-authored-by: Alexey Kuleshevich <[email protected]>
1 parent ac400ce commit 3a83422

File tree

2 files changed

+16
-18
lines changed
  • eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/Binary
  • libs/cardano-ledger-binary/src/Cardano/Ledger

2 files changed

+16
-18
lines changed

eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/Binary/Golden.hs

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,25 @@ import Cardano.Ledger.Alonzo.Core (
2121
pattern SpendingPurpose,
2222
)
2323
import Cardano.Ledger.Alonzo.Scripts (ExUnits (..))
24-
import Cardano.Ledger.Alonzo.TxWits (Redeemers (..))
24+
import Cardano.Ledger.Alonzo.TxWits (Redeemers (..), unRedeemers)
2525
import Cardano.Ledger.BaseTypes (Version)
2626
import Cardano.Ledger.Binary (
2727
Annotator (..),
2828
DecCBOR (..),
2929
ToCBOR (..),
3030
decodeFullAnnotator,
31-
toStrictByteString,
31+
toLazyByteString,
3232
)
3333
import Cardano.Ledger.Binary.Plain (DecoderError (..), Tokens (..))
3434
import Cardano.Ledger.Plutus (Data (..))
35-
import Data.ByteString (fromStrict)
3635
import qualified Data.Map as Map
3736
import Data.Typeable (Proxy (..), Typeable)
3837
import PlutusLedgerApi.Common (Data (..))
3938
import Test.Cardano.Ledger.Binary.Plain.Golden (Enc (..))
39+
import Test.Cardano.Ledger.Binary.RoundTrip (embedTripAnnExpectation)
4040
import 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

5253
expectDecoderFailure ::
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

7071
expectDecoderResultOn ::
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
7475
expectDecoderResultOn 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
8379
listRedeemersEnc :: 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

libs/cardano-ledger-binary/src/Cardano/Ledger/Binary.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module Cardano.Ledger.Binary (
99
Term (..),
1010
C.DeserialiseFailure (..),
1111
translateViaCBORAnnotator,
12+
toLazyByteString,
1213
) where
1314

1415
import Cardano.Ledger.Binary.Decoding
@@ -40,6 +41,7 @@ import qualified Cardano.Ledger.Binary.Plain as Plain
4041
import Cardano.Ledger.Binary.Version
4142
import qualified Codec.CBOR.Read as C (DeserialiseFailure (..))
4243
import Codec.CBOR.Term (Term (..))
44+
import Codec.CBOR.Write (toLazyByteString)
4345
import Control.Monad.Except (Except, MonadError (throwError))
4446
import Data.Text (Text)
4547

0 commit comments

Comments
 (0)