Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit 3acda87

Browse files
committed
[CO-319] Add roundtrip tests
1 parent 8ee4ddc commit 3acda87

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

wallet-new/src/Cardano/Wallet/API/V1/Types.hs

+4-5
Original file line numberDiff line numberDiff line change
@@ -862,11 +862,10 @@ instance Bounded AccountIndex where
862862

863863
mkAccountIndex :: Word32 -> Either Text AccountIndex
864864
mkAccountIndex index | index >= getAccIndex minBound = Right $ AccountIndex index
865-
| otherwise = Left $ "mkAccountIndex: Account index should be in range ["
866-
<> show (getAccIndex minBound)
867-
<> ".."
868-
<> show (getAccIndex maxBound)
869-
<> "]"
865+
| otherwise = Left $ sformat
866+
("mkAccountIndex: Account index should be in range ["%int%".."%int%"]")
867+
(getAccIndex minBound)
868+
(getAccIndex maxBound)
870869

871870
instance ToJSON AccountIndex where
872871
toJSON = toJSON . getAccIndex

wallet-new/test/MarshallingSpec.hs

+26-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import Pos.Client.Txp.Util (InputSelectionPolicy)
1111
import qualified Pos.Crypto as Crypto
1212
import qualified Pos.Txp.Toil.Types as V0
1313
import qualified Pos.Wallet.Web.ClientTypes.Types as V0
14+
import Servant.API (FromHttpApiData (..), ToHttpApiData (..))
1415
import Test.Hspec
1516
import Test.Hspec.QuickCheck
1617
import Test.QuickCheck
@@ -22,6 +23,7 @@ import Pos.Util.BackupPhrase (BackupPhrase)
2223
import qualified Pos.Core as Core
2324

2425
import Cardano.Wallet.API.Indices
26+
import Cardano.Wallet.API.Request.Pagination (Page, PerPage)
2527
import Cardano.Wallet.API.V1.Errors (WalletError)
2628
import Cardano.Wallet.API.V1.Migration.Types (Migrate (..))
2729
import Cardano.Wallet.API.V1.Types
@@ -32,7 +34,7 @@ import qualified Cardano.Wallet.Util as Util
3234
spec :: Spec
3335
spec = parallel $ describe "Marshalling & Unmarshalling" $ do
3436
parallel $ describe "Roundtrips" $ do
35-
-- Aeson roundrips
37+
-- Aeson roundtrips
3638
aesonRoundtripProp @(V1 BackupPhrase) Proxy
3739
aesonRoundtripProp @Account Proxy
3840
aesonRoundtripProp @AssuranceLevel Proxy
@@ -63,8 +65,19 @@ spec = parallel $ describe "Marshalling & Unmarshalling" $ do
6365
aesonRoundtripProp @EstimatedCompletionTime Proxy
6466
aesonRoundtripProp @SyncProgress Proxy
6567
aesonRoundtripProp @SyncThroughput Proxy
66-
67-
-- Migrate roundrips
68+
aesonRoundtripProp @AccountIndex Proxy
69+
70+
-- HttpApiData roundtrips
71+
httpApiDataRoundtripProp @AccountIndex Proxy
72+
httpApiDataRoundtripProp @(V1 Core.TxId) Proxy
73+
httpApiDataRoundtripProp @WalletId Proxy
74+
httpApiDataRoundtripProp @(V1 Core.Timestamp) Proxy
75+
httpApiDataRoundtripProp @(V1 Core.Address) Proxy
76+
httpApiDataRoundtripProp @PerPage Proxy
77+
httpApiDataRoundtripProp @Page Proxy
78+
httpApiDataRoundtripProp @Core.Coin Proxy
79+
80+
-- Migrate roundtrips
6881
migrateRoundtripProp @(V1 Core.Address) @(V0.CId V0.Addr) Proxy Proxy
6982
migrateRoundtripProp @(V1 Core.Coin) @V0.CCoin Proxy Proxy
7083
migrateRoundtripProp @AssuranceLevel @V0.CWalletAssurance Proxy Proxy
@@ -151,6 +164,16 @@ aesonRoundtripProp
151164
aesonRoundtripProp proxy =
152165
prop ("Aeson " <> show (typeRep proxy) <> " roundtrips") (aesonRoundtrip proxy)
153166

167+
httpApiDataRoundtrip :: (Arbitrary a, FromHttpApiData a, ToHttpApiData a, Eq a, Show a) => proxy a -> Property
168+
httpApiDataRoundtrip (_ :: proxy a) = forAll arbitrary $ \(s :: a) -> do
169+
parseQueryParam (toQueryParam s) === Right s
170+
171+
httpApiDataRoundtripProp
172+
:: (Arbitrary a, ToHttpApiData a, FromHttpApiData a, Eq a, Show a, Typeable a)
173+
=> proxy a -> Spec
174+
httpApiDataRoundtripProp proxy =
175+
prop ("HttpApiData " <> show (typeRep proxy) <> " roundtrips") (httpApiDataRoundtrip proxy)
176+
154177
generalRoundtrip
155178
:: (Arbitrary from, Eq from, Show from, Show e)
156179
=> (from -> to) -> (to -> Either e from) -> Property

0 commit comments

Comments
 (0)