@@ -18,6 +18,7 @@ import Cardano.Wallet.Api.Types
1818 ( ApiStakePool
1919 , ApiT (.. )
2020 , ApiTransaction
21+ , ApiTxId (.. )
2122 , ApiWallet
2223 , ApiWithdrawRewards (.. )
2324 , DecodeAddress
@@ -92,7 +93,6 @@ import Test.Integration.Framework.DSL
9293 , verify
9394 , waitForNextEpoch
9495 , walletId
95- , (.<=)
9696 , (.>)
9797 , (.>)
9898 )
@@ -159,14 +159,18 @@ spec = do
159159
160160 -- Earn rewards
161161 waitForNextEpoch ctx
162- previousBalance <- eventually " Wallet gets rewards" $ do
162+ ( previousBalance, walletRewards) <- eventually " Wallet gets rewards" $ do
163163 r <- request @ ApiWallet ctx (Link. getWallet @ 'Shelley w) Default Empty
164164 verify r
165165 [ expectField (# balance . # getApiT . # reward) (.> (Quantity 0 ))
166166 ]
167- pure $ getFromResponse (# balance . # getApiT . # available) r
167+ let availableBalance =
168+ getFromResponse (# balance . # getApiT . # available) r
169+ let rewardBalance =
170+ getFromResponse (# balance . # getApiT . # reward) r
171+ pure (availableBalance, rewardBalance)
168172
169- -- Use rewards
173+ -- Try to use rewards
170174 addrs <- listAddresses @ n ctx w
171175 let coin = 1 :: Natural
172176 let addr = (addrs !! 1 ) ^. # id
@@ -181,6 +185,23 @@ spec = do
181185 ]
182186 , "passphrase": #{fixturePassphrase}
183187 }|]
188+
189+ -- cannot use rewards by default
190+ r1 <- request @ (ApiTransaction n ) ctx
191+ (Link. createTransaction @ 'Shelley w)
192+ Default (Json payload)
193+ expectResponseCode HTTP. status202 r1
194+ let txId1 = getFromResponse # id r1
195+ eventually " Wallet has not consumed rewards" $ do
196+ let linkSrc = Link. getTransaction @ 'Shelley w (ApiTxId txId1)
197+ request @ (ApiTransaction n ) ctx linkSrc Default Empty >>= flip verify
198+ [ expectField (# status . # getApiT) (`shouldBe` InLedger )
199+ ]
200+ request @ ApiWallet ctx (Link. getWallet @ 'Shelley w) Default Empty >>= flip verify
201+ [ expectField (# balance . # getApiT . # reward) (`shouldBe` walletRewards)
202+ ]
203+
204+ -- can use rewards with special transaction query param (ApiWithdrawRewards True)
184205 request @ (ApiTransaction n ) ctx
185206 (Link. createTransaction' @ 'Shelley w (ApiWithdrawRewards True ))
186207 Default (Json payload) >>= flip verify
@@ -191,7 +212,7 @@ spec = do
191212 -- Rewards are have been consumed.
192213 eventually " Wallet has consumed rewards" $ do
193214 request @ ApiWallet ctx (Link. getWallet @ 'Shelley w) Default Empty >>= flip verify
194- [ expectField (# balance . # getApiT . # reward) (.<= (Quantity 0 ))
215+ [ expectField (# balance . # getApiT . # reward) (`shouldBe` (Quantity 0 ))
195216 , expectField (# balance . # getApiT . # available) (.> previousBalance)
196217 ]
197218
@@ -521,7 +542,7 @@ spec = do
521542 r <- listPools ctx
522543 expectResponseCode HTTP. status200 r
523544 let oneMillionAda = 1_000_000_000_000
524- let pools = either (error . show ) id $ snd r
545+ let pools = either (error . show ) Prelude. id $ snd r
525546
526547 -- To ignore the ordering of the pools, we use Set.
527548 setOf pools (view # cost)
@@ -576,7 +597,7 @@ spec = do
576597
577598 verify r
578599 [ expectListSize 3
579- , expectField id $ \ pools ->
600+ , expectField Prelude. id $ \ pools ->
580601 -- To ignore the arbitrary order,
581602 -- we sort on the names before comparing
582603 sortOn name ( mapMaybe (fmap getApiT . view # metadata) pools)
0 commit comments