BREAKING: Rename Origin (#12258)

* BREAKING: Rename Origin

* more renaming

* a bit more renaming

* fix

* more fixing

* fix in frame_support

* even more fixes

* fix

* small fix

* ...

* update .stderr

* docs

* update docs

* update docs

* docs
This commit is contained in:
Sergej Sakac
2022-09-21 00:13:09 +02:00
committed by GitHub
parent 986d20b352
commit e4b6f4a66d
221 changed files with 5233 additions and 4200 deletions
+179 -164
View File
@@ -65,7 +65,7 @@ impl frame_system::Config for Test {
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type BlockNumber = u64;
type RuntimeCall = RuntimeCall;
@@ -269,28 +269,28 @@ fn basic_stuff() {
#[test]
fn basic_voting_works() {
new_test_ext().execute_with(|| {
assert_ok!(Voting::vote(Origin::signed(1), 3, aye(2, 5)));
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 3, aye(2, 5)));
assert_eq!(tally(3), Tally::from_parts(10, 0, 2));
assert_ok!(Voting::vote(Origin::signed(1), 3, nay(2, 5)));
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 3, nay(2, 5)));
assert_eq!(tally(3), Tally::from_parts(0, 10, 0));
assert_eq!(Balances::usable_balance(1), 8);
assert_ok!(Voting::vote(Origin::signed(1), 3, aye(5, 1)));
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 3, aye(5, 1)));
assert_eq!(tally(3), Tally::from_parts(5, 0, 5));
assert_ok!(Voting::vote(Origin::signed(1), 3, nay(5, 1)));
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 3, nay(5, 1)));
assert_eq!(tally(3), Tally::from_parts(0, 5, 0));
assert_eq!(Balances::usable_balance(1), 5);
assert_ok!(Voting::vote(Origin::signed(1), 3, aye(10, 0)));
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 3, aye(10, 0)));
assert_eq!(tally(3), Tally::from_parts(1, 0, 10));
assert_ok!(Voting::vote(Origin::signed(1), 3, nay(10, 0)));
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 3, nay(10, 0)));
assert_eq!(tally(3), Tally::from_parts(0, 1, 0));
assert_eq!(Balances::usable_balance(1), 0);
assert_ok!(Voting::remove_vote(Origin::signed(1), None, 3));
assert_ok!(Voting::remove_vote(RuntimeOrigin::signed(1), None, 3));
assert_eq!(tally(3), Tally::from_parts(0, 0, 0));
assert_ok!(Voting::unlock(Origin::signed(1), class(3), 1));
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), class(3), 1));
assert_eq!(Balances::usable_balance(1), 10);
});
}
@@ -298,28 +298,28 @@ fn basic_voting_works() {
#[test]
fn voting_balance_gets_locked() {
new_test_ext().execute_with(|| {
assert_ok!(Voting::vote(Origin::signed(1), 3, aye(2, 5)));
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 3, aye(2, 5)));
assert_eq!(tally(3), Tally::from_parts(10, 0, 2));
assert_ok!(Voting::vote(Origin::signed(1), 3, nay(2, 5)));
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 3, nay(2, 5)));
assert_eq!(tally(3), Tally::from_parts(0, 10, 0));
assert_eq!(Balances::usable_balance(1), 8);
assert_ok!(Voting::vote(Origin::signed(1), 3, aye(5, 1)));
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 3, aye(5, 1)));
assert_eq!(tally(3), Tally::from_parts(5, 0, 5));
assert_ok!(Voting::vote(Origin::signed(1), 3, nay(5, 1)));
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 3, nay(5, 1)));
assert_eq!(tally(3), Tally::from_parts(0, 5, 0));
assert_eq!(Balances::usable_balance(1), 5);
assert_ok!(Voting::vote(Origin::signed(1), 3, aye(10, 0)));
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 3, aye(10, 0)));
assert_eq!(tally(3), Tally::from_parts(1, 0, 10));
assert_ok!(Voting::vote(Origin::signed(1), 3, nay(10, 0)));
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 3, nay(10, 0)));
assert_eq!(tally(3), Tally::from_parts(0, 1, 0));
assert_eq!(Balances::usable_balance(1), 0);
assert_ok!(Voting::remove_vote(Origin::signed(1), None, 3));
assert_ok!(Voting::remove_vote(RuntimeOrigin::signed(1), None, 3));
assert_eq!(tally(3), Tally::from_parts(0, 0, 0));
assert_ok!(Voting::unlock(Origin::signed(1), class(3), 1));
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), class(3), 1));
assert_eq!(Balances::usable_balance(1), 10);
});
}
@@ -327,12 +327,12 @@ fn voting_balance_gets_locked() {
#[test]
fn successful_but_zero_conviction_vote_balance_can_be_unlocked() {
new_test_ext().execute_with(|| {
assert_ok!(Voting::vote(Origin::signed(1), 3, aye(1, 1)));
assert_ok!(Voting::vote(Origin::signed(2), 3, nay(20, 0)));
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 3, aye(1, 1)));
assert_ok!(Voting::vote(RuntimeOrigin::signed(2), 3, nay(20, 0)));
let c = class(3);
Polls::set(vec![(3, Completed(3, false))].into_iter().collect());
assert_ok!(Voting::remove_vote(Origin::signed(2), Some(c), 3));
assert_ok!(Voting::unlock(Origin::signed(2), c, 2));
assert_ok!(Voting::remove_vote(RuntimeOrigin::signed(2), Some(c), 3));
assert_ok!(Voting::unlock(RuntimeOrigin::signed(2), c, 2));
assert_eq!(Balances::usable_balance(2), 20);
});
}
@@ -340,12 +340,12 @@ fn successful_but_zero_conviction_vote_balance_can_be_unlocked() {
#[test]
fn unsuccessful_conviction_vote_balance_can_be_unlocked() {
new_test_ext().execute_with(|| {
assert_ok!(Voting::vote(Origin::signed(1), 3, aye(1, 1)));
assert_ok!(Voting::vote(Origin::signed(2), 3, nay(20, 0)));
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 3, aye(1, 1)));
assert_ok!(Voting::vote(RuntimeOrigin::signed(2), 3, nay(20, 0)));
let c = class(3);
Polls::set(vec![(3, Completed(3, false))].into_iter().collect());
assert_ok!(Voting::remove_vote(Origin::signed(1), Some(c), 3));
assert_ok!(Voting::unlock(Origin::signed(1), c, 1));
assert_ok!(Voting::remove_vote(RuntimeOrigin::signed(1), Some(c), 3));
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), c, 1));
assert_eq!(Balances::usable_balance(1), 10);
});
}
@@ -354,17 +354,17 @@ fn unsuccessful_conviction_vote_balance_can_be_unlocked() {
fn successful_conviction_vote_balance_stays_locked_for_correct_time() {
new_test_ext().execute_with(|| {
for i in 1..=5 {
assert_ok!(Voting::vote(Origin::signed(i), 3, aye(10, i as u8)));
assert_ok!(Voting::vote(RuntimeOrigin::signed(i), 3, aye(10, i as u8)));
}
let c = class(3);
Polls::set(vec![(3, Completed(3, true))].into_iter().collect());
for i in 1..=5 {
assert_ok!(Voting::remove_vote(Origin::signed(i), Some(c), 3));
assert_ok!(Voting::remove_vote(RuntimeOrigin::signed(i), Some(c), 3));
}
for block in 1..=(3 + 5 * 3) {
run_to(block);
for i in 1..=5 {
assert_ok!(Voting::unlock(Origin::signed(i), c, i));
assert_ok!(Voting::unlock(RuntimeOrigin::signed(i), c, i));
let expired = block >= (3 << (i - 1)) + 3;
assert_eq!(Balances::usable_balance(i), i * 10 - if expired { 0 } else { 10 });
}
@@ -385,20 +385,20 @@ fn classwise_delegation_works() {
.into_iter()
.collect(),
);
assert_ok!(Voting::delegate(Origin::signed(1), 0, 2, Conviction::Locked1x, 5));
assert_ok!(Voting::delegate(Origin::signed(1), 1, 3, Conviction::Locked1x, 5));
assert_ok!(Voting::delegate(Origin::signed(1), 2, 4, Conviction::Locked1x, 5));
assert_ok!(Voting::delegate(RuntimeOrigin::signed(1), 0, 2, Conviction::Locked1x, 5));
assert_ok!(Voting::delegate(RuntimeOrigin::signed(1), 1, 3, Conviction::Locked1x, 5));
assert_ok!(Voting::delegate(RuntimeOrigin::signed(1), 2, 4, Conviction::Locked1x, 5));
assert_eq!(Balances::usable_balance(1), 5);
assert_ok!(Voting::vote(Origin::signed(2), 0, aye(10, 0)));
assert_ok!(Voting::vote(Origin::signed(2), 1, nay(10, 0)));
assert_ok!(Voting::vote(Origin::signed(2), 2, nay(10, 0)));
assert_ok!(Voting::vote(Origin::signed(3), 0, nay(10, 0)));
assert_ok!(Voting::vote(Origin::signed(3), 1, aye(10, 0)));
assert_ok!(Voting::vote(Origin::signed(3), 2, nay(10, 0)));
assert_ok!(Voting::vote(Origin::signed(4), 0, nay(10, 0)));
assert_ok!(Voting::vote(Origin::signed(4), 1, nay(10, 0)));
assert_ok!(Voting::vote(Origin::signed(4), 2, aye(10, 0)));
assert_ok!(Voting::vote(RuntimeOrigin::signed(2), 0, aye(10, 0)));
assert_ok!(Voting::vote(RuntimeOrigin::signed(2), 1, nay(10, 0)));
assert_ok!(Voting::vote(RuntimeOrigin::signed(2), 2, nay(10, 0)));
assert_ok!(Voting::vote(RuntimeOrigin::signed(3), 0, nay(10, 0)));
assert_ok!(Voting::vote(RuntimeOrigin::signed(3), 1, aye(10, 0)));
assert_ok!(Voting::vote(RuntimeOrigin::signed(3), 2, nay(10, 0)));
assert_ok!(Voting::vote(RuntimeOrigin::signed(4), 0, nay(10, 0)));
assert_ok!(Voting::vote(RuntimeOrigin::signed(4), 1, nay(10, 0)));
assert_ok!(Voting::vote(RuntimeOrigin::signed(4), 2, aye(10, 0)));
// 4 hasn't voted yet
assert_eq!(
@@ -414,7 +414,7 @@ fn classwise_delegation_works() {
);
// 4 votes nay to 3.
assert_ok!(Voting::vote(Origin::signed(4), 3, nay(10, 0)));
assert_ok!(Voting::vote(RuntimeOrigin::signed(4), 3, nay(10, 0)));
assert_eq!(
Polls::get(),
vec![
@@ -428,8 +428,8 @@ fn classwise_delegation_works() {
);
// Redelegate for class 2 to account 3.
assert_ok!(Voting::undelegate(Origin::signed(1), 2));
assert_ok!(Voting::delegate(Origin::signed(1), 2, 3, Conviction::Locked1x, 5));
assert_ok!(Voting::undelegate(RuntimeOrigin::signed(1), 2));
assert_ok!(Voting::delegate(RuntimeOrigin::signed(1), 2, 3, Conviction::Locked1x, 5));
assert_eq!(
Polls::get(),
vec![
@@ -443,12 +443,12 @@ fn classwise_delegation_works() {
);
// Redelegating with a lower lock does not forget previous lock and updates correctly.
assert_ok!(Voting::undelegate(Origin::signed(1), 0));
assert_ok!(Voting::undelegate(Origin::signed(1), 1));
assert_ok!(Voting::undelegate(Origin::signed(1), 2));
assert_ok!(Voting::delegate(Origin::signed(1), 0, 2, Conviction::Locked1x, 3));
assert_ok!(Voting::delegate(Origin::signed(1), 1, 3, Conviction::Locked1x, 3));
assert_ok!(Voting::delegate(Origin::signed(1), 2, 4, Conviction::Locked1x, 3));
assert_ok!(Voting::undelegate(RuntimeOrigin::signed(1), 0));
assert_ok!(Voting::undelegate(RuntimeOrigin::signed(1), 1));
assert_ok!(Voting::undelegate(RuntimeOrigin::signed(1), 2));
assert_ok!(Voting::delegate(RuntimeOrigin::signed(1), 0, 2, Conviction::Locked1x, 3));
assert_ok!(Voting::delegate(RuntimeOrigin::signed(1), 1, 3, Conviction::Locked1x, 3));
assert_ok!(Voting::delegate(RuntimeOrigin::signed(1), 2, 4, Conviction::Locked1x, 3));
assert_eq!(
Polls::get(),
vec![
@@ -462,24 +462,24 @@ fn classwise_delegation_works() {
);
assert_eq!(Balances::usable_balance(1), 5);
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
assert_ok!(Voting::unlock(Origin::signed(1), 1, 1));
assert_ok!(Voting::unlock(Origin::signed(1), 2, 1));
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 1, 1));
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 2, 1));
// unlock does nothing since the delegation already took place.
assert_eq!(Balances::usable_balance(1), 5);
// Redelegating with higher amount extends previous lock.
assert_ok!(Voting::undelegate(Origin::signed(1), 0));
assert_ok!(Voting::delegate(Origin::signed(1), 0, 2, Conviction::Locked1x, 6));
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
assert_ok!(Voting::undelegate(RuntimeOrigin::signed(1), 0));
assert_ok!(Voting::delegate(RuntimeOrigin::signed(1), 0, 2, Conviction::Locked1x, 6));
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
assert_eq!(Balances::usable_balance(1), 4);
assert_ok!(Voting::undelegate(Origin::signed(1), 1));
assert_ok!(Voting::delegate(Origin::signed(1), 1, 3, Conviction::Locked1x, 7));
assert_ok!(Voting::unlock(Origin::signed(1), 1, 1));
assert_ok!(Voting::undelegate(RuntimeOrigin::signed(1), 1));
assert_ok!(Voting::delegate(RuntimeOrigin::signed(1), 1, 3, Conviction::Locked1x, 7));
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 1, 1));
assert_eq!(Balances::usable_balance(1), 3);
assert_ok!(Voting::undelegate(Origin::signed(1), 2));
assert_ok!(Voting::delegate(Origin::signed(1), 2, 4, Conviction::Locked1x, 8));
assert_ok!(Voting::unlock(Origin::signed(1), 2, 1));
assert_ok!(Voting::undelegate(RuntimeOrigin::signed(1), 2));
assert_ok!(Voting::delegate(RuntimeOrigin::signed(1), 2, 4, Conviction::Locked1x, 8));
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 2, 1));
assert_eq!(Balances::usable_balance(1), 2);
assert_eq!(
Polls::get(),
@@ -499,14 +499,14 @@ fn classwise_delegation_works() {
fn redelegation_after_vote_ending_should_keep_lock() {
new_test_ext().execute_with(|| {
Polls::set(vec![(0, Ongoing(Tally::new(0), 0))].into_iter().collect());
assert_ok!(Voting::delegate(Origin::signed(1), 0, 2, Conviction::Locked1x, 5));
assert_ok!(Voting::vote(Origin::signed(2), 0, aye(10, 1)));
assert_ok!(Voting::delegate(RuntimeOrigin::signed(1), 0, 2, Conviction::Locked1x, 5));
assert_ok!(Voting::vote(RuntimeOrigin::signed(2), 0, aye(10, 1)));
Polls::set(vec![(0, Completed(1, true))].into_iter().collect());
assert_eq!(Balances::usable_balance(1), 5);
assert_ok!(Voting::undelegate(Origin::signed(1), 0));
assert_ok!(Voting::delegate(Origin::signed(1), 0, 3, Conviction::Locked1x, 3));
assert_ok!(Voting::undelegate(RuntimeOrigin::signed(1), 0));
assert_ok!(Voting::delegate(RuntimeOrigin::signed(1), 0, 3, Conviction::Locked1x, 3));
assert_eq!(Balances::usable_balance(1), 5);
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
assert_eq!(Balances::usable_balance(1), 5);
});
}
@@ -523,9 +523,9 @@ fn lock_amalgamation_valid_with_multiple_removed_votes() {
.into_iter()
.collect(),
);
assert_ok!(Voting::vote(Origin::signed(1), 0, aye(5, 1)));
assert_ok!(Voting::vote(Origin::signed(1), 1, aye(10, 1)));
assert_ok!(Voting::vote(Origin::signed(1), 2, aye(5, 2)));
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 0, aye(5, 1)));
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 1, aye(10, 1)));
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 2, aye(5, 2)));
assert_eq!(Balances::usable_balance(1), 0);
Polls::set(
@@ -533,28 +533,28 @@ fn lock_amalgamation_valid_with_multiple_removed_votes() {
.into_iter()
.collect(),
);
assert_ok!(Voting::remove_vote(Origin::signed(1), Some(0), 0));
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
assert_ok!(Voting::remove_vote(RuntimeOrigin::signed(1), Some(0), 0));
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
assert_eq!(Balances::usable_balance(1), 0);
assert_ok!(Voting::remove_vote(Origin::signed(1), Some(0), 1));
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
assert_ok!(Voting::remove_vote(RuntimeOrigin::signed(1), Some(0), 1));
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
assert_eq!(Balances::usable_balance(1), 0);
assert_ok!(Voting::remove_vote(Origin::signed(1), Some(0), 2));
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
assert_ok!(Voting::remove_vote(RuntimeOrigin::signed(1), Some(0), 2));
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
assert_eq!(Balances::usable_balance(1), 0);
run_to(3);
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
assert_eq!(Balances::usable_balance(1), 0);
run_to(6);
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
assert!(Balances::usable_balance(1) <= 5);
run_to(7);
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
assert_eq!(Balances::usable_balance(1), 10);
});
}
@@ -562,25 +562,25 @@ fn lock_amalgamation_valid_with_multiple_removed_votes() {
#[test]
fn lock_amalgamation_valid_with_multiple_delegations() {
new_test_ext().execute_with(|| {
assert_ok!(Voting::delegate(Origin::signed(1), 0, 2, Conviction::Locked1x, 5));
assert_ok!(Voting::undelegate(Origin::signed(1), 0));
assert_ok!(Voting::delegate(Origin::signed(1), 0, 2, Conviction::Locked1x, 10));
assert_ok!(Voting::undelegate(Origin::signed(1), 0));
assert_ok!(Voting::delegate(Origin::signed(1), 0, 2, Conviction::Locked2x, 5));
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
assert_ok!(Voting::delegate(RuntimeOrigin::signed(1), 0, 2, Conviction::Locked1x, 5));
assert_ok!(Voting::undelegate(RuntimeOrigin::signed(1), 0));
assert_ok!(Voting::delegate(RuntimeOrigin::signed(1), 0, 2, Conviction::Locked1x, 10));
assert_ok!(Voting::undelegate(RuntimeOrigin::signed(1), 0));
assert_ok!(Voting::delegate(RuntimeOrigin::signed(1), 0, 2, Conviction::Locked2x, 5));
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
assert_eq!(Balances::usable_balance(1), 0);
assert_ok!(Voting::undelegate(Origin::signed(1), 0));
assert_ok!(Voting::undelegate(RuntimeOrigin::signed(1), 0));
run_to(3);
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
assert_eq!(Balances::usable_balance(1), 0);
run_to(6);
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
assert!(Balances::usable_balance(1) <= 5);
run_to(7);
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
assert_eq!(Balances::usable_balance(1), 10);
});
}
@@ -589,32 +589,32 @@ fn lock_amalgamation_valid_with_multiple_delegations() {
fn lock_amalgamation_valid_with_move_roundtrip_to_delegation() {
new_test_ext().execute_with(|| {
Polls::set(vec![(0, Ongoing(Tally::new(0), 0))].into_iter().collect());
assert_ok!(Voting::vote(Origin::signed(1), 0, aye(5, 1)));
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 0, aye(5, 1)));
Polls::set(vec![(0, Completed(1, true))].into_iter().collect());
assert_ok!(Voting::remove_vote(Origin::signed(1), Some(0), 0));
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
assert_ok!(Voting::remove_vote(RuntimeOrigin::signed(1), Some(0), 0));
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
assert_eq!(Balances::usable_balance(1), 5);
assert_ok!(Voting::delegate(Origin::signed(1), 0, 2, Conviction::Locked1x, 10));
assert_ok!(Voting::undelegate(Origin::signed(1), 0));
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
assert_ok!(Voting::delegate(RuntimeOrigin::signed(1), 0, 2, Conviction::Locked1x, 10));
assert_ok!(Voting::undelegate(RuntimeOrigin::signed(1), 0));
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
assert_eq!(Balances::usable_balance(1), 0);
Polls::set(vec![(1, Ongoing(Tally::new(0), 0))].into_iter().collect());
assert_ok!(Voting::vote(Origin::signed(1), 1, aye(5, 2)));
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 1, aye(5, 2)));
Polls::set(vec![(1, Completed(1, true))].into_iter().collect());
assert_ok!(Voting::remove_vote(Origin::signed(1), Some(0), 1));
assert_ok!(Voting::remove_vote(RuntimeOrigin::signed(1), Some(0), 1));
run_to(3);
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
assert_eq!(Balances::usable_balance(1), 0);
run_to(6);
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
assert!(Balances::usable_balance(1) <= 5);
run_to(7);
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
assert_eq!(Balances::usable_balance(1), 10);
});
}
@@ -622,33 +622,33 @@ fn lock_amalgamation_valid_with_move_roundtrip_to_delegation() {
#[test]
fn lock_amalgamation_valid_with_move_roundtrip_to_casting() {
new_test_ext().execute_with(|| {
assert_ok!(Voting::delegate(Origin::signed(1), 0, 2, Conviction::Locked1x, 5));
assert_ok!(Voting::undelegate(Origin::signed(1), 0));
assert_ok!(Voting::delegate(RuntimeOrigin::signed(1), 0, 2, Conviction::Locked1x, 5));
assert_ok!(Voting::undelegate(RuntimeOrigin::signed(1), 0));
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
assert_eq!(Balances::usable_balance(1), 5);
Polls::set(vec![(0, Ongoing(Tally::new(0), 0))].into_iter().collect());
assert_ok!(Voting::vote(Origin::signed(1), 0, aye(10, 1)));
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 0, aye(10, 1)));
Polls::set(vec![(0, Completed(1, true))].into_iter().collect());
assert_ok!(Voting::remove_vote(Origin::signed(1), Some(0), 0));
assert_ok!(Voting::remove_vote(RuntimeOrigin::signed(1), Some(0), 0));
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
assert_eq!(Balances::usable_balance(1), 0);
assert_ok!(Voting::delegate(Origin::signed(1), 0, 2, Conviction::Locked2x, 10));
assert_ok!(Voting::undelegate(Origin::signed(1), 0));
assert_ok!(Voting::delegate(RuntimeOrigin::signed(1), 0, 2, Conviction::Locked2x, 10));
assert_ok!(Voting::undelegate(RuntimeOrigin::signed(1), 0));
run_to(3);
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
assert_eq!(Balances::usable_balance(1), 0);
run_to(6);
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
assert!(Balances::usable_balance(1) <= 5);
run_to(7);
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
assert_eq!(Balances::usable_balance(1), 10);
});
}
@@ -656,30 +656,30 @@ fn lock_amalgamation_valid_with_move_roundtrip_to_casting() {
#[test]
fn lock_aggregation_over_different_classes_with_delegation_works() {
new_test_ext().execute_with(|| {
assert_ok!(Voting::delegate(Origin::signed(1), 0, 2, Conviction::Locked1x, 5));
assert_ok!(Voting::delegate(Origin::signed(1), 1, 2, Conviction::Locked2x, 5));
assert_ok!(Voting::delegate(Origin::signed(1), 2, 2, Conviction::Locked1x, 10));
assert_ok!(Voting::delegate(RuntimeOrigin::signed(1), 0, 2, Conviction::Locked1x, 5));
assert_ok!(Voting::delegate(RuntimeOrigin::signed(1), 1, 2, Conviction::Locked2x, 5));
assert_ok!(Voting::delegate(RuntimeOrigin::signed(1), 2, 2, Conviction::Locked1x, 10));
assert_ok!(Voting::undelegate(Origin::signed(1), 0));
assert_ok!(Voting::undelegate(Origin::signed(1), 1));
assert_ok!(Voting::undelegate(Origin::signed(1), 2));
assert_ok!(Voting::undelegate(RuntimeOrigin::signed(1), 0));
assert_ok!(Voting::undelegate(RuntimeOrigin::signed(1), 1));
assert_ok!(Voting::undelegate(RuntimeOrigin::signed(1), 2));
run_to(3);
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
assert_ok!(Voting::unlock(Origin::signed(1), 1, 1));
assert_ok!(Voting::unlock(Origin::signed(1), 2, 1));
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 1, 1));
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 2, 1));
assert_eq!(Balances::usable_balance(1), 0);
run_to(6);
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
assert_ok!(Voting::unlock(Origin::signed(1), 1, 1));
assert_ok!(Voting::unlock(Origin::signed(1), 2, 1));
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 1, 1));
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 2, 1));
assert_eq!(Balances::usable_balance(1), 5);
run_to(7);
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
assert_ok!(Voting::unlock(Origin::signed(1), 1, 1));
assert_ok!(Voting::unlock(Origin::signed(1), 2, 1));
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 1, 1));
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 2, 1));
assert_eq!(Balances::usable_balance(1), 10);
});
}
@@ -696,34 +696,34 @@ fn lock_aggregation_over_different_classes_with_casting_works() {
.into_iter()
.collect(),
);
assert_ok!(Voting::vote(Origin::signed(1), 0, aye(5, 1)));
assert_ok!(Voting::vote(Origin::signed(1), 1, aye(10, 1)));
assert_ok!(Voting::vote(Origin::signed(1), 2, aye(5, 2)));
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 0, aye(5, 1)));
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 1, aye(10, 1)));
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 2, aye(5, 2)));
Polls::set(
vec![(0, Completed(1, true)), (1, Completed(1, true)), (2, Completed(1, true))]
.into_iter()
.collect(),
);
assert_ok!(Voting::remove_vote(Origin::signed(1), Some(0), 0));
assert_ok!(Voting::remove_vote(Origin::signed(1), Some(1), 1));
assert_ok!(Voting::remove_vote(Origin::signed(1), Some(2), 2));
assert_ok!(Voting::remove_vote(RuntimeOrigin::signed(1), Some(0), 0));
assert_ok!(Voting::remove_vote(RuntimeOrigin::signed(1), Some(1), 1));
assert_ok!(Voting::remove_vote(RuntimeOrigin::signed(1), Some(2), 2));
run_to(3);
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
assert_ok!(Voting::unlock(Origin::signed(1), 1, 1));
assert_ok!(Voting::unlock(Origin::signed(1), 2, 1));
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 1, 1));
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 2, 1));
assert_eq!(Balances::usable_balance(1), 0);
run_to(6);
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
assert_ok!(Voting::unlock(Origin::signed(1), 1, 1));
assert_ok!(Voting::unlock(Origin::signed(1), 2, 1));
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 1, 1));
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 2, 1));
assert_eq!(Balances::usable_balance(1), 5);
run_to(7);
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
assert_ok!(Voting::unlock(Origin::signed(1), 1, 1));
assert_ok!(Voting::unlock(Origin::signed(1), 2, 1));
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 1, 1));
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 2, 1));
assert_eq!(Balances::usable_balance(1), 10);
});
}
@@ -731,21 +731,30 @@ fn lock_aggregation_over_different_classes_with_casting_works() {
#[test]
fn errors_with_vote_work() {
new_test_ext().execute_with(|| {
assert_noop!(Voting::vote(Origin::signed(1), 0, aye(10, 0)), Error::<Test>::NotOngoing);
assert_noop!(Voting::vote(Origin::signed(1), 1, aye(10, 0)), Error::<Test>::NotOngoing);
assert_noop!(Voting::vote(Origin::signed(1), 2, aye(10, 0)), Error::<Test>::NotOngoing);
assert_noop!(
Voting::vote(Origin::signed(1), 3, aye(11, 0)),
Voting::vote(RuntimeOrigin::signed(1), 0, aye(10, 0)),
Error::<Test>::NotOngoing
);
assert_noop!(
Voting::vote(RuntimeOrigin::signed(1), 1, aye(10, 0)),
Error::<Test>::NotOngoing
);
assert_noop!(
Voting::vote(RuntimeOrigin::signed(1), 2, aye(10, 0)),
Error::<Test>::NotOngoing
);
assert_noop!(
Voting::vote(RuntimeOrigin::signed(1), 3, aye(11, 0)),
Error::<Test>::InsufficientFunds
);
assert_ok!(Voting::delegate(Origin::signed(1), 0, 2, Conviction::None, 10));
assert_ok!(Voting::delegate(RuntimeOrigin::signed(1), 0, 2, Conviction::None, 10));
assert_noop!(
Voting::vote(Origin::signed(1), 3, aye(10, 0)),
Voting::vote(RuntimeOrigin::signed(1), 3, aye(10, 0)),
Error::<Test>::AlreadyDelegating
);
assert_ok!(Voting::undelegate(Origin::signed(1), 0));
assert_ok!(Voting::undelegate(RuntimeOrigin::signed(1), 0));
Polls::set(
vec![
(0, Ongoing(Tally::new(0), 0)),
@@ -756,11 +765,11 @@ fn errors_with_vote_work() {
.into_iter()
.collect(),
);
assert_ok!(Voting::vote(Origin::signed(1), 0, aye(10, 0)));
assert_ok!(Voting::vote(Origin::signed(1), 1, aye(10, 0)));
assert_ok!(Voting::vote(Origin::signed(1), 2, aye(10, 0)));
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 0, aye(10, 0)));
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 1, aye(10, 0)));
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 2, aye(10, 0)));
assert_noop!(
Voting::vote(Origin::signed(1), 3, aye(10, 0)),
Voting::vote(RuntimeOrigin::signed(1), 3, aye(10, 0)),
Error::<Test>::MaxVotesReached
);
});
@@ -770,21 +779,21 @@ fn errors_with_vote_work() {
fn errors_with_delegating_work() {
new_test_ext().execute_with(|| {
assert_noop!(
Voting::delegate(Origin::signed(1), 0, 2, Conviction::None, 11),
Voting::delegate(RuntimeOrigin::signed(1), 0, 2, Conviction::None, 11),
Error::<Test>::InsufficientFunds
);
assert_noop!(
Voting::delegate(Origin::signed(1), 3, 2, Conviction::None, 10),
Voting::delegate(RuntimeOrigin::signed(1), 3, 2, Conviction::None, 10),
Error::<Test>::BadClass
);
assert_ok!(Voting::vote(Origin::signed(1), 3, aye(10, 0)));
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 3, aye(10, 0)));
assert_noop!(
Voting::delegate(Origin::signed(1), 0, 2, Conviction::None, 10),
Voting::delegate(RuntimeOrigin::signed(1), 0, 2, Conviction::None, 10),
Error::<Test>::AlreadyVoting
);
assert_noop!(Voting::undelegate(Origin::signed(1), 0), Error::<Test>::NotDelegating);
assert_noop!(Voting::undelegate(RuntimeOrigin::signed(1), 0), Error::<Test>::NotDelegating);
});
}
@@ -792,31 +801,37 @@ fn errors_with_delegating_work() {
fn remove_other_vote_works() {
new_test_ext().execute_with(|| {
assert_noop!(
Voting::remove_other_vote(Origin::signed(2), 1, 0, 3),
Voting::remove_other_vote(RuntimeOrigin::signed(2), 1, 0, 3),
Error::<Test>::NotVoter
);
assert_ok!(Voting::vote(Origin::signed(1), 3, aye(10, 2)));
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 3, aye(10, 2)));
assert_noop!(
Voting::remove_other_vote(Origin::signed(2), 1, 0, 3),
Voting::remove_other_vote(RuntimeOrigin::signed(2), 1, 0, 3),
Error::<Test>::NoPermission
);
Polls::set(vec![(3, Completed(1, true))].into_iter().collect());
run_to(6);
assert_noop!(
Voting::remove_other_vote(Origin::signed(2), 1, 0, 3),
Voting::remove_other_vote(RuntimeOrigin::signed(2), 1, 0, 3),
Error::<Test>::NoPermissionYet
);
run_to(7);
assert_ok!(Voting::remove_other_vote(Origin::signed(2), 1, 0, 3));
assert_ok!(Voting::remove_other_vote(RuntimeOrigin::signed(2), 1, 0, 3));
});
}
#[test]
fn errors_with_remove_vote_work() {
new_test_ext().execute_with(|| {
assert_noop!(Voting::remove_vote(Origin::signed(1), Some(0), 3), Error::<Test>::NotVoter);
assert_ok!(Voting::vote(Origin::signed(1), 3, aye(10, 2)));
assert_noop!(
Voting::remove_vote(RuntimeOrigin::signed(1), Some(0), 3),
Error::<Test>::NotVoter
);
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 3, aye(10, 2)));
Polls::set(vec![(3, Completed(1, true))].into_iter().collect());
assert_noop!(Voting::remove_vote(Origin::signed(1), None, 3), Error::<Test>::ClassNeeded);
assert_noop!(
Voting::remove_vote(RuntimeOrigin::signed(1), None, 3),
Error::<Test>::ClassNeeded
);
});
}