Migrate membership, nicks, scored-pool and session to decl_error (#4463)

* Migrate membership, nicks, scored-pool and session to decl_error

* Fix tests

* Update frame/scored-pool/src/tests.rs

Co-Authored-By: Shawn Tabrizi <shawntabrizi@gmail.com>

* Remove InsufficientBalance error from scored-pool

* Replace Error::<Test, DefaultInstance> with Error::<Test, _>

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
Stanislav Tkach
2019-12-20 18:12:21 +02:00
committed by Shawn Tabrizi
parent 9950ea98fc
commit 328563f8d4
7 changed files with 115 additions and 81 deletions
+11 -14
View File
@@ -20,15 +20,12 @@ use super::*;
use mock::*;
use frame_support::{assert_ok, assert_noop};
use sp_runtime::traits::OnInitialize;
use sp_runtime::traits::{OnInitialize, BadOrigin};
type ScoredPool = Module<Test>;
type System = frame_system::Module<Test>;
type Balances = pallet_balances::Module<Test>;
const OOB_ERR: &str = "index out of bounds";
const INDEX_ERR: &str = "index does not match requested account";
#[test]
fn query_membership_works() {
new_test_ext().execute_with(|| {
@@ -44,11 +41,11 @@ fn submit_candidacy_must_not_work() {
new_test_ext().execute_with(|| {
assert_noop!(
ScoredPool::submit_candidacy(Origin::signed(99)),
"balance too low to submit candidacy"
"not enough free funds"
);
assert_noop!(
ScoredPool::submit_candidacy(Origin::signed(40)),
"already a member"
Error::<Test, _>::AlreadyInPool
);
});
}
@@ -111,7 +108,7 @@ fn kicking_works_only_for_authorized() {
new_test_ext().execute_with(|| {
let who = 40;
let index = find_in_pool(who).expect("entity must be in pool") as u32;
assert_noop!(ScoredPool::kick(Origin::signed(99), who, index), "bad origin");
assert_noop!(ScoredPool::kick(Origin::signed(99), who, index), BadOrigin);
});
}
@@ -203,7 +200,7 @@ fn withdraw_candidacy_must_only_work_for_members() {
new_test_ext().execute_with(|| {
let who = 77;
let index = 0;
assert_noop!( ScoredPool::withdraw_candidacy(Origin::signed(who), index), INDEX_ERR);
assert_noop!( ScoredPool::withdraw_candidacy(Origin::signed(who), index), Error::<Test, _>::WrongAccountIndex);
});
}
@@ -212,9 +209,9 @@ fn oob_index_should_abort() {
new_test_ext().execute_with(|| {
let who = 40;
let oob_index = ScoredPool::pool().len() as u32;
assert_noop!(ScoredPool::withdraw_candidacy(Origin::signed(who), oob_index), OOB_ERR);
assert_noop!(ScoredPool::score(Origin::signed(ScoreOrigin::get()), who, oob_index, 99), OOB_ERR);
assert_noop!(ScoredPool::kick(Origin::signed(KickOrigin::get()), who, oob_index), OOB_ERR);
assert_noop!(ScoredPool::withdraw_candidacy(Origin::signed(who), oob_index), Error::<Test, _>::InvalidIndex);
assert_noop!(ScoredPool::score(Origin::signed(ScoreOrigin::get()), who, oob_index, 99), Error::<Test, _>::InvalidIndex);
assert_noop!(ScoredPool::kick(Origin::signed(KickOrigin::get()), who, oob_index), Error::<Test, _>::InvalidIndex);
});
}
@@ -223,9 +220,9 @@ fn index_mismatches_should_abort() {
new_test_ext().execute_with(|| {
let who = 40;
let index = 3;
assert_noop!(ScoredPool::withdraw_candidacy(Origin::signed(who), index), INDEX_ERR);
assert_noop!(ScoredPool::score(Origin::signed(ScoreOrigin::get()), who, index, 99), INDEX_ERR);
assert_noop!(ScoredPool::kick(Origin::signed(KickOrigin::get()), who, index), INDEX_ERR);
assert_noop!(ScoredPool::withdraw_candidacy(Origin::signed(who), index), Error::<Test, _>::WrongAccountIndex);
assert_noop!(ScoredPool::score(Origin::signed(ScoreOrigin::get()), who, index, 99), Error::<Test, _>::WrongAccountIndex);
assert_noop!(ScoredPool::kick(Origin::signed(KickOrigin::get()), who, index), Error::<Test, _>::WrongAccountIndex);
});
}