Adds test-runtime to start working on tests

This commit is contained in:
Bastian Köcher
2019-03-06 13:51:23 +01:00
parent 1f665b5b55
commit d629154da5
15 changed files with 3267 additions and 1011 deletions
+931 -996
View File
File diff suppressed because it is too large Load Diff
+4 -4
View File
@@ -7,10 +7,10 @@ edition = "2018"
[dependencies]
# substrate deps
substrate-client = { git = "https://github.com/paritytech/substrate" }
substrate-consensus-common = { git = "https://github.com/paritytech/substrate" }
substrate-primitives = { git = "https://github.com/paritytech/substrate" }
sr-primitives = { git = "https://github.com/paritytech/substrate" }
substrate-client = { git = "https://github.com/paritytech/substrate", branch = "bkchr-validate_block" }
substrate-consensus-common = { git = "https://github.com/paritytech/substrate", branch = "bkchr-validate_block" }
substrate-primitives = { git = "https://github.com/paritytech/substrate", branch = "bkchr-validate_block" }
sr-primitives = { git = "https://github.com/paritytech/substrate", branch = "bkchr-validate_block" }
# polkadot deps
polkadot-service = { git = "https://github.com/paritytech/polkadot" }
+1 -1
View File
@@ -1,5 +1,5 @@
[package]
name = "runtime"
name = "cumulus-runtime"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
+5
View File
@@ -20,6 +20,11 @@ use rstd::{vec::Vec, collections::btree_map::BTreeMap};
use codec::{Encode, Decode};
use runtime_primitives::traits::Block as BlockT;
#[cfg(not(feature = "std"))]
#[doc(hidden)]
pub use rstd::slice;
#[macro_use]
pub mod validate_block;
type WitnessData = BTreeMap<Vec<u8>, Vec<u8>>;
+5 -4
View File
@@ -17,8 +17,9 @@
//! A module that enables a runtime to work as parachain.
#[cfg(not(feature = "std"))]
#[doc(hidden)]
pub use rstd::slice;
use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, One};
#[cfg(not(feature = "std"))]
use executive::ExecuteBlock;
#[cfg(not(feature = "std"))]
#[doc(hidden)]
@@ -84,12 +85,12 @@ macro_rules! register_validate_block_impl {
pub fn validate_block<Block: BlockT, E: ExecuteBlock<Block>>(mut block: &[u8], mut prev_head: &[u8]) {
use codec::Decode;
let block = ParachainBlock::<Block>::decode(&mut block).expect("Could not decode parachain block.");
let block = crate::ParachainBlock::<Block>::decode(&mut block).expect("Could not decode parachain block.");
let parent_header = <<Block as BlockT>::Header as Decode>::decode(&mut prev_head).expect("Could not decode parent header.");
let _guard = unsafe {
use storage_functions as storage;
STORAGE = Some(block.witness_data);
storage::STORAGE = Some(block.witness_data);
(
// Replace storage calls with our own implementations
rio::ext_get_allocated_storage.replace_implementation(storage::ext_get_allocated_storage),
@@ -12,15 +12,12 @@
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
//! All storage functions that are replaced by `validate_block` in the Substrate runtime.
use crate::{ParachainBlock, WitnessData};
use runtime_primitives::traits::{Block as BlockT, One, Header as HeaderT};
use crate::WitnessData;
use rstd::{slice, ptr, cmp};
use codec::Decode;
use executive::ExecuteBlock;
pub static mut STORAGE: Option<WitnessData> = None;
const STORAGE_SET_EXPECT: &str = "`STORAGE` needs to be set before calling this function.";
+17 -1
View File
@@ -1,3 +1,19 @@
// Copyright 2019 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
// Substrate 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.
// Substrate 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 Cumulus. If not, see <http://www.gnu.org/licenses/>.
use crate::ParachainBlock;
use rio::{twox_128, TestExternalities};
@@ -12,7 +28,7 @@ use std::collections::BTreeMap;
use codec::{KeyedVec, Encode};
const WASM_CODE: &'static [u8] =
include_bytes!("../../../core/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm");
include_bytes!("../../test-runtime/wasm/target/wasm32-unknown-unknown/release/cumulus_test_runtime.compact.wasm");
fn create_witness_data() -> BTreeMap<Vec<u8>, Vec<u8>> {
map![
+16
View File
@@ -0,0 +1,16 @@
[package]
name = "cumulus-test-runtime"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
[dependencies]
runtime = { package = "cumulus-runtime", path = "..", default-features = false }
substrate-test-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "bkchr-validate_block" }
[features]
default = ["std"]
std = [
"runtime/std",
"substrate-test-runtime/std",
]
+23
View File
@@ -0,0 +1,23 @@
// Copyright 2019 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
// Substrate 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.
// Substrate 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 Cumulus. If not, see <http://www.gnu.org/licenses/>.
//! A Cumulus test runtime.
#![cfg_attr(not(feature = "std"), no_std)]
use substrate_test_runtime::{Block, system::BlockExecutor};
runtime::register_validate_block!(Block, BlockExecutor);
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,25 @@
[package]
name = "cumulus-test-runtime-wasm"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
[lib]
name = "cumulus_test_runtime"
crate-type = ["cdylib"]
[dependencies]
cumulus-test-runtime = { path = "..", default-features = false }
[features]
default = []
std = [
"cumulus-test-runtime/std",
]
[profile.release]
panic = "abort"
lto = true
[workspace]
members = []
+13
View File
@@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -e
if cargo --version | grep -q "nightly"; then
CARGO_CMD="cargo"
else
CARGO_CMD="cargo +nightly"
fi
CARGO_INCREMENTAL=0 RUSTFLAGS="-C link-arg=--export-table" $CARGO_CMD build --target=wasm32-unknown-unknown --release
for i in cumulus_test_runtime
do
wasm-gc target/wasm32-unknown-unknown/release/$i.wasm target/wasm32-unknown-unknown/release/$i.compact.wasm
done
@@ -0,0 +1,21 @@
// Copyright 2019 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
// Substrate 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.
// Substrate 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 Cumulus. If not, see <http://www.gnu.org/licenses/>.
//! The Cumulus test runtime reexported for WebAssembly compile.
#![cfg_attr(not(feature = "std"), no_std)]
pub use cumulus_test_runtime::*;
+28
View File
@@ -0,0 +1,28 @@
#!/usr/bin/env bash
# This script assumes that all pre-requisites are installed.
set -e
PROJECT_ROOT=`git rev-parse --show-toplevel`
source `dirname "$0"`/common.sh
export CARGO_INCREMENTAL=0
# Save current directory.
pushd .
cd $ROOT
for SRC in "${SRCS[@]}"
do
echo "*** Building wasm binaries in $SRC"
cd "$PROJECT_ROOT/$SRC"
./build.sh
cd - >> /dev/null
done
# Restore initial directory.
popd
+18
View File
@@ -0,0 +1,18 @@
#!/usr/bin/env bash
ROOT=`dirname "$0"`
# A list of directories which contain wasm projects.
SRCS=(
"runtime/test-runtime/wasm"
)
# Make pushd/popd silent.
pushd () {
command pushd "$@" > /dev/null
}
popd () {
command popd "$@" > /dev/null
}