Skip to content

Commit

Permalink
Merge pull request #4629 from IntersectMBO/aniketd/add-txinfo-golden-…
Browse files Browse the repository at this point in the history
…test-for-conway

Add TxInfo golden test for Conway
  • Loading branch information
lehins authored Sep 17, 2024
2 parents a00b723 + f475aac commit a8b02a7
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
-- | Deserializes `TranslationInstance`s from golden/translations.cbor file.
--
-- Each instance represents arguments passed to `ExtendedUTxO.txInfo` along with the produced result.
-- This test checks that calling `alonzoTxInfo` with the arguments from this file, produces the same result as in the flie.
-- This test checks that calling `alonzoTxInfo` with the arguments from this file, produces the same result as in the file.
--
-- To regenerate the golden file (for example, if the logic in the translation changes),
-- run the following command from the root of the repository:
-- cabal run cardano-ledger-alonzotest:gen-golden"
-- cabal run cardano-ledger-alonzo:gen-golden"
module Test.Cardano.Ledger.Alonzo.GoldenTranslation (
tests,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@

-- | Deserializes `TranslationInstance`s from golden/translations.cbor file.
--
-- Each instance represents arguments passed to `ExtendedUTxO.txInfo` along with the produced result.
-- This test checks that calling `alonzoTxInfo` with the arguments from this file, produces the same result as in the flie.
--
-- To regenerate the golden file (for example, if the logic in the translation changes),
-- run the following command from the root of the repository:
-- cabal run cardano-ledger-<era>-test:gen-golden"
-- cabal run cardano-ledger-<era>:gen-golden"
module Test.Cardano.Ledger.Babbage.GoldenTranslation (
spec,
)
Expand Down
1 change: 1 addition & 0 deletions eras/conway/impl/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* `reCommitteeStateL`
* Add a new field to `GovInfoEvent` and change "unclaimed" field from `Set` to a `Map`.
* Changed return type of `proposalsShowDebug`
* Added `gen-golden` executable needed for golden tests: #4629

### `testlib`

Expand Down
4 changes: 3 additions & 1 deletion eras/conway/impl/cardano-ledger-conway.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ test-suite tests
Test.Cardano.Ledger.Conway.GovActionReorderSpec
Test.Cardano.Ledger.Conway.Plutus.PlutusSpec
Test.Cardano.Ledger.Conway.TxInfoSpec
Test.Cardano.Ledger.Conway.GoldenTranslation
Paths_cardano_ledger_conway

default-language: Haskell2010
Expand Down Expand Up @@ -241,4 +242,5 @@ test-suite tests
data-default-class,
microlens,
plutus-ledger-api,
testlib
testlib,
HUnit
Binary file modified eras/conway/impl/golden/translations.cbor
Binary file not shown.
2 changes: 2 additions & 0 deletions eras/conway/impl/test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import qualified Test.Cardano.Ledger.Conway.BinarySpec as Binary
import qualified Test.Cardano.Ledger.Conway.CommitteeRatifySpec as CommitteeRatify
import qualified Test.Cardano.Ledger.Conway.DRepRatifySpec as DRepRatify
import qualified Test.Cardano.Ledger.Conway.GenesisSpec as Genesis
import qualified Test.Cardano.Ledger.Conway.GoldenTranslation as Golden
import qualified Test.Cardano.Ledger.Conway.GovActionReorderSpec as GovActionReorder
import qualified Test.Cardano.Ledger.Conway.Imp as Imp
import Test.Cardano.Ledger.Conway.Plutus.PlutusSpec as PlutusSpec
Expand All @@ -24,6 +25,7 @@ main :: IO ()
main =
ledgerTestMain $
describe "Conway" $ do
Golden.spec
Spec.spec
Proposals.spec
Binary.spec
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}

-- | Deserializes `TranslationInstance`s from golden/translations.cbor file.
--
-- To regenerate the golden file (for example, if the logic in the translation changes),
-- run the following command from the root of the repository:
-- cabal run cardano-ledger-<era>:gen-golden"
module Test.Cardano.Ledger.Conway.GoldenTranslation (
spec,
)
where

import Cardano.Ledger.Conway (Conway)
import Paths_cardano_ledger_conway (getDataFileName)
import Test.Cardano.Ledger.Alonzo.Translation.Golden (assertTranslationResultsMatchGolden)
import Test.Cardano.Ledger.Common
import Test.Cardano.Ledger.Conway.Translation.TranslatableGen ()
import Test.HUnit (Assertion)

spec :: Spec
spec =
describe "Golden translation tests" $
it "golden/translation.cbor" $
check "golden/translations.cbor"

check :: String -> Assertion
check file = assertTranslationResultsMatchGolden @Conway (getDataFileName file)

0 comments on commit a8b02a7

Please sign in to comment.