Skip to content

Commit

Permalink
Add governance treasury withdrawal test case
Browse files Browse the repository at this point in the history
🎉
  • Loading branch information
carbolymer committed Jan 11, 2024
1 parent b480540 commit 5f8a93e
Show file tree
Hide file tree
Showing 5 changed files with 640 additions and 13 deletions.
7 changes: 7 additions & 0 deletions cardano-testnet/cardano-testnet.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ test-suite cardano-testnet-test
Cardano.Testnet.Test.Misc

Cardano.Testnet.Test.LedgerEvents.Gov.ProposeNewConstitution
Cardano.Testnet.Test.LedgerEvents.Gov.TreasuryWithdrawal
Cardano.Testnet.Test.LedgerEvents.SanityCheck

Cardano.Testnet.Test.Node.Shutdown
Expand All @@ -200,15 +201,21 @@ test-suite cardano-testnet-test
, hedgehog
, hedgehog-extras
, http-conduit
, lifted-base
, lens-aeson
, microlens
, monad-control
, process
, regex-compat
, tasty
, text
, time
, transformers
, transformers-except
, unliftio
, resourcet
, transformers-base
, lifted-async

ghc-options: -threaded -rtsopts -with-rtsopts=-N -with-rtsopts=-T

Expand Down
23 changes: 19 additions & 4 deletions cardano-testnet/src/Testnet/Components/Configuration.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE GADTs #-}
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeApplications #-}

Expand Down Expand Up @@ -111,19 +112,25 @@ createSPOGenesisAndFiles testnetOptions startTime (TmpAbsolutePath tempAbsPath')
$ HM.adjust
(J.rewriteObject (HM.insert "major" (toJSON @Int 8)))
"protocolVersion"
. HM.insert "rho" (toJSON @Double 0.1)
. HM.insert "tau" (toJSON @Double 0.1)
) "protocolParams"
. HM.insert "rho" (toJSON @Double 0.1)
. HM.insert "tau" (toJSON @Double 0.1)
. HM.insert "updateQuorum" (toJSON @Int 2)
. HM.insert "maxLovelaceSupply" (toJSON @Int 1_000_000_000_000_000)
)

execCli_
[ "genesis", "create-staked"
, "--genesis-dir", tempAbsPath'
, "--testnet-magic", show @Int testnetMagic
, "--gen-pools", show @Int numPoolNodes
, "--supply", "1000000000000"
, "--supply-delegated", "1000000000000"
, "--supply", show @Integer 1_000_000_000_000
, "--supply-delegated", show @Integer 140_000_000_002
-- 1_140_000_000_002
-- -7_999_800_000_000_001
-- 2_000_000_000_000 -- supply
-- 240_000_000_002 -- supply delegated
-- 10_000_000_000_000 -- mas lovelace supply
, "--gen-stake-delegs", "3"
, "--gen-utxo-keys", show numSeededUTxOKeys
, "--start-time", DTC.formatIso8601 startTime
Expand All @@ -146,6 +153,14 @@ createSPOGenesisAndFiles testnetOptions startTime (TmpAbsolutePath tempAbsPath')
H.renameFile (tempAbsPath' </> "genesis.conway.json") (genesisShelleyDir </> "genesis.conway.json")
H.renameFile (tempAbsPath' </> "genesis.json") (genesisShelleyDir </> "genesis.json")

H.rewriteJsonFile (genesisShelleyDir </> "genesis.json") . J.rewriteObject $
HM.insert "maxLovelaceSupply" (toJSON @Int 10_000_000_000_000_000)
. HM.insert "activeSlotsCoeff" (toJSON @Double 0.3)

H.rewriteJsonFile (genesisShelleyDir </> "genesis.conway.json") . J.rewriteObject $
HM.insert "dRepActivity" (Number 200)
. HM.insert "govActionLifetime" (Number 2)

return genesisShelleyDir

ifaceAddress :: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ hprop_ledger_events_propose_new_constitution = H.integrationRetryWorkspace 2 "pr

-- Create Conway constitution
gov <- H.createDirectoryIfMissing $ work </> "governance"
proposalAnchorFile <- H.note $ work </> gov </> "sample-proposFal-anchor"
proposalAnchorFile <- H.note $ work </> gov </> "sample-proposal-anchor"
consitutionFile <- H.note $ work </> gov </> "sample-constitution"
constitutionActionFp <- H.note $ work </> gov </> "constitution.action"

Expand Down Expand Up @@ -139,7 +139,6 @@ hprop_ledger_events_propose_new_constitution = H.integrationRetryWorkspace 2 "pr
]

-- Retrieve UTxOs for registration submission

void $ H.execCli' execConfig
[ "conway", "query", "utxo"
, "--address", Text.unpack $ paymentKeyInfoAddr $ head wallets
Expand All @@ -149,12 +148,13 @@ hprop_ledger_events_propose_new_constitution = H.integrationRetryWorkspace 2 "pr
]

utxo1Json <- H.leftFailM . H.readJsonFile $ work </> "utxo-1.json"
UTxO utxo1 <- H.noteShowM $ H.noteShowM $ decodeEraUTxO sbe utxo1Json
txin1 <- H.noteShow =<< H.headM (Map.keys utxo1)
UTxO utxo1 <- H.noteShowM $ decodeEraUTxO sbe utxo1Json
txin1 <- H.noteShowM $ H.headM (Map.keys utxo1)

drepRegTxbodyFp <- H.note $ work </> "drep.registration.txbody"
drepRegTxSignedFp <- H.note $ work </> "drep.registration.tx"

-- TX: UTXO1 -> UTXO2
void $ H.execCli' execConfig
[ "conway", "transaction", "build"
, "--testnet-magic", show @Int testnetMagic
Expand Down Expand Up @@ -186,7 +186,6 @@ hprop_ledger_events_propose_new_constitution = H.integrationRetryWorkspace 2 "pr
]

-- Create constitution proposal

void $ H.execCli' execConfig
[ "conway", "governance", "action", "create-constitution"
, "--testnet"
Expand All @@ -211,9 +210,10 @@ hprop_ledger_events_propose_new_constitution = H.integrationRetryWorkspace 2 "pr
]

utxo2Json <- H.leftFailM . H.readJsonFile $ work </> "utxo-2.json"
UTxO utxo2 <- H.noteShowM $ H.noteShowM $ decodeEraUTxO sbe utxo2Json
UTxO utxo2 <- H.noteShowM $ decodeEraUTxO sbe utxo2Json
txin2 <- H.noteShow =<< H.headM (Map.keys utxo2)

-- TX: UTXO2 -> UTXO1
void $ H.execCli' execConfig
[ "conway", "transaction", "build"
, "--testnet-magic", show @Int testnetMagic
Expand Down Expand Up @@ -277,7 +277,6 @@ hprop_ledger_events_propose_new_constitution = H.integrationRetryWorkspace 2 "pr
]

-- We need more UTxOs

void $ H.execCli' execConfig
[ "conway", "query", "utxo"
, "--address", Text.unpack $ paymentKeyInfoAddr $ head wallets
Expand All @@ -287,13 +286,14 @@ hprop_ledger_events_propose_new_constitution = H.integrationRetryWorkspace 2 "pr
]

utxo3Json <- H.leftFailM . H.readJsonFile $ work </> "utxo-3.json"
UTxO utxo3 <- H.noteShowM $ H.noteShowM $ decodeEraUTxO sbe utxo3Json
UTxO utxo3 <- H.noteShowM $ decodeEraUTxO sbe utxo3Json
txin3 <- H.noteShow =<< H.headM (Map.keys utxo3)

voteTxFp <- H.note $ work </> gov </> "vote.tx"
voteTxBodyFp <- H.note $ work </> gov </> "vote.txbody"

-- Submit votes
-- TX: UTXO3 -> UTXO2
void $ H.execCli' execConfig
[ "conway", "transaction", "build"
, "--testnet-magic", show @Int testnetMagic
Expand Down Expand Up @@ -412,5 +412,6 @@ filterRatificationState _ _ = False
-- TODO: Move to cardano-api and share with
-- https://github.com/input-output-hk/cardano-cli/blob/694782210c6d73a1b5151400214ef691f6f3ecb0/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Hash.hs#L67
-- when doing so
-- remove after merging https://github.com/IntersectMBO/cardano-api/commit/d589604b51d5d31ecfb5cc311cd55e5ce0f93ae1
renderSafeHashAsHex :: Ledger.SafeHash c tag -> Text.Text
renderSafeHashAsHex = hashToTextAsHex . Ledger.extractHash
Loading

0 comments on commit 5f8a93e

Please sign in to comment.