Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Babbage serialization tests #2666

Merged
merged 2 commits into from
Feb 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ packages:
eras/alonzo/impl
eras/alonzo/test-suite
eras/babbage/impl
eras/babbage/test-suite
eras/byron/chain/executable-spec
eras/byron/ledger/executable-spec
eras/byron/ledger/impl
Expand Down Expand Up @@ -122,6 +123,9 @@ package cardano-ledger-alonzo-test
package cardano-ledger-babbage
ghc-options: -Werror

package cardano-ledger-babbage-test
ghc-options: -Werror

package byron-spec-chain
ghc-options: -Werror

Expand Down
1 change: 0 additions & 1 deletion eras/alonzo/test-suite/cardano-ledger-alonzo-test.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ library
Test.Cardano.Ledger.Alonzo.Serialisation.Generators
Test.Cardano.Ledger.Alonzo.AlonzoEraGen
Test.Cardano.Ledger.Alonzo.Scripts
Test.Cardano.Ledger.Alonzo.Trace
Test.Cardano.Ledger.Alonzo.PlutusScripts
build-depends:
bytestring,
Expand Down
19 changes: 0 additions & 19 deletions eras/alonzo/test-suite/src/Test/Cardano/Ledger/Alonzo/Trace.hs

This file was deleted.

21 changes: 11 additions & 10 deletions eras/babbage/impl/src/Cardano/Ledger/Babbage/TxBody.hs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import Cardano.Binary
decodeBreakOr,
decodeListLenOrIndef,
encodeListLen,
serialize,
)
import Cardano.Crypto.Hash
import Cardano.Ledger.Address (Addr (..))
Expand Down Expand Up @@ -662,7 +663,7 @@ instance
<> toCBOR addr
<> toCBOR cv
<> toCBOR d
<> toCBOR rs
<> encodeCIC rs
toCBOR (TxOutCompactDH addr cv dh) =
encodeListLen 3
<> toCBOR addr
Expand Down Expand Up @@ -710,29 +711,29 @@ instance
True -> pure $ TxOutCompactDH a cv dh
False -> cborError $ DecoderErrorCustom "txout" "Excess terms in txout"
Just 2 ->
TxOutCompact
<$> fromCBOR
<*> decodeNonNegative
TxOutCompact <$> fromCBOR <*> decodeNonNegative
Just 3 ->
TxOutCompactDH
<$> fromCBOR
<*> decodeNonNegative
<*> fromCBOR
TxOutCompactDH <$> fromCBOR <*> decodeNonNegative <*> fromCBOR
Just 4 -> do
1 <- fromCBOR @Word8
0 <- fromCBOR @Word8
TxOutCompactDatum <$> fromCBOR <*> decodeNonNegative <*> fromCBOR
Just 5 -> do
1 <- fromCBOR @Word8
2 <- fromCBOR @Word8
TxOutCompactRefScript' <$> fromCBOR <*> decodeNonNegative <*> fromCBOR <*> decodeCIC "Script"
Just n -> cborError $ DecoderErrorCustom "txout" $ "wrong number of terms in txout: " <> T.pack (show n)

-- decodes the CBOR from TkBytes
decodeCIC :: (FromCBOR (Annotator b)) => T.Text -> Decoder s b
decodeCIC s = do
lbs <- fromCBOR
case decodeAnnotator s fromCBOR lbs of
Left _ -> fail "foo"
Right x -> pure x

-- encodes the CBOR as TkBytes
encodeCIC :: ToCBOR a => a -> Encoding
encodeCIC = toCBOR . serialize

encodeTxBodyRaw ::
( Era era,
ToCBOR (PParamsDelta era),
Expand Down
109 changes: 109 additions & 0 deletions eras/babbage/test-suite/cardano-ledger-babbage-test.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
cabal-version: 3.0

name: cardano-ledger-babbage-test
version: 0.1.0.0
synopsis: Tests for Cardano ledger babbage era
description:
This package builds upon the Alonzo ledger
bug-reports: https://github.com/input-output-hk/cardano-ledger/issues
license: Apache-2.0
author: IOHK Formal Methods Team
maintainer: formal.methods@iohk.io
copyright: 2020 Input Output (Hong Kong) Ltd.
category: Network
build-type: Simple

-- extra-source-files:

source-repository head
type: git
location: https://github.com/input-output-hk/cardano-ledger
subdir: eras/babbage/test-suite

common base
build-depends: base >= 4.12 && < 4.15

common project-config
default-language: Haskell2010

ghc-options: -Wall
-Wcompat
-Wincomplete-record-updates
-Wincomplete-uni-patterns
-Wpartial-fields
-Wredundant-constraints
-- -Wunused-packages

library
import: base, project-config

exposed-modules:
Test.Cardano.Ledger.Babbage.Serialisation.Generators
build-depends:
bytestring,
cardano-binary,
cardano-ledger-alonzo,
cardano-ledger-alonzo-test,
cardano-ledger-babbage,
cardano-ledger-core,
cardano-ledger-pretty,
cardano-ledger-shelley-ma-test,
cardano-ledger-shelley-ma,
cardano-protocol-tpraos,
cardano-slotting,
containers,
data-default-class,
hashable,
plutus-tx,
plutus-ledger-api,
QuickCheck,
cardano-ledger-shelley-test,
cardano-ledger-shelley,
small-steps,
strict-containers,
text,
hs-source-dirs:
src

test-suite cardano-ledger-babbage-test
import: base, project-config

type: exitcode-stdio-1.0
main-is: Tests.hs
hs-source-dirs:
test
other-modules:
Test.Cardano.Ledger.Babbage.Serialisation.Tripping
build-depends:
QuickCheck,
base16-bytestring,
bytestring,
cardano-binary,
cardano-data,
cardano-ledger-alonzo,
cardano-ledger-alonzo-test,
cardano-ledger-babbage,
cardano-ledger-babbage-test,
cardano-ledger-core,
cardano-ledger-pretty,
cardano-ledger-shelley,
cardano-ledger-shelley-ma,
cardano-ledger-shelley-ma-test,
cardano-ledger-shelley-test,
cardano-protocol-tpraos,
cardano-slotting,
cborg,
containers,
data-default-class,
plutus-core,
plutus-ledger-api,
plutus-tx,
small-steps,
small-steps-test,
strict-containers,
tasty,
tasty-hunit,
tasty-quickcheck,
time,
pretty-show,
transformers
Loading