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

Commit 0a47916

Browse files
committed
[CBR-26] Fix tests
1 parent c719e00 commit 0a47916

File tree

7 files changed

+54
-26
lines changed

7 files changed

+54
-26
lines changed

wallet-new/test/MarshallingSpec.hs

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import qualified Test.QuickCheck.Property as Property
2020

2121
import qualified Pos.Core as Core
2222
import qualified Pos.Core.Update as Core
23+
import qualified Pos.Core.Txp as Core
2324

2425
import Cardano.Wallet.API.Indices
2526
import Cardano.Wallet.API.Request.Pagination (Page, PerPage)

wallet-new/test/WalletNewGen.hs

+5-7
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ module WalletNewGen
44

55
import Universum
66

7-
import Cardano.Wallet.API.V1.Errors (WalletError (..))
8-
import Cardano.Wallet.API.V1.Types (SyncProgress (..), V1 (..),
9-
mkEstimatedCompletionTime, mkSyncPercentage,
10-
mkSyncThroughput)
117
import Hedgehog
128
import qualified Hedgehog.Gen as Gen
139
import qualified Hedgehog.Range as Range
10+
11+
import Cardano.Wallet.API.V1.Types (SyncProgress (..), V1 (..),
12+
WalletError (..), mkEstimatedCompletionTime,
13+
mkSyncPercentage, mkSyncThroughput, exampleWalletId)
1414
import Pos.Core.Common (BlockCount (..))
1515

1616
import Test.Pos.Core.Gen (genAddress)
@@ -20,12 +20,10 @@ genWalletError :: Gen WalletError
2020
genWalletError = Gen.choice
2121
[ NotEnoughMoney <$> Gen.int (Range.constant 1 1000)
2222
, OutputIsRedeem . V1 <$> genAddress
23-
, MigrationFailed <$> Gen.text (Range.constant 1 100) Gen.alphaNum
24-
, JSONValidationFailed <$> Gen.text (Range.constant 1 100) Gen.alphaNum
2523
, UnknownError <$> Gen.text (Range.constant 1 100) Gen.alphaNum
2624
, InvalidAddressFormat <$> Gen.text (Range.constant 1 100) Gen.alphaNum
2725
, pure WalletNotFound
28-
, pure WalletAlreadyExists
26+
, pure (WalletAlreadyExists exampleWalletId)
2927
, pure AddressNotFound
3028
, pure TxFailedToStabilize
3129
, pure TxRedemptionDepleted

wallet-new/test/WalletNewJson.hs

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ module WalletNewJson
44

55
import Universum
66

7-
import Cardano.Wallet.API.V1.Errors (WalletError (..))
7+
import Cardano.Wallet.API.Response (JSONValidationError (..))
8+
import Cardano.Wallet.API.V1.Migration.Types (MigrationError (..))
89
import Cardano.Wallet.API.V1.Types (SyncProgress (..), V1 (..),
9-
mkEstimatedCompletionTime, mkSyncPercentage,
10-
mkSyncThroughput)
10+
WalletError (..), mkEstimatedCompletionTime,
11+
mkSyncPercentage, mkSyncThroughput, exampleWalletId)
1112
import Data.List.NonEmpty (fromList)
1213
import Hedgehog (Property)
1314
import qualified Hedgehog as H
@@ -73,7 +74,7 @@ golden_WalletError_WalletNotFound =
7374
golden_WalletError_WalletAlreadyExists :: Property
7475
golden_WalletError_WalletAlreadyExists =
7576
goldenTestJSON
76-
WalletAlreadyExists
77+
(WalletAlreadyExists exampleWalletId)
7778
"test/golden/WalletError_WalletAlreadyExists"
7879

7980
golden_WalletError_AddressNotFound :: Property

wallet-new/test/unit/Test/Spec/Accounts.hs

+26-8
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ spec = describe "Accounts" $ do
123123
monadicIO $ do
124124
wId <- pick arbitrary
125125
withLayer $ \layer _ -> do
126-
res <- (WalletLayer._pwlDeleteAccount layer) wId 100
126+
res <- WalletLayer._pwlDeleteAccount layer wId
127+
(V1.unsafeMkAccountIndex 100)
127128
case res of
128129
Left (WalletLayer.DeleteAccountError
129130
(V1 (Kernel.UnknownHdAccountRoot _))) ->
@@ -139,7 +140,9 @@ spec = describe "Accounts" $ do
139140
prop "fails if the account doesn't exists" $ withMaxSuccess 50 $ do
140141
monadicIO $ do
141142
withFixture $ \_ layer _ Fixture{..} -> do
142-
res <- (WalletLayer._pwlDeleteAccount layer) (V1.walId fixtureV1Wallet) 100
143+
res <- WalletLayer._pwlDeleteAccount layer
144+
(V1.walId fixtureV1Wallet)
145+
(V1.unsafeMkAccountIndex 100)
143146
case res of
144147
Left (WalletLayer.DeleteAccountError
145148
(V1 (Kernel.UnknownHdAccount _))) ->
@@ -170,7 +173,9 @@ spec = describe "Accounts" $ do
170173
monadicIO $ do
171174
wId <- pick arbitrary
172175
withLayer $ \layer _ -> do
173-
let delete = Handlers.deleteAccount layer wId 100
176+
let delete = Handlers.deleteAccount layer
177+
wId
178+
(V1.unsafeMkAccountIndex 100)
174179
res <- try . runExceptT . runHandler' $ delete
175180
case res of
176181
Left (_e :: WalletLayer.DeleteAccountError) -> return ()
@@ -180,7 +185,10 @@ spec = describe "Accounts" $ do
180185
prop "Servant handler fails if the account doesn't exist" $ withMaxSuccess 50 $ do
181186
monadicIO $ do
182187
withFixture $ \_ layer _ Fixture{..} -> do
183-
let delete = Handlers.deleteAccount layer (V1.walId fixtureV1Wallet) 100
188+
let delete =
189+
Handlers.deleteAccount layer
190+
(V1.walId fixtureV1Wallet)
191+
(V1.unsafeMkAccountIndex 100)
184192
res <- try . runExceptT . runHandler' $ delete
185193
case res of
186194
Left (_e :: WalletLayer.DeleteAccountError) -> return ()
@@ -207,7 +215,10 @@ spec = describe "Accounts" $ do
207215
monadicIO $ do
208216
wId <- pick arbitrary
209217
withLayer $ \layer _ -> do
210-
res <- (WalletLayer._pwlUpdateAccount layer) wId 100 (V1.AccountUpdate "new account")
218+
res <- WalletLayer._pwlUpdateAccount layer
219+
wId
220+
(V1.unsafeMkAccountIndex 100)
221+
(V1.AccountUpdate "new account")
211222
case res of
212223
Left (WalletLayer.UpdateAccountError
213224
(V1 (Kernel.UnknownHdAccountRoot _))) ->
@@ -224,7 +235,10 @@ spec = describe "Accounts" $ do
224235
monadicIO $ do
225236
withFixture $ \_ layer _ Fixture{..} -> do
226237
let wId = V1.walId fixtureV1Wallet
227-
res <- (WalletLayer._pwlUpdateAccount layer) wId 100 (V1.AccountUpdate "new account")
238+
res <- WalletLayer._pwlUpdateAccount layer
239+
wId
240+
(V1.unsafeMkAccountIndex 100)
241+
(V1.AccountUpdate "new account")
228242
case res of
229243
Left (WalletLayer.UpdateAccountError
230244
(V1 (Kernel.UnknownHdAccount _))) ->
@@ -268,7 +282,9 @@ spec = describe "Accounts" $ do
268282
monadicIO $ do
269283
wId <- pick arbitrary
270284
withLayer $ \layer _ -> do
271-
res <- (WalletLayer._pwlGetAccount layer) wId 100
285+
res <- WalletLayer._pwlGetAccount layer
286+
wId
287+
(V1.unsafeMkAccountIndex 100)
272288
case res of
273289
Left (WalletLayer.GetAccountError (V1 (Kernel.UnknownHdAccountRoot _))) ->
274290
return ()
@@ -283,7 +299,9 @@ spec = describe "Accounts" $ do
283299
prop "fails if the account doesn't exists" $ withMaxSuccess 50 $ do
284300
monadicIO $ do
285301
withFixture $ \_ layer _ Fixture{..} -> do
286-
res <- (WalletLayer._pwlGetAccount layer) (V1.walId fixtureV1Wallet) 100
302+
res <- WalletLayer._pwlGetAccount layer
303+
(V1.walId fixtureV1Wallet)
304+
(V1.unsafeMkAccountIndex 100)
287305
case res of
288306
Left (WalletLayer.GetAccountError (V1 (Kernel.UnknownHdAccount _))) ->
289307
return ()

wallet-new/test/unit/Test/Spec/Addresses.hs

+6-3
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ spec = describe "Addresses" $ do
129129
let (HdRootId hdRoot) = fixtureHdRootId
130130
(AccountIdHdRnd myAccountId) = fixtureAccountId
131131
wId = sformat build (view fromDb hdRoot)
132-
accIdx = myAccountId ^. hdAccountIdIx . to getHdAccountIx
132+
accIdx = V1.unsafeMkAccountIndex $
133+
myAccountId ^. hdAccountIdIx . to getHdAccountIx
133134
res <- (WalletLayer._pwlCreateAddress layer) (V1.NewAddress Nothing accIdx (V1.WalletId wId))
134135
(bimap STB STB res) `shouldSatisfy` isRight
135136

@@ -168,7 +169,8 @@ spec = describe "Addresses" $ do
168169
let (HdRootId hdRoot) = fixtureHdRootId
169170
(AccountIdHdRnd myAccountId) = fixtureAccountId
170171
wId = sformat build (view fromDb hdRoot)
171-
accIdx = myAccountId ^. hdAccountIdIx . to getHdAccountIx
172+
accIdx = V1.unsafeMkAccountIndex $
173+
myAccountId ^. hdAccountIdIx . to getHdAccountIx
172174
req = V1.NewAddress Nothing accIdx (V1.WalletId wId)
173175
res <- runExceptT . runHandler' $ Handlers.newAddress layer req
174176
(bimap identity STB res) `shouldSatisfy` isRight
@@ -184,7 +186,8 @@ spec = describe "Addresses" $ do
184186
let (HdRootId hdRoot) = fixtureHdRootId
185187
(AccountIdHdRnd myAccountId) = fixtureAccountId
186188
wId = sformat build (view fromDb hdRoot)
187-
accIdx = myAccountId ^. hdAccountIdIx . to getHdAccountIx
189+
accIdx = V1.unsafeMkAccountIndex $
190+
myAccountId ^. hdAccountIdIx . to getHdAccountIx
188191
(WalletLayer._pwlCreateAddress layer) (V1.NewAddress Nothing accIdx (V1.WalletId wId))
189192
case res2 of
190193
Left (WalletLayer.CreateAddressError err) ->

wallet-new/test/unit/Test/Spec/GetTransactions.hs

+10-3
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,12 @@ spec =
6363
Left _ -> expectationFailure "decodeTextAddress failed"
6464
Right rootAddr -> do
6565
let meta = testMeta {_txMetaWalletId = rootAddr, _txMetaAccountIx = accIdx}
66-
_ <- liftIO ((WalletLayer._pwlCreateAddress layer) (V1.NewAddress Nothing accIdx (V1.WalletId wId)))
66+
_ <- liftIO $ WalletLayer._pwlCreateAddress layer
67+
(V1.NewAddress
68+
Nothing
69+
(V1.unsafeMkAccountIndex accIdx)
70+
(V1.WalletId wId)
71+
)
6772
putTxMeta (pwallet ^. Kernel.walletMeta) meta
6873
(result, mbCount) <- (getTxMetas hdl) (Offset 0) (Limit 10) Everything Nothing NoFilterOp NoFilterOp Nothing
6974
map Isomorphic result `shouldMatchList` [Isomorphic meta]
@@ -100,7 +105,8 @@ spec =
100105
let (AccountIdHdRnd hdAccountId) = fixtureAccountId
101106
let (HdRootId (InDb rootAddress)) = fixtureHdRootId
102107
let sourceWallet = V1.WalletId (sformat build rootAddress)
103-
let accountIndex = hdAccountId ^. hdAccountIdIx . to getHdAccountIx
108+
let accountIndex = V1.unsafeMkAccountIndex $
109+
hdAccountId ^. hdAccountIdIx . to getHdAccountIx
104110
let destinations =
105111
fmap (\(addr, coin) -> V1.PaymentDistribution (V1.V1 addr) (V1.V1 coin)
106112
) fixturePayees
@@ -123,7 +129,8 @@ spec =
123129
layer = walletPassiveLayer activeLayer
124130
(HdRootId hdRoot) = fixtureHdRootId
125131
wId = sformat build (view fromDb hdRoot)
126-
accIdx = hdAccountId ^. hdAccountIdIx . to getHdAccountIx
132+
accIdx = V1.unsafeMkAccountIndex $
133+
hdAccountId ^. hdAccountIdIx . to getHdAccountIx
127134
hdl = (pw ^. Kernel.walletMeta)
128135
db <- Kernel.getWalletSnapshot pw
129136
let isPending = Kernel.currentTxIsPending db txid hdAccountId

wallet-new/test/unit/Test/Spec/NewPayment.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ withPayment initialBalance toPay action = do
151151
let (AccountIdHdRnd hdAccountId) = fixtureAccountId
152152
let (HdRootId (InDb rootAddress)) = fixtureHdRootId
153153
let sourceWallet = V1.WalletId (sformat build rootAddress)
154-
let accountIndex = hdAccountId ^. hdAccountIdIx . to getHdAccountIx
154+
let accountIndex = V1.unsafeMkAccountIndex $ hdAccountId ^. hdAccountIdIx . to getHdAccountIx
155155
let destinations =
156156
fmap (\(addr, coin) -> V1.PaymentDistribution (V1.V1 addr) (V1.V1 coin)
157157
) fixturePayees

0 commit comments

Comments
 (0)