Skip to content

Commit

Permalink
Propagate changes to cardano-testnet
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimbo4350 committed Jun 18, 2024
1 parent b7267bd commit 785b023
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 39 deletions.
4 changes: 2 additions & 2 deletions cardano-testnet/src/Testnet/EpochStateProcessing.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import Prelude
import Control.Monad
import qualified Data.Map as Map
import Data.Maybe
import Data.Word (Word32)
import Data.Word (Word16)
import GHC.Exts (IsList (toList), toList)
import GHC.Stack
import Lens.Micro (to, (^.))
Expand All @@ -36,7 +36,7 @@ maybeExtractGovernanceActionIndex
:: HasCallStack
=> TxId -- ^ transaction id searched for
-> AnyNewEpochState
-> Maybe Word32
-> Maybe Word16
maybeExtractGovernanceActionIndex txid (AnyNewEpochState sbe newEpochState) =
caseShelleyToBabbageOrConwayEraOnwards
(const $ error "Governance actions only available in Conway era onwards")
Expand Down
14 changes: 7 additions & 7 deletions cardano-testnet/src/Testnet/Process/Cli/DRep.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import qualified Data.Aeson.Lens as AL
import Data.Text (Text)
import qualified Data.Text as Text
import Data.Typeable (Typeable)
import Data.Word (Word32)
import Data.Word (Word16)
import GHC.Exts (fromString)
import GHC.Stack
import Lens.Micro ((^?))
Expand Down Expand Up @@ -152,7 +152,7 @@ generateVoteFiles
-> String -- ^ Name for the subfolder that will be created under 'work' to store
-- the output voting files.
-> String -- ^ Transaction ID string of the governance action.
-> Word32 -- ^ Index of the governance action.
-> Word16 -- ^ Index of the governance action.
-> [(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").
Expand All @@ -165,7 +165,7 @@ generateVoteFiles execConfig work prefix governanceActionTxId governanceActionIn
[ "conway", "governance", "vote", "create"
, "--" ++ vote
, "--governance-action-tx-id", governanceActionTxId
, "--governance-action-index", show @Word32 governanceActionIndex
, "--governance-action-index", show @Word16 governanceActionIndex
, "--drep-verification-key-file", verificationKeyFp drepKeyPair
, "--out-file", unFile path
]
Expand Down Expand Up @@ -301,14 +301,14 @@ delegateToDRep execConfig epochStateView sbe work prefix
--
-- 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').
-- identifier (as a 'String') and the action index (as a 'Word16').
getLastPParamUpdateActionId
:: HasCallStack
=> MonadTest m
=> MonadCatch m
=> MonadIO m
=> H.ExecConfig -- ^ Specifies the CLI execution configuration.
-> m (Maybe (String, Word32))
-> m (Maybe (String, Word16))
getLastPParamUpdateActionId execConfig = do
govStateJSON :: Aeson.Value <- execCliStdoutToJson execConfig
[ "conway", "query", "gov-state"
Expand Down Expand Up @@ -346,11 +346,11 @@ makeActivityChangeProposal
-> ConwayEraOnwards era -- ^ The 'ConwayEraOnwards' witness for current era.
-> FilePath -- ^ Base directory path where generated files will be stored.
-> String -- ^ Name for the subfolder that will be created under 'work' folder.
-> Maybe (String, Word32) -- ^ The transaction id and the index of the previosu governance action if any.
-> Maybe (String, Word16) -- ^ The transaction id and the index of the previosu governance action if any.
-> EpochInterval -- ^ The target DRep activity interval to be set by the proposal.
-> PaymentKeyInfo -- ^ Wallet that will pay for the transaction.
-> EpochInterval -- ^ Number of epochs to wait for the proposal to be registered by the chain.
-> m (String, Word32) -- ^ The transaction id and the index of the governance action.
-> m (String, Word16) -- ^ The transaction id and the index of the governance action.
makeActivityChangeProposal execConfig epochStateView ceo work prefix
prevGovActionInfo drepActivity wallet timeout = do

Expand Down
8 changes: 4 additions & 4 deletions cardano-testnet/src/Testnet/Process/Cli/SPO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import qualified Data.Map.Strict as Map
import Data.Set (Set)
import qualified Data.Set as Set
import qualified Data.Text as Text
import Data.Word (Word32)
import Data.Word (Word16)
import GHC.Stack (HasCallStack)
import qualified GHC.Stack as GHC
import Lens.Micro
Expand Down Expand Up @@ -129,7 +129,7 @@ checkStakeKeyRegistered tempAbsP nodeConfigFile sPath terminationEpoch execConfi
, "foldEpochStateError: " <> show e
]
where
handler :: StakeAddress -> AnyNewEpochState -> SlotNo -> BlockNo -> StateT DelegationsAndRewards IO LedgerStateCondition
handler :: StakeAddress -> AnyNewEpochState -> SlotNo -> BlockNo -> StateT DelegationsAndRewards IO ConditionResult
handler (StakeAddress network sCred) (AnyNewEpochState sbe newEpochState) _ _ =
let umap = shelleyBasedEraConstraints sbe $ newEpochState ^. L.nesEsL . L.epochStateUMapL
dag = L.filterStakePoolDelegsAndRewards umap $ Set.singleton sCred
Expand Down Expand Up @@ -417,7 +417,7 @@ generateVoteFiles :: (MonadTest m, MonadIO m, MonadCatch m)
-> String -- ^ Name for the subfolder that will be created under 'work' to store
-- the output voting files.
-> String -- ^ Transaction ID string of the governance action.
-> Word32 -- ^ Index of the governance action.
-> Word16 -- ^ Index of the governance action.
-> [(PoolNodeKeys, [Char])] -- ^ List of tuples where each tuple contains a 'PoolNodeKeys'
-- representing the SPO keys and a 'String' representing the
-- vote type (i.e: "yes", "no", or "abstain").
Expand All @@ -430,7 +430,7 @@ generateVoteFiles ceo execConfig work prefix governanceActionTxId governanceActi
[ eraToString $ toCardanoEra ceo , "governance", "vote", "create"
, "--" ++ vote
, "--governance-action-tx-id", governanceActionTxId
, "--governance-action-index", show @Word32 governanceActionIndex
, "--governance-action-index", show @Word16 governanceActionIndex
, "--cold-verification-key-file", verificationKeyFp $ poolNodeKeysCold spoKeys
, "--out-file", unFile path
]
Expand Down
2 changes: 1 addition & 1 deletion cardano-testnet/src/Testnet/Runtime.hs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ startLedgerNewEpochStateLogging testnetRuntime tmpWorkspace = withFrozenCallStac
-> AnyNewEpochState
-> SlotNo
-> BlockNo
-> StateT (Maybe AnyNewEpochState) IO LedgerStateCondition
-> StateT (Maybe AnyNewEpochState) IO ConditionResult
handler outputFp diffFp anes@(AnyNewEpochState !sbe !nes) _ (BlockNo blockNo) = handleException $ do
let prettyNes = shelleyBasedEraConstraints sbe (encodePretty nes)
blockLabel = "#### BLOCK " <> show blockNo <> " ####"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import Lens.Micro
import System.FilePath ((</>))
import qualified System.Info as SYS

import Testnet.Components.Configuration
import Testnet.Process.Run (execCli', mkExecConfig)
import Testnet.Property.Util (decodeEraUTxO, integrationRetryWorkspace)
import Testnet.Types
Expand All @@ -48,9 +49,10 @@ hprop_transaction = integrationRetryWorkspace 0 "babbage-transaction" $ \tempAbs
let
sbe = ShelleyBasedEraBabbage
era = toCardanoEra sbe
cEra = AnyCardanoEra era
tempBaseAbsPath = makeTmpBaseAbsPath $ TmpAbsolutePath tempAbsPath'
options = cardanoDefaultTestnetOptions
{ cardanoNodeEra = AnyCardanoEra era -- TODO: We should only support the latest era and the upcoming era
{ cardanoNodeEra = cEra -- TODO: We should only support the latest era and the upcoming era
}

TestnetRuntime
Expand All @@ -68,7 +70,7 @@ hprop_transaction = integrationRetryWorkspace 0 "babbage-transaction" $ \tempAbs
txbodySignedFp <- H.note $ work </> "tx.body.signed"

void $ execCli' execConfig
[ "babbage", "query", "utxo"
[ anyEraToString cEra, "query", "utxo"
, "--address", Text.unpack $ paymentKeyInfoAddr wallet0
, "--cardano-mode"
, "--out-file", work </> "utxo-1.json"
Expand All @@ -79,14 +81,14 @@ hprop_transaction = integrationRetryWorkspace 0 "babbage-transaction" $ \tempAbs
txin1 <- H.noteShow =<< H.headM (Map.keys utxo1)

void $ execCli' execConfig
[ "babbage", "transaction", "build"
[ anyEraToString cEra, "transaction", "build"
, "--change-address", Text.unpack $ paymentKeyInfoAddr wallet0
, "--tx-in", Text.unpack $ renderTxIn txin1
, "--tx-out", Text.unpack (paymentKeyInfoAddr wallet0) <> "+" <> show @Int 5_000_001
, "--out-file", txbodyFp
]
cddlUnwitnessedTx <- H.readJsonFileOk txbodyFp
apiTx <- H.evalEither $ deserialiseTxLedgerCddl sbe cddlUnwitnessedTx
apiTx <- H.evalEither $ deserialiseFromTextEnvelope (AsTx AsBabbageEra) cddlUnwitnessedTx
let txFee = L.unCoin $ extractTxFee apiTx

-- This is the current calculated fee.
Expand All @@ -96,21 +98,21 @@ hprop_transaction = integrationRetryWorkspace 0 "babbage-transaction" $ \tempAbs
330 H.=== txFee

void $ execCli' execConfig
[ "babbage", "transaction", "sign"
[ anyEraToString cEra, "transaction", "sign"
, "--tx-body-file", txbodyFp
, "--signing-key-file", signingKeyFp $ paymentKeyInfoPair wallet0
, "--out-file", txbodySignedFp
]

void $ execCli' execConfig
[ "babbage", "transaction", "submit"
[ anyEraToString cEra, "transaction", "submit"
, "--tx-file", txbodySignedFp
]


H.byDurationM 1 15 "Expected UTxO found" $ do
void $ execCli' execConfig
[ "babbage", "query", "utxo"
[ anyEraToString cEra, "query", "utxo"
, "--address", Text.unpack $ paymentKeyInfoAddr wallet0
, "--cardano-mode"
, "--out-file", work </> "utxo-2.json"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ prop_foldEpochState = integrationWorkspace "foldEpochState" $ \tempAbsBasePath'
=> AnyNewEpochState
-> SlotNo
-> BlockNo
-> StateT [(SlotNo, BlockNo)] IO LedgerStateCondition
-> StateT [(SlotNo, BlockNo)] IO ConditionResult
handler _ slotNo blockNo = do
modify ((slotNo, blockNo):)
s <- get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import Control.Monad
import Control.Monad.Catch (MonadCatch)
import Data.Data (Typeable)
import qualified Data.Map as Map
import Data.Word (Word32)
import Data.Word (Word16)
import GHC.Stack (HasCallStack, withFrozenCallStack)
import System.FilePath ((</>))

Expand Down Expand Up @@ -169,7 +169,7 @@ activityChangeProposalTest
-- the proposal.
-> EpochInterval -- ^ The maximum number of epochs to wait for the DRep activity interval to
-- become expected value.
-> m (String, Word32) -- ^ The transaction id and the index of the governance action.
-> m (String, Word16) -- ^ The transaction id and the index of the governance action.
activityChangeProposalTest execConfig epochStateView ceo work prefix
wallet votes change minWait mExpected maxWait = do
let sbe = conwayEraOnwardsToShelleyBasedEra ceo
Expand Down Expand Up @@ -214,7 +214,7 @@ voteChangeProposal
-> FilePath -- ^ Base directory path where generated files will be stored.
-> String -- ^ Name for the subfolder that will be created under 'work' folder.
-> String -- ^ The transaction id of the governance action to vote.
-> Word32 -- ^ The index of the governance action to vote.
-> Word16 -- ^ The index of the governance action to vote.
-> [([Char], Int)] -- ^ Votes to be casted for the proposal. Each tuple contains the index
-- of the default DRep that will make the vote and the type of the vote
-- (i.e: "yes", "no", "abstain").
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ hprop_ledger_events_info_action = integrationRetryWorkspace 0 "info-hash" $ \tem
[ "conway", "governance", "vote", "create"
, "--yes"
, "--governance-action-tx-id", txidString
, "--governance-action-index", show @Word32 governanceActionIndex
, "--governance-action-index", show @Word16 governanceActionIndex
, "--drep-verification-key-file", verificationKeyFp $ defaultDRepKeyPair n
, "--out-file", voteFp n
]
Expand Down Expand Up @@ -220,7 +220,7 @@ data InfoActionState = InfoActionState

foldBlocksCheckInfoAction
:: FilePath -- ^ Where to store debug logs
-> Word32 -- ^ gov action index
-> Word16 -- ^ gov action index
-> Env
-> LedgerState
-> [LedgerEvent]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Prelude

import Control.Monad.Catch (MonadCatch)
import Data.Typeable (Typeable)
import Data.Word (Word32)
import Data.Word (Word16)
import System.FilePath ((</>))

import Testnet.Components.Query
Expand Down Expand Up @@ -104,7 +104,7 @@ failToVoteChangeProposalWithSPOs
-> FilePath -- ^ Base directory path where generated files will be stored.
-> String -- ^ Name for the subfolder that will be created under 'work' folder.
-> String -- ^ The transaction id of the governance action to vote.
-> Word32 -- ^ The index of the governance action to vote.
-> Word16 -- ^ The index of the governance action to vote.
-> [([Char], Int)] -- ^ Votes to be casted for the proposal. Each tuple contains the index
-- of the default SPO that will make the vote and the type of the vote
-- (i.e: "yes", "no", "abstain").
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import Control.Monad.Catch (MonadCatch)
import Data.Data (Typeable)
import Data.String (fromString)
import qualified Data.Text as Text
import Data.Word (Word32)
import Data.Word (Word16)
import GHC.Stack (HasCallStack)
import Lens.Micro ((^.))
import System.FilePath ((</>))
Expand Down Expand Up @@ -176,15 +176,15 @@ desiredPoolNumberProposalTest
-> 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.
-> Maybe (String, Word32) -- ^ The transaction identifier and index of the previous passed
-> Maybe (String, Word16) -- ^ The transaction identifier and index of the previous passed
-- governance action if any.
-> t (Int, String) -- ^ Model of votes to issue as a list of pairs of amount of each vote
-- together with the vote (i.e: "yes", "no", "abstain")
-> Integer -- ^ What to change the @desiredPoolNumber@ to
-> Integer -- ^ Minimum number of epochs to wait before checking the result
-> Maybe Integer -- ^ What the expected result is of the change (if anything)
-> Integer -- ^ Maximum number of epochs to wait while waiting for the result
-> m (String, Word32)
-> m (String, Word16)
desiredPoolNumberProposalTest execConfig epochStateView ceo work prefix wallet
previousProposalInfo votes change minWait mExpected maxWait = do
let sbe = conwayEraOnwardsToShelleyBasedEra ceo
Expand Down Expand Up @@ -222,11 +222,11 @@ makeDesiredPoolNumberChangeProposal
-> ConwayEraOnwards ConwayEra -- ^ The conway era onwards witness for the era 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.
-> Maybe (String, Word32) -- ^ The transaction identifier and index of the previous passed
-> Maybe (String, Word16) -- ^ The transaction identifier and index of the previous passed
-- governance action if any.
-> Word32 -- ^ What to change the @desiredPoolNumber@ to
-> Word16 -- ^ What to change the @desiredPoolNumber@ to
-> PaymentKeyInfo -- ^ Wallet that will pay for the transaction.
-> m (String, Word32)
-> m (String, Word16)
makeDesiredPoolNumberChangeProposal execConfig epochStateView ceo work prefix
prevGovActionInfo desiredPoolNumber wallet = do

Expand Down Expand Up @@ -309,7 +309,7 @@ voteChangeProposal :: (MonadTest m, MonadIO m, MonadCatch m, H.MonadAssertion m)
-> FilePath -- ^ Base directory path where the subdirectory with the intermediate files will be created.
-> String -- ^ Name for the subdirectory that will be created for storing the intermediate files.
-> String -- ^ Transaction id of the governance action to vote.
-> Word32 -- ^ Index of the governance action to vote in the transaction.
-> Word16 -- ^ Index of the governance action to vote in the transaction.
-> [DefaultDRepVote] -- ^ List of votes to issue as pairs of the vote and the number of DRep that votes it.
-> PaymentKeyInfo -- ^ Wallet that will pay for the transactions
-> m ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ foldBlocksCheckConstitutionWasRatified
:: String -- submitted constitution hash
-> String -- submitted guard rail script hash
-> AnyNewEpochState
-> StateT s IO LedgerStateCondition -- ^ Accumulator at block i and fold status
-> StateT s IO ConditionResult -- ^ Accumulator at block i and fold status
foldBlocksCheckConstitutionWasRatified submittedConstitutionHash submittedGuardRailScriptHash anyNewEpochState =
if filterRatificationState submittedConstitutionHash submittedGuardRailScriptHash anyNewEpochState
then return ConditionMet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ prop_check_if_treasury_is_growing = integrationRetryWorkspace 0 "growing-treasur
H.note_ "treasury is not growing"
H.failure
where
handler :: AnyNewEpochState -> SlotNo -> BlockNo -> StateT (Map EpochNo Integer) IO LedgerStateCondition
handler :: AnyNewEpochState -> SlotNo -> BlockNo -> StateT (Map EpochNo Integer) IO ConditionResult
handler (AnyNewEpochState _ newEpochState) _slotNo _blockNo = do
let (Coin coin) = newEpochState ^. L.nesEsL . L.esAccountStateL . L.asTreasuryL
epochNo = newEpochState ^. L.nesELL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ tests = do
[ T.testGroup "Ledger Events"
[ ignoreOnWindows "Sanity Check" LedgerEvents.hprop_ledger_events_sanity_check
, ignoreOnWindows "Treasury Growth" Gov.prop_check_if_treasury_is_growing
-- TODO: Replace foldBlocks with checkLedgerStateCondition
-- TODO: Replace foldBlocks with checkConditionResult
, T.testGroup "Governance"
[ ignoreOnMacAndWindows "Committee Add New" Gov.hprop_constitutional_committee_add_new
, ignoreOnMacAndWindows "Committee Motion Of No Confidence" Gov.hprop_gov_no_confidence
Expand Down

0 comments on commit 785b023

Please sign in to comment.