Skip to content

Commit

Permalink
Babbage serialization tests
Browse files Browse the repository at this point in the history
  • Loading branch information
goolord committed Feb 23, 2022
1 parent e8ff740 commit b0f2ca8
Show file tree
Hide file tree
Showing 9 changed files with 641 additions and 11 deletions.
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
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
110 changes: 110 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,110 @@
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
Test.Cardano.Ledger.Babbage.Trace
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

0 comments on commit b0f2ca8

Please sign in to comment.