Skip to content

Commit

Permalink
Test CC threshold set to zero
Browse files Browse the repository at this point in the history
  • Loading branch information
saratomaz committed Apr 23, 2024
1 parent ce6ab2f commit a543b2b
Showing 1 changed file with 163 additions and 0 deletions.
163 changes: 163 additions & 0 deletions cardano_node_tests/tests/tests_conway/test_committee.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from cardano_node_tests.utils import governance_utils
from cardano_node_tests.utils import helpers
from cardano_node_tests.utils import submit_utils
from cardano_node_tests.utils.governance_utils import PrevGovActionIds
from cardano_node_tests.utils.versions import VERSIONS

LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -1332,3 +1333,165 @@ def _check_const_state(state: dict):
ledger_3979 = issues.ledger_3979.copy()
ledger_3979.message = " ;".join(xfail_ledger_3979_msgs)
ledger_3979.finish_test()

@allure.link(helpers.get_vcs_link())
@pytest.mark.skipif(not configuration.HAS_CC, reason="Runs only on setup with CC")
@pytest.mark.long
def test_committee_zero_threshold(
self,
cluster_lock_governance: governance_setup.GovClusterT,
pool_user_lg: clusterlib.PoolUser,
):
"""Test that actions that requires CC approval can be ratified when threshold == 0.
Even if the CC disapprove the action
* set CC threshold to zero
* submit a "create constitution" action
* vote to disapprove the action by the CC and approve by the DReps
* check that the action is ratified
* check that the action is enacted
"""
cluster, governance_data = cluster_lock_governance
temp_template = common.get_test_id(cluster)

def _check_rat_enact_state(
fin_approve_epoch: int, action_txid: str, action_type: PrevGovActionIds
) -> None:
# Check ratification
_cur_epoch = cluster.g_query.get_epoch()
if _cur_epoch == fin_approve_epoch:
_cur_epoch = cluster.wait_for_new_epoch(padding_seconds=5)

if _cur_epoch == fin_approve_epoch + 1:
rat_gov_state = cluster.g_conway_governance.query.gov_state()
conway_common.save_gov_state(
gov_state=rat_gov_state, name_template=f"{temp_template}_rat_{_cur_epoch}"
)

rat_action = governance_utils.lookup_ratified_actions(
gov_state=rat_gov_state, action_txid=action_txid
)
assert rat_action, "Action not found in ratified actions"

# Wait for enactment
_cur_epoch = cluster.wait_for_new_epoch(padding_seconds=5)

# Check enactment
assert _cur_epoch == fin_approve_epoch + 2, f"Unexpected epoch {_cur_epoch}"
enact_gov_state = cluster.g_conway_governance.query.gov_state()
conway_common.save_gov_state(
gov_state=enact_gov_state, name_template=f"{temp_template}_enact_{_cur_epoch}"
)

prev_action_rec = governance_utils.get_prev_action(
action_type=action_type,
gov_state=enact_gov_state,
)

assert prev_action_rec.txid == action_txid, "Action not enacted"

deposit_amt = cluster.conway_genesis["govActionDeposit"]
anchor_url = "http://www.cc-update.com"
anchor_data_hash = "5d372dca1a4cc90d7d16d966c48270e33e3aa0abcb0e78f0d5ca7ff330d2245d"
prev_action_rec = governance_utils.get_prev_action(
action_type=governance_utils.PrevGovActionIds.COMMITTEE,
gov_state=cluster.g_conway_governance.query.gov_state(),
)

update_threshold_action = cluster.g_conway_governance.action.update_committee(
action_name=temp_template,
deposit_amt=deposit_amt,
anchor_url=anchor_url,
anchor_data_hash=anchor_data_hash,
threshold="0",
prev_action_txid=prev_action_rec.txid,
prev_action_ix=prev_action_rec.ix,
deposit_return_stake_vkey_file=pool_user_lg.stake.vkey_file,
)

tx_files = clusterlib.TxFiles(
proposal_files=[update_threshold_action.action_file],
signing_key_files=[
pool_user_lg.payment.skey_file,
],
)

tx_output_action = clusterlib_utils.build_and_submit_tx(
cluster_obj=cluster,
name_template=f"{temp_template}_update_threshold",
src_address=pool_user_lg.payment.address,
use_build_cmd=True,
tx_files=tx_files,
)

action_txid = cluster.g_transaction.get_txid(tx_body_file=tx_output_action.out_file)
action_gov_state = cluster.g_conway_governance.query.gov_state()
_cur_epoch = cluster.g_query.get_epoch()
conway_common.save_gov_state(
gov_state=action_gov_state, name_template=f"{temp_template}_action_{_cur_epoch}"
)
prop_action = governance_utils.lookup_proposal(
gov_state=action_gov_state, action_txid=action_txid
)
action_ix = prop_action["actionId"]["govActionIx"]

conway_common.cast_vote(
cluster_obj=cluster,
governance_data=governance_data,
name_template=f"{temp_template}_add_yes",
payment_addr=pool_user_lg.payment,
action_txid=action_txid,
action_ix=action_ix,
approve_drep=True,
approve_spo=True,
)

_check_rat_enact_state(
fin_approve_epoch=cluster.g_query.get_epoch(),
action_txid=action_txid,
action_type=governance_utils.PrevGovActionIds.COMMITTEE,
)

# Try to ratify a "create constitution" action that are expecting approval from the CC
anchor_url = "http://www.const-action.com"
constitution_url = "http://www.const-new.com"
(
const_action,
const_action_txid,
const_action_ix,
) = conway_common.propose_change_constitution(
cluster_obj=cluster,
name_template=f"{temp_template}_constitution",
anchor_url=anchor_url,
anchor_data_hash=cluster.g_conway_governance.get_anchor_data_hash(text=anchor_url),
constitution_url=constitution_url,
constitution_hash=cluster.g_conway_governance.get_anchor_data_hash(
text=constitution_url
),
pool_user=pool_user_lg,
)
conway_common.cast_vote(
cluster_obj=cluster,
governance_data=governance_data,
name_template=f"{temp_template}_constitution",
payment_addr=pool_user_lg.payment,
action_txid=const_action_txid,
action_ix=const_action_ix,
approve_cc=False,
approve_drep=True,
)

_check_rat_enact_state(
fin_approve_epoch=cluster.g_query.get_epoch(),
action_txid=const_action_txid,
action_type=governance_utils.PrevGovActionIds.CONSTITUTION,
)

# Reinstate the original CC members
governance_setup.reinstate_committee(
cluster_obj=cluster,
governance_data=governance_data,
name_template=f"{temp_template}_reinstate",
pool_user=pool_user_lg,
)

0 comments on commit a543b2b

Please sign in to comment.