Skip to content

Commit

Permalink
Logic changes to join/quitStakePools (#4468)
Browse files Browse the repository at this point in the history
<!--
Detail in a few bullet points the work accomplished in this PR.

Before you submit, don't forget to:

* Make sure the GitHub PR fields are correct:
   ✓ Set a good Title for your PR.
   ✓ Assign yourself to the PR.
   ✓ Assign one or more reviewer(s).
   ✓ Link to a Jira issue, and/or other GitHub issues or PRs.
   ✓ In the PR description delete any empty sections
     and all text commented in <!--, so that this text does not appear
     in merge commit messages.

* Don't waste reviewers' time:
   ✓ If it's a draft, select the Create Draft PR option.
✓ Self-review your changes to make sure nothing unexpected slipped
through.

* Try to make your intent clear:
   ✓ Write a good Description that explains what this PR is meant to do.
   ✓ Jira will detect and link to this PR once created, but you can also
     link this PR in the description of the corresponding Jira ticket.
   ✓ Highlight what Testing you have done.
   ✓ Acknowledge any changes required to the Documentation.
-->

- [x] Legacy joinStakePools automatically sets Abstain in Conway
- [x] check withdrawals and quitting (quitStakePools) with
joinStakePools

### Comments

In order to run
```
just conway-integration-tests-cabal-match STAKE_POOLS_
```

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

### Issue Number

ADP-3261
  • Loading branch information
paweljakubas authored Mar 1, 2024
2 parents 6967381 + e7831c3 commit 241100c
Show file tree
Hide file tree
Showing 8 changed files with 908 additions and 85 deletions.
23 changes: 21 additions & 2 deletions lib/integration/framework/Test/Integration/Framework/DSL.hs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ module Test.Integration.Framework.DSL
, notDelegating
, delegating
, onlyVoting
, votingAndDelegating
, getSlotParams
, arbitraryStake

Expand Down Expand Up @@ -235,6 +236,7 @@ module Test.Integration.Framework.DSL
, listLimitedTransactions
, noConway
, noBabbage
, babbageOrConway
) where

import Prelude
Expand Down Expand Up @@ -3522,17 +3524,28 @@ delegating pidActive nexts = (notDelegating nexts)
{ active = ApiWalletDelegationNext Delegating (Just pidActive) Nothing Nothing
}

-- this one will be revisited when I add voting and delegation together. Now only voting
onlyVoting
:: ApiT DRep
-- ^ Pool joined
-- ^ voting
-> [(Maybe (ApiT PoolId), EpochInfo)]
-- ^ Pools to be joined & epoch at which the new delegation will become active
-> ApiWalletDelegation
onlyVoting drep nexts = (notDelegating nexts)
{ active = ApiWalletDelegationNext Voting Nothing (Just drep) Nothing
}

votingAndDelegating
:: ApiT PoolId
-- ^ Pool joined
-> ApiT DRep
-- ^ voting
-> [(Maybe (ApiT PoolId), EpochInfo)]
-- ^ Pools to be joined & epoch at which the new delegation will become active
-> ApiWalletDelegation
votingAndDelegating pidActive drep nexts = (notDelegating nexts)
{ active = ApiWalletDelegationNext VotingAndDelegating (Just pidActive) (Just drep) Nothing
}

getRetirementEpoch :: StakePool -> Maybe EpochNo
getRetirementEpoch = fmap (view #epochNumber) . view #retirement

Expand Down Expand Up @@ -3602,3 +3615,9 @@ noBabbage :: MonadIO m => Context -> String -> m ()
noBabbage ctx reason = liftIO $ do
when (_mainEra ctx == ApiBabbage) $
pendingWith $ "BABBAGE is not supported: " <> reason

babbageOrConway :: Context -> a -> a -> a
babbageOrConway ctx valBabbage valConway =
case _mainEra ctx of
ApiBabbage -> valBabbage
_ -> valConway
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ import Cardano.Wallet.Primitive.Types
import Cardano.Wallet.Primitive.Types.Coin
( Coin (..)
)
import Cardano.Wallet.Primitive.Types.DRep
( DRep (..)
)
import Cardano.Wallet.Primitive.Types.Tx.Constraints
( TxSize (..)
)
Expand Down Expand Up @@ -152,6 +155,7 @@ import Test.Integration.Framework.DSL
( Headers (..)
, Payload (..)
, arbitraryStake
, babbageOrConway
, bracketSettings
, decodeErrorInfo
, delegating
Expand Down Expand Up @@ -193,6 +197,7 @@ import Test.Integration.Framework.DSL
, verify
, verifyMaintenanceAction
, verifyMetadataSource
, votingAndDelegating
, waitForEpoch
, waitForNextEpoch
, waitForTxImmutability
Expand Down Expand Up @@ -399,6 +404,7 @@ spec = describe "SHELLEY_STAKE_POOLS" $ do
]

-- Listing stake keys shows
let delegStatus = babbageOrConway ctx Delegating VotingAndDelegating
request @(ApiStakeKeys n) ctx (Link.listStakeKeys src) Default Empty
>>= flip
verify
Expand All @@ -410,7 +416,7 @@ spec = describe "SHELLEY_STAKE_POOLS" $ do
(acc ^. #_stake) .> ApiAmount 0
acc
^. (#_delegation . #active . #status)
`shouldBe` Delegating
`shouldBe` delegStatus
acc
^. (#_delegation . #active . #target)
`shouldBe` (Just (ApiT pool))
Expand Down Expand Up @@ -709,12 +715,13 @@ spec = describe "SHELLEY_STAKE_POOLS" $ do
waitForTxStatus ctx w InLedger . getResponse
=<< joinStakePool @n ctx (SpecificPool pool1) (w, fixturePassphrase)

let delegStatus = babbageOrConway ctx Delegating VotingAndDelegating
request @ApiWallet ctx (Link.getWallet @'Shelley w) Default Empty
>>= flip
verify
[ expectField (#delegation . #next) $ \case
[dlg] -> do
(dlg ^. #status) `shouldBe` Delegating
(dlg ^. #status) `shouldBe` delegStatus
(dlg ^. #target) `shouldBe` Just (ApiT pool1)
(view #epochNumber <$> dlg ^. #changesAt)
`shouldSatisfy` ( \x ->
Expand All @@ -736,10 +743,14 @@ spec = describe "SHELLEY_STAKE_POOLS" $ do
-- Epoch A+2: stake is active, rewards start accumulating.
waitNumberOfEpochBoundaries 2 ctx

let deleg pool = babbageOrConway ctx
(delegating (ApiT pool) [])
(votingAndDelegating (ApiT pool) (ApiT Abstain) [])

request @ApiWallet ctx (Link.getWallet @'Shelley w) Default Empty
>>= flip
verify
[expectField #delegation (`shouldBe` delegating (ApiT pool1) [])]
[expectField #delegation (`shouldBe` deleg pool1)]

-- join another stake pool
waitForTxStatus ctx w InLedger . getResponse
Expand All @@ -751,7 +762,7 @@ spec = describe "SHELLEY_STAKE_POOLS" $ do
request @ApiWallet ctx (Link.getWallet @'Shelley w) Default Empty
>>= flip
verify
[expectField #delegation (`shouldBe` delegating (ApiT pool2) [])]
[expectField #delegation (`shouldBe` deleg pool2)]

it "STAKE_POOLS_JOIN_04 - Rewards accumulate" $ \ctx -> runResourceT $ do
w <- fixtureWallet ctx
Expand Down Expand Up @@ -986,10 +997,14 @@ spec = describe "SHELLEY_STAKE_POOLS" $ do

waitNumberOfEpochBoundaries 2 ctx

let deleg = babbageOrConway ctx
(delegating (ApiT pool1) [])
(votingAndDelegating (ApiT pool1) (ApiT Abstain) [])

request @ApiWallet ctx (Link.getWallet @'Shelley w) Default Empty
>>= flip
verify
[expectField #delegation (`shouldBe` delegating (ApiT pool1) [])]
[expectField #delegation (`shouldBe` deleg)]

-- Cannot join the same pool
liftIO
Expand Down Expand Up @@ -1138,14 +1153,18 @@ spec = describe "SHELLEY_STAKE_POOLS" $ do
-- Epoch A+2: stake is active, rewards start accumulating.
waitNumberOfEpochBoundaries 2 ctx

let deleg = babbageOrConway ctx
(delegating (ApiT pool) [])
(votingAndDelegating (ApiT pool) (ApiT Abstain) [])

request @ApiWallet
ctx
(Link.getWallet @'Shelley w)
Default
Empty
>>= flip
verify
[ expectField #delegation (`shouldBe` delegating (ApiT pool) [])
[ expectField #delegation (`shouldBe` deleg)
]

rQuit <- quitStakePool @n ctx (w, fixturePassphrase)
Expand Down Expand Up @@ -1202,7 +1221,8 @@ spec = describe "SHELLEY_STAKE_POOLS" $ do
"STAKE_POOLS_QUIT_01x - \
\I cannot quit if I have not enough to cover fees"
$ \ctx -> runResourceT $ do
let initBalance = [costOfJoining ctx + depositAmt ctx]
let fuzz = costOf 50 ctx
let initBalance = [costOfJoining ctx + depositAmt ctx + fuzz]
w <- fixtureWalletWith @n ctx initBalance

pool : _ <-
Expand All @@ -1225,14 +1245,18 @@ spec = describe "SHELLEY_STAKE_POOLS" $ do
-- Epoch A+2: stake is active, rewards start accumulating.
waitNumberOfEpochBoundaries 2 ctx

let deleg = babbageOrConway ctx
(delegating (ApiT pool) [])
(votingAndDelegating (ApiT pool) (ApiT Abstain) [])

request @ApiWallet
ctx
(Link.getWallet @'Shelley w)
Default
Empty
>>= flip
verify
[ expectField #delegation (`shouldBe` delegating (ApiT pool) [])
[ expectField #delegation (`shouldBe` deleg)
]

response <- quitStakePool @n ctx (w, fixturePassphrase)
Expand Down
Loading

0 comments on commit 241100c

Please sign in to comment.