Skip to content

Commit

Permalink
Merge branch 'dev' into fix-spec
Browse files Browse the repository at this point in the history
  • Loading branch information
axiongsupra authored Sep 5, 2024
2 parents 3847bfa + 28fa00c commit 2909d36
Show file tree
Hide file tree
Showing 24 changed files with 816 additions and 6,323 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/aptos-framework-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ name: Run aptos framework checks
on:
push:
branches:
- master
- integrate_consensus_key
- dev
pull_request:
branches:
- master
- integrate_consensus_key
- dev

env:
CARGO_TERM_COLOR: always
Expand Down
33 changes: 5 additions & 28 deletions aptos-move/e2e-move-tests/src/supra_governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ use crate::harness::MoveHarness;
use aptos_cached_packages::aptos_stdlib;
use aptos_language_e2e_tests::account::Account;
use aptos_types::{
account_address::AccountAddress, move_utils::MemberId, state_store::table::TableHandle,
account_address::AccountAddress, state_store::table::TableHandle,
transaction::TransactionStatus,
};
use serde::{Deserialize, Serialize};
use std::str::FromStr;

#[derive(Deserialize, Serialize)]
struct PartialVotingProposals {
Expand All @@ -27,19 +26,17 @@ struct VotingRecordsV2 {
pub votes: TableHandle,
}

pub fn create_proposal_v2(
pub fn supra_create_proposal_v2(
harness: &mut MoveHarness,
account: &Account,
stake_pool: AccountAddress,
execution_hash: Vec<u8>,
metadata_location: Vec<u8>,
metadata_hash: Vec<u8>,
is_multi_step_proposal: bool,
) -> TransactionStatus {
harness.run_transaction_payload(
account,
aptos_stdlib::supra_governance_create_proposal_v2(
stake_pool,
aptos_stdlib::supra_governance_supra_create_proposal_v2(
execution_hash,
metadata_location,
metadata_hash,
Expand All @@ -48,37 +45,17 @@ pub fn create_proposal_v2(
)
}

pub fn partial_vote(
pub fn supra_vote(
harness: &mut MoveHarness,
account: &Account,
stake_pool: AccountAddress,
proposal_id: u64,
voting_power: u64,
should_pass: bool,
) -> TransactionStatus {
harness.run_transaction_payload(
account,
aptos_stdlib::supra_governance_partial_vote(
stake_pool,
aptos_stdlib::supra_governance_supra_vote(
proposal_id,
voting_power,
should_pass,
),
)
}

pub fn get_remaining_voting_power(
harness: &mut MoveHarness,
stake_pool: AccountAddress,
proposal_id: u64,
) -> u64 {
let fun = MemberId::from_str("0x1::supra_governance::get_remaining_voting_power").unwrap();
let res = harness
.execute_view_function(fun, vec![], vec![
bcs::to_bytes(&stake_pool).unwrap(),
bcs::to_bytes(&proposal_id).unwrap(),
])
.values
.unwrap();
bcs::from_bytes::<u64>(&res[0]).unwrap()
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ script {

fun main(core_resources: &signer) {
let framework_signer = supra_governance::get_signer_testnet_only(core_resources, @supra_framework);
supra_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[]);
supra_governance::force_end_epoch(&framework_signer);
Expand Down
98 changes: 21 additions & 77 deletions aptos-move/e2e-move-tests/src/tests/vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

use crate::{
supra_governance::*, assert_abort, assert_success, increase_lockup, setup_staking,
supra_governance::*, assert_abort, assert_success,
tests::common, MoveHarness,
};
use aptos_types::account_address::AccountAddress;
Expand All @@ -18,47 +18,30 @@ fn build_scripts() -> BTreeMap<String, Vec<u8>> {
}

#[test]
fn test_vote() {
fn test_supra_vote() {
// Genesis starts with one validator with index 0
let mut harness = MoveHarness::new();
let validator_1 = harness.new_account_at(AccountAddress::from_hex_literal("0x123").unwrap());
let validator_2 = harness.new_account_at(AccountAddress::from_hex_literal("0x234").unwrap());
let validator_1_address = *validator_1.address();
let validator_2_address = *validator_2.address();

let stake_amount_1 = 25_000_000;
assert_success!(setup_staking(&mut harness, &validator_1, stake_amount_1));
assert_success!(increase_lockup(&mut harness, &validator_1));
let stake_amount_2 = 25_000_000;
assert_success!(setup_staking(&mut harness, &validator_2, stake_amount_2));
assert_success!(increase_lockup(&mut harness, &validator_2));
let proposer = harness.new_account_at(AccountAddress::from_hex_literal("0xdd2").unwrap());
let voter = harness.new_account_at(AccountAddress::from_hex_literal("0xdd1").unwrap());

let mut proposal_id: u64 = 0;
assert_success!(create_proposal_v2(
assert_success!(supra_create_proposal_v2(
&mut harness,
&validator_2,
validator_2_address,
&proposer,
vec![1],
vec![],
vec![],
true
));
// Voters can vote on a partial voting proposal but argument voting_power will be ignored.
assert_success!(partial_vote(
// Voters can vote on a voting proposal.
assert_success!(supra_vote(
&mut harness,
&validator_1,
validator_1_address,
&voter,
proposal_id,
100,
true
));
// No remaining voting power.
assert_eq!(
get_remaining_voting_power(&mut harness, validator_1_address, proposal_id),
0
);

// Enable partial governance voting. In production it requires governance.
// 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
Expand All @@ -69,21 +52,18 @@ fn test_vote() {

// If a voter has already voted on a proposal before partial voting is enabled, the voter cannot vote on the proposal again.
assert_abort!(
partial_vote(
supra_vote(
&mut harness,
&validator_1,
validator_1_address,
&voter,
proposal_id,
100,
true
),
0x10005
0x8000D
);

assert_success!(create_proposal_v2(
assert_success!(supra_create_proposal_v2(
&mut harness,
&validator_1,
validator_1_address,
&voter,
vec![1],
vec![],
vec![],
Expand All @@ -93,63 +73,27 @@ fn test_vote() {
// Cannot vote on a non-exist proposal.
let wrong_proposal_id: u64 = 2;
assert_abort!(
partial_vote(
supra_vote(
&mut harness,
&validator_1,
validator_1_address,
&voter,
wrong_proposal_id,
100,
true
),
25863
);

proposal_id = 1;
assert_eq!(
get_remaining_voting_power(&mut harness, validator_1_address, proposal_id),
stake_amount_1
);
assert_eq!(
get_remaining_voting_power(&mut harness, validator_2_address, proposal_id),
stake_amount_1
);

// A voter can vote on a proposal multiple times with both Yes/No.
assert_success!(partial_vote(
assert_success!(supra_vote(
&mut harness,
&validator_1,
validator_1_address,
&voter,
proposal_id,
100,
true
));
assert_eq!(
get_remaining_voting_power(&mut harness, validator_1_address, proposal_id),
stake_amount_1 - 100
);
assert_success!(partial_vote(
assert_success!(supra_vote(
&mut harness,
&validator_1,
validator_1_address,
&voter,
proposal_id,
1000,
false
));
assert_eq!(
get_remaining_voting_power(&mut harness, validator_1_address, proposal_id),
stake_amount_1 - 1100
);
// A voter cannot use voting power more than it has.
assert_success!(partial_vote(
&mut harness,
&validator_1,
validator_1_address,
proposal_id,
stake_amount_1,
true
));
assert_eq!(
get_remaining_voting_power(&mut harness, validator_1_address, proposal_id),
0
);
}
Loading

0 comments on commit 2909d36

Please sign in to comment.