Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Fix incorrect use of syn::exports #7838

Merged
merged 5 commits into from
Jan 6, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 4 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client/chain-spec/derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ proc-macro = true
proc-macro-crate = "0.1.4"
proc-macro2 = "1.0.6"
quote = "1.0.3"
syn = "1.0.7"
syn = "1.0.58"

[dev-dependencies]
2 changes: 1 addition & 1 deletion client/cli/proc-macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ proc-macro = true
proc-macro-crate = "0.1.4"
proc-macro2 = "1.0.6"
quote = { version = "1.0.3", features = ["proc-macro"] }
syn = { version = "1.0.7", features = ["proc-macro", "full", "extra-traits", "parsing"] }
syn = { version = "1.0.58", features = ["proc-macro", "full", "extra-traits", "parsing"] }
2 changes: 1 addition & 1 deletion client/executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ hex-literal = "0.3.1"
sc-runtime-test = { version = "2.0.0", path = "runtime-test" }
substrate-test-runtime = { version = "2.0.0", path = "../../test-utils/runtime" }
sp-state-machine = { version = "0.8.0", path = "../../primitives/state-machine" }
test-case = "0.3.3"
sp-runtime = { version = "2.0.0", path = "../../primitives/runtime" }
sp-tracing = { version = "2.0.0", path = "../../primitives/tracing" }
sc-tracing = { version = "2.0.0", path = "../tracing" }
tracing = "0.1.22"
tracing-subscriber = "0.2.15"
paste = "0.1.6"

[features]
default = [ "std" ]
Expand Down
107 changes: 50 additions & 57 deletions client/executor/src/integration_tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use sp_core::{
};
use sc_runtime_test::wasm_binary_unwrap;
use sp_state_machine::TestExternalities as CoreTestExternalities;
use test_case::test_case;
use sp_trie::{TrieConfiguration, trie_types::Layout};
use sp_wasm_interface::HostFunctions as _;
use sp_runtime::traits::BlakeTwo256;
Expand All @@ -37,6 +36,25 @@ use crate::WasmExecutionMethod;
pub type TestExternalities = CoreTestExternalities<BlakeTwo256, u64>;
type HostFunctions = sp_io::SubstrateHostFunctions;

/// Simple macro that runs a given method as test with the available wasm execution methods.
#[macro_export]
macro_rules! test_wasm_execution {
($method_name:ident) => {
paste::item! {
#[test]
fn [<$method_name _interpreted>]() {
$method_name(WasmExecutionMethod::Interpreted);
}

#[test]
#[cfg(feature = "wasmtime")]
fn [<$method_name _compiled>]() {
$method_name(WasmExecutionMethod::Compiled);
}
}
};
}

fn call_in_wasm<E: Externalities>(
function: &str,
call_data: &[u8],
Expand All @@ -59,8 +77,7 @@ fn call_in_wasm<E: Externalities>(
)
}

#[test_case(WasmExecutionMethod::Interpreted)]
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
test_wasm_execution!(returning_should_work);
fn returning_should_work(wasm_method: WasmExecutionMethod) {
let mut ext = TestExternalities::default();
let mut ext = ext.ext();
Expand All @@ -74,8 +91,7 @@ fn returning_should_work(wasm_method: WasmExecutionMethod) {
assert_eq!(output, vec![0u8; 0]);
}

#[test_case(WasmExecutionMethod::Interpreted)]
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
test_wasm_execution!(call_not_existing_function);
fn call_not_existing_function(wasm_method: WasmExecutionMethod) {
let mut ext = TestExternalities::default();
let mut ext = ext.ext();
Expand All @@ -102,8 +118,7 @@ fn call_not_existing_function(wasm_method: WasmExecutionMethod) {
}
}

#[test_case(WasmExecutionMethod::Interpreted)]
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
test_wasm_execution!(call_yet_another_not_existing_function);
fn call_yet_another_not_existing_function(wasm_method: WasmExecutionMethod) {
let mut ext = TestExternalities::default();
let mut ext = ext.ext();
Expand All @@ -130,8 +145,7 @@ fn call_yet_another_not_existing_function(wasm_method: WasmExecutionMethod) {
}
}

#[test_case(WasmExecutionMethod::Interpreted)]
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
test_wasm_execution!(panicking_should_work);
fn panicking_should_work(wasm_method: WasmExecutionMethod) {
let mut ext = TestExternalities::default();
let mut ext = ext.ext();
Expand Down Expand Up @@ -161,8 +175,7 @@ fn panicking_should_work(wasm_method: WasmExecutionMethod) {
assert!(output.is_err());
}

#[test_case(WasmExecutionMethod::Interpreted)]
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
test_wasm_execution!(storage_should_work);
fn storage_should_work(wasm_method: WasmExecutionMethod) {
let mut ext = TestExternalities::default();

Expand Down Expand Up @@ -191,8 +204,7 @@ fn storage_should_work(wasm_method: WasmExecutionMethod) {
assert_eq!(ext, expected);
}

#[test_case(WasmExecutionMethod::Interpreted)]
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
test_wasm_execution!(clear_prefix_should_work);
fn clear_prefix_should_work(wasm_method: WasmExecutionMethod) {
let mut ext = TestExternalities::default();
{
Expand Down Expand Up @@ -225,8 +237,7 @@ fn clear_prefix_should_work(wasm_method: WasmExecutionMethod) {
assert_eq!(expected, ext);
}

#[test_case(WasmExecutionMethod::Interpreted)]
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
test_wasm_execution!(blake2_256_should_work);
fn blake2_256_should_work(wasm_method: WasmExecutionMethod) {
let mut ext = TestExternalities::default();
let mut ext = ext.ext();
Expand All @@ -250,8 +261,7 @@ fn blake2_256_should_work(wasm_method: WasmExecutionMethod) {
);
}

#[test_case(WasmExecutionMethod::Interpreted)]
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
test_wasm_execution!(blake2_128_should_work);
fn blake2_128_should_work(wasm_method: WasmExecutionMethod) {
let mut ext = TestExternalities::default();
let mut ext = ext.ext();
Expand All @@ -275,8 +285,7 @@ fn blake2_128_should_work(wasm_method: WasmExecutionMethod) {
);
}

#[test_case(WasmExecutionMethod::Interpreted)]
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
test_wasm_execution!(sha2_256_should_work);
fn sha2_256_should_work(wasm_method: WasmExecutionMethod) {
let mut ext = TestExternalities::default();
let mut ext = ext.ext();
Expand Down Expand Up @@ -306,8 +315,7 @@ fn sha2_256_should_work(wasm_method: WasmExecutionMethod) {
);
}

#[test_case(WasmExecutionMethod::Interpreted)]
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
test_wasm_execution!(twox_256_should_work);
fn twox_256_should_work(wasm_method: WasmExecutionMethod) {
let mut ext = TestExternalities::default();
let mut ext = ext.ext();
Expand Down Expand Up @@ -335,8 +343,7 @@ fn twox_256_should_work(wasm_method: WasmExecutionMethod) {
);
}

#[test_case(WasmExecutionMethod::Interpreted)]
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
test_wasm_execution!(twox_128_should_work);
fn twox_128_should_work(wasm_method: WasmExecutionMethod) {
let mut ext = TestExternalities::default();
let mut ext = ext.ext();
Expand All @@ -360,8 +367,7 @@ fn twox_128_should_work(wasm_method: WasmExecutionMethod) {
);
}

#[test_case(WasmExecutionMethod::Interpreted)]
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
test_wasm_execution!(ed25519_verify_should_work);
fn ed25519_verify_should_work(wasm_method: WasmExecutionMethod) {
let mut ext = TestExternalities::default();
let mut ext = ext.ext();
Expand Down Expand Up @@ -397,8 +403,7 @@ fn ed25519_verify_should_work(wasm_method: WasmExecutionMethod) {
);
}

#[test_case(WasmExecutionMethod::Interpreted)]
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
test_wasm_execution!(sr25519_verify_should_work);
fn sr25519_verify_should_work(wasm_method: WasmExecutionMethod) {
let mut ext = TestExternalities::default();
let mut ext = ext.ext();
Expand Down Expand Up @@ -434,8 +439,7 @@ fn sr25519_verify_should_work(wasm_method: WasmExecutionMethod) {
);
}

#[test_case(WasmExecutionMethod::Interpreted)]
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
test_wasm_execution!(ordered_trie_root_should_work);
fn ordered_trie_root_should_work(wasm_method: WasmExecutionMethod) {
let mut ext = TestExternalities::default();
let trie_input = vec![b"zero".to_vec(), b"one".to_vec(), b"two".to_vec()];
Expand All @@ -450,8 +454,7 @@ fn ordered_trie_root_should_work(wasm_method: WasmExecutionMethod) {
);
}

#[test_case(WasmExecutionMethod::Interpreted)]
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
test_wasm_execution!(offchain_index);
fn offchain_index(wasm_method: WasmExecutionMethod) {
let mut ext = TestExternalities::default();
let (offchain, _state) = testing::TestOffchainExt::new();
Expand All @@ -472,8 +475,7 @@ fn offchain_index(wasm_method: WasmExecutionMethod) {
);
}

#[test_case(WasmExecutionMethod::Interpreted)]
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
test_wasm_execution!(offchain_local_storage_should_work);
fn offchain_local_storage_should_work(wasm_method: WasmExecutionMethod) {
let mut ext = TestExternalities::default();
let (offchain, state) = testing::TestOffchainExt::new();
Expand All @@ -490,8 +492,7 @@ fn offchain_local_storage_should_work(wasm_method: WasmExecutionMethod) {
assert_eq!(state.read().persistent_storage.get(b"test"), Some(vec![]));
}

#[test_case(WasmExecutionMethod::Interpreted)]
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
test_wasm_execution!(offchain_http_should_work);
fn offchain_http_should_work(wasm_method: WasmExecutionMethod) {
let mut ext = TestExternalities::default();
let (offchain, state) = testing::TestOffchainExt::new();
Expand Down Expand Up @@ -519,9 +520,7 @@ fn offchain_http_should_work(wasm_method: WasmExecutionMethod) {
);
}

#[test_case(WasmExecutionMethod::Interpreted)]
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
#[should_panic(expected = "Allocator ran out of space")]
test_wasm_execution!(should_trap_when_heap_exhausted);
fn should_trap_when_heap_exhausted(wasm_method: WasmExecutionMethod) {
let mut ext = TestExternalities::default();

Expand All @@ -531,18 +530,20 @@ fn should_trap_when_heap_exhausted(wasm_method: WasmExecutionMethod) {
HostFunctions::host_functions(),
8,
);
executor.call_in_wasm(

let err = executor.call_in_wasm(
&wasm_binary_unwrap()[..],
None,
"test_exhaust_heap",
&[0],
&mut ext.ext(),
sp_core::traits::MissingHostFunctions::Allow,
).unwrap();
).unwrap_err();

assert!(err.contains("Allocator ran out of space"));
}

#[test_case(WasmExecutionMethod::Interpreted)]
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
test_wasm_execution!(returns_mutable_static);
fn returns_mutable_static(wasm_method: WasmExecutionMethod) {
let runtime = crate::wasm_runtime::create_wasm_runtime_with_code(
wasm_method,
Expand All @@ -567,8 +568,7 @@ fn returns_mutable_static(wasm_method: WasmExecutionMethod) {
// returned to its initial value and thus the stack space is going to be leaked.
//
// See https://github.com/paritytech/substrate/issues/2967 for details
#[test_case(WasmExecutionMethod::Interpreted)]
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
test_wasm_execution!(restoration_of_globals);
fn restoration_of_globals(wasm_method: WasmExecutionMethod) {
// Allocate 32 pages (of 65536 bytes) which gives the runtime 2048KB of heap to operate on
// (plus some additional space unused from the initial pages requested by the wasm runtime
Expand Down Expand Up @@ -596,7 +596,7 @@ fn restoration_of_globals(wasm_method: WasmExecutionMethod) {
assert!(res.is_ok());
}

#[test_case(WasmExecutionMethod::Interpreted)]
test_wasm_execution!(heap_is_reset_between_calls);
fn heap_is_reset_between_calls(wasm_method: WasmExecutionMethod) {
let runtime = crate::wasm_runtime::create_wasm_runtime_with_code(
wasm_method,
Expand All @@ -620,8 +620,7 @@ fn heap_is_reset_between_calls(wasm_method: WasmExecutionMethod) {
instance.call_export("check_and_set_in_heap", &params).unwrap();
}

#[test_case(WasmExecutionMethod::Interpreted)]
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
test_wasm_execution!(parallel_execution);
fn parallel_execution(wasm_method: WasmExecutionMethod) {
let executor = std::sync::Arc::new(crate::WasmExecutor::new(
wasm_method,
Expand Down Expand Up @@ -656,7 +655,7 @@ fn parallel_execution(wasm_method: WasmExecutionMethod) {
}
}

#[test_case(WasmExecutionMethod::Interpreted)]
test_wasm_execution!(wasm_tracing_should_work);
fn wasm_tracing_should_work(wasm_method: WasmExecutionMethod) {

use std::sync::{Arc, Mutex};
Expand Down Expand Up @@ -728,10 +727,8 @@ fn wasm_tracing_should_work(wasm_method: WasmExecutionMethod) {
assert_eq!(len, 2);
}

#[test_case(WasmExecutionMethod::Interpreted)]
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
test_wasm_execution!(spawning_runtime_instance_should_work);
fn spawning_runtime_instance_should_work(wasm_method: WasmExecutionMethod) {

let mut ext = TestExternalities::default();
let mut ext = ext.ext();

Expand All @@ -743,10 +740,8 @@ fn spawning_runtime_instance_should_work(wasm_method: WasmExecutionMethod) {
).unwrap();
}

#[test_case(WasmExecutionMethod::Interpreted)]
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
test_wasm_execution!(spawning_runtime_instance_nested_should_work);
fn spawning_runtime_instance_nested_should_work(wasm_method: WasmExecutionMethod) {

let mut ext = TestExternalities::default();
let mut ext = ext.ext();

Expand All @@ -758,10 +753,8 @@ fn spawning_runtime_instance_nested_should_work(wasm_method: WasmExecutionMethod
).unwrap();
}

#[test_case(WasmExecutionMethod::Interpreted)]
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
test_wasm_execution!(panic_in_spawned_instance_panics_on_joining_its_result);
fn panic_in_spawned_instance_panics_on_joining_its_result(wasm_method: WasmExecutionMethod) {

let mut ext = TestExternalities::default();
let mut ext = ext.ext();

Expand Down
Loading