fix tests after merge

This commit is contained in:
Robert Habermeier
2018-02-06 14:44:25 +01:00
parent 2b691cef06
commit de65de4758
13 changed files with 77 additions and 59 deletions
+2
View File
@@ -996,6 +996,7 @@ dependencies = [
name = "polkadot-client"
version = "0.1.0"
dependencies = [
"ed25519 0.1.0",
"error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"hex-literal 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1003,6 +1004,7 @@ dependencies = [
"parking_lot 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"polkadot-executor 0.1.0",
"polkadot-primitives 0.1.0",
"polkadot-runtime-codec 0.1.0",
"polkadot-serializer 0.1.0",
"polkadot-state-machine 0.1.0",
"triehash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
+2
View File
@@ -11,6 +11,8 @@ polkadot-primitives = { path = "../primitives", version = "0.1" }
polkadot-state-machine = { path = "../state-machine", version = "0.1" }
polkadot-serializer = { path = "../serializer" }
polkadot-executor = { path = "../executor" }
polkadot-runtime-codec = { path = "../runtime-codec", version = "0.1" }
native-runtime = { path = "../native-runtime" }
triehash = "0.1"
hex-literal = "0.1"
ed25519 = { path = "../ed25519", version = "0.1" }
+20 -17
View File
@@ -40,19 +40,21 @@ pub fn construct_genesis_block(storage: &HashMap<Vec<u8>, Vec<u8>>) -> Block {
#[cfg(test)]
mod tests {
use super::*;
use native_runtime::codec::{Slicable, Joiner};
use codec::{Slicable, Joiner};
use native_runtime::support::{one, two, Hashable};
use native_runtime::runtime::genesismap::{GenesisConfig, additional_storage_with_genesis};
use native_runtime::primitives::{AccountID, Hash, BlockNumber, Transaction,
UncheckedTransaction, Digest, Function};
use state_machine::execute;
use state_machine::OverlayedChanges;
use state_machine::backend::InMemory;
use polkadot_executor::executor;
use primitives::{AccountId, Hash, H256};
use primitives::block::{Number as BlockNumber, Header, Digest};
use primitives::runtime_function::Function;
use primitives::transaction::{UncheckedTransaction, Transaction};
use primitives::contract::CallData;
use primitives::ed25519::Pair;
use ed25519::Pair;
fn secret_for(who: &AccountID) -> Option<Pair> {
fn secret_for(who: &AccountId) -> Option<Pair> {
match who {
x if *x == one() => Some(Pair::from_seed(b"12345678901234567890123456789012")),
x if *x == two() => Some("9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60".into()),
@@ -65,12 +67,12 @@ mod tests {
let transactions = txs.into_iter().map(|transaction| {
let signature = secret_for(&transaction.signed).unwrap()
.sign(&transaction.to_vec())
.inner();
.sign(&transaction.to_vec());
UncheckedTransaction { transaction, signature }
}).collect::<Vec<_>>();
let transaction_root = ordered_trie_root(transactions.iter().map(Slicable::to_vec)).0;
let transaction_root = H256(ordered_trie_root(transactions.iter().map(Slicable::to_vec)).0);
let mut header = Header {
parent_hash,
@@ -84,24 +86,26 @@ mod tests {
let mut overlay = OverlayedChanges::default();
for tx in transactions.iter() {
header = Header::from_slice(&execute(
let ret_data = execute(
backend,
&mut overlay,
&executor(),
"execute_transaction",
&CallData(vec![].join(&header).join(tx))
).unwrap()).unwrap();
).unwrap();
header = Header::from_slice(&mut &ret_data[..]).unwrap();
}
header = Header::from_slice(&execute(
let ret_data = execute(
backend,
&mut overlay,
&executor(),
"finalise_block",
&CallData(vec![].join(&header))
).unwrap()).unwrap();
).unwrap();
header = Header::from_slice(&mut &ret_data[..]).unwrap();
(vec![].join(&Block { header, transactions }), hash)
(vec![].join(&Block { header, transactions }), H256(hash))
}
fn block1(genesis_hash: Hash, backend: &InMemory) -> (Vec<u8>, Hash) {
@@ -109,12 +113,11 @@ mod tests {
backend,
1,
genesis_hash,
hex!("25e5b37074063ab75c889326246640729b40d0c86932edc527bc80db0e04fe5c"),
H256(hex!("25e5b37074063ab75c889326246640729b40d0c86932edc527bc80db0e04fe5c")),
vec![Transaction {
signed: one(),
nonce: 0,
function: Function::StakingTransfer,
input_data: vec![].join(&two()).join(&69u64),
function: Function::StakingTransfer(two(), 69),
}]
)
}
@@ -125,7 +128,7 @@ mod tests {
vec![one(), two()], 1000
).genesis_map();
let block = construct_genesis_block(&storage);
let genesis_hash = block.header.blake2_256();
let genesis_hash = H256(block.header.blake2_256());
storage.extend(additional_storage_with_genesis(&block).into_iter());
let mut overlay = OverlayedChanges::default();
+2
View File
@@ -21,8 +21,10 @@
extern crate polkadot_primitives as primitives;
extern crate polkadot_state_machine as state_machine;
extern crate polkadot_serializer as ser;
extern crate polkadot_runtime_codec as codec;
extern crate polkadot_executor;
extern crate native_runtime;
extern crate ed25519;
extern crate triehash;
extern crate parking_lot;
+19 -21
View File
@@ -42,13 +42,15 @@ impl CodeExecutor for NativeExecutor {
#[cfg(test)]
mod tests {
use super::*;
use codec::{KeyedVec, Slicable};
use native_runtime::support::{one, two, Hashable};
use runtime_std::TestExternalities;
use codec::{KeyedVec, Slicable, Joiner};
use native_runtime::support::{one, two, Hashable};
use native_runtime::runtime::staking::balance;
use state_machine::TestExternalities;
use primitives::twox_128;
use primitives::{twox_128, Hash, H256};
use primitives::runtime_function::Function;
use primitives::block::{Header, Number as BlockNumber, Block, Digest};
use primitives::transaction::{Transaction, UncheckedTransaction};
use ed25519::Pair;
const BLOATY_CODE: &[u8] = include_bytes!("../../wasm-runtime/target/wasm32-unknown-unknown/release/runtime_polkadot.wasm");
const COMPACT_CODE: &[u8] = include_bytes!("../../wasm-runtime/target/wasm32-unknown-unknown/release/runtime_polkadot.compact.wasm");
@@ -60,8 +62,8 @@ mod tests {
function: Function::StakingTransfer(two(), 69),
};
let signature = secret_for(&transaction.signed).unwrap()
.sign(&transaction.to_vec())
.inner();
.sign(&transaction.to_vec());
UncheckedTransaction { transaction, signature }
}
@@ -147,8 +149,7 @@ mod tests {
], }
}
use primitives::ed25519::Pair;
fn secret_for(who: &AccountID) -> Option<Pair> {
fn secret_for(who: &::primitives::AccountId) -> Option<Pair> {
match who {
x if *x == one() => Some(Pair::from_seed(b"12345678901234567890123456789012")),
x if *x == two() => Some("9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60".into()),
@@ -161,12 +162,12 @@ mod tests {
let transactions = txs.into_iter().map(|transaction| {
let signature = secret_for(&transaction.signed).unwrap()
.sign(&transaction.to_vec())
.inner();
.sign(&transaction.to_vec());
UncheckedTransaction { transaction, signature }
}).collect::<Vec<_>>();
let transaction_root = ordered_trie_root(transactions.iter().map(Slicable::to_vec)).0;
let transaction_root = H256(ordered_trie_root(transactions.iter().map(Slicable::to_vec)).0);
let header = Header {
parent_hash,
@@ -177,19 +178,18 @@ mod tests {
};
let hash = header.blake2_256();
(Block { header, transactions }.to_vec(), hash)
(Block { header, transactions }.to_vec(), H256(hash))
}
fn block1() -> (Vec<u8>, Hash) {
construct_block(
1,
[69u8; 32],
hex!("2481853da20b9f4322f34650fea5f240dcbfb266d02db94bfa0153c31f4a29db"),
H256([69u8; 32]),
H256(hex!("2481853da20b9f4322f34650fea5f240dcbfb266d02db94bfa0153c31f4a29db")),
vec![Transaction {
signed: one(),
nonce: 0,
function: Function::StakingTransfer,
input_data: vec![].join(&two()).join(&69u64),
function: Function::StakingTransfer(two(), 69),
}]
)
}
@@ -198,19 +198,17 @@ mod tests {
construct_block(
2,
block1().1,
hex!("2e69e4405a13981224078ad5355c68401bf56d0fe3f14a3536734666e6a8a047"),
H256(hex!("2cdbbf9bd766c2286a5f4091c131fe161addd060ba6fc041b3419089f4601bda")),
vec![
Transaction {
signed: two(),
nonce: 0,
function: Function::StakingTransfer,
input_data: vec![].join(&one()).join(&5u64),
function: Function::StakingTransfer(one(), 5),
},
Transaction {
signed: one(),
nonce: 1,
function: Function::StakingTransfer,
input_data: vec![].join(&two()).join(&15u64),
function: Function::StakingTransfer(two(), 15),
}
]
)
+8 -11
View File
@@ -287,17 +287,17 @@ impl CodeExecutor for WasmExecutor {
#[cfg(test)]
mod tests {
use super::*;
use rustc_hex::FromHex;
use primitives::{AccountId, blake2_256, twox_128};
use primitives::block::Header;
use primitives::transaction::{Transaction, UncheckedTransaction};
use codec::KeyedVec;
use state_machine::TestExternalities;
use runtime_std;
use codec::{KeyedVec, Slicable, Joiner};
use native_runtime::support::{one, two};
use native_runtime::runtime::staking::balance;
use state_machine::TestExternalities;
use primitives::{twox_128, AccountId};
use primitives::runtime_function::Function;
use primitives::block::Header;
use primitives::transaction::{Transaction, UncheckedTransaction};
use runtime_std;
use ed25519::Pair;
fn secret_for(who: &AccountId) -> Option<Pair> {
@@ -309,16 +309,13 @@ mod tests {
}
fn tx() -> UncheckedTransaction {
use native_runtime::codec::Slicable;
let transaction = Transaction {
signed: one(),
nonce: 0,
function: Function::StakingTransfer(two(), 69),
};
let signature = secret_for(&transaction.signed).unwrap()
.sign(&transaction.to_vec())
.inner();
.sign(&transaction.to_vec());
UncheckedTransaction { transaction, signature }
}
+13
View File
@@ -120,6 +120,19 @@ pub struct Header {
pub digest: Digest,
}
impl Header {
/// Create a new instance with default fields except `number`, which is given as an argument.
pub fn from_block_number(number: Number) -> Self {
Header {
parent_hash: Default::default(),
number,
state_root: Default::default(),
transaction_root: Default::default(),
digest: Default::default(),
}
}
}
impl Slicable for Header {
fn from_slice(value: &mut &[u8]) -> Option<Self> {
Some(Header {
@@ -20,14 +20,15 @@ use std::collections::HashMap;
use runtime_std::twox_128;
use codec::{KeyedVec, Joiner};
use support::Hashable;
use primitives::{AccountID, BlockNumber, Block};
use primitives::block::{Number as BlockNumber, Block};
use primitives::AccountId;
use runtime::staking::Balance;
/// Configuration of a general Polkadot genesis block.
pub struct GenesisConfig {
pub validators: Vec<AccountID>,
pub authorities: Vec<AccountID>,
pub balances: Vec<(AccountID, Balance)>,
pub validators: Vec<AccountId>,
pub authorities: Vec<AccountId>,
pub balances: Vec<(AccountId, Balance)>,
pub block_time: u64,
pub session_length: BlockNumber,
pub sessions_per_era: BlockNumber,
@@ -36,7 +37,7 @@ pub struct GenesisConfig {
}
impl GenesisConfig {
pub fn new_simple(authorities_validators: Vec<AccountID>, balance: Balance) -> Self {
pub fn new_simple(authorities_validators: Vec<AccountId>, balance: Balance) -> Self {
GenesisConfig {
validators: authorities_validators.clone(),
authorities: authorities_validators.clone(),
@@ -282,8 +282,8 @@ mod tests {
let h = Header {
parent_hash: H256([69u8; 32]),
number: 1,
state_root: H256(hex!("2481853da20b9f4322f34650fea5f240dcbfb266d02db94bfa0153c31f4a29db")),
transaction_root: H256(hex!("c4b361b976b3aa90f9f0cdd32f4afc80dd96f200145a687196388a00363c2235")),
state_root: H256(hex!("1ab2dbb7d4868a670b181327b0b6a58dc64b10cfb9876f737a5aa014b8da31e0")),
transaction_root: H256(hex!("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")),
digest: Digest { logs: vec![], },
};
@@ -306,10 +306,10 @@ mod tests {
let mut t = new_test_ext();
let h = Header {
parent_hash: [69u8; 32],
parent_hash: H256([69u8; 32]),
number: 1,
state_root: [0u8; 32],
transaction_root: hex!("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"),
state_root: H256([0u8; 32]),
transaction_root: H256(hex!("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")),
digest: Digest { logs: vec![], },
};