Skip to content

Commit

Permalink
Refactor: Remove SomeKeyPair
Browse files Browse the repository at this point in the history
  • Loading branch information
carbolymer committed Oct 22, 2024
1 parent 9ba52c1 commit f447036
Show file tree
Hide file tree
Showing 14 changed files with 56 additions and 49 deletions.
9 changes: 5 additions & 4 deletions cardano-testnet/src/Testnet/Process/Cli/DRep.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module Testnet.Process.Cli.DRep
) where

import Cardano.Api hiding (Certificate, TxBody)
import Cardano.Api.Experimental (Some (..))
import Cardano.Api.Ledger (EpochInterval (EpochInterval, unEpochInterval))

import Cardano.Testnet (maybeExtractGovernanceActionIndex)
Expand Down Expand Up @@ -239,7 +240,7 @@ registerDRep execConfig epochStateView ceo work prefix wallet = do
drepRegTxBody <- createCertificatePublicationTxBody execConfig epochStateView sbe baseDir "reg-cert-txbody"
drepRegCert wallet
drepSignedRegTx <- signTx execConfig cEra baseDir "signed-reg-tx"
drepRegTxBody [SomeKeyPair drepKeyPair, SomeKeyPair $ paymentKeyInfoPair wallet]
drepRegTxBody [Some drepKeyPair, Some $ paymentKeyInfoPair wallet]
submitTx execConfig cEra drepSignedRegTx

return drepKeyPair
Expand Down Expand Up @@ -286,8 +287,8 @@ delegateToDRep execConfig epochStateView sbe work prefix

-- Sign transaction
repRegSignedRegTx1 <- signTx execConfig cEra baseDir "signed-reg-tx"
repRegTxBody1 [ SomeKeyPair $ paymentKeyInfoPair payingWallet
, SomeKeyPair skeyPair]
repRegTxBody1 [ Some $ paymentKeyInfoPair payingWallet
, Some skeyPair]

-- Submit transaction
submitTx execConfig cEra repRegSignedRegTx1
Expand Down Expand Up @@ -398,7 +399,7 @@ makeActivityChangeProposal execConfig epochStateView ceo work
]

signedProposalTx <- signTx execConfig cEra baseDir "signed-proposal"
(File proposalBody) [SomeKeyPair $ paymentKeyInfoPair wallet]
(File proposalBody) [Some $ paymentKeyInfoPair wallet]

submitTx execConfig cEra signedProposalTx

Expand Down
5 changes: 3 additions & 2 deletions cardano-testnet/src/Testnet/Process/Cli/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module Testnet.Process.Cli.Transaction
) where

import Cardano.Api hiding (Certificate, TxBody)
import Cardano.Api.Experimental (Some (..))
import Cardano.Api.Ledger (Coin (unCoin))

import Prelude
Expand Down Expand Up @@ -146,14 +147,14 @@ signTx
-> FilePath -- ^ Base directory path where the signed transaction file will be stored.
-> String -- ^ Prefix for the output signed transaction file name. The extension will be @.tx@.
-> File TxBody In -- ^ Transaction body to be signed, obtained using 'createCertificatePublicationTxBody' or similar.
-> [SomeKeyPair] -- ^ List of key pairs used for signing the transaction.
-> [Some KeyPair] -- ^ List of key pairs used for signing the transaction.
-> m (File SignedTx In)
signTx execConfig cEra work prefix txBody signatoryKeyPairs = do
let signedTx = File (work </> prefix <> ".tx")
void $ execCli' execConfig $
[ anyEraToString cEra, "transaction", "sign"
, "--tx-body-file", unFile txBody
] ++ (concat [["--signing-key-file", signingKeyFp kp] | SomeKeyPair kp <- signatoryKeyPairs]) ++
] ++ (concat [["--signing-key-file", signingKeyFp kp] | Some kp <- signatoryKeyPairs]) ++
[ "--out-file", unFile signedTx
]
return signedTx
Expand Down
4 changes: 0 additions & 4 deletions cardano-testnet/src/Testnet/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ module Testnet.Types
, KeyPair(..)
, verificationKeyFp
, signingKeyFp
, SomeKeyPair(..)
, VKey
, SKey
, VrfKey
Expand Down Expand Up @@ -97,9 +96,6 @@ verificationKeyFp = unFile . verificationKey
signingKeyFp :: KeyPair k -> FilePath
signingKeyFp = unFile . signingKey

data SomeKeyPair = forall a. SomeKeyPair (KeyPair a)
deriving instance Show SomeKeyPair

-- | Verification key tag
data VKey k

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ hprop_kes_period_info = integrationRetryWorkspace 2 "kes-period-info" $ \tempAbs
let node1SocketPath = Api.File $ IO.sprocketSystemName node1sprocket
termEpoch = EpochNo 3
epochStateView <- getEpochStateView configurationFile node1SocketPath
(stakePoolId, stakePoolColdSigningKey, stakePoolColdVKey, _, _)
(stakePoolId, KeyPair{signingKey=File stakePoolColdSigningKey, verificationKey=File stakePoolColdVKey}, _)
<- registerSingleSpo asbe 1 tempAbsPath
configurationFile
node1SocketPath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ hprop_leadershipSchedule = integrationRetryWorkspace 2 "leadership-schedule" $ \
let node1SocketPath = Api.File $ IO.sprocketSystemName node1sprocket
termEpoch = EpochNo 15
epochStateView <- getEpochStateView configurationFile node1SocketPath
(stakePoolIdNewSpo, stakePoolColdSigningKey, stakePoolColdVKey, vrfSkey, _)
(stakePoolIdNewSpo, KeyPair{signingKey=File stakePoolColdSigningKey, verificationKey=File stakePoolColdVKey}, KeyPair{signingKey=File vrfSkey})
<- registerSingleSpo asbe 1 tempAbsPath
configurationFile
node1SocketPath
Expand All @@ -117,30 +117,32 @@ hprop_leadershipSchedule = integrationRetryWorkspace 2 "leadership-schedule" $ \
let testStakeDelegator = work </> "test-delegator"

H.createDirectoryIfMissing_ testStakeDelegator
let testDelegatorVkeyFp = testStakeDelegator </> "test-delegator.vkey"
testDelegatorSKeyFp = testStakeDelegator </> "test-delegator.skey"
testDelegatorPaymentVKeyFp = testStakeDelegator </> "test-delegator-payment.vkey"
testDelegatorPaymentSKeyFp = testStakeDelegator </> "test-delegator-payment.skey"
let testDelegatorKeys = KeyPair
{ signingKey = File $ testStakeDelegator </> "test-delegator.skey"
, verificationKey = File $ testStakeDelegator </> "test-delegator.vkey"
}
testDelegatorPaymentKeys = KeyPair
{ signingKey = File $ testStakeDelegator </> "test-delegator-payment.skey"
, verificationKey = File $ testStakeDelegator </> "test-delegator-payment.vkey"
}
testDelegatorRegCertFp = testStakeDelegator </> "test-delegator.regcert"
testDelegatorDelegCert = testStakeDelegator </> "test-delegator.delegcert"

cliStakeAddressKeyGen
$ KeyPair (File testDelegatorVkeyFp) (File testDelegatorSKeyFp)
cliAddressKeyGen
$ KeyPair (File testDelegatorPaymentVKeyFp) (File testDelegatorPaymentSKeyFp)
cliStakeAddressKeyGen testDelegatorKeys
cliAddressKeyGen testDelegatorPaymentKeys

-- NB: We must include the stake credential
testDelegatorPaymentAddr <- execCli
[ "latest", "address", "build"
, "--testnet-magic", show @Int testnetMagic
, "--payment-verification-key-file", testDelegatorPaymentVKeyFp
, "--stake-verification-key-file", testDelegatorVkeyFp
, "--payment-verification-key-file", verificationKeyFp testDelegatorPaymentKeys
, "--stake-verification-key-file", verificationKeyFp testDelegatorKeys
]
testDelegatorStakeAddress
<- filter (/= '\n')
<$> execCli
[ "latest", "stake-address", "build"
, "--stake-verification-key-file", testDelegatorVkeyFp
, "--stake-verification-key-file", verificationKeyFp testDelegatorKeys
, "--testnet-magic", show @Int testnetMagic
]

Expand All @@ -149,15 +151,15 @@ hprop_leadershipSchedule = integrationRetryWorkspace 2 "leadership-schedule" $ \
createStakeKeyRegistrationCertificate
tempAbsPath
(cardanoNodeEra cTestnetOptions)
testDelegatorVkeyFp
(verificationKey testDelegatorKeys)
keyDeposit
testDelegatorRegCertFp

-- Test stake address deleg cert
createStakeDelegationCertificate
tempAbsPath
sbe
testDelegatorVkeyFp
(verificationKey testDelegatorKeys)
stakePoolIdNewSpo
testDelegatorDelegCert

Expand Down Expand Up @@ -197,7 +199,7 @@ hprop_leadershipSchedule = integrationRetryWorkspace 2 "leadership-schedule" $ \
, "--tx-body-file", delegRegTestDelegatorTxBodyFp
, "--testnet-magic", show @Int testnetMagic
, "--signing-key-file", utxoSKeyFile
, "--signing-key-file", testDelegatorSKeyFp
, "--signing-key-file", signingKeyFp testDelegatorKeys
, "--out-file", delegRegTestDelegatorTxFp
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module Cardano.Testnet.Test.Cli.Query
) where

import Cardano.Api
import Cardano.Api.Experimental (Some (..))
import qualified Cardano.Api.Genesis as Api
import Cardano.Api.Ledger (Coin (Coin), EpochInterval (EpochInterval), StandardCrypto,
extractHash, unboundRational)
Expand All @@ -28,7 +29,6 @@ import qualified Cardano.Ledger.BaseTypes as L
import Cardano.Ledger.Core (valueTxOutL)
import Cardano.Ledger.Shelley.LedgerState (esLStateL, lsUTxOStateL, nesEpochStateL,
utxosUtxoL)
import qualified Cardano.Ledger.TxIn as L
import qualified Cardano.Ledger.UTxO as L
import Cardano.Testnet

Expand Down Expand Up @@ -328,7 +328,7 @@ hprop_cli_queries = integrationWorkspace "cli-queries" $ \tempAbsBasePath' -> H.
-- Now we create a transaction and check if it exists in the mempool
mempoolWork <- H.createDirectoryIfMissing $ work </> "mempool-test"
txBody <- mkSimpleSpendOutputsOnlyTx execConfig epochStateView sbe mempoolWork "tx-body" wallet0 wallet1 10_000_000
signedTx <- signTx execConfig cEra mempoolWork "signed-tx" txBody [SomeKeyPair $ paymentKeyInfoPair wallet0]
signedTx <- signTx execConfig cEra mempoolWork "signed-tx" txBody [Some $ paymentKeyInfoPair wallet0]
submitTx execConfig cEra signedTx
txId <- retrieveTransactionId execConfig signedTx
-- And we check
Expand All @@ -350,7 +350,7 @@ hprop_cli_queries = integrationWorkspace "cli-queries" $ \tempAbsBasePath' -> H.
-- Submit a transaction to publish the reference script
txBody <- mkSpendOutputsOnlyTx execConfig epochStateView sbe refScriptSizeWork "tx-body" wallet1
[(ReferenceScriptAddress plutusV3Script, transferAmount)]
signedTx <- signTx execConfig cEra refScriptSizeWork "signed-tx" txBody [SomeKeyPair $ paymentKeyInfoPair wallet1]
signedTx <- signTx execConfig cEra refScriptSizeWork "signed-tx" txBody [Some $ paymentKeyInfoPair wallet1]
submitTx execConfig cEra signedTx
-- Wait until transaction is on chain and obtain transaction identifier
txId <- retrieveTransactionId execConfig signedTx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module Cardano.Testnet.Test.Gov.CommitteeAddNew
) where

import Cardano.Api as Api
import Cardano.Api.Experimental (Some (..))
import qualified Cardano.Api.Ledger as L
import Cardano.Api.Shelley (ShelleyLedgerEra)

Expand Down Expand Up @@ -214,7 +215,7 @@ hprop_constitutional_committee_add_new = integrationWorkspace "constitutional-co
committeeMembers `H.assertWith` null

signedProposalTx <-
signTx execConfig cEra work "signed-proposal" (File txbodyFp) [SomeKeyPair $ paymentKeyInfoPair wallet0]
signTx execConfig cEra work "signed-proposal" (File txbodyFp) [Some $ paymentKeyInfoPair wallet0]
submitTx execConfig cEra signedProposalTx

governanceActionTxId <- H.noteM $ retrieveTransactionId execConfig signedProposalTx
Expand Down Expand Up @@ -245,7 +246,7 @@ hprop_constitutional_committee_add_new = integrationWorkspace "constitutional-co
, verificationKey = error "unused"
}
drepSKeys = map (defaultDRepKeyPair . snd) drepVotes
signingKeys = SomeKeyPair <$> paymentKeyInfoPair wallet0:poolNodePaymentKeyPair:drepSKeys
signingKeys = Some <$> paymentKeyInfoPair wallet0:poolNodePaymentKeyPair:drepSKeys
voteTxFp <- signTx
execConfig cEra gov "signed-vote-tx" voteTxBodyFp signingKeys

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

import Cardano.Api as Api
import Cardano.Api.Eon.ShelleyBasedEra (ShelleyLedgerEra)
import Cardano.Api.Experimental (Some (..))
import Cardano.Api.Ledger (EpochInterval (EpochInterval, unEpochInterval), drepExpiry)

import Cardano.Ledger.Conway.Core (EraGov, curPParamsGovStateL)
Expand Down Expand Up @@ -286,7 +287,7 @@ voteChangeProposal execConfig epochStateView sbe work prefix governanceActionTxI
voteTxBodyFp <- createVotingTxBody execConfig epochStateView sbe baseDir "vote-tx-body"
voteFiles wallet

let signingKeys = SomeKeyPair <$> (paymentKeyInfoPair wallet:(defaultDRepKeyPair . snd <$> votes))
let signingKeys = Some <$> (paymentKeyInfoPair wallet:(defaultDRepKeyPair . snd <$> votes))
voteTxFp <- signTx execConfig cEra baseDir "signed-vote-tx" voteTxBodyFp signingKeys

submitTx execConfig cEra voteTxFp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module Cardano.Testnet.Test.Gov.DRepDeposit
) where

import Cardano.Api
import Cardano.Api.Experimental (Some (..))
import qualified Cardano.Api.Ledger as L

import Cardano.Testnet
Expand Down Expand Up @@ -84,7 +85,7 @@ hprop_ledger_events_drep_deposits = integrationWorkspace "drep-deposits" $ \temp
drepRegTxBody1 <- createCertificatePublicationTxBody execConfig epochStateView sbe drepDir1 "reg-cert-txbody"
drepRegCert1 wallet0
drepSignedRegTx1 <- signTx execConfig cEra drepDir1 "signed-reg-tx"
drepRegTxBody1 [SomeKeyPair drepKeyPair1, SomeKeyPair $ paymentKeyInfoPair wallet0]
drepRegTxBody1 [Some drepKeyPair1, Some $ paymentKeyInfoPair wallet0]

failToSubmitTx execConfig cEra drepSignedRegTx1 "ConwayDRepIncorrectDeposit"

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

import Cardano.Api as Api
import Cardano.Api.Experimental (Some (..))
import Cardano.Api.Ledger
import Cardano.Api.Shelley

Expand Down Expand Up @@ -184,7 +185,7 @@ hprop_gov_no_confidence = integrationWorkspace "no-confidence" $ \tempAbsBasePat
]

signedProposalTx <- signTx execConfig cEra work "signed-proposal"
(File txbodyFp) [SomeKeyPair $ paymentKeyInfoPair wallet0]
(File txbodyFp) [Some $ paymentKeyInfoPair wallet0]

submitTx execConfig cEra signedProposalTx

Expand Down Expand Up @@ -216,12 +217,12 @@ hprop_gov_no_confidence = integrationWorkspace "no-confidence" $ \tempAbsBasePat
-- Submit votes
voteTxBodyFp <- DRep.createVotingTxBody execConfig epochStateView sbe work "vote-tx-body"
allVoteFiles wallet0
let spoSigningKeys = [SomeKeyPair $ defaultSpoColdKeyPair n | (_, n) <- spoVotes]
drepSigningKeys = [SomeKeyPair $ defaultDRepKeyPair n | (_, n) <- drepVotes]
let spoSigningKeys = [Some $ defaultSpoColdKeyPair n | (_, n) <- spoVotes]
drepSigningKeys = [Some $ defaultDRepKeyPair n | (_, n) <- drepVotes]
allVoteSigningKeys = spoSigningKeys ++ drepSigningKeys

voteTxFp <- signTx execConfig cEra work "signed-vote-tx" voteTxBodyFp
(SomeKeyPair (paymentKeyInfoPair wallet0) : allVoteSigningKeys)
(Some (paymentKeyInfoPair wallet0) : allVoteSigningKeys)

submitTx execConfig cEra voteTxFp

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

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

import Cardano.Testnet
Expand Down Expand Up @@ -180,7 +181,7 @@ failToVoteChangeProposalWithSPOs ceo execConfig epochStateView work prefix
voteTxBodyFp <- createVotingTxBody execConfig epochStateView sbe baseDir "vote-tx-body"
voteFiles wallet

let signingKeys = SomeKeyPair (paymentKeyInfoPair wallet):(SomeKeyPair . defaultSpoColdKeyPair . snd <$> votes)
let signingKeys = Some (paymentKeyInfoPair wallet):(Some . defaultSpoColdKeyPair . snd <$> votes)
voteTxFp <- signTx execConfig cEra baseDir "signed-vote-tx" voteTxBodyFp signingKeys

failToSubmitTx execConfig cEra voteTxFp "DisallowedVoters"
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module Cardano.Testnet.Test.Gov.PredefinedAbstainDRep

import Cardano.Api as Api
import Cardano.Api.Eon.ShelleyBasedEra (ShelleyLedgerEra)
import Cardano.Api.Experimental (Some (..))
import Cardano.Api.Ledger (EpochInterval (EpochInterval))

import Cardano.Ledger.Conway.Core (ppNOptL)
Expand Down Expand Up @@ -42,8 +43,7 @@ import qualified Testnet.Process.Run as H
import qualified Testnet.Property.Util as H
import Testnet.Start.Types
import Testnet.Types (KeyPair (..),
PaymentKeyInfo (paymentKeyInfoAddr, paymentKeyInfoPair),
SomeKeyPair (SomeKeyPair), StakingKey)
PaymentKeyInfo (paymentKeyInfoAddr, paymentKeyInfoPair), StakingKey)

import Hedgehog
import qualified Hedgehog.Extras as H
Expand Down Expand Up @@ -158,8 +158,8 @@ delegateToAlwaysAbstain execConfig epochStateView sbe work prefix

-- Sign transaction
repRegSignedRegTx1 <- signTx execConfig cEra baseDir "signed-reg-tx"
repRegTxBody1 [ SomeKeyPair (paymentKeyInfoPair payingWallet)
, SomeKeyPair skeyPair]
repRegTxBody1 [ Some (paymentKeyInfoPair payingWallet)
, Some skeyPair]

-- Submit transaction
submitTx execConfig cEra repRegSignedRegTx1
Expand Down Expand Up @@ -281,7 +281,7 @@ makeDesiredPoolNumberChangeProposal execConfig epochStateView ceo work prefix
]

signedProposalTx <- signTx execConfig cEra baseDir "signed-proposal"
(File proposalBody) [SomeKeyPair $ paymentKeyInfoPair wallet]
(File proposalBody) [Some $ paymentKeyInfoPair wallet]

submitTx execConfig cEra signedProposalTx

Expand Down Expand Up @@ -326,7 +326,7 @@ voteChangeProposal execConfig epochStateView sbe work prefix
voteFiles wallet

voteTxFp <- signTx execConfig cEra baseDir "signed-vote-tx" voteTxBodyFp
(SomeKeyPair (paymentKeyInfoPair wallet):[SomeKeyPair $ defaultDRepKeyPair n | (_, n) <- votes])
(Some (paymentKeyInfoPair wallet):[Some $ defaultDRepKeyPair n | (_, n) <- votes])
submitTx execConfig cEra voteTxFp

-- | Obtains the @desiredPoolNumberValue@ from the protocol parameters.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module Cardano.Testnet.Test.Gov.ProposeNewConstitution
) where

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

import qualified Cardano.Crypto.Hash as L
Expand Down Expand Up @@ -199,7 +200,7 @@ hprop_ledger_events_propose_new_constitution = integrationWorkspace "propose-new
]

signedProposalTx <- signTx execConfig cEra gov "signed-proposal"
(File txbodyFp) [SomeKeyPair $ paymentKeyInfoPair wallet1]
(File txbodyFp) [Some $ paymentKeyInfoPair wallet1]

submitTx execConfig cEra signedProposalTx

Expand All @@ -218,7 +219,7 @@ hprop_ledger_events_propose_new_constitution = integrationWorkspace "propose-new
voteTxBodyFp <- createVotingTxBody execConfig epochStateView sbe work "vote-tx-body"
voteFiles wallet0

let signingKeys = SomeKeyPair <$> (paymentKeyInfoPair wallet0:(defaultDRepKeyPair . snd <$> allVotes))
let signingKeys = Some <$> (paymentKeyInfoPair wallet0:(defaultDRepKeyPair . snd <$> allVotes))
voteTxFp <- signTx execConfig cEra gov "signed-vote-tx" voteTxBodyFp signingKeys

submitTx execConfig cEra voteTxFp
Expand Down
Loading

0 comments on commit f447036

Please sign in to comment.