From 6f17d319fe9b2d9465b92d503a7b76382ae38ac0 Mon Sep 17 00:00:00 2001 From: KtorZ Date: Fri, 6 Dec 2019 11:38:31 +0100 Subject: [PATCH 1/3] add an extra scenario regarding rewards behavior 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 --- .../Jormungandr/Scenario/API/StakePools.hs | 40 +++++++++++++++---- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/lib/jormungandr/test/integration/Test/Integration/Jormungandr/Scenario/API/StakePools.hs b/lib/jormungandr/test/integration/Test/Integration/Jormungandr/Scenario/API/StakePools.hs index 6ea620476b9..e360da6776f 100644 --- a/lib/jormungandr/test/integration/Test/Integration/Jormungandr/Scenario/API/StakePools.hs +++ b/lib/jormungandr/test/integration/Test/Integration/Jormungandr/Scenario/API/StakePools.hs @@ -254,17 +254,32 @@ 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 + ] + + eventually $ do + request @ApiWallet ctx (getWalletEp w) Default Empty >>= flip verify + [ expectFieldSatisfy balanceReward (> 0) + ] + it "STAKE_POOLS_JOIN_01 - I can join another stake-pool after previously \ \ joining another one" $ \ctx -> do w <- fixtureWallet ctx @@ -628,6 +643,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] From c39fa4bdb6698cdf226a3620d5d185cb7e3433de Mon Sep 17 00:00:00 2001 From: KtorZ Date: Fri, 6 Dec 2019 14:10:43 +0100 Subject: [PATCH 2/3] check that rewards are not received at e+3 after quitting pool --- .../Jormungandr/Scenario/API/StakePools.hs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/jormungandr/test/integration/Test/Integration/Jormungandr/Scenario/API/StakePools.hs b/lib/jormungandr/test/integration/Test/Integration/Jormungandr/Scenario/API/StakePools.hs index e360da6776f..d7f9295c50d 100644 --- a/lib/jormungandr/test/integration/Test/Integration/Jormungandr/Scenario/API/StakePools.hs +++ b/lib/jormungandr/test/integration/Test/Integration/Jormungandr/Scenario/API/StakePools.hs @@ -275,9 +275,18 @@ spec = do [ 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 (> 0) + [ expectFieldSatisfy balanceReward (== reward) ] it "STAKE_POOLS_JOIN_01 - I can join another stake-pool after previously \ From b70ee873f0c6e0c7a04653371e5acf3c38bed1b4 Mon Sep 17 00:00:00 2001 From: KtorZ Date: Mon, 9 Dec 2019 18:01:20 +0100 Subject: [PATCH 3/3] actually for wait for 2 epochs before querying reward balance again after quitting --- .../Test/Integration/Jormungandr/Scenario/API/StakePools.hs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/jormungandr/test/integration/Test/Integration/Jormungandr/Scenario/API/StakePools.hs b/lib/jormungandr/test/integration/Test/Integration/Jormungandr/Scenario/API/StakePools.hs index d7f9295c50d..ebe8a4f54ce 100644 --- a/lib/jormungandr/test/integration/Test/Integration/Jormungandr/Scenario/API/StakePools.hs +++ b/lib/jormungandr/test/integration/Test/Integration/Jormungandr/Scenario/API/StakePools.hs @@ -251,6 +251,8 @@ spec = do , expectListItemFieldEqual 1 status InLedger ] + waitForNextEpoch ctx + waitForNextEpoch ctx reward <- getFromResponse balanceReward <$> request @ApiWallet ctx (getWalletEp w) Default Empty