Skip to content

Commit

Permalink
Merge pull request #5188 from input-output-hk/newhoggy/golden-tests-f…
Browse files Browse the repository at this point in the history
…or-errors

Golden tests for `cardano-api` errors
  • Loading branch information
newhoggy authored May 9, 2023
2 parents a245e2b + c6429f3 commit 9507125
Show file tree
Hide file tree
Showing 100 changed files with 478 additions and 22 deletions.
2 changes: 1 addition & 1 deletion cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repository cardano-haskell-packages
-- See CONTRIBUTING for information about these, including some Nix commands
-- you need to run if you change them
index-state:
, hackage.haskell.org 2023-04-29T00:00:00Z
, hackage.haskell.org 2023-05-03T00:00:00Z
, cardano-haskell-packages 2023-04-30T00:28:07Z

packages:
Expand Down
11 changes: 11 additions & 0 deletions cardano-api/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog for cardano-api

## vNext


## 8.0.0 - May 2023

- Add `getSlotForRelativeTime` function ([PR 5130](https://github.com/input-output-hk/cardano-node/pull/5130))

### Features
Expand All @@ -16,6 +20,13 @@

- Expose envirnment construction functionality: `mkProtocolInfoCardano` and `genesisConfigToEnv`

- New error exports:
- `TxOutInAnyEra(..)`
- `txOutInAnyEra`
- `StakePoolMetadataValidationError(..)`
- `ScriptHash(..)`
([PR 5188](https://github.com/input-output-hk/cardano-node/pull/5188))

- Rename `TestEnableDevelopmentHardForkEras` to `ExperimentalHardForksEnabled` and
`TestEnableDevelopmentNetworkProtocols` to `ExperimentalProtocolsEnabled`
([PR 4341](https://github.com/input-output-hk/cardano-node/pull/4341))
Expand Down
31 changes: 30 additions & 1 deletion cardano-api/cardano-api.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ test-suite cardano-api-test
, cardano-slotting ^>= 0.1
, containers
, hedgehog
, hedgehog-extras ^>= 0.4.2
, hedgehog-extras ^>= 0.4.3
, hedgehog-quickcheck
, mtl
, microlens
Expand Down Expand Up @@ -258,3 +258,32 @@ test-suite cardano-api-test
Test.Cardano.Api.Typed.Value

ghc-options: -threaded -rtsopts -with-rtsopts=-N -with-rtsopts=-T

test-suite cardano-api-golden
import: project-config

hs-source-dirs: golden
main-is: cardano-api-golden.hs
type: exitcode-stdio-1.0

build-depends: aeson
, bech32 >= 1.1.0
, bytestring
, cardano-api
, cardano-binary
, cardano-crypto-class
, cardano-ledger-alonzo
, containers
, hedgehog-extras >= 0.4.3.0
, hspec
, hw-hspec-hedgehog
, plutus-core ^>= 1.1
, plutus-ledger-api ^>= 1.1
, text

ghc-options: -threaded -rtsopts -with-rtsopts=-N -with-rtsopts=-T

build-tool-depends: hspec-discover:hspec-discover

other-modules: Test.Golden.ErrorsSpec

297 changes: 297 additions & 0 deletions cardano-api/golden/Test/Golden/ErrorsSpec.hs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions cardano-api/golden/cardano-api-golden.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{-# OPTIONS_GHC -F -pgmF hspec-discover #-}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
There was an error in extracting the bytes from the data part of the Bech32-encoded string.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
StringToDecodeTooLong
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
There was an error in deserialising the data part of the Bech32-encoded string into a value of the expected type.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Unexpected Bech32 prefix: the actual prefix is "<text>", but it was expected to be "<text>"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Mismatch in the Bech32 prefix: the actual prefix is "<text>", but the prefix for this payload value should be "<text>"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Mismatch in the Bech32 prefix: the actual prefix is "<text>", but the prefix for this payload value should be "<text>"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Invalid key.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TextEnvelope aeson decode error: <string>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Invalid cost model: applyParams error: Internal problem occurred upon generating the applied cost model parameters with JSON error: <string> Cost model: CostModel [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<string>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Candidate nonce is still evolving
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Failed to successfully decode ledger state
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Failed to successfully decode the current epoch state: DecoderErrorVoid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Failed to successfully decode protocol state: Attempted to decode Void
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Leadership schedule currently cannot be calculated from genesis
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Error while calculating the slot range: <text>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
The current stake distribution is currently unstable and therefore we cannot predict the following epoch's leadership schedule. Please wait until : SlotNo 2 before running the leadership-schedule command again.
Current slot: SlotNo 1
Stability window: SlotNo 3
Calculated last slot of current epoch: SlotNo 4
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The stake pool: "9e734b6c2263c0917bfc550e9c949f41afa3fe000377243bd29df399" has no stake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Key mismatch: the signing key does not match the one that goes with the counter
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The Alonzo era protocol parameters in use is missing one or more of the following fields: UTxOCostPerWord, CostModels, Prices, MaxTxExUnits, MaxBlockExUnits, MaxValueSize, CollateralPercent, MaxCollateralInputs. Did you intend to use an Alonzo era protocol parameters value?
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The ConwayEra protocol parameters value is missing the following field: MinUTxoValue. Did you intend to use a ConwayEra protocol parameters value?
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Expected Base16-encoded bytestring, but got <bytestring>; <string>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Failed to deserialise <bytestring> as VerificationKey GenesisKey. <string>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ScriptData is invalid: Constructor numbers in script data value 0 is outside the range 0 .. 2^64-1.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Error decoding ScriptData JSON value: JSON schema error within the script data: null
JSON null values are not supported.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
JSON schema error within the script data: "<JSON>"
JSON null values are not supported.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Value out of range within the script data: "<JSON>"
Constructor numbers in script data value 1 is outside the range 0 .. 2^64-1.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Expected a list of key/value pair { "k": ..., "v": ... } objects.
Unexpected value: "<JSON>"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
JSON object does not match the schema.
Expected a single field named "int", "bytes", "list" or "map".
Unexpected object field(s): {"<text>":"<JSON>"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
JSON bool values are not supported.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
JSON object expected. Unexpected value: "<JSON>"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
JSON null values are not supported.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
JSON numbers must be integers. Unexpected value: 0.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
JSON schema error within the script data: null
JSON null values are not supported.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The value in the field "<text>" does not have the type required by the schema.
Unexpected value: "<JSON>"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Constructor numbers in script data value 1 is outside the range 0 .. 2^64-1.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
The Plutus script evaluation failed: Cost model parameters were not as we expected
Script debugging logs: <text>
<text>
<text>
<text>
<text>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The execution units required by this Plutus script overflows a 64bit word. In a properly configured chain this should be practically impossible. So this probably indicates a chain configuration problem, perhaps with the values in the cost model.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
No cost model was found for language PlutusV2
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The redeemer pointer: RdmrPtr Mint 0 points to a Plutus script that does not exist.
The pointers that can be resolved are: fromList []
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The supplied UTxO is missing the txin 210c0a4bb6391baf606843e67863d1474cc462374ab12c42d55f78a0b55b56e0#1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
transaction input 0 (in the order of the TxIds) is not a Plutus script witnessed tx input and cannot be spent using a Plutus script witness.The script hash is "a0d442ce189bc932515c85be74ac939df19ea8450c03030234790921".
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
transaction input 0 (in the order of the TxIds) points to a script hash that is not known.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The Plutus script witness for the txin does not have a script datum (according to the UTxO). The txin in question is 210c0a4bb6391baf606843e67863d1474cc462374ab12c42d55f78a0b55b56e0#1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The Plutus script witness has the wrong datum (according to the UTxO). The expected datum value has hash "ee155ace9c40292074cb6aff8c9ccdd273c81648ff1149ef36bcea6ebb8a3e25"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Stake pool metadata must consist of at most 0 bytes, but it consists of 1 bytes.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<string>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Could not JSON decode TextEnvelopeCddl file at: <string> Error: <string>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TextEnvelopeCddl error: Byron key witnesses are currently unsupported.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TextEnvelopeCDDL CBOR decoding error: DecoderErrorVoid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Unknown TextEnvelopeCddl type: <text>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TextEnvelopeCddl type error: Expected one of: <text> Actual: <text>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Unknown key witness specified
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TextEnvelope aeson decode error: <string>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TextEnvelope decode error: DecoderErrorVoid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TextEnvelope type error: Expected one of: <string>, <string> Actual: <string>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
An error occurred while converting from the cardano-api cost models to the cardano-ledger cost models. Error: <string> Cost models: fromList [(AnyPlutusScriptVersion PlutusScriptV2,CostModel [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42])]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Error translating the transaction context: TimeTranslationPastHorizon "<text>"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Transaction body has no inputs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Transaction body has no collateral inputs, but uses Plutus scripts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Transaction body has no outputs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Transaction input index is too big, acceptable value is up to 2^32-1, in input TxIn "210c0a4bb6391baf606843e67863d1474cc462374ab12c42d55f78a0b55b56e0" (TxIx 1)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Error in metadata entry 1: Byte string metadata value must consist of at most 64 bytes, but it consists of 2 bytes.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Transaction cannot mint ada, only non-ada assets
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Transaction uses Plutus scripts but does not provide the protocol parameters to hash
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Negative quantity (1) in transaction output: TxOutInAnyEra AllegraEra (TxOut (AddressInEra (ShelleyAddressInEra ShelleyBasedEraAllegra) (ShelleyAddress Mainnet (KeyHashObj (KeyHash "250ca83514191f9ceaccee2eb3276d5ad964e17cc31a067691e04ca8")) StakeRefNull)) (TxOutAdaOnly AdaOnlyInAllegraEra (Lovelace 1)) TxOutDatumNone ReferenceScriptNone)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Quantity too large (1 >= 2^64) in transaction output: TxOutInAnyEra AllegraEra (TxOut (AddressInEra (ShelleyAddressInEra ShelleyBasedEraAllegra) (ShelleyAddress Mainnet (KeyHashObj (KeyHash "250ca83514191f9ceaccee2eb3276d5ad964e17cc31a067691e04ca8")) StakeRefNull)) (TxOutAdaOnly AdaOnlyInAllegraEra (Lovelace 1)) TxOutDatumNone ReferenceScriptNone)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Transaction body has no inputs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The transaction does not balance in its use of ada. The net balance of the transaction is negative: Lovelace 1 lovelace. The usual solution is to provide more inputs, or inputs with more ada.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
The transaction does balance in its use of ada, however the net balance does not meet the minimum UTxO threshold.
Balance: Lovelace 1
Offending output (change output): addr1vyjse2p4zsv3l882enhzave8d4ddje8p0np35pnkj8sye2qu9km4v + 1 lovelace
Minimum UTxO threshold: Lovelace 0
The usual solution is to provide more inputs, or inputs with more ada to meet the minimum UTxO threshold
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The Byron era is not yet supported by makeTransactionBodyAutoBalance
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Minimum UTxO threshold not met for tx output: addr1vyjse2p4zsv3l882enhzave8d4ddje8p0np35pnkj8sye2qu9km4v + 1 lovelace
Minimum required UTxO: Lovelace 1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The minUTxOValue protocol parameter is required but missing
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Non-Ada assets are unbalanced: 1 lovelace
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ScriptWitnessIndex (redeemer pointer): ScriptWitnessIndexTxIn 1 is missing from the execution units (redeemer pointer) map: fromList [(ScriptWitnessIndexTxIn 2,ExecutionUnits {executionSteps = 1, executionMemory = 1})]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
An error occurred while converting from the cardano-api cost models to the cardano-ledger cost models. Error: <string> Cost models: fromList []
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
One or more of the scripts were expected to fail validation, but none did.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The following scripts have execution failures:
the script for transaction input 1 (in the order of the TxIds) failed with:
The execution units required by this Plutus script overflows a 64bit word. In a properly configured chain this should be practically impossible. So this probably indicates a chain configuration problem, perhaps with the values in the cost model.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
JSON schema error within the metadata item 0: "<JSON>"
JSON null values are not supported.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The JSON metadata top level must be a map (JSON object) with unsigned integer keys.
Invalid key: "<text>"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The JSON metadata top level must be a map (JSON object) from word to value.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Value out of range within the metadata item 0: "<JSON>"
Byte string metadata value must consist of at most 64 bytes, but it consists of 0 bytes.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Byte string metadata value must consist of at most 64 bytes, but it consists of 0 bytes.
9 changes: 6 additions & 3 deletions cardano-api/src/Cardano/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ module Cardano.Api (
CtxTx, CtxUTxO,
TxOut(TxOut),
TxOutValue(..),
TxOutInAnyEra(..),
txOutInAnyEra,
txOutValueToLovelace,
txOutValueToValue,
lovelaceToTxOutValue,
Expand Down Expand Up @@ -382,7 +384,7 @@ module Cardano.Api (
-- * Stake pool off-chain metadata
StakePoolMetadata,
validateAndHashStakePoolMetadata,
StakePoolMetadataValidationError,
StakePoolMetadataValidationError(..),

-- * Scripts
-- | Both 'PaymentCredential's and 'StakeCredential's can use scripts.
Expand Down Expand Up @@ -463,19 +465,20 @@ module Cardano.Api (
scriptDataToJson,
ScriptDataJsonError (..),
ScriptDataJsonSchemaError (..),
ScriptDataJsonBytesError,
ScriptDataJsonBytesError(..),
scriptDataJsonToHashable,

-- ** Script execution units
ExecutionUnits(..),
ExecutionUnitPrices(..),
CostModel(..),
InvalidCostModel(..),
toAlonzoCostModel,
fromAlonzoCostModel,

-- ** Script addresses
-- | Making addresses from scripts.
ScriptHash,
ScriptHash(..),
hashScript,

-- * Serialisation
Expand Down
Loading

0 comments on commit 9507125

Please sign in to comment.