diff --git a/lib/core/src/Cardano/Wallet/Api/Types.hs b/lib/core/src/Cardano/Wallet/Api/Types.hs index ef49280715f..0aa8cc280b4 100644 --- a/lib/core/src/Cardano/Wallet/Api/Types.hs +++ b/lib/core/src/Cardano/Wallet/Api/Types.hs @@ -3483,11 +3483,11 @@ instance EncodeAddress n => ToJSON (ApiMintBurnOperation n) where instance DecodeAddress n => FromJSON (ApiMintBurnOperation n) where parseJSON = Aeson.withObject "ApiMintBurnOperation" $ \o -> - case HM.toList o of - [("mint", mint)] -> ApiMint <$> parseJSON mint - [("burn", burn)] -> ApiBurn <$> parseJSON burn - [] -> fail "Must include a mint or burn operation" - _ -> fail "Each operation may be either a \"mint\" or a \"burn\"." + case HM.keys o of + ["mint"] -> ApiMint <$> o .: "mint" + ["burn"] -> ApiBurn <$> o .: "burn" + [] -> fail "Must include a \"mint\" or \"burn\" property." + _ -> fail "May be either a \"mint\" or a \"burn\"." instance FromJSON ApiMintedBurnedInfo where parseJSON = genericParseJSON defaultRecordTypeOptions diff --git a/lib/core/test/unit/Cardano/Wallet/Api/Malformed.hs b/lib/core/test/unit/Cardano/Wallet/Api/Malformed.hs index 17cff0cedb7..3651ce64f14 100644 --- a/lib/core/test/unit/Cardano/Wallet/Api/Malformed.hs +++ b/lib/core/test/unit/Cardano/Wallet/Api/Malformed.hs @@ -2064,7 +2064,7 @@ instance Malformed (BodyParam (PostMintBurnAssetData ('Testnet pm))) where } } } - + }] , "passphrase": #{nameTooLong} }|] @@ -2091,7 +2091,7 @@ instance Malformed (BodyParam (PostMintBurnAssetData ('Testnet pm))) where } } } - + }] , "passphrase": #{nameTooLong} }|] @@ -2109,11 +2109,11 @@ instance Malformed (BodyParam (PostMintBurnAssetData ('Testnet pm))) where } } } - + }] , "passphrase": #{nameTooLong} }|] - , "Error in $['mint_burn'][0].operation: Each operation may either be a mint or a burn, not both" + , "Error in $['mint_burn'][0].operation: May be either a 'mint' or a 'burn'." ) , ( [aesonQQ| { "mint_burn": [{ "monetary_policy_index": "0" @@ -2126,6 +2126,15 @@ instance Malformed (BodyParam (PostMintBurnAssetData ('Testnet pm))) where }] , "passphrase": "" }|] - , "Error in $['mint_burn'][0].operation: Encountered unexpected key(s): ['something_else']" + , "Error in $['mint_burn'][0].operation: May be either a 'mint' or a 'burn'." + ) + , ( [aesonQQ| + { "mint_burn": [{ "monetary_policy_index": "0" + , "asset_name": "deadbeef" + , "operation": {} + }] + , "passphrase": "" + }|] + , "Error in $['mint_burn'][0].operation: Must include a 'mint' or 'burn' property." ) ]