diff --git a/cardano-api/internal/Cardano/Api/Governance/Actions/MetadataValidation.hs b/cardano-api/internal/Cardano/Api/Governance/Actions/MetadataValidation.hs index 83c74623c..c4cd442c5 100644 --- a/cardano-api/internal/Cardano/Api/Governance/Actions/MetadataValidation.hs +++ b/cardano-api/internal/Cardano/Api/Governance/Actions/MetadataValidation.hs @@ -11,6 +11,7 @@ import Data.ByteString (ByteString) import Data.Either.Combinators (mapRight) import Data.Text (Text) import GHC.Generics (Generic) +import Cardano.Api.GeneralParsers (textWithMaxLength) validateGovActionAnchorData :: ByteString -> Either String () validateGovActionAnchorData bytes = mapRight (const ()) (eitherDecodeStrict bytes :: Either String CIP108Common) @@ -98,8 +99,8 @@ instance FromJSON Body where parseJSON :: Value -> Parser Body parseJSON = withObject "Body" $ \v -> Body - <$> v .: "title" - <*> v .: "abstract" + <$> (v .: "title" >>= textWithMaxLength "title" 80) + <*> (v .: "abstract" >>= textWithMaxLength "abstract" 2500) <*> v .: "motivation" <*> v .: "rationale" <*> v .:? "references" diff --git a/cardano-api/test/cardano-api-test/Test/Cardano/Api/GovAnchorValidation.hs b/cardano-api/test/cardano-api-test/Test/Cardano/Api/GovAnchorValidation.hs index 4a7f7333b..a396ddedf 100644 --- a/cardano-api/test/cardano-api-test/Test/Cardano/Api/GovAnchorValidation.hs +++ b/cardano-api/test/cardano-api-test/Test/Cardano/Api/GovAnchorValidation.hs @@ -43,6 +43,9 @@ tests = , testProperty "Positive smoke test for treasury withdrawal anchor data JSON schema" prop_positive_smoke_test_threasury_withdrawal_anchor_data_json_schema + , testProperty + "Title name too long smoke test for treasury withdrawal anchor data JSON schema" + prop_title_name_too_long_smoke_test_threasury_withdrawal_anchor_data_json_schema ] prop_positive_smoke_test_drep_registration_anchor_data_json_schema :: Property @@ -95,3 +98,14 @@ prop_positive_smoke_test_threasury_withdrawal_anchor_data_json_schema = property ) value <- H.evalEither eitherValue validateGovActionAnchorData value === Right () + +prop_title_name_too_long_smoke_test_threasury_withdrawal_anchor_data_json_schema :: Property +prop_title_name_too_long_smoke_test_threasury_withdrawal_anchor_data_json_schema = propertyOnce $ do + (eitherValue :: Either (FileError Any) ByteString) <- + readByteStringFile + ( File "test/cardano-api-test/files/input/gov-anchor-data/too-long-title-treasury-withdraw.jsonld" + :: File DRepMetadata In + ) + value <- H.evalEither eitherValue + validateGovActionAnchorData value + === Left "Error in $.body: key \"title\" exceeds maximum length of 80 characters. Got length: 112" diff --git a/cardano-api/test/cardano-api-test/files/input/gov-anchor-data/too-long-title-treasury-withdraw.jsonld b/cardano-api/test/cardano-api-test/files/input/gov-anchor-data/too-long-title-treasury-withdraw.jsonld new file mode 100644 index 000000000..46e49bf3c --- /dev/null +++ b/cardano-api/test/cardano-api-test/files/input/gov-anchor-data/too-long-title-treasury-withdraw.jsonld @@ -0,0 +1,66 @@ +{ + "@context": { + "@language": "en-us", + "CIP100": "https://github.com/cardano-foundation/CIPs/blob/master/CIP-0100/README.md#", + "CIP108": "https://github.com/cardano-foundation/CIPs/blob/master/CIP-0108/README.md#", + "hashAlgorithm": "CIP100:hashAlgorithm", + "body": { + "@id": "CIP108:body", + "@context": { + "references": { + "@id": "CIP108:references", + "@container": "@set", + "@context": { + "GovernanceMetadata": "CIP100:GovernanceMetadataReference", + "Other": "CIP100:OtherReference", + "label": "CIP100:reference-label", + "uri": "CIP100:reference-uri", + "referenceHash": { + "@id": "CIP108:referenceHash", + "@context": { + "hashDigest": "CIP108:hashDigest", + "hashAlgorithm": "CIP100:hashAlgorithm" + } + } + } + }, + "title": "CIP108:title", + "abstract": "CIP108:abstract", + "motivation": "CIP108:motivation", + "rationale": "CIP108:rationale" + } + }, + "authors": { + "@id": "CIP100:authors", + "@container": "@set", + "@context": { + "name": "http://xmlns.com/foaf/0.1/name", + "witness": { + "@id": "CIP100:witness", + "@context": { + "witnessAlgorithm": "CIP100:witnessAlgorithm", + "publicKey": "CIP100:publicKey", + "signature": "CIP100:signature" + } + } + } + } + }, + "hashAlgorithm": "blake2b-256", + "body": { + "title": "Buy Ryan an island that is sunny and full of palm trees and has a lot of sand and is quiet yet not too far away.", + "abstract": "Withdraw 200000000000 ADA from the treasury so Ryan can buy an island.", + "motivation": "The current problem is that Ryan does not have an island, but he would really like an island.", + "rationale": "With these funds from the treasury will be sold for **cold hard cash**, this cash can then be used to purchase an island for Ryan. An example of this island is provided in the references." + }, + "authors": [ + { + "name": "Ryan Williams", + "witness": { + "witnessAlgorithm": "ed25519", + "publicKey": "7ea09a34aebb13c9841c71397b1cabfec5ddf950405293dee496cac2f437480a", + "signature": "a476985b4cc0d457f247797611799a6f6a80fc8cb7ec9dcb5a8223888d0618e30de165f3d869c4a0d9107d8a5b612ad7c5e42441907f5b91796f0d7187d64a01" + } + } + ] + } \ No newline at end of file