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 ecbf2c45c2
commit 68100e7545
15 changed files with 3267 additions and 1011 deletions
+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![