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

Commit b275035

Browse files
authored
Fix incorrect use of syn::exports (#7838)
* Fix incorrect use of syn::exports Instead of using `syn::exports` we should import the trait from the quote crate directly. * Use own macro for test cases to fix compilation with latest syn * Fix test
1 parent 698d80b commit b275035

File tree

16 files changed

+86
-107
lines changed

16 files changed

+86
-107
lines changed

Cargo.lock

+3-16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/chain-spec/derive/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ proc-macro = true
1818
proc-macro-crate = "0.1.4"
1919
proc-macro2 = "1.0.6"
2020
quote = "1.0.3"
21-
syn = "1.0.7"
21+
syn = "1.0.58"
2222

2323
[dev-dependencies]

client/cli/proc-macro/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ proc-macro = true
1818
proc-macro-crate = "0.1.4"
1919
proc-macro2 = "1.0.6"
2020
quote = { version = "1.0.3", features = ["proc-macro"] }
21-
syn = { version = "1.0.7", features = ["proc-macro", "full", "extra-traits", "parsing"] }
21+
syn = { version = "1.0.58", features = ["proc-macro", "full", "extra-traits", "parsing"] }

client/executor/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ hex-literal = "0.3.1"
4444
sc-runtime-test = { version = "2.0.0", path = "runtime-test" }
4545
substrate-test-runtime = { version = "2.0.0", path = "../../test-utils/runtime" }
4646
sp-state-machine = { version = "0.8.0", path = "../../primitives/state-machine" }
47-
test-case = "0.3.3"
4847
sp-runtime = { version = "2.0.0", path = "../../primitives/runtime" }
4948
sp-tracing = { version = "2.0.0", path = "../../primitives/tracing" }
5049
sc-tracing = { version = "2.0.0", path = "../tracing" }
5150
tracing = "0.1.22"
5251
tracing-subscriber = "0.2.15"
52+
paste = "0.1.6"
5353

5454
[features]
5555
default = [ "std" ]

client/executor/src/integration_tests/mod.rs

+59-57
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ use sp_core::{
2626
};
2727
use sc_runtime_test::wasm_binary_unwrap;
2828
use sp_state_machine::TestExternalities as CoreTestExternalities;
29-
use test_case::test_case;
3029
use sp_trie::{TrieConfiguration, trie_types::Layout};
3130
use sp_wasm_interface::HostFunctions as _;
3231
use sp_runtime::traits::BlakeTwo256;
@@ -37,6 +36,34 @@ use crate::WasmExecutionMethod;
3736
pub type TestExternalities = CoreTestExternalities<BlakeTwo256, u64>;
3837
type HostFunctions = sp_io::SubstrateHostFunctions;
3938

39+
/// Simple macro that runs a given method as test with the available wasm execution methods.
40+
#[macro_export]
41+
macro_rules! test_wasm_execution {
42+
($method_name:ident) => {
43+
paste::item! {
44+
#[test]
45+
fn [<$method_name _interpreted>]() {
46+
$method_name(WasmExecutionMethod::Interpreted);
47+
}
48+
49+
#[test]
50+
#[cfg(feature = "wasmtime")]
51+
fn [<$method_name _compiled>]() {
52+
$method_name(WasmExecutionMethod::Compiled);
53+
}
54+
}
55+
};
56+
57+
(interpreted_only $method_name:ident) => {
58+
paste::item! {
59+
#[test]
60+
fn [<$method_name _interpreted>]() {
61+
$method_name(WasmExecutionMethod::Interpreted);
62+
}
63+
}
64+
};
65+
}
66+
4067
fn call_in_wasm<E: Externalities>(
4168
function: &str,
4269
call_data: &[u8],
@@ -59,8 +86,7 @@ fn call_in_wasm<E: Externalities>(
5986
)
6087
}
6188

62-
#[test_case(WasmExecutionMethod::Interpreted)]
63-
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
89+
test_wasm_execution!(returning_should_work);
6490
fn returning_should_work(wasm_method: WasmExecutionMethod) {
6591
let mut ext = TestExternalities::default();
6692
let mut ext = ext.ext();
@@ -74,8 +100,7 @@ fn returning_should_work(wasm_method: WasmExecutionMethod) {
74100
assert_eq!(output, vec![0u8; 0]);
75101
}
76102

77-
#[test_case(WasmExecutionMethod::Interpreted)]
78-
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
103+
test_wasm_execution!(call_not_existing_function);
79104
fn call_not_existing_function(wasm_method: WasmExecutionMethod) {
80105
let mut ext = TestExternalities::default();
81106
let mut ext = ext.ext();
@@ -102,8 +127,7 @@ fn call_not_existing_function(wasm_method: WasmExecutionMethod) {
102127
}
103128
}
104129

105-
#[test_case(WasmExecutionMethod::Interpreted)]
106-
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
130+
test_wasm_execution!(call_yet_another_not_existing_function);
107131
fn call_yet_another_not_existing_function(wasm_method: WasmExecutionMethod) {
108132
let mut ext = TestExternalities::default();
109133
let mut ext = ext.ext();
@@ -130,8 +154,7 @@ fn call_yet_another_not_existing_function(wasm_method: WasmExecutionMethod) {
130154
}
131155
}
132156

133-
#[test_case(WasmExecutionMethod::Interpreted)]
134-
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
157+
test_wasm_execution!(panicking_should_work);
135158
fn panicking_should_work(wasm_method: WasmExecutionMethod) {
136159
let mut ext = TestExternalities::default();
137160
let mut ext = ext.ext();
@@ -161,8 +184,7 @@ fn panicking_should_work(wasm_method: WasmExecutionMethod) {
161184
assert!(output.is_err());
162185
}
163186

164-
#[test_case(WasmExecutionMethod::Interpreted)]
165-
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
187+
test_wasm_execution!(storage_should_work);
166188
fn storage_should_work(wasm_method: WasmExecutionMethod) {
167189
let mut ext = TestExternalities::default();
168190

@@ -191,8 +213,7 @@ fn storage_should_work(wasm_method: WasmExecutionMethod) {
191213
assert_eq!(ext, expected);
192214
}
193215

194-
#[test_case(WasmExecutionMethod::Interpreted)]
195-
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
216+
test_wasm_execution!(clear_prefix_should_work);
196217
fn clear_prefix_should_work(wasm_method: WasmExecutionMethod) {
197218
let mut ext = TestExternalities::default();
198219
{
@@ -225,8 +246,7 @@ fn clear_prefix_should_work(wasm_method: WasmExecutionMethod) {
225246
assert_eq!(expected, ext);
226247
}
227248

228-
#[test_case(WasmExecutionMethod::Interpreted)]
229-
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
249+
test_wasm_execution!(blake2_256_should_work);
230250
fn blake2_256_should_work(wasm_method: WasmExecutionMethod) {
231251
let mut ext = TestExternalities::default();
232252
let mut ext = ext.ext();
@@ -250,8 +270,7 @@ fn blake2_256_should_work(wasm_method: WasmExecutionMethod) {
250270
);
251271
}
252272

253-
#[test_case(WasmExecutionMethod::Interpreted)]
254-
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
273+
test_wasm_execution!(blake2_128_should_work);
255274
fn blake2_128_should_work(wasm_method: WasmExecutionMethod) {
256275
let mut ext = TestExternalities::default();
257276
let mut ext = ext.ext();
@@ -275,8 +294,7 @@ fn blake2_128_should_work(wasm_method: WasmExecutionMethod) {
275294
);
276295
}
277296

278-
#[test_case(WasmExecutionMethod::Interpreted)]
279-
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
297+
test_wasm_execution!(sha2_256_should_work);
280298
fn sha2_256_should_work(wasm_method: WasmExecutionMethod) {
281299
let mut ext = TestExternalities::default();
282300
let mut ext = ext.ext();
@@ -306,8 +324,7 @@ fn sha2_256_should_work(wasm_method: WasmExecutionMethod) {
306324
);
307325
}
308326

309-
#[test_case(WasmExecutionMethod::Interpreted)]
310-
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
327+
test_wasm_execution!(twox_256_should_work);
311328
fn twox_256_should_work(wasm_method: WasmExecutionMethod) {
312329
let mut ext = TestExternalities::default();
313330
let mut ext = ext.ext();
@@ -335,8 +352,7 @@ fn twox_256_should_work(wasm_method: WasmExecutionMethod) {
335352
);
336353
}
337354

338-
#[test_case(WasmExecutionMethod::Interpreted)]
339-
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
355+
test_wasm_execution!(twox_128_should_work);
340356
fn twox_128_should_work(wasm_method: WasmExecutionMethod) {
341357
let mut ext = TestExternalities::default();
342358
let mut ext = ext.ext();
@@ -360,8 +376,7 @@ fn twox_128_should_work(wasm_method: WasmExecutionMethod) {
360376
);
361377
}
362378

363-
#[test_case(WasmExecutionMethod::Interpreted)]
364-
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
379+
test_wasm_execution!(ed25519_verify_should_work);
365380
fn ed25519_verify_should_work(wasm_method: WasmExecutionMethod) {
366381
let mut ext = TestExternalities::default();
367382
let mut ext = ext.ext();
@@ -397,8 +412,7 @@ fn ed25519_verify_should_work(wasm_method: WasmExecutionMethod) {
397412
);
398413
}
399414

400-
#[test_case(WasmExecutionMethod::Interpreted)]
401-
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
415+
test_wasm_execution!(sr25519_verify_should_work);
402416
fn sr25519_verify_should_work(wasm_method: WasmExecutionMethod) {
403417
let mut ext = TestExternalities::default();
404418
let mut ext = ext.ext();
@@ -434,8 +448,7 @@ fn sr25519_verify_should_work(wasm_method: WasmExecutionMethod) {
434448
);
435449
}
436450

437-
#[test_case(WasmExecutionMethod::Interpreted)]
438-
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
451+
test_wasm_execution!(ordered_trie_root_should_work);
439452
fn ordered_trie_root_should_work(wasm_method: WasmExecutionMethod) {
440453
let mut ext = TestExternalities::default();
441454
let trie_input = vec![b"zero".to_vec(), b"one".to_vec(), b"two".to_vec()];
@@ -450,8 +463,7 @@ fn ordered_trie_root_should_work(wasm_method: WasmExecutionMethod) {
450463
);
451464
}
452465

453-
#[test_case(WasmExecutionMethod::Interpreted)]
454-
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
466+
test_wasm_execution!(offchain_index);
455467
fn offchain_index(wasm_method: WasmExecutionMethod) {
456468
let mut ext = TestExternalities::default();
457469
let (offchain, _state) = testing::TestOffchainExt::new();
@@ -472,8 +484,7 @@ fn offchain_index(wasm_method: WasmExecutionMethod) {
472484
);
473485
}
474486

475-
#[test_case(WasmExecutionMethod::Interpreted)]
476-
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
487+
test_wasm_execution!(offchain_local_storage_should_work);
477488
fn offchain_local_storage_should_work(wasm_method: WasmExecutionMethod) {
478489
let mut ext = TestExternalities::default();
479490
let (offchain, state) = testing::TestOffchainExt::new();
@@ -490,8 +501,7 @@ fn offchain_local_storage_should_work(wasm_method: WasmExecutionMethod) {
490501
assert_eq!(state.read().persistent_storage.get(b"test"), Some(vec![]));
491502
}
492503

493-
#[test_case(WasmExecutionMethod::Interpreted)]
494-
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
504+
test_wasm_execution!(offchain_http_should_work);
495505
fn offchain_http_should_work(wasm_method: WasmExecutionMethod) {
496506
let mut ext = TestExternalities::default();
497507
let (offchain, state) = testing::TestOffchainExt::new();
@@ -519,9 +529,7 @@ fn offchain_http_should_work(wasm_method: WasmExecutionMethod) {
519529
);
520530
}
521531

522-
#[test_case(WasmExecutionMethod::Interpreted)]
523-
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
524-
#[should_panic(expected = "Allocator ran out of space")]
532+
test_wasm_execution!(should_trap_when_heap_exhausted);
525533
fn should_trap_when_heap_exhausted(wasm_method: WasmExecutionMethod) {
526534
let mut ext = TestExternalities::default();
527535

@@ -531,18 +539,20 @@ fn should_trap_when_heap_exhausted(wasm_method: WasmExecutionMethod) {
531539
HostFunctions::host_functions(),
532540
8,
533541
);
534-
executor.call_in_wasm(
542+
543+
let err = executor.call_in_wasm(
535544
&wasm_binary_unwrap()[..],
536545
None,
537546
"test_exhaust_heap",
538547
&[0],
539548
&mut ext.ext(),
540549
sp_core::traits::MissingHostFunctions::Allow,
541-
).unwrap();
550+
).unwrap_err();
551+
552+
assert!(err.contains("Allocator ran out of space"));
542553
}
543554

544-
#[test_case(WasmExecutionMethod::Interpreted)]
545-
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
555+
test_wasm_execution!(returns_mutable_static);
546556
fn returns_mutable_static(wasm_method: WasmExecutionMethod) {
547557
let runtime = crate::wasm_runtime::create_wasm_runtime_with_code(
548558
wasm_method,
@@ -567,8 +577,7 @@ fn returns_mutable_static(wasm_method: WasmExecutionMethod) {
567577
// returned to its initial value and thus the stack space is going to be leaked.
568578
//
569579
// See https://github.com/paritytech/substrate/issues/2967 for details
570-
#[test_case(WasmExecutionMethod::Interpreted)]
571-
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
580+
test_wasm_execution!(restoration_of_globals);
572581
fn restoration_of_globals(wasm_method: WasmExecutionMethod) {
573582
// Allocate 32 pages (of 65536 bytes) which gives the runtime 2048KB of heap to operate on
574583
// (plus some additional space unused from the initial pages requested by the wasm runtime
@@ -596,7 +605,7 @@ fn restoration_of_globals(wasm_method: WasmExecutionMethod) {
596605
assert!(res.is_ok());
597606
}
598607

599-
#[test_case(WasmExecutionMethod::Interpreted)]
608+
test_wasm_execution!(interpreted_only heap_is_reset_between_calls);
600609
fn heap_is_reset_between_calls(wasm_method: WasmExecutionMethod) {
601610
let runtime = crate::wasm_runtime::create_wasm_runtime_with_code(
602611
wasm_method,
@@ -620,8 +629,7 @@ fn heap_is_reset_between_calls(wasm_method: WasmExecutionMethod) {
620629
instance.call_export("check_and_set_in_heap", &params).unwrap();
621630
}
622631

623-
#[test_case(WasmExecutionMethod::Interpreted)]
624-
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
632+
test_wasm_execution!(parallel_execution);
625633
fn parallel_execution(wasm_method: WasmExecutionMethod) {
626634
let executor = std::sync::Arc::new(crate::WasmExecutor::new(
627635
wasm_method,
@@ -656,7 +664,7 @@ fn parallel_execution(wasm_method: WasmExecutionMethod) {
656664
}
657665
}
658666

659-
#[test_case(WasmExecutionMethod::Interpreted)]
667+
test_wasm_execution!(wasm_tracing_should_work);
660668
fn wasm_tracing_should_work(wasm_method: WasmExecutionMethod) {
661669

662670
use std::sync::{Arc, Mutex};
@@ -728,10 +736,8 @@ fn wasm_tracing_should_work(wasm_method: WasmExecutionMethod) {
728736
assert_eq!(len, 2);
729737
}
730738

731-
#[test_case(WasmExecutionMethod::Interpreted)]
732-
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
739+
test_wasm_execution!(spawning_runtime_instance_should_work);
733740
fn spawning_runtime_instance_should_work(wasm_method: WasmExecutionMethod) {
734-
735741
let mut ext = TestExternalities::default();
736742
let mut ext = ext.ext();
737743

@@ -743,10 +749,8 @@ fn spawning_runtime_instance_should_work(wasm_method: WasmExecutionMethod) {
743749
).unwrap();
744750
}
745751

746-
#[test_case(WasmExecutionMethod::Interpreted)]
747-
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
752+
test_wasm_execution!(spawning_runtime_instance_nested_should_work);
748753
fn spawning_runtime_instance_nested_should_work(wasm_method: WasmExecutionMethod) {
749-
750754
let mut ext = TestExternalities::default();
751755
let mut ext = ext.ext();
752756

@@ -758,10 +762,8 @@ fn spawning_runtime_instance_nested_should_work(wasm_method: WasmExecutionMethod
758762
).unwrap();
759763
}
760764

761-
#[test_case(WasmExecutionMethod::Interpreted)]
762-
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
765+
test_wasm_execution!(panic_in_spawned_instance_panics_on_joining_its_result);
763766
fn panic_in_spawned_instance_panics_on_joining_its_result(wasm_method: WasmExecutionMethod) {
764-
765767
let mut ext = TestExternalities::default();
766768
let mut ext = ext.ext();
767769

0 commit comments

Comments
 (0)