Skip to content

Commit

Permalink
align core unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
paweljakubas committed Jun 8, 2021
1 parent b046b85 commit d3a139e
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 0 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions lib/core/test/unit/Cardano/Wallet/Api/Malformed.hs
Expand Up @@ -55,6 +55,7 @@ import Cardano.Wallet.Api.Types
, ApiMaintenanceActionPostData
, ApiPoolId
, ApiPostAccountKeyData
, ApiPostAccountKeyDataWithPurpose
, ApiPostRandomAddressData
, ApiPutAddressesData
, ApiSelectCoinsData
Expand Down Expand Up @@ -1127,6 +1128,48 @@ instance Malformed (BodyParam ApiPostAccountKeyData) where
)
]

instance Malformed (BodyParam ApiPostAccountKeyDataWithPurpose) where
malformed = jsonValid ++ jsonInvalid
where
jsonInvalid = first BodyParam <$>
[ ("1020344", "Error in $: parsing Cardano.Wallet.Api.Types.ApiPostAccountKeyDataWithPurpose(ApiPostAccountKeyDataWithPurpose) failed, expected Object, but encountered Number")
, ("\"1020344\"", "Error in $: parsing Cardano.Wallet.Api.Types.ApiPostAccountKeyDataWithPurpose(ApiPostAccountKeyDataWithPurpose) failed, expected Object, but encountered String")
, ("\"slot_number : \"random\"}", "trailing junk after valid JSON: endOfInput")
, ("{\"name : \"random\"}", msgJsonInvalid)
]
jsonValid = first (BodyParam . Aeson.encode) <$>
[ ( [aesonQQ| { "passphrase": #{nameTooLong}, "format": "extended" }|]
, "Error in $.passphrase: passphrase is too long: expected at most 255 characters"
)
, ( [aesonQQ| { "passphrase": 123, "format": "extended" }|]
, "Error in $.passphrase: parsing Passphrase failed, expected String, but encountered Number"
)
, ( [aesonQQ| { "passphrase": [], "format": "extended" }|]
, "Error in $.passphrase: parsing Passphrase failed, expected String, but encountered Array"
)
, ( [aesonQQ| { "passphrase": 1.5, "format": "extended" }|]
, "Error in $.passphrase: parsing Passphrase failed, expected String, but encountered Number"
)
, ( [aesonQQ| { "format": "extended" }|]
, "Error in $: parsing Cardano.Wallet.Api.Types.ApiPostAccountKeyDataWithPurpose(ApiPostAccountKeyDataWithPurpose) failed, key 'passphrase' not found"
)
, ( [aesonQQ| { "passphrase": "The proper passphrase" }|]
, "Error in $: parsing Cardano.Wallet.Api.Types.ApiPostAccountKeyDataWithPurpose(ApiPostAccountKeyDataWithPurpose) failed, key 'format' not found"
)
, ( [aesonQQ| { "passphrase": "The proper passphrase", "format": 123 }|]
, "Error in $.format: parsing Cardano.Wallet.Api.Types.KeyFormat failed, expected String, but encountered Number"
)
, ( [aesonQQ| { "passphrase": "The proper passphrase", "format": [] }|]
, "Error in $.format: parsing Cardano.Wallet.Api.Types.KeyFormat failed, expected String, but encountered Array"
)
, ( [aesonQQ| { "passphrase": "The proper passphrase", "format": 1.5 }|]
, "Error in $.format: parsing Cardano.Wallet.Api.Types.KeyFormat failed, expected String, but encountered Number"
)
, ( [aesonQQ| { "passphrase": "The proper passphrase", "format": "ok" }|]
, "Error in $.format: parsing Cardano.Wallet.Api.Types.KeyFormat failed, expected one of the tags ['extended','non_extended'], but found tag 'ok'"
)
]

instance Malformed (BodyParam (ApiSelectCoinsData ('Testnet pm))) where
malformed = jsonValid ++ jsonInvalid
where
Expand Down
9 changes: 9 additions & 0 deletions lib/core/test/unit/Cardano/Wallet/Api/TypesSpec.hs
Expand Up @@ -92,6 +92,7 @@ import Cardano.Wallet.Api.Types
, ApiOurStakeKey
, ApiPendingSharedWallet (..)
, ApiPostAccountKeyData
, ApiPostAccountKeyDataWithPurpose
, ApiPostRandomAddressData
, ApiPutAddressesData (..)
, ApiRawMetadata (..)
Expand Down Expand Up @@ -401,6 +402,7 @@ spec = parallel $ do
jsonRoundtripAndGolden $ Proxy @ApiAddressData
jsonRoundtripAndGolden $ Proxy @(ApiT DerivationIndex)
jsonRoundtripAndGolden $ Proxy @ApiPostAccountKeyData
jsonRoundtripAndGolden $ Proxy @ApiPostAccountKeyDataWithPurpose
jsonRoundtripAndGolden $ Proxy @ApiAccountKey
jsonRoundtripAndGolden $ Proxy @ApiAccountKeyShared
jsonRoundtripAndGolden $ Proxy @ApiEpochInfo
Expand Down Expand Up @@ -2051,6 +2053,10 @@ instance Arbitrary ApiPostAccountKeyData where
arbitrary = genericArbitrary
shrink = genericShrink

instance Arbitrary ApiPostAccountKeyDataWithPurpose where
arbitrary = genericArbitrary
shrink = genericShrink

instance Arbitrary TokenFingerprint where
arbitrary = do
AssetId policy aName <- genAssetIdSmallRange
Expand Down Expand Up @@ -2380,6 +2386,9 @@ instance ToSchema ApiWalletSignData where
instance ToSchema ApiPostAccountKeyData where
declareNamedSchema _ = declareSchemaForDefinition "ApiPostAccountKeyData"

instance ToSchema ApiPostAccountKeyDataWithPurpose where
declareNamedSchema _ = declareSchemaForDefinition "ApiPostAccountKeyDataWithPurpose"

instance ToSchema ApiAccountKey where
declareNamedSchema _ = declareSchemaForDefinition "ApiAccountKey"

Expand Down

0 comments on commit d3a139e

Please sign in to comment.