mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-09 20:11:09 +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:
@@ -319,10 +319,11 @@ fn info_expect_equal_hash(given: &Hash, expected: &Hash) {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
use runtime_io::{with_externalities, TestExternalities};
|
||||
use runtime_io::TestExternalities;
|
||||
use substrate_test_runtime_client::{AccountKeyring, Sr25519Keyring};
|
||||
use sr_primitives::set_and_run_with_externalities;
|
||||
use crate::{Header, Transfer, WASM_BINARY};
|
||||
use primitives::{Blake2Hasher, NeverNativeValue, map, traits::CodeExecutor};
|
||||
use primitives::{NeverNativeValue, map, traits::CodeExecutor};
|
||||
use substrate_executor::{NativeExecutor, WasmExecutionMethod, native_executor_instance};
|
||||
|
||||
// Declare an instance of the native executor dispatch for the test runtime.
|
||||
@@ -336,7 +337,7 @@ mod tests {
|
||||
NativeExecutor::new(WasmExecutionMethod::Interpreted, None)
|
||||
}
|
||||
|
||||
fn new_test_ext() -> TestExternalities<Blake2Hasher> {
|
||||
fn new_test_ext() -> TestExternalities {
|
||||
let authorities = vec![
|
||||
Sr25519Keyring::Alice.to_raw_public(),
|
||||
Sr25519Keyring::Bob.to_raw_public(),
|
||||
@@ -357,7 +358,7 @@ mod tests {
|
||||
)
|
||||
}
|
||||
|
||||
fn block_import_works<F>(block_executor: F) where F: Fn(Block, &mut TestExternalities<Blake2Hasher>) {
|
||||
fn block_import_works<F>(block_executor: F) where F: Fn(Block, &mut TestExternalities) {
|
||||
let h = Header {
|
||||
parent_hash: [69u8; 32].into(),
|
||||
number: 1,
|
||||
@@ -370,7 +371,7 @@ mod tests {
|
||||
extrinsics: vec![],
|
||||
};
|
||||
|
||||
with_externalities(&mut new_test_ext(), || polish_block(&mut b));
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || polish_block(&mut b));
|
||||
|
||||
block_executor(b, &mut new_test_ext());
|
||||
}
|
||||
@@ -378,7 +379,7 @@ mod tests {
|
||||
#[test]
|
||||
fn block_import_works_native() {
|
||||
block_import_works(|b, ext| {
|
||||
with_externalities(ext, || {
|
||||
set_and_run_with_externalities(ext, || {
|
||||
execute_block(b);
|
||||
});
|
||||
});
|
||||
@@ -397,7 +398,9 @@ mod tests {
|
||||
})
|
||||
}
|
||||
|
||||
fn block_import_with_transaction_works<F>(block_executor: F) where F: Fn(Block, &mut TestExternalities<Blake2Hasher>) {
|
||||
fn block_import_with_transaction_works<F>(block_executor: F)
|
||||
where F: Fn(Block, &mut TestExternalities)
|
||||
{
|
||||
let mut b1 = Block {
|
||||
header: Header {
|
||||
parent_hash: [69u8; 32].into(),
|
||||
@@ -417,7 +420,7 @@ mod tests {
|
||||
};
|
||||
|
||||
let mut dummy_ext = new_test_ext();
|
||||
with_externalities(&mut dummy_ext, || polish_block(&mut b1));
|
||||
set_and_run_with_externalities(&mut dummy_ext, || polish_block(&mut b1));
|
||||
|
||||
let mut b2 = Block {
|
||||
header: Header {
|
||||
@@ -443,26 +446,26 @@ mod tests {
|
||||
],
|
||||
};
|
||||
|
||||
with_externalities(&mut dummy_ext, || polish_block(&mut b2));
|
||||
set_and_run_with_externalities(&mut dummy_ext, || polish_block(&mut b2));
|
||||
drop(dummy_ext);
|
||||
|
||||
let mut t = new_test_ext();
|
||||
|
||||
with_externalities(&mut t, || {
|
||||
set_and_run_with_externalities(&mut t, || {
|
||||
assert_eq!(balance_of(AccountKeyring::Alice.into()), 111);
|
||||
assert_eq!(balance_of(AccountKeyring::Bob.into()), 0);
|
||||
});
|
||||
|
||||
block_executor(b1, &mut t);
|
||||
|
||||
with_externalities(&mut t, || {
|
||||
set_and_run_with_externalities(&mut t, || {
|
||||
assert_eq!(balance_of(AccountKeyring::Alice.into()), 42);
|
||||
assert_eq!(balance_of(AccountKeyring::Bob.into()), 69);
|
||||
});
|
||||
|
||||
block_executor(b2, &mut t);
|
||||
|
||||
with_externalities(&mut t, || {
|
||||
set_and_run_with_externalities(&mut t, || {
|
||||
assert_eq!(balance_of(AccountKeyring::Alice.into()), 0);
|
||||
assert_eq!(balance_of(AccountKeyring::Bob.into()), 42);
|
||||
assert_eq!(balance_of(AccountKeyring::Charlie.into()), 69);
|
||||
@@ -472,7 +475,7 @@ mod tests {
|
||||
#[test]
|
||||
fn block_import_with_transaction_works_native() {
|
||||
block_import_with_transaction_works(|b, ext| {
|
||||
with_externalities(ext, || {
|
||||
set_and_run_with_externalities(ext, || {
|
||||
execute_block(b);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user