Skip to content

Commit 9ac29e1

Browse files
committed
refactor: use immutable sets for config constants
Switch various configuration and parameter sets from mutable set or dict types to immutable alternatives (`frozenset` and `MappingProxyType`). This improves code safety by preventing accidental modification of these constants and clarifies their intended usage as fixed reference data.
1 parent 2bbd429 commit 9ac29e1

File tree

5 files changed

+148
-129
lines changed

5 files changed

+148
-129
lines changed

cardano_node_tests/tests/test_ledger_state.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@
1616
LOGGER = logging.getLogger(__name__)
1717

1818

19-
LEDGER_STATE_KEYS = {
20-
"blocksBefore",
21-
"blocksCurrent",
22-
"lastEpoch",
23-
"possibleRewardUpdate",
24-
"stakeDistrib",
25-
"stateBefore",
26-
}
19+
LEDGER_STATE_KEYS = frozenset(
20+
{
21+
"blocksBefore",
22+
"blocksCurrent",
23+
"lastEpoch",
24+
"possibleRewardUpdate",
25+
"stakeDistrib",
26+
"stateBefore",
27+
}
28+
)
2729

2830

2931
class TestLedgerState:

cardano_node_tests/tests/tests_conway/test_pparam_update.py

Lines changed: 85 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -32,79 +32,93 @@
3232
)
3333

3434

35-
NETWORK_GROUP_PPARAMS = {
36-
"maxBlockBodySize",
37-
"maxTxSize",
38-
"maxBlockHeaderSize",
39-
"maxValueSize",
40-
"maxTxExecutionUnits",
41-
"maxBlockExecutionUnits",
42-
"maxCollateralInputs",
43-
}
44-
45-
ECONOMIC_GROUP_PPARAMS = {
46-
"txFeePerByte",
47-
"txFeeFixed",
48-
"stakeAddressDeposit",
49-
"stakePoolDeposit",
50-
"monetaryExpansion",
51-
"treasuryCut",
52-
"minPoolCost",
53-
"utxoCostPerByte",
54-
"executionUnitPrices",
55-
}
56-
57-
TECHNICAL_GROUP_PPARAMS = {
58-
"poolPledgeInfluence",
59-
"poolRetireMaxEpoch",
60-
"stakePoolTargetNum",
61-
"costModels",
62-
"collateralPercentage",
63-
}
64-
65-
GOVERNANCE_GROUP_PPARAMS = {
66-
"govActionLifetime",
67-
"govActionDeposit",
68-
"dRepDeposit",
69-
"dRepActivity",
70-
"committeeMinSize",
71-
"committeeMaxTermLength",
72-
}
73-
74-
GOVERNANCE_GROUP_PPARAMS_DREP_THRESHOLDS = {
75-
"committeeNoConfidence",
76-
"committeeNormal",
77-
"hardForkInitiation",
78-
"motionNoConfidence",
79-
"ppEconomicGroup",
80-
"ppGovGroup",
81-
"ppNetworkGroup",
82-
"ppTechnicalGroup",
83-
"treasuryWithdrawal",
84-
"updateToConstitution",
85-
}
86-
87-
GOVERNANCE_GROUP_PPARAMS_POOL_THRESHOLDS = {
88-
"committeeNoConfidence",
89-
"committeeNormal",
90-
"hardForkInitiation",
91-
"motionNoConfidence",
92-
"ppSecurityGroup",
93-
}
35+
NETWORK_GROUP_PPARAMS = frozenset(
36+
{
37+
"maxBlockBodySize",
38+
"maxTxSize",
39+
"maxBlockHeaderSize",
40+
"maxValueSize",
41+
"maxTxExecutionUnits",
42+
"maxBlockExecutionUnits",
43+
"maxCollateralInputs",
44+
}
45+
)
46+
47+
ECONOMIC_GROUP_PPARAMS = frozenset(
48+
{
49+
"txFeePerByte",
50+
"txFeeFixed",
51+
"stakeAddressDeposit",
52+
"stakePoolDeposit",
53+
"monetaryExpansion",
54+
"treasuryCut",
55+
"minPoolCost",
56+
"utxoCostPerByte",
57+
"executionUnitPrices",
58+
}
59+
)
60+
61+
TECHNICAL_GROUP_PPARAMS = frozenset(
62+
{
63+
"poolPledgeInfluence",
64+
"poolRetireMaxEpoch",
65+
"stakePoolTargetNum",
66+
"costModels",
67+
"collateralPercentage",
68+
}
69+
)
70+
71+
GOVERNANCE_GROUP_PPARAMS = frozenset(
72+
{
73+
"govActionLifetime",
74+
"govActionDeposit",
75+
"dRepDeposit",
76+
"dRepActivity",
77+
"committeeMinSize",
78+
"committeeMaxTermLength",
79+
}
80+
)
81+
82+
GOVERNANCE_GROUP_PPARAMS_DREP_THRESHOLDS = frozenset(
83+
{
84+
"committeeNoConfidence",
85+
"committeeNormal",
86+
"hardForkInitiation",
87+
"motionNoConfidence",
88+
"ppEconomicGroup",
89+
"ppGovGroup",
90+
"ppNetworkGroup",
91+
"ppTechnicalGroup",
92+
"treasuryWithdrawal",
93+
"updateToConstitution",
94+
}
95+
)
96+
97+
GOVERNANCE_GROUP_PPARAMS_POOL_THRESHOLDS = frozenset(
98+
{
99+
"committeeNoConfidence",
100+
"committeeNormal",
101+
"hardForkInitiation",
102+
"motionNoConfidence",
103+
"ppSecurityGroup",
104+
}
105+
)
94106

95107
# Security related pparams that require also SPO approval
96-
SECURITY_PPARAMS = {
97-
"maxBlockBodySize",
98-
"maxTxSize",
99-
"maxBlockHeaderSize",
100-
"maxValueSize",
101-
"maxBlockExecutionUnits",
102-
"txFeePerByte",
103-
"txFeeFixed",
104-
"utxoCostPerByte",
105-
"govActionDeposit",
106-
"minFeeRefScriptsCoinsPerByte", # not in 8.8 release yet
107-
}
108+
SECURITY_PPARAMS = frozenset(
109+
{
110+
"maxBlockBodySize",
111+
"maxTxSize",
112+
"maxBlockHeaderSize",
113+
"maxValueSize",
114+
"maxBlockExecutionUnits",
115+
"txFeePerByte",
116+
"txFeeFixed",
117+
"utxoCostPerByte",
118+
"govActionDeposit",
119+
"minFeeRefScriptsCoinsPerByte", # not in 8.8 release yet
120+
}
121+
)
108122

109123

110124
def _get_rational_str(value: float) -> str:

cardano_node_tests/utils/tx_view.py

Lines changed: 51 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import logging
66
import pathlib as pl
77
import re
8+
import types
89
import typing as tp
910

1011
import yaml
@@ -15,54 +16,56 @@
1516

1617
LOGGER = logging.getLogger(__name__)
1718

18-
CERTIFICATES_INFORMATION = {
19-
"genesis key delegation": {"VRF key hash", "delegate key hash", "genesis key hash"},
20-
"MIR": {
21-
"pot",
22-
"target stake addresses",
23-
"send to treasury",
24-
"send to reserves",
25-
"MIR amount", # node 8.3.0+
26-
},
27-
"stake address deregistration": {
28-
"stake credential key hash",
29-
"stake credential script hash",
30-
"key hash", # node 8.3.0+
31-
"script hash", # node 8.3.0+
32-
"keyHash", # node 8.4.0+
33-
"scriptHash", # node 8.4.0+
34-
},
35-
"stake address registration": {
36-
"stake credential key hash",
37-
"stake credential script hash",
38-
"key hash", # node 8.3.0+
39-
"script hash", # node 8.3.0+
40-
"keyHash", # node 8.4.0+
41-
"scriptHash", # node 8.4.0+
42-
},
43-
"stake address delegation": {
44-
"pool",
45-
"stake credential key hash",
46-
"stake credential script hash",
47-
"credential", # node 8.3.0+
48-
},
49-
"stake pool retirement": {"epoch", "pool"},
50-
"stake pool registration": {
51-
"VRF key hash",
52-
"vrf", # node 8.3.0+
53-
"cost",
54-
"margin",
55-
"metadata",
56-
"owners (stake key hashes)",
57-
"owners", # node 8.3.0+
58-
"pledge",
59-
"pool",
60-
"relays",
61-
"reward account",
62-
"rewardAccount", # node 8.3.0+
63-
"publicKey", # node 8.3.0+
64-
},
65-
}
19+
CERTIFICATES_INFORMATION = types.MappingProxyType(
20+
{
21+
"genesis key delegation": {"VRF key hash", "delegate key hash", "genesis key hash"},
22+
"MIR": {
23+
"pot",
24+
"target stake addresses",
25+
"send to treasury",
26+
"send to reserves",
27+
"MIR amount", # node 8.3.0+
28+
},
29+
"stake address deregistration": {
30+
"stake credential key hash",
31+
"stake credential script hash",
32+
"key hash", # node 8.3.0+
33+
"script hash", # node 8.3.0+
34+
"keyHash", # node 8.4.0+
35+
"scriptHash", # node 8.4.0+
36+
},
37+
"stake address registration": {
38+
"stake credential key hash",
39+
"stake credential script hash",
40+
"key hash", # node 8.3.0+
41+
"script hash", # node 8.3.0+
42+
"keyHash", # node 8.4.0+
43+
"scriptHash", # node 8.4.0+
44+
},
45+
"stake address delegation": {
46+
"pool",
47+
"stake credential key hash",
48+
"stake credential script hash",
49+
"credential", # node 8.3.0+
50+
},
51+
"stake pool retirement": {"epoch", "pool"},
52+
"stake pool registration": {
53+
"VRF key hash",
54+
"vrf", # node 8.3.0+
55+
"cost",
56+
"margin",
57+
"metadata",
58+
"owners (stake key hashes)",
59+
"owners", # node 8.3.0+
60+
"pledge",
61+
"pool",
62+
"relays",
63+
"reward account",
64+
"rewardAccount", # node 8.3.0+
65+
"publicKey", # node 8.3.0+
66+
},
67+
}
68+
)
6669

6770

6871
def load_raw(*, tx_view: str) -> dict:

framework_tests/test_resources_management.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from cardano_node_tests.cluster_management import resources_management
22

3-
ALL_POOLS = {"pool1", "pool2", "pool3", "pool4", "pool5"}
3+
ALL_POOLS = frozenset({"pool1", "pool2", "pool3", "pool4", "pool5"})
44

55

66
def test_get_lockable():

framework_tests/test_resources_naming.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from cardano_node_tests.cluster_management import resources
22
from cardano_node_tests.cluster_management import resources_management
33

4-
ALL_POOLS = {"pool1", "pool2", "pool3", "pool4", "pool5"}
4+
ALL_POOLS = frozenset({"pool1", "pool2", "pool3", "pool4", "pool5"})
55

66

77
def test_sanitize_res_name():

0 commit comments

Comments
 (0)