diff --git a/hydra-cardano-api/src/Hydra/Cardano/Api/Tx.hs b/hydra-cardano-api/src/Hydra/Cardano/Api/Tx.hs index fd85dbfdaf1..8fb4b5766e1 100644 --- a/hydra-cardano-api/src/Hydra/Cardano/Api/Tx.hs +++ b/hydra-cardano-api/src/Hydra/Cardano/Api/Tx.hs @@ -227,7 +227,6 @@ toLedgerTx = \case & datsTxWitsL .~ datums & rdmrsTxWitsL .~ redeemers in mkBasicTx - -- TODO: Test that aux data hash is correctly updated in conversions (body & auxDataHashTxBodyL .~ maybe SNothing (SJust . hashTxAuxData) auxData) & isValidTxL .~ toLedgerScriptValidity validity & auxDataTxL .~ maybeToStrictMaybe auxData @@ -237,12 +236,13 @@ toLedgerTx = \case fromLedgerTx :: Ledger.Tx (ShelleyLedgerEra Era) -> Tx Era fromLedgerTx ledgerTx = Tx - (ShelleyTxBody shelleyBasedEra body scripts scriptsData (strictMaybeToMaybe auxData) validity) + (ShelleyTxBody shelleyBasedEra body' scripts scriptsData (strictMaybeToMaybe auxData) validity) (fromLedgerTxWitness wits) where -- XXX: The suggested way (by the ledger team) forward is to use lenses to -- introspect ledger transactions. Ledger.AlonzoTx body wits isValid auxData = ledgerTx + body' = body & auxDataHashTxBodyL .~ (hashTxAuxData <$> auxData) scripts = Map.elems $ Ledger.txscripts' wits diff --git a/hydra-node/test/Hydra/Ledger/CardanoSpec.hs b/hydra-node/test/Hydra/Ledger/CardanoSpec.hs index b1bd3e38ae1..3dbed3aca5c 100644 --- a/hydra-node/test/Hydra/Ledger/CardanoSpec.hs +++ b/hydra-node/test/Hydra/Ledger/CardanoSpec.hs @@ -8,9 +8,11 @@ import Hydra.Prelude import Test.Hydra.Prelude import Cardano.Binary (decodeFull, serialize') -import Cardano.Ledger.Api (ensureMinCoinTxOut) +import Cardano.Ledger.Api (auxDataHashTxBodyL, bodyTxL, ensureMinCoinTxOut) +import Cardano.Ledger.BaseTypes (StrictMaybe (..)) import Cardano.Ledger.Core (PParams ()) import Cardano.Ledger.Credential (Credential (..)) +import Control.Lens ((.~)) import Data.Aeson (eitherDecode, encode) import Data.Aeson qualified as Aeson import Data.Aeson.Lens (key) @@ -71,6 +73,8 @@ spec = prop "Roundtrip to and from Ledger" roundtripLedger + prop "Roundtrip tx metadata" roundtripTxMetadata + prop "Roundtrip CBOR encoding" $ roundtripCBOR @Tx prop "JSON encoding of Tx according to schema" $ @@ -152,6 +156,10 @@ roundtripLedger :: Tx -> Property roundtripLedger tx = fromLedgerTx (toLedgerTx tx) === tx +roundtripTxMetadata :: Tx -> Property +roundtripTxMetadata tx = + fromLedgerTx (toLedgerTx tx & bodyTxL . auxDataHashTxBodyL .~ SNothing) === tx + roundtripCBOR :: (Eq a, Show a, ToCBOR a, FromCBOR a) => a -> Property roundtripCBOR a = let encoded = serialize' a