Files
pezkuwi-subxt/polkadot/parachain/tests/wasm_executor/mod.rs
T
Bastian Köcher 06386558ae Switch parachain interface to new runtime_interface macro (#665)
* Make use of `runtime_interface` for parachain externalities

This also changes the encoding of the `ValidationResult` return value to
match the default encoding used in Substrate.

* Fix compilation for web

* Update `Cargo.lock`

* Include feedback

* Move proc macro

* Update parachain/src/lib.rs

Co-Authored-By: Robert Habermeier <rphmeier@gmail.com>

Co-authored-by: Robert Habermeier <rphmeier@gmail.com>
2020-01-08 20:44:50 +01:00

78 lines
2.3 KiB
Rust

// Copyright 2019-2020 Parity Technologies (UK) Ltd.
// This file is part of Polkadot.
// Polkadot is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Polkadot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
//! Basic parachain that adds a number as part of its state.
use polkadot_parachain as parachain;
use crate::{adder, DummyExt};
use crate::parachain::{ValidationParams, 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 result = parachain::wasm_executor::validate_candidate(
INFINITE_LOOP_CODE,
ValidationParams {
parent_head: Default::default(),
block_data: Vec::new(),
ingress: Vec::new(),
},
DummyExt,
parachain::wasm_executor::ExecutionMode::RemoteTest,
);
match result {
Err(parachain::wasm_executor::Error::Timeout) => {},
r => panic!("{:?}", r),
}
// check that another parachain can validate normaly
adder::execute_good_on_parent();
}
#[test]
fn parallel_execution() {
let start = std::time::Instant::now();
let thread = std::thread::spawn(move ||
parachain::wasm_executor::validate_candidate(
INFINITE_LOOP_CODE,
ValidationParams {
parent_head: Default::default(),
block_data: Vec::new(),
ingress: Vec::new(),
},
DummyExt,
parachain::wasm_executor::ExecutionMode::RemoteTest,
).ok());
let _ = parachain::wasm_executor::validate_candidate(
INFINITE_LOOP_CODE,
ValidationParams {
parent_head: Default::default(),
block_data: Vec::new(),
ingress: Vec::new(),
},
DummyExt,
parachain::wasm_executor::ExecutionMode::RemoteTest,
);
thread.join().unwrap();
// total time should be < 2 x EXECUTION_TIMEOUT_SEC
assert!(
std::time::Instant::now().duration_since(start)
< std::time::Duration::from_secs(EXECUTION_TIMEOUT_SEC * 2)
);
}