Companion PR for #6569 (#1394)

* Update wasm-builder version to 2.0.0

* Fix all crate compile

* Update cargo lock

* Bump runtime impl_version
This commit is contained in:
Wei Tang
2020-07-24 14:00:34 +02:00
committed by GitHub
parent 62d323a878
commit b8de0ff16f
21 changed files with 209 additions and 142 deletions
@@ -19,7 +19,7 @@ use wasm_builder_runner::WasmBuilder;
fn main() {
WasmBuilder::new()
.with_current_project()
.with_wasm_builder_from_crates("1.0.11")
.with_wasm_builder_from_crates("2.0.0")
.export_heap_base()
.build()
}
@@ -33,6 +33,13 @@ static ALLOC: dlmalloc::GlobalDlmalloc = dlmalloc::GlobalDlmalloc;
#[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.")
}
/// Head data for this parachain.
#[derive(Default, Clone, Hash, Eq, PartialEq, Encode, Decode)]
pub struct HeadData {
@@ -19,7 +19,7 @@ use wasm_builder_runner::WasmBuilder;
fn main() {
WasmBuilder::new()
.with_current_project()
.with_wasm_builder_from_crates("1.0.11")
.with_wasm_builder_from_crates("2.0.0")
.export_heap_base()
.build()
}
@@ -34,6 +34,13 @@ static ALLOC: dlmalloc::GlobalDlmalloc = dlmalloc::GlobalDlmalloc;
#[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.")
}
#[derive(Encode, Decode, Clone, Default)]
pub struct State {
/// The current code that is "active" in this chain.
@@ -19,7 +19,7 @@ use wasm_builder_runner::WasmBuilder;
fn main() {
WasmBuilder::new()
.with_current_project()
.with_wasm_builder_from_crates("1.0.11")
.with_wasm_builder_from_crates("2.0.0")
.export_heap_base()
.build()
}
@@ -23,6 +23,13 @@
#[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.")
}
#[cfg(not(feature = "std"))]
#[panic_handler]
#[no_mangle]
@@ -46,4 +53,3 @@ pub fn oom(_: core::alloc::Layout) -> ! {
pub extern fn validate_block(params: *const u8, len: usize) -> usize {
loop {}
}
@@ -44,8 +44,6 @@ struct BlockData {
add: u64,
}
const TEST_CODE: &[u8] = adder::WASM_BINARY;
fn hash_state(state: u64) -> [u8; 32] {
tiny_keccak::keccak256(state.encode().as_slice())
}
@@ -70,7 +68,7 @@ pub fn execute_good_on_parent() {
let pool = parachain::wasm_executor::ValidationPool::new();
let ret = parachain::wasm_executor::validate_candidate(
TEST_CODE,
adder::wasm_binary_unwrap(),
ValidationParams {
parent_head: GenericHeadData(parent_head.encode()),
block_data: GenericBlockData(block_data.encode()),
@@ -109,7 +107,7 @@ fn execute_good_chain_on_parent() {
};
let ret = parachain::wasm_executor::validate_candidate(
TEST_CODE,
adder::wasm_binary_unwrap(),
ValidationParams {
parent_head: GenericHeadData(parent_head.encode()),
block_data: GenericBlockData(block_data.encode()),
@@ -149,7 +147,7 @@ fn execute_bad_on_parent() {
};
let _ret = parachain::wasm_executor::validate_candidate(
TEST_CODE,
adder::wasm_binary_unwrap(),
ValidationParams {
parent_head: GenericHeadData(parent_head.encode()),
block_data: GenericBlockData(block_data.encode()),
@@ -24,8 +24,6 @@ use parachain::primitives::{
use codec::{Decode, Encode};
use code_upgrader::{hash_state, HeadData, BlockData, State};
const TEST_CODE: &[u8] = code_upgrader::WASM_BINARY;
#[test]
pub fn execute_good_no_upgrade() {
let pool = parachain::wasm_executor::ValidationPool::new();
@@ -42,7 +40,7 @@ pub fn execute_good_no_upgrade() {
};
let ret = parachain::wasm_executor::validate_candidate(
TEST_CODE,
code_upgrader::wasm_binary_unwrap(),
ValidationParams {
parent_head: GenericHeadData(parent_head.encode()),
block_data: GenericBlockData(block_data.encode()),
@@ -78,7 +76,7 @@ pub fn execute_good_with_upgrade() {
};
let ret = parachain::wasm_executor::validate_candidate(
TEST_CODE,
code_upgrader::wasm_binary_unwrap(),
ValidationParams {
parent_head: GenericHeadData(parent_head.encode()),
block_data: GenericBlockData(block_data.encode()),
@@ -121,7 +119,7 @@ pub fn code_upgrade_not_allowed() {
};
parachain::wasm_executor::validate_candidate(
TEST_CODE,
code_upgrader::wasm_binary_unwrap(),
ValidationParams {
parent_head: GenericHeadData(parent_head.encode()),
block_data: GenericBlockData(block_data.encode()),
@@ -151,7 +149,7 @@ pub fn applies_code_upgrade_after_delay() {
};
let ret = parachain::wasm_executor::validate_candidate(
TEST_CODE,
code_upgrader::wasm_binary_unwrap(),
ValidationParams {
parent_head: GenericHeadData(parent_head.encode()),
block_data: GenericBlockData(block_data.encode()),
@@ -186,7 +184,7 @@ pub fn applies_code_upgrade_after_delay() {
};
let ret = parachain::wasm_executor::validate_candidate(
TEST_CODE,
code_upgrader::wasm_binary_unwrap(),
ValidationParams {
parent_head: GenericHeadData(parent_head.encode()),
block_data: GenericBlockData(block_data.encode()),
@@ -22,15 +22,12 @@ use parachain::{
wasm_executor::EXECUTION_TIMEOUT_SEC,
};
// Code that exposes `validate_block` and loops infinitely
const INFINITE_LOOP_CODE: &[u8] = halt::WASM_BINARY;
#[test]
fn terminates_on_timeout() {
let pool = parachain::wasm_executor::ValidationPool::new();
let result = parachain::wasm_executor::validate_candidate(
INFINITE_LOOP_CODE,
halt::wasm_binary_unwrap(),
ValidationParams {
block_data: BlockData(Vec::new()),
parent_head: Default::default(),
@@ -59,7 +56,7 @@ fn parallel_execution() {
let pool2 = pool.clone();
let thread = std::thread::spawn(move ||
parachain::wasm_executor::validate_candidate(
INFINITE_LOOP_CODE,
halt::wasm_binary_unwrap(),
ValidationParams {
block_data: BlockData(Vec::new()),
parent_head: Default::default(),
@@ -71,7 +68,7 @@ fn parallel_execution() {
parachain::wasm_executor::ExecutionMode::RemoteTest(&pool2),
).ok());
let _ = parachain::wasm_executor::validate_candidate(
INFINITE_LOOP_CODE,
halt::wasm_binary_unwrap(),
ValidationParams {
block_data: BlockData(Vec::new()),
parent_head: Default::default(),