Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Participating in Council Governance is Free for First Time Voters and Successful Closing #7661

Merged
21 commits merged into from
Dec 15, 2020
Merged
Changes from 3 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
2a24ad4
wk2049 | D5 | addition-motions first free vote for members | p1
shamb0 Dec 3, 2020
a3b6a91
Update frame/collective/src/lib.rs
shamb0 Dec 4, 2020
eb70a2c
wk2049 | D6 | addition-motions first free vote for members | p2
shamb0 Dec 4, 2020
e260a69
Update frame/collective/src/lib.rs
shamb0 Dec 5, 2020
c99f1fe
Update frame/collective/src/lib.rs
shamb0 Dec 5, 2020
18fe1ad
Merge remote-tracking branch 'upstream/master' into issue-6904-first-…
shamb0 Dec 5, 2020
4c5bca8
wk2049 | D7 | addition-motions first free vote for members | p3
shamb0 Dec 5, 2020
4a185b4
Update frame/collective/src/lib.rs
shamb0 Dec 5, 2020
7aa902e
wk2049 | D7 | addition-motions first free vote for members | p4
shamb0 Dec 5, 2020
002d299
wk2049 | D7 | addition-motions first free vote for members | p6
shamb0 Dec 5, 2020
f50afcf
Update frame/collective/src/lib.rs
shamb0 Dec 8, 2020
9f205ab
Update frame/collective/src/lib.rs
shamb0 Dec 8, 2020
3efae32
Update frame/collective/src/lib.rs
shamb0 Dec 8, 2020
e969e99
Update frame/collective/src/lib.rs
shamb0 Dec 8, 2020
4fa0baa
Update frame/collective/src/lib.rs
shamb0 Dec 8, 2020
ae3b46e
Update frame/collective/src/lib.rs
shamb0 Dec 8, 2020
0c66e21
Update frame/collective/src/lib.rs
shamb0 Dec 8, 2020
fe55802
wk2050 | D3 | addition-motions first free vote for members | p7
shamb0 Dec 8, 2020
2dcedc2
wk2050 | D3 | addition-motions first free vote for members | p8
shamb0 Dec 8, 2020
150420a
update comment
shawntabrizi Dec 8, 2020
a70f611
Merge branch 'master' into pr/7661
shawntabrizi Dec 14, 2020
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
253 changes: 241 additions & 12 deletions frame/collective/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ use frame_support::{
},
ensure,
traits::{ChangeMembers, EnsureOrigin, Get, InitializeMembers},
weights::{DispatchClass, GetDispatchInfo, Weight},
weights::{DispatchClass, GetDispatchInfo, Weight, Pays},
};
use frame_system::{self as system, ensure_signed, ensure_root};

Expand Down Expand Up @@ -486,6 +486,8 @@ decl_module! {

/// Add an aye or nay vote for the sender to the given proposal.
///
/// And transaction fee is free for First time voters.
///
/// Requires the sender to be a member.
///
shamb0 marked this conversation as resolved.
Show resolved Hide resolved
/// # <weight>
Expand Down Expand Up @@ -515,6 +517,9 @@ decl_module! {
let position_yes = voting.ayes.iter().position(|a| a == &who);
let position_no = voting.nays.iter().position(|a| a == &who);

// Detects first vote of the member in the motion
let is_account_voting_first_time = position_yes.is_none() && position_no.is_none();
shamb0 marked this conversation as resolved.
Show resolved Hide resolved

if approve {
if position_yes.is_none() {
voting.ayes.push(who.clone());
Expand All @@ -541,13 +546,25 @@ decl_module! {

Voting::<T, I>::insert(&proposal, voting);

Ok(Some(T::WeightInfo::vote(members.len() as u32)).into())
if is_account_voting_first_time {
Ok((
Some(T::WeightInfo::vote(members.len() as u32)),
Pays::No,
).into())
} else {
Ok((
Some(T::WeightInfo::vote(members.len() as u32)),
Pays::Yes,
).into())
}
}

/// Close a vote that is either approved, disapproved or whose voting period has ended.
///
/// May be called by any signed account in order to finish voting and close the proposal.
///
/// And transaction fee is free for successful close.
shamb0 marked this conversation as resolved.
Show resolved Hide resolved
///
/// If called before the end of the voting period it will only close the vote if it is
/// has enough votes to be approved or disapproved.
///
Expand Down Expand Up @@ -611,15 +628,18 @@ decl_module! {
Self::deposit_event(RawEvent::Closed(proposal_hash, yes_votes, no_votes));
let (proposal_weight, proposal_count) =
Self::do_approve_proposal(seats, voting, proposal_hash, proposal);
return Ok(Some(
T::WeightInfo::close_early_approved(len as u32, seats, proposal_count)
.saturating_add(proposal_weight)
return Ok((
Some(T::WeightInfo::close_early_approved(len as u32, seats, proposal_count)
.saturating_add(proposal_weight)),
Pays::No
).into());

} else if disapproved {
Self::deposit_event(RawEvent::Closed(proposal_hash, yes_votes, no_votes));
let proposal_count = Self::do_disapprove_proposal(proposal_hash);
return Ok(Some(
T::WeightInfo::close_early_disapproved(seats, proposal_count)
return Ok((
Some(T::WeightInfo::close_early_disapproved(seats, proposal_count)),
Pays::No
).into());
}

Expand Down Expand Up @@ -647,15 +667,17 @@ decl_module! {
Self::deposit_event(RawEvent::Closed(proposal_hash, yes_votes, no_votes));
let (proposal_weight, proposal_count) =
Self::do_approve_proposal(seats, voting, proposal_hash, proposal);
return Ok(Some(
T::WeightInfo::close_approved(len as u32, seats, proposal_count)
.saturating_add(proposal_weight)
return Ok((
Some(T::WeightInfo::close_approved(len as u32, seats, proposal_count)
.saturating_add(proposal_weight)),
Pays::No
shamb0 marked this conversation as resolved.
Show resolved Hide resolved
shamb0 marked this conversation as resolved.
Show resolved Hide resolved
).into());
} else {
Self::deposit_event(RawEvent::Closed(proposal_hash, yes_votes, no_votes));
let proposal_count = Self::do_disapprove_proposal(proposal_hash);
return Ok(Some(
T::WeightInfo::close_disapproved(seats, proposal_count)
return Ok((
Some(T::WeightInfo::close_disapproved(seats, proposal_count)),
Pays::No
).into());
}
}
Expand Down Expand Up @@ -1441,6 +1463,213 @@ mod tests {
});
}

#[test]
fn motions_all_first_vote_free_works() {
new_test_ext().execute_with(|| {
let proposal = make_proposal(42);
let proposal_len: u32 = proposal.using_encoded(|p| p.len() as u32);
let hash: H256 = proposal.blake2_256().into();
let end = 4;
assert_ok!(
Collective::propose(
Origin::signed(1),
2,
Box::new(proposal.clone()),
proposal_len
)
);
assert_eq!(
Collective::voting(&hash),
Some(Votes { index: 0, threshold: 2, ayes: vec![1], nays: vec![], end })
);

// For the motion, acc 2's first vote, expecting Ok with Pays::No ...
shamb0 marked this conversation as resolved.
Show resolved Hide resolved
assert_eq!(
Collective::vote(Origin::signed(2), hash.clone(), 0, true),
Ok(
PostDispatchInfo {
actual_weight: Some(
207711000,
),
pays_fee: Pays::No,
}
)
);

// Duplicate vote, expecting error with Pays::Yes ...
shamb0 marked this conversation as resolved.
Show resolved Hide resolved
let vote_rval: DispatchResultWithPostInfo = Collective::vote(
Origin::signed(2),
hash.clone(),
0,
true
);
match vote_rval {
Ok(_) => {
// Forced Panic, Invalid case, should not occur.
assert!(false);
},
Err(err) => {
assert_eq!( err.post_info.pays_fee, Pays::Yes );
},
}

// Modifying vote, expecting ok with Pays::Yes ...
shamb0 marked this conversation as resolved.
Show resolved Hide resolved
assert_eq!(
Collective::vote(Origin::signed(2), hash.clone(), 0, false),
Ok(
PostDispatchInfo {
actual_weight: Some(
207711000,
),
pays_fee: Pays::Yes,
}
)
);

// For the motion, acc 3's first vote, expecting Ok with Pays::No ...
shamb0 marked this conversation as resolved.
Show resolved Hide resolved
assert_eq!(
Collective::vote(Origin::signed(3), hash.clone(), 0, true),
Ok(
PostDispatchInfo {
actual_weight: Some(
207711000,
),
pays_fee: Pays::No,
}
)
);

// acc 3 modify the vote, expecting Ok with Pays::Yes ...
shamb0 marked this conversation as resolved.
Show resolved Hide resolved
assert_eq!(
Collective::vote(Origin::signed(3), hash.clone(), 0, false),
Ok(
PostDispatchInfo {
actual_weight: Some(
207711000,
),
pays_fee: Pays::Yes,
}
)
);

// Test close() Extrincis | Check DispatchResultWithPostInfo with Pay Info

let proposal_weight = proposal.get_dispatch_info().weight;

// trying to close the valid proposal, Expecting OK with Pays::No
assert_eq!(
Collective::close(
Origin::signed(2),
hash.clone(),
0,
proposal_weight,
proposal_len
),
Ok(
PostDispatchInfo {
actual_weight: Some(
437711000,
),
pays_fee: Pays::No,
},
)
);

// trying to close the proposal, which is already closed.
// Expecting error "ProposalMissing" with Pays::Yes
let close_rval: DispatchResultWithPostInfo = Collective::close(
Origin::signed(2),
hash.clone(),
0,
proposal_weight,
proposal_len
);
match close_rval {
Ok(_) => {
// Forced Panic, Invalid case, should not occur.
assert!(false);
},
Err(err) => {
assert_eq!( err.post_info.pays_fee, Pays::Yes );
},
}

// Verify the events pool
assert_eq!(System::events(), vec![
shawntabrizi marked this conversation as resolved.
Show resolved Hide resolved
EventRecord {
phase: Phase::Initialization,
event: Event::collective_Instance1(RawEvent::Proposed(
1,
0,
hex!["68eea8f20b542ec656c6ac2d10435ae3bd1729efc34d1354ab85af840aad2d35"].into(),
2
)),
topics: vec![],
},
EventRecord {
phase: Phase::Initialization,
event: Event::collective_Instance1(RawEvent::Voted(
2,
hex!["68eea8f20b542ec656c6ac2d10435ae3bd1729efc34d1354ab85af840aad2d35"].into(),
true,
2,
0
)),
topics: vec![],
},
EventRecord {
phase: Phase::Initialization,
event: Event::collective_Instance1(RawEvent::Voted(
2,
hex!["68eea8f20b542ec656c6ac2d10435ae3bd1729efc34d1354ab85af840aad2d35"].into(),
false,
1,
1
)),
topics: vec![],
},
EventRecord {
phase: Phase::Initialization,
event: Event::collective_Instance1(RawEvent::Voted(
3,
hex!["68eea8f20b542ec656c6ac2d10435ae3bd1729efc34d1354ab85af840aad2d35"].into(),
true,
2,
1
)),
topics: vec![],
},
EventRecord {
phase: Phase::Initialization,
event: Event::collective_Instance1(RawEvent::Voted(
3,
hex!["68eea8f20b542ec656c6ac2d10435ae3bd1729efc34d1354ab85af840aad2d35"].into(),
false,
1,
2
)),
topics: vec![],
},
EventRecord {
phase: Phase::Initialization,
event: Event::collective_Instance1(RawEvent::Closed(
hex!["68eea8f20b542ec656c6ac2d10435ae3bd1729efc34d1354ab85af840aad2d35"].into(),
1,
2,
)),
topics: vec![],
},
EventRecord {
phase: Phase::Initialization,
event: Event::collective_Instance1(RawEvent::Disapproved(
hex!["68eea8f20b542ec656c6ac2d10435ae3bd1729efc34d1354ab85af840aad2d35"].into(),
)),
topics: vec![],
},
]);
});
}

#[test]
fn motions_reproposing_disapproved_works() {
new_test_ext().execute_with(|| {
Expand Down