Skip to content

Commit

Permalink
cardano-testnet | Add verification check in stake registration/deregi…
Browse files Browse the repository at this point in the history
…stration test
  • Loading branch information
carbolymer committed Oct 29, 2024
1 parent 02cd604 commit 6e2dd65
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
16 changes: 16 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,17 @@ getKeyDeposit epochStateView ceo = conwayEraOnwardsConstraints ceo $ do
return $ govState ^. L.cgsCurPParamsL
. L.ppKeyDepositL


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
6 changes: 3 additions & 3 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 @@ -181,7 +181,7 @@ createStakeKeyRegistrationCertificate
-> AnyShelleyBasedEra
-> File (VKey StakeKey) In -- ^ Stake verification key file
-> L.Coin -- ^ deposit amount used only in Conway
-> FilePath -- ^ Output file path
-> FilePath -- ^ Output file p ath
-> m ()
createStakeKeyRegistrationCertificate tempAbsP (AnyShelleyBasedEra sbe) (File stakeVerKey) (L.Coin deposit) outputFp = GHC.withFrozenCallStack $ do
let tempAbsPath' = unTmpAbsPath tempAbsP
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
(\L.StakeCredentials{L.scDeposits} -> M.notMember stakeKeyHash 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
(\L.StakeCredentials{L.scDeposits} -> M.member stakeKeyHash scDeposits)

-- deregister stake address
createStakeKeyDeregistrationCertificate
Expand Down Expand Up @@ -145,3 +170,10 @@ 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
(\L.StakeCredentials{L.scDeposits} -> M.notMember stakeKeyHash scDeposits)

0 comments on commit 6e2dd65

Please sign in to comment.