@@ -22,15 +22,20 @@ import Cardano.Api as Api
22
22
import Cardano.Api.Error (displayError )
23
23
import Cardano.Api.Shelley
24
24
25
+ import qualified Cardano.Crypto.Hash as L
25
26
import qualified Cardano.Ledger.Conway.Governance as L
26
27
import qualified Cardano.Ledger.Conway.Governance as Ledger
28
+ import qualified Cardano.Ledger.Hashes as L
29
+ import qualified Cardano.Ledger.Shelley.LedgerState as L
27
30
import Cardano.Testnet
28
31
29
32
import Prelude
30
33
31
34
import Control.Monad
32
35
import Control.Monad.State.Strict (StateT )
33
36
import qualified Data.Map.Strict as Map
37
+ import Data.Maybe
38
+ import Data.Maybe.Strict
34
39
import Data.String
35
40
import qualified Data.Text as Text
36
41
import Data.Word
@@ -39,7 +44,9 @@ import GHC.Stack (HasCallStack, callStack)
39
44
import Lens.Micro
40
45
import System.FilePath ((</>) )
41
46
47
+ import Testnet.Components.Configuration
42
48
import Testnet.Components.Query
49
+ import Testnet.Defaults
43
50
import qualified Testnet.Process.Cli as P
44
51
import qualified Testnet.Process.Run as H
45
52
import qualified Testnet.Property.Utils as H
@@ -175,6 +182,16 @@ hprop_ledger_events_propose_new_constitution = H.integrationWorkspace "propose-n
175
182
176
183
-- Create constitution proposal
177
184
185
+ guardRailScriptFp <- H. note $ work </> " guard-rail-script.plutusV3"
186
+ H. writeFile guardRailScriptFp $ Text. unpack plutusV3NonSpendingScript
187
+ -- TODO: Update help text for policyid. The script hash is not
188
+ -- only useful for minting scripts
189
+ constitutionScriptHash <- filter (/= ' \n ' ) <$>
190
+ H. execCli' execConfig
191
+ [ convertToEraString cEra, " transaction"
192
+ , " policyid"
193
+ , " --script-file" , guardRailScriptFp
194
+ ]
178
195
void $ H. execCli' execConfig
179
196
[ " conway" , " governance" , " action" , " create-constitution"
180
197
, " --testnet"
@@ -184,6 +201,7 @@ hprop_ledger_events_propose_new_constitution = H.integrationWorkspace "propose-n
184
201
, " --anchor-data-hash" , proposalAnchorDataHash
185
202
, " --constitution-url" , " https://tinyurl.com/2pahcy6z"
186
203
, " --constitution-hash" , constitutionHash
204
+ , " --constitution-script-hash" , constitutionScriptHash
187
205
, " --out-file" , constitutionActionFp
188
206
]
189
207
@@ -289,10 +307,16 @@ hprop_ledger_events_propose_new_constitution = H.integrationWorkspace "propose-n
289
307
290
308
-- We check that constitution was succcessfully ratified
291
309
292
- ! eConstitutionAdopted <- runExceptT
293
- $ foldEpochState (File configurationFile) (File socketPath) QuickValidation (EpochNo 10 ) ()
294
- $ checkConstitutionWasRatified constitutionHash
295
- evalEither $ void eConstitutionAdopted
310
+ ! eConstitutionAdopted
311
+ <- runExceptT $ foldEpochState
312
+ (File configurationFile)
313
+ (File socketPath)
314
+ FullValidation
315
+ (EpochNo 10 )
316
+ ()
317
+ (foldBlocksCheckConstitutionWasRatified constitutionHash constitutionScriptHash)
318
+
319
+ void $ evalEither eConstitutionAdopted
296
320
297
321
foldBlocksCheckProposalWasSubmitted
298
322
:: TxId -- TxId of submitted tx
@@ -335,26 +359,34 @@ filterNewGovProposals txid (NewGovernanceProposals eventTxId (AnyProposals props
335
359
filterNewGovProposals _ _ = False
336
360
337
361
338
- checkConstitutionWasRatified
362
+ foldBlocksCheckConstitutionWasRatified
339
363
:: String -- submitted constitution hash
364
+ -> String -- submitted guard rail script hash
340
365
-> AnyNewEpochState
341
- -> StateT () IO LedgerStateCondition -- ^ Accumulator at block i and fold status
342
- checkConstitutionWasRatified submittedConstitutionHash (AnyNewEpochState sbe newEpochState) = do
343
- caseShelleyToBabbageOrConwayEraOnwards
344
- (const $ error " checkConstitutionWasRatified: Only Conway era supported" )
345
- (const $ do
346
- let ratifyState = L. extractDRepPulsingState (newEpochState ^. L. newEpochStateDRepPulsingStateL)
347
- if filterRatificationState submittedConstitutionHash ratifyState
348
- then return ConditionMet
349
- else return ConditionNotMet
350
- )
351
- sbe
366
+ -> StateT s IO LedgerStateCondition -- ^ Accumulator at block i and fold status
367
+ foldBlocksCheckConstitutionWasRatified submittedConstitutionHash submittedGuardRailScriptHash anyNewEpochState =
368
+ if filterRatificationState submittedConstitutionHash submittedGuardRailScriptHash anyNewEpochState
369
+ then return ConditionMet
370
+ else return ConditionNotMet
352
371
353
372
-- cgsDRepPulsingStateL . ratifyStateL
354
373
filterRatificationState
355
374
:: String -- ^ Submitted constitution anchor hash
356
- -> L. RatifyState (ShelleyLedgerEra era )
375
+ -> String -- ^ Submitted guard rail script hash
376
+ -> AnyNewEpochState
357
377
-> Bool
358
- filterRatificationState c rState =
359
- let constitutionAnchorHash = Ledger. anchorDataHash $ Ledger. constitutionAnchor (rState ^. Ledger. rsEnactStateL . Ledger. ensConstitutionL)
360
- in Text. pack c == renderSafeHashAsHex constitutionAnchorHash
378
+ filterRatificationState c guardRailScriptHash (AnyNewEpochState sbe newEpochState) =
379
+ caseShelleyToBabbageOrConwayEraOnwards
380
+ (const $ error " filterRatificationState: Only conway era supported" )
381
+
382
+ (const $ do
383
+ let rState = Ledger. extractDRepPulsingState $ newEpochState ^. L. newEpochStateGovStateL . L. drepPulsingStateGovStateL
384
+ constitution = rState ^. Ledger. rsEnactStateL . Ledger. ensConstitutionL
385
+ constitutionAnchorHash = Ledger. anchorDataHash $ Ledger. constitutionAnchor constitution
386
+ L. ScriptHash constitutionScriptHash = fromMaybe (error " filterRatificationState: consitution does not have a guardrail script" )
387
+ $ strictMaybeToMaybe $ constitution ^. Ledger. constitutionScriptL
388
+ Text. pack c == renderSafeHashAsHex constitutionAnchorHash && L. hashToTextAsHex constitutionScriptHash == Text. pack guardRailScriptHash
389
+
390
+ )
391
+ sbe
392
+
0 commit comments