Skip to content

Commit 4ca29e2

Browse files
committed
cardano-testnet | Refactor: use default key deposit from defaultShelleyGenesis instead of hardcoding it
1 parent 4184f92 commit 4ca29e2

File tree

18 files changed

+68
-44
lines changed

18 files changed

+68
-44
lines changed

cardano-testnet/cardano-testnet.cabal

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,30 +183,31 @@ test-suite cardano-testnet-test
183183

184184
main-is: cardano-testnet-test.hs
185185

186-
other-modules: Cardano.Testnet.Test.Cli.LeadershipSchedule
187-
Cardano.Testnet.Test.Cli.StakeSnapshot
188-
Cardano.Testnet.Test.Cli.Transaction
189-
Cardano.Testnet.Test.Cli.Conway.Plutus
186+
other-modules: Cardano.Testnet.Test.Cli.Conway.Plutus
190187
Cardano.Testnet.Test.Cli.Conway.StakeSnapshot
191188
Cardano.Testnet.Test.Cli.KesPeriodInfo
189+
Cardano.Testnet.Test.Cli.LeadershipSchedule
192190
Cardano.Testnet.Test.Cli.Query
193191
Cardano.Testnet.Test.Cli.QuerySlotNumber
192+
Cardano.Testnet.Test.Cli.StakeSnapshot
193+
Cardano.Testnet.Test.Cli.Transaction
194+
Cardano.Testnet.Test.Cli.Transaction.RegisterDeregisterStakeAddress
194195
Cardano.Testnet.Test.FoldEpochState
195196
Cardano.Testnet.Test.Gov.CommitteeAddNew
196197
Cardano.Testnet.Test.Gov.DRepActivity
197198
Cardano.Testnet.Test.Gov.DRepDeposit
198199
Cardano.Testnet.Test.Gov.DRepRetirement
200+
Cardano.Testnet.Test.Gov.GovActionTimeout
199201
Cardano.Testnet.Test.Gov.InfoAction
200202
Cardano.Testnet.Test.Gov.NoConfidence
201203
Cardano.Testnet.Test.Gov.PParamChangeFailsSPO
204+
Cardano.Testnet.Test.Gov.PredefinedAbstainDRep
202205
Cardano.Testnet.Test.Gov.ProposeNewConstitution
203206
Cardano.Testnet.Test.Gov.ProposeNewConstitutionSPO
204-
Cardano.Testnet.Test.Gov.GovActionTimeout
205207
Cardano.Testnet.Test.Gov.TreasuryDonation
206208
Cardano.Testnet.Test.Gov.TreasuryGrowth
207209
Cardano.Testnet.Test.Gov.TreasuryWithdrawal
208210
Cardano.Testnet.Test.Misc
209-
Cardano.Testnet.Test.Gov.PredefinedAbstainDRep
210211
Cardano.Testnet.Test.Node.Shutdown
211212
Cardano.Testnet.Test.SanityCheck
212213
Cardano.Testnet.Test.SubmitApi.Transaction

cardano-testnet/src/Testnet/Components/Query.hs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ module Testnet.Components.Query
3737
, checkDRepState
3838
, assertNewEpochState
3939
, getGovActionLifetime
40+
, getKeyDeposit
4041
) where
4142

4243
import Cardano.Api as Api
@@ -571,11 +572,22 @@ assertNewEpochState epochStateView sbe maxWait lens expected = withFrozenCallSta
571572
-- The @govActionLifetime@ or governance action maximum lifetime in epochs is
572573
-- the number of epochs such that a governance action submitted during an epoch @e@
573574
-- expires if it is still not ratified as of the end of epoch: @e + govActionLifetime + 1@.
574-
getGovActionLifetime :: (ConwayEraPParams (ShelleyLedgerEra era), H.MonadAssertion m, MonadTest m, MonadIO m)
575+
getGovActionLifetime :: (H.MonadAssertion m, MonadTest m, MonadIO m)
575576
=> EpochStateView
576577
-> ConwayEraOnwards era
577578
-> m EpochInterval
578-
getGovActionLifetime epochStateView ceo = do
579+
getGovActionLifetime epochStateView ceo = conwayEraOnwardsConstraints ceo $ do
579580
govState :: ConwayGovState era <- getGovState epochStateView ceo
580581
return $ govState ^. L.cgsCurPParamsL
581582
. L.ppGovActionLifetimeL
583+
584+
-- | Obtains the key registration deposit from the protocol parameters.
585+
getKeyDeposit :: (H.MonadAssertion m, MonadTest m, MonadIO m)
586+
=> EpochStateView
587+
-> ConwayEraOnwards era
588+
-> m L.Coin
589+
getKeyDeposit epochStateView ceo = conwayEraOnwardsConstraints ceo $ do
590+
govState :: ConwayGovState era <- getGovState epochStateView ceo
591+
return $ govState ^. L.cgsCurPParamsL
592+
. L.ppKeyDepositL
593+

cardano-testnet/src/Testnet/Defaults.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,7 @@ defaultShelleyGenesis asbe startTime maxSupply options = do
388388
-- TODO: find out why this actually degrates network stability - turned off for now
389389
-- securityParam = ceiling $ fromIntegral epochLength * cardanoActiveSlotsCoeff / 10
390390
pVer = eraToProtocolVersion asbe
391-
-- TODO: Remove after merging https://github.com/IntersectMBO/cardano-node/pull/6017
392-
protocolParams = Api.sgProtocolParams Api.shelleyGenesisDefaults & L.ppKeyDepositL .~ 0
391+
protocolParams = Api.sgProtocolParams Api.shelleyGenesisDefaults
393392
protocolParamsWithPVer = protocolParams & ppProtocolVersionL' .~ pVer
394393
Api.shelleyGenesisDefaults
395394
{ Api.sgActiveSlotsCoeff = unsafeBoundedRational activeSlotsCoeff

cardano-testnet/src/Testnet/Process/Cli/SPO.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,10 +341,9 @@ registerSingleSpo asbe identifier tap@(TmpAbsolutePath tempAbsPath') nodeConfigF
341341
-- NB: Pledger and owner can be the same
342342

343343
-- Create pledger registration certificate
344-
345344
createStakeKeyRegistrationCertificate tap asbe
346345
poolOwnerstakeVkeyFp
347-
0
346+
400_000
348347
(workDir </> "pledger.regcert")
349348

350349
void $ execCli' execConfig

cardano-testnet/src/Testnet/Types.hs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ module Testnet.Types
2929
, SomeKeyPair(..)
3030
, VKey
3131
, SKey
32-
, ColdPoolKey
3332
, VrfKey
3433
, StakingKey
3534
, PaymentKey
@@ -143,7 +142,6 @@ isTestnetNodeSpo = isJust . poolKeys
143142
nodeSocketPath :: TestnetNode -> SocketPath
144143
nodeSocketPath = File . H.sprocketSystemName . nodeSprocket
145144

146-
data ColdPoolKey
147145
data StakingKey
148146
data SpoColdKey
149147

cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Conway/Plutus.hs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module Cardano.Testnet.Test.Cli.Conway.Plutus
1111
) where
1212

1313
import Cardano.Api
14+
import qualified Cardano.Api.Ledger as L
1415

1516
import Cardano.Testnet
1617

@@ -53,7 +54,8 @@ hprop_plutus_v3 = integrationWorkspace "all-plutus-script-purposes" $ \tempAbsBa
5354

5455
let
5556
tempBaseAbsPath = makeTmpBaseAbsPath $ TmpAbsolutePath tempAbsPath'
56-
sbe = ShelleyBasedEraConway -- TODO: We should only support the latest era and the upcoming era
57+
ceo = ConwayEraOnwardsConway
58+
sbe = conwayEraOnwardsToShelleyBasedEra ceo
5759
era = toCardanoEra sbe
5860
anyEra = AnyCardanoEra era
5961
options = def { cardanoNodeEra = AnyShelleyBasedEra sbe }
@@ -106,12 +108,13 @@ hprop_plutus_v3 = integrationWorkspace "all-plutus-script-purposes" $ \tempAbsBa
106108
scriptStakeRegistrationCertificate
107109
<- H.note $ work </> "script-stake-registration-certificate"
108110

111+
keyDeposit <- fromIntegral . L.unCoin <$> getKeyDeposit epochStateView ceo
109112
-- Create script stake registration certificate
110113
createScriptStakeRegistrationCertificate
111114
tempAbsPath
112115
anyEra
113116
plutusScript
114-
0
117+
keyDeposit
115118
scriptStakeRegistrationCertificate
116119

117120
-- 1. Put UTxO and datum at Plutus spending script address

cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/KesPeriodInfo.hs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module Cardano.Testnet.Test.Cli.KesPeriodInfo
1212
) where
1313

1414
import Cardano.Api as Api
15+
import Cardano.Api.Ledger (Coin (..))
1516

1617
import Cardano.CLI.Types.Output
1718
import Cardano.Node.Configuration.Topology
@@ -32,6 +33,7 @@ import System.FilePath ((</>))
3233
import qualified System.Info as SYS
3334

3435
import Testnet.Components.Configuration
36+
import Testnet.Components.Query
3537
import Testnet.Process.Cli.Keys
3638
import Testnet.Process.Cli.SPO
3739
import Testnet.Process.Run (execCli, execCli', mkExecConfig)
@@ -60,7 +62,8 @@ hprop_kes_period_info = integrationRetryWorkspace 2 "kes-period-info" $ \tempAbs
6062
<- mkConf tempAbsBasePath'
6163

6264
let tempBaseAbsPath = makeTmpBaseAbsPath tempAbsPath
63-
sbe = ShelleyBasedEraConway
65+
ceo = ConwayEraOnwardsConway
66+
sbe = conwayEraOnwardsToShelleyBasedEra ceo
6467
asbe = AnyShelleyBasedEra sbe
6568
eraString = eraToString sbe
6669
cTestnetOptions = def { cardanoNodeEra = asbe }
@@ -90,6 +93,7 @@ hprop_kes_period_info = integrationRetryWorkspace 2 "kes-period-info" $ \tempAbs
9093

9194
let node1SocketPath = Api.File $ IO.sprocketSystemName node1sprocket
9295
termEpoch = EpochNo 3
96+
epochStateView <- getEpochStateView configurationFile node1SocketPath
9397
(stakePoolId, stakePoolColdSigningKey, stakePoolColdVKey, _, _)
9498
<- registerSingleSpo asbe 1 tempAbsPath
9599
configurationFile
@@ -135,12 +139,13 @@ hprop_kes_period_info = integrationRetryWorkspace 2 "kes-period-info" $ \tempAbs
135139
, "--testnet-magic", show @Int testnetMagic
136140
]
137141

142+
keyDeposit <- fromIntegral . unCoin <$> getKeyDeposit epochStateView ceo
138143
-- Test stake address registration cert
139144
createStakeKeyRegistrationCertificate
140145
tempAbsPath
141146
(cardanoNodeEra cTestnetOptions)
142147
testDelegatorVkeyFp
143-
0
148+
keyDeposit
144149
testDelegatorRegCertFp
145150

146151
-- Test stake address deleg cert

cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/LeadershipSchedule.hs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module Cardano.Testnet.Test.Cli.LeadershipSchedule
1515

1616
import Cardano.Api
1717
import qualified Cardano.Api as Api
18+
import Cardano.Api.Ledger (Coin (..))
1819

1920
import Cardano.Node.Configuration.Topology
2021
import Cardano.Testnet
@@ -37,6 +38,7 @@ import System.FilePath ((</>))
3738
import qualified System.Info as SYS
3839

3940
import Testnet.Components.Configuration
41+
import Testnet.Components.Query
4042
import Testnet.Process.Cli.Keys
4143
import Testnet.Process.Cli.SPO
4244
import Testnet.Process.Run (execCli, execCli', mkExecConfig)
@@ -60,7 +62,8 @@ hprop_leadershipSchedule = integrationRetryWorkspace 2 "leadership-schedule" $ \
6062
H.note_ SYS.os
6163
conf@Conf { tempAbsPath=tempAbsPath@(TmpAbsolutePath work) } <- mkConf tempAbsBasePath'
6264
let tempBaseAbsPath = makeTmpBaseAbsPath tempAbsPath
63-
sbe = shelleyBasedEra @ConwayEra -- TODO: We should only support the latest era and the upcoming era
65+
ceo = ConwayEraOnwardsConway
66+
sbe = conwayEraOnwardsToShelleyBasedEra ceo
6467
asbe = AnyShelleyBasedEra sbe
6568
cTestnetOptions = def
6669
{ cardanoNodeEra = asbe
@@ -97,6 +100,7 @@ hprop_leadershipSchedule = integrationRetryWorkspace 2 "leadership-schedule" $ \
97100
txin1 <- H.noteShow =<< H.headM (Map.keys utxo1)
98101
let node1SocketPath = Api.File $ IO.sprocketSystemName node1sprocket
99102
termEpoch = EpochNo 15
103+
epochStateView <- getEpochStateView configurationFile node1SocketPath
100104
(stakePoolIdNewSpo, stakePoolColdSigningKey, stakePoolColdVKey, vrfSkey, _)
101105
<- registerSingleSpo asbe 1 tempAbsPath
102106
configurationFile
@@ -140,12 +144,13 @@ hprop_leadershipSchedule = integrationRetryWorkspace 2 "leadership-schedule" $ \
140144
, "--testnet-magic", show @Int testnetMagic
141145
]
142146

147+
keyDeposit <- fromIntegral . unCoin <$> getKeyDeposit epochStateView ceo
143148
-- Test stake address registration cert
144149
createStakeKeyRegistrationCertificate
145150
tempAbsPath
146151
(cardanoNodeEra cTestnetOptions)
147152
testDelegatorVkeyFp
148-
0
153+
keyDeposit
149154
testDelegatorRegCertFp
150155

151156
-- Test stake address deleg cert

cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/CommitteeAddNew.hs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,12 @@ hprop_constitutional_committee_add_new = integrationWorkspace "constitutional-co
127127
, signingKey = File stakeSKeyFp
128128
}
129129

130+
keyDepositStr <- show . L.unCoin <$> getKeyDeposit epochStateView ceo
130131
-- Register stake address
131-
132132
void $ execCli' execConfig
133133
[ eraName, "stake-address", "registration-certificate"
134134
, "--stake-verification-key-file", stakeVkeyFp
135-
, "--key-reg-deposit-amt", show @Int 0 -- TODO: why this needs to be 0????
135+
, "--key-reg-deposit-amt", keyDepositStr
136136
, "--out-file", stakeCertFp
137137
]
138138

@@ -164,7 +164,6 @@ hprop_constitutional_committee_add_new = integrationWorkspace "constitutional-co
164164
, "--tx-file", stakeCertTxSignedFp
165165
]
166166

167-
168167
minGovActDeposit <- getMinGovActionDeposit epochStateView ceo
169168

170169
ccColdKeys <- H.noteShowM $

cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/GovActionTimeout.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module Cardano.Testnet.Test.Gov.GovActionTimeout
1111
) where
1212

1313
import Cardano.Api as Api
14-
import Cardano.Api.Ledger (EpochInterval (EpochInterval, unEpochInterval))
14+
import Cardano.Api.Ledger (Coin (..), EpochInterval (EpochInterval, unEpochInterval))
1515

1616
import Cardano.Testnet
1717

@@ -94,12 +94,12 @@ hprop_check_gov_action_timeout = integrationWorkspace "gov-action-timeout" $ \te
9494

9595
cliStakeAddressKeyGen stakeKeys
9696

97+
keyDepositStr <- show . unCoin <$> getKeyDeposit epochStateView ceo
9798
-- Register stake address
98-
9999
void $ execCli' execConfig
100100
[ eraName, "stake-address", "registration-certificate"
101101
, "--stake-verification-key-file", stakeVkeyFp
102-
, "--key-reg-deposit-amt", show @Int 0 -- TODO: why this needs to be 0????
102+
, "--key-reg-deposit-amt", keyDepositStr
103103
, "--out-file", stakeCertFp
104104
]
105105

0 commit comments

Comments
 (0)