Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cardano-testnet | Add verification check in stake registration/deregistration test #6026

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions cardano-testnet/src/Testnet/Components/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module Testnet.Components.Query
, assertNewEpochState
, getGovActionLifetime
, getKeyDeposit
, getDelegationState
) where

import Cardano.Api as Api
Expand All @@ -51,6 +52,7 @@ import qualified Cardano.Ledger.Coin as L
import qualified Cardano.Ledger.Conway.Governance as L
import qualified Cardano.Ledger.Conway.PParams as L
import qualified Cardano.Ledger.Shelley.LedgerState as L
import qualified Cardano.Ledger.UMap as L
import qualified Cardano.Ledger.UTxO as L

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


-- | Returns delegation state from the epoch state.
getDelegationState :: (H.MonadAssertion m, MonadTest m, MonadIO m)
=> EpochStateView
-> m (L.StakeCredentials StandardCrypto)
getDelegationState epochStateView = do
AnyNewEpochState sbe newEpochState <- getEpochState epochStateView
let pools = shelleyBasedEraConstraints sbe $ newEpochState
^. L.nesEsL
. L.esLStateL
. L.lsCertStateL
. L.certDStateL
. L.dsUnifiedL

pure $ L.toStakeCredentials pools
Comment on lines +607 to +609
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
. L.dsUnifiedL
pure $ L.toStakeCredentials pools
. L.dsUnifiedL
pure $ L.toStakeCredentials pools

Rationale: being a challenger in nitpick of the year category 😆

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we have a leaderbard?


4 changes: 2 additions & 2 deletions cardano-testnet/src/Testnet/Process/Cli/SPO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ checkStakePoolRegistered
:: (MonadTest m, MonadCatch m, MonadIO m, HasCallStack)
=> TmpAbsolutePath
-> ExecConfig
-> File (VKey StakeKey) In -- ^ Stake pool cold verification key file
-> File (VKey StakePoolKey) In -- ^ Stake pool cold verification key file
-> FilePath -- ^ Output file path of stake pool info
-> m String -- ^ Stake pool ID
checkStakePoolRegistered tempAbsP execConfig (File poolColdVkeyFp) outputFp =
Expand Down Expand Up @@ -251,7 +251,7 @@ registerSingleSpo
-> ExecConfig
-> (TxIn, File (SKey PaymentKey) In, String)
-> m ( String
, KeyPair StakeKey
, KeyPair StakePoolKey
, KeyPair VrfKey
) -- ^ Result tuple:
-- 1. String: Registered stake pool ID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ module Cardano.Testnet.Test.Cli.Transaction.RegisterDeregisterStakeAddress
) where

import Cardano.Api as Api
import Cardano.Api.Address (StakeCredential (..), toShelleyStakeCredential)

import Cardano.CLI.Types.Key (SomeSigningKey (AStakeSigningKey))
import qualified Cardano.Ledger.UMap as L
import Cardano.Testnet

import Prelude

import Control.Monad
import Data.Default.Class
import qualified Data.Map as M
import qualified Data.Text as Text
import System.FilePath ((</>))

Expand All @@ -30,6 +34,7 @@ import Testnet.Start.Types
import Testnet.Types

import Hedgehog
import qualified Hedgehog as H
import qualified Hedgehog.Extras as H

-- | Execute me with:
Expand Down Expand Up @@ -75,11 +80,20 @@ hprop_tx_register_deregister_stake_address = integrationWorkspace "register-dere
stakeKeys = KeyPair { verificationKey = File $ work </> "stake.vkey"
, signingKey = File $ work </> "stake.skey"
}

cliStakeAddressKeyGen stakeKeys
keyDeposit <- getKeyDeposit epochStateView ceo
createStakeKeyRegistrationCertificate
tempAbsPath (AnyShelleyBasedEra sbe) (verificationKey stakeKeys) keyDeposit stakeCertFp

-- obtain stake key hash as ledger's Credential
AStakeSigningKey key <- H.leftFailM . H.evalIO $
readKeyFileAnyOf
[FromSomeType (AsSigningKey AsStakeKey) AStakeSigningKey]
[FromSomeType (AsSigningKey AsStakeKey) AStakeSigningKey]
(signingKey stakeKeys)
stakeKeyHash <- H.noteShow . toShelleyStakeCredential . StakeCredentialByKey . verificationKeyHash $ getVerificationKey key

stakeCertTxBodyFp <- H.note $ work </> "stake.registration.txbody"
stakeCertTxSignedFp <- H.note $ work </> "stake.registration.tx"

Expand All @@ -105,12 +119,23 @@ hprop_tx_register_deregister_stake_address = integrationWorkspace "register-dere
, "--out-file", stakeCertTxSignedFp
]

H.note_ "Check that stake address isn't registered yet"
getDelegationState epochStateView >>=
flip H.assertWith
(M.notMember stakeKeyHash . L.scDeposits)

void $ execCli' execConfig
[ eraName, "transaction", "submit"
, "--tx-file", stakeCertTxSignedFp
]

H.noteShowM_ $ waitForBlocks epochStateView 1

_ <- waitForBlocks epochStateView 1

H.note_ "Check that stake address is registered"
getDelegationState epochStateView >>=
flip H.assertWith
(M.member stakeKeyHash . L.scDeposits)

-- deregister stake address
createStakeKeyDeregistrationCertificate
Expand Down Expand Up @@ -145,3 +170,11 @@ hprop_tx_register_deregister_stake_address = integrationWorkspace "register-dere
[ eraName, "transaction", "submit"
, "--tx-file", stakeCertDeregTxSignedFp
]

_ <- waitForBlocks epochStateView 1

H.note_ "Check that stake address is deregistered"
getDelegationState epochStateView >>=
flip H.assertWith
(M.notMember stakeKeyHash . L.scDeposits)

Loading