Skip to content

Commit

Permalink
Update api tests for listAssets and getAsset
Browse files Browse the repository at this point in the history
  • Loading branch information
rvl committed Jan 19, 2021
1 parent 93af64d commit 2607332
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 4 deletions.
33 changes: 33 additions & 0 deletions lib/core/test/unit/Cardano/Wallet/Api/Malformed.hs
Expand Up @@ -79,6 +79,8 @@ import Cardano.Wallet.Primitive.Types
( WalletId, walletNameMaxLength )
import Cardano.Wallet.Primitive.Types.Address
( Address (..) )
import Cardano.Wallet.Primitive.Types.TokenPolicy
( TokenName, TokenPolicyId )
import Control.Arrow
( first )
import Data.Aeson.QQ
Expand Down Expand Up @@ -230,6 +232,37 @@ instance Malformed (PathParam (ApiT DerivationIndex)) where
\Indexes without suffixes are called 'Soft' \
\Indexes with suffixes are called 'Hardened'."

instance Wellformed (PathParam (ApiT TokenPolicyId)) where
wellformed = [PathParam $ T.replicate 64 "0"]

instance Malformed (PathParam (ApiT TokenPolicyId)) where
malformed = first PathParam <$>
[ ( "faff", msgWrongLength )
, ( T.replicate 65 "0", msgWrongLength )
, ( T.replicate 64 "x", msgMalformed )
]
where
msgWrongLength = "TokenPolicyId should be 32 bytes long"
msgMalformed = "TokenPolicyId must be hex-encoded"

instance Wellformed (PathParam (ApiT TokenName)) where
wellformed = PathParam <$>
[ T.replicate 64 "0"
, ""
, "FF"
, "594f4c4f"
, "e29883"
]

instance Malformed (PathParam (ApiT TokenName)) where
malformed = first PathParam <$>
[ ( T.replicate 65 "0", msgWrongLength )
, ( "patate", msgMalformed )
]
where
msgWrongLength = "AssetName can be at most 32 bytes long"
msgMalformed = "AssetName must be hex-encoded"

--
-- Class instances (BodyParam)
--
Expand Down
34 changes: 30 additions & 4 deletions lib/core/test/unit/Cardano/Wallet/Api/TypesSpec.hs
Expand Up @@ -50,6 +50,7 @@ import Cardano.Wallet.Api.Types
, ApiAddress (..)
, ApiAddressData (..)
, ApiAddressInspect (..)
, ApiAsset (..)
, ApiBlockInfo (..)
, ApiBlockReference (..)
, ApiByronWallet (..)
Expand Down Expand Up @@ -90,6 +91,8 @@ import Cardano.Wallet.Api.Types
, ApiUtxoStatistics (..)
, ApiVerificationKey (..)
, ApiWallet (..)
, ApiWalletAssetsBalance (..)
, ApiWalletBalance (..)
, ApiWalletDelegation (..)
, ApiWalletDelegationNext (..)
, ApiWalletDelegationStatus (..)
Expand All @@ -116,11 +119,11 @@ import Cardano.Wallet.Api.Types
, PostTransactionFeeData (..)
, SettingsPutData (..)
, SomeByronWalletPostData (..)
, WalletBalance (..)
, WalletOrAccountPostData (..)
, WalletPostData (..)
, WalletPutData (..)
, WalletPutPassphraseData (..)
, toApiAsset
)
import Cardano.Wallet.Gen
( genMnemonic
Expand Down Expand Up @@ -182,6 +185,10 @@ import Cardano.Wallet.Primitive.Types.Hash
( Hash (..) )
import Cardano.Wallet.Primitive.Types.RewardAccount
( RewardAccount (..) )
import Cardano.Wallet.Primitive.Types.TokenMap
( TokenMap )
import Cardano.Wallet.Primitive.Types.TokenMap.Gen
( genAssetIdSmallRange, genTokenMapSmallRange, shrinkTokenMapSmallRange )
import Cardano.Wallet.Primitive.Types.Tx
( Direction (..)
, TxIn (..)
Expand Down Expand Up @@ -283,6 +290,7 @@ import Test.QuickCheck
, InfiniteList (..)
, Positive (..)
, applyArbitrary2
, applyArbitrary3
, arbitraryBoundedEnum
, arbitraryPrintableChar
, arbitrarySizedBoundedIntegral
Expand Down Expand Up @@ -398,7 +406,7 @@ spec = parallel $ do
jsonRoundtripAndGolden $ Proxy @(ApiT Direction)
jsonRoundtripAndGolden $ Proxy @(ApiT TxMetadata)
jsonRoundtripAndGolden $ Proxy @(ApiT TxStatus)
jsonRoundtripAndGolden $ Proxy @(ApiT WalletBalance)
jsonRoundtripAndGolden $ Proxy @(ApiWalletBalance)
jsonRoundtripAndGolden $ Proxy @(ApiT WalletId)
jsonRoundtripAndGolden $ Proxy @(ApiT WalletName)
jsonRoundtripAndGolden $ Proxy @ApiWalletPassphraseInfo
Expand Down Expand Up @@ -723,6 +731,7 @@ spec = parallel $ do
{ id = id (x :: ApiWallet)
, addressPoolGap = addressPoolGap (x :: ApiWallet)
, balance = balance (x :: ApiWallet)
, assets = assets (x :: ApiWallet)
, delegation = delegation (x :: ApiWallet)
, name = name (x :: ApiWallet)
, passphrase = passphrase (x :: ApiWallet)
Expand Down Expand Up @@ -874,6 +883,7 @@ spec = parallel $ do
, amount = amount (x :: ApiTransaction ('Testnet 0))
, fee = fee (x :: ApiTransaction ('Testnet 0))
, deposit = deposit (x :: ApiTransaction ('Testnet 0))
, assets = assets (x :: ApiTransaction ('Testnet 0))
, insertedAt = insertedAt (x :: ApiTransaction ('Testnet 0))
, pendingSince = pendingSince (x :: ApiTransaction ('Testnet 0))
, expiresAt = expiresAt (x :: ApiTransaction ('Testnet 0))
Expand All @@ -883,6 +893,7 @@ spec = parallel $ do
, outputs = outputs (x :: ApiTransaction ('Testnet 0))
, status = status (x :: ApiTransaction ('Testnet 0))
, withdrawals = withdrawals (x :: ApiTransaction ('Testnet 0))
, forge = forge (x :: ApiTransaction ('Testnet 0))
, metadata = metadata (x :: ApiTransaction ('Testnet 0))
}
in
Expand All @@ -899,6 +910,7 @@ spec = parallel $ do
x' = AddressAmount
{ address = address (x :: AddressAmount (ApiT Address, Proxy ('Testnet 0)))
, amount = amount (x :: AddressAmount (ApiT Address, Proxy ('Testnet 0)))
, assets = assets (x :: AddressAmount (ApiT Address, Proxy ('Testnet 0)))
}
in
x' === x .&&. show x' === show x
Expand Down Expand Up @@ -1284,10 +1296,18 @@ instance Arbitrary ByronWalletPutPassphraseData where
arbitrary = genericArbitrary
shrink = genericShrink

instance Arbitrary WalletBalance where
instance Arbitrary ApiWalletBalance where
arbitrary = genericArbitrary
shrink = genericShrink

instance Arbitrary ApiWalletAssetsBalance where
arbitrary = genericArbitrary
shrink = genericShrink

instance Arbitrary TokenMap where
arbitrary = genTokenMapSmallRange
shrink = shrinkTokenMapSmallRange

instance Arbitrary WalletDelegationStatus where
arbitrary = genericArbitrary
shrink = genericShrink
Expand Down Expand Up @@ -1576,8 +1596,11 @@ instance Arbitrary Word31 where
arbitrary = arbitrarySizedBoundedIntegral
shrink = shrinkIntegral

instance Arbitrary ApiAsset where
arbitrary = toApiAsset Nothing <$> genAssetIdSmallRange

instance Arbitrary a => Arbitrary (AddressAmount a) where
arbitrary = applyArbitrary2 AddressAmount
arbitrary = applyArbitrary3 AddressAmount
shrink _ = []

instance Arbitrary (PostTransactionData t) where
Expand Down Expand Up @@ -1861,6 +1884,9 @@ instance ToSchema ApiStakePoolMetrics where
instance ToSchema ApiFee where
declareNamedSchema _ = declareSchemaForDefinition "ApiFee"

instance ToSchema ApiAsset where
declareNamedSchema _ = declareSchemaForDefinition "ApiAsset"

instance ToSchema ApiTxId where
declareNamedSchema _ = declareSchemaForDefinition "ApiTxId"

Expand Down

0 comments on commit 2607332

Please sign in to comment.