Skip to content

Commit

Permalink
add one more voting integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
paweljakubas committed Sep 9, 2024
1 parent e36895f commit ffdc73a
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -647,18 +647,84 @@ spec = describe "SHELLEY_STAKE_POOLS" $ do
]
decodeErrorInfo r `shouldBe` PoolAlreadyJoined

it "STAKE_POOLS_JOIN_02 - \
it "STAKE_POOLS_JOIN_02a - \
\Can join the stake pool if voting was cast before in Conway"
$ \ctx -> runResourceT $ do
noBabbage ctx "joining the pool possible in Conway if voting was previously cast"

w <- fixtureWallet ctx

let voteNoConfidence = Json [json|{
"vote": "no_confidence"
}|]
rTx1 <- request @(ApiConstructTransaction n) ctx
(Link.createUnsignedTransaction @'Shelley w) Default voteNoConfidence
verify rTx1
[ expectResponseCode HTTP.status202
]
let ApiSerialisedTransaction apiTx1 _ = getFromResponse #transaction rTx1
signedTx1 <- signTx ctx w apiTx1 [ expectResponseCode HTTP.status202 ]
submittedTx1 <- submitTxWithWid ctx w signedTx1
verify submittedTx1
[ expectSuccess
, expectResponseCode HTTP.status202
]
let voting = ApiT NoConfidence
let getSrcWallet =
let endpoint = Link.getWallet @'Shelley w
in request @ApiWallet ctx endpoint Default Empty

waitNumberOfEpochBoundaries 2 ctx

eventually "Wallet is voting abstain" $ do
getSrcWallet >>= flip verify
[ expectField #delegation (`shouldBe` onlyVoting voting [])
]

pool1 : pool2 : _ <- map (view #id) <$> notRetiringPools ctx

waitForTxStatus ctx w InLedger . getResponse
=<< joinStakePool @n ctx (SpecificPool pool1) (w, fixturePassphrase)

eventually "Wallet is delegating to pool1 and voting" $ do
getSrcWallet >>= flip verify
[ expectField #delegation
(`shouldBe` votingAndDelegating (ApiT pool1) voting [])
]

-- joinStakePool would try once again joining pool and fail as we have already voted
-- and we do not aim to change voting
r1 <- joinStakePool @n ctx (SpecificPool pool1) (w, fixturePassphrase)
verify r1
[ expectResponseCode HTTP.status403
]
decodeErrorInfo r1 `shouldBe` PoolAlreadyJoined

-- but we can join another pool and have initial voting
r2 <- joinStakePool @n ctx (SpecificPool pool2) (w, fixturePassphrase)
verify r2
[ expectSuccess
, expectResponseCode HTTP.status202
]

eventually "Wallet is delegating to pool2 and voting" $ do
getSrcWallet >>= flip verify
[ expectField #delegation
(`shouldBe` votingAndDelegating (ApiT pool2) voting [])
]

it "STAKE_POOLS_JOIN_02b - \
\Can join the stake pool if voting was cast before in Conway"
$ \ctx -> runResourceT $ do
noBabbage ctx "joining the pool possible in Conway if voting was previously cast"

w <- fixtureWallet ctx

let voteAbstain = Json [json|{
let voteNoConfidence = Json [json|{
"vote": "no_confidence"
}|]
rTx1 <- request @(ApiConstructTransaction n) ctx
(Link.createUnsignedTransaction @'Shelley w) Default voteAbstain
(Link.createUnsignedTransaction @'Shelley w) Default voteNoConfidence
verify rTx1
[ expectResponseCode HTTP.status202
]
Expand Down
49 changes: 49 additions & 0 deletions lib/integration/scenarios/Test/Integration/Scenario/API/Voting.hs
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,55 @@ spec = describe "VOTING_TRANSACTIONS" $ do
(`shouldBe` votingAndDelegating (ApiT pool2) (ApiT voting) [])
]

it "VOTING_01i - Delegation works in Conway in presence of voting and does not change it"
$ \ctx -> runResourceT $ do
noBabbage ctx "voting can be checked only in Conway onwards"
w <- fixtureWallet ctx

eventually "Initially wallet is neither delegating nor voting" $ do
getSrcWallet ctx w >>= flip verify
[ expectField #delegation
(`shouldBe` notDelegating [])
]

pool1 : pool2 : _ <- map (view #id) <$> notRetiringPools ctx

let voting1 = Abstain

-- Join Pool
rJoin1 <- joinStakePool @n ctx (SpecificPool pool1) (w, fixturePassphrase)
verify rJoin1
[ expectResponseCode HTTP.status202
]
eventually "Wallet is voting Abstain and delegating to pool1" $ do
getSrcWallet ctx w >>= flip verify
[ expectField #delegation
(`shouldBe` votingAndDelegating (ApiT pool1) (ApiT voting1) [])
]

let voting2 = NoConfidence
rTx <- joinDRep @n ctx (SpecificDRep voting2) (w, fixturePassphrase)
verify rTx
[ expectResponseCode HTTP.status202
]

eventually "Wallet is voting NoConfidence and delegating to pool1" $ do
getSrcWallet ctx w >>= flip verify
[ expectField #delegation
(`shouldBe` votingAndDelegating (ApiT pool1) (ApiT voting2) [])
]

-- Rejoin Pool
rJoin2 <- joinStakePool @n ctx (SpecificPool pool2) (w, fixturePassphrase)
verify rJoin2
[ expectResponseCode HTTP.status202
]
eventually "Wallet is voting NoConfidence and delegating to pool2" $ do
getSrcWallet ctx w >>= flip verify
[ expectField #delegation
(`shouldBe` votingAndDelegating (ApiT pool2) (ApiT voting2) [])
]

where
stakeKeyDerPath = NE.fromList
[ ApiT (DerivationIndex 2_147_485_500)
Expand Down

0 comments on commit ffdc73a

Please sign in to comment.