diff --git a/cardano-testnet/cardano-testnet.cabal b/cardano-testnet/cardano-testnet.cabal index 4b6414a9214..a3e03a4fccb 100644 --- a/cardano-testnet/cardano-testnet.cabal +++ b/cardano-testnet/cardano-testnet.cabal @@ -108,6 +108,7 @@ library Testnet.Start.Byron Testnet.Start.Types Testnet.SubmitApi + Testnet.Types other-modules: Parsers.Cardano Parsers.Help @@ -185,8 +186,6 @@ test-suite cardano-testnet-test Cardano.Testnet.Test.Cli.Query Cardano.Testnet.Test.Cli.QuerySlotNumber Cardano.Testnet.Test.FoldEpochState - Cardano.Testnet.Test.Misc - Cardano.Testnet.Test.Gov.DRepActivity Cardano.Testnet.Test.Gov.DRepDeposit Cardano.Testnet.Test.Gov.DRepRetirement @@ -195,9 +194,9 @@ test-suite cardano-testnet-test Cardano.Testnet.Test.Gov.ProposeNewConstitutionSPO Cardano.Testnet.Test.Gov.TreasuryGrowth Cardano.Testnet.Test.Gov.TreasuryWithdrawal - Cardano.Testnet.Test.SanityCheck - + Cardano.Testnet.Test.Misc Cardano.Testnet.Test.Node.Shutdown + Cardano.Testnet.Test.SanityCheck Cardano.Testnet.Test.SubmitApi.Babbage.Transaction type: exitcode-stdio-1.0 diff --git a/cardano-testnet/src/Cardano/Testnet.hs b/cardano-testnet/src/Cardano/Testnet.hs index 602173c79e7..052943262ea 100644 --- a/cardano-testnet/src/Cardano/Testnet.hs +++ b/cardano-testnet/src/Cardano/Testnet.hs @@ -48,6 +48,6 @@ import Testnet.EpochStateProcessing import Testnet.Filepath import Testnet.Process.Run (procChairman) import Testnet.Property.Util -import Testnet.Runtime import Testnet.Start.Cardano import Testnet.Start.Types +import Testnet.Types diff --git a/cardano-testnet/src/Parsers/Cardano.hs b/cardano-testnet/src/Parsers/Cardano.hs index ae23aa8c0cb..77fba0cff2c 100644 --- a/cardano-testnet/src/Parsers/Cardano.hs +++ b/cardano-testnet/src/Parsers/Cardano.hs @@ -12,11 +12,11 @@ import qualified Data.List as L import Options.Applicative import qualified Options.Applicative as OA -import Testnet.Process.Cli +import Testnet.Process.Cli (pNetworkId) import Testnet.Property.Util -import Testnet.Runtime (readNodeLoggingFormat) import Testnet.Start.Cardano import Testnet.Start.Types +import Testnet.Types (readNodeLoggingFormat) optsTestnet :: EnvCli -> Parser CardanoTestnetOptions diff --git a/cardano-testnet/src/Testnet/Components/DRep.hs b/cardano-testnet/src/Testnet/Components/DRep.hs index 025c27ab3f2..d7c395873e9 100644 --- a/cardano-testnet/src/Testnet/Components/DRep.hs +++ b/cardano-testnet/src/Testnet/Components/DRep.hs @@ -20,11 +20,7 @@ module Testnet.Components.DRep , getLastPParamUpdateActionId ) where -import Cardano.Api (AnyCardanoEra (..), ConwayEra, ConwayEraOnwards, EpochNo (EpochNo), - FileDirection (In), MonadIO, ShelleyBasedEra (..), ToCardanoEra (toCardanoEra), - conwayEraOnwardsToShelleyBasedEra, renderTxIn) - -import Cardano.CLI.Types.Common (File (..)) +import Cardano.Api hiding (Certificate, TxBody) import Prelude @@ -37,8 +33,7 @@ import Data.Text (Text) import qualified Data.Text as Text import Data.Word (Word32) import GHC.IO.Exception (ExitCode (..)) -import GHC.Stack (HasCallStack) -import qualified GHC.Stack as GHC +import GHC.Stack import Lens.Micro ((^?)) import System.FilePath (()) @@ -46,10 +41,8 @@ import Testnet.Components.Query (EpochStateView, findLargestUtxoForPay getCurrentEpochNo, getMinDRepDeposit, waitUntilEpoch) import qualified Testnet.Process.Cli as H import qualified Testnet.Process.Run as H -import Testnet.Runtime (KeyPair (..), - PaymentKeyInfo (paymentKeyInfoAddr, paymentKeyInfoPair), PaymentKeyPair (..), - SomeKeyPair (..), StakingKeyPair (..)) import Testnet.Start.Types (anyEraToString) +import Testnet.Types import Hedgehog (MonadTest, evalMaybe) import qualified Hedgehog.Extras as H @@ -58,19 +51,23 @@ import qualified Hedgehog.Extras as H -- -- Returns the generated 'PaymentKeyPair' containing paths to the verification and -- signing key files. -generateDRepKeyPair :: (MonadTest m, MonadCatch m, MonadIO m, HasCallStack) +generateDRepKeyPair + :: MonadTest m + => MonadCatch m + => MonadIO m + => HasCallStack => H.ExecConfig -- ^ Specifies the CLI execution configuration. -> FilePath -- ^ Base directory path where keys will be stored. -> String -- ^ Name for the subfolder that will be created under 'work' folder to store the output keys. - -> m PaymentKeyPair + -> m (KeyPair PaymentKey) generateDRepKeyPair execConfig work prefix = do baseDir <- H.createDirectoryIfMissing $ work prefix - let dRepKeyPair = PaymentKeyPair { paymentVKey = baseDir "verification.vkey" - , paymentSKey = baseDir "signature.skey" - } + let dRepKeyPair = KeyPair { verificationKey = File $ baseDir "verification.vkey" + , signingKey = File $ baseDir "signature.skey" + } void $ H.execCli' execConfig [ "conway", "governance", "drep", "key-gen" - , "--verification-key-file", paymentVKey dRepKeyPair - , "--signing-key-file", paymentSKey dRepKeyPair + , "--verification-key-file", verificationKeyFp dRepKeyPair + , "--signing-key-file", signingKeyFp dRepKeyPair ] return dRepKeyPair @@ -84,11 +81,14 @@ data Certificate -- Returns the generated @File DRepRegistrationCertificate In@ file path to the -- registration certificate. generateRegistrationCertificate - :: (MonadTest m, MonadCatch m, MonadIO m, HasCallStack) + :: MonadTest m + => MonadCatch m + => MonadIO m + => HasCallStack => H.ExecConfig -- ^ Specifies the CLI execution configuration. -> FilePath -- ^ Base directory path where the certificate file will be stored. -> String -- ^ Prefix for the output certificate file name. The extension will be @.regcert@. - -> PaymentKeyPair -- ^ Payment key pair associated with the DRep. Can be generated using + -> KeyPair PaymentKey -- ^ Payment key pair associated with the DRep. Can be generated using -- 'generateDRepKeyPair'. -> Integer -- ^ Deposit amount required for DRep registration. The right amount -- can be obtained using 'getMinDRepDeposit'. @@ -96,7 +96,7 @@ generateRegistrationCertificate generateRegistrationCertificate execConfig work prefix drepKeyPair depositAmount = do let dRepRegistrationCertificate = File (work prefix <> ".regcert") void $ H.execCli' execConfig [ "conway", "governance", "drep", "registration-certificate" - , "--drep-verification-key-file", paymentVKey drepKeyPair + , "--drep-verification-key-file", verificationKeyFp drepKeyPair , "--key-reg-deposit-amt", show @Integer depositAmount , "--out-file", unFile dRepRegistrationCertificate ] @@ -110,7 +110,10 @@ data TxBody -- -- Returns the generated @File TxBody In@ file path to the transaction body. createCertificatePublicationTxBody - :: (H.MonadAssertion m, MonadTest m, MonadCatch m, MonadIO m) + :: H.MonadAssertion m + => MonadTest m + => MonadCatch m + => MonadIO m => H.ExecConfig -- ^ Specifies the CLI execution configuration. -> EpochStateView -- ^ Current epoch state view for transaction building. It can be obtained -- using the 'getEpochStateView' function. @@ -142,7 +145,10 @@ data VoteFile -- -- Returns a list of generated @File VoteFile In@ representing the paths to -- the generated voting files. -generateVoteFiles :: (MonadTest m, MonadIO m, MonadCatch m) +generateVoteFiles + :: MonadTest m + => MonadIO m + => MonadCatch m => H.ExecConfig -- ^ Specifies the CLI execution configuration. -> FilePath -- ^ Base directory path where the voting files and directories will be -- stored. @@ -150,7 +156,7 @@ generateVoteFiles :: (MonadTest m, MonadIO m, MonadCatch m) -- the output voting files. -> String -- ^ Transaction ID string of the governance action. -> Word32 -- ^ Index of the governance action. - -> [(PaymentKeyPair, [Char])] -- ^ List of tuples where each tuple contains a 'PaymentKeyPair' + -> [(KeyPair PaymentKey, [Char])] -- ^ List of tuples where each tuple contains a 'PaymentKeyPair' -- representing the DRep key pair and a 'String' representing the -- vote type (i.e: "yes", "no", or "abstain"). -> m [File VoteFile In] @@ -163,7 +169,7 @@ generateVoteFiles execConfig work prefix governanceActionTxId governanceActionIn , "--" ++ vote , "--governance-action-tx-id", governanceActionTxId , "--governance-action-index", show @Word32 governanceActionIndex - , "--drep-verification-key-file", paymentVKey drepKeyPair + , "--drep-verification-key-file", verificationKeyFp drepKeyPair , "--out-file", unFile path ] return path @@ -176,7 +182,10 @@ generateVoteFiles execConfig work prefix governanceActionTxId governanceActionIn -- -- Returns the generated @File TxBody In@ file path to the transaction body. createVotingTxBody - :: (H.MonadAssertion m, MonadTest m, MonadCatch m, MonadIO m) + :: H.MonadAssertion m + => MonadTest m + => MonadCatch m + => MonadIO m => H.ExecConfig -- ^ Specifies the CLI execution configuration. -> EpochStateView -- ^ Current epoch state view for transaction building. It can be obtained -- using the 'getEpochStateView' function. @@ -210,27 +219,33 @@ data SignedTx -- This function takes five parameters: -- -- Returns the generated @File SignedTx In@ file path to the signed transaction file. -signTx :: (MonadTest m, MonadCatch m, MonadIO m, KeyPair k) +signTx + :: MonadTest m + => MonadCatch m + => MonadIO m => H.ExecConfig -- ^ Specifies the CLI execution configuration. -> AnyCardanoEra -- ^ Specifies the current Cardano era. -> 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. - -> [k] -- ^ List of payment key pairs used for signing the transaction. + -> [SomeKeyPair] -- ^ 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 $ H.execCli' execConfig $ [ anyEraToString cEra, "transaction", "sign" , "--tx-body-file", unFile txBody - ] ++ (concat [["--signing-key-file", secretKey kp] | kp <- signatoryKeyPairs]) ++ + ] ++ (concat [["--signing-key-file", signingKeyFp kp] | SomeKeyPair kp <- signatoryKeyPairs]) ++ [ "--out-file", unFile signedTx ] return signedTx -- | Submits a signed transaction using @cardano-cli@. submitTx - :: (MonadTest m, MonadCatch m, MonadIO m) + :: HasCallStack + => MonadTest m + => MonadCatch m + => MonadIO m => H.ExecConfig -- ^ Specifies the CLI execution configuration. -> AnyCardanoEra -- ^ Specifies the current Cardano era. -> File SignedTx In -- ^ Signed transaction to be submitted, obtained using 'signTx'. @@ -247,23 +262,26 @@ submitTx execConfig cEra signedTx = -- If the submission succeeds unexpectedly, it raises a failure message that is -- meant to be caught by @Hedgehog@. failToSubmitTx - :: (MonadTest m, MonadCatch m, MonadIO m, HasCallStack) + :: MonadTest m + => MonadCatch m + => MonadIO m + => HasCallStack => H.ExecConfig -- ^ Specifies the CLI execution configuration. -> AnyCardanoEra -- ^ Specifies the current Cardano era. -> File SignedTx In -- ^ Signed transaction to be submitted, obtained using 'signTx'. -> String -- ^ Substring of the error to check for to ensure submission failed for -- the right reason. -> m () -failToSubmitTx execConfig cEra signedTx reasonForFailure = GHC.withFrozenCallStack $ do +failToSubmitTx execConfig cEra signedTx reasonForFailure = withFrozenCallStack $ do (exitCode, _, stderr) <- H.execFlexAny' execConfig "cardano-cli" "CARDANO_CLI" [ anyEraToString cEra, "transaction", "submit" , "--tx-file", unFile signedTx ] case exitCode of -- Did it fail? - ExitSuccess -> H.failMessage GHC.callStack "Transaction submission was expected to fail but it succeeded" + ExitSuccess -> H.failMessage callStack "Transaction submission was expected to fail but it succeeded" _ -> if reasonForFailure `isInfixOf` stderr -- Did it fail for the expected reason? then return () - else H.failMessage GHC.callStack $ "Transaction submission failed for the wrong reason (not " ++ + else H.failMessage callStack $ "Transaction submission failed for the wrong reason (not " ++ show reasonForFailure ++ "): " ++ stderr -- | Retrieves the transaction ID (governance action ID) from a signed @@ -271,7 +289,10 @@ failToSubmitTx execConfig cEra signedTx reasonForFailure = GHC.withFrozenCallSta -- -- Returns the transaction ID (governance action ID) as a 'String'. retrieveTransactionId - :: (MonadTest m, MonadCatch m, MonadIO m) + :: HasCallStack + => MonadTest m + => MonadCatch m + => MonadIO m => H.ExecConfig -- ^ Specifies the CLI execution configuration. -> File SignedTx In -- ^ Signed transaction to be submitted, obtained using 'signTx'. -> m String @@ -286,7 +307,12 @@ retrieveTransactionId execConfig signedTxBody = do -- generating a fresh key pair in the process. -- -- Returns the key pair for the DRep as a 'PaymentKeyPair'. -registerDRep :: (MonadCatch m, MonadIO m, MonadTest m, H.MonadAssertion m) +registerDRep + :: HasCallStack + => MonadCatch m + => MonadIO m + => MonadTest m + => H.MonadAssertion m => H.ExecConfig -- ^ Specifies the CLI execution configuration. -> EpochStateView -- ^ Current epoch state view for transaction building. It can be obtained -- using the 'getEpochStateView' function. @@ -295,7 +321,7 @@ registerDRep :: (MonadCatch m, MonadIO m, MonadTest m, H.MonadAssertion m) -> FilePath -- ^ Name for the subfolder that will be created under 'work' folder to store the output keys. -> PaymentKeyInfo -- ^ Payment key information associated with the transaction, -- as returned by 'cardanoTestnetDefault'. - -> m PaymentKeyPair + -> m (KeyPair PaymentKey) registerDRep execConfig epochStateView ceo work prefix wallet = do let sbe = conwayEraOnwardsToShelleyBasedEra ceo era = toCardanoEra sbe @@ -310,7 +336,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 [drepKeyPair, paymentKeyInfoPair wallet] + drepRegTxBody [SomeKeyPair drepKeyPair, SomeKeyPair $ paymentKeyInfoPair wallet] submitTx execConfig cEra drepSignedRegTx return drepKeyPair @@ -318,21 +344,25 @@ registerDRep execConfig epochStateView ceo work prefix wallet = do -- | Delegate to a Delegate Representative (DRep) by creating and submitting -- a vote delegation certificate transaction using @cardano-cli@. delegateToDRep - :: (MonadTest m, MonadIO m, H.MonadAssertion m, MonadCatch m) + :: HasCallStack + => MonadTest m + => MonadIO m + => H.MonadAssertion m + => MonadCatch m => H.ExecConfig -- ^ Specifies the CLI execution configuration. -> EpochStateView -- ^ Current epoch state view for transaction building. It can be obtained - -> FilePath -- ^ Path to the node configuration file as returned by 'cardanoTestnetDefault'. - -> FilePath -- ^ Path to the cardano-node unix socket file. + -> NodeConfigFile In -- ^ Path to the node configuration file as returned by 'cardanoTestnetDefault'. + -> SocketPath -- ^ Path to the cardano-node unix socket file. -> ShelleyBasedEra ConwayEra -- ^ The Shelley-based era (e.g., 'ConwayEra') in which the transaction will be constructed. -> FilePath -- ^ Base directory path where generated files will be stored. -> String -- ^ Name for the subfolder that will be created under 'work' folder. -> PaymentKeyInfo -- ^ Wallet that will pay for the transaction. - -> StakingKeyPair -- ^ Staking key pair used for delegation. - -> PaymentKeyPair -- ^ Delegate Representative (DRep) key pair ('PaymentKeyPair') to which delegate. + -> KeyPair StakingKey -- ^ Staking key pair used for delegation. + -> KeyPair PaymentKey -- ^ Delegate Representative (DRep) key pair ('PaymentKeyPair') to which delegate. -> m () -delegateToDRep execConfig epochStateView configurationFile socketPath sbe work prefix - payingWallet skeyPair@(StakingKeyPair vKeyFile _sKeyFile) - (PaymentKeyPair drepVKey _drepSKey) = do +delegateToDRep execConfig epochStateView configurationFile' socketPath sbe work prefix + payingWallet skeyPair@KeyPair{verificationKey=File vKeyFile} + KeyPair{verificationKey=File drepVKey} = do let era = toCardanoEra sbe cEra = AnyCardanoEra era @@ -354,7 +384,7 @@ delegateToDRep execConfig epochStateView configurationFile socketPath sbe work p -- Sign transaction repRegSignedRegTx1 <- signTx execConfig cEra baseDir "signed-reg-tx" - repRegTxBody1 [ SomeKeyPair (paymentKeyInfoPair payingWallet) + repRegTxBody1 [ SomeKeyPair $ paymentKeyInfoPair payingWallet , SomeKeyPair skeyPair] -- Submit transaction @@ -362,7 +392,7 @@ delegateToDRep execConfig epochStateView configurationFile socketPath sbe work p -- Wait two epochs (EpochNo epochAfterProp) <- getCurrentEpochNo epochStateView - void $ waitUntilEpoch (File configurationFile) (File socketPath) (EpochNo (epochAfterProp + 2)) + void $ waitUntilEpoch configurationFile' socketPath (EpochNo (epochAfterProp + 2)) -- | This function obtains the identifier for the last enacted parameter update proposal -- if any. @@ -370,7 +400,11 @@ delegateToDRep execConfig epochStateView configurationFile socketPath sbe work p -- If no previous proposal was enacted, the function returns 'Nothing'. -- If there was a previous enacted proposal, the function returns a tuple with its transaction -- identifier (as a 'String') and the action index (as a 'Word32'). -getLastPParamUpdateActionId :: (MonadTest m, MonadCatch m, MonadIO m) +getLastPParamUpdateActionId + :: HasCallStack + => MonadTest m + => MonadCatch m + => MonadIO m => H.ExecConfig -- ^ Specifies the CLI execution configuration. -> m (Maybe (String, Word32)) getLastPParamUpdateActionId execConfig = do diff --git a/cardano-testnet/src/Testnet/Components/Query.hs b/cardano-testnet/src/Testnet/Components/Query.hs index cd82196be7e..7f42bbe6b2b 100644 --- a/cardano-testnet/src/Testnet/Components/Query.hs +++ b/cardano-testnet/src/Testnet/Components/Query.hs @@ -19,7 +19,6 @@ module Testnet.Components.Query , findUtxosWithAddress , findLargestUtxoWithAddress , findLargestUtxoForPaymentKey - , startLedgerNewEpochStateLogging ) where import Cardano.Api as Api @@ -54,7 +53,7 @@ import Lens.Micro (to, (^.)) import Testnet.Property.Assert import Testnet.Property.Util (runInBackground) -import Testnet.Runtime +import Testnet.Types import qualified Hedgehog as H import Hedgehog.Extras (MonadAssertion) diff --git a/cardano-testnet/src/Testnet/Components/SPO.hs b/cardano-testnet/src/Testnet/Components/SPO.hs index b282dbc41e4..9f7caabacec 100644 --- a/cardano-testnet/src/Testnet/Components/SPO.hs +++ b/cardano-testnet/src/Testnet/Components/SPO.hs @@ -41,12 +41,12 @@ import System.FilePath.Posix (()) import Testnet.Components.DRep (VoteFile) import Testnet.Filepath -import Testnet.Process.Cli hiding (File, unFile) +import Testnet.Process.Cli import qualified Testnet.Process.Run as H import Testnet.Process.Run (execCli, execCli', execCli_) import Testnet.Property.Util -import Testnet.Runtime (PoolNodeKeys (poolNodeKeysColdVkey)) import Testnet.Start.Types +import Testnet.Types import Hedgehog import Hedgehog.Extras (ExecConfig) @@ -283,8 +283,8 @@ registerSingleSpo identifier tap@(TmpAbsolutePath tempAbsPath') nodeConfigFile s let poolOwnerstakeVkeyFp = spoReqDir "pool-owner-stake.vkey" poolOwnerstakeSKeyFp = spoReqDir "pool-owner-stake.skey" - _ <- cliStakeAddressKeyGen tempAbsPath' - $ KeyNames poolOwnerstakeVkeyFp poolOwnerstakeSKeyFp + cliStakeAddressKeyGen + $ KeyPair (File poolOwnerstakeVkeyFp) (File poolOwnerstakeSKeyFp) poolownerstakeaddr <- filter (/= '\n') <$> execCli @@ -296,8 +296,8 @@ registerSingleSpo identifier tap@(TmpAbsolutePath tempAbsPath') nodeConfigFile s -- 2. Generate stake pool owner payment key pair let poolOwnerPaymentVkeyFp = spoReqDir "pool-owner-payment.vkey" poolOwnerPaymentSkeyFp = spoReqDir "pool-owner-payment.skey" - _ <- cliAddressKeyGen tempAbsPath' - $ KeyNames poolOwnerPaymentVkeyFp poolOwnerPaymentSkeyFp + cliAddressKeyGen + $ KeyPair (File poolOwnerPaymentVkeyFp) (File poolOwnerPaymentSkeyFp) poolowneraddresswstakecred <- execCli [ "address", "build" , "--payment-verification-key-file", poolOwnerPaymentVkeyFp @@ -319,8 +319,8 @@ registerSingleSpo identifier tap@(TmpAbsolutePath tempAbsPath') nodeConfigFile s -- 4. Generate VRF keys let vrfVkeyFp = spoReqDir "pool-vrf.vkey" vrfSkeyFp = spoReqDir "pool-vrf.skey" - _ <- cliNodeKeyGenVrf tempAbsPath' - $ KeyNames vrfVkeyFp vrfSkeyFp + cliNodeKeyGenVrf + $ KeyPair (File vrfVkeyFp) (File vrfSkeyFp) -- 5. Create registration certificate let poolRegCertFp = spoReqDir "registration.cert" @@ -433,7 +433,7 @@ generateVoteFiles ceo execConfig work prefix governanceActionTxId governanceActi , "--" ++ vote , "--governance-action-tx-id", governanceActionTxId , "--governance-action-index", show @Word32 governanceActionIndex - , "--cold-verification-key-file", poolNodeKeysColdVkey spoKeys + , "--cold-verification-key-file", verificationKeyFp $ poolNodeKeysCold spoKeys , "--out-file", unFile path ] return path diff --git a/cardano-testnet/src/Testnet/Defaults.hs b/cardano-testnet/src/Testnet/Defaults.hs index d6e73c9ecaf..3a763d46bec 100644 --- a/cardano-testnet/src/Testnet/Defaults.hs +++ b/cardano-testnet/src/Testnet/Defaults.hs @@ -14,14 +14,10 @@ module Testnet.Defaults , defaultByronProtocolParamsJsonValue , defaultYamlConfig , defaultConwayGenesis - , defaultDRepVkeyFp - , defaultDRepSkeyFp , defaultDRepKeyPair , defaultDelegatorStakeKeyPair - , defaultSPOKeys - , defaultSPOColdKeyPair - , defaultSPOColdVKeyFp - , defaultSPOColdSKeyFp + , defaultSpoKeys + , defaultSpoColdKeyPair , defaultShelleyGenesis , defaultGenesisFilepath , defaultYamlHardforkViaConfig @@ -30,7 +26,7 @@ module Testnet.Defaults , plutusV3SpendingScript ) where -import Cardano.Api (AnyCardanoEra (..), CardanoEra (..), pshow) +import Cardano.Api (AnyCardanoEra (..), CardanoEra (..), File (..), pshow) import qualified Cardano.Api.Shelley as Api import Cardano.Ledger.Alonzo.Core (PParams (..)) @@ -76,9 +72,8 @@ import Numeric.Natural import System.FilePath (()) import Test.Cardano.Ledger.Core.Rational -import Testnet.Runtime (PaymentKeyPair (PaymentKeyPair), PoolNodeKeys (..), - SPOColdKeyPair (..), StakingKeyPair (StakingKeyPair)) import Testnet.Start.Types +import Testnet.Types {- HLINT ignore "Use underscore" -} @@ -505,60 +500,49 @@ defaultGenesisFilepath era = eraToString era <> "-genesis.json" -- | The relative path to DRep keys in directories created by cardano-testnet -defaultDRepVkeyFp +defaultDRepKeyPair :: Int -- ^ The DRep's index (starts at 1) - -> FilePath -defaultDRepVkeyFp n = "drep-keys" ("drep" <> show n) "drep.vkey" - --- | The relative path to DRep secret keys in directories created by cardano-testnet -defaultDRepSkeyFp - :: Int -- ^ The DRep's index (starts at 1) - -> FilePath -defaultDRepSkeyFp n = "drep-keys" ("drep" <> show n) "drep.skey" - --- | The relative path to DRep key pairs in directories created by cardano-testnet -defaultDRepKeyPair :: Int -> PaymentKeyPair -defaultDRepKeyPair n = PaymentKeyPair (defaultDRepVkeyFp n) (defaultDRepSkeyFp n) - --- | The relative path to SPO cold verification key in directories created by cardano-testnet -defaultSPOColdVKeyFp :: Int -> FilePath -defaultSPOColdVKeyFp n = "pools-keys" "pool" <> show n "cold.vkey" - --- | The relative path to SPO cold secret key in directories created by cardano-testnet -defaultSPOColdSKeyFp :: Int -> FilePath -defaultSPOColdSKeyFp n = "pools-keys" "pool" <> show n "cold.skey" + -> KeyPair PaymentKey +defaultDRepKeyPair n = + KeyPair + { verificationKey = File $ "drep-keys" ("drep" <> show n) "drep.vkey" + , signingKey = File $ "drep-keys" ("drep" <> show n) "drep.skey" + } --- | The relative path to SPO key cold key pair in directories created by cardano-testnet -defaultSPOColdKeyPair :: Int -> SPOColdKeyPair -defaultSPOColdKeyPair n = SPOColdKeyPair (defaultSPOColdVKeyFp n) (defaultSPOColdSKeyFp n) +-- | The relative path to SPO keys in directories created by cardano-testnet +defaultSpoColdKeyPair + :: Int + -> KeyPair SpoColdKey +defaultSpoColdKeyPair n = + KeyPair + { verificationKey = File $ "pools-keys" "pool" <> show n "cold.vkey" + , signingKey = File $ "pools-keys" "pool" <> show n "cold.skey" + } -- | The relative path to SPO key pairs in directories created by cardano-testnet -defaultSPOKeys :: Int -> PoolNodeKeys -defaultSPOKeys n = +defaultSpoKeys :: Int -> PoolNodeKeys +defaultSpoKeys n = PoolNodeKeys - { poolNodeKeysColdVkey = defaultSPOColdVKeyFp n - , poolNodeKeysColdSkey = defaultSPOColdSKeyFp n - , poolNodeKeysVrfVkey = "pools-keys" "pool" ++ show n "vrf.vkey" - , poolNodeKeysVrfSkey = "pools-keys" "pool" ++ show n "vrf.skey" - , poolNodeKeysStakingVkey = "pools-keys" "pool" ++ show n "staking-reward.vkey" - , poolNodeKeysStakingSkey = "pools-keys" "pool" ++ show n "staking-reward.skey" + { poolNodeKeysCold = defaultSpoColdKeyPair n + , poolNodeKeysVrf = + KeyPair + { verificationKey = File $ "pools-keys" "pool" ++ show n "vrf.vkey" + , signingKey = File $ "pools-keys" "pool" ++ show n "vrf.skey" + } + , poolNodeKeysStaking = + KeyPair + { verificationKey = File $ "pools-keys" "pool" ++ show n "staking-reward.vkey" + , signingKey = File $ "pools-keys" "pool" ++ show n "staking-reward.skey" + } } --- | The relative path to stake delegator stake keys in directories created by cardano-testnet -defaultDelegatorStakeVkeyFp - :: Int -- ^ The Stake delegator index (starts at 1) - -> FilePath -defaultDelegatorStakeVkeyFp n = "stake-delegators" ("delegator" <> show n) "staking.vkey" - --- | The relative path to stake delegator stake secret keys in directories created by cardano-testnet -defaultDelegatorStakeSkeyFp - :: Int -- ^ The Stake delegator index (starts at 1) - -> FilePath -defaultDelegatorStakeSkeyFp n = "stake-delegators" ("delegator" <> show n) "staking.skey" - -- | The relative path to stake delegator key pairs in directories created by cardano-testnet -defaultDelegatorStakeKeyPair :: Int -> StakingKeyPair -defaultDelegatorStakeKeyPair n = StakingKeyPair (defaultDelegatorStakeVkeyFp n) (defaultDelegatorStakeSkeyFp n) +defaultDelegatorStakeKeyPair :: Int -> KeyPair StakingKey +defaultDelegatorStakeKeyPair n = + KeyPair + { verificationKey = File $ "stake-delegators" ("delegator" <> show n) "staking.vkey" + , signingKey = File $ "stake-delegators" ("delegator" <> show n) "staking.skey" + } -- TODO: We should not hardcode a script like this. We need to move -- plutus-example from plutus apps to cardano-node-testnet. This will diff --git a/cardano-testnet/src/Testnet/EpochStateProcessing.hs b/cardano-testnet/src/Testnet/EpochStateProcessing.hs index 63d1a962d35..e2dd8790658 100644 --- a/cardano-testnet/src/Testnet/EpochStateProcessing.hs +++ b/cardano-testnet/src/Testnet/EpochStateProcessing.hs @@ -1,3 +1,6 @@ +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE RankNTypes #-} +{-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeFamilies #-} module Testnet.EpochStateProcessing @@ -5,24 +8,18 @@ module Testnet.EpochStateProcessing , findCondition ) where -import Cardano.Api (AnyNewEpochState (..), ConwayEra, EpochNo, File (File), - FoldBlocksError, LedgerStateCondition (..), MonadIO, ShelleyBasedEra, - ValidationMode (FullValidation), foldEpochState, runExceptT, - shelleyBasedEraConstraints) -import qualified Cardano.Api as Api +import Cardano.Api import Cardano.Api.Ledger (GovActionId (..)) import qualified Cardano.Api.Ledger as L import qualified Cardano.Ledger.Conway.Governance as L -import Cardano.Ledger.Shelley.API (TxId (..)) +import qualified Cardano.Ledger.Shelley.API as L import qualified Cardano.Ledger.Shelley.LedgerState as L import Prelude import Control.Monad.State.Strict (MonadState (put), StateT) -import Data.Data ((:~:) (..)) import qualified Data.Map as Map -import Data.Type.Equality (TestEquality (..)) import Data.Word (Word32) import GHC.Stack import Lens.Micro ((^.)) @@ -34,15 +31,15 @@ findCondition => MonadTest m => MonadIO m => (AnyNewEpochState -> Maybe a) - -> FilePath - -> FilePath + -> NodeConfigFile In + -> SocketPath -> EpochNo -- ^ The termination epoch: the condition must be found *before* this epoch -> m (Either FoldBlocksError (Maybe a)) findCondition epochStateFoldFunc configurationFile socketPath maxEpochNo = withFrozenCallStack $ evalIO . runExceptT $ do result <- foldEpochState - (File configurationFile) - (File socketPath) + configurationFile + socketPath FullValidation maxEpochNo Nothing @@ -58,20 +55,21 @@ findCondition epochStateFoldFunc configurationFile socketPath maxEpochNo = withF Just x -> put (Just x) >> pure ConditionMet Nothing -> pure ConditionNotMet -maybeExtractGovernanceActionIndex :: ShelleyBasedEra ConwayEra -- ^ The era in which the test runs - -> Api.TxId +maybeExtractGovernanceActionIndex + :: HasCallStack + => TxId -- ^ transaction id searched for -> AnyNewEpochState -> Maybe Word32 -maybeExtractGovernanceActionIndex sbe txid (AnyNewEpochState actualEra newEpochState) = - case testEquality sbe actualEra of - Just Refl -> do - let proposals = shelleyBasedEraConstraints sbe newEpochState - ^. L.newEpochStateGovStateL - . L.proposalsGovStateL - Map.foldlWithKey' (compareWithTxId txid) Nothing (L.proposalsActionsMap proposals) - Nothing -> do - error $ "Eras mismatch! expected: " <> show sbe <> ", actual: " <> show actualEra +maybeExtractGovernanceActionIndex txid (AnyNewEpochState sbe newEpochState) = + caseShelleyToBabbageOrConwayEraOnwards + (const $ error "Governance actions only available in Conway era onwards") + (\ceo -> conwayEraOnwardsConstraints ceo $ do + let proposals = newEpochState ^. L.newEpochStateGovStateL . L.proposalsGovStateL + Map.foldlWithKey' (compareWithTxId txid) Nothing (L.proposalsActionsMap proposals) + ) + sbe where - compareWithTxId (Api.TxId ti1) Nothing (GovActionId (TxId ti2) (L.GovActionIx gai)) _ + compareWithTxId (TxId ti1) Nothing (GovActionId (L.TxId ti2) (L.GovActionIx gai)) _ | ti1 == L.extractHash ti2 = Just gai compareWithTxId _ x _ _ = x + diff --git a/cardano-testnet/src/Testnet/Process/Cli.hs b/cardano-testnet/src/Testnet/Process/Cli.hs index adb0caff301..022b7fd901e 100644 --- a/cardano-testnet/src/Testnet/Process/Cli.hs +++ b/cardano-testnet/src/Testnet/Process/Cli.hs @@ -1,3 +1,5 @@ +{-# LANGUAGE DataKinds #-} + module Testnet.Process.Cli ( cliAddressKeyGen , cliNodeKeyGen @@ -6,29 +8,20 @@ module Testnet.Process.Cli , cliStakeAddressKeyGen , execCliStdoutToJson , pNetworkId - , KeyGen - , KeyNames (..) - - , File (..) - - , VKey - , SKey , OperatorCounter , ByronDelegationKey , ByronDelegationCert - , getVKeyPath - , getSKeyPath - , cliKeyGen , cliByronSigningKeyAddress ) where -import Cardano.Api (ByronAddr, ByronKeyLegacy, PaymentKey, StakeKey, bounded) -import Cardano.Api.Shelley (KesKey, StakePoolKey, VrfKey) +import Cardano.Api (ByronAddr, ByronKeyLegacy, File (..), FileDirection (..), StakeKey, + bounded) +import Cardano.Api.Shelley (KesKey, StakePoolKey) import Control.Monad.Catch (MonadCatch) import Control.Monad.IO.Class (MonadIO) @@ -41,84 +34,63 @@ import qualified Options.Applicative as Opt import System.FilePath.Posix import Testnet.Process.Run +import Testnet.Types hiding (testnetMagic) import Hedgehog (MonadTest) import Hedgehog.Extras (ExecConfig) import qualified Hedgehog.Extras.Test.Base as H import qualified Hedgehog.Extras.Test.File as H (writeFile) -data KeyNames = KeyNames - { verificationKeyFile :: FilePath - , signingKeyFile :: FilePath - } - -type KeyGen a = (File (VKey a), File (SKey a)) - cliAddressKeyGen :: () => (MonadTest m, MonadCatch m, MonadIO m, HasCallStack) - => TmpDir - -> KeyNames - -> m (KeyGen PaymentKey) + => KeyPair PaymentKey + -> m () cliAddressKeyGen = GHC.withFrozenCallStack $ shelleyKeyGen "address" "key-gen" cliStakeAddressKeyGen :: () => (MonadTest m, MonadCatch m, MonadIO m, HasCallStack) - => TmpDir - -> KeyNames - -> m (KeyGen StakeKey) + => KeyPair StakeKey + -> m () cliStakeAddressKeyGen = GHC.withFrozenCallStack $ shelleyKeyGen "stake-address" "key-gen" cliNodeKeyGenVrf :: () => (MonadTest m, MonadCatch m, MonadIO m, HasCallStack) - => TmpDir - -> KeyNames - -> m (KeyGen VrfKey) + => KeyPair VrfKey + -> m () cliNodeKeyGenVrf = GHC.withFrozenCallStack $ shelleyKeyGen "node" "key-gen-VRF" cliNodeKeyGenKes :: () => (MonadTest m, MonadCatch m, MonadIO m, HasCallStack) - => TmpDir - -> KeyNames - -> m (KeyGen KesKey) + => KeyPair KesKey + -> m () cliNodeKeyGenKes = GHC.withFrozenCallStack $ shelleyKeyGen "node" "key-gen-KES" shelleyKeyGen :: () => (MonadTest m, MonadCatch m, MonadIO m, HasCallStack) - => String - -> String - -> TmpDir - -> KeyNames - -> m (KeyGen x) -shelleyKeyGen command subCommand tmpDir keyNames = - GHC.withFrozenCallStack $ do - let - vKeyPath = tmpDir verificationKeyFile keyNames - sKeyPath = tmpDir signingKeyFile keyNames + => String -- ^ command + -> String -- ^ sub command + -> KeyPair k + -> m () +shelleyKeyGen command subCommand keyPair = + GHC.withFrozenCallStack $ execCli_ [ command, subCommand - , "--verification-key-file", vKeyPath - , "--signing-key-file", sKeyPath + , "--verification-key-file", verificationKeyFp keyPair + , "--signing-key-file", signingKeyFp keyPair ] - return (File vKeyPath, File sKeyPath) cliNodeKeyGen - :: TmpDir - -> FilePath - -> FilePath - -> FilePath - -> H.Integration (File (VKey StakePoolKey), File (SKey StakePoolKey), File OperatorCounter) -cliNodeKeyGen tmpDir vkey skey counter = do - let - vkPath = tmpDir vkey - skPath = tmpDir skey - counterPath = tmpDir counter + :: (MonadTest m, MonadCatch m, MonadIO m, HasCallStack) + => KeyPair StakePoolKey + -> File OperatorCounter Out + -> m () +cliNodeKeyGen keyPair (File counterPath) = execCli_ [ "node", "key-gen" - , "--cold-verification-key-file", vkPath - , "--cold-signing-key-file", skPath + , "--cold-verification-key-file", verificationKeyFp keyPair + , "--cold-signing-key-file", signingKeyFp keyPair , "--operational-certificate-issue-counter-file", counterPath ] - return (File vkPath, File skPath, File counterPath) -- | Call a command of the CLI that returns JSON to stdout. Then parse it, -- and deserialize it to a Haskell value. Fail the test if a step fails. @@ -134,12 +106,6 @@ execCliStdoutToJson execConfig cmd = GHC.withFrozenCallStack $ do result <- execCli' execConfig cmd H.leftFail $ Aeson.eitherDecode $ Data.String.fromString result --- | Verification keys -data VKey a - --- | Signing keys -data SKey a - -- | The 'OperatorCounter' data OperatorCounter @@ -151,17 +117,8 @@ data ByronDelegationCert type TmpDir = FilePath -newtype File a = File {unFile :: FilePath} - deriving (Show, Eq) - -getVKeyPath :: (File (VKey a), File (SKey a)) -> FilePath -getVKeyPath = unFile . fst - -getSKeyPath :: (File (VKey a), File (SKey a)) -> FilePath -getSKeyPath = unFile . snd - -- Byron -cliKeyGen :: TmpDir -> FilePath -> H.Integration (File ByronKeyLegacy) +cliKeyGen :: TmpDir -> FilePath -> H.Integration (File ByronKeyLegacy Out) cliKeyGen tmp key = do let keyPath = tmp key execCli_ @@ -173,9 +130,9 @@ cliKeyGen tmp key = do cliByronSigningKeyAddress :: TmpDir -> Int - -> File ByronKeyLegacy + -> File ByronKeyLegacy In -> FilePath - -> H.Integration (File ByronAddr) + -> H.Integration (File ByronAddr Out) cliByronSigningKeyAddress tmp testnetMagic (File key) destPath = do let addrPath = tmp destPath addr <- execCli diff --git a/cardano-testnet/src/Testnet/Property/Assert.hs b/cardano-testnet/src/Testnet/Property/Assert.hs index e19fdfd1947..b537bbd57ed 100644 --- a/cardano-testnet/src/Testnet/Property/Assert.hs +++ b/cardano-testnet/src/Testnet/Property/Assert.hs @@ -177,9 +177,12 @@ getRelevantSlots poolNodeStdoutFile slotLowerBound = do assertErasEqual :: HasCallStack + => TestEquality eon + => Show (eon expectedEra) + => Show (eon receivedEra) => MonadError String m - => ShelleyBasedEra expectedEra - -> ShelleyBasedEra receivedEra + => eon expectedEra + -> eon receivedEra -> m (expectedEra :~: receivedEra) assertErasEqual expectedEra receivedEra = withFrozenCallStack $ case testEquality expectedEra receivedEra of diff --git a/cardano-testnet/src/Testnet/Runtime.hs b/cardano-testnet/src/Testnet/Runtime.hs index cf2861cb39b..903f1bd2567 100644 --- a/cardano-testnet/src/Testnet/Runtime.hs +++ b/cardano-testnet/src/Testnet/Runtime.hs @@ -1,63 +1,26 @@ -{-# LANGUAGE DeriveAnyClass #-} -{-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE DuplicateRecordFields #-} {-# LANGUAGE ExistentialQuantification #-} {-# LANGUAGE FlexibleContexts #-} -{-# LANGUAGE InstanceSigs #-} {-# LANGUAGE LambdaCase #-} -{-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} module Testnet.Runtime - ( LeadershipSlot(..) - , NodeLoggingFormat(..) - , PaymentKeyInfo(..) - , PaymentKeyPair(..) - , StakingKeyPair(..) - , TestnetRuntime(..) - , NodeRuntime(..) - , PoolNode(..) - , PoolNodeKeys(..) - , Delegator(..) - , SPOColdKeyPair(..) - , KeyPair(..) - , SomeKeyPair(..) - , allNodes - , poolSprockets - , poolNodeStdout - , readNodeLoggingFormat - , startNode - , ShelleyGenesis(..) - , shelleyGenesis - , getStartTime - , fromNominalDiffTimeMicro + ( startNode , startLedgerNewEpochStateLogging ) where import Cardano.Api import qualified Cardano.Api as Api -import qualified Cardano.Chain.Genesis as G -import Cardano.Crypto.ProtocolMagic (RequiresNetworkMagic (..)) -import Cardano.Ledger.Crypto (StandardCrypto) -import Cardano.Ledger.Shelley.Genesis -import Cardano.Node.Configuration.POM -import qualified Cardano.Node.Protocol.Byron as Byron -import Cardano.Node.Types - import Prelude import Control.Exception.Safe import Control.Monad import Control.Monad.State.Strict (StateT) import Control.Monad.Trans.Resource -import qualified Data.Aeson as A import qualified Data.List as List import Data.Text (Text, unpack) -import Data.Time.Clock (UTCTime) -import GHC.Generics (Generic) -import qualified GHC.IO.Handle as IO import GHC.Stack import qualified GHC.Stack as GHC import Network.Socket (PortNumber) @@ -71,7 +34,7 @@ import Testnet.Filepath import qualified Testnet.Ping as Ping import Testnet.Process.Run import Testnet.Property.Util (runInBackground) -import Testnet.Start.Types +import Testnet.Types hiding (testnetMagic) import Hedgehog (MonadTest) import qualified Hedgehog as H @@ -79,129 +42,6 @@ import Hedgehog.Extras.Stock.IO.Network.Sprocket (Sprocket (..)) import qualified Hedgehog.Extras.Stock.IO.Network.Sprocket as H import qualified Hedgehog.Extras.Test.Base as H -data TestnetRuntime = TestnetRuntime - { configurationFile :: !FilePath - , shelleyGenesisFile :: !FilePath - , testnetMagic :: !Int - , poolNodes :: ![PoolNode] - , wallets :: ![PaymentKeyInfo] - , delegators :: ![Delegator] - } - -data NodeRuntime = NodeRuntime - { nodeName :: !String - , nodeIpv4 :: !Text - , nodePort :: !PortNumber - , nodeSprocket :: !Sprocket - , nodeStdinHandle :: !IO.Handle - , nodeStdout :: !FilePath - , nodeStderr :: !FilePath - , nodeProcessHandle :: !IO.ProcessHandle - } - -data PoolNode = PoolNode - { poolRuntime :: NodeRuntime - , poolKeys :: PoolNodeKeys - } - -data PoolNodeKeys = PoolNodeKeys - { poolNodeKeysColdVkey :: FilePath - , poolNodeKeysColdSkey :: FilePath - , poolNodeKeysVrfVkey :: FilePath - , poolNodeKeysVrfSkey :: FilePath - , poolNodeKeysStakingVkey :: FilePath - , poolNodeKeysStakingSkey :: FilePath - } deriving (Eq, Show) - -data SPOColdKeyPair = SPOColdKeyPair - { spoColdVKey :: FilePath - , spoColdSKey :: FilePath - } deriving (Eq, Show) - -data PaymentKeyPair = PaymentKeyPair - { paymentVKey :: FilePath - , paymentSKey :: FilePath - } deriving (Eq, Show) - -data PaymentKeyInfo = PaymentKeyInfo - { paymentKeyInfoPair :: PaymentKeyPair - , paymentKeyInfoAddr :: Text - } deriving (Eq, Show) - -data StakingKeyPair = StakingKeyPair - { stakingVKey :: FilePath - , stakingSKey :: FilePath - } deriving (Eq, Show) - -data Delegator = Delegator - { paymentKeyPair :: PaymentKeyPair - , stakingKeyPair :: StakingKeyPair - } deriving (Eq, Show) - -data LeadershipSlot = LeadershipSlot - { slotNumber :: Int - , slotTime :: Text - } deriving (Eq, Show, Generic, FromJSON) - -class KeyPair a where - secretKey :: a -> FilePath - -instance KeyPair PaymentKeyPair where - secretKey :: PaymentKeyPair -> FilePath - secretKey = paymentSKey - -instance KeyPair StakingKeyPair where - secretKey :: StakingKeyPair -> FilePath - secretKey = stakingSKey - -instance KeyPair SPOColdKeyPair where - secretKey :: SPOColdKeyPair -> FilePath - secretKey = spoColdSKey - -data SomeKeyPair = forall a . KeyPair a => SomeKeyPair a - -instance KeyPair SomeKeyPair where - secretKey :: SomeKeyPair -> FilePath - secretKey (SomeKeyPair x) = secretKey x - -poolNodeStdout :: PoolNode -> FilePath -poolNodeStdout = nodeStdout . poolRuntime - -poolSprockets :: TestnetRuntime -> [Sprocket] -poolSprockets = fmap (nodeSprocket . poolRuntime) . poolNodes - -shelleyGenesis :: (H.MonadTest m, MonadIO m, HasCallStack) => TestnetRuntime -> m (ShelleyGenesis StandardCrypto) -shelleyGenesis TestnetRuntime{shelleyGenesisFile} = withFrozenCallStack $ - H.evalEither =<< H.evalIO (A.eitherDecodeFileStrict' shelleyGenesisFile) - -getStartTime - :: (H.MonadTest m, MonadIO m, HasCallStack) - => FilePath -> TestnetRuntime -> m UTCTime -getStartTime tempRootPath TestnetRuntime{configurationFile} = withFrozenCallStack $ H.evalEither <=< H.evalIO . runExceptT $ do - byronGenesisFile <- - decodeNodeConfiguration configurationFile >>= \case - NodeProtocolConfigurationCardano NodeByronProtocolConfiguration{npcByronGenesisFile} _ _ _ _ -> - pure $ unGenesisFile npcByronGenesisFile - let byronGenesisFilePath = tempRootPath byronGenesisFile - G.gdStartTime . G.configGenesisData <$> decodeGenesisFile byronGenesisFilePath - where - decodeNodeConfiguration :: FilePath -> ExceptT String IO NodeProtocolConfiguration - decodeNodeConfiguration file = do - partialNodeCfg <- ExceptT $ A.eitherDecodeFileStrict' file - fmap ncProtocolConfig . liftEither . makeNodeConfiguration $ defaultPartialNodeConfiguration <> partialNodeCfg - decodeGenesisFile :: FilePath -> ExceptT String IO G.Config - decodeGenesisFile fp = withExceptT (docToString . prettyError) $ - Byron.readGenesis (GenesisFile fp) Nothing RequiresNoMagic - -readNodeLoggingFormat :: String -> Either String NodeLoggingFormat -readNodeLoggingFormat = \case - "json" -> Right NodeLoggingFormatAsJson - "text" -> Right NodeLoggingFormatAsText - s -> Left $ "Unrecognised node logging format: " <> show s <> ". Valid options: \"json\", \"text\"" - -allNodes :: TestnetRuntime -> [NodeRuntime] -allNodes tr = fmap poolRuntime (poolNodes tr) - data NodeStartFailure = ProcessRelatedFailure ProcessError | ExecutableRelatedFailure ExecutableError @@ -359,7 +199,7 @@ startLedgerNewEpochStateLogging testnetRuntime tmpWorkspace = withFrozenCallStac socketPath <- H.noteM $ H.sprocketSystemName <$> H.headM (poolSprockets testnetRuntime) _ <- runInBackground . runExceptT $ foldEpochState - (File $ configurationFile testnetRuntime) + (configurationFile testnetRuntime) (Api.File socketPath) Api.QuickValidation (EpochNo maxBound) diff --git a/cardano-testnet/src/Testnet/Start/Cardano.hs b/cardano-testnet/src/Testnet/Start/Cardano.hs index fd3a9d34baa..042fe9b8bb0 100644 --- a/cardano-testnet/src/Testnet/Start/Cardano.hs +++ b/cardano-testnet/src/Testnet/Start/Cardano.hs @@ -12,7 +12,6 @@ module Testnet.Start.Cardano , cardanoDefaultTestnetNodeOptions , TestnetRuntime (..) - , PaymentKeyPair(..) , cardanoTestnet , cardanoTestnetDefault @@ -60,9 +59,10 @@ import Testnet.Filepath import qualified Testnet.Process.Run as H import Testnet.Process.Run import qualified Testnet.Property.Assert as H -import Testnet.Runtime as TR hiding (shelleyGenesis) +import Testnet.Runtime as TR import qualified Testnet.Start.Byron as Byron import Testnet.Start.Types +import Testnet.Types as TR hiding (shelleyGenesis) import Hedgehog (MonadTest) import qualified Hedgehog as H @@ -223,8 +223,8 @@ cardanoTestnet optionsMagic :: Word32 = fromIntegral $ cardanoTestnetMagic testnetOptions testnetMagic = cardanoTestnetMagic testnetOptions numPoolNodes = length $ cardanoNodes testnetOptions - nbPools = numPools testnetOptions - nbDReps = numDReps testnetOptions + nPools = numPools testnetOptions + nDReps = numDReps testnetOptions era = cardanoNodeEra testnetOptions portNumbers <- requestAvailablePortNumbers numPoolNodes @@ -269,18 +269,28 @@ cardanoTestnet writeGenesisSpecFile "alonzo" alonzoGenesis writeGenesisSpecFile "conway" conwayGenesis - configurationFile <- H.noteShow $ tmpAbsPath "configuration.yaml" + configurationFile <- H.noteShow . File $ tmpAbsPath "configuration.yaml" - _ <- createSPOGenesisAndFiles nbPools nbDReps era shelleyGenesis alonzoGenesis conwayGenesis (TmpAbsolutePath tmpAbsPath) + _ <- createSPOGenesisAndFiles nPools nDReps era shelleyGenesis alonzoGenesis conwayGenesis (TmpAbsolutePath tmpAbsPath) poolKeys <- H.noteShow $ flip fmap [1..numPoolNodes] $ \n -> + -- TODO: use Testnet.Defaults.defaultSpoKeys here PoolNodeKeys - { poolNodeKeysColdVkey = tmpAbsPath "pools" "cold" <> show n <> ".vkey" - , poolNodeKeysColdSkey = tmpAbsPath "pools" "cold" <> show n <> ".skey" - , poolNodeKeysVrfVkey = tmpAbsPath "pools" "vrf" <> show n <> ".vkey" - , poolNodeKeysVrfSkey = tmpAbsPath "pools" "vrf" <> show n <> ".skey" - , poolNodeKeysStakingVkey = tmpAbsPath "pools" "staking-reward" <> show n <> ".vkey" - , poolNodeKeysStakingSkey = tmpAbsPath "pools" "staking-reward" <> show n <> ".skey" + { poolNodeKeysCold = + KeyPair + { verificationKey = File $ tmpAbsPath "pools-keys" "cold" <> show n <> ".vkey" + , signingKey = File $ tmpAbsPath "pools-keys" "cold" <> show n <> ".skey" + } + , poolNodeKeysVrf = + KeyPair + { verificationKey = File $ tmpAbsPath "pools-keys" "vrf" <> show n <> ".vkey" + , signingKey = File $ tmpAbsPath "pools-keys" "vrf" <> show n <> ".skey" + } + , poolNodeKeysStaking = + KeyPair + { verificationKey = File $ tmpAbsPath "pools-keys" "staking-reward" <> show n <> ".vkey" + , signingKey = File $ tmpAbsPath "pools-keys" "staking-reward" <> show n <> ".skey" + } } let makeUTxOVKeyFp :: Int -> FilePath makeUTxOVKeyFp n = tmpAbsPath "utxo-keys" "utxo" <> show n "utxo.vkey" @@ -303,22 +313,22 @@ cardanoTestnet paymentAddr <- H.readFile paymentAddrFile pure $ PaymentKeyInfo - { paymentKeyInfoPair = PaymentKeyPair - { paymentSKey = paymentSKeyFile - , paymentVKey = paymentVKeyFile + { paymentKeyInfoPair = KeyPair + { signingKey = File paymentSKeyFile + , verificationKey = File paymentVKeyFile } , paymentKeyInfoAddr = Text.pack paymentAddr } _delegators <- forM [1..3] $ \(idx :: Int) -> do pure $ Delegator - { paymentKeyPair = PaymentKeyPair - { paymentSKey = tmpAbsPath "stake-delegator-keys/payment" <> show idx <> ".skey" - , paymentVKey = tmpAbsPath "stake-delegator-keys/payment" <> show idx <> ".vkey" + { paymentKeyPair = KeyPair + { signingKey = File $ tmpAbsPath "stake-delegator-keys/payment" <> show idx <> ".skey" + , verificationKey = File $ tmpAbsPath "stake-delegator-keys/payment" <> show idx <> ".vkey" } - , stakingKeyPair = StakingKeyPair - { stakingSKey = tmpAbsPath "stake-delegator-keys/staking" <> show idx <> ".skey" - , stakingVKey = tmpAbsPath "stake-delegator-keys/staking" <> show idx <> ".vkey" + , stakingKeyPair = KeyPair + { signingKey = File $ tmpAbsPath "stake-delegator-keys/staking" <> show idx <> ".skey" + , verificationKey = File $ tmpAbsPath "stake-delegator-keys/staking" <> show idx <> ".vkey" } } @@ -331,7 +341,7 @@ cardanoTestnet -- Add Byron, Shelley and Alonzo genesis hashes to node configuration config <- createConfigJson (TmpAbsolutePath tmpAbsPath) era - H.evalIO $ LBS.writeFile configurationFile config + H.evalIO $ LBS.writeFile (unFile configurationFile) config -- Byron related forM_ (zip [1..] portNumbers) $ \(i, portNumber) -> do @@ -360,7 +370,7 @@ cardanoTestnet eRuntime <- runExceptT $ startNode (TmpAbsolutePath tmpAbsPath) nodeName testnetIpv4Address port testnetMagic [ "run" - , "--config", configurationFile + , "--config", unFile configurationFile , "--topology", keyDir "topology.json" , "--database-path", keyDir "db" , "--shelley-kes-key", keyDir "kes.skey" @@ -385,8 +395,8 @@ cardanoTestnet H.noteShowIO_ DTC.getCurrentTime forM_ wallets $ \wallet -> do - H.cat $ paymentSKey $ paymentKeyInfoPair wallet - H.cat $ paymentVKey $ paymentKeyInfoPair wallet + H.cat . signingKeyFp $ paymentKeyInfoPair wallet + H.cat . verificationKeyFp $ paymentKeyInfoPair wallet let runtime = TestnetRuntime { configurationFile @@ -403,8 +413,8 @@ cardanoTestnet execConfig <- H.mkExecConfig tempBaseAbsPath node1sprocket testnetMagic forM_ wallets $ \wallet -> do - H.cat $ paymentSKey $ paymentKeyInfoPair wallet - H.cat $ paymentVKey $ paymentKeyInfoPair wallet + H.cat . signingKeyFp $ paymentKeyInfoPair wallet + H.cat . verificationKeyFp $ paymentKeyInfoPair wallet utxos <- execCli' execConfig [ "query", "utxo" diff --git a/cardano-testnet/src/Testnet/SubmitApi.hs b/cardano-testnet/src/Testnet/SubmitApi.hs index 31a238bd967..2c27c4a83a4 100644 --- a/cardano-testnet/src/Testnet/SubmitApi.hs +++ b/cardano-testnet/src/Testnet/SubmitApi.hs @@ -1,26 +1,21 @@ +{-# LANGUAGE DataKinds #-} {-# LANGUAGE DisambiguateRecordFields #-} {-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE TypeApplications #-} - -{- HLINT ignore "Redundant id" -} -{- HLINT ignore "Redundant return" -} -{- HLINT ignore "Use head" -} -{- HLINT ignore "Use let" -} -{- HLINT ignore "Redundant <&>" -} module Testnet.SubmitApi ( SubmitApiConf (..) , withSubmitApi ) where +import Cardano.Api + import Cardano.Testnet import qualified Cardano.Testnet as H import Prelude -import Data.Functor ((<&>)) import qualified System.IO as IO import qualified System.Process as IO @@ -36,7 +31,7 @@ import qualified Hedgehog.Extras.Test.Process as H data SubmitApiConf = SubmitApiConf { tempAbsPath :: FilePath - , configPath :: FilePath + , configPath :: File NodeConfig In , epochSlots :: Int , sprocket :: Sprocket , testnetMagic :: Int @@ -64,32 +59,26 @@ withSubmitApi [submitApiPort] <- H.evalIO $ maybe (IO.allocateRandomPorts 1) (pure . (:[])) maybePort - (_, _, _, hProcess, _) <- H.createProcess =<< - ( H.procSubmitApi - ( [ "--config", configPath - , "--cardano-mode" - , "--epoch-slots", show @Int epochSlots - , "--socket-path", IO.sprocketArgumentName sprocket - , "--testnet-magic", show @Int testnetMagic - , "--port", show @Int submitApiPort - ] - <> args - ) <&> - ( \cp -> cp - { IO.std_in = IO.CreatePipe - , IO.std_out = IO.UseHandle hNodeStdout - , IO.std_err = IO.UseHandle hNodeStderr - , IO.cwd = Just tempBaseAbsPath - } - ) - ) + cp <- H.procSubmitApi $ + [ "--config", unFile configPath + , "--cardano-mode" + , "--epoch-slots", show epochSlots + , "--socket-path", IO.sprocketArgumentName sprocket + , "--testnet-magic", show testnetMagic + , "--port", show submitApiPort + ] <> args + + (_, _, _, hProcess, _) <- H.createProcess $ cp + { IO.std_in = IO.CreatePipe + , IO.std_out = IO.UseHandle hNodeStdout + , IO.std_err = IO.UseHandle hNodeStderr + , IO.cwd = Just tempBaseAbsPath + } H.onFailure $ H.evalIO $ IO.terminateProcess hProcess - H.noteShow_ =<< H.getPid hProcess let uriBase = "http://localhost:" <> show submitApiPort - f uriBase H.evalIO $ IO.terminateProcess hProcess diff --git a/cardano-testnet/src/Testnet/Types.hs b/cardano-testnet/src/Testnet/Types.hs new file mode 100644 index 00000000000..a447ecf77aa --- /dev/null +++ b/cardano-testnet/src/Testnet/Types.hs @@ -0,0 +1,194 @@ +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE DeriveAnyClass #-} +{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE ExistentialQuantification #-} +{-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE LambdaCase #-} +{-# LANGUAGE NamedFieldPuns #-} +{-# LANGUAGE RankNTypes #-} +{-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE StandaloneDeriving #-} + +module Testnet.Types + ( LeadershipSlot(..) + , NodeLoggingFormat(..) + , PaymentKeyInfo(..) + , TestnetRuntime(..) + , NodeRuntime(..) + , nodeSocketPath + , PoolNode(..) + , PoolNodeKeys(..) + , Delegator(..) + , KeyPair(..) + , verificationKeyFp + , signingKeyFp + , SomeKeyPair(..) + , VKey + , SKey + , ColdPoolKey + , VrfKey + , StakingKey + , PaymentKey + , DRepKey + , SpoColdKey + , allNodes + , poolSprockets + , poolNodeStdout + , readNodeLoggingFormat + , ShelleyGenesis(..) + , shelleyGenesis + , getStartTime + , fromNominalDiffTimeMicro + ) where + +import Cardano.Api +import Cardano.Api.Shelley (VrfKey) + +import qualified Cardano.Chain.Genesis as G +import Cardano.Crypto.ProtocolMagic (RequiresNetworkMagic (..)) +import Cardano.Ledger.Crypto (StandardCrypto) +import Cardano.Ledger.Shelley.Genesis +import Cardano.Node.Configuration.POM +import qualified Cardano.Node.Protocol.Byron as Byron +import Cardano.Node.Types + +import Prelude + +import Control.Monad +import qualified Data.Aeson as A +import Data.Text (Text) +import Data.Time.Clock (UTCTime) +import GHC.Generics (Generic) +import qualified GHC.IO.Handle as IO +import GHC.Stack +import Network.Socket (PortNumber) +import System.FilePath +import qualified System.Process as IO + +import Testnet.Start.Types + +import qualified Hedgehog as H +import qualified Hedgehog.Extras.Stock as H +import Hedgehog.Extras.Stock.IO.Network.Sprocket (Sprocket (..)) + +data KeyPair k = KeyPair + { verificationKey :: forall dir. (File (VKey k) dir) + , signingKey :: forall dir. (File (SKey k) dir) + } + +deriving instance Show (KeyPair k) +deriving instance Eq (KeyPair k) + +verificationKeyFp :: KeyPair k -> FilePath +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 + +-- | Signing key tag +data SKey k + +data TestnetRuntime = TestnetRuntime + { configurationFile :: !(NodeConfigFile In) + , shelleyGenesisFile :: !FilePath + , testnetMagic :: !Int + , poolNodes :: ![PoolNode] + , wallets :: ![PaymentKeyInfo] + , delegators :: ![Delegator] + } + +poolSprockets :: TestnetRuntime -> [Sprocket] +poolSprockets = fmap (nodeSprocket . poolRuntime) . poolNodes + +data NodeRuntime = NodeRuntime + { nodeName :: !String + , nodeIpv4 :: !Text + , nodePort :: !PortNumber + , nodeSprocket :: !Sprocket + , nodeStdinHandle :: !IO.Handle + , nodeStdout :: !FilePath + , nodeStderr :: !FilePath + , nodeProcessHandle :: !IO.ProcessHandle + } + +nodeSocketPath :: NodeRuntime -> SocketPath +nodeSocketPath = File . H.sprocketSystemName . nodeSprocket + +data PoolNode = PoolNode + { poolRuntime :: NodeRuntime + , poolKeys :: PoolNodeKeys + } + +poolNodeStdout :: PoolNode -> FilePath +poolNodeStdout = nodeStdout . poolRuntime + +data ColdPoolKey +data StakingKey +data SpoColdKey + +data PoolNodeKeys = PoolNodeKeys + { poolNodeKeysCold :: KeyPair SpoColdKey + , poolNodeKeysVrf :: KeyPair VrfKey + , poolNodeKeysStaking :: KeyPair StakingKey + } deriving (Eq, Show) + +data PaymentKeyInfo = PaymentKeyInfo + { paymentKeyInfoPair :: KeyPair PaymentKey + , paymentKeyInfoAddr :: Text + } deriving (Eq, Show) + +data Delegator = Delegator + { paymentKeyPair :: KeyPair PaymentKey + , stakingKeyPair :: KeyPair StakingKey + } deriving (Eq, Show) + +data LeadershipSlot = LeadershipSlot + { slotNumber :: Int + , slotTime :: Text + } deriving (Eq, Show, Generic, FromJSON) + +shelleyGenesis + :: H.MonadTest m + => MonadIO m + => HasCallStack + => TestnetRuntime -> m (ShelleyGenesis StandardCrypto) +shelleyGenesis TestnetRuntime{shelleyGenesisFile} = withFrozenCallStack $ + H.evalEither =<< H.evalIO (A.eitherDecodeFileStrict' shelleyGenesisFile) + +getStartTime + :: H.MonadTest m + => MonadIO m + => HasCallStack + => FilePath + -> TestnetRuntime + -> m UTCTime +getStartTime tempRootPath TestnetRuntime{configurationFile} = withFrozenCallStack $ H.evalEither <=< H.evalIO . runExceptT $ do + byronGenesisFile <- + decodeNodeConfiguration configurationFile >>= \case + NodeProtocolConfigurationCardano NodeByronProtocolConfiguration{npcByronGenesisFile} _ _ _ _ -> + pure $ unGenesisFile npcByronGenesisFile + let byronGenesisFilePath = tempRootPath byronGenesisFile + G.gdStartTime . G.configGenesisData <$> decodeGenesisFile byronGenesisFilePath + where + decodeNodeConfiguration :: File NodeConfig In -> ExceptT String IO NodeProtocolConfiguration + decodeNodeConfiguration (File file) = do + partialNodeCfg <- ExceptT $ A.eitherDecodeFileStrict' file + fmap ncProtocolConfig . liftEither . makeNodeConfiguration $ defaultPartialNodeConfiguration <> partialNodeCfg + decodeGenesisFile :: FilePath -> ExceptT String IO G.Config + decodeGenesisFile fp = withExceptT (docToString . prettyError) $ + Byron.readGenesis (GenesisFile fp) Nothing RequiresNoMagic + +readNodeLoggingFormat :: String -> Either String NodeLoggingFormat +readNodeLoggingFormat = \case + "json" -> Right NodeLoggingFormatAsJson + "text" -> Right NodeLoggingFormatAsText + s -> Left $ "Unrecognised node logging format: " <> show s <> ". Valid options: \"json\", \"text\"" + +allNodes :: TestnetRuntime -> [NodeRuntime] +allNodes tr = fmap poolRuntime (poolNodes tr) diff --git a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Babbage/LeadershipSchedule.hs b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Babbage/LeadershipSchedule.hs index 6d405b276fd..719d756f23e 100644 --- a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Babbage/LeadershipSchedule.hs +++ b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Babbage/LeadershipSchedule.hs @@ -44,6 +44,7 @@ import Testnet.Process.Run import Testnet.Property.Assert import qualified Testnet.Property.Util as H import Testnet.Runtime +import Testnet.Types import Hedgehog (Property, (===)) import qualified Hedgehog as H @@ -80,7 +81,7 @@ hprop_leadershipSchedule = H.integrationRetryWorkspace 2 "babbage-leadership-sch ----------------Need to register an SPO------------------ let utxoAddr = Text.unpack $ paymentKeyInfoAddr wallet0 - utxoSKeyFile = paymentSKey $ paymentKeyInfoPair wallet0 + utxoSKeyFile = signingKeyFp $ paymentKeyInfoPair wallet0 void $ H.execCli' execConfig [ "conway", "query", "utxo" , "--address", utxoAddr @@ -92,11 +93,10 @@ hprop_leadershipSchedule = H.integrationRetryWorkspace 2 "babbage-leadership-sch UTxO utxo1 <- H.noteShowM $ decodeEraUTxO sbe utxo1Json txin1 <- H.noteShow =<< H.headM (Map.keys utxo1) let node1SocketPath = Api.File $ IO.sprocketSystemName node1sprocket - nodeConfigFile = Api.File configurationFile termEpoch = EpochNo 15 (stakePoolIdNewSpo, stakePoolColdSigningKey, stakePoolColdVKey, vrfSkey, _) <- registerSingleSpo 1 tempAbsPath - (Api.File configurationFile) + configurationFile node1SocketPath (EpochNo 10) cTestnetOptions @@ -117,10 +117,10 @@ hprop_leadershipSchedule = H.integrationRetryWorkspace 2 "babbage-leadership-sch testDelegatorRegCertFp = testStakeDelegator "test-delegator.regcert" testDelegatorDelegCert = testStakeDelegator "test-delegator.delegcert" - _ <- cliStakeAddressKeyGen work - $ KeyNames testDelegatorVkeyFp testDelegatorSKeyFp - _ <- cliAddressKeyGen work - $ KeyNames testDelegatorPaymentVKeyFp testDelegatorPaymentSKeyFp + cliStakeAddressKeyGen + $ KeyPair (File testDelegatorVkeyFp) (File testDelegatorSKeyFp) + cliAddressKeyGen + $ KeyPair (File testDelegatorPaymentVKeyFp) (File testDelegatorPaymentSKeyFp) -- NB: We must include the stake credential testDelegatorPaymentAddr <- execCli @@ -206,7 +206,7 @@ hprop_leadershipSchedule = H.integrationRetryWorkspace 2 "babbage-leadership-sch let testDelegatorStakeAddressInfoOutFp = work "test-delegator-stake-address-info.json" void $ checkStakeKeyRegistered tempAbsPath - nodeConfigFile + configurationFile node1SocketPath termEpoch execConfig @@ -226,8 +226,8 @@ hprop_leadershipSchedule = H.integrationRetryWorkspace 2 "babbage-leadership-sch let testSpoKesVKey = work "kes.vkey" testSpoKesSKey = work "kes.skey" - _ <- cliNodeKeyGenKes work - $ KeyNames testSpoKesVKey testSpoKesSKey + cliNodeKeyGenKes + $ KeyPair (File testSpoKesVKey) (File testSpoKesSKey) let testSpoOperationalCertFp = testSpoDir "node-operational.cert" void $ execCli' execConfig @@ -248,11 +248,11 @@ hprop_leadershipSchedule = H.integrationRetryWorkspace 2 "babbage-leadership-sch ] jsonBS <- createConfigJson tempAbsPath (cardanoNodeEra cTestnetOptions) - H.lbsWriteFile configurationFile jsonBS + H.lbsWriteFile (unFile configurationFile) jsonBS [newNodePort] <- requestAvailablePortNumbers 1 eRuntime <- runExceptT $ startNode (TmpAbsolutePath work) "test-spo" "127.0.0.1" newNodePort testnetMagic [ "run" - , "--config", configurationFile + , "--config", unFile configurationFile , "--topology", topologyFile , "--database-path", testSpoDir "db" , "--shelley-kes-key", testSpoKesSKey @@ -264,7 +264,7 @@ hprop_leadershipSchedule = H.integrationRetryWorkspace 2 "babbage-leadership-sch Right runtime -> return $ nodeStdout runtime -- Wait for 2 epochs to pass - void $ waitUntilEpoch (Api.File configurationFile) + void $ waitUntilEpoch configurationFile node1SocketPath (EpochNo 3) currentLeaderShipScheduleFile <- H.noteTempFile work "current-schedule.log" diff --git a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Babbage/StakeSnapshot.hs b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Babbage/StakeSnapshot.hs index 18b04ac0233..863b428f65d 100644 --- a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Babbage/StakeSnapshot.hs +++ b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Babbage/StakeSnapshot.hs @@ -3,8 +3,6 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} -{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-} - module Cardano.Testnet.Test.Cli.Babbage.StakeSnapshot ( hprop_stakeSnapshot ) where @@ -25,7 +23,7 @@ import Testnet.Components.TestWatchdog import Testnet.Process.Cli (execCliStdoutToJson) import qualified Testnet.Process.Run as H import qualified Testnet.Property.Util as H -import Testnet.Runtime +import Testnet.Types import Hedgehog (Property, (===)) import qualified Hedgehog as H @@ -57,7 +55,7 @@ hprop_stakeSnapshot = H.integrationRetryWorkspace 2 "babbage-stake-snapshot" $ \ poolSprocket1 <- H.noteShow $ nodeSprocket $ poolRuntime poolNode1 execConfig <- H.mkExecConfig tempBaseAbsPath poolSprocket1 testnetMagic - void $ waitUntilEpoch (Api.File configurationFile) + void $ waitUntilEpoch configurationFile (Api.File $ IO.sprocketSystemName poolSprocket1) (EpochNo 3) json <- execCliStdoutToJson execConfig [ "query", "stake-snapshot", "--all-stake-pools" ] diff --git a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Babbage/Transaction.hs b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Babbage/Transaction.hs index 17efe546e50..d1556c7978a 100644 --- a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Babbage/Transaction.hs +++ b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Babbage/Transaction.hs @@ -33,7 +33,7 @@ import Testnet.Components.TestWatchdog import qualified Testnet.Process.Run as H import Testnet.Process.Run import qualified Testnet.Property.Util as H -import Testnet.Runtime +import Testnet.Types import Hedgehog (Property) import qualified Hedgehog as H @@ -100,7 +100,7 @@ hprop_transaction = H.integrationRetryWorkspace 0 "babbage-transaction" $ \tempA void $ execCli' execConfig [ "babbage", "transaction", "sign" , "--tx-body-file", txbodyFp - , "--signing-key-file", paymentSKey $ paymentKeyInfoPair wallet0 + , "--signing-key-file", signingKeyFp $ paymentKeyInfoPair wallet0 , "--out-file", txbodySignedFp ] diff --git a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Conway/Plutus.hs b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Conway/Plutus.hs index 05c69bb5930..529e2afaa44 100644 --- a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Conway/Plutus.hs +++ b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Conway/Plutus.hs @@ -5,11 +5,6 @@ {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeApplications #-} -{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-} - -{- HLINT ignore "Redundant id" -} -{- HLINT ignore "Redundant return" -} -{- HLINT ignore "Use head" -} module Cardano.Testnet.Test.Cli.Conway.Plutus ( hprop_plutus_v3 @@ -34,7 +29,7 @@ import Testnet.Defaults import qualified Testnet.Process.Run as H import Testnet.Process.Run import qualified Testnet.Property.Util as H -import Testnet.Runtime +import Testnet.Types import Hedgehog (Property) import qualified Hedgehog as H @@ -68,16 +63,17 @@ hprop_plutus_v3 = H.integrationWorkspace "all-plutus-script-purposes" $ \tempAbs TestnetRuntime { testnetMagic , poolNodes - , wallets + , wallets=wallet0:wallet1:_ } <- cardanoTestnetDefault options conf poolNode1 <- H.headM poolNodes poolSprocket1 <- H.noteShow $ nodeSprocket $ poolRuntime poolNode1 execConfig <- H.mkExecConfig tempBaseAbsPath poolSprocket1 testnetMagic - let utxoAddr = Text.unpack $ paymentKeyInfoAddr $ wallets !! 0 - utxoAddr2 = Text.unpack $ paymentKeyInfoAddr $ wallets !! 1 - utxoSKeyFile = paymentSKey . paymentKeyInfoPair $ wallets !! 0 - utxoSKeyFile2 = paymentSKey . paymentKeyInfoPair $ wallets !! 1 + H.noteShow_ wallet0 + let utxoAddr = Text.unpack $ paymentKeyInfoAddr wallet0 + utxoAddr2 = Text.unpack $ paymentKeyInfoAddr wallet1 + utxoSKeyFile = signingKeyFp $ paymentKeyInfoPair wallet0 + utxoSKeyFile2 = signingKeyFp $ paymentKeyInfoPair wallet1 void $ H.execCli' execConfig [ anyEraToString anyEra, "query", "utxo" @@ -90,7 +86,7 @@ hprop_plutus_v3 = H.integrationWorkspace "all-plutus-script-purposes" $ \tempAbs let keys1 = Map.keys utxo1 H.note_ $ "keys1: " <> show (length keys1) - txin1 <- H.noteShow $ keys1 !! 0 + txin1 <- H.noteShowM $ H.headM keys1 plutusMintingScript <- H.note $ work "always-succeeds-non-spending-script.plutusV3" H.writeFile plutusMintingScript $ Text.unpack plutusV3NonSpendingScript @@ -136,7 +132,7 @@ hprop_plutus_v3 = H.integrationWorkspace "all-plutus-script-purposes" $ \tempAbs -- Register script stake address void $ execCli' execConfig [ anyEraToString anyEra, "transaction", "build" - , "--change-address", Text.unpack $ paymentKeyInfoAddr $ wallets !! 0 + , "--change-address", Text.unpack $ paymentKeyInfoAddr wallet0 , "--tx-in", Text.unpack $ renderTxIn txin1 , "--tx-out", plutusSpendingScriptAddr <> "+" <> show @Int 5_000_000 , "--tx-out-datum-hash", scriptdatumhash @@ -169,7 +165,7 @@ hprop_plutus_v3 = H.integrationWorkspace "all-plutus-script-purposes" $ \tempAbs let keys2 = Map.keys utxo2 H.note_ $ "keys2: " <> show (length keys2) - txinCollateral <- H.noteShow $ keys2 !! 0 + txinCollateral <- H.noteShowM $ H.headM keys2 void $ H.execCli' execConfig [ anyEraToString anyEra, "query", "utxo" @@ -183,7 +179,7 @@ hprop_plutus_v3 = H.integrationWorkspace "all-plutus-script-purposes" $ \tempAbs let keys3 = Map.keys utxoPlutus H.note_ $ "keys3: " <> show (length keys3) - plutusScriptTxIn <- H.noteShow $ keys3 !! 0 + plutusScriptTxIn <- H.noteShowM $ H.headM keys3 let spendScriptUTxOTxBody = work "spend-script-utxo-tx-body" spendScriptUTxOTx = work "spend-script-utxo-tx" mintValue = mconcat ["5 ", mintingPolicyId, ".", assetName] @@ -193,7 +189,7 @@ hprop_plutus_v3 = H.integrationWorkspace "all-plutus-script-purposes" $ \tempAbs void $ execCli' execConfig [ anyEraToString anyEra, "transaction", "build" - , "--change-address", Text.unpack $ paymentKeyInfoAddr $ wallets !! 1 + , "--change-address", Text.unpack $ paymentKeyInfoAddr wallet1 , "--tx-in-collateral", Text.unpack $ renderTxIn txinCollateral , "--tx-in", Text.unpack $ renderTxIn plutusScriptTxIn , "--tx-in-script-file", plutusSpendingScript diff --git a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Conway/StakeSnapshot.hs b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Conway/StakeSnapshot.hs index 14081d6e146..cdb001f0e14 100644 --- a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Conway/StakeSnapshot.hs +++ b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Conway/StakeSnapshot.hs @@ -22,7 +22,7 @@ import Testnet.Components.TestWatchdog import Testnet.Process.Cli (execCliStdoutToJson) import qualified Testnet.Process.Run as H import qualified Testnet.Property.Util as H -import Testnet.Runtime +import Testnet.Types import Hedgehog (Property, (===)) import qualified Hedgehog as H @@ -53,7 +53,7 @@ hprop_stakeSnapshot = H.integrationRetryWorkspace 2 "conway-stake-snapshot" $ \t poolSprocket1 <- H.noteShow $ nodeSprocket $ poolRuntime poolNode1 execConfig <- H.mkExecConfig tempBaseAbsPath poolSprocket1 testnetMagic - void $ waitUntilEpoch (Api.File configurationFile) + void $ waitUntilEpoch configurationFile (Api.File $ IO.sprocketSystemName poolSprocket1) (EpochNo 3) diff --git a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/KesPeriodInfo.hs b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/KesPeriodInfo.hs index 32f329e6ad4..f604c1d5272 100644 --- a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/KesPeriodInfo.hs +++ b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/KesPeriodInfo.hs @@ -38,6 +38,7 @@ import qualified Testnet.Process.Run as H import Testnet.Process.Run import qualified Testnet.Property.Util as H import Testnet.Runtime +import Testnet.Types import Hedgehog (Property) import qualified Hedgehog as H @@ -75,7 +76,7 @@ hprop_kes_period_info = H.integrationRetryWorkspace 2 "kes-period-info" $ \tempA -- We get our UTxOs from here let utxoAddr = Text.unpack $ paymentKeyInfoAddr wallet0 - utxoSKeyFile = paymentSKey $ paymentKeyInfoPair wallet0 + utxoSKeyFile = signingKeyFp $ paymentKeyInfoPair wallet0 void $ H.execCli' execConfig [ anyEraToString anyEra, "query", "utxo" , "--address", utxoAddr @@ -88,11 +89,10 @@ hprop_kes_period_info = H.integrationRetryWorkspace 2 "kes-period-info" $ \tempA txin1 <- H.noteShow =<< H.headM (Map.keys utxo1) let node1SocketPath = Api.File $ IO.sprocketSystemName node1sprocket - nodeConfigFile = Api.File configurationFile termEpoch = EpochNo 3 (stakePoolId, stakePoolColdSigningKey, stakePoolColdVKey, _, _) <- registerSingleSpo 1 tempAbsPath - nodeConfigFile + configurationFile node1SocketPath termEpoch cTestnetOptions @@ -113,10 +113,10 @@ hprop_kes_period_info = H.integrationRetryWorkspace 2 "kes-period-info" $ \tempA testDelegatorRegCertFp = testStakeDelegator "test-delegator.regcert" testDelegatorDelegCert = testStakeDelegator "test-delegator.delegcert" - _ <- cliStakeAddressKeyGen work - $ KeyNames testDelegatorVkeyFp testDelegatorSKeyFp - _ <- cliAddressKeyGen work - $ KeyNames testDelegatorPaymentVKeyFp testDelegatorPaymentSKeyFp + cliStakeAddressKeyGen + $ KeyPair (File testDelegatorVkeyFp) (File testDelegatorSKeyFp) + cliAddressKeyGen + $ KeyPair (File testDelegatorPaymentVKeyFp) (File testDelegatorPaymentSKeyFp) -- NB: We must include the stake credential testDelegatorPaymentAddr <- execCli @@ -200,7 +200,7 @@ hprop_kes_period_info = H.integrationRetryWorkspace 2 "kes-period-info" $ \tempA let testDelegatorStakeAddressInfoOutFp = work "test-delegator-stake-address-info.json" void $ checkStakeKeyRegistered tempAbsPath - nodeConfigFile + configurationFile node1SocketPath termEpoch execConfig @@ -223,10 +223,10 @@ hprop_kes_period_info = H.integrationRetryWorkspace 2 "kes-period-info" $ \tempA testSpoKesVKey = work "kes.vkey" testSpoKesSKey = work "kes.skey" - _ <- cliNodeKeyGenVrf work - $ KeyNames testSpoVrfVKey testSpoVrfSKey - _ <- cliNodeKeyGenKes work - $ KeyNames testSpoKesVKey testSpoKesSKey + cliNodeKeyGenVrf + $ KeyPair (File testSpoVrfVKey) (File testSpoVrfSKey) + cliNodeKeyGenKes + $ KeyPair (File testSpoKesVKey) (File testSpoKesSKey) let testSpoOperationalCertFp = testSpoDir "node-operational.cert" void $ execCli' execConfig @@ -247,11 +247,11 @@ hprop_kes_period_info = H.integrationRetryWorkspace 2 "kes-period-info" $ \tempA ] jsonBS <- createConfigJson tempAbsPath (cardanoNodeEra cTestnetOptions) - H.lbsWriteFile configurationFile jsonBS + H.lbsWriteFile (unFile configurationFile) jsonBS [newNodePortNumber] <- requestAvailablePortNumbers 1 eRuntime <- runExceptT $ startNode tempAbsPath "test-spo" "127.0.0.1" newNodePortNumber testnetMagic [ "run" - , "--config", configurationFile + , "--config", unFile configurationFile , "--topology", topologyFile , "--database-path", testSpoDir "db" , "--shelley-kes-key", testSpoKesSKey @@ -306,7 +306,7 @@ hprop_kes_period_info = H.integrationRetryWorkspace 2 "kes-period-info" $ \tempA let nodeHasMintedEpoch = currEpoch & succ & succ & succ currentEpoch <- waitUntilEpoch - (Api.File configurationFile) + configurationFile (Api.File $ sprocketSystemName node1sprocket) nodeHasMintedEpoch diff --git a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Query.hs b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Query.hs index 725c43b9867..7aae22fec8d 100644 --- a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Query.hs +++ b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Query.hs @@ -31,12 +31,11 @@ import Testnet.Components.TestWatchdog import qualified Testnet.Process.Cli as H import qualified Testnet.Process.Run as H import qualified Testnet.Property.Util as H -import Testnet.Runtime +import Testnet.Types import Hedgehog import qualified Hedgehog as H import qualified Hedgehog.Extras as H -import qualified Hedgehog.Extras.Stock.IO.Network.Sprocket as IO import qualified Hedgehog.Extras.Test.Golden as H -- | Test CLI queries @@ -67,24 +66,20 @@ hprop_cli_queries = H.integrationWorkspace "cli-queries" $ \tempAbsBasePath' -> } <- cardanoTestnetDefault fastTestnetOptions conf - poolNode1 <- H.headM poolNodes - poolSprocket1 <- H.noteShow $ nodeSprocket $ poolRuntime poolNode1 + PoolNode{poolRuntime} <- H.headM poolNodes + poolSprocket1 <- H.noteShow $ nodeSprocket poolRuntime execConfig <- H.mkExecConfig tempBaseAbsPath poolSprocket1 testnetMagic + let socketPath = nodeSocketPath poolRuntime - let socketName' = IO.sprocketName poolSprocket1 - socketBase = IO.sprocketBase poolSprocket1 -- /tmp - socketPath = socketBase socketName' - - epochStateView <- getEpochStateView (File configurationFile) (File socketPath) + epochStateView <- getEpochStateView configurationFile socketPath H.note_ $ "Sprocket: " <> show poolSprocket1 H.note_ $ "Abs path: " <> tempAbsBasePath' - H.note_ $ "Socketpath: " <> socketPath - H.note_ $ "Foldblocks config file: " <> configurationFile + H.note_ $ "Socketpath: " <> unFile socketPath + H.note_ $ "Foldblocks config file: " <> unFile configurationFile checkDRepsNumber epochStateView sbe 3 - -- protocol-parameters do -- to stdout diff --git a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/QuerySlotNumber.hs b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/QuerySlotNumber.hs index 53bd840938f..88b11b9bc11 100644 --- a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/QuerySlotNumber.hs +++ b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/QuerySlotNumber.hs @@ -28,7 +28,7 @@ import Testnet.Components.TestWatchdog import qualified Testnet.Process.Run as H import Testnet.Process.Run import qualified Testnet.Property.Util as H -import Testnet.Runtime +import Testnet.Types import Hedgehog (Property) import qualified Hedgehog.Extras.Stock as H diff --git a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/FoldBlocks.hs b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/FoldBlocks.hs deleted file mode 100644 index 514e4d1504f..00000000000 --- a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/FoldBlocks.hs +++ /dev/null @@ -1,81 +0,0 @@ -{-# LANGUAGE NamedFieldPuns #-} -{-# LANGUAGE NumericUnderscores #-} -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE TupleSections #-} - -module Cardano.Testnet.Test.FoldBlocks where - -import Cardano.Api hiding (cardanoEra) -import qualified Cardano.Api as Api -import Cardano.Api.Error -import qualified Cardano.Api.Shelley as Api - -import Cardano.Testnet as TN - -import Prelude - -import qualified Control.Concurrent as IO -import Control.Concurrent.Async (async, link) -import Control.Exception (Exception, throw) -import Control.Monad -import qualified System.Directory as IO -import System.FilePath (()) - -import Testnet.Components.TestWatchdog -import qualified Testnet.Property.Util as H -import Testnet.Runtime - -import qualified Hedgehog as H -import qualified Hedgehog.Extras.Stock.IO.Network.Sprocket as H -import qualified Hedgehog.Extras.Test as H - - -newtype FoldBlocksException = FoldBlocksException Api.FoldBlocksError -instance Exception FoldBlocksException -instance Show FoldBlocksException where - show (FoldBlocksException a) = displayError a - --- | This test starts a testnet with wery short timing, then starts --- `foldBlocks` in another thread to listen for ledger state, ledger --- events and block, and on reception writes this to the `lock` `MVar` --- that main thread blocks on. -prop_foldBlocks :: H.Property -prop_foldBlocks = H.integrationRetryWorkspace 2 "foldblocks" $ \tempAbsBasePath' -> runWithDefaultWatchdog_ $ do - -- Start testnet - conf <- TN.mkConf tempAbsBasePath' - - let tempAbsPath' = unTmpAbsPath $ tempAbsPath conf - era = BabbageEra - options = cardanoDefaultTestnetOptions - { cardanoNodeEra = AnyCardanoEra era -- TODO: We should only support the latest era and the upcoming era - } - - runtime@TestnetRuntime{configurationFile} <- cardanoTestnetDefault options conf - - -- Get socketPath - socketPathAbs <- do - socketPath' <- H.sprocketArgumentName <$> H.headM (poolSprockets runtime) - H.noteIO (IO.canonicalizePath $ tempAbsPath' socketPath') - - -- Start foldBlocks in a separate thread - lock <- H.evalIO IO.newEmptyMVar - H.evalIO $ do - a <- async $ - -- The `forever` is here because `foldBlocks` drains blocks - -- until current slot and then quits -- even if there are no - -- permanent (= older than the k parameter) blocks created. In - -- that case we simply restart `foldBlocks` again. - forever $ do - let handler :: Env -> LedgerState -> [Api.LedgerEvent] -> BlockInMode -> () -> IO ((), FoldStatus) - handler _env _ledgerState _ledgerEvents _blockInCardanoMode _ = (, ContinueFold) <$> IO.putMVar lock () - e <- runExceptT (Api.foldBlocks (File configurationFile) (Api.File socketPathAbs) Api.QuickValidation () handler) - either (throw . FoldBlocksException) (\_ -> pure ()) e - link a -- Throw async thread's exceptions in main thread - - -- The `lock` is written to from within the `handler` above. It - -- tests that `foldBlocks` receives ledger state; once that happens, - -- handler is called, which then writes to the `lock` and allows the - -- test to finish. - _ <- H.evalIO $ H.timeout 30_000_000 $ IO.readMVar lock - H.assert True - diff --git a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/FoldEpochState.hs b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/FoldEpochState.hs index 466b2617656..03965ace67b 100644 --- a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/FoldEpochState.hs +++ b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/FoldEpochState.hs @@ -15,8 +15,9 @@ import Control.Monad.Trans.State.Strict import qualified System.Directory as IO import System.FilePath (()) +import Testnet.Components.TestWatchdog import qualified Testnet.Property.Util as H -import Testnet.Runtime +import Testnet.Types import Hedgehog ((===)) import qualified Hedgehog as H @@ -24,7 +25,7 @@ import qualified Hedgehog.Extras.Stock.IO.Network.Sprocket as H import qualified Hedgehog.Extras.Test as H prop_foldEpochState :: H.Property -prop_foldEpochState = H.integrationWorkspace "foldEpochState" $ \tempAbsBasePath' -> do +prop_foldEpochState = H.integrationWorkspace "foldEpochState" $ \tempAbsBasePath' -> runWithDefaultWatchdog_ $ do conf <- TN.mkConf tempAbsBasePath' let tempAbsPath' = unTmpAbsPath $ tempAbsPath conf @@ -52,6 +53,6 @@ prop_foldEpochState = H.integrationWorkspace "foldEpochState" $ \tempAbsBasePath else pure ConditionNotMet (_, nums) <- H.leftFailM $ H.evalIO $ runExceptT $ - Api.foldEpochState (File configurationFile) (Api.File socketPathAbs) Api.QuickValidation (EpochNo maxBound) [] handler + Api.foldEpochState configurationFile (Api.File socketPathAbs) Api.QuickValidation (EpochNo maxBound) [] handler length nums === 10 diff --git a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/DRepActivity.hs b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/DRepActivity.hs index 6b1916de23f..06b62270089 100644 --- a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/DRepActivity.hs +++ b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/DRepActivity.hs @@ -43,11 +43,10 @@ import Testnet.Defaults import qualified Testnet.Process.Cli as P import qualified Testnet.Process.Run as H import qualified Testnet.Property.Util as H -import Testnet.Runtime +import Testnet.Types import Hedgehog import qualified Hedgehog.Extras as H -import qualified Hedgehog.Extras.Stock.IO.Network.Sprocket as IO -- | Execute me with: -- @DISABLE_RETRIES=1 cabal test cardano-testnet-test --test-options '-p "/DRep Activity/"'@ @@ -78,20 +77,17 @@ hprop_check_drep_activity = H.integrationWorkspace "test-activity" $ \tempAbsBas } <- cardanoTestnetDefault fastTestnetOptions conf - poolNode1 <- H.headM poolNodes - poolSprocket1 <- H.noteShow $ nodeSprocket $ poolRuntime poolNode1 + PoolNode{poolRuntime} <- H.headM poolNodes + poolSprocket1 <- H.noteShow $ nodeSprocket poolRuntime execConfig <- H.mkExecConfig tempBaseAbsPath poolSprocket1 testnetMagic + let socketPath = nodeSocketPath poolRuntime - let socketName' = IO.sprocketName poolSprocket1 - socketBase = IO.sprocketBase poolSprocket1 -- /tmp - socketPath = socketBase socketName' - - epochStateView <- getEpochStateView (File configurationFile) (File socketPath) + epochStateView <- getEpochStateView configurationFile socketPath H.note_ $ "Sprocket: " <> show poolSprocket1 H.note_ $ "Abs path: " <> tempAbsBasePath' - H.note_ $ "Socketpath: " <> socketPath - H.note_ $ "Foldblocks config file: " <> configurationFile + H.note_ $ "Socketpath: " <> unFile socketPath + H.note_ $ "Foldblocks config file: " <> unFile configurationFile gov <- H.createDirectoryIfMissing $ work "governance" @@ -155,8 +151,8 @@ activityChangeProposalTest :: (HasCallStack, MonadTest m, MonadIO m, H.MonadAssertion m, MonadCatch m, Foldable t) => H.ExecConfig -> EpochStateView - -> FilePath - -> FilePath + -> NodeConfigFile In + -> SocketPath -> ConwayEraOnwards ConwayEra -> FilePath -> FilePath @@ -183,7 +179,7 @@ activityChangeProposalTest execConfig epochStateView configurationFile socketPat H.note_ $ "Epoch before \"" <> prefix <> "\" prop: " <> show epochBeforeProp thisProposal@(governanceActionTxId, governanceActionIndex) <- - makeActivityChangeProposal execConfig epochStateView (File configurationFile) (File socketPath) + makeActivityChangeProposal execConfig epochStateView configurationFile socketPath ceo baseDir "proposal" mPreviousProposalInfo change wallet (epochBeforeProp + maxWait) voteChangeProposal execConfig epochStateView sbe baseDir "vote" @@ -202,8 +198,8 @@ activityChangeProposalTest execConfig epochStateView configurationFile socketPat waitAndCheck epochAfterProp = do !eProposalResult <- evalIO . runExceptT $ foldEpochState - (File configurationFile) - (File socketPath) + configurationFile + socketPath FullValidation (EpochNo (epochAfterProp + maxWait)) () @@ -258,10 +254,10 @@ makeActivityChangeProposal execConfig epochStateView configurationFile socketPat let stakeVkeyFp = baseDir "stake.vkey" stakeSKeyFp = baseDir "stake.skey" - _ <- P.cliStakeAddressKeyGen baseDir - $ P.KeyNames { P.verificationKeyFile = stakeVkeyFp - , P.signingKeyFile = stakeSKeyFp - } + P.cliStakeAddressKeyGen + $ KeyPair { verificationKey = File stakeVkeyFp + , signingKey = File stakeSKeyFp + } proposalAnchorFile <- H.note $ baseDir "sample-proposal-anchor" H.writeFile proposalAnchorFile "dummy anchor data" @@ -302,15 +298,15 @@ makeActivityChangeProposal execConfig epochStateView configurationFile socketPat ] signedProposalTx <- signTx execConfig cEra baseDir "signed-proposal" - (File proposalBody) [paymentKeyInfoPair wallet] + (File proposalBody) [SomeKeyPair $ paymentKeyInfoPair wallet] submitTx execConfig cEra signedProposalTx governanceActionTxId <- retrieveTransactionId execConfig signedProposalTx - !propSubmittedResult <- findCondition (maybeExtractGovernanceActionIndex sbe (fromString governanceActionTxId)) - (unFile configurationFile) - (unFile socketPath) + !propSubmittedResult <- findCondition (maybeExtractGovernanceActionIndex (fromString governanceActionTxId)) + configurationFile + socketPath (EpochNo timeout) governanceActionIndex <- case propSubmittedResult of @@ -323,7 +319,12 @@ makeActivityChangeProposal execConfig epochStateView configurationFile socketPat return (governanceActionTxId, governanceActionIndex) -voteChangeProposal :: (HasCallStack, MonadTest m, MonadIO m, MonadCatch m, H.MonadAssertion m) +voteChangeProposal + :: HasCallStack + => MonadTest m + => MonadIO m + => MonadCatch m + => H.MonadAssertion m => H.ExecConfig -> EpochStateView -> ShelleyBasedEra ConwayEra @@ -347,6 +348,7 @@ voteChangeProposal execConfig epochStateView sbe work prefix governanceActionTxI voteTxBodyFp <- createVotingTxBody execConfig epochStateView sbe baseDir "vote-tx-body" voteFiles wallet - voteTxFp <- signTx execConfig cEra baseDir "signed-vote-tx" voteTxBodyFp - (paymentKeyInfoPair wallet:[defaultDRepKeyPair n | (_, n) <- votes]) + let signingKeys = SomeKeyPair <$> (paymentKeyInfoPair wallet:(defaultDRepKeyPair . snd <$> votes)) + voteTxFp <- signTx execConfig cEra baseDir "signed-vote-tx" voteTxBodyFp signingKeys + submitTx execConfig cEra voteTxFp diff --git a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/DRepDeposit.hs b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/DRepDeposit.hs index c12a50fc8b8..a26292bcc00 100644 --- a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/DRepDeposit.hs +++ b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/DRepDeposit.hs @@ -9,9 +9,8 @@ import qualified Cardano.Api.Ledger as L import Cardano.Testnet (CardanoTestnetOptions (cardanoEpochLength, cardanoNodeEra, cardanoNumDReps), - Conf (Conf, tempAbsPath), NodeRuntime (nodeSprocket), - TmpAbsolutePath (unTmpAbsPath), cardanoDefaultTestnetOptions, - cardanoTestnetDefault, makeTmpBaseAbsPath, mkConf) + Conf (Conf, tempAbsPath), TmpAbsolutePath (unTmpAbsPath), + cardanoDefaultTestnetOptions, cardanoTestnetDefault, makeTmpBaseAbsPath, mkConf) import Prelude @@ -25,12 +24,10 @@ import Testnet.Components.Query (checkDRepState, getEpochStateView, ge import Testnet.Components.TestWatchdog (runWithDefaultWatchdog_) import qualified Testnet.Process.Run as H import qualified Testnet.Property.Util as H -import Testnet.Runtime (PaymentKeyInfo (paymentKeyInfoPair), PoolNode (poolRuntime), - TestnetRuntime (TestnetRuntime, configurationFile, poolNodes, testnetMagic, wallets)) +import Testnet.Types import Hedgehog (Property) import qualified Hedgehog.Extras as H -import qualified Hedgehog.Extras.Stock.IO.Network.Sprocket as IO -- | Execute me with: @@ -63,20 +60,17 @@ hprop_ledger_events_drep_deposits = H.integrationWorkspace "drep-deposits" $ \te } <- cardanoTestnetDefault fastTestnetOptions conf - poolNode1 <- H.headM poolNodes - poolSprocket1 <- H.noteShow $ nodeSprocket $ poolRuntime poolNode1 + PoolNode{poolRuntime} <- H.headM poolNodes + poolSprocket1 <- H.noteShow $ nodeSprocket poolRuntime execConfig <- H.mkExecConfig tempBaseAbsPath poolSprocket1 testnetMagic + let socketPath = nodeSocketPath poolRuntime - let socketName' = IO.sprocketName poolSprocket1 - socketBase = IO.sprocketBase poolSprocket1 -- /tmp - socketPath = socketBase socketName' - - epochStateView <- getEpochStateView (File configurationFile) (File socketPath) + epochStateView <- getEpochStateView configurationFile socketPath H.note_ $ "Sprocket: " <> show poolSprocket1 H.note_ $ "Abs path: " <> tempAbsBasePath' - H.note_ $ "Socketpath: " <> socketPath - H.note_ $ "Foldblocks config file: " <> configurationFile + H.note_ $ "Socketpath: " <> unFile socketPath + H.note_ $ "Foldblocks config file: " <> unFile configurationFile gov <- H.createDirectoryIfMissing $ work "governance" @@ -92,7 +86,7 @@ hprop_ledger_events_drep_deposits = H.integrationWorkspace "drep-deposits" $ \te drepRegTxBody1 <- createCertificatePublicationTxBody execConfig epochStateView sbe drepDir1 "reg-cert-txbody" drepRegCert1 wallet0 drepSignedRegTx1 <- signTx execConfig cEra drepDir1 "signed-reg-tx" - drepRegTxBody1 [drepKeyPair1, paymentKeyInfoPair wallet0] + drepRegTxBody1 [SomeKeyPair drepKeyPair1, SomeKeyPair $ paymentKeyInfoPair wallet0] failToSubmitTx execConfig cEra drepSignedRegTx1 "ConwayDRepIncorrectDeposit" diff --git a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/DRepRetirement.hs b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/DRepRetirement.hs index fc999654779..e49c7db4728 100644 --- a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/DRepRetirement.hs +++ b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/DRepRetirement.hs @@ -25,12 +25,11 @@ import Testnet.Defaults import qualified Testnet.Process.Cli as P import qualified Testnet.Process.Run as H import qualified Testnet.Property.Util as H -import Testnet.Runtime +import Testnet.Types import Hedgehog import qualified Hedgehog as H import qualified Hedgehog.Extras as H -import qualified Hedgehog.Extras.Stock.IO.Network.Sprocket as IO -- | The era in which this test runs sbe :: ShelleyBasedEra ConwayEra @@ -63,19 +62,16 @@ hprop_drep_retirement = H.integrationRetryWorkspace 2 "drep-retirement" $ \tempA } <- cardanoTestnetDefault fastTestnetOptions conf - poolNode1 <- H.headM poolNodes - poolSprocket1 <- H.noteShow $ nodeSprocket $ poolRuntime poolNode1 + PoolNode{poolRuntime} <- H.headM poolNodes + poolSprocket1 <- H.noteShow $ nodeSprocket poolRuntime execConfig <- H.mkExecConfig tempBaseAbsPath poolSprocket1 testnetMagic + let socketPath = nodeSocketPath poolRuntime - let socketName' = IO.sprocketName poolSprocket1 - socketBase = IO.sprocketBase poolSprocket1 -- /tmp - socketPath = socketBase socketName' - - epochStateView <- getEpochStateView (File configurationFile) (File socketPath) + epochStateView <- getEpochStateView configurationFile socketPath H.note_ $ "Sprocket: " <> show poolSprocket1 H.note_ $ "Abs path: " <> tempAbsBasePath' - H.note_ $ "Socketpath: " <> socketPath + H.note_ $ "Socketpath: " <> unFile socketPath -- Create Conway constitution gov <- H.createDirectoryIfMissing $ work "governance" @@ -83,10 +79,10 @@ hprop_drep_retirement = H.integrationRetryWorkspace 2 "drep-retirement" $ \tempA let stakeVkeyFp = gov "stake.vkey" stakeSKeyFp = gov "stake.skey" - _ <- P.cliStakeAddressKeyGen tempAbsPath' - $ P.KeyNames { P.verificationKeyFile = stakeVkeyFp - , P.signingKeyFile = stakeSKeyFp - } + P.cliStakeAddressKeyGen + $ KeyPair { verificationKey = File stakeVkeyFp + , signingKey = File stakeSKeyFp + } let sizeBefore = 3 checkDRepsNumber epochStateView sbe sizeBefore @@ -95,7 +91,7 @@ hprop_drep_retirement = H.integrationRetryWorkspace 2 "drep-retirement" $ \tempA H.noteM_ $ H.execCli' execConfig [ "conway", "governance", "drep", "retirement-certificate" - , "--drep-verification-key-file", defaultDRepVkeyFp 1 + , "--drep-verification-key-file", verificationKeyFp $ defaultDRepKeyPair 1 , "--deposit-amt", show @Int 1_000_000 , "--out-file", dreprRetirementCertFile ] @@ -124,8 +120,8 @@ hprop_drep_retirement = H.integrationRetryWorkspace 2 "drep-retirement" $ \tempA H.noteM_ $ H.execCli' execConfig [ "conway", "transaction", "sign" , "--tx-body-file", drepRetirementRegTxbodyFp - , "--signing-key-file", paymentSKey $ paymentKeyInfoPair wallet0 - , "--signing-key-file", defaultDRepSkeyFp 1 + , "--signing-key-file", signingKeyFp $ paymentKeyInfoPair wallet0 + , "--signing-key-file", signingKeyFp $ defaultDRepKeyPair 1 , "--out-file", drepRetirementRegTxSignedFp ] diff --git a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/InfoAction.hs b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/InfoAction.hs index c360f2215b5..b70d4cc32cc 100644 --- a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/InfoAction.hs +++ b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/InfoAction.hs @@ -37,11 +37,10 @@ import Testnet.Defaults import qualified Testnet.Process.Cli as P import qualified Testnet.Process.Run as H import qualified Testnet.Property.Util as H -import Testnet.Runtime +import Testnet.Types import Hedgehog import qualified Hedgehog.Extras as H -import qualified Hedgehog.Extras.Stock.IO.Network.Sprocket as IO -- | Execute me with: -- @DISABLE_RETRIES=1 cabal test cardano-testnet-test --test-options '-p "/InfoAction/'@ @@ -55,8 +54,9 @@ hprop_ledger_events_info_action = H.integrationRetryWorkspace 0 "info-hash" $ \t work <- H.createDirectoryIfMissing $ tempAbsPath' "work" - let sbe = ShelleyBasedEraConway + let ceo = ConwayEraOnwardsConway era = toCardanoEra sbe + sbe = conwayEraOnwardsToShelleyBasedEra ceo fastTestnetOptions = cardanoDefaultTestnetOptions { cardanoEpochLength = 100 , cardanoNodeEra = AnyCardanoEra era @@ -70,20 +70,17 @@ hprop_ledger_events_info_action = H.integrationRetryWorkspace 0 "info-hash" $ \t } <- cardanoTestnetDefault fastTestnetOptions conf - poolNode1 <- H.headM poolNodes - poolSprocket1 <- H.noteShow $ nodeSprocket $ poolRuntime poolNode1 + PoolNode{poolRuntime} <- H.headM poolNodes + poolSprocket1 <- H.noteShow $ nodeSprocket poolRuntime execConfig <- H.mkExecConfig tempBaseAbsPath poolSprocket1 testnetMagic + let socketPath = nodeSocketPath poolRuntime - let socketName' = IO.sprocketName poolSprocket1 - socketBase = IO.sprocketBase poolSprocket1 -- /tmp - socketPath = socketBase socketName' - - epochStateView <- getEpochStateView (File configurationFile) (File socketPath) + epochStateView <- getEpochStateView configurationFile socketPath H.note_ $ "Sprocket: " <> show poolSprocket1 H.note_ $ "Abs path: " <> tempAbsBasePath' - H.note_ $ "Socketpath: " <> socketPath - H.note_ $ "Foldblocks config file: " <> configurationFile + H.note_ $ "Socketpath: " <> unFile socketPath + H.note_ $ "Foldblocks config file: " <> unFile configurationFile gov <- H.createDirectoryIfMissing $ work "governance" proposalAnchorFile <- H.note $ work gov "sample-proposal-anchor" @@ -99,10 +96,10 @@ hprop_ledger_events_info_action = H.integrationRetryWorkspace 0 "info-hash" $ \t let stakeVkeyFp = gov "stake.vkey" stakeSKeyFp = gov "stake.skey" - _ <- P.cliStakeAddressKeyGen tempAbsPath' - $ P.KeyNames { P.verificationKeyFile = stakeVkeyFp - , P.signingKeyFile = stakeSKeyFp - } + P.cliStakeAddressKeyGen + $ KeyPair { verificationKey = File stakeVkeyFp + , signingKey= File stakeSKeyFp + } -- Create info action proposal @@ -133,7 +130,7 @@ hprop_ledger_events_info_action = H.integrationRetryWorkspace 0 "info-hash" $ \t void $ H.execCli' execConfig [ "conway", "transaction", "sign" , "--tx-body-file", txbodyFp - , "--signing-key-file", paymentSKey $ paymentKeyInfoPair wallet1 + , "--signing-key-file", signingKeyFp $ paymentKeyInfoPair wallet1 , "--out-file", txbodySignedFp ] @@ -147,7 +144,7 @@ hprop_ledger_events_info_action = H.integrationRetryWorkspace 0 "info-hash" $ \t , "--tx-file", txbodySignedFp ] - !propSubmittedResult <- findCondition (maybeExtractGovernanceActionIndex sbe (fromString txidString)) + !propSubmittedResult <- findCondition (maybeExtractGovernanceActionIndex (fromString txidString)) configurationFile socketPath (EpochNo 10) @@ -170,7 +167,7 @@ hprop_ledger_events_info_action = H.integrationRetryWorkspace 0 "info-hash" $ \t , "--yes" , "--governance-action-tx-id", txidString , "--governance-action-index", show @Word32 governanceActionIndex - , "--drep-verification-key-file", defaultDRepVkeyFp n + , "--drep-verification-key-file", verificationKeyFp $ defaultDRepKeyPair n , "--out-file", voteFp n ] @@ -197,10 +194,10 @@ hprop_ledger_events_info_action = H.integrationRetryWorkspace 0 "info-hash" $ \t void $ H.execCli' execConfig [ "conway", "transaction", "sign" , "--tx-body-file", voteTxBodyFp - , "--signing-key-file", paymentSKey $ paymentKeyInfoPair wallet0 - , "--signing-key-file", defaultDRepSkeyFp 1 - , "--signing-key-file", defaultDRepSkeyFp 2 - , "--signing-key-file", defaultDRepSkeyFp 3 + , "--signing-key-file", signingKeyFp $ paymentKeyInfoPair wallet0 + , "--signing-key-file", signingKeyFp $ defaultDRepKeyPair 1 + , "--signing-key-file", signingKeyFp $ defaultDRepKeyPair 2 + , "--signing-key-file", signingKeyFp $ defaultDRepKeyPair 3 , "--out-file", voteTxFp ] @@ -212,8 +209,8 @@ hprop_ledger_events_info_action = H.integrationRetryWorkspace 0 "info-hash" $ \t -- We check that info action was succcessfully ratified !meInfoRatified <- H.timeout 120_000_000 $ runExceptT $ foldBlocks - (File configurationFile) - (File socketPath) + configurationFile + socketPath FullValidation (InfoActionState False False) -- Initial accumulator state (foldBlocksCheckInfoAction (tempAbsPath' "events.log") governanceActionIndex ) diff --git a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/ProposeNewConstitution.hs b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/ProposeNewConstitution.hs index bb44c00b99c..fc264643c42 100644 --- a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/ProposeNewConstitution.hs +++ b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/ProposeNewConstitution.hs @@ -42,11 +42,10 @@ import Testnet.Defaults import qualified Testnet.Process.Cli as P import qualified Testnet.Process.Run as H import qualified Testnet.Property.Util as H -import Testnet.Runtime +import Testnet.Types import Hedgehog import qualified Hedgehog.Extras as H -import qualified Hedgehog.Extras.Stock.IO.Network.Sprocket as IO -- | Execute me with: -- @DISABLE_RETRIES=1 cabal test cardano-testnet-test --test-options '-p "/ProposeAndRatifyNewConstitution/"'@ @@ -86,20 +85,17 @@ hprop_ledger_events_propose_new_constitution = H.integrationWorkspace "propose-n } <- cardanoTestnetDefault fastTestnetOptions conf - poolNode1 <- H.headM poolNodes - poolSprocket1 <- H.noteShow $ nodeSprocket $ poolRuntime poolNode1 + PoolNode{poolRuntime} <- H.headM poolNodes + poolSprocket1 <- H.noteShow $ nodeSprocket poolRuntime execConfig <- H.mkExecConfig tempBaseAbsPath poolSprocket1 testnetMagic + let socketPath = nodeSocketPath poolRuntime - let socketName' = IO.sprocketName poolSprocket1 - socketBase = IO.sprocketBase poolSprocket1 -- /tmp - socketPath = socketBase socketName' - - epochStateView <- getEpochStateView (File configurationFile) (File socketPath) + epochStateView <- getEpochStateView configurationFile socketPath H.note_ $ "Sprocket: " <> show poolSprocket1 H.note_ $ "Abs path: " <> tempAbsBasePath' - H.note_ $ "Socketpath: " <> socketPath - H.note_ $ "Foldblocks config file: " <> configurationFile + H.note_ $ "Socketpath: " <> unFile socketPath + H.note_ $ "Foldblocks config file: " <> unFile configurationFile -- Create Conway constitution gov <- H.createDirectoryIfMissing $ work "governance" @@ -122,12 +118,12 @@ hprop_ledger_events_propose_new_constitution = H.integrationWorkspace "propose-n let stakeVkeyFp = gov "stake.vkey" stakeSKeyFp = gov "stake.skey" - _ <- P.cliStakeAddressKeyGen tempAbsPath' - $ P.KeyNames { P.verificationKeyFile = stakeVkeyFp - , P.signingKeyFile = stakeSKeyFp - } - -- Create constitution proposal + P.cliStakeAddressKeyGen + $ KeyPair { verificationKey = File stakeVkeyFp + , signingKey = File stakeSKeyFp + } + -- Create constitution proposal guardRailScriptFp <- H.note $ work "guard-rail-script.plutusV3" H.writeFile guardRailScriptFp $ Text.unpack plutusV3NonSpendingScript -- TODO: Update help text for policyid. The script hash is not @@ -167,13 +163,13 @@ hprop_ledger_events_propose_new_constitution = H.integrationWorkspace "propose-n ] signedProposalTx <- signTx execConfig cEra gov "signed-proposal" - (File txbodyFp) [paymentKeyInfoPair wallet1] + (File txbodyFp) [SomeKeyPair $ paymentKeyInfoPair wallet1] submitTx execConfig cEra signedProposalTx governanceActionTxId <- retrieveTransactionId execConfig signedProposalTx - !propSubmittedResult <- findCondition (maybeExtractGovernanceActionIndex sbe (fromString governanceActionTxId)) + !propSubmittedResult <- findCondition (maybeExtractGovernanceActionIndex (fromString governanceActionTxId)) configurationFile socketPath (EpochNo 10) @@ -195,8 +191,9 @@ hprop_ledger_events_propose_new_constitution = H.integrationWorkspace "propose-n voteTxBodyFp <- createVotingTxBody execConfig epochStateView sbe work "vote-tx-body" voteFiles wallet0 - voteTxFp <- signTx execConfig cEra gov "signed-vote-tx" voteTxBodyFp - (paymentKeyInfoPair wallet0:[defaultDRepKeyPair n | (_, n) <- allVotes]) + let signingKeys = SomeKeyPair <$> (paymentKeyInfoPair wallet0:(defaultDRepKeyPair . snd <$> allVotes)) + voteTxFp <- signTx execConfig cEra gov "signed-vote-tx" voteTxBodyFp signingKeys + submitTx execConfig cEra voteTxFp _ <- waitForEpochs epochStateView (EpochInterval 1) @@ -215,8 +212,8 @@ hprop_ledger_events_propose_new_constitution = H.integrationWorkspace "propose-n -- We check that constitution was succcessfully ratified void . H.leftFailM . evalIO . runExceptT $ foldEpochState - (File configurationFile) - (File socketPath) + configurationFile + socketPath FullValidation (EpochNo 10) () diff --git a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/ProposeNewConstitutionSPO.hs b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/ProposeNewConstitutionSPO.hs index d4793b43abe..fcae279c2b0 100644 --- a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/ProposeNewConstitutionSPO.hs +++ b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/ProposeNewConstitutionSPO.hs @@ -9,7 +9,6 @@ module Cardano.Testnet.Test.Gov.ProposeNewConstitutionSPO ) where import Cardano.Api -import qualified Cardano.Api as Api import Cardano.Api.Ledger import qualified Cardano.Ledger.Conway.Governance as L @@ -31,16 +30,15 @@ import Testnet.Components.DRep (createVotingTxBody, failToSubmitTx, re import Testnet.Components.Query import Testnet.Components.SPO (generateVoteFiles) import Testnet.Components.TestWatchdog -import Testnet.Defaults (defaultSPOColdKeyPair, defaultSPOKeys) +import Testnet.Defaults import qualified Testnet.Process.Cli as P import qualified Testnet.Process.Run as H import qualified Testnet.Property.Util as H -import Testnet.Runtime +import Testnet.Types import Hedgehog import qualified Hedgehog as H import qualified Hedgehog.Extras as H -import qualified Hedgehog.Extras.Stock.IO.Network.Sprocket as IO -- | Test that SPO cannot vote on a new constitution -- Execute me with: @@ -49,8 +47,7 @@ hprop_ledger_events_propose_new_constitution_spo :: Property hprop_ledger_events_propose_new_constitution_spo = H.integrationWorkspace "propose-new-constitution-spo" $ \tempAbsBasePath' -> runWithDefaultWatchdog_ $ do conf@Conf { tempAbsPath=tempAbsPath@(TmpAbsolutePath work) } <- mkConf tempAbsBasePath' - let tempAbsPath' = unTmpAbsPath tempAbsPath - tempBaseAbsPath = makeTmpBaseAbsPath tempAbsPath + let tempBaseAbsPath = makeTmpBaseAbsPath tempAbsPath let ceo = ConwayEraOnwardsConway sbe = conwayEraOnwardsToShelleyBasedEra ceo @@ -70,20 +67,17 @@ hprop_ledger_events_propose_new_constitution_spo = H.integrationWorkspace "propo } <- cardanoTestnetDefault fastTestnetOptions conf - poolNode1 <- H.headM poolNodes - poolSprocket1 <- H.noteShow $ nodeSprocket $ poolRuntime poolNode1 + PoolNode{poolRuntime} <- H.headM poolNodes + poolSprocket1 <- H.noteShow $ nodeSprocket poolRuntime execConfig <- H.mkExecConfig tempBaseAbsPath poolSprocket1 testnetMagic + let socketPath = nodeSocketPath poolRuntime - let socketName' = IO.sprocketName poolSprocket1 - socketBase = IO.sprocketBase poolSprocket1 -- /tmp - socketPath = socketBase socketName' - - epochStateView <- getEpochStateView (File configurationFile) (File socketPath) + epochStateView <- getEpochStateView configurationFile socketPath H.note_ $ "Sprocket: " <> show poolSprocket1 H.note_ $ "Abs path: " <> tempAbsBasePath' - H.note_ $ "Socketpath: " <> socketPath - H.note_ $ "Foldblocks config file: " <> configurationFile + H.note_ $ "Socketpath: " <> unFile socketPath + H.note_ $ "Foldblocks config file: " <> unFile configurationFile -- Create Conway constitution gov <- H.createDirectoryIfMissing $ work "governance" @@ -106,10 +100,10 @@ hprop_ledger_events_propose_new_constitution_spo = H.integrationWorkspace "propo let stakeVkeyFp = gov "stake.vkey" stakeSKeyFp = gov "stake.skey" - _ <- P.cliStakeAddressKeyGen tempAbsPath' - $ P.KeyNames { P.verificationKeyFile = stakeVkeyFp - , P.signingKeyFile = stakeSKeyFp - } + P.cliStakeAddressKeyGen + $ KeyPair { verificationKey = File stakeVkeyFp + , signingKey= File stakeSKeyFp + } minDRepDeposit <- getMinDRepDeposit epochStateView ceo @@ -138,7 +132,7 @@ hprop_ledger_events_propose_new_constitution_spo = H.integrationWorkspace "propo , "--out-file", txBodyFp ] - txBodySigned <- signTx execConfig cEra work "proposal-signed-tx" (File txBodyFp) [paymentKeyInfoPair wallet0] + txBodySigned <- signTx execConfig cEra work "proposal-signed-tx" (File txBodyFp) [SomeKeyPair $ paymentKeyInfoPair wallet0] submitTx execConfig cEra txBodySigned @@ -149,7 +143,7 @@ hprop_ledger_events_propose_new_constitution_spo = H.integrationWorkspace "propo -- Proposal should be there already, so don't wait a lot: let terminationEpoch = succ . succ $ currentEpoch - mGovActionId <- getConstitutionProposal (Api.File configurationFile) (Api.File socketPath) terminationEpoch + mGovActionId <- getConstitutionProposal configurationFile socketPath terminationEpoch govActionId <- H.evalMaybe mGovActionId -- Proposal was successfully submitted, now we vote on the proposal and confirm it was ratified @@ -157,14 +151,14 @@ hprop_ledger_events_propose_new_constitution_spo = H.integrationWorkspace "propo let L.GovActionIx governanceActionIndex = L.gaidGovActionIx govActionId votes <- generateVoteFiles ceo execConfig work "vote-files" txIdString governanceActionIndex - [(defaultSPOKeys n, "yes") | n <- [1..3]] + [(defaultSpoKeys n, "yes") | n <- [1..3]] -- Submit votes votesTxBody <- createVotingTxBody execConfig epochStateView sbe work "vote-tx-body" votes wallet0 votesSignedTx <- signTx execConfig cEra work "vote-signed-tx" votesTxBody (SomeKeyPair (paymentKeyInfoPair wallet0) - :[SomeKeyPair $ defaultSPOColdKeyPair n | n <- [1..3]]) + :[SomeKeyPair $ defaultSpoColdKeyPair n | n <- [1..3]]) -- Call should fail, because SPOs are unallowed to vote on the constitution failToSubmitTx execConfig cEra votesSignedTx "DisallowedVoters" diff --git a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/TreasuryGrowth.hs b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/TreasuryGrowth.hs index 3d34ac35e79..8ca69b180a5 100644 --- a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/TreasuryGrowth.hs +++ b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/TreasuryGrowth.hs @@ -23,7 +23,7 @@ import System.FilePath (()) import Testnet.Components.TestWatchdog import qualified Testnet.Property.Util as H -import Testnet.Runtime +import Testnet.Types import qualified Hedgehog as H import qualified Hedgehog.Extras.Stock.IO.Network.Sprocket as H @@ -46,12 +46,12 @@ prop_check_if_treasury_is_growing = H.integrationRetryWorkspace 0 "growing-treas runtime@TestnetRuntime{configurationFile} <- cardanoTestnetDefault options conf -- Get socketPath - socketPathAbs <- do + socketPathAbs <- Api.File <$> do socketPath' <- H.sprocketArgumentName <$> H.headM (poolSprockets runtime) H.noteIO (IO.canonicalizePath $ tempAbsPath' socketPath') (_condition, treasuryValues) <- H.leftFailM . H.evalIO . runExceptT $ - Api.foldEpochState (File configurationFile) (Api.File socketPathAbs) Api.QuickValidation (EpochNo 10) M.empty handler + Api.foldEpochState configurationFile socketPathAbs Api.QuickValidation (EpochNo 10) M.empty handler H.note_ $ "treasury for last 5 epochs: " <> show treasuryValues let treasuriesSortedByEpoch = diff --git a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/TreasuryWithdrawal.hs b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/TreasuryWithdrawal.hs index a2d98caca9f..40ab345ab4c 100644 --- a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/TreasuryWithdrawal.hs +++ b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/TreasuryWithdrawal.hs @@ -42,12 +42,11 @@ import Testnet.Defaults import qualified Testnet.Process.Cli as P import qualified Testnet.Process.Run as H import qualified Testnet.Property.Util as H -import Testnet.Runtime import Testnet.Start.Types (eraToString) +import Testnet.Types import Hedgehog import qualified Hedgehog.Extras as H -import qualified Hedgehog.Extras.Stock.IO.Network.Sprocket as IO hprop_ledger_events_treasury_withdrawal:: Property hprop_ledger_events_treasury_withdrawal = H.integrationRetryWorkspace 1 "treasury-withdrawal" $ \tempAbsBasePath' -> runWithDefaultWatchdog_ $ do @@ -77,20 +76,17 @@ hprop_ledger_events_treasury_withdrawal = H.integrationRetryWorkspace 1 "treasu } <- cardanoTestnetDefault fastTestnetOptions conf - poolNode1 <- H.headM poolNodes - poolSprocket1 <- H.noteShow $ nodeSprocket $ poolRuntime poolNode1 + PoolNode{poolRuntime} <- H.headM poolNodes + poolSprocket1 <- H.noteShow $ nodeSprocket poolRuntime execConfig <- H.mkExecConfig tempBaseAbsPath poolSprocket1 testnetMagic + let socketPath = nodeSocketPath poolRuntime - let socketName' = IO.sprocketName poolSprocket1 - socketBase = IO.sprocketBase poolSprocket1 -- /tmp - socketPath = socketBase socketName' - - epochStateView <- getEpochStateView (File configurationFile) (File socketPath) + epochStateView <- getEpochStateView configurationFile socketPath H.note_ $ "Sprocket: " <> show poolSprocket1 H.note_ $ "Abs path: " <> tempAbsBasePath' - H.note_ $ "Socketpath: " <> socketPath - H.note_ $ "Foldblocks config file: " <> configurationFile + H.note_ $ "Socketpath: " <> unFile socketPath + H.note_ $ "Foldblocks config file: " <> unFile configurationFile gov <- H.createDirectoryIfMissing $ work "governance" proposalAnchorFile <- H.note $ work gov "sample-proposal-anchor" @@ -110,10 +106,10 @@ hprop_ledger_events_treasury_withdrawal = H.integrationRetryWorkspace 1 "treasu stakeSKeyFp = gov "stake.skey" stakeCertFp = gov "stake.regcert" - _ <- P.cliStakeAddressKeyGen tempAbsPath' - $ P.KeyNames { P.verificationKeyFile = stakeVkeyFp - , P.signingKeyFile = stakeSKeyFp - } + P.cliStakeAddressKeyGen + $ KeyPair { verificationKey = File stakeVkeyFp + , signingKey= File stakeSKeyFp + } void $ H.execCli' execConfig [ eraName, "stake-address", "registration-certificate" @@ -138,7 +134,7 @@ hprop_ledger_events_treasury_withdrawal = H.integrationRetryWorkspace 1 "treasu void $ H.execCli' execConfig [ eraName, "transaction", "sign" , "--tx-body-file", stakeCertTxBodyFp - , "--signing-key-file", paymentSKey $ paymentKeyInfoPair wallet1 + , "--signing-key-file", signingKeyFp $ paymentKeyInfoPair wallet1 , "--signing-key-file", stakeSKeyFp , "--out-file", stakeCertTxSignedFp ] @@ -185,7 +181,7 @@ hprop_ledger_events_treasury_withdrawal = H.integrationRetryWorkspace 1 "treasu void $ H.execCli' execConfig [ eraName, "transaction", "sign" , "--tx-body-file", txbodyFp - , "--signing-key-file", paymentSKey $ paymentKeyInfoPair wallet0 + , "--signing-key-file", signingKeyFp $ paymentKeyInfoPair wallet0 , "--out-file", txbodySignedFp ] @@ -203,7 +199,7 @@ hprop_ledger_events_treasury_withdrawal = H.integrationRetryWorkspace 1 "treasu currentEpoch <- getCurrentEpochNo epochStateView let terminationEpoch = succ . succ $ currentEpoch L.GovActionIx governanceActionIndex <- fmap L.gaidGovActionIx . H.nothingFailM $ - getTreasuryWithdrawalProposal (File configurationFile) (File socketPath) terminationEpoch + getTreasuryWithdrawalProposal configurationFile socketPath terminationEpoch let voteFp :: Int -> FilePath voteFp n = work gov "vote-" <> show n @@ -215,7 +211,7 @@ hprop_ledger_events_treasury_withdrawal = H.integrationRetryWorkspace 1 "treasu , "--yes" , "--governance-action-tx-id", txidString , "--governance-action-index", show governanceActionIndex - , "--drep-verification-key-file", defaultDRepVkeyFp n + , "--drep-verification-key-file", verificationKeyFp $ defaultDRepKeyPair n , "--out-file", voteFp n ] @@ -239,10 +235,10 @@ hprop_ledger_events_treasury_withdrawal = H.integrationRetryWorkspace 1 "treasu void $ H.execCli' execConfig [ eraName, "transaction", "sign" , "--tx-body-file", voteTxBodyFp - , "--signing-key-file", paymentSKey $ paymentKeyInfoPair wallet1 - , "--signing-key-file", defaultDRepSkeyFp 1 - , "--signing-key-file", defaultDRepSkeyFp 2 - , "--signing-key-file", defaultDRepSkeyFp 3 + , "--signing-key-file", signingKeyFp $ paymentKeyInfoPair wallet1 + , "--signing-key-file", signingKeyFp $ defaultDRepKeyPair 1 + , "--signing-key-file", signingKeyFp $ defaultDRepKeyPair 2 + , "--signing-key-file", signingKeyFp $ defaultDRepKeyPair 3 , "--out-file", voteTxFp ] @@ -254,7 +250,7 @@ hprop_ledger_events_treasury_withdrawal = H.integrationRetryWorkspace 1 "treasu withdrawals <- H.nothingFailM $ getCurrentEpochNo epochStateView >>= - getAnyWithdrawals (File configurationFile) (File socketPath) . (`L.addEpochInterval` EpochInterval 5) + getAnyWithdrawals configurationFile socketPath . (`L.addEpochInterval` EpochInterval 5) H.noteShow_ withdrawals (L.unCoin . snd <$> M.toList withdrawals) === [withdrawalAmount] diff --git a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Node/Shutdown.hs b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Node/Shutdown.hs index 8423ecea46b..533b816b4f9 100644 --- a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Node/Shutdown.hs +++ b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Node/Shutdown.hs @@ -39,8 +39,8 @@ import Testnet.Defaults import Testnet.Process.Run import qualified Testnet.Property.Util as H import Testnet.Property.Util -import Testnet.Runtime import Testnet.Start.Byron +import Testnet.Types import Hedgehog (Property, (===)) import qualified Hedgehog as H diff --git a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/SanityCheck.hs b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/SanityCheck.hs index 97a04063057..b22bbbc0d89 100644 --- a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/SanityCheck.hs +++ b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/SanityCheck.hs @@ -18,15 +18,13 @@ import Prelude import GHC.IO.Exception (IOException) import GHC.Stack -import System.FilePath (()) import Testnet.Components.TestWatchdog import qualified Testnet.Property.Util as H -import Testnet.Runtime +import Testnet.Types import Hedgehog import qualified Hedgehog.Extras as H -import qualified Hedgehog.Extras.Stock.IO.Network.Sprocket as IO newtype AdditionalCatcher = IOE IOException @@ -51,21 +49,19 @@ hprop_ledger_events_sanity_check = H.integrationWorkspace "ledger-events-sanity- , cardanoSlotLength = 0.1 } - !testnetRuntime + TestnetRuntime{configurationFile, poolNodes} <- cardanoTestnetDefault fastTestnetOptions conf - NodeRuntime{nodeSprocket} <- H.headM $ poolRuntime <$> poolNodes testnetRuntime - let socketName' = IO.sprocketName nodeSprocket - socketBase = IO.sprocketBase nodeSprocket -- /tmp - socketPath = socketBase socketName' + nr@NodeRuntime{nodeSprocket} <- H.headM $ poolRuntime <$> poolNodes + let socketPath = nodeSocketPath nr H.note_ $ "Sprocket: " <> show nodeSprocket H.note_ $ "Abs path: " <> tempAbsBasePath' - H.note_ $ "Socketpath: " <> socketPath + H.note_ $ "Socketpath: " <> unFile socketPath !ret <- runExceptT $ handleIOExceptionsWith IOE $ evalIO $ runExceptT $ foldBlocks - (File $ configurationFile testnetRuntime) - (File socketPath) + configurationFile + socketPath FullValidation [] -- Initial accumulator state foldBlocksAccumulator diff --git a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/SubmitApi/Babbage/Transaction.hs b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/SubmitApi/Babbage/Transaction.hs index 63513993317..7e251cb7f6e 100644 --- a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/SubmitApi/Babbage/Transaction.hs +++ b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/SubmitApi/Babbage/Transaction.hs @@ -40,8 +40,8 @@ import Testnet.Components.TestWatchdog import qualified Testnet.Process.Run as H import Testnet.Process.Run import qualified Testnet.Property.Util as H -import Testnet.Runtime import Testnet.SubmitApi +import Testnet.Types import Hedgehog (Property, (===)) import qualified Hedgehog as H @@ -80,7 +80,7 @@ hprop_transaction = H.integrationRetryWorkspace 0 "submit-api-babbage-transactio execConfig <- H.mkExecConfig tempBaseAbsPath poolSprocket1 testnetMagic void $ procSubmitApi - [ "--config", configurationFile + [ "--config", unFile configurationFile , "--testnet-magic", show @Int testnetMagic , "--socket-path", "FILEPATH" ] @@ -114,7 +114,7 @@ hprop_transaction = H.integrationRetryWorkspace 0 "submit-api-babbage-transactio void $ execCli' execConfig [ "babbage", "transaction", "sign" , "--tx-body-file", txbodyFp - , "--signing-key-file", paymentSKey $ paymentKeyInfoPair wallet0 + , "--signing-key-file", signingKeyFp $ paymentKeyInfoPair wallet0 , "--out-file", txbodySignedFp ]