diff --git a/CHANGELOG.md b/CHANGELOG.md index dc3f09772..1fe50446f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,6 +64,10 @@ math: true - Ogmios now exits with code 0 when it is stopped with `SIGINT` (Ctrl+C) or `SIGTERM`. Before, it exited with code 255 when it ran as PID 1, for example in a Docker container. +- In the Dijkstra era, `evaluateTransaction` no longer ignores `additionalUtxo` when the mempool of the node holds transactions. Before, the evaluation then failed for inputs found only in `additionalUtxo`. `additionalUtxo` can now also hold Dijkstra outputs, such as native scripts with a `guard` clause. + +- `evaluateTransaction` now reads scripts with `"language": "plutus:v4"` in `additionalUtxo`. Before, it refused them. + ### [6.14.0] - 2025-10-16 #### Added diff --git a/server/src/Ogmios/Data/EraTranslation.hs b/server/src/Ogmios/Data/EraTranslation.hs index 91493ef02..21d1de990 100644 --- a/server/src/Ogmios/Data/EraTranslation.hs +++ b/server/src/Ogmios/Data/EraTranslation.hs @@ -182,12 +182,18 @@ data MultiEraTxOut block where :: Babbage.BabbageTxOut ConwayEra -> MultiEraTxOut block + TxOutInDijkstraEra + :: Babbage.BabbageTxOut DijkstraEra + -> MultiEraTxOut block + deriving instance ( Eq (Babbage.BabbageTxOut BabbageEra) , Eq (Babbage.BabbageTxOut ConwayEra) + , Eq (Babbage.BabbageTxOut DijkstraEra) ) => Eq (MultiEraTxOut block) deriving instance ( Show (Babbage.BabbageTxOut BabbageEra) , Show (Babbage.BabbageTxOut ConwayEra) + , Show (Babbage.BabbageTxOut DijkstraEra) ) => Show (MultiEraTxOut block) diff --git a/server/src/Ogmios/Data/Json/Query.hs b/server/src/Ogmios/Data/Json/Query.hs index f3694f171..1f07a251b 100644 --- a/server/src/Ogmios/Data/Json/Query.hs +++ b/server/src/Ogmios/Data/Json/Query.hs @@ -57,7 +57,9 @@ module Ogmios.Data.Json.Query ( decodeDRepCredential, decodeStakingCredential, decodeDatumHash, + decodeDijkstraNativeScript, decodeHash, + decodeNativeScript, decodeOneEraHash, decodePoint, decodePolicyId, @@ -318,6 +320,7 @@ import qualified Cardano.Ledger.Conway.Governance as Ledger.Conway import qualified Cardano.Ledger.Core as Ledger import qualified Cardano.Ledger.Credential as Ledger import qualified Cardano.Ledger.DRep as Ledger +import qualified Cardano.Ledger.Dijkstra.Scripts as Ledger.Dijkstra import qualified Cardano.Ledger.Hashes as Ledger import qualified Cardano.Ledger.Mary.Value as Ledger.Mary import qualified Cardano.Ledger.Plutus.Data as Ledger.Plutus @@ -2772,9 +2775,10 @@ decodeScript :: ( AlonzoEraScript era , Ledger.Script era ~ Ledger.Alonzo.AlonzoScript era ) => + (Json.Value -> Json.Parser (Ledger.NativeScript era)) -> Json.Value -> Json.Parser (Ledger.Script era) -decodeScript v = +decodeScript decodeNativeScriptInEra v = Json.withText "Script::CBOR" decodeFromBase16Cbor v <|> Json.withObject "Script::JSON" decodeFromWrappedJson v where @@ -2798,7 +2802,7 @@ decodeScript v = Left (_ :: Text) -> fail "couldn't decode native script" (_, Just script) -> - Ledger.Alonzo.NativeScript <$> decodeNativeScript script + Ledger.Alonzo.NativeScript <$> decodeNativeScriptInEra script (_, _) -> fail "missing field 'cbor' or 'json' to decode native script" Just lang@"plutus:v1" -> do @@ -2813,6 +2817,10 @@ decodeScript v = bytes <- o .: "cbor" plutus <- Ledger.Alonzo.mkBinaryPlutusScript Ledger.Plutus.PlutusV3 <$> decodePlutusScript Plutus.PlutusV3 lang bytes maybe (fail "unable to instantiate PlutusScript from binary data") (pure . Ledger.Alonzo.PlutusScript) plutus + Just lang@"plutus:v4" -> do + bytes <- o .: "cbor" + plutus <- Ledger.Alonzo.mkBinaryPlutusScript Ledger.Plutus.PlutusV4 <$> decodePlutusScript Plutus.PlutusV4 lang bytes + maybe (fail "unable to instantiate PlutusScript from binary data") (pure . Ledger.Alonzo.PlutusScript) plutus _ -> fail "missing or unknown script language." where @@ -2957,7 +2965,18 @@ decodeNativeScript :: (AllegraEraScript era) => Json.Value -> Json.Parser (Ledger.NativeScript era) -decodeNativeScript = Json.withObject "Script" $ \o -> do +decodeNativeScript = + decodeNativeScriptWith decodeNativeScript + +-- | Decode a native script, and the scripts inside 'all', 'any' and 'some' +-- with the given decoder. +decodeNativeScriptWith :: + forall era. + (AllegraEraScript era) => + (Json.Value -> Json.Parser (Ledger.NativeScript era)) -> + Json.Value -> + Json.Parser (Ledger.NativeScript era) +decodeNativeScriptWith decodeInner = Json.withObject "Script" $ \o -> do clause <- o .: "clause" case clause :: Text of "signature" -> @@ -2980,19 +2999,36 @@ decodeNativeScript = Json.withObject "Script" $ \o -> do pure $ mkRequireSignature @era (Ledger.KeyHash from) decodeAllOf o = do xs <- StrictSeq.fromList <$> (o .: "from") - mkRequireAllOf @era <$> traverse decodeNativeScript xs + mkRequireAllOf @era <$> traverse decodeInner xs decodeAnyOf o = do xs <- StrictSeq.fromList <$> (o .: "from") - mkRequireAnyOf @era <$> traverse decodeNativeScript xs + mkRequireAnyOf @era <$> traverse decodeInner xs decodeSomeOf o = do n <- o .: "atLeast" xs <- StrictSeq.fromList <$> (o .: "from") - mkRequireMOf @era n <$> traverse decodeNativeScript xs + mkRequireMOf @era n <$> traverse decodeInner xs decodeTimeExpire o = mkTimeExpire @era . SlotNo <$> (o .: "slot") decodeTimeStart o = mkTimeStart @era . SlotNo <$> (o .: "slot") +decodeDijkstraNativeScript :: + Json.Value -> + Json.Parser (Ledger.NativeScript DijkstraEra) +decodeDijkstraNativeScript value = + Json.withObject + "Script" + ( \o -> do + clause <- o .: "clause" + case clause :: Text of + "guard" -> do + from <- o .: "from" >>= decodeStakingCredential decodeAsScriptHash + pure (Ledger.Dijkstra.RequireGuard (coerceKeyRole from)) + _ -> + decodeNativeScriptWith decodeDijkstraNativeScript value + ) + value + decodeTip :: Json.Value -> Json.Parser (Tip (CardanoBlock crypto)) @@ -3039,7 +3075,7 @@ decodeTxOut :: Json.Value -> Json.Parser (MultiEraTxOut (CardanoBlock crypto)) decodeTxOut = Json.withObject "TxOut" $ \o -> do - decodeTxOutBabbage o <|> decodeTxOutConway o + decodeTxOutBabbage o <|> decodeTxOutConway o <|> decodeTxOutDijkstra o where decodeTxOutBabbage o = do address <- o .: "address" >>= decodeAddress @@ -3064,7 +3100,7 @@ decodeTxOut = Json.withObject "TxOut" $ \o -> do .:? "script" >>= maybe (pure SNothing) - (fmap SJust . decodeScript) + (fmap SJust . decodeScript decodeNativeScript) pure $ TxOutInBabbageEra $ Ledger.Babbage.BabbageTxOut address value datum script @@ -3091,10 +3127,37 @@ decodeTxOut = Json.withObject "TxOut" $ \o -> do .:? "script" >>= maybe (pure SNothing) - (fmap SJust . decodeScript) + (fmap SJust . decodeScript decodeNativeScript) pure $ TxOutInConwayEra $ Ledger.Babbage.BabbageTxOut address value datum script + decodeTxOutDijkstra o = do + address <- o .: "address" >>= decodeAddress + value <- o .: "value" >>= decodeValue + + datumHash <- o .:? "datumHash" + inlineDatum <- o .:? "datum" + datum <- case (datumHash, inlineDatum) of + (Nothing, Nothing) -> + pure Ledger.Plutus.NoDatum + (Just Json.Null, Just Json.Null) -> + pure Ledger.Plutus.NoDatum + (Just x, Nothing) -> + Ledger.Plutus.DatumHash <$> decodeDatumHash x + (Nothing, Just x) -> + Ledger.Plutus.Datum <$> decodeBinaryData @DijkstraEra x + (Just{}, Just{}) -> + fail "specified both 'datumHash' & 'datum'" + + script <- + o + .:? "script" + >>= maybe + (pure SNothing) + (fmap SJust . decodeScript decodeDijkstraNativeScript) + + pure $ TxOutInDijkstraEra $ Ledger.Babbage.BabbageTxOut address value datum script + decodeUtxo :: forall block. () => @@ -3104,6 +3167,7 @@ decodeUtxo v = do xs <- Json.parseJSONList v (UTxOInBabbageEra . Sh.UTxO . Map.fromList <$> traverse decodeBabbageUtxoEntry xs) <|> (UTxOInConwayEra . Sh.UTxO . Map.fromList <$> traverse decodeConwayUtxoEntry xs) + <|> (UTxOInDijkstraEra . Sh.UTxO . Map.fromList <$> traverse decodeDijkstraUtxoEntry xs) where decodeBabbageUtxoEntry :: Json.Value -> @@ -3114,6 +3178,7 @@ decodeUtxo v = do <*> ( decodeTxOut o >>= \case TxOutInBabbageEra o' -> pure o' TxOutInConwayEra{} -> empty + TxOutInDijkstraEra{} -> empty ) decodeConwayUtxoEntry :: @@ -3125,6 +3190,19 @@ decodeUtxo v = do <*> ( decodeTxOut o >>= \case TxOutInBabbageEra o' -> pure (upgrade o') TxOutInConwayEra o' -> pure o' + TxOutInDijkstraEra{} -> empty + ) + + decodeDijkstraUtxoEntry :: + Json.Value -> + Json.Parser (Ledger.TxIn, Ledger.Babbage.BabbageTxOut DijkstraEra) + decodeDijkstraUtxoEntry o = + (,) + <$> decodeTxIn o + <*> ( decodeTxOut o >>= \case + TxOutInBabbageEra o' -> pure (upgrade (upgrade o')) + TxOutInConwayEra o' -> pure (upgrade o') + TxOutInDijkstraEra o' -> pure o' ) decodeValue :: diff --git a/server/src/Ogmios/Data/Protocol/TxSubmission.hs b/server/src/Ogmios/Data/Protocol/TxSubmission.hs index 7b411f9e8..54c81cb1b 100644 --- a/server/src/Ogmios/Data/Protocol/TxSubmission.hs +++ b/server/src/Ogmios/Data/Protocol/TxSubmission.hs @@ -498,7 +498,7 @@ utxoFromMempool = go ( utxo & withoutKeys (inputs tx) - & union (outputs tx) + & mergeUtxo (outputs tx) ) txs @@ -511,23 +511,6 @@ utxoFromMempool = UTxOInDijkstraEra (UTxO utxo) -> UTxOInDijkstraEra (UTxO (Map.withoutKeys utxo ks)) - union :: MultiEraUTxO block -> MultiEraUTxO block -> MultiEraUTxO block - union l r = case (l, r) of - (UTxOInBabbageEra (UTxO ul), UTxOInBabbageEra (UTxO ur)) -> - UTxOInBabbageEra (UTxO (Map.union ul ur)) - (UTxOInBabbageEra (upgrade -> (UTxO ul)), UTxOInConwayEra (UTxO ur)) -> - UTxOInConwayEra (UTxO (Map.union ul ur)) - (UTxOInConwayEra (UTxO ul), UTxOInBabbageEra (upgrade -> (UTxO ur))) -> - UTxOInConwayEra (UTxO (Map.union ul ur)) - (UTxOInConwayEra (UTxO ul), UTxOInConwayEra (UTxO ur)) -> - UTxOInConwayEra (UTxO (Map.union ul ur)) - (UTxOInDijkstraEra (UTxO ul), UTxOInDijkstraEra (UTxO ur)) -> - UTxOInDijkstraEra (UTxO (Map.union ul ur)) - (_, UTxOInDijkstraEra (UTxO ur)) -> - UTxOInDijkstraEra (UTxO ur) - (UTxOInDijkstraEra (UTxO ul), _) -> - UTxOInDijkstraEra (UTxO ul) - newUtxoFor :: TxId -> [out] -> Map TxIn out newUtxoFor h outs = Map.fromList [(TxIn h ix, out) | (out, ix) <- zip outs [minBound ..]] @@ -594,10 +577,14 @@ mergeUtxo a b = case (a, b) of UTxOInConwayEra $ UTxO (Map.union l r) (UTxOInDijkstraEra (unUTxO -> l), UTxOInDijkstraEra (unUTxO -> r)) -> UTxOInDijkstraEra $ UTxO (Map.union l r) - (_, UTxOInDijkstraEra (unUTxO -> r)) -> - UTxOInDijkstraEra $ UTxO r - (UTxOInDijkstraEra (unUTxO -> l), _) -> - UTxOInDijkstraEra $ UTxO l + (UTxOInBabbageEra (unUTxO -> l), UTxOInDijkstraEra (unUTxO -> r)) -> + UTxOInDijkstraEra $ UTxO (Map.union (upgrade . upgrade <$> l) r) + (UTxOInDijkstraEra (unUTxO -> l), UTxOInBabbageEra (unUTxO -> r)) -> + UTxOInDijkstraEra $ UTxO (Map.union l (upgrade . upgrade <$> r)) + (UTxOInConwayEra (unUTxO -> l), UTxOInDijkstraEra (unUTxO -> r)) -> + UTxOInDijkstraEra $ UTxO (Map.union (upgrade <$> l) r) + (UTxOInDijkstraEra (unUTxO -> l), UTxOInConwayEra (unUTxO -> r)) -> + UTxOInDijkstraEra $ UTxO (Map.union l (upgrade <$> r)) utxoReferences :: MultiEraUTxO (CardanoBlock crypto) -> [Text] utxoReferences = diff --git a/server/test/golden/Utxo_5.json b/server/test/golden/Utxo_5.json new file mode 100644 index 000000000..81f8440f0 --- /dev/null +++ b/server/test/golden/Utxo_5.json @@ -0,0 +1,99 @@ +[ + { + "transaction": { + "id": "e7eabf0367fe570e5723079b06c3a6623b205909162058103e5a74e3b518aad0" + }, + "index": 0, + "address": "addr_test1wqag3rt979nep9g2wtdwu8mr4gz6m4kjdpp5zp705km8wys6t2kla", + "value": { "ada": { "lovelace": 1094740 } } + }, + { + "transaction": { + "id": "e7eabf0367fe570e5723079b06c3a6623b205909162058103e5a74e3b518aad0" + }, + "index": 1, + "address": "addr_test1wqag3rt979nep9g2wtdwu8mr4gz6m4kjdpp5zp705km8wys6t2kla", + "value": { "ada": { "lovelace": 1094740 } }, + "script": { + "language": "native", + "json": { + "clause": "guard", + "from": "7616bc21e09658365ae3410c7ee0cca1e058a2264d9037bb079ed535" + } + } + }, + { + "transaction": { + "id": "e7eabf0367fe570e5723079b06c3a6623b205909162058103e5a74e3b518aad0" + }, + "index": 2, + "address": "addr_test1wqag3rt979nep9g2wtdwu8mr4gz6m4kjdpp5zp705km8wys6t2kla", + "value": { "ada": { "lovelace": 1094740 } }, + "script": { + "language": "native", + "json": { + "clause": "all", + "from": [ + { + "clause": "guard", + "from": "7616bc21e09658365ae3410c7ee0cca1e058a2264d9037bb079ed535" + } + ] + } + } + }, + { + "transaction": { + "id": "e7eabf0367fe570e5723079b06c3a6623b205909162058103e5a74e3b518aad0" + }, + "index": 3, + "address": "addr_test1wqag3rt979nep9g2wtdwu8mr4gz6m4kjdpp5zp705km8wys6t2kla", + "value": { "ada": { "lovelace": 1094740 } }, + "script": { + "language": "native", + "json": { + "clause": "any", + "from": [ + { + "clause": "signature", + "from": "3c07030e36bfffe67e2e2ec09e5293d384637cd2f004356ef320f3fe" + }, + { + "clause": "guard", + "from": "7616bc21e09658365ae3410c7ee0cca1e058a2264d9037bb079ed535" + } + ] + } + } + }, + { + "transaction": { + "id": "e7eabf0367fe570e5723079b06c3a6623b205909162058103e5a74e3b518aad0" + }, + "index": 4, + "address": "addr_test1wqag3rt979nep9g2wtdwu8mr4gz6m4kjdpp5zp705km8wys6t2kla", + "value": { "ada": { "lovelace": 1094740 } }, + "script": { + "language": "native", + "json": { + "clause": "some", + "atLeast": 1, + "from": [ + { + "clause": "signature", + "from": "3c07030e36bfffe67e2e2ec09e5293d384637cd2f004356ef320f3fe" + }, + { + "clause": "all", + "from": [ + { + "clause": "guard", + "from": "7616bc21e09658365ae3410c7ee0cca1e058a2264d9037bb079ed535" + } + ] + } + ] + } + } + } +] diff --git a/server/test/golden/Utxo_6.json b/server/test/golden/Utxo_6.json new file mode 100644 index 000000000..9261906aa --- /dev/null +++ b/server/test/golden/Utxo_6.json @@ -0,0 +1,11 @@ +[ + { + "transaction": { + "id": "e7eabf0367fe570e5723079b06c3a6623b205909162058103e5a74e3b518aad0" + }, + "index": 0, + "address": "addr_test1wqag3rt979nep9g2wtdwu8mr4gz6m4kjdpp5zp705km8wys6t2kla", + "value": { "ada": { "lovelace": 1094740 } }, + "script": { "language": "plutus:v4", "cbor": "450101002499" } + } +] diff --git a/server/test/unit/Ogmios/App/Protocol/TxSubmissionSpec.hs b/server/test/unit/Ogmios/App/Protocol/TxSubmissionSpec.hs index 561b5a582..a07c9a93e 100644 --- a/server/test/unit/Ogmios/App/Protocol/TxSubmissionSpec.hs +++ b/server/test/unit/Ogmios/App/Protocol/TxSubmissionSpec.hs @@ -19,16 +19,34 @@ import Ogmios.App.Protocol.TxSubmission ( SomeEvaluationInAnyEra (..) , newEvaluateTransactionResponse ) +import Ogmios.Data.EraTranslation + ( MultiEraUTxO (..) + , Upgrade (..) + ) import Ogmios.Data.Ledger.ScriptFailure ( EvaluateTransactionError (..) ) import Cardano.Ledger.Core ( TopTx + , inputsTxBodyL + , mkBasicTx + , mkBasicTxBody + , outputsTxBodyL + , txIdTx ) import Ogmios.Data.Protocol.TxSubmission ( Tx - , TxIn + , TxIn (..) , UTxO (..) + , mergeUtxo + , utxoFromMempool + ) +import Ouroboros.Consensus.Cardano.Block + ( CardanoBlock + , GenTx (..) + ) +import Ouroboros.Consensus.Shelley.Ledger.Mempool + ( mkShelleyTx ) import Ogmios.Prelude hiding ( Era @@ -50,15 +68,18 @@ import Test.QuickCheck ( Arbitrary (..) , Property , conjoin + , counterexample , cover , forAllBlind , forAllShrinkBlind + , listOf1 , suchThat , (===) , (==>) ) import qualified Data.Map as Map +import qualified Data.Set as Set type Tx' = Tx TopTx BabbageEra type TxOut' = BabbageTxOut BabbageEra @@ -70,6 +91,13 @@ spec = parallel $ do prop "succeeds when fully identical" prop_coherent_intersection prop "fails on ambiguous intersection" prop_ambiguous_intersection + context "mergeUtxo" $ do + prop "keeps both sides when the eras differ" prop_merge_across_eras + prop "keeps the first argument on a shared key, upgraded" prop_merge_first_wins_across_eras + + context "utxoFromMempool" $ do + prop "keeps earlier outputs when a Dijkstra transaction follows a Conway one" prop_mempool_across_eras + prop_merge :: Property prop_merge = forAllShrinkBlind genUtxoBabbage shrinkUtxo $ \(UTxO utxoNetwork) -> @@ -130,3 +158,75 @@ prop_ambiguous_intersection = ) (UTxO utxoNetwork) (SomeEvaluationInAnyEra (UTxO utxoUser) tx) + +prop_merge_across_eras :: Property +prop_merge_across_eras = + forAllBlind (arbitrary @(UTxO BabbageEra)) $ \babbage -> + forAllBlind (arbitrary @(UTxO ConwayEra)) $ \conway -> + forAllBlind (arbitrary @(UTxO DijkstraEra)) $ \dijkstra -> + conjoin + [ dijkstraKeys (mergeUtxo a b) === Just (keys a <> keys b) + | older <- [UTxOInBabbageEra babbage, UTxOInConwayEra conway] + , (a, b) <- [(older, UTxOInDijkstraEra dijkstra), (UTxOInDijkstraEra dijkstra, older)] + ] + where + keys :: MultiEraUTxO () -> Set TxIn + keys = \case + UTxOInBabbageEra (UTxO u) -> Map.keysSet u + UTxOInConwayEra (UTxO u) -> Map.keysSet u + UTxOInDijkstraEra (UTxO u) -> Map.keysSet u + + dijkstraKeys :: MultiEraUTxO () -> Maybe (Set TxIn) + dijkstraKeys = \case + UTxOInDijkstraEra (UTxO u) -> Just (Map.keysSet u) + _ -> Nothing + +prop_merge_first_wins_across_eras :: Property +prop_merge_first_wins_across_eras = + forAllBlind arbitrary $ \txIn -> + forAllBlind (arbitrary @(BabbageTxOut BabbageEra)) $ \babbageOut -> + forAllBlind (arbitrary @(BabbageTxOut ConwayEra)) $ \conwayOut -> + forAllBlind (arbitrary @(BabbageTxOut DijkstraEra)) $ \dijkstraOut -> + let babbage = UTxOInBabbageEra (UTxO (Map.singleton txIn babbageOut)) + conway = UTxOInConwayEra (UTxO (Map.singleton txIn conwayOut)) + dijkstra = UTxOInDijkstraEra (UTxO (Map.singleton txIn dijkstraOut)) + in conjoin + [ lookupDijkstra txIn (mergeUtxo babbage dijkstra) === Just (upgrade (upgrade babbageOut)) + , lookupDijkstra txIn (mergeUtxo dijkstra babbage) === Just dijkstraOut + , lookupDijkstra txIn (mergeUtxo conway dijkstra) === Just (upgrade conwayOut) + , lookupDijkstra txIn (mergeUtxo dijkstra conway) === Just dijkstraOut + ] + where + lookupDijkstra :: TxIn -> MultiEraUTxO () -> Maybe (BabbageTxOut DijkstraEra) + lookupDijkstra k = \case + UTxOInDijkstraEra (UTxO u) -> Map.lookup k u + _ -> Nothing + +prop_mempool_across_eras :: Property +prop_mempool_across_eras = + forAllBlind (listOf1 (arbitrary @(BabbageTxOut ConwayEra))) $ \conwayOuts -> + forAllBlind (arbitrary @(BabbageTxOut DijkstraEra)) $ \dijkstraOut -> + let conwayTx :: Tx TopTx ConwayEra + conwayTx = mkBasicTx (mkBasicTxBody & outputsTxBodyL .~ fromList conwayOuts) + + spent :: TxIn + spent = TxIn (txIdTx conwayTx) minBound + + dijkstraTx :: Tx TopTx DijkstraEra + dijkstraTx = mkBasicTx $ mkBasicTxBody + & inputsTxBodyL .~ Set.singleton spent + & outputsTxBodyL .~ fromList [dijkstraOut] + + mempool :: [GenTx (CardanoBlock StandardCrypto)] + mempool = [GenTxConway (mkShelleyTx conwayTx), GenTxDijkstra (mkShelleyTx dijkstraTx)] + + expected :: Map TxIn (BabbageTxOut DijkstraEra) + expected = Map.fromList $ + [ (TxIn (txIdTx conwayTx) ix, upgrade out) + | (ix, out) <- zip [minBound ..] conwayOuts + , ix /= minBound + ] + <> [ (TxIn (txIdTx dijkstraTx) minBound, dijkstraOut) ] + in case utxoFromMempool mempool of + UTxOInDijkstraEra (UTxO u) -> u === expected + _ -> counterexample "expected a Dijkstra UTxO" False diff --git a/server/test/unit/Ogmios/Data/JsonSpec.hs b/server/test/unit/Ogmios/Data/JsonSpec.hs index 07c2a711d..81384f6cf 100644 --- a/server/test/unit/Ogmios/Data/JsonSpec.hs +++ b/server/test/unit/Ogmios/Data/JsonSpec.hs @@ -107,6 +107,7 @@ import Ogmios.Data.Json.Prelude ( import Ogmios.Data.Json.Query ( QueryInEra, SomeQuery (..), + decodeNativeScript, parseQueryLedgerConstitution, parseQueryLedgerConstitutionalCommittee, parseQueryLedgerDelegateRepresentatives, @@ -192,6 +193,7 @@ import Ogmios.Data.Protocol.TxSubmission ( EvaluateTransactionResponse, SubmitTransaction, SubmitTransactionResponse (..), + UTxO (..), _encodeEvaluateTransactionResponse, _encodeSubmitTransactionResponse, ) @@ -483,9 +485,29 @@ spec = do Json.Success UTxOInDijkstraEra{} -> fail "successfully decoded an invalid payload (as Dijkstra Utxo)?" + specify "Golden: Utxo_5.json" $ do + json <- decodeFileThrow "Utxo_5.json" + case Json.parse decodeUtxo json of + Json.Error e -> + fail (show e) + Json.Success (UTxOInDijkstraEra (UTxO utxo)) -> + Map.size utxo `shouldBe` 5 + Json.Success _ -> + fail "decoded a Utxo with a guard script in an era before Dijkstra?" + + specify "Golden: Utxo_6.json" $ do + json <- decodeFileThrow "Utxo_6.json" + case Json.parse decodeUtxo json of + Json.Error e -> + fail (show e) + Json.Success (UTxOInDijkstraEra (UTxO utxo)) -> + Map.size utxo `shouldBe` 1 + Json.Success _ -> + fail "decoded a Utxo with a plutus:v4 script in an era before Dijkstra?" + specify "Golden: Script_Native_0.json" $ do json <- decodeFileThrow "Script_Native_0.json" - case traverse @[] (Json.parse (decodeScript @BabbageEra)) json of + case traverse @[] (Json.parse (decodeScript @BabbageEra decodeNativeScript)) json of Json.Error e -> fail (show e) Json.Success{} ->