From ac19c683b7880f2b918dbc1d6c93def3d574cfaf Mon Sep 17 00:00:00 2001 From: Pawel Jakubas Date: Tue, 25 Jan 2022 11:22:51 +0100 Subject: [PATCH] demostrate that rejoining works --- .../Scenario/API/Shelley/TransactionsNew.hs | 62 ++++++++++++++++++- 1 file changed, 59 insertions(+), 3 deletions(-) diff --git a/lib/core-integration/src/Test/Integration/Scenario/API/Shelley/TransactionsNew.hs b/lib/core-integration/src/Test/Integration/Scenario/API/Shelley/TransactionsNew.hs index 0c64906bf06..041652640cd 100644 --- a/lib/core-integration/src/Test/Integration/Scenario/API/Shelley/TransactionsNew.hs +++ b/lib/core-integration/src/Test/Integration/Scenario/API/Shelley/TransactionsNew.hs @@ -152,6 +152,7 @@ import Test.Integration.Framework.DSL , eventually , expectErrorMessage , expectField + , expectListField , expectResponseCode , expectSuccess , fixtureMultiAssetWallet @@ -1062,14 +1063,14 @@ spec = describe "NEW_SHELLEY_TRANSACTIONS" $ do it "TRANS_NEW_JOIN_01a - Can join stakepool and rejoin" $ \ctx -> runResourceT $ do wa <- fixtureWallet ctx - pool':_ <- map (view #id) . snd <$> unsafeRequest + pool1:pool2:_ <- map (view #id) . snd <$> unsafeRequest @[ApiStakePool] ctx (Link.listStakePools arbitraryStake) Empty let delegation = Json [json|{ "delegations": [{ "join": { - "pool": #{pool'}, + "pool": #{pool1}, "stake_key_index": "0H" } }] @@ -1094,7 +1095,7 @@ spec = describe "NEW_SHELLEY_TRANSACTIONS" $ do let registerStakeKeyCert = WalletDelegationCertificate $ RegisterRewardAccount stakeKeyDerPath let delegatingCert = - WalletDelegationCertificate $ JoinPool stakeKeyDerPath pool' + WalletDelegationCertificate $ JoinPool stakeKeyDerPath pool1 let txCbor = getFromResponse #transaction (HTTP.status202, Right signedTx) let decodePayload = Json (toJSON $ ApiSerialisedTransaction txCbor) @@ -1147,6 +1148,61 @@ spec = describe "NEW_SHELLEY_TRANSACTIONS" $ do (.> (Quantity 0)) ] + eventually "Wallet is delegating to pool1" $ do + request @ApiWallet ctx (Link.getWallet @'Shelley wa) Default Empty + >>= flip verify + [ expectField #delegation (`shouldBe` delegating pool1 []) + ] + + -- join another stake pool + let delegationOther = Json [json|{ + "delegations": [{ + "join": { + "pool": #{pool2}, + "stake_key_index": "0H" + } + }] + }|] + rTx' <- request @(ApiConstructTransaction n) ctx + (Link.createUnsignedTransaction @'Shelley wa) Default delegationOther + verify rTx' + [ expectResponseCode HTTP.status202 + ] + let apiTx' = getFromResponse #transaction rTx' + signedTx' <- signTx ctx wa apiTx' [ expectResponseCode HTTP.status202 ] + let delegatingCert' = + WalletDelegationCertificate $ JoinPool stakeKeyDerPath pool2 + + let txCbor' = getFromResponse #transaction (HTTP.status202, Right signedTx') + let decodePayload' = Json (toJSON $ ApiSerialisedTransaction txCbor') + rDecodedTx' <- request @(ApiDecodedTransaction n) ctx + (Link.decodeTransaction @'Shelley wa) Default decodePayload' + verify rDecodedTx' + [ expectResponseCode HTTP.status202 + , expectField #certificates (`shouldBe` [delegatingCert']) + ] + submittedTx' <- submitTxWithWid ctx wa signedTx' + verify submittedTx' + [ expectSuccess + , expectResponseCode HTTP.status202 + ] + + -- Wait for the certificate to be inserted + eventually "Certificates are inserted" $ do + let ep = Link.listTransactions @'Shelley wa + request @[ApiTransaction n] ctx ep Default Empty >>= flip verify + [ expectListField 1 + (#direction . #getApiT) (`shouldBe` Outgoing) + , expectListField 1 + (#status . #getApiT) (`shouldBe` InLedger) + ] + + eventually "Wallet is delegating to pool2" $ do + request @ApiWallet ctx (Link.getWallet @'Shelley wa) Default Empty + >>= flip verify + [ expectField #delegation (`shouldBe` delegating pool2 []) + ] + it "TRANS_NEW_JOIN_01b - Invalid pool id" $ \ctx -> runResourceT $ do