Skip to content

Commit

Permalink
Add pparams update test separate. Need to undo changes to propose
Browse files Browse the repository at this point in the history
constitution!
  • Loading branch information
Jimbo4350 committed May 13, 2024
1 parent 0c11a42 commit d1fdfc3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,24 @@ module Cardano.Testnet.Test.Gov.UpdatePParam
import Cardano.Api as Api
import Cardano.Api.Ledger (EpochInterval (..))
import qualified Cardano.Api.Ledger as L
import Cardano.Api.Shelley (createAnchor)

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

import Prelude

import Control.Monad
import Control.Monad.State.Strict (StateT)
import Data.Aeson.Encode.Pretty (encodePretty)
import Data.Bifunctor (first)
import qualified Data.ByteString as BS
import qualified Data.Map.Strict as Map
import Data.Maybe
import Data.Maybe.Strict
import Data.String
import qualified Data.Text as Text
import Data.Word
import GHC.Exts (IsList (..))
import Lens.Micro
import System.FilePath ((</>))

Expand All @@ -52,7 +48,7 @@ import Hedgehog
import qualified Hedgehog.Extras as H

-- | Execute me with:
-- @DISABLE_RETRIES=1 cabal test cardano-testnet-test --test-options '-p "/Propose And Ratify New Constitution/"'@
-- @DISABLE_RETRIES=1 cabal test cardano-testnet-test --test-options '-p "/Update PParams/"'@
hprop_update_pparam :: Property
hprop_update_pparam = H.integrationWorkspace "propose-new-constitution" $ \tempAbsBasePath' -> runWithDefaultWatchdog_ $ do
-- Start a local test net
Expand All @@ -61,10 +57,14 @@ hprop_update_pparam = H.integrationWorkspace "propose-new-constitution" $ \tempA
tempBaseAbsPath = makeTmpBaseAbsPath tempAbsPath

work <- H.createDirectoryIfMissing $ tempAbsPath' </> "work"

-- Generate model for votes
let allVotes :: [(String, Int)]
let ceo = ConwayEraOnwardsConway
sbe = conwayEraOnwardsToShelleyBasedEra ceo
era = toCardanoEra sbe
cEra = AnyCardanoEra era
-- Generate model for votes
allVotes :: [(String, Int)]
allVotes = zip (concatMap (uncurry replicate) [(4, "yes"), (3, "no"), (2, "abstain")]) [1..]

annotateShow allVotes

let numVotes :: Int
Expand All @@ -73,29 +73,38 @@ hprop_update_pparam = H.integrationWorkspace "propose-new-constitution" $ \tempA

guardRailScript <- H.note $ work </> "guard-rail-script.plutusV3"
H.writeFile guardRailScript $ Text.unpack plutusV3NonSpendingScript
execConfigOffline <- H.mkExecConfigOffline tempBaseAbsPath

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

proposalAnchorFile <- H.note $ gov </> "sample-proposal-anchor"
H.writeFile proposalAnchorFile "dummy anchor data"
proposalAnchorDataBS <- evalIO $ BS.readFile proposalAnchorFile
proposalAnchorDataHash <- H.execCli' execConfigOffline
[ "conway", "governance"
, "hash", "anchor-data", "--file-text", proposalAnchorFile
]

-- TODO: Update help text for policyid. The script hash is not
-- only useful for minting scripts
-- TODO: Left off here. Use offline execConfig function
constitutionScriptHash <- filter (/= '\n') <$>
H.execCli' execConfig
H.execCli' execConfigOffline
[ anyEraToString cEra, "transaction"
, "policyid"
, "--script-file", guardRailScript
]

H.note_ $ "Constitution script hash: " <> constitutionScriptHash

let ceo = ConwayEraOnwardsConway
sbe = conwayEraOnwardsToShelleyBasedEra ceo
era = toCardanoEra sbe
cEra = AnyCardanoEra era
fastTestnetOptions = cardanoDefaultTestnetOptions
url <- evalMaybe $ L.textToUrl 28 "https://tinyurl.com/3wrwb2as"
let fastTestnetOptions = cardanoDefaultTestnetOptions
{ cardanoEpochLength = 100
, cardanoNodeEra = cEra
, cardanoNumDReps = numVotes
}
constitution = undefined
anchor = createAnchor url proposalAnchorDataBS
ScriptHash cScriptHash = fromString constitutionScriptHash
constitution = L.Constitution anchor $ L.SJust cScriptHash

alonzoGenesis <- evalEither $ first prettyError defaultAlonzoGenesis
(startTime, shelleyGenesis') <- getDefaultShelleyGenesis fastTestnetOptions
Expand Down Expand Up @@ -123,15 +132,7 @@ hprop_update_pparam = H.integrationWorkspace "propose-new-constitution" $ \tempA
H.note_ $ "Abs path: " <> tempAbsBasePath'
H.note_ $ "Socketpath: " <> unFile socketPath
H.note_ $ "Foldblocks config file: " <> unFile configurationFile
gov <- H.createDirectoryIfMissing $ work </> "governance"

proposalAnchorFile <- H.note $ gov </> "sample-proposal-anchor"
H.writeFile proposalAnchorFile "dummy anchor data"

proposalAnchorDataHash <- H.execCli' execConfig
[ "conway", "governance"
, "hash", "anchor-data", "--file-text", proposalAnchorFile
]

let stakeVkeyFp = gov </> "stake.vkey"
stakeSKeyFp = gov </> "stake.skey"
Expand Down Expand Up @@ -228,6 +229,7 @@ hprop_update_pparam = H.integrationWorkspace "propose-new-constitution" $ \tempA
pparamsVoteTxBodyFp <- createVotingTxBody execConfig epochStateView sbe work "pparams-vote-tx-body"
pparamsVoteFiles wallet0

let signingKeys = SomeKeyPair <$> (paymentKeyInfoPair wallet0:(defaultDRepKeyPair . snd <$> allVotes))

pparamsVoteTxFp <- signTx execConfig cEra work "signed-vote-tx" pparamsVoteTxBodyFp signingKeys
submitTx execConfig cEra pparamsVoteTxFp
Expand All @@ -252,34 +254,3 @@ checkPParamsUpdated committeeTermLength (AnyNewEpochState sbe nes) =
in if curCommTermLength == committeeTermLength
then Just () -- PParams was successfully updated and we terminate the fold.
else Nothing -- PParams was not updated yet, we continue the fold.

checkConstitutionWasRatified
:: String -- submitted constitution hash
-> String -- submitted guard rail script hash
-> AnyNewEpochState
-> StateT s IO LedgerStateCondition -- ^ Accumulator at block i and fold status
checkConstitutionWasRatified submittedConstitutionHash submittedGuardRailScriptHash anyNewEpochState =
if filterRatificationState submittedConstitutionHash submittedGuardRailScriptHash anyNewEpochState
then return ConditionMet
else return ConditionNotMet

filterRatificationState
:: String -- ^ Submitted constitution anchor hash
-> String -- ^ Submitted guard rail script hash
-> AnyNewEpochState
-> Bool
filterRatificationState c guardRailScriptHash (AnyNewEpochState sbe newEpochState) = do
caseShelleyToBabbageOrConwayEraOnwards
(const $ error "filterRatificationState: Only conway era supported")

(const $ do
-- This is the next ratify state! Not the current constitution!!!
let constitution = newEpochState ^. L.newEpochStateGovStateL . L.cgsConstitutionL
constitutionAnchorHash = Ledger.anchorDataHash $ Ledger.constitutionAnchor constitution
L.ScriptHash constitutionScriptHash = fromMaybe (error "filterRatificationState: consitution does not have a guardrail script")
$ strictMaybeToMaybe $ constitution ^. Ledger.constitutionScriptL
Text.pack c == renderSafeHashAsHex constitutionAnchorHash && L.hashToTextAsHex constitutionScriptHash == Text.pack guardRailScriptHash

)
sbe

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import qualified Cardano.Testnet.Test.Gov.ProposeNewConstitution as Gov
import qualified Cardano.Testnet.Test.Gov.ProposeNewConstitutionSPO as Gov
import qualified Cardano.Testnet.Test.Gov.TreasuryGrowth as Gov
import qualified Cardano.Testnet.Test.Gov.TreasuryWithdrawal as Gov
import qualified Cardano.Testnet.Test.Gov.UpdatePParam as Gov
import qualified Cardano.Testnet.Test.Node.Shutdown
import qualified Cardano.Testnet.Test.SanityCheck as LedgerEvents
import qualified Cardano.Testnet.Test.SubmitApi.Babbage.Transaction
Expand Down Expand Up @@ -49,7 +50,8 @@ tests = do
, H.ignoreOnWindows "Treasury Growth" Gov.prop_check_if_treasury_is_growing
-- TODO: Replace foldBlocks with checkLedgerStateCondition
, T.testGroup "Governance"
[ H.ignoreOnMacAndWindows "Committee Add New" Gov.hprop_constitutional_committee_add_new
[ H.ignoreOnMacAndWindows "Update PParams" Gov.hprop_update_pparam
, H.ignoreOnMacAndWindows "Committee Add New" Gov.hprop_constitutional_committee_add_new
, H.ignoreOnMacAndWindows "Committee Motion Of No Confidence" Gov.hprop_gov_no_confidence
-- TODO: "DRep Activity" is too flaky at the moment. Disabling until we can fix it.
-- , H.ignoreOnWindows "DRep Activity" Cardano.Testnet.Test.LedgerEvents.Gov.DRepActivity.hprop_check_drep_activity
Expand Down

0 comments on commit d1fdfc3

Please sign in to comment.