Skip to content

Commit

Permalink
WIP: Huddle for Alonzo
Browse files Browse the repository at this point in the history
  • Loading branch information
aniketd committed Nov 28, 2024
1 parent 397bf8f commit ea9c930
Show file tree
Hide file tree
Showing 12 changed files with 697 additions and 302 deletions.
1 change: 1 addition & 0 deletions eras/allegra/impl/cardano-ledger-allegra.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ library testlib
containers,
cuddle,
generic-random,
heredoc,
microlens,
mtl,
small-steps,
Expand Down
44 changes: 13 additions & 31 deletions eras/allegra/impl/testlib/Test/Cardano/Ledger/Allegra/CDDL.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{-# LANGUAGE OverloadedLists #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}

Expand All @@ -11,21 +12,8 @@ module Test.Cardano.Ledger.Allegra.CDDL where
import Codec.CBOR.Cuddle.Huddle
import Data.Function (($))
import Test.Cardano.Ledger.Core.Binary.CDDL
import Test.Cardano.Ledger.Shelley.CDDL (
bootstrap_witness,
certificate,
header,
metadata_hash,
set,
transaction_index,
transaction_input,
transaction_metadatum,
transaction_metadatum_label,
transaction_output,
update,
vkeywitness,
withdrawals,
)
import Test.Cardano.Ledger.Shelley.CDDL hiding (block, transaction, transaction_body)
import Text.Heredoc

cddl :: Huddle
cddl = collectFrom [block, transaction]
Expand All @@ -36,20 +24,23 @@ cddl = collectFrom [block, transaction]

native_script :: Rule
native_script =
comment "Timelock validity intervals are half-open intervals [a, b)." $
"native_script"
comment
[str|
|invalid_before
| Timelock validity intervals are half-open intervals [a, b).
| This field specifies the left (included) endpoint a.
|invalid_hereafter
| Timelock validity intervals are half-open intervals [a, b).
| This field specifies the right (excluded) endpoint b.
|]
$ "native_script"
=:= arr [a script_pubkey]
/ arr [a script_all]
/ arr [a script_any]
/ arr [a script_n_of_k]
/ arr [a invalid_before]
-- Timelock validity intervals are half-open intervals [a, b).
-- This field specifies the left (included) endpoint a.
/ arr [a invalid_hereafter]

-- Timelock validity intervals are half-open intervals [a, b).
-- This field specifies the right (excluded) endpoint b.

script_pubkey :: Named Group
script_pubkey = "script_pubkey" =:~ grp [0, a addr_keyhash]

Expand All @@ -70,15 +61,6 @@ invalid_before = "invalid_before" =:~ grp [4, a VUInt]
invalid_hereafter :: Named Group
invalid_hereafter = "invalid_hereafter" =:~ grp [5, a VUInt]

transaction_witness_set :: Rule
transaction_witness_set =
"transaction_witness_set"
=:= mp
[ opt $ idx 0 ==> arr [0 <+ a vkeywitness]
, opt $ idx 1 ==> arr [0 <+ a native_script]
, opt $ idx 2 ==> arr [0 <+ a bootstrap_witness]
]

auxiliary_data :: Rule
auxiliary_data =
"auxiliary_data"
Expand Down
2 changes: 1 addition & 1 deletion eras/alonzo/impl/.ghcid
Original file line number Diff line number Diff line change
@@ -1 +1 @@
--command="cabal repl --repl-options='-isrc -fwarn-unused-binds -fwarn-unused-imports -fno-code -fobject-code -g2 -fno-break-on-exception -fno-break-on-error -ferror-spans -j -Wno-unused-packages'" --clear --no-height-limit --reverse-errors --reload=../../../ --outputfile=/tmp/cardano-ledger-alonzo-ghcid.txt
--command="cabal repl --repl-options='-isrc -fwarn-unused-binds -fwarn-unused-imports -fno-code -fobject-code -g2 -fno-break-on-exception -fno-break-on-error -ferror-spans -j -Wno-unused-packages'" --clear --no-height-limit --reverse-errors --reload=../../../ --outputfile=/tmp/cardano-ledger-alonzo-ghcid.txt
20 changes: 19 additions & 1 deletion eras/alonzo/impl/cardano-ledger-alonzo.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ library
library testlib
exposed-modules:
Test.Cardano.Ledger.Alonzo.Arbitrary
Test.Cardano.Ledger.Alonzo.CDDL
Test.Cardano.Ledger.Alonzo.Binary.Cddl
Test.Cardano.Ledger.Alonzo.Binary.CostModelsSpec
Test.Cardano.Ledger.Alonzo.Binary.RoundTrip
Expand Down Expand Up @@ -135,13 +136,15 @@ library testlib
cardano-crypto-class,
cardano-data,
cardano-ledger-alonzo,
cardano-ledger-allegra,
cardano-ledger-allegra:{cardano-ledger-allegra, testlib},
cardano-ledger-binary,
cardano-ledger-mary:testlib,
cardano-ledger-core:{cardano-ledger-core, testlib},
cardano-ledger-shelley:{cardano-ledger-shelley, testlib},
cardano-strict-containers,
cardano-slotting,
cuddle,
heredoc,
plutus-ledger-api,
generic-random,
microlens,
Expand All @@ -153,6 +156,21 @@ library testlib
tree-diff,
QuickCheck

executable huddle-cddl
main-is: Main.hs
hs-source-dirs: huddle-cddl
other-modules: Paths_cardano_ledger_alonzo
default-language: Haskell2010
ghc-options:
-Wall -Wcompat -Wincomplete-record-updates
-Wincomplete-uni-patterns -Wredundant-constraints -Wpartial-fields
-Wunused-packages -threaded -rtsopts -with-rtsopts=-N

build-depends:
base,
testlib,
cardano-ledger-binary:testlib >=1.5

executable gen-golden
main-is: GenerateGoldenFileMain.hs
hs-source-dirs: test
Expand Down
2 changes: 0 additions & 2 deletions eras/alonzo/impl/cddl-files/alonzo.cddl
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,6 @@ auxiliary_data =
, ? 2 => [ * plutus_script ]
})



vkeywitness = [ $vkey, $signature ]

bootstrap_witness =
Expand Down
11 changes: 11 additions & 0 deletions eras/alonzo/impl/huddle-cddl/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Main where

import Paths_cardano_ledger_alonzo
import qualified Test.Cardano.Ledger.Alonzo.CDDL as Alonzo
import Test.Cardano.Ledger.Binary.Cuddle (writeSpec)

-- Generate cddl files for all relevant specifications
main :: IO ()
main = do
specFile <- getDataFileName "cddl-files/alonzo.cddl"
writeSpec Alonzo.alonzo specFile
Loading

0 comments on commit ea9c930

Please sign in to comment.