Skip to content

Commit

Permalink
Merge pull request #6026 from IntersectMBO/mgalazyn/test/add-checks-f…
Browse files Browse the repository at this point in the history
…or-stake-regi-deregistration-test

cardano-testnet | Add verification check in stake registration/deregistration test
  • Loading branch information
carbolymer authored Nov 12, 2024
2 parents 85e3898 + eb09bcf commit 9dbf0b1
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
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

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)

0 comments on commit 9dbf0b1

Please sign in to comment.