Skip to content

Commit 927748a

Browse files
committed
refactor(conway): use shared update_cost_model helper
Refactored the PlutusV2 cost model update test to use the shared `conway_common.update_cost_model` helper instead of a local function. This reduces code duplication and improves maintainability. Also updated the test to use more descriptive temp_template names for clarity.
1 parent ae30840 commit 927748a

File tree

1 file changed

+10
-68
lines changed

1 file changed

+10
-68
lines changed

cardano_node_tests/tests/tests_conway/test_update_plutusv2_builtins.py

Lines changed: 10 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from cardano_node_tests.tests import common
1212
from cardano_node_tests.tests.tests_conway import conway_common
1313
from cardano_node_tests.tests.tests_plutus_v2 import mint_raw
14-
from cardano_node_tests.utils import clusterlib_utils
1514
from cardano_node_tests.utils import configuration
1615
from cardano_node_tests.utils import governance_utils
1716
from cardano_node_tests.utils import helpers
@@ -95,85 +94,28 @@ def test_update_in_pv9(
9594
if len(init_cost_model) >= 185:
9695
pytest.skip("PlutusV2 cost model was already updated.")
9796

98-
cost_proposal_file = DATA_DIR / "cost_models_list_185_v2_v3.json"
99-
100-
def _update_cost_model() -> None:
101-
anchor_data = governance_utils.get_default_anchor_data()
102-
_name_template = f"{temp_template}_cost_model"
103-
104-
update_proposals = [
105-
clusterlib_utils.UpdateProposal(
106-
arg="--cost-model-file",
107-
value=str(cost_proposal_file),
108-
name="", # costModels
109-
)
110-
]
111-
112-
cost_model_proposal = conway_common.propose_pparams_update(
113-
cluster_obj=cluster,
114-
name_template=_name_template,
115-
anchor_url=anchor_data.url,
116-
anchor_data_hash=anchor_data.hash,
117-
pool_user=pool_user_lgp,
118-
proposals=update_proposals,
119-
)
120-
121-
# Make sure we have enough time to submit the votes in one epoch
122-
clusterlib_utils.wait_for_epoch_interval(cluster_obj=cluster, start=1, stop=-40)
123-
prop_epoch = cluster.g_query.get_epoch()
124-
125-
# Vote & approve the action
126-
conway_common.cast_vote(
127-
cluster_obj=cluster,
128-
governance_data=governance_data,
129-
name_template=f"{_name_template}_yes",
130-
payment_addr=pool_user_lgp.payment,
131-
action_txid=cost_model_proposal.action_txid,
132-
action_ix=cost_model_proposal.action_ix,
133-
approve_cc=True,
134-
)
135-
136-
assert cluster.g_query.get_epoch() == prop_epoch, (
137-
"Epoch changed and it would affect other checks"
138-
)
139-
140-
# Wait for ratification
141-
rat_epoch = cluster.wait_for_epoch(epoch_no=prop_epoch + 1, padding_seconds=5)
142-
rat_gov_state = cluster.g_query.get_gov_state()
143-
conway_common.save_gov_state(
144-
gov_state=rat_gov_state, name_template=f"{_name_template}_{rat_epoch}"
145-
)
146-
rat_action = governance_utils.lookup_ratified_actions(
147-
state=rat_gov_state,
148-
action_txid=cost_model_proposal.action_txid,
149-
action_ix=cost_model_proposal.action_ix,
150-
)
151-
assert rat_action, "Action not found in ratified actions"
152-
153-
# Wait for enactment
154-
enact_epoch = cluster.wait_for_epoch(epoch_no=prop_epoch + 2, padding_seconds=5)
155-
enact_gov_state = cluster.g_query.get_gov_state()
156-
conway_common.save_gov_state(
157-
gov_state=enact_gov_state, name_template=f"{temp_template}_enact_{enact_epoch}"
158-
)
159-
pparams = enact_gov_state.get("currentPParams") or {}
160-
assert len(pparams["costModels"]["PlutusV2"]) == 185
161-
16297
# Check that Plutus script fails as expected in PV9
16398
mint_raw.check_missing_builtin(
16499
cluster_obj=cluster,
165-
temp_template=temp_template,
100+
temp_template=f"{temp_template}_check1",
166101
payment_addr=payment_addrs_lgp[0],
167102
issuer_addr=payment_addrs_lgp[1],
168103
)
169104

170105
# Update the PlutusV2 cost model
171-
_update_cost_model()
106+
updated_cost_models = conway_common.update_cost_model(
107+
cluster_obj=cluster,
108+
name_template=f"{temp_template}_cost_model",
109+
governance_data=governance_data,
110+
cost_proposal_file=DATA_DIR / "cost_models_list_185_v2_v3.json",
111+
pool_user=pool_user_lgp,
112+
)
113+
assert len(updated_cost_models["PlutusV2"]) == 185
172114

173115
# Check again that the Plutus script fails as expected in PV9
174116
mint_raw.check_missing_builtin(
175117
cluster_obj=cluster,
176-
temp_template=temp_template,
118+
temp_template=f"{temp_template}_check2",
177119
payment_addr=payment_addrs_lgp[0],
178120
issuer_addr=payment_addrs_lgp[1],
179121
)

0 commit comments

Comments
 (0)