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
+2 -2
View File
@@ -28,7 +28,7 @@ use sr_staking_primitives::{
};
use sr_primitives::testing::Header;
use sr_primitives::traits::{IdentityLookup, BlakeTwo256};
use substrate_primitives::{H256, Blake2Hasher};
use substrate_primitives::H256;
use support::{impl_outer_origin, impl_outer_event, parameter_types, StorageMap, StorageDoubleMap};
use {runtime_io, system};
@@ -103,7 +103,7 @@ impl_outer_event! {
}
}
pub fn new_test_ext() -> runtime_io::TestExternalities<Blake2Hasher> {
pub fn new_test_ext() -> runtime_io::TestExternalities {
let t = system::GenesisConfig::default().build_storage::<Runtime>().unwrap();
t.into()
}
+8 -8
View File
@@ -24,11 +24,11 @@ use crate::mock::{
offence_reports,
};
use system::{EventRecord, Phase};
use runtime_io::with_externalities;
use sr_primitives::set_and_run_with_externalities;
#[test]
fn should_report_an_authority_and_trigger_on_offence() {
with_externalities(&mut new_test_ext(), || {
set_and_run_with_externalities(&mut new_test_ext(), || {
// given
let time_slot = 42;
assert_eq!(offence_reports(KIND, time_slot), vec![]);
@@ -51,7 +51,7 @@ fn should_report_an_authority_and_trigger_on_offence() {
#[test]
fn should_calculate_the_fraction_correctly() {
with_externalities(&mut new_test_ext(), || {
set_and_run_with_externalities(&mut new_test_ext(), || {
// given
let time_slot = 42;
assert_eq!(offence_reports(KIND, time_slot), vec![]);
@@ -83,7 +83,7 @@ fn should_calculate_the_fraction_correctly() {
#[test]
fn should_not_report_the_same_authority_twice_in_the_same_slot() {
with_externalities(&mut new_test_ext(), || {
set_and_run_with_externalities(&mut new_test_ext(), || {
// given
let time_slot = 42;
assert_eq!(offence_reports(KIND, time_slot), vec![]);
@@ -113,7 +113,7 @@ fn should_not_report_the_same_authority_twice_in_the_same_slot() {
#[test]
fn should_report_in_different_time_slot() {
with_externalities(&mut new_test_ext(), || {
set_and_run_with_externalities(&mut new_test_ext(), || {
// given
let time_slot = 42;
assert_eq!(offence_reports(KIND, time_slot), vec![]);
@@ -143,7 +143,7 @@ fn should_report_in_different_time_slot() {
#[test]
fn should_deposit_event() {
with_externalities(&mut new_test_ext(), || {
set_and_run_with_externalities(&mut new_test_ext(), || {
// given
let time_slot = 42;
assert_eq!(offence_reports(KIND, time_slot), vec![]);
@@ -171,7 +171,7 @@ fn should_deposit_event() {
#[test]
fn doesnt_deposit_event_for_dups() {
with_externalities(&mut new_test_ext(), || {
set_and_run_with_externalities(&mut new_test_ext(), || {
// given
let time_slot = 42;
assert_eq!(offence_reports(KIND, time_slot), vec![]);
@@ -208,7 +208,7 @@ fn doesnt_deposit_event_for_dups() {
fn should_properly_count_offences() {
// We report two different authorities for the same issue. Ultimately, the 1st authority
// should have `count` equal 2 and the count of the 2nd one should be equal to 1.
with_externalities(&mut new_test_ext(), || {
set_and_run_with_externalities(&mut new_test_ext(), || {
// given
let time_slot = 42;
assert_eq!(offence_reports(KIND, time_slot), vec![]);