Skip to content

Commit

Permalink
Merge #1137
Browse files Browse the repository at this point in the history
1137: Add an extra scenario to illustrate the delegation "latency" r=KtorZ a=KtorZ

# Issue Number

<!-- Put here a reference to the issue this PR relates to and which requirements it tackles -->

#904 

# Overview

<!-- Detail in a few bullet points the work accomplished in this PR -->

- [x] I have added an extra scenario regarding rewards behavior described below

# Comments

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

At epoch e: Join stake pool P1
At epoch e+1: Quit stake pool P1
At epoch e+2: Stake is being delegated to P1
At epoch e+3: Reward is earned from the delegation in e+2


<!-- 
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: KtorZ <matthias.benkort@gmail.com>
  • Loading branch information
iohk-bors[bot] and KtorZ authored Dec 9, 2019
2 parents b13ddbc + 48ca283 commit 85e21d0
Showing 1 changed file with 42 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -254,17 +254,41 @@ spec = do
reward <- getFromResponse balanceReward <$>
request @ApiWallet ctx (getWalletEp w) Default Empty

-- Wait an epoch and make sure the reward doesn't increase
epoch <- getFromResponse (#networkTip . #epochNumber) <$>
request @ApiNetworkInformation ctx networkInfoEp Default Empty
eventually $ do
epoch' <- getFromResponse (#networkTip . #epochNumber) <$>
request @ApiNetworkInformation ctx networkInfoEp Default Empty
unless (getApiT epoch' > getApiT epoch) $ fail "not yet"
waitForNextEpoch ctx
request @ApiWallet ctx (getWalletEp w) Default Empty >>= flip verify
[ expectFieldSatisfy balanceReward (== reward)
]

it "STAKE_POOLS_JOIN_04 -\
\Delegate, stop in the next epoch, and still earn rewards" $ \ctx -> do
w <- fixtureWallet ctx
(_, p1:_) <- eventually $
unsafeRequest @[ApiStakePool] ctx listStakePoolsEp Empty

joinStakePool ctx (p1 ^. #id) (w, fixturePassphrase) >>= flip verify
[ expectResponseCode HTTP.status202
]

waitForNextEpoch ctx

quitStakePool ctx (p1 ^. #id) (w, fixturePassphrase) >>= flip verify
[ expectResponseCode HTTP.status202
]

reward <- eventually $ do
r <- request @ApiWallet ctx (getWalletEp w) Default Empty
verify r
[ expectFieldSatisfy balanceReward (> 0)
]
pure $ getFromResponse balanceReward r

waitForNextEpoch ctx

eventually $ do
request @ApiWallet ctx (getWalletEp w) Default Empty >>= flip verify
[ expectFieldSatisfy balanceReward (== reward)
]

it "STAKE_POOLS_JOIN_01 - I can join another stake-pool after previously \
\ joining another one" $ \ctx -> do
w <- fixtureWallet ctx
Expand Down Expand Up @@ -628,6 +652,17 @@ arbitraryPoolId :: ApiT PoolId
arbitraryPoolId = either (error . show) ApiT $ fromText
"a659052d84ddb6a04189bee523d59c0a3385c921f43db5dc5de17a4f3f11dc4c"

waitForNextEpoch
:: Context t
-> IO ()
waitForNextEpoch ctx = do
epoch <- getFromResponse (#nodeTip . #epochNumber) <$>
request @ApiNetworkInformation ctx networkInfoEp Default Empty
eventually $ do
epoch' <- getFromResponse (#nodeTip . #epochNumber) <$>
request @ApiNetworkInformation ctx networkInfoEp Default Empty
unless (getApiT epoch' > getApiT epoch) $ fail "not yet"

joinStakePoolWithWalletBalance
:: (Context t)
-> [Natural]
Expand Down

0 comments on commit 85e21d0

Please sign in to comment.