mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 04:01:10 +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:
@@ -236,13 +236,12 @@ pub use serde::{Serialize, Deserialize};
|
||||
mod tests {
|
||||
use super::*;
|
||||
use codec::{Codec, EncodeLike};
|
||||
use runtime_io::with_externalities;
|
||||
use primitives::Blake2Hasher;
|
||||
pub use srml_metadata::{
|
||||
use sr_primitives::set_and_run_with_externalities;
|
||||
use srml_metadata::{
|
||||
DecodeDifferent, StorageEntryMetadata, StorageMetadata, StorageEntryType,
|
||||
StorageEntryModifier, DefaultByte, DefaultByteGetter, StorageHasher
|
||||
StorageEntryModifier, DefaultByteGetter, StorageHasher,
|
||||
};
|
||||
pub use rstd::marker::PhantomData;
|
||||
use rstd::marker::PhantomData;
|
||||
|
||||
pub trait Trait {
|
||||
type BlockNumber: Codec + EncodeLike + Default;
|
||||
@@ -281,7 +280,7 @@ mod tests {
|
||||
type Origin = u32;
|
||||
}
|
||||
|
||||
fn new_test_ext() -> runtime_io::TestExternalities<Blake2Hasher> {
|
||||
fn new_test_ext() -> runtime_io::TestExternalities {
|
||||
GenesisConfig::default().build_storage().unwrap().into()
|
||||
}
|
||||
|
||||
@@ -289,7 +288,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn linked_map_issue_3318() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
OptionLinkedMap::insert(1, 1);
|
||||
assert_eq!(OptionLinkedMap::get(1), Some(1));
|
||||
OptionLinkedMap::insert(1, 2);
|
||||
@@ -299,7 +298,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn linked_map_swap_works() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
OptionLinkedMap::insert(0, 0);
|
||||
OptionLinkedMap::insert(1, 1);
|
||||
OptionLinkedMap::insert(2, 2);
|
||||
@@ -328,7 +327,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn linked_map_basic_insert_remove_should_work() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
// initialized during genesis
|
||||
assert_eq!(Map::get(&15u32), 42u64);
|
||||
|
||||
@@ -354,7 +353,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn linked_map_enumeration_and_head_should_work() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
assert_eq!(Map::head(), Some(15));
|
||||
assert_eq!(Map::enumerate().collect::<Vec<_>>(), vec![(15, 42)]);
|
||||
// insert / remove
|
||||
@@ -406,7 +405,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn double_map_basic_insert_remove_remove_prefix_should_work() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
type DoubleMap = DataDM;
|
||||
// initialized during genesis
|
||||
assert_eq!(DoubleMap::get(&15u32, &16u32), 42u64);
|
||||
@@ -446,7 +445,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn double_map_append_should_work() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
type DoubleMap = AppendableDM<Test>;
|
||||
|
||||
let key1 = 17u32;
|
||||
|
||||
@@ -758,8 +758,8 @@ mod test3 {
|
||||
#[cfg(test)]
|
||||
#[allow(dead_code)]
|
||||
mod test_append_and_len {
|
||||
use crate::storage::{StorageValue};
|
||||
use runtime_io::{with_externalities, TestExternalities};
|
||||
use runtime_io::TestExternalities;
|
||||
use sr_primitives::set_and_run_with_externalities;
|
||||
use codec::{Encode, Decode};
|
||||
|
||||
pub trait Trait {
|
||||
@@ -801,7 +801,7 @@ mod test_append_and_len {
|
||||
|
||||
#[test]
|
||||
fn default_for_option() {
|
||||
with_externalities(&mut TestExternalities::default(), || {
|
||||
set_and_run_with_externalities(&mut TestExternalities::default(), || {
|
||||
assert_eq!(OptionVec::get(), None);
|
||||
assert_eq!(JustVec::get(), vec![]);
|
||||
});
|
||||
@@ -809,7 +809,7 @@ mod test_append_and_len {
|
||||
|
||||
#[test]
|
||||
fn append_works() {
|
||||
with_externalities(&mut TestExternalities::default(), || {
|
||||
set_and_run_with_externalities(&mut TestExternalities::default(), || {
|
||||
let _ = MapVec::append(1, [1, 2, 3].iter());
|
||||
let _ = MapVec::append(1, [4, 5].iter());
|
||||
assert_eq!(MapVec::get(1), vec![1, 2, 3, 4, 5]);
|
||||
@@ -822,7 +822,7 @@ mod test_append_and_len {
|
||||
|
||||
#[test]
|
||||
fn append_works_for_default() {
|
||||
with_externalities(&mut TestExternalities::default(), || {
|
||||
set_and_run_with_externalities(&mut TestExternalities::default(), || {
|
||||
assert_eq!(JustVecWithDefault::get(), vec![6, 9]);
|
||||
let _ = JustVecWithDefault::append([1].iter());
|
||||
assert_eq!(JustVecWithDefault::get(), vec![6, 9, 1]);
|
||||
@@ -839,7 +839,7 @@ mod test_append_and_len {
|
||||
|
||||
#[test]
|
||||
fn append_or_put_works() {
|
||||
with_externalities(&mut TestExternalities::default(), || {
|
||||
set_and_run_with_externalities(&mut TestExternalities::default(), || {
|
||||
let _ = MapVec::append_or_insert(1, &[1, 2, 3][..]);
|
||||
let _ = MapVec::append_or_insert(1, &[4, 5][..]);
|
||||
assert_eq!(MapVec::get(1), vec![1, 2, 3, 4, 5]);
|
||||
@@ -856,7 +856,7 @@ mod test_append_and_len {
|
||||
|
||||
#[test]
|
||||
fn len_works() {
|
||||
with_externalities(&mut TestExternalities::default(), || {
|
||||
set_and_run_with_externalities(&mut TestExternalities::default(), || {
|
||||
JustVec::put(&vec![1, 2, 3, 4]);
|
||||
OptionVec::put(&vec![1, 2, 3, 4, 5]);
|
||||
MapVec::insert(1, &vec![1, 2, 3, 4, 5, 6]);
|
||||
@@ -871,7 +871,7 @@ mod test_append_and_len {
|
||||
|
||||
#[test]
|
||||
fn len_works_for_default() {
|
||||
with_externalities(&mut TestExternalities::default(), || {
|
||||
set_and_run_with_externalities(&mut TestExternalities::default(), || {
|
||||
// vec
|
||||
assert_eq!(JustVec::get(), vec![]);
|
||||
assert_eq!(JustVec::decode_len(), Ok(0));
|
||||
|
||||
@@ -10,6 +10,7 @@ codec = { package = "parity-scale-codec", version = "1.0.0", default-features =
|
||||
runtime-io ={ package = "sr-io", path = "../../../core/sr-io", default-features = false }
|
||||
support = { package = "srml-support", version = "2", path = "../", default-features = false }
|
||||
inherents = { package = "substrate-inherents", path = "../../../core/inherents", default-features = false }
|
||||
sr-primitives = { package = "sr-primitives", path = "../../../core/sr-primitives", default-features = false }
|
||||
primitives = { package = "substrate-primitives", path = "../../../core/primitives", default-features = false }
|
||||
trybuild = "1.0.14"
|
||||
pretty_assertions = "0.6.1"
|
||||
@@ -23,4 +24,5 @@ std = [
|
||||
"support/std",
|
||||
"inherents/std",
|
||||
"primitives/std",
|
||||
"sr-primitives/std",
|
||||
]
|
||||
|
||||
@@ -15,20 +15,22 @@
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
#![recursion_limit="128"]
|
||||
|
||||
use runtime_io::with_externalities;
|
||||
use sr_primitives::{
|
||||
generic, BuildStorage, traits::{BlakeTwo256, Block as _, Verify},
|
||||
set_and_run_with_externalities,
|
||||
};
|
||||
use support::{
|
||||
Parameter, traits::Get, parameter_types,
|
||||
sr_primitives::{generic, BuildStorage, traits::{BlakeTwo256, Block as _, Verify}},
|
||||
metadata::{
|
||||
DecodeDifferent, StorageMetadata, StorageEntryModifier, StorageEntryType, DefaultByteGetter,
|
||||
StorageEntryMetadata, StorageHasher
|
||||
StorageEntryMetadata, StorageHasher,
|
||||
},
|
||||
StorageValue, StorageMap, StorageLinkedMap, StorageDoubleMap,
|
||||
};
|
||||
use inherents::{
|
||||
ProvideInherent, InherentData, InherentIdentifier, RuntimeString, MakeFatalError
|
||||
};
|
||||
use primitives::{H256, sr25519, Blake2Hasher};
|
||||
use primitives::{H256, sr25519};
|
||||
|
||||
mod system;
|
||||
|
||||
@@ -275,7 +277,7 @@ pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
|
||||
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
|
||||
pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<u32, Call, Signature, ()>;
|
||||
|
||||
fn new_test_ext() -> runtime_io::TestExternalities<Blake2Hasher> {
|
||||
fn new_test_ext() -> runtime_io::TestExternalities {
|
||||
GenesisConfig{
|
||||
module1_Instance1: Some(module1::GenesisConfig {
|
||||
value: 3,
|
||||
@@ -329,7 +331,7 @@ fn storage_instance_independance() {
|
||||
|
||||
#[test]
|
||||
fn storage_with_instance_basic_operation() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
type Value = module2::Value<Runtime, module2::Instance1>;
|
||||
type Map = module2::Map<module2::Instance1>;
|
||||
type LinkedMap = module2::LinkedMap<module2::Instance1>;
|
||||
|
||||
Reference in New Issue
Block a user