Skip to content

Commit

Permalink
Merge #1863
Browse files Browse the repository at this point in the history
1863: At check that rewards are not spent when query param withdrawRewards is not used in tx r=piotr-iohk a=piotr-iohk



# Issue Number

#1858

# Overview

- 75f9cbf
  At check that rewards are not spent when query param withdrawRewards is not used in tx
  



# Comments

<!-- Additional comments or screenshots to attach if any -->

<!-- 
Don't forget to:

 ✓ Self-review your changes to make sure nothing unexpected slipped through
 ✓ Assign yourself to the PR
 ✓ Assign one or several reviewer(s)
 ✓ Once created, link this PR to its corresponding ticket
 ✓ Assign the PR to a corresponding milestone
 ✓ Acknowledge any changes required to the Wiki
-->


Co-authored-by: Piotr Stachyra <[email protected]>
  • Loading branch information
iohk-bors[bot] and Piotr Stachyra authored Jul 6, 2020
2 parents dfd32b3 + 125550a commit 9a910f3
Showing 1 changed file with 28 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import Cardano.Wallet.Api.Types
( ApiStakePool
, ApiT (..)
, ApiTransaction
, ApiTxId (..)
, ApiWallet
, ApiWithdrawRewards (..)
, DecodeAddress
Expand Down Expand Up @@ -92,7 +93,6 @@ import Test.Integration.Framework.DSL
, verify
, waitForNextEpoch
, walletId
, (.<=)
, (.>)
, (.>)
)
Expand Down Expand Up @@ -159,14 +159,18 @@ spec = do

-- Earn rewards
waitForNextEpoch ctx
previousBalance <- eventually "Wallet gets rewards" $ do
(previousBalance, walletRewards) <- eventually "Wallet gets rewards" $ do
r <- request @ApiWallet ctx (Link.getWallet @'Shelley w) Default Empty
verify r
[ expectField (#balance . #getApiT . #reward) (.> (Quantity 0))
]
pure $ getFromResponse (#balance . #getApiT . #available) r
let availableBalance =
getFromResponse (#balance . #getApiT . #available) r
let rewardBalance =
getFromResponse (#balance . #getApiT . #reward) r
pure (availableBalance, rewardBalance)

-- Use rewards
-- Try to use rewards
addrs <- listAddresses @n ctx w
let coin = 1 :: Natural
let addr = (addrs !! 1) ^. #id
Expand All @@ -181,6 +185,23 @@ spec = do
]
, "passphrase": #{fixturePassphrase}
}|]

-- cannot use rewards by default
r1 <- request @(ApiTransaction n) ctx
(Link.createTransaction @'Shelley w)
Default (Json payload)
expectResponseCode HTTP.status202 r1
let txId1 = getFromResponse #id r1
eventually "Wallet has not consumed rewards" $ do
let linkSrc = Link.getTransaction @'Shelley w (ApiTxId txId1)
request @(ApiTransaction n) ctx linkSrc Default Empty >>= flip verify
[ expectField (#status . #getApiT) (`shouldBe` InLedger)
]
request @ApiWallet ctx (Link.getWallet @'Shelley w) Default Empty >>= flip verify
[ expectField (#balance . #getApiT . #reward) (`shouldBe` walletRewards)
]

-- can use rewards with special transaction query param (ApiWithdrawRewards True)
request @(ApiTransaction n) ctx
(Link.createTransaction' @'Shelley w (ApiWithdrawRewards True))
Default (Json payload) >>= flip verify
Expand All @@ -191,7 +212,7 @@ spec = do
-- Rewards are have been consumed.
eventually "Wallet has consumed rewards" $ do
request @ApiWallet ctx (Link.getWallet @'Shelley w) Default Empty >>= flip verify
[ expectField (#balance . #getApiT . #reward) (.<= (Quantity 0))
[ expectField (#balance . #getApiT . #reward) (`shouldBe` (Quantity 0))
, expectField (#balance . #getApiT . #available) (.> previousBalance)
]

Expand Down Expand Up @@ -521,7 +542,7 @@ spec = do
r <- listPools ctx
expectResponseCode HTTP.status200 r
let oneMillionAda = 1_000_000_000_000
let pools = either (error . show) id $ snd r
let pools = either (error . show) Prelude.id $ snd r

-- To ignore the ordering of the pools, we use Set.
setOf pools (view #cost)
Expand Down Expand Up @@ -576,7 +597,7 @@ spec = do

verify r
[ expectListSize 3
, expectField id $ \pools ->
, expectField Prelude.id $ \pools ->
-- To ignore the arbitrary order,
-- we sort on the names before comparing
sortOn name ( mapMaybe (fmap getApiT . view #metadata) pools)
Expand Down

0 comments on commit 9a910f3

Please sign in to comment.