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:
Bastian Köcher
2019-10-09 15:50:30 +02:00
committed by GitHub
parent 984c6ac839
commit 8a39be474e
95 changed files with 1600 additions and 1420 deletions
+5 -7
View File
@@ -23,11 +23,9 @@ use support::{
StorageValue, StorageMap, parameter_types, assert_ok,
traits::{Get, ChangeMembers, Currency}
};
use runtime_io::with_externalities;
use primitives::{H256, Blake2Hasher};
use primitives::H256;
use sr_primitives::{
Perbill, BuildStorage,
testing::Header,
Perbill, BuildStorage, set_and_run_with_externalities, testing::Header,
traits::{BlakeTwo256, IdentityLookup, Block as BlockT},
};
use crate as elections;
@@ -213,7 +211,7 @@ impl ExtBuilder {
self.desired_seats = seats;
self
}
pub fn build(self) -> runtime_io::TestExternalities<Blake2Hasher> {
pub fn build(self) -> runtime_io::TestExternalities {
VOTER_BOND.with(|v| *v.borrow_mut() = self.voter_bond);
VOTING_FEE.with(|v| *v.borrow_mut() = self.voting_fee);
PRESENT_SLASH_PER_VOTER.with(|v| *v.borrow_mut() = self.bad_presentation_punishment);
@@ -283,9 +281,9 @@ pub(crate) fn locks(who: &u64) -> Vec<u64> {
Balances::locks(who).iter().map(|l| l.amount).collect::<Vec<u64>>()
}
pub(crate) fn new_test_ext_with_candidate_holes() -> runtime_io::TestExternalities<Blake2Hasher> {
pub(crate) fn new_test_ext_with_candidate_holes() -> runtime_io::TestExternalities {
let mut t = ExtBuilder::default().build();
with_externalities(&mut t, || {
set_and_run_with_externalities(&mut t, || {
<elections::Candidates<Test>>::put(vec![0, 0, 1]);
elections::CandidateCount::put(1);
<elections::RegisterInfoOf<Test>>::insert(1, (0, 2));