Skip to content

Commit

Permalink
Enable partial_governance_voting
Browse files Browse the repository at this point in the history
- Enable the feature flag partial_governance_voting by default
- Adjust the Move unit tests
  • Loading branch information
junkil-park committed Dec 11, 2024
1 parent 807a2db commit fb462c3
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
17 changes: 11 additions & 6 deletions aptos-move/e2e-move-tests/src/tests/vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<BTreeMap<String, Vec<u8>>> = Lazy::new(build_scripts);

Expand All @@ -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,
Expand All @@ -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.
Expand Down
21 changes: 17 additions & 4 deletions aptos-move/framework/aptos-framework/sources/aptos_governance.move
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>();
vector::push_back(&mut execution_hash, 1);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<u8>();
vector::push_back(&mut execution_hash, 1);
Expand Down Expand Up @@ -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<u8>();
vector::push_back(&mut execution_hash, 1);
let proposer_addr = signer::address_of(&proposer);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions types/src/on_chain_config/aptos_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit fb462c3

Please sign in to comment.