From eb09bcf57e557aa3b4a3a461177ba43cf121e250 Mon Sep 17 00:00:00 2001 From: Mateusz Galazyn Date: Tue, 29 Oct 2024 18:17:18 +0100 Subject: [PATCH] cardano-testnet | Add verification check in stake registration/deregistration test --- .../src/Testnet/Components/Query.hs | 18 ++++++++++ .../src/Testnet/Process/Cli/SPO.hs | 4 +-- .../RegisterDeregisterStakeAddress.hs | 35 ++++++++++++++++++- 3 files changed, 54 insertions(+), 3 deletions(-) diff --git a/cardano-testnet/src/Testnet/Components/Query.hs b/cardano-testnet/src/Testnet/Components/Query.hs index b17d5a04641..4977c04d37f 100644 --- a/cardano-testnet/src/Testnet/Components/Query.hs +++ b/cardano-testnet/src/Testnet/Components/Query.hs @@ -38,6 +38,7 @@ module Testnet.Components.Query , assertNewEpochState , getGovActionLifetime , getKeyDeposit + , getDelegationState ) where import Cardano.Api as Api @@ -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) @@ -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 + diff --git a/cardano-testnet/src/Testnet/Process/Cli/SPO.hs b/cardano-testnet/src/Testnet/Process/Cli/SPO.hs index e2e7ebc2887..aa916d3f30a 100644 --- a/cardano-testnet/src/Testnet/Process/Cli/SPO.hs +++ b/cardano-testnet/src/Testnet/Process/Cli/SPO.hs @@ -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 = @@ -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 diff --git a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Transaction/RegisterDeregisterStakeAddress.hs b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Transaction/RegisterDeregisterStakeAddress.hs index c86946976ae..53b36186c7a 100644 --- a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Transaction/RegisterDeregisterStakeAddress.hs +++ b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Transaction/RegisterDeregisterStakeAddress.hs @@ -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 (()) @@ -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: @@ -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" @@ -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 @@ -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) +