Skip to content

Commit 9dbf0b1

Browse files
authored
Merge pull request #6026 from IntersectMBO/mgalazyn/test/add-checks-for-stake-regi-deregistration-test
cardano-testnet | Add verification check in stake registration/deregistration test
2 parents 85e3898 + eb09bcf commit 9dbf0b1

File tree

3 files changed

+54
-3
lines changed

3 files changed

+54
-3
lines changed

cardano-testnet/src/Testnet/Components/Query.hs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ module Testnet.Components.Query
3838
, assertNewEpochState
3939
, getGovActionLifetime
4040
, getKeyDeposit
41+
, getDelegationState
4142
) where
4243

4344
import Cardano.Api as Api
@@ -51,6 +52,7 @@ import qualified Cardano.Ledger.Coin as L
5152
import qualified Cardano.Ledger.Conway.Governance as L
5253
import qualified Cardano.Ledger.Conway.PParams as L
5354
import qualified Cardano.Ledger.Shelley.LedgerState as L
55+
import qualified Cardano.Ledger.UMap as L
5456
import qualified Cardano.Ledger.UTxO as L
5557

5658
import Control.Exception.Safe (MonadCatch)
@@ -590,3 +592,19 @@ getKeyDeposit epochStateView ceo = conwayEraOnwardsConstraints ceo $ do
590592
return $ govState ^. L.cgsCurPParamsL
591593
. L.ppKeyDepositL
592594

595+
596+
-- | Returns delegation state from the epoch state.
597+
getDelegationState :: (H.MonadAssertion m, MonadTest m, MonadIO m)
598+
=> EpochStateView
599+
-> m (L.StakeCredentials StandardCrypto)
600+
getDelegationState epochStateView = do
601+
AnyNewEpochState sbe newEpochState <- getEpochState epochStateView
602+
let pools = shelleyBasedEraConstraints sbe $ newEpochState
603+
^. L.nesEsL
604+
. L.esLStateL
605+
. L.lsCertStateL
606+
. L.certDStateL
607+
. L.dsUnifiedL
608+
609+
pure $ L.toStakeCredentials pools
610+

cardano-testnet/src/Testnet/Process/Cli/SPO.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ checkStakePoolRegistered
5252
:: (MonadTest m, MonadCatch m, MonadIO m, HasCallStack)
5353
=> TmpAbsolutePath
5454
-> ExecConfig
55-
-> File (VKey StakeKey) In -- ^ Stake pool cold verification key file
55+
-> File (VKey StakePoolKey) In -- ^ Stake pool cold verification key file
5656
-> FilePath -- ^ Output file path of stake pool info
5757
-> m String -- ^ Stake pool ID
5858
checkStakePoolRegistered tempAbsP execConfig (File poolColdVkeyFp) outputFp =
@@ -251,7 +251,7 @@ registerSingleSpo
251251
-> ExecConfig
252252
-> (TxIn, File (SKey PaymentKey) In, String)
253253
-> m ( String
254-
, KeyPair StakeKey
254+
, KeyPair StakePoolKey
255255
, KeyPair VrfKey
256256
) -- ^ Result tuple:
257257
-- 1. String: Registered stake pool ID

cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Transaction/RegisterDeregisterStakeAddress.hs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,17 @@ module Cardano.Testnet.Test.Cli.Transaction.RegisterDeregisterStakeAddress
99
) where
1010

1111
import Cardano.Api as Api
12+
import Cardano.Api.Address (StakeCredential (..), toShelleyStakeCredential)
1213

14+
import Cardano.CLI.Types.Key (SomeSigningKey (AStakeSigningKey))
15+
import qualified Cardano.Ledger.UMap as L
1316
import Cardano.Testnet
1417

1518
import Prelude
1619

1720
import Control.Monad
1821
import Data.Default.Class
22+
import qualified Data.Map as M
1923
import qualified Data.Text as Text
2024
import System.FilePath ((</>))
2125

@@ -30,6 +34,7 @@ import Testnet.Start.Types
3034
import Testnet.Types
3135

3236
import Hedgehog
37+
import qualified Hedgehog as H
3338
import qualified Hedgehog.Extras as H
3439

3540
-- | Execute me with:
@@ -75,11 +80,20 @@ hprop_tx_register_deregister_stake_address = integrationWorkspace "register-dere
7580
stakeKeys = KeyPair { verificationKey = File $ work </> "stake.vkey"
7681
, signingKey = File $ work </> "stake.skey"
7782
}
83+
7884
cliStakeAddressKeyGen stakeKeys
7985
keyDeposit <- getKeyDeposit epochStateView ceo
8086
createStakeKeyRegistrationCertificate
8187
tempAbsPath (AnyShelleyBasedEra sbe) (verificationKey stakeKeys) keyDeposit stakeCertFp
8288

89+
-- obtain stake key hash as ledger's Credential
90+
AStakeSigningKey key <- H.leftFailM . H.evalIO $
91+
readKeyFileAnyOf
92+
[FromSomeType (AsSigningKey AsStakeKey) AStakeSigningKey]
93+
[FromSomeType (AsSigningKey AsStakeKey) AStakeSigningKey]
94+
(signingKey stakeKeys)
95+
stakeKeyHash <- H.noteShow . toShelleyStakeCredential . StakeCredentialByKey . verificationKeyHash $ getVerificationKey key
96+
8397
stakeCertTxBodyFp <- H.note $ work </> "stake.registration.txbody"
8498
stakeCertTxSignedFp <- H.note $ work </> "stake.registration.tx"
8599

@@ -105,12 +119,23 @@ hprop_tx_register_deregister_stake_address = integrationWorkspace "register-dere
105119
, "--out-file", stakeCertTxSignedFp
106120
]
107121

122+
H.note_ "Check that stake address isn't registered yet"
123+
getDelegationState epochStateView >>=
124+
flip H.assertWith
125+
(M.notMember stakeKeyHash . L.scDeposits)
126+
108127
void $ execCli' execConfig
109128
[ eraName, "transaction", "submit"
110129
, "--tx-file", stakeCertTxSignedFp
111130
]
112131

113-
H.noteShowM_ $ waitForBlocks epochStateView 1
132+
133+
_ <- waitForBlocks epochStateView 1
134+
135+
H.note_ "Check that stake address is registered"
136+
getDelegationState epochStateView >>=
137+
flip H.assertWith
138+
(M.member stakeKeyHash . L.scDeposits)
114139

115140
-- deregister stake address
116141
createStakeKeyDeregistrationCertificate
@@ -145,3 +170,11 @@ hprop_tx_register_deregister_stake_address = integrationWorkspace "register-dere
145170
[ eraName, "transaction", "submit"
146171
, "--tx-file", stakeCertDeregTxSignedFp
147172
]
173+
174+
_ <- waitForBlocks epochStateView 1
175+
176+
H.note_ "Check that stake address is deregistered"
177+
getDelegationState epochStateView >>=
178+
flip H.assertWith
179+
(M.notMember stakeKeyHash . L.scDeposits)
180+

0 commit comments

Comments
 (0)