Better handling of stable-only build (#6569)

* Better handling of stable-only build

* Fix node template build

* Fix wasm builder node-template version mismatch

* Fix load_spec error

* Add , in parameter

* Add descrptive panic messages in tests

* Add descriptive tests in node/executor benches

* Fix missing compact_code_unwrap

* Add missing wasm_binary_unwrap function for executor integration test

* Only define import_sp_io in no_std

* Small Cargo.toml styling fix

* Bump wasm-builder to 2.0.0

* Fix all `with_wasm_builder_from_crates` version in Substrate

* Use `with_wasm_builder_from_crates` for node-template

Co-authored-by: Gavin Wood <gavin@parity.io>
This commit is contained in:
Wei Tang
2020-07-22 21:40:11 +02:00
committed by GitHub
parent ffa2177d46
commit ac8de557d6
33 changed files with 161 additions and 108 deletions
@@ -20,7 +20,7 @@ use wasm_builder_runner::WasmBuilder;
fn main() {
WasmBuilder::new()
.with_current_project()
.with_wasm_builder_from_crates_or_path("1.0.11", "../../../utils/wasm-builder")
.with_wasm_builder_from_crates_or_path("2.0.0", "../../../utils/wasm-builder")
.export_heap_base()
.import_memory()
.build()
@@ -26,8 +26,16 @@ use sp_runtime_interface::runtime_interface;
#[cfg(feature = "std")]
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
#[cfg(feature = "std")]
/// Wasm binary unwrapped. If built with `BUILD_DUMMY_WASM_BINARY`, the function panics.
pub fn wasm_binary_unwrap() -> &'static [u8] {
WASM_BINARY.expect("Development wasm binary is not available. Testing is only \
supported with the flag disabled.")
}
/// This function is not used, but we require it for the compiler to include `sp-io`.
/// `sp-io` is required for its panic and oom handler.
#[cfg(not(feature = "std"))]
#[no_mangle]
pub fn import_sp_io() {
sp_io::misc::print_utf8(&[]);
@@ -50,4 +58,4 @@ wasm_export_functions! {
assert!(!test_api::test_versionning(142));
assert!(!test_api::test_versionning(0));
}
}
}
@@ -20,7 +20,7 @@ use wasm_builder_runner::WasmBuilder;
fn main() {
WasmBuilder::new()
.with_current_project()
.with_wasm_builder_from_crates_or_path("1.0.11", "../../../utils/wasm-builder")
.with_wasm_builder_from_crates_or_path("2.0.0", "../../../utils/wasm-builder")
.export_heap_base()
.import_memory()
.build()
@@ -30,6 +30,13 @@ use sp_core::{sr25519::Public, wasm_export_functions};
#[cfg(feature = "std")]
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
#[cfg(feature = "std")]
/// Wasm binary unwrapped. If built with `BUILD_DUMMY_WASM_BINARY`, the function panics.
pub fn wasm_binary_unwrap() -> &'static [u8] {
WASM_BINARY.expect("Development wasm binary is not available. Testing is only \
supported with the flag disabled.")
}
/// Used in the `test_array_as_mutable_reference` test.
const TEST_ARRAY: [u8; 16] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];
@@ -22,8 +22,8 @@
use sp_runtime_interface::*;
use sp_runtime_interface_test_wasm::{WASM_BINARY, test_api::HostFunctions};
use sp_runtime_interface_test_wasm_deprecated::WASM_BINARY as WASM_BINARY_DEPRECATED;
use sp_runtime_interface_test_wasm::{wasm_binary_unwrap, test_api::HostFunctions};
use sp_runtime_interface_test_wasm_deprecated::wasm_binary_unwrap as wasm_binary_deprecated_unwrap;
use sp_wasm_interface::HostFunctions as HostFunctionsT;
use sc_executor::CallInWasm;
@@ -64,17 +64,17 @@ fn call_wasm_method<HF: HostFunctionsT>(binary: &[u8], method: &str) -> TestExte
#[test]
fn test_return_data() {
call_wasm_method::<HostFunctions>(&WASM_BINARY[..], "test_return_data");
call_wasm_method::<HostFunctions>(&wasm_binary_unwrap()[..], "test_return_data");
}
#[test]
fn test_return_option_data() {
call_wasm_method::<HostFunctions>(&WASM_BINARY[..], "test_return_option_data");
call_wasm_method::<HostFunctions>(&wasm_binary_unwrap()[..], "test_return_option_data");
}
#[test]
fn test_set_storage() {
let mut ext = call_wasm_method::<HostFunctions>(&WASM_BINARY[..], "test_set_storage");
let mut ext = call_wasm_method::<HostFunctions>(&wasm_binary_unwrap()[..], "test_set_storage");
let expected = "world";
assert_eq!(expected.as_bytes(), &ext.ext().storage("hello".as_bytes()).unwrap()[..]);
@@ -82,27 +82,27 @@ fn test_set_storage() {
#[test]
fn test_return_value_into_mutable_reference() {
call_wasm_method::<HostFunctions>(&WASM_BINARY[..], "test_return_value_into_mutable_reference");
call_wasm_method::<HostFunctions>(&wasm_binary_unwrap()[..], "test_return_value_into_mutable_reference");
}
#[test]
fn test_get_and_return_array() {
call_wasm_method::<HostFunctions>(&WASM_BINARY[..], "test_get_and_return_array");
call_wasm_method::<HostFunctions>(&wasm_binary_unwrap()[..], "test_get_and_return_array");
}
#[test]
fn test_array_as_mutable_reference() {
call_wasm_method::<HostFunctions>(&WASM_BINARY[..], "test_array_as_mutable_reference");
call_wasm_method::<HostFunctions>(&wasm_binary_unwrap()[..], "test_array_as_mutable_reference");
}
#[test]
fn test_return_input_public_key() {
call_wasm_method::<HostFunctions>(&WASM_BINARY[..], "test_return_input_public_key");
call_wasm_method::<HostFunctions>(&wasm_binary_unwrap()[..], "test_return_input_public_key");
}
#[test]
fn host_function_not_found() {
let err = call_wasm_method_with_result::<()>(&WASM_BINARY[..], "test_return_data").unwrap_err();
let err = call_wasm_method_with_result::<()>(&wasm_binary_unwrap()[..], "test_return_data").unwrap_err();
assert!(err.contains("Instantiation: Export "));
assert!(err.contains(" not found"));
@@ -111,46 +111,46 @@ fn host_function_not_found() {
#[test]
#[should_panic(expected = "Invalid utf8 data provided")]
fn test_invalid_utf8_data_should_return_an_error() {
call_wasm_method::<HostFunctions>(&WASM_BINARY[..], "test_invalid_utf8_data_should_return_an_error");
call_wasm_method::<HostFunctions>(&wasm_binary_unwrap()[..], "test_invalid_utf8_data_should_return_an_error");
}
#[test]
fn test_overwrite_native_function_implementation() {
call_wasm_method::<HostFunctions>(&WASM_BINARY[..], "test_overwrite_native_function_implementation");
call_wasm_method::<HostFunctions>(&wasm_binary_unwrap()[..], "test_overwrite_native_function_implementation");
}
#[test]
fn test_u128_i128_as_parameter_and_return_value() {
call_wasm_method::<HostFunctions>(&WASM_BINARY[..], "test_u128_i128_as_parameter_and_return_value");
call_wasm_method::<HostFunctions>(&wasm_binary_unwrap()[..], "test_u128_i128_as_parameter_and_return_value");
}
#[test]
fn test_vec_return_value_memory_is_freed() {
call_wasm_method::<HostFunctions>(&WASM_BINARY[..], "test_vec_return_value_memory_is_freed");
call_wasm_method::<HostFunctions>(&wasm_binary_unwrap()[..], "test_vec_return_value_memory_is_freed");
}
#[test]
fn test_encoded_return_value_memory_is_freed() {
call_wasm_method::<HostFunctions>(&WASM_BINARY[..], "test_encoded_return_value_memory_is_freed");
call_wasm_method::<HostFunctions>(&wasm_binary_unwrap()[..], "test_encoded_return_value_memory_is_freed");
}
#[test]
fn test_array_return_value_memory_is_freed() {
call_wasm_method::<HostFunctions>(&WASM_BINARY[..], "test_array_return_value_memory_is_freed");
call_wasm_method::<HostFunctions>(&wasm_binary_unwrap()[..], "test_array_return_value_memory_is_freed");
}
#[test]
fn test_versionining_with_new_host_works() {
// We call to the new wasm binary with new host function.
call_wasm_method::<HostFunctions>(
&WASM_BINARY[..],
&wasm_binary_unwrap()[..],
"test_versionning_works",
);
// we call to the old wasm binary with a new host functions
// old versions of host functions should be called and test should be ok!
call_wasm_method::<HostFunctions>(
&WASM_BINARY_DEPRECATED[..],
&wasm_binary_deprecated_unwrap()[..],
"test_versionning_works",
);
}
@@ -192,7 +192,7 @@ fn test_tracing() {
let _guard = tracing::subscriber::set_default(subscriber.clone());
// Call some method to generate a trace
call_wasm_method::<HostFunctions>(&WASM_BINARY[..], "test_return_data");
call_wasm_method::<HostFunctions>(&wasm_binary_unwrap()[..], "test_return_data");
let inner = subscriber.0.lock().unwrap();
assert!(inner.spans.contains("return_input_version_1"));