Skip to content

Commit

Permalink
better Malformed
Browse files Browse the repository at this point in the history
  • Loading branch information
paweljakubas committed Oct 28, 2020
1 parent 326f728 commit 20862e6
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lib/core/src/Cardano/Wallet/Api/Types.hs
Expand Up @@ -1319,7 +1319,7 @@ instance ToJSON (ApiT (Passphrase purpose)) where
instance FromJSON ApiScript where
parseJSON = withObject "Script" $ \o -> do
script' <- o .: "script"
fmap (ApiScript . ApiT) $ parseJSON script'
(ApiScript . ApiT) <$> parseJSON script'
instance ToJSON ApiScript where
toJSON (ApiScript (ApiT script')) =
object ["script" .= toJSON script']
Expand Down
20 changes: 20 additions & 0 deletions lib/core/test/unit/Cardano/Wallet/Api/Malformed.hs
Expand Up @@ -267,6 +267,26 @@ instance Malformed (BodyParam ApiScript) where
}|]
, "Error in $: key 'script' not found"
)
, ( Aeson.encode [aesonQQ|
{ "script": {}
}|]
, "Error in $: key 'some' not found"
)
, ( Aeson.encode [aesonQQ|
{ "script": 2
}|]
, "Error in $: parsing Script SomeOf failed, expected Object, but encountered Number"
)
, ( Aeson.encode [aesonQQ|
{ "script": { "some" : 2 }
}|]
, "Error in $.some: parsing HashMap ~Text failed, expected Object, but encountered Number"
)
, ( Aeson.encode [aesonQQ|
{ "script": { "some" : { "something": 2, "at_least": 0 } }
}|]
, "Error in $: key 'from' not found"
)
]

instance Malformed (BodyParam SomeByronWalletPostData) where
Expand Down
3 changes: 0 additions & 3 deletions lib/core/test/unit/Cardano/Wallet/Api/TypesSpec.hs
Expand Up @@ -269,7 +269,6 @@ import Test.QuickCheck
( Arbitrary (..)
, Gen
, InfiniteList (..)
, Positive (..)
, applyArbitrary2
, applyArbitrary4
, arbitraryBoundedEnum
Expand All @@ -282,8 +281,6 @@ import Test.QuickCheck
, property
, scale
, shrinkIntegral
, sized
, suchThat
, vector
, vectorOf
, (.&&.)
Expand Down
43 changes: 32 additions & 11 deletions specifications/api/swagger.yaml
Expand Up @@ -335,14 +335,36 @@ x-walletCredentialPubkey: &walletCredentialPubkey

x-script: &script
description: |
Script allows to ..
Script allows establishing either spending or staking guard that could be removed
when a special combination of signing keys is present.
The script can be constructed using four primitives:
- verification key hash for which a corresponding signing key is expected
- all condition for which all list elements' expectation are met for the condition to be valid
- any condition for which any list element' expectation is to be met for the condition to be valid
- some condition for which a minimal number of list elements' expectation is to be met for the condition to be valid
example:
0: "script_vkh18srsxr3khll7vl3w9mqfu55n6wzxxlxj7qzr2mhnyreluzt36ms"
1: { "all": [ "script_vkh18srsxr3khll7vl3w9mqfu55n6wzxxlxj7qzr2mhnyreluzt36ms"
, "script_vkh18srsxr3khll7vl3w9mqfu55n6wzxxlxj7qzr2mhnyreluzt37ms"] }
2: { "all": [ "script_vkh18srsxr3khll7vl3w9mqfu55n6wzxxlxj7qzr2mhnyreluzt36ms"
, { "any" : [ "script_vkh18srsxr3khll7vl3w9mqfu55n6wzxxlxj7qzr2mhnyreluzt37ms"
, "script_vkh18srsxr3khll7vl3w9mqfu55n6wzxxlxj7qzr2mhnyreluzt38ms"] }
] }
3: { "all": [ "script_vkh18srsxr3khll7vl3w9mqfu55n6wzxxlxj7qzr2mhnyreluzt36ms"
, { "some" : { "from" : [ "script_vkh18srsxr3khll7vl3w9mqfu55n6wzxxlxj7qzr2mhnyreluzt37ms"
, "script_vkh18srsxr3khll7vl3w9mqfu55n6wzxxlxj7qzr2mhnyreluzt38ms"]
, "at_least" : 2
}
} ] }
nullable: false
additionalProperties:
$ref: "#/components/schemas/ScriptValue"

x-credential: &credential
description: |
Credential that could act in as spending or staking credential.
Credential that could act as either spending or staking credential.
Could be either public key or script.
oneOf:
- title: Key Credential
Expand Down Expand Up @@ -696,13 +718,6 @@ x-signedTransactionBlob: &signedTransactionBlob
type: string
format: binary

x-addressParts: &addressParts
description: Address credentials.
type: object
properties:
payment_credential: *credential
stake_credential: *credential

x-transactionStatus: &transactionStatus
description: |
Current transaction status.
Expand Down Expand Up @@ -1520,6 +1535,12 @@ components:
properties:
script: *script

ApiCredentials: &ApiCredentials
type: object
properties:
payment_credential: *credential
stake_credential: *credential

ApiByronWalletRandomPostData: &ApiByronWalletRandomPostData
type: object
required:
Expand Down Expand Up @@ -1712,7 +1733,7 @@ components:
- title: Require Key Hash
type: string
format: bech32
example: script_vkh1wqaz0q0zhtxlgn0ewssevn2mrtm30fgh2g7hr7z9rj5856457mm
example: script_vkh18srsxr3khll7vl3w9mqfu55n6wzxxlxj7qzr2mhnyreluzt36ms

- title: Require All
type: object
Expand Down Expand Up @@ -3291,7 +3312,7 @@ paths:
requestBody:
content:
application/json:
schema: *addressParts
schema: *ApiCredentials
responses: *responsesPostAddress

/settings:
Expand Down

0 comments on commit 20862e6

Please sign in to comment.