From fb462c30ea637fadfeb46f77b513d4ba23d13e24 Mon Sep 17 00:00:00 2001 From: Junkil Park Date: Tue, 10 Dec 2024 09:22:43 -0800 Subject: [PATCH] Enable partial_governance_voting - Enable the feature flag partial_governance_voting by default - Adjust the Move unit tests --- .../sources/main.move | 10 ++++++--- aptos-move/e2e-move-tests/src/tests/vote.rs | 17 +++++++++------ .../sources/aptos_governance.move | 21 +++++++++++++++---- types/src/on_chain_config/aptos_features.rs | 1 + 4 files changed, 36 insertions(+), 13 deletions(-) diff --git a/aptos-move/e2e-move-tests/src/tests/vote.data/enable_partial_governance_voting/sources/main.move b/aptos-move/e2e-move-tests/src/tests/vote.data/enable_partial_governance_voting/sources/main.move index 60b8843709463..99bb9161506e3 100644 --- a/aptos-move/e2e-move-tests/src/tests/vote.data/enable_partial_governance_voting/sources/main.move +++ b/aptos-move/e2e-move-tests/src/tests/vote.data/enable_partial_governance_voting/sources/main.move @@ -2,11 +2,15 @@ script { use aptos_framework::aptos_governance; use std::features; - fun main(core_resources: &signer) { + fun main(core_resources: &signer, enable_partial_governance_voting: bool) { let framework_signer = aptos_governance::get_signer_testnet_only(core_resources, @aptos_framework); - aptos_governance::initialize_partial_voting(&framework_signer); let feature = features::get_partial_governance_voting(); - features::change_feature_flags_for_next_epoch(&framework_signer, vector[feature], vector[]); + if (enable_partial_governance_voting) { + aptos_governance::initialize_partial_voting(&framework_signer); + features::change_feature_flags_for_next_epoch(&framework_signer, vector[feature], vector[]); + } else { + features::change_feature_flags_for_next_epoch(&framework_signer, vector[], vector[feature]); + }; aptos_governance::force_end_epoch(&framework_signer); } } diff --git a/aptos-move/e2e-move-tests/src/tests/vote.rs b/aptos-move/e2e-move-tests/src/tests/vote.rs index ebba2e3654ef9..39027c98c8601 100644 --- a/aptos-move/e2e-move-tests/src/tests/vote.rs +++ b/aptos-move/e2e-move-tests/src/tests/vote.rs @@ -8,6 +8,7 @@ use crate::{ use aptos_types::account_address::AccountAddress; use once_cell::sync::Lazy; use std::collections::BTreeMap; +use move_core_types::transaction_argument::TransactionArgument; pub static PROPOSAL_SCRIPTS: Lazy>> = Lazy::new(build_scripts); @@ -33,6 +34,15 @@ fn test_vote() { assert_success!(setup_staking(&mut harness, &validator_2, stake_amount_2)); assert_success!(increase_lockup(&mut harness, &validator_2)); + // Disable partial governance voting. + let core_resources = + harness.new_account_at(AccountAddress::from_hex_literal("0xA550C18").unwrap()); + let script_code = PROPOSAL_SCRIPTS + .get("enable_partial_governance_voting") + .expect("proposal script should be built"); + let txn = harness.create_script(&core_resources, script_code.clone(), vec![], vec![TransactionArgument::Bool(false)]); + assert_success!(harness.run(txn)); + let mut proposal_id: u64 = 0; assert_success!(create_proposal_v2( &mut harness, @@ -59,12 +69,7 @@ fn test_vote() { ); // Enable partial governance voting. In production it requires governance. - let core_resources = - harness.new_account_at(AccountAddress::from_hex_literal("0xA550C18").unwrap()); - let script_code = PROPOSAL_SCRIPTS - .get("enable_partial_governance_voting") - .expect("proposal script should be built"); - let txn = harness.create_script(&core_resources, script_code.clone(), vec![], vec![]); + let txn = harness.create_script(&core_resources, script_code.clone(), vec![], vec![TransactionArgument::Bool(true)]); assert_success!(harness.run(txn)); // If a voter has already voted on a proposal before partial voting is enabled, the voter cannot vote on the proposal again. diff --git a/aptos-move/framework/aptos-framework/sources/aptos_governance.move b/aptos-move/framework/aptos-framework/sources/aptos_governance.move index f44ba1b3239fc..5d8d0e99b0598 100644 --- a/aptos-move/framework/aptos-framework/sources/aptos_governance.move +++ b/aptos-move/framework/aptos-framework/sources/aptos_governance.move @@ -811,7 +811,7 @@ module aptos_framework::aptos_governance { multi_step: bool, use_generic_resolve_function: bool, ) acquires ApprovedExecutionHashes, GovernanceConfig, GovernanceResponsbility, VotingRecords, VotingRecordsV2, GovernanceEvents { - setup_voting(&aptos_framework, &proposer, &yes_voter, &no_voter); + setup_partial_voting(&aptos_framework, &proposer, &yes_voter, &no_voter); let execution_hash = vector::empty(); vector::push_back(&mut execution_hash, 1); @@ -898,7 +898,7 @@ module aptos_framework::aptos_governance { no_voter: signer, multi_step: bool, ) acquires ApprovedExecutionHashes, GovernanceConfig, GovernanceResponsbility, VotingRecords, VotingRecordsV2, GovernanceEvents { - setup_voting(&aptos_framework, &proposer, &yes_voter, &no_voter); + setup_partial_voting(&aptos_framework, &proposer, &yes_voter, &no_voter); create_proposal_for_test(&proposer, multi_step); vote(&yes_voter, signer::address_of(&yes_voter), 0, true); @@ -1134,6 +1134,7 @@ module aptos_framework::aptos_governance { voter_1: signer, voter_2: signer, ) acquires ApprovedExecutionHashes, GovernanceConfig, GovernanceResponsbility, VotingRecords, VotingRecordsV2, GovernanceEvents { + features::change_feature_flags_for_testing(&aptos_framework, vector[], vector[features::get_partial_governance_voting()]); setup_voting(&aptos_framework, &proposer, &voter_1, &voter_2); let execution_hash = vector::empty(); vector::push_back(&mut execution_hash, 1); @@ -1171,7 +1172,7 @@ module aptos_framework::aptos_governance { voter_1: signer, voter_2: signer, ) acquires GovernanceConfig, GovernanceResponsbility, VotingRecords, VotingRecordsV2, GovernanceEvents { - setup_voting_with_initialized_stake(&aptos_framework, &proposer, &voter_1, &voter_2); + setup_partial_voting_with_initialized_stake(&aptos_framework, &proposer, &voter_1, &voter_2); let execution_hash = vector::empty(); vector::push_back(&mut execution_hash, 1); let proposer_addr = signer::address_of(&proposer); @@ -1299,6 +1300,18 @@ module aptos_framework::aptos_governance { stake::end_epoch(); } + #[test_only] + public fun setup_partial_voting_with_initialized_stake( + aptos_framework: &signer, + proposer: &signer, + yes_voter: &signer, + no_voter: &signer, + ) acquires GovernanceResponsbility { + initialize_partial_voting(aptos_framework); + features::change_feature_flags_for_testing(aptos_framework, vector[features::get_partial_governance_voting()], vector[]); + setup_voting_with_initialized_stake(aptos_framework, proposer, yes_voter, no_voter); + } + #[test_only] public fun setup_partial_voting( aptos_framework: &signer, @@ -1340,7 +1353,7 @@ module aptos_framework::aptos_governance { yes_voter: signer, no_voter: signer, ) acquires GovernanceResponsbility, GovernanceConfig, ApprovedExecutionHashes, VotingRecords, VotingRecordsV2, GovernanceEvents { - setup_voting(&aptos_framework, &proposer, &yes_voter, &no_voter); + setup_partial_voting(&aptos_framework, &proposer, &yes_voter, &no_voter); create_proposal_for_test(&proposer, true); vote(&yes_voter, signer::address_of(&yes_voter), 0, true); diff --git a/types/src/on_chain_config/aptos_features.rs b/types/src/on_chain_config/aptos_features.rs index 70bc4f18aa546..2247a60edb152 100644 --- a/types/src/on_chain_config/aptos_features.rs +++ b/types/src/on_chain_config/aptos_features.rs @@ -122,6 +122,7 @@ impl FeatureFlag { FeatureFlag::BLS12_381_STRUCTURES, FeatureFlag::ED25519_PUBKEY_VALIDATE_RETURN_FALSE_WRONG_LENGTH, FeatureFlag::STRUCT_CONSTRUCTORS, + FeatureFlag::PARTIAL_GOVERNANCE_VOTING, FeatureFlag::SIGNATURE_CHECKER_V2, FeatureFlag::STORAGE_SLOT_METADATA, FeatureFlag::CHARGE_INVARIANT_VIOLATION,