From 8b5d36d7022ef4ad334d2a3211c4a9a0390e6127 Mon Sep 17 00:00:00 2001 From: Pawel Jakubas Date: Fri, 13 Dec 2024 14:49:20 +0100 Subject: [PATCH] applying review remarks --- .../lib/Cardano/Wallet/Primitive/Types/DRep.hs | 2 +- .../test/unit/Cardano/Wallet/Api/Malformed.hs | 16 +++++++++++----- specifications/api/swagger.yaml | 7 +++---- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/lib/primitive/lib/Cardano/Wallet/Primitive/Types/DRep.hs b/lib/primitive/lib/Cardano/Wallet/Primitive/Types/DRep.hs index 15634e13d79..ca2118bd5c3 100644 --- a/lib/primitive/lib/Cardano/Wallet/Primitive/Types/DRep.hs +++ b/lib/primitive/lib/Cardano/Wallet/Primitive/Types/DRep.hs @@ -80,7 +80,7 @@ data DRepID = deriving (Eq, Generic, Show, Ord) deriving anyclass NFData --- | Encode 'DRepID' as Bech32 with "drep" hrp. +-- | Encode 'DRepID' as Bech32 with "drep" human readable prefix. encodeDRepIDBech32 :: DRepID -> Text encodeDRepIDBech32 drepid = Bech32.encodeLenient hrp diff --git a/lib/unit/test/unit/Cardano/Wallet/Api/Malformed.hs b/lib/unit/test/unit/Cardano/Wallet/Api/Malformed.hs index 3f5ba82d2c9..a059a4d12c6 100644 --- a/lib/unit/test/unit/Cardano/Wallet/Api/Malformed.hs +++ b/lib/unit/test/unit/Cardano/Wallet/Api/Malformed.hs @@ -215,9 +215,12 @@ instance Wellformed (PathParam ApiDRepSpecifier) where wellformed = PathParam <$> [ "abstain" , "no_confidence" - , "drep1ytje8qacj9dyua6esh86rdjqpdactf8wph05gdd72u46axcvy952y" --28-byte payload with key hash byte prefix ('22' in hex prefixed) - , "drep1y0je8qacj9dyua6esh86rdjqpdactf8wph05gdd72u46axcvk492r" --28-byte payload with script hash byte prefix ('23' in hex prefixed) + , payloadKeyHashWith22HexByte + , payloadScriptHashWith23HexByte ] + where + payloadKeyHashWith22HexByte = "drep1ytje8qacj9dyua6esh86rdjqpdactf8wph05gdd72u46axcvy952y" + payloadScriptHashWith23HexByte = "drep1y0je8qacj9dyua6esh86rdjqpdactf8wph05gdd72u46axcvk492r" instance Malformed (PathParam ApiDRepSpecifier) where malformed = first PathParam <$> @@ -226,13 +229,16 @@ instance Malformed (PathParam ApiDRepSpecifier) where , (T.replicate 65 "1", msg1) , ("something", msg1) , ("no-confidence", msg1) - , ("drep15k6929drl7xt0spvudgcxndryn4kmlzpk4meed0xhqe25nle07s",msg2) --28-byte payload without byte prefix correct hrp prefix - , ("drep1xhje8qacj9dyua6esh86rdjqpdactf8wph05gdd72u46axc9fjca3",msg2) --28-byte payload with wrong byte prefix but correct hrp prefix - , ("drepp1ytje8qacj9dyua6esh86rdjqpdactf8wph05gdd72u46axcp60l06",msg1) --28-byte payload with key hash byte prefix but wrong hrp prefix + , (payloadWithoutCorrectBytePrefixCorrectHrp, msg2) + , (payloadWithWrongBytePrefixCorrectHrp, msg2) + , (payloadWithCorrectBytePrefixWrondHrp, msg1) ] where msg1 = "Invalid DRep key hash: expecting a Bech32 encoded value with human readable part of 'drep'." msg2 = "Invalid DRep metadata: expecting a byte '00100010' value for key hash or a byte '0b00100011' value for script hash." + payloadWithoutCorrectBytePrefixCorrectHrp = "drep15k6929drl7xt0spvudgcxndryn4kmlzpk4meed0xhqe25nle07s" + payloadWithWrongBytePrefixCorrectHrp = "drep1xhje8qacj9dyua6esh86rdjqpdactf8wph05gdd72u46axc9fjca3" + payloadWithCorrectBytePrefixWrondHrp = "drepp1ytje8qacj9dyua6esh86rdjqpdactf8wph05gdd72u46axcp60l06" instance Wellformed (PathParam (ApiAddress ('Testnet 0))) where wellformed = [PathParam diff --git a/specifications/api/swagger.yaml b/specifications/api/swagger.yaml index 93bfd17cf3e..aeb27a75725 100644 --- a/specifications/api/swagger.yaml +++ b/specifications/api/swagger.yaml @@ -411,10 +411,9 @@ x-drepScriptHash: &drepScriptHash format: bech32 example: drep1wqaz0q0zhtxlgn0ewssevn2mrtm30fgh2g7hr7z9rj5856457mm description: | - DRep's script hash according to CIP-0129. Note this is identical - to drepKeyHash but for unknown reasons we need to different - schema fragments here. - pattern: "^(drep)1[0-9a-z]*$" + DRep's script hash according to CIP-0129 uses also 'drep' bech32 prefix. + This one is deprecated and should not be used. + pattern: "^(drep_script)1[0-9a-z]*$" x-walletAccountXPubkey: &walletAccountXPubkey description: An extended account public key (public key + chain code)