Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable partial_governance_voting #15553

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
21 changes: 15 additions & 6 deletions aptos-move/e2e-move-tests/src/tests/vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::{
tests::common, MoveHarness,
};
use aptos_types::account_address::AccountAddress;
use move_core_types::transaction_argument::TransactionArgument;
use once_cell::sync::Lazy;
use std::collections::BTreeMap;

Expand Down Expand Up @@ -33,6 +34,17 @@ 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 +71,9 @@ 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
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
Loading