@@ -171,36 +171,20 @@ transactionSpecs wRef wc = beforeAll_ (setupLogging "wallet-new_transactionSpecs
171171 <> " error, got: "
172172 <> show err
173173
174- randomTest " fails if you spend more money than your available balance" 1 $ do
175- wallet <- run $ sampleWallet wRef wc
176- (toAcct, toAddr) <- run $ firstAccountAndId wc wallet
177-
178- let payment = Payment
179- { pmtSource = PaymentSource
180- { psWalletId = walId wallet
181- , psAccountIndex = accIndex toAcct
182- }
183- , pmtDestinations = pure PaymentDistribution
184- { pdAddress = addrId toAddr
185- , pdAmount = tooMuchCash (accAmount toAcct)
186- }
187- , pmtGroupingPolicy = Nothing
188- , pmtSpendingPassword = Nothing
189- }
190- tooMuchCash (V1 c) = V1 (Core. mkCoin (Core. getCoin c * 2 ))
191- etxn <- run $ postTransaction wc payment
192- err <- liftIO (etxn `shouldPrism` _Left)
193- case err of
194- ClientWalletError (NotEnoughMoney (ErrAvailableBalanceIsInsufficient _)) ->
195- return ()
174+ randomTest " fails if you don't have any money" 1 $ run $ do
175+ (wallet, account) <- fixtureWallet Nothing
176+ resp <- makePayment (Core. mkCoin 14 ) (wallet, account) =<< getRandomAddress
177+ let err = NotEnoughMoney (ErrAvailableBalanceIsInsufficient 0 )
178+ expectFailure (ClientWalletError err) resp
196179
197- _ ->
198- liftIO $ expectationFailure $
199- " Expected 'NotEnoughMoney ~ ErrAvailableBalanceIsInsufficient', got: "
200- <> show err
180+ randomTest " fails if you spend more money than your available balance" 1 $ run $ do
181+ (wallet, account) <- fixtureWallet (Just $ Core. mkCoin 42 )
182+ resp <- makePayment (Core. mkCoin 10000 ) (wallet, account) =<< getRandomAddress
183+ let err = NotEnoughMoney (ErrAvailableBalanceIsInsufficient 42 )
184+ expectFailure (ClientWalletError err) resp
201185
202186 randomTest " fails if you can't cover fee with a transaction" 1 $ run $ do
203- (wallet, account) <- fixtureWallet (Core. mkCoin 42 )
187+ (wallet, account) <- fixtureWallet (Just $ Core. mkCoin 42 )
204188 resp <- makePayment (Core. mkCoin 42 ) (wallet, account) =<< getRandomAddress
205189 let err = NotEnoughMoney ErrCannotCoverFee
206190 expectFailure (ClientWalletError err) resp
@@ -277,15 +261,18 @@ transactionSpecs wRef wc = beforeAll_ (setupLogging "wallet-new_transactionSpecs
277261 return (unV1 $ addrId toAddr)
278262
279263 fixtureWallet
280- :: Core. Coin
264+ :: Maybe Core. Coin
281265 -> IO (Wallet , Account )
282- fixtureWallet coin = do
266+ fixtureWallet mcoin = do
283267 genesis <- genesisWallet wc
284268 (genesisAccount, _) <- firstAccountAndId wc genesis
285269 wallet <- randomWallet CreateWallet >>= createWalletCheck wc
286270 (account, address) <- firstAccountAndId wc wallet
287- txn <- makePayment coin (genesis, genesisAccount) (unV1 $ addrId address) >>= shouldPrismFlipped _Right
288- pollTransactions wc (walId wallet) (accIndex account) (txId txn)
271+ case mcoin of
272+ Nothing -> return ()
273+ Just coin -> do
274+ txn <- makePayment coin (genesis, genesisAccount) (unV1 $ addrId address) >>= shouldPrismFlipped _Right
275+ pollTransactions wc (walId wallet) (accIndex account) (txId txn)
289276 return (wallet, account)
290277
291278 expectFailure
@@ -295,4 +282,4 @@ transactionSpecs wRef wc = beforeAll_ (setupLogging "wallet-new_transactionSpecs
295282 -> IO ()
296283 expectFailure want eresp = do
297284 resp <- eresp `shouldPrism` _Left
298- want `shouldBe` resp
285+ resp `shouldBe` want
0 commit comments