Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

fix substrate test runtime and broken ed25519 test #68

Merged
merged 7 commits into from
Feb 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
*.swp
polkadot/runtime/wasm/target/
substrate/executor/wasm/target/
substrate/test-runtime/wasm/target/
**/._*
29 changes: 29 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@ members = [
"substrate/rpc",
"substrate/runtime-io",
"substrate/runtime-std",
"substrate/runtime-support",
"substrate/serializer",
"substrate/state-machine",
"substrate/test-runtime",
]
exclude = [
"substrate/executor/wasm",
"polkadot/runtime/wasm",
"substrate/executor/wasm",
"substrate/pwasm-alloc",
"substrate/pwasm-libc",
"substrate/test-runtime/wasm",
]
5 changes: 5 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

cd substrate/executor/wasm && ./build.sh && cd ../../..
cd substrate/test-runtime/wasm && ./build.sh && cd ../../..
cd polkadot/runtime/wasm && ./build.sh && cd ../../..
4 changes: 2 additions & 2 deletions polkadot/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ extern crate error_chain;
#[macro_use]
extern crate log;

mod genesis;
pub mod error;

use codec::Slicable;
use polkadot_runtime::genesismap::{additional_storage_with_genesis, GenesisConfig};
use client::genesis;

/// Parse command line arguments and start the node.
///
Expand Down Expand Up @@ -83,7 +83,7 @@ pub fn run<I, T>(args: I) -> error::Result<()> where
storage = genesis_config.genesis_map();
let block = genesis::construct_genesis_block(&storage);
storage.extend(additional_storage_with_genesis(&block));
(primitives::block::Header::decode(&mut block.header.to_vec().as_ref()).expect("to_vec() always gives a valid serialisation; qed"), storage.into_iter().collect())
(primitives::block::Header::decode(&mut block.header.encode().as_ref()).expect("to_vec() always gives a valid serialisation; qed"), storage.into_iter().collect())
};
let client = client::new_in_mem(executor, prepare_genesis)?;

Expand Down
1 change: 1 addition & 0 deletions polkadot/executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ triehash = { version = "0.1" }
ed25519 = { path = "../../substrate/ed25519" }
substrate-codec = { path = "../../substrate/codec" }
substrate-runtime-io = { path = "../../substrate/runtime-io" }
substrate-runtime-support = { path = "../../substrate/runtime-support" }
substrate-state-machine = { path = "../../substrate/state-machine" }
substrate-executor = { path = "../../substrate/executor" }
substrate-primitives = { path = "../../substrate/primitives" }
Expand Down
44 changes: 22 additions & 22 deletions polkadot/executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ extern crate substrate_primitives as primitives;
extern crate polkadot_primitives as polkadot_primitives;
extern crate ed25519;
extern crate triehash;
#[cfg(test)]
#[macro_use]
extern crate hex_literal;

#[cfg(test)] extern crate substrate_runtime_support as runtime_support;
#[cfg(test)] #[macro_use] extern crate hex_literal;

use polkadot_runtime as runtime;
use substrate_executor::error::{Error, ErrorKind};
Expand Down Expand Up @@ -62,7 +62,7 @@ mod tests {
use super::*;
use substrate_executor::WasmExecutor;
use codec::{KeyedVec, Slicable, Joiner};
use polkadot_runtime::support::{one, two, Hashable};
use runtime_support::{one, two, Hashable};
use polkadot_runtime::runtime::staking::balance;
use state_machine::{CodeExecutor, TestExternalities};
use primitives::twox_128;
Expand All @@ -87,7 +87,7 @@ mod tests {
function: Function::StakingTransfer(two(), 69),
};
let signature = secret_for(&transaction.signed).unwrap()
.sign(&transaction.to_vec());
.sign(&transaction.encode());

UncheckedTransaction { transaction, signature }
}
Expand All @@ -99,7 +99,7 @@ mod tests {
twox_128(&one.to_keyed_vec(b"sta:bal:")).to_vec() => vec![68u8, 0, 0, 0, 0, 0, 0, 0]
], };

let r = executor().call(&mut t, BLOATY_CODE, "execute_transaction", &vec![].join(&Header::from_block_number(1u64)).join(&tx()));
let r = executor().call(&mut t, BLOATY_CODE, "execute_transaction", &vec![].and(&Header::from_block_number(1u64)).and(&tx()));
assert!(r.is_err());
}

Expand All @@ -110,7 +110,7 @@ mod tests {
twox_128(&one.to_keyed_vec(b"sta:bal:")).to_vec() => vec![68u8, 0, 0, 0, 0, 0, 0, 0]
], };

let r = executor().call(&mut t, COMPACT_CODE, "execute_transaction", &vec![].join(&Header::from_block_number(1u64)).join(&tx()));
let r = executor().call(&mut t, COMPACT_CODE, "execute_transaction", &vec![].and(&Header::from_block_number(1u64)).and(&tx()));
assert!(r.is_err());
}

Expand All @@ -123,7 +123,7 @@ mod tests {
twox_128(&one.to_keyed_vec(b"sta:bal:")).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0]
], };

let r = executor().call(&mut t, COMPACT_CODE, "execute_transaction", &vec![].join(&Header::from_block_number(1u64)).join(&tx()));
let r = executor().call(&mut t, COMPACT_CODE, "execute_transaction", &vec![].and(&Header::from_block_number(1u64)).and(&tx()));
assert!(r.is_ok());

runtime_io::with_externalities(&mut t, || {
Expand All @@ -141,7 +141,7 @@ mod tests {
twox_128(&one.to_keyed_vec(b"sta:bal:")).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0]
], };

let r = executor().call(&mut t, BLOATY_CODE, "execute_transaction", &vec![].join(&Header::from_block_number(1u64)).join(&tx()));
let r = executor().call(&mut t, BLOATY_CODE, "execute_transaction", &vec![].and(&Header::from_block_number(1u64)).and(&tx()));
assert!(r.is_ok());

runtime_io::with_externalities(&mut t, || {
Expand All @@ -156,20 +156,20 @@ mod tests {
let three = [3u8; 32];

TestExternalities { storage: map![
twox_128(&0u64.to_keyed_vec(b"sys:old:")).to_vec() => [69u8; 32].to_vec(),
twox_128(b"gov:apr").to_vec() => vec![].join(&667u32),
twox_128(b"ses:len").to_vec() => vec![].join(&2u64),
twox_128(b"ses:val:len").to_vec() => vec![].join(&3u32),
twox_128(&0u64.to_keyed_vec(b"sys:old:")).to_vec() => [69u8; 32].encode(),
twox_128(b"gov:apr").to_vec() => vec![].and(&667u32),
twox_128(b"ses:len").to_vec() => vec![].and(&2u64),
twox_128(b"ses:val:len").to_vec() => vec![].and(&3u32),
twox_128(&0u32.to_keyed_vec(b"ses:val:")).to_vec() => one.to_vec(),
twox_128(&1u32.to_keyed_vec(b"ses:val:")).to_vec() => two.to_vec(),
twox_128(&2u32.to_keyed_vec(b"ses:val:")).to_vec() => three.to_vec(),
twox_128(b"sta:wil:len").to_vec() => vec![].join(&3u32),
twox_128(b"sta:wil:len").to_vec() => vec![].and(&3u32),
twox_128(&0u32.to_keyed_vec(b"sta:wil:")).to_vec() => one.to_vec(),
twox_128(&1u32.to_keyed_vec(b"sta:wil:")).to_vec() => two.to_vec(),
twox_128(&2u32.to_keyed_vec(b"sta:wil:")).to_vec() => three.to_vec(),
twox_128(b"sta:spe").to_vec() => vec![].join(&2u64),
twox_128(b"sta:vac").to_vec() => vec![].join(&3u64),
twox_128(b"sta:era").to_vec() => vec![].join(&0u64),
twox_128(b"sta:spe").to_vec() => vec![].and(&2u64),
twox_128(b"sta:vac").to_vec() => vec![].and(&3u64),
twox_128(b"sta:era").to_vec() => vec![].and(&0u64),
twox_128(&one.to_keyed_vec(b"sta:bal:")).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0]
], }
}
Expand All @@ -187,12 +187,12 @@ mod tests {

let transactions = txs.into_iter().map(|transaction| {
let signature = secret_for(&transaction.signed).unwrap()
.sign(&transaction.to_vec());
.sign(&transaction.encode());

UncheckedTransaction { transaction, signature }
}).collect::<Vec<_>>();

let transaction_root = ordered_trie_root(transactions.iter().map(Slicable::to_vec)).0.into();
let transaction_root = ordered_trie_root(transactions.iter().map(Slicable::encode)).0.into();

let header = Header {
parent_hash,
Expand All @@ -203,7 +203,7 @@ mod tests {
};
let hash = header.blake2_256();

(Block { header, transactions }.to_vec(), hash.into())
(Block { header, transactions }.encode(), hash.into())
}

fn block1() -> (Vec<u8>, Hash) {
Expand Down Expand Up @@ -285,7 +285,7 @@ mod tests {
], };

let foreign_code = include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.wasm");
let r = WasmExecutor.call(&mut t, &foreign_code[..], "execute_transaction", &vec![].join(&Header::from_block_number(1u64)).join(&tx()));
let r = WasmExecutor.call(&mut t, &foreign_code[..], "execute_transaction", &vec![].and(&Header::from_block_number(1u64)).and(&tx()));
assert!(r.is_err());
}

Expand All @@ -299,7 +299,7 @@ mod tests {
], };

let foreign_code = include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.compact.wasm");
let r = WasmExecutor.call(&mut t, &foreign_code[..], "execute_transaction", &vec![].join(&Header::from_block_number(1u64)).join(&tx()));
let r = WasmExecutor.call(&mut t, &foreign_code[..], "execute_transaction", &vec![].and(&Header::from_block_number(1u64)).and(&tx()));
assert!(r.is_ok());

runtime_io::with_externalities(&mut t, || {
Expand Down
36 changes: 14 additions & 22 deletions polkadot/primitives/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ impl Slicable for Log {
Vec::<u8>::decode(input).map(Log)
}

fn as_slice_then<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
self.0.as_slice_then(f)
fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
self.0.using_encoded(f)
}
}

Expand All @@ -62,8 +62,8 @@ impl Slicable for Digest {
Vec::<Log>::decode(input).map(|logs| Digest { logs })
}

fn as_slice_then<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
self.logs.as_slice_then(f)
fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
self.logs.using_encoded(f)
}
}

Expand All @@ -86,18 +86,14 @@ impl Slicable for Block {
Some(Block { header, transactions })
}

fn to_vec(&self) -> Vec<u8> {
fn encode(&self) -> Vec<u8> {
let mut v = Vec::new();

v.extend(self.header.to_vec());
v.extend(self.transactions.to_vec());
v.extend(self.header.encode());
v.extend(self.transactions.encode());

v
}

fn as_slice_then<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
f(self.to_vec().as_slice())
}
}

/// A relay chain block header.
Expand Down Expand Up @@ -144,21 +140,17 @@ impl Slicable for Header {
})
}

fn to_vec(&self) -> Vec<u8> {
fn encode(&self) -> Vec<u8> {
let mut v = Vec::new();

self.parent_hash.as_slice_then(|s| v.extend(s));
self.number.as_slice_then(|s| v.extend(s));
self.state_root.as_slice_then(|s| v.extend(s));
self.transaction_root.as_slice_then(|s| v.extend(s));
self.digest.as_slice_then(|s| v.extend(s));
self.parent_hash.using_encoded(|s| v.extend(s));
self.number.using_encoded(|s| v.extend(s));
self.state_root.using_encoded(|s| v.extend(s));
self.transaction_root.using_encoded(|s| v.extend(s));
self.digest.using_encoded(|s| v.extend(s));

v
}

fn as_slice_then<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
f(self.to_vec().as_slice())
}
}

#[cfg(test)]
Expand Down Expand Up @@ -189,7 +181,7 @@ mod tests {
}
}"#);

let v = header.to_vec();
let v = header.encode();
assert_eq!(Header::decode(&mut &v[..]).unwrap(), header);
}
}
Loading