mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-21 23:51:01 +00:00
Move Externalities into its own crate (#3775)
* Move `Externalities` into `substrate-externalities` - `Externalities` now support generic extensions - Split of `primtives-storage` for storage primitive types * Move the externalities scoping into `substrate-externalities` * Fix compilation * Review feedback * Adds macro for declaring extensions * Fix benchmarks * Introduce `ExtensionStore` trait * Last review comments * Implement it for `ExtensionStore`
This commit is contained in:
@@ -20,7 +20,7 @@ use super::*;
|
||||
|
||||
use std::cell::RefCell;
|
||||
use support::{impl_outer_origin, parameter_types};
|
||||
use primitives::{H256, Blake2Hasher};
|
||||
use primitives::H256;
|
||||
// The testing primitives are very useful for avoiding having to work with signatures
|
||||
// or public keys. `u64` is used as the `AccountId` and no `Signature`s are requried.
|
||||
use sr_primitives::{
|
||||
@@ -132,7 +132,7 @@ impl Trait for Test {
|
||||
|
||||
// This function basically just builds a genesis storage key/value store according to
|
||||
// our desired mockup.
|
||||
pub fn new_test_ext() -> runtime_io::TestExternalities<Blake2Hasher> {
|
||||
pub fn new_test_ext() -> runtime_io::TestExternalities {
|
||||
let mut t = system::GenesisConfig::default().build_storage::<Test>().unwrap();
|
||||
// We use default for brevity, but you can configure as desired if needed.
|
||||
balances::GenesisConfig::<Test> {
|
||||
|
||||
@@ -20,8 +20,7 @@ use super::*;
|
||||
use mock::*;
|
||||
|
||||
use support::{assert_ok, assert_noop};
|
||||
use runtime_io::with_externalities;
|
||||
use sr_primitives::traits::OnInitialize;
|
||||
use sr_primitives::{set_and_run_with_externalities, traits::OnInitialize};
|
||||
|
||||
type ScoredPool = Module<Test>;
|
||||
type System = system::Module<Test>;
|
||||
@@ -32,7 +31,7 @@ const INDEX_ERR: &str = "index does not match requested account";
|
||||
|
||||
#[test]
|
||||
fn query_membership_works() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
assert_eq!(ScoredPool::members(), vec![20, 40]);
|
||||
assert_eq!(Balances::reserved_balance(&31), CandidateDeposit::get());
|
||||
assert_eq!(Balances::reserved_balance(&40), CandidateDeposit::get());
|
||||
@@ -42,7 +41,7 @@ fn query_membership_works() {
|
||||
|
||||
#[test]
|
||||
fn submit_candidacy_must_not_work() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
assert_noop!(
|
||||
ScoredPool::submit_candidacy(Origin::signed(99)),
|
||||
"balance too low to submit candidacy"
|
||||
@@ -56,7 +55,7 @@ fn submit_candidacy_must_not_work() {
|
||||
|
||||
#[test]
|
||||
fn submit_candidacy_works() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
// given
|
||||
let who = 15;
|
||||
|
||||
@@ -71,7 +70,7 @@ fn submit_candidacy_works() {
|
||||
|
||||
#[test]
|
||||
fn scoring_works() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
// given
|
||||
let who = 15;
|
||||
let score = 99;
|
||||
@@ -89,7 +88,7 @@ fn scoring_works() {
|
||||
|
||||
#[test]
|
||||
fn scoring_same_element_with_same_score_works() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
// given
|
||||
let who = 31;
|
||||
let index = find_in_pool(who).expect("entity must be in pool") as u32;
|
||||
@@ -109,7 +108,7 @@ fn scoring_same_element_with_same_score_works() {
|
||||
|
||||
#[test]
|
||||
fn kicking_works_only_for_authorized() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
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");
|
||||
@@ -118,7 +117,7 @@ fn kicking_works_only_for_authorized() {
|
||||
|
||||
#[test]
|
||||
fn kicking_works() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
// given
|
||||
let who = 40;
|
||||
assert_eq!(Balances::reserved_balance(&who), CandidateDeposit::get());
|
||||
@@ -138,7 +137,7 @@ fn kicking_works() {
|
||||
|
||||
#[test]
|
||||
fn unscored_entities_must_not_be_used_for_filling_members() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
// given
|
||||
// we submit a candidacy, score will be `None`
|
||||
assert_ok!(ScoredPool::submit_candidacy(Origin::signed(15)));
|
||||
@@ -163,7 +162,7 @@ fn unscored_entities_must_not_be_used_for_filling_members() {
|
||||
|
||||
#[test]
|
||||
fn refreshing_works() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
// given
|
||||
let who = 15;
|
||||
assert_ok!(ScoredPool::submit_candidacy(Origin::signed(who)));
|
||||
@@ -181,7 +180,7 @@ fn refreshing_works() {
|
||||
|
||||
#[test]
|
||||
fn refreshing_happens_every_period() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
// given
|
||||
System::set_block_number(1);
|
||||
assert_ok!(ScoredPool::submit_candidacy(Origin::signed(15)));
|
||||
@@ -201,7 +200,7 @@ fn refreshing_happens_every_period() {
|
||||
|
||||
#[test]
|
||||
fn withdraw_candidacy_must_only_work_for_members() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
let who = 77;
|
||||
let index = 0;
|
||||
assert_noop!( ScoredPool::withdraw_candidacy(Origin::signed(who), index), INDEX_ERR);
|
||||
@@ -210,7 +209,7 @@ fn withdraw_candidacy_must_only_work_for_members() {
|
||||
|
||||
#[test]
|
||||
fn oob_index_should_abort() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
let who = 40;
|
||||
let oob_index = ScoredPool::pool().len() as u32;
|
||||
assert_noop!(ScoredPool::withdraw_candidacy(Origin::signed(who), oob_index), OOB_ERR);
|
||||
@@ -221,7 +220,7 @@ fn oob_index_should_abort() {
|
||||
|
||||
#[test]
|
||||
fn index_mismatches_should_abort() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
let who = 40;
|
||||
let index = 3;
|
||||
assert_noop!(ScoredPool::withdraw_candidacy(Origin::signed(who), index), INDEX_ERR);
|
||||
@@ -232,7 +231,7 @@ fn index_mismatches_should_abort() {
|
||||
|
||||
#[test]
|
||||
fn withdraw_unscored_candidacy_must_work() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
// given
|
||||
let who = 5;
|
||||
|
||||
@@ -247,7 +246,7 @@ fn withdraw_unscored_candidacy_must_work() {
|
||||
|
||||
#[test]
|
||||
fn withdraw_scored_candidacy_must_work() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
// given
|
||||
let who = 40;
|
||||
assert_eq!(Balances::reserved_balance(&who), CandidateDeposit::get());
|
||||
@@ -265,7 +264,7 @@ fn withdraw_scored_candidacy_must_work() {
|
||||
|
||||
#[test]
|
||||
fn candidacy_resubmitting_works() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
// given
|
||||
let who = 15;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user