mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-09 20:11:09 +00:00
Test compiled wasm code in test-runtime (#1364)
* Test compiled wasm code in test-runtime * Drop lazy_static * Move substrate-executor to dev-dependencies
This commit is contained in:
Generated
+1
@@ -3859,6 +3859,7 @@ dependencies = [
|
||||
"srml-support 0.1.0",
|
||||
"substrate-client 0.1.0",
|
||||
"substrate-consensus-aura-primitives 0.1.0",
|
||||
"substrate-executor 0.1.0",
|
||||
"substrate-keyring 0.1.0",
|
||||
"substrate-primitives 0.1.0",
|
||||
]
|
||||
|
||||
@@ -20,6 +20,9 @@ sr-primitives = { path = "../sr-primitives", default-features = false }
|
||||
sr-version = { path = "../sr-version", default-features = false }
|
||||
srml-support = { path = "../../srml/support", default-features = false }
|
||||
|
||||
[dev-dependencies]
|
||||
substrate-executor = { path = "../executor" }
|
||||
|
||||
[features]
|
||||
default = ["std"]
|
||||
std = [
|
||||
|
||||
@@ -45,6 +45,8 @@ extern crate substrate_keyring as keyring;
|
||||
#[cfg_attr(any(feature = "std", test), macro_use)]
|
||||
extern crate substrate_primitives as primitives;
|
||||
|
||||
#[cfg(test)] extern crate substrate_executor;
|
||||
|
||||
#[cfg(feature = "std")] pub mod genesismap;
|
||||
pub mod system;
|
||||
|
||||
|
||||
@@ -248,6 +248,10 @@ mod tests {
|
||||
use ::{Header, Digest, Extrinsic, Transfer};
|
||||
use primitives::{Blake2Hasher};
|
||||
use primitives::storage::well_known_keys;
|
||||
use substrate_executor::WasmExecutor;
|
||||
|
||||
const WASM_CODE: &'static [u8] =
|
||||
include_bytes!("../wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm");
|
||||
|
||||
fn new_test_ext() -> TestExternalities<Blake2Hasher> {
|
||||
TestExternalities::new(map![
|
||||
@@ -265,8 +269,7 @@ mod tests {
|
||||
Extrinsic { transfer: tx, signature }
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn block_import_works() {
|
||||
fn block_import_works<F>(block_executor: F) where F: Fn(Block, &mut TestExternalities<Blake2Hasher>) {
|
||||
let mut t = new_test_ext();
|
||||
|
||||
let h = Header {
|
||||
@@ -282,13 +285,27 @@ mod tests {
|
||||
extrinsics: vec![],
|
||||
};
|
||||
|
||||
with_externalities(&mut t, || {
|
||||
execute_block(b);
|
||||
block_executor(b, &mut t);
|
||||
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn block_import_works_native() {
|
||||
block_import_works(|b, ext| {
|
||||
with_externalities(ext, || {
|
||||
execute_block(b);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn block_import_with_transaction_works() {
|
||||
fn block_import_works_wasm() {
|
||||
block_import_works(|b, ext| {
|
||||
WasmExecutor::new().call(ext, 8, &WASM_CODE, "Core_execute_block", &b.encode()).unwrap();
|
||||
})
|
||||
}
|
||||
|
||||
fn block_import_with_transaction_works<F>(block_executor: F) where F: Fn(Block, &mut TestExternalities<Blake2Hasher>) {
|
||||
let mut t = new_test_ext();
|
||||
|
||||
with_externalities(&mut t, || {
|
||||
@@ -345,12 +362,29 @@ mod tests {
|
||||
],
|
||||
};
|
||||
|
||||
block_executor(b, &mut t);
|
||||
|
||||
with_externalities(&mut t, || {
|
||||
execute_block(b);
|
||||
|
||||
assert_eq!(balance_of(Keyring::Alice.to_raw_public().into()), 0);
|
||||
assert_eq!(balance_of(Keyring::Bob.to_raw_public().into()), 42);
|
||||
assert_eq!(balance_of(Keyring::Charlie.to_raw_public().into()), 69);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn block_import_with_transaction_works_native() {
|
||||
block_import_with_transaction_works(|b, ext| {
|
||||
with_externalities(ext, || {
|
||||
execute_block(b);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn block_import_with_transaction_works_wasm() {
|
||||
block_import_with_transaction_works(|b, ext| {
|
||||
WasmExecutor::new().call(ext, 8, &WASM_CODE, "Core_execute_block", &b.encode()).unwrap();
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
BIN
Binary file not shown.
Generated
+1
-1
@@ -1059,7 +1059,7 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sr-sandbox"
|
||||
name = "sr-"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
||||
Reference in New Issue
Block a user