Merge branch 'master' into author-relay-block

This commit is contained in:
Robert Habermeier
2018-01-31 18:10:53 +01:00
58 changed files with 3509 additions and 561 deletions
+6 -4
View File
@@ -18,6 +18,7 @@
use primitives::block;
use client;
use state_machine;
mod error;
@@ -35,11 +36,12 @@ build_rpc_trait! {
}
}
impl<B> ChainApi for B where
B: client::Blockchain + Send + Sync + 'static,
B::Error: ::std::error::Error + Send,
impl<B, E> ChainApi for client::Client<B, E> where
B: client::backend::Backend + Send + Sync + 'static,
E: state_machine::CodeExecutor + Send + Sync + 'static,
client::error::Error: From<<<B as client::backend::Backend>::State as state_machine::backend::Backend>::Error>,
{
fn header(&self, hash: block::HeaderHash) -> Result<Option<block::Header>> {
self.header(&hash).chain_err(|| "Blockchain error")
client::Client::header(self, &hash).chain_err(|| "Blockchain error")
}
}
+6 -7
View File
@@ -14,28 +14,27 @@
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
use primitives::parachain;
use polkadot_executor as executor;
use client;
use super::*;
use test_helpers::Blockchain;
#[test]
fn should_return_header() {
let state = Blockchain::default();
let client = client::new_in_mem(executor::executor()).unwrap();
assert_matches!(
ChainApi::header(&state, 0.into()),
ChainApi::header(&client, "11265ce45dd2baaaf071f6df8c5a44f0ed1d85a50e71451ff2d4345e57d12e3a".into()),
Ok(Some(ref x)) if x == &block::Header {
parent_hash: 0.into(),
number: 0,
state_root: 0.into(),
parachain_activity: parachain::Activity(vec![0]),
parachain_activity: Default::default(),
logs: vec![],
}
);
assert_matches!(
ChainApi::header(&state, 5.into()),
ChainApi::header(&client, 5.into()),
Ok(None)
);
}
-3
View File
@@ -36,6 +36,3 @@ extern crate assert_matches;
pub mod chain;
pub mod state;
#[cfg(test)]
mod test_helpers;
+2 -1
View File
@@ -42,8 +42,9 @@ build_rpc_trait! {
}
impl<B, E> StateApi for Client<B, E> where
B: client::Blockchain + Send + Sync + 'static,
B: client::backend::Backend + Send + Sync + 'static,
E: state_machine::CodeExecutor + Send + Sync + 'static,
client::error::Error: From<<<B as client::backend::Backend>::State as state_machine::backend::Backend>::Error>,
{
fn storage(&self, key: StorageKey, block: block::HeaderHash) -> Result<StorageData> {
Ok(self.storage(&block, &key)?)
+7 -5
View File
@@ -18,14 +18,15 @@ use super::*;
use polkadot_executor as executor;
use self::error::{Error, ErrorKind};
use test_helpers::Blockchain;
use client;
#[test]
fn should_return_storage() {
let client = Client::new(Blockchain::default(), executor::executor());
let client = client::new_in_mem(executor::executor()).unwrap();
let genesis_hash = "11265ce45dd2baaaf071f6df8c5a44f0ed1d85a50e71451ff2d4345e57d12e3a".into();
assert_matches!(
StateApi::storage(&client, StorageKey(vec![10]), 0.into()),
StateApi::storage(&client, StorageKey(vec![10]), genesis_hash),
Ok(ref x) if x.0.is_empty()
)
}
@@ -34,10 +35,11 @@ fn should_return_storage() {
#[ignore] // TODO: [ToDr] reenable once we can properly mock the wasm executor env
fn should_call_contract() {
// TODO [ToDr] Fix test after we are able to mock state.
let client = Client::new(Blockchain::default(), executor::executor());
let client = client::new_in_mem(executor::executor()).unwrap();
let genesis_hash = "11265ce45dd2baaaf071f6df8c5a44f0ed1d85a50e71451ff2d4345e57d12e3a".into();
assert_matches!(
StateApi::call(&client, "balanceOf".into(), CallData(vec![1,2,3]), 0.into()),
StateApi::call(&client, "balanceOf".into(), CallData(vec![1,2,3]), genesis_hash),
Err(Error(ErrorKind::Client(client::error::ErrorKind::Execution(_)), _))
)
}
-45
View File
@@ -1,45 +0,0 @@
// Copyright 2017 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/>.
use client;
use primitives::{block, parachain};
/// Temporary dummy blockchain implementation for tests.
#[derive(Debug, Default)]
pub struct Blockchain;
impl client::Blockchain for Blockchain {
type Error = ::std::io::Error;
fn latest_hash(&self) -> Result<block::HeaderHash, Self::Error> {
Ok(0.into())
}
fn header(&self, hash: &block::HeaderHash) -> Result<Option<block::Header>, Self::Error> {
Ok(if hash != &0.into() {
None
} else {
Some(block::Header {
parent_hash: 0.into(),
number: 0,
state_root: 0.into(),
parachain_activity: parachain::Activity(vec![0]),
logs: vec![],
})
})
}
}