Skip to content

Commit

Permalink
cardano-testnet | Refactor: use function for creating registration ce…
Browse files Browse the repository at this point in the history
…rtificate
  • Loading branch information
carbolymer committed Oct 24, 2024
1 parent 7b1b9b1 commit a3bb676
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 186 deletions.
8 changes: 4 additions & 4 deletions cardano-testnet/src/Testnet/Process/Cli/SPO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,10 @@ createScriptStakeRegistrationCertificate
=> TmpAbsolutePath
-> AnyCardanoEra
-> FilePath -- ^ Script file
-> Int -- ^ Registration deposit amount used only in Conway
-> L.Coin -- ^ Registration deposit amount used only in Conway
-> FilePath -- ^ Output file path
-> m ()
createScriptStakeRegistrationCertificate tempAbsP (AnyCardanoEra cEra) scriptFile deposit outputFp =
createScriptStakeRegistrationCertificate tempAbsP (AnyCardanoEra cEra) scriptFile (L.Coin deposit) outputFp =
GHC.withFrozenCallStack $ do
let tempAbsPath' = unTmpAbsPath tempAbsP
extraArgs = monoidForEraInEon @ConwayEraOnwards cEra $
Expand All @@ -221,10 +221,10 @@ createStakeKeyDeregistrationCertificate
=> TmpAbsolutePath
-> ShelleyBasedEra era
-> File (VKey StakeKey) In -- ^ Stake verification key file
-> Int -- ^ deposit amount used only in Conway
-> L.Coin -- ^ deposit amount used only in Conway
-> FilePath -- ^ Output file path
-> m ()
createStakeKeyDeregistrationCertificate tempAbsP sbe (File stakeVerKey) deposit outputFp =
createStakeKeyDeregistrationCertificate tempAbsP sbe (File stakeVerKey) (L.Coin deposit) outputFp =
GHC.withFrozenCallStack $ do
let tempAbsPath' = unTmpAbsPath tempAbsP
extraArgs = monoidForEraInEon @ConwayEraOnwards (toCardanoEra sbe) $
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,21 @@ module Cardano.Testnet.Test.Cli.Transaction.RegisterDeregisterStakeAddress
) where

import Cardano.Api as Api
import Cardano.Api.Ledger (Coin (..), EpochInterval (..))

import qualified Cardano.Crypto.Hash as L
import qualified Cardano.Ledger.Conway.Governance as L
import qualified Cardano.Ledger.Conway.Governance as Ledger
import qualified Cardano.Ledger.Hashes as L
import qualified Cardano.Ledger.Shelley.LedgerState as L
import Cardano.Testnet

import Prelude

import Control.Monad
import Control.Monad.State.Strict (StateT)
import Data.Default.Class
import Data.Maybe
import Data.Maybe.Strict
import Data.String
import qualified Data.Text as Text
import GHC.Exts (IsList (..))
import Lens.Micro
import System.FilePath ((</>))

import Testnet.Components.Configuration
import Testnet.Components.Query
import Testnet.Defaults
import Testnet.EpochStateProcessing (waitForGovActionVotes)
import Testnet.Process.Cli.DRep
import Testnet.Process.Cli.Keys
import Testnet.Process.Cli.Transaction
import Testnet.Process.Cli.SPO (createStakeKeyDeregistrationCertificate,
createStakeKeyRegistrationCertificate)
import Testnet.Process.Run (execCli', execCliAny, mkExecConfig)
import Testnet.Property.Util (integrationWorkspace)
import Testnet.Start.Types
Expand Down Expand Up @@ -83,33 +69,16 @@ hprop_tx_register_deregister_stake_address = integrationWorkspace "register-dere
H.note_ $ "Socketpath: " <> unFile socketPath
H.note_ $ "Foldblocks config file: " <> unFile configurationFile

-- Create Conway constitution
gov <- H.createDirectoryIfMissing $ work </> "governance"

let stakeVkeyFp = gov </> "stake.vkey"
stakeSKeyFp = gov </> "stake.skey"
stakeCertFp = gov </> "stake.regcert"
stakeCertDeregFp = gov </> "stake.deregcert"
stakeKeys = KeyPair { verificationKey = File stakeVkeyFp
, signingKey = File stakeSKeyFp
}

cliStakeAddressKeyGen stakeKeys

keyDepositStr <- show . unCoin <$> getKeyDeposit epochStateView ceo
-- Register stake address
void $ execCli' execConfig
[ eraName, "stake-address", "registration-certificate"
, "--stake-verification-key-file", stakeVkeyFp
, "--key-reg-deposit-amt", keyDepositStr
, "--out-file", stakeCertFp
]

stakeAddress <- H.noteM $ execCli' execConfig
[ eraName, "stake-address", "build"
, "--stake-verification-key-file", stakeVkeyFp
, "--out-file", "/dev/stdout"
]
let stakeCertFp = work </> "stake.regcert"
stakeCertDeregFp = work </> "stake.deregcert"
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

stakeCertTxBodyFp <- H.note $ work </> "stake.registration.txbody"
stakeCertTxSignedFp <- H.note $ work </> "stake.registration.tx"
Expand All @@ -132,7 +101,7 @@ hprop_tx_register_deregister_stake_address = integrationWorkspace "register-dere
[ eraName, "transaction", "sign"
, "--tx-body-file", stakeCertTxBodyFp
, "--signing-key-file", signingKeyFp $ paymentKeyInfoPair wallet0
, "--signing-key-file", stakeSKeyFp
, "--signing-key-file", signingKeyFp stakeKeys
, "--out-file", stakeCertTxSignedFp
]

Expand All @@ -143,22 +112,9 @@ hprop_tx_register_deregister_stake_address = integrationWorkspace "register-dere

H.noteShowM_ $ waitForBlocks epochStateView 1

do
(_, stdout', stderr') <- execCliAny execConfig
[ eraName, "query", "stake-address-info"
, "--address", stakeAddress
, "--out-file", "/dev/stdout"
]
H.note_ stdout'
H.note_ stderr'

-- deregister stake address
void $ execCli' execConfig
[ eraName, "stake-address", "deregistration-certificate"
, "--stake-verification-key-file", stakeVkeyFp
, "--key-reg-deposit-amt", keyDepositStr
, "--out-file", stakeCertDeregFp
]
createStakeKeyDeregistrationCertificate
tempAbsPath sbe (verificationKey stakeKeys) keyDeposit stakeCertDeregFp

stakeCertDeregTxBodyFp <- H.note $ work </> "stake.deregistration.txbody"
stakeCertDeregTxSignedFp <- H.note $ work </> "stake.deregistration.tx"
Expand All @@ -181,7 +137,7 @@ hprop_tx_register_deregister_stake_address = integrationWorkspace "register-dere
[ eraName, "transaction", "sign"
, "--tx-body-file", stakeCertDeregTxBodyFp
, "--signing-key-file", signingKeyFp $ paymentKeyInfoPair wallet1
, "--signing-key-file", stakeSKeyFp
, "--signing-key-file", signingKeyFp stakeKeys
, "--out-file", stakeCertDeregTxSignedFp
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import Testnet.EpochStateProcessing (waitForGovActionVotes)
import qualified Testnet.Process.Cli.DRep as DRep
import Testnet.Process.Cli.Keys
import qualified Testnet.Process.Cli.SPO as SPO
import Testnet.Process.Cli.SPO (createStakeKeyRegistrationCertificate)
import Testnet.Process.Cli.Transaction
import Testnet.Process.Run (execCli', mkExecConfig)
import Testnet.Property.Util (integrationWorkspace)
Expand Down Expand Up @@ -119,23 +120,16 @@ hprop_constitutional_committee_add_new = integrationWorkspace "constitutional-co

let ccColdSKeyFp n = gov </> "cc-" <> show n <> "-cold.skey"
ccColdVKeyFp n = gov </> "cc-" <> show n <> "-cold.vkey"
stakeVkeyFp = gov </> "stake.vkey"
stakeSKeyFp = gov </> "stake.skey"
stakeCertFp = gov </> "stake.regcert"
stakeKeys = KeyPair { verificationKey = File $ gov </> "stake.vkey"
, signingKey = File $ gov </> "stake.skey"
}

cliStakeAddressKeyGen
$ KeyPair { verificationKey = File stakeVkeyFp
, signingKey = File stakeSKeyFp
}

keyDepositStr <- show . L.unCoin <$> getKeyDeposit epochStateView ceo
-- Register stake address
void $ execCli' execConfig
[ eraName, "stake-address", "registration-certificate"
, "--stake-verification-key-file", stakeVkeyFp
, "--key-reg-deposit-amt", keyDepositStr
, "--out-file", stakeCertFp
]
-- Register new stake address
cliStakeAddressKeyGen stakeKeys
keyDeposit <- getKeyDeposit epochStateView ceo
createStakeKeyRegistrationCertificate
tempAbsPath (AnyShelleyBasedEra sbe) (verificationKey stakeKeys) keyDeposit stakeCertFp

stakeCertTxBodyFp <- H.note $ work </> "stake.registration.txbody"
stakeCertTxSignedFp <- H.note $ work </> "stake.registration.tx"
Expand All @@ -156,7 +150,7 @@ hprop_constitutional_committee_add_new = integrationWorkspace "constitutional-co
[ eraName, "transaction", "sign"
, "--tx-body-file", stakeCertTxBodyFp
, "--signing-key-file", signingKeyFp $ paymentKeyInfoPair wallet1
, "--signing-key-file", stakeSKeyFp
, "--signing-key-file", signingKeyFp stakeKeys
, "--out-file", stakeCertTxSignedFp
]

Expand Down Expand Up @@ -191,7 +185,7 @@ hprop_constitutional_committee_add_new = integrationWorkspace "constitutional-co
, "--anchor-url", "https://tinyurl.com/3wrwb2as"
, "--anchor-data-hash", proposalAnchorDataHash
, "--governance-action-deposit", show minGovActDeposit
, "--deposit-return-stake-verification-key-file", stakeVkeyFp
, "--deposit-return-stake-verification-key-file", verificationKeyFp stakeKeys
, "--threshold", "0.2"
, "--out-file", updateCommitteeFp
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import Testnet.Components.Query
import Testnet.Defaults (defaultDRepKeyPair, defaultDelegatorStakeKeyPair)
import Testnet.Process.Cli.DRep
import Testnet.Process.Cli.Keys (cliStakeAddressKeyGen)
import Testnet.Process.Cli.SPO (createStakeKeyRegistrationCertificate)
import Testnet.Process.Cli.Transaction
import Testnet.Process.Run (execCli', mkExecConfig)
import Testnet.Property.Util (integrationWorkspace)
Expand Down Expand Up @@ -89,23 +90,15 @@ hprop_check_drep_activity = integrationWorkspace "test-activity" $ \tempAbsBaseP

gov <- H.createDirectoryIfMissing $ work </> "governance"

let stakeVkeyFp = gov </> "stake.vkey"
stakeSKeyFp = gov </> "stake.skey"
stakeCertFp = gov </> "stake.regcert"
stakeKeys = KeyPair { verificationKey = File stakeVkeyFp
, signingKey = File stakeSKeyFp
-- Register stake address
let stakeCertFp = gov </> "stake.regcert"
stakeKeys = KeyPair { verificationKey = File $ gov </> "stake.vkey"
, signingKey = File $ gov </> "stake.skey"
}

cliStakeAddressKeyGen stakeKeys

-- Register stake address

void $ execCli' execConfig
[ eraName, "stake-address", "registration-certificate"
, "--stake-verification-key-file", stakeVkeyFp
, "--key-reg-deposit-amt", show @Int 0 -- TODO: why this needs to be 0????
, "--out-file", stakeCertFp
]
keyDeposit <- getKeyDeposit epochStateView ceo
createStakeKeyRegistrationCertificate
tempAbsPath (AnyShelleyBasedEra sbe) (verificationKey stakeKeys) keyDeposit stakeCertFp

stakeCertTxBodyFp <- H.note $ work </> "stake.registration.txbody"
stakeCertTxSignedFp <- H.note $ work </> "stake.registration.tx"
Expand All @@ -126,7 +119,7 @@ hprop_check_drep_activity = integrationWorkspace "test-activity" $ \tempAbsBaseP
[ eraName, "transaction", "sign"
, "--tx-body-file", stakeCertTxBodyFp
, "--signing-key-file", signingKeyFp $ paymentKeyInfoPair wallet1
, "--signing-key-file", stakeSKeyFp
, "--signing-key-file", signingKeyFp stakeKeys
, "--out-file", stakeCertTxSignedFp
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module Cardano.Testnet.Test.Gov.GovActionTimeout
) where

import Cardano.Api as Api
import Cardano.Api.Ledger (Coin (..), EpochInterval (EpochInterval, unEpochInterval))
import Cardano.Api.Ledger (EpochInterval (..))

import Cardano.Testnet

Expand All @@ -26,6 +26,7 @@ import System.FilePath ((</>))
import Testnet.Components.Query
import Testnet.Process.Cli.DRep (makeActivityChangeProposal)
import Testnet.Process.Cli.Keys (cliStakeAddressKeyGen)
import Testnet.Process.Cli.SPO (createStakeKeyRegistrationCertificate)
import Testnet.Process.Run (execCli', mkExecConfig)
import Testnet.Property.Util (integrationWorkspace)
import Testnet.Start.Types
Expand Down Expand Up @@ -85,23 +86,16 @@ hprop_check_gov_action_timeout = integrationWorkspace "gov-action-timeout" $ \te
govActionLifetime <- getGovActionLifetime epochStateView ceo
H.note_ $ "govActionLifetime: " <> show govActionLifetime

let stakeVkeyFp = gov </> "stake.vkey"
stakeSKeyFp = gov </> "stake.skey"
stakeCertFp = gov </> "stake.regcert"
stakeKeys = KeyPair { verificationKey = File stakeVkeyFp
, signingKey = File stakeSKeyFp
}

-- Register stake address
let stakeCertFp = gov </> "stake.regcert"
stakeKeys = KeyPair { verificationKey = File $ gov </> "stake.vkey"
, signingKey = File $ gov </> "stake.skey"
}
cliStakeAddressKeyGen stakeKeys
keyDeposit <- getKeyDeposit epochStateView ceo
createStakeKeyRegistrationCertificate
tempAbsPath (AnyShelleyBasedEra sbe) (verificationKey stakeKeys) keyDeposit stakeCertFp

keyDepositStr <- show . unCoin <$> getKeyDeposit epochStateView ceo
-- Register stake address
void $ execCli' execConfig
[ eraName, "stake-address", "registration-certificate"
, "--stake-verification-key-file", stakeVkeyFp
, "--key-reg-deposit-amt", keyDepositStr
, "--out-file", stakeCertFp
]

stakeCertTxBodyFp <- H.note $ work </> "stake.registration.txbody"
stakeCertTxSignedFp <- H.note $ work </> "stake.registration.tx"
Expand All @@ -122,7 +116,7 @@ hprop_check_gov_action_timeout = integrationWorkspace "gov-action-timeout" $ \te
[ eraName, "transaction", "sign"
, "--tx-body-file", stakeCertTxBodyFp
, "--signing-key-file", signingKeyFp $ paymentKeyInfoPair wallet1
, "--signing-key-file", stakeSKeyFp
, "--signing-key-file", signingKeyFp stakeKeys
, "--out-file", stakeCertTxSignedFp
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module Cardano.Testnet.Test.Gov.InfoAction

import Cardano.Api as Api
import Cardano.Api.Error (displayError)
import Cardano.Api.Ledger (Coin (..), EpochInterval (EpochInterval))
import Cardano.Api.Ledger (EpochInterval (EpochInterval))
import Cardano.Api.Shelley

import Cardano.Ledger.Conway.Governance (RatifyState (..))
Expand All @@ -36,6 +36,7 @@ import System.FilePath ((</>))
import Testnet.Components.Query
import Testnet.Defaults
import Testnet.Process.Cli.Keys
import Testnet.Process.Cli.SPO (createStakeKeyRegistrationCertificate)
import Testnet.Process.Run (execCli', mkExecConfig)
import Testnet.Property.Util (integrationRetryWorkspace)
import Testnet.Start.Types
Expand Down Expand Up @@ -93,23 +94,15 @@ hprop_ledger_events_info_action = integrationRetryWorkspace 2 "info-hash" $ \tem
[ "hash", "anchor-data", "--file-text", proposalAnchorFile
]

let stakeVkeyFp = gov </> "stake.vkey"
stakeSKeyFp = gov </> "stake.skey"
stakeCertFp = gov </> "stake.regcert"
stakeKeys = KeyPair { verificationKey = File stakeVkeyFp
, signingKey = File stakeSKeyFp
-- Register stake address
let stakeCertFp = gov </> "stake.regcert"
stakeKeys = KeyPair { verificationKey = File $ gov </> "stake.vkey"
, signingKey = File $ gov </> "stake.skey"
}

cliStakeAddressKeyGen stakeKeys

-- Register stake address
keyDepositStr <- show . unCoin <$> getKeyDeposit epochStateView ceo
void $ execCli' execConfig
[ eraName, "stake-address", "registration-certificate"
, "--stake-verification-key-file", stakeVkeyFp
, "--key-reg-deposit-amt", keyDepositStr
, "--out-file", stakeCertFp
]
keyDeposit <- getKeyDeposit epochStateView ceo
createStakeKeyRegistrationCertificate
tempAbsPath (AnyShelleyBasedEra sbe) (verificationKey stakeKeys) keyDeposit stakeCertFp

stakeCertTxBodyFp <- H.note $ work </> "stake.registration.txbody"
stakeCertTxSignedFp <- H.note $ work </> "stake.registration.tx"
Expand All @@ -130,7 +123,7 @@ hprop_ledger_events_info_action = integrationRetryWorkspace 2 "info-hash" $ \tem
[ eraName, "transaction", "sign"
, "--tx-body-file", stakeCertTxBodyFp
, "--signing-key-file", signingKeyFp $ paymentKeyInfoPair wallet0
, "--signing-key-file", stakeSKeyFp
, "--signing-key-file", signingKeyFp stakeKeys
, "--out-file", stakeCertTxSignedFp
]

Expand All @@ -145,7 +138,7 @@ hprop_ledger_events_info_action = integrationRetryWorkspace 2 "info-hash" $ \tem
[ eraName, "governance", "action", "create-info"
, "--testnet"
, "--governance-action-deposit", show @Int 1_000_000 -- TODO: Get this from the node
, "--deposit-return-stake-verification-key-file", stakeVkeyFp
, "--deposit-return-stake-verification-key-file", verificationKeyFp stakeKeys
, "--anchor-url", "https://tinyurl.com/3wrwb2as"
, "--anchor-data-hash", proposalAnchorDataHash
, "--out-file", infoActionFp
Expand Down
Loading

0 comments on commit a3bb676

Please sign in to comment.