From f344e15bf896c04137f2be48fb99e3ee530c74ad Mon Sep 17 00:00:00 2001 From: Gav Wood <gavin@parity.io> Date: Mon, 12 Feb 2018 15:30:38 +0100 Subject: [PATCH] Additional runtime tests for the test-runtime (#69) * Remove rustc dependency from ed25519 and refactor a little. * Runtime support provides more extensive test-key functionality. * Additional APIs for ed25519 stuff. * Extensive test for test-runtime. * Fixes for the new test key API. * Additional convenience for tests * Take advantage of more convenient API. * Redo formating. * Remove old test identities. * Remove boilerplate, add test. * Refactor out unneeded code. * Clean up algo for determining authorities. * Remove unneeded API. * Make `to_*` consume * Only export keyring when testing * Fix build & warning * Extract Keyring into separate library. * Add tests for Keyring and a trait-based API. * Address grumbles. --- substrate/Cargo.lock | 16 ++- substrate/Cargo.toml | 1 + substrate/polkadot/api/src/lib.rs | 8 +- substrate/polkadot/cli/src/lib.rs | 2 +- substrate/polkadot/executor/Cargo.toml | 3 + substrate/polkadot/executor/src/lib.rs | 116 ++++++---------- substrate/polkadot/runtime/Cargo.toml | 3 + substrate/polkadot/runtime/src/lib.rs | 1 + .../runtime/src/runtime/governance.rs | 38 +++--- .../runtime/src/runtime/parachains.rs | 2 +- .../polkadot/runtime/src/runtime/session.rs | 2 +- .../polkadot/runtime/src/runtime/staking.rs | 18 +-- .../polkadot/runtime/src/runtime/system.rs | 22 +-- substrate/polkadot/runtime/wasm/Cargo.lock | 3 +- .../release/polkadot_runtime.compact.wasm | Bin 75751 -> 75751 bytes .../release/polkadot_runtime.wasm | Bin 75800 -> 75800 bytes substrate/substrate/client/Cargo.toml | 1 + substrate/substrate/client/src/backend.rs | 2 +- substrate/substrate/client/src/error.rs | 12 ++ substrate/substrate/client/src/genesis.rs | 81 +++--------- substrate/substrate/client/src/lib.rs | 53 +++++++- substrate/substrate/ed25519/Cargo.toml | 2 +- substrate/substrate/ed25519/src/lib.rs | 77 ++++++----- substrate/substrate/executor/src/lib.rs | 2 + .../substrate/executor/src/native_executor.rs | 37 +++++- substrate/substrate/keyring/Cargo.toml | 8 ++ substrate/substrate/keyring/src/lib.rs | 125 ++++++++++++++++++ .../substrate/runtime-support/Cargo.toml | 2 + .../substrate/runtime-support/src/lib.rs | 9 -- .../substrate/runtime-support/src/testing.rs | 28 ---- substrate/substrate/state-machine/src/lib.rs | 39 ------ substrate/substrate/test-runtime/Cargo.toml | 19 ++- substrate/substrate/test-runtime/src/lib.rs | 10 +- .../substrate/test-runtime/src/system.rs | 90 +++++++++++-- .../substrate/test-runtime/wasm/Cargo.lock | 5 +- .../substrate/test-runtime/wasm/Cargo.toml | 22 +-- .../substrate_test_runtime.compact.wasm | Bin 31904 -> 31904 bytes .../release/substrate_test_runtime.wasm | Bin 31984 -> 31984 bytes 38 files changed, 523 insertions(+), 336 deletions(-) create mode 100644 substrate/substrate/keyring/Cargo.toml create mode 100644 substrate/substrate/keyring/src/lib.rs delete mode 100644 substrate/substrate/runtime-support/src/testing.rs diff --git a/substrate/Cargo.lock b/substrate/Cargo.lock index a2d998ac449..6e54ac6c5e8 100644 --- a/substrate/Cargo.lock +++ b/substrate/Cargo.lock @@ -195,8 +195,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" name = "ed25519" version = "0.1.0" dependencies = [ + "hex-literal 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "ring 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-primitives 0.1.0", "untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1021,6 +1021,7 @@ dependencies = [ "polkadot-runtime 0.1.0", "substrate-codec 0.1.0", "substrate-executor 0.1.0", + "substrate-keyring 0.1.0", "substrate-primitives 0.1.0", "substrate-runtime-io 0.1.0", "substrate-runtime-support 0.1.0", @@ -1050,6 +1051,7 @@ dependencies = [ "polkadot-primitives 0.1.0", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-codec 0.1.0", + "substrate-keyring 0.1.0", "substrate-primitives 0.1.0", "substrate-runtime-io 0.1.0", "substrate-runtime-std 0.1.0", @@ -1387,6 +1389,7 @@ dependencies = [ "parking_lot 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-codec 0.1.0", "substrate-executor 0.1.0", + "substrate-keyring 0.1.0", "substrate-primitives 0.1.0", "substrate-runtime-support 0.1.0", "substrate-serializer 0.1.0", @@ -1424,6 +1427,14 @@ dependencies = [ "triehash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "substrate-keyring" +version = "0.1.0" +dependencies = [ + "ed25519 0.1.0", + "hex-literal 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "substrate-network" version = "0.1.0" @@ -1515,6 +1526,7 @@ dependencies = [ name = "substrate-runtime-support" version = "0.1.0" dependencies = [ + "ed25519 0.1.0", "environmental 0.1.0", "hex-literal 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-codec 0.1.0", @@ -1548,9 +1560,11 @@ dependencies = [ name = "substrate-test-runtime" version = "0.1.0" dependencies = [ + "ed25519 0.1.0", "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)", "substrate-codec 0.1.0", + "substrate-keyring 0.1.0", "substrate-primitives 0.1.0", "substrate-runtime-io 0.1.0", "substrate-runtime-std 0.1.0", diff --git a/substrate/Cargo.toml b/substrate/Cargo.toml index e46ed6d7252..b2378b684b1 100644 --- a/substrate/Cargo.toml +++ b/substrate/Cargo.toml @@ -25,6 +25,7 @@ members = [ "substrate/codec", "substrate/environmental", "substrate/executor", + "substrate/keyring", "substrate/network", "substrate/primitives", "substrate/rpc-servers", diff --git a/substrate/polkadot/api/src/lib.rs b/substrate/polkadot/api/src/lib.rs index c79295823a7..a16781eb69b 100644 --- a/substrate/polkadot/api/src/lib.rs +++ b/substrate/polkadot/api/src/lib.rs @@ -31,7 +31,7 @@ use client::backend::Backend; use client::blockchain::BlockId; use client::Client; use polkadot_runtime::runtime; -use polkadot_executor::LocalNativeExecutionDispatch as LocalDispatch; +use polkadot_executor::Executor as LocalDispatch; use substrate_executor::{NativeExecutionDispatch, NativeExecutor}; use primitives::{AccountId, SessionKey}; use primitives::parachain::DutyRoster; @@ -64,8 +64,8 @@ error_chain! { /// /// All calls should fail when the exact runtime is unknown. pub trait PolkadotApi { - /// Get authorities at a given block. - fn authorities(&self, at: &BlockId) -> Result<Vec<SessionKey>>; + /// Get session keys at a given block. + fn session_keys(&self, at: &BlockId) -> Result<Vec<SessionKey>>; /// Get validators at a given block. fn validators(&self, at: &BlockId) -> Result<Vec<AccountId>>; @@ -104,7 +104,7 @@ macro_rules! with_runtime { impl<B: Backend> PolkadotApi for Client<B, NativeExecutor<LocalDispatch>> where ::client::error::Error: From<<<B as Backend>::State as state_machine::backend::Backend>::Error> { - fn authorities(&self, at: &BlockId) -> Result<Vec<SessionKey>> { + fn session_keys(&self, at: &BlockId) -> Result<Vec<SessionKey>> { with_runtime!(self, at, ::runtime::consensus::authorities) } diff --git a/substrate/polkadot/cli/src/lib.rs b/substrate/polkadot/cli/src/lib.rs index 59e6ef270e1..807ff6c2cb8 100644 --- a/substrate/polkadot/cli/src/lib.rs +++ b/substrate/polkadot/cli/src/lib.rs @@ -65,7 +65,7 @@ pub fn run<I, T>(args: I) -> error::Result<()> where init_logger(log_pattern); // Create client - let executor = polkadot_executor::executor(); + let executor = polkadot_executor::Executor::new(); let mut storage = Default::default(); let god_key = hex!["3d866ec8a9190c8343c2fc593d21d8a6d0c5c4763aaab2349de3a6111d64d124"]; diff --git a/substrate/polkadot/executor/Cargo.toml b/substrate/polkadot/executor/Cargo.toml index 60cd4ee20d6..cca94287b0c 100644 --- a/substrate/polkadot/executor/Cargo.toml +++ b/substrate/polkadot/executor/Cargo.toml @@ -16,3 +16,6 @@ substrate-executor = { path = "../../substrate/executor" } substrate-primitives = { path = "../../substrate/primitives" } polkadot-primitives = { path = "../primitives" } polkadot-runtime = { path = "../runtime" } + +[dev-dependencies] +substrate-keyring = { path = "../../substrate/keyring" } diff --git a/substrate/polkadot/executor/src/lib.rs b/substrate/polkadot/executor/src/lib.rs index 7db96440a46..a7cef0c3cb3 100644 --- a/substrate/polkadot/executor/src/lib.rs +++ b/substrate/polkadot/executor/src/lib.rs @@ -18,7 +18,7 @@ //! executed is equivalent to the natively compiled code. extern crate polkadot_runtime; -extern crate substrate_executor; +#[macro_use] extern crate substrate_executor; extern crate substrate_codec as codec; extern crate substrate_state_machine as state_machine; extern crate substrate_runtime_io as runtime_io; @@ -27,48 +27,26 @@ extern crate polkadot_primitives as polkadot_primitives; extern crate ed25519; extern crate triehash; +#[cfg(test)] extern crate substrate_keyring as keyring; #[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}; -use substrate_executor::{NativeExecutionDispatch, NativeExecutor}; -use state_machine::Externalities; - -/// A null struct which implements `NativeExecutionDispatch` feeding in the hard-coded runtime. -pub struct LocalNativeExecutionDispatch; - -impl NativeExecutionDispatch for LocalNativeExecutionDispatch { - fn native_equivalent() -> &'static [u8] { - // WARNING!!! This assumes that the runtime was built *before* the main project. Until we - // get a proper build script, this must be strictly adhered to or things will go wrong. - include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.compact.wasm") - } - - fn dispatch(ext: &mut Externalities, method: &str, data: &[u8]) -> Result<Vec<u8>, Error> { - ::substrate_executor::with_native_environment(ext, move || runtime::api::dispatch(method, data))? - .ok_or_else(|| ErrorKind::MethodNotFound(method.to_owned()).into()) - } -} - -/// Creates new RustExecutor for contracts. -pub fn executor() -> NativeExecutor<LocalNativeExecutionDispatch> { - NativeExecutor { _dummy: ::std::marker::PhantomData } -} +native_executor_instance!(pub Executor, polkadot_runtime::api::dispatch, include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.compact.wasm")); #[cfg(test)] mod tests { use runtime_io; - use super::*; + use super::Executor; use substrate_executor::WasmExecutor; use codec::{KeyedVec, Slicable, Joiner}; - use runtime_support::{one, two, Hashable}; + use keyring::Keyring; + use runtime_support::Hashable; use polkadot_runtime::runtime::staking::balance; use state_machine::{CodeExecutor, TestExternalities}; use primitives::twox_128; use polkadot_primitives::{Hash, Header, BlockNumber, Block, Digest, Transaction, - UncheckedTransaction, Function, AccountId}; - use ed25519::Pair; + UncheckedTransaction, Function}; + use ed25519::{Public, Pair}; const BLOATY_CODE: &[u8] = include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.wasm"); const COMPACT_CODE: &[u8] = include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.compact.wasm"); @@ -82,11 +60,11 @@ mod tests { fn tx() -> UncheckedTransaction { let transaction = Transaction { - signed: one(), + signed: Keyring::One.to_raw_public(), nonce: 0, - function: Function::StakingTransfer(two(), 69), + function: Function::StakingTransfer(Keyring::Two.to_raw_public(), 69), }; - let signature = secret_for(&transaction.signed).unwrap() + let signature = Keyring::from_raw_public(transaction.signed).unwrap() .sign(&transaction.encode()); UncheckedTransaction { transaction, signature } @@ -94,36 +72,36 @@ mod tests { #[test] fn panic_execution_with_foreign_code_gives_error() { - let one = one(); + let one = Keyring::One.to_raw_public(); let mut t = TestExternalities { storage: map![ 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![].and(&Header::from_block_number(1u64)).and(&tx())); + let r = Executor::new().call(&mut t, BLOATY_CODE, "execute_transaction", &vec![].and(&Header::from_block_number(1u64)).and(&tx())); assert!(r.is_err()); } #[test] fn panic_execution_with_native_equivalent_code_gives_error() { - let one = one(); + let one = Keyring::One.to_raw_public(); let mut t = TestExternalities { storage: map![ 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![].and(&Header::from_block_number(1u64)).and(&tx())); + let r = Executor::new().call(&mut t, COMPACT_CODE, "execute_transaction", &vec![].and(&Header::from_block_number(1u64)).and(&tx())); assert!(r.is_err()); } #[test] fn successful_execution_with_native_equivalent_code_gives_ok() { - let one = one(); - let two = two(); + let one = Keyring::One.to_raw_public(); + let two = Keyring::Two.to_raw_public(); let mut t = TestExternalities { storage: map![ 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![].and(&Header::from_block_number(1u64)).and(&tx())); + let r = Executor::new().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, || { @@ -134,14 +112,14 @@ mod tests { #[test] fn successful_execution_with_foreign_code_gives_ok() { - let one = one(); - let two = two(); + let one = Keyring::One.to_raw_public(); + let two = Keyring::Two.to_raw_public(); let mut t = TestExternalities { storage: map![ 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![].and(&Header::from_block_number(1u64)).and(&tx())); + let r = Executor::new().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, || { @@ -151,8 +129,8 @@ mod tests { } fn new_test_ext() -> TestExternalities { - let one = one(); - let two = two(); + let one = Keyring::One.to_raw_public(); + let two = Keyring::Two.to_raw_public(); let three = [3u8; 32]; TestExternalities { storage: map![ @@ -174,19 +152,11 @@ mod tests { ], } } - 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()), - _ => None, - } - } - fn construct_block(number: BlockNumber, parent_hash: Hash, state_root: Hash, txs: Vec<Transaction>) -> (Vec<u8>, Hash) { use triehash::ordered_trie_root; let transactions = txs.into_iter().map(|transaction| { - let signature = secret_for(&transaction.signed).unwrap() + let signature = Pair::from(Keyring::from_public(Public::from_raw(transaction.signed)).unwrap()) .sign(&transaction.encode()); UncheckedTransaction { transaction, signature } @@ -212,9 +182,9 @@ mod tests { [69u8; 32].into(), hex!("2481853da20b9f4322f34650fea5f240dcbfb266d02db94bfa0153c31f4a29db").into(), vec![Transaction { - signed: one(), + signed: Keyring::One.to_raw_public(), nonce: 0, - function: Function::StakingTransfer(two(), 69), + function: Function::StakingTransfer(Keyring::Two.to_raw_public(), 69), }] ) } @@ -226,14 +196,14 @@ mod tests { hex!("1feb4d3a2e587079e6ce1685fa79994efd995e33cb289d39cded67aac1bb46a9").into(), vec![ Transaction { - signed: two(), + signed: Keyring::Two.to_raw_public(), nonce: 0, - function: Function::StakingTransfer(one(), 5), + function: Function::StakingTransfer(Keyring::One.to_raw_public(), 5), }, Transaction { - signed: one(), + signed: Keyring::One.to_raw_public(), nonce: 1, - function: Function::StakingTransfer(two(), 15), + function: Function::StakingTransfer(Keyring::Two.to_raw_public(), 15), } ] ) @@ -243,18 +213,18 @@ mod tests { fn full_native_block_import_works() { let mut t = new_test_ext(); - executor().call(&mut t, COMPACT_CODE, "execute_block", &block1().0).unwrap(); + Executor::new().call(&mut t, COMPACT_CODE, "execute_block", &block1().0).unwrap(); runtime_io::with_externalities(&mut t, || { - assert_eq!(balance(&one()), 42); - assert_eq!(balance(&two()), 69); + assert_eq!(balance(&Keyring::One.to_raw_public()), 42); + assert_eq!(balance(&Keyring::Two.to_raw_public()), 69); }); - executor().call(&mut t, COMPACT_CODE, "execute_block", &block2().0).unwrap(); + Executor::new().call(&mut t, COMPACT_CODE, "execute_block", &block2().0).unwrap(); runtime_io::with_externalities(&mut t, || { - assert_eq!(balance(&one()), 32); - assert_eq!(balance(&two()), 79); + assert_eq!(balance(&Keyring::One.to_raw_public()), 32); + assert_eq!(balance(&Keyring::Two.to_raw_public()), 79); }); } @@ -265,21 +235,21 @@ mod tests { WasmExecutor.call(&mut t, COMPACT_CODE, "execute_block", &block1().0).unwrap(); runtime_io::with_externalities(&mut t, || { - assert_eq!(balance(&one()), 42); - assert_eq!(balance(&two()), 69); + assert_eq!(balance(&Keyring::One.to_raw_public()), 42); + assert_eq!(balance(&Keyring::Two.to_raw_public()), 69); }); WasmExecutor.call(&mut t, COMPACT_CODE, "execute_block", &block2().0).unwrap(); runtime_io::with_externalities(&mut t, || { - assert_eq!(balance(&one()), 32); - assert_eq!(balance(&two()), 79); + assert_eq!(balance(&Keyring::One.to_raw_public()), 32); + assert_eq!(balance(&Keyring::Two.to_raw_public()), 79); }); } #[test] fn panic_execution_gives_error() { - let one = one(); + let one = Keyring::One.to_raw_public(); let mut t = TestExternalities { storage: map![ twox_128(&one.to_keyed_vec(b"sta:bal:")).to_vec() => vec![68u8, 0, 0, 0, 0, 0, 0, 0] ], }; @@ -291,8 +261,8 @@ mod tests { #[test] fn successful_execution_gives_ok() { - let one = one(); - let two = two(); + let one = Keyring::One.to_raw_public(); + let two = Keyring::Two.to_raw_public(); let mut t = TestExternalities { storage: map![ twox_128(&one.to_keyed_vec(b"sta:bal:")).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0] diff --git a/substrate/polkadot/runtime/Cargo.toml b/substrate/polkadot/runtime/Cargo.toml index c8decd0462d..4efe5c15e77 100644 --- a/substrate/polkadot/runtime/Cargo.toml +++ b/substrate/polkadot/runtime/Cargo.toml @@ -14,6 +14,9 @@ substrate-runtime-support = { path = "../../substrate/runtime-support" } substrate-primitives = { path = "../../substrate/primitives" } polkadot-primitives = { path = "../primitives" } +[dev-dependencies] +substrate-keyring = { path = "../../substrate/keyring" } + [features] default = ["std"] std = [ diff --git a/substrate/polkadot/runtime/src/lib.rs b/substrate/polkadot/runtime/src/lib.rs index 6eb3a259fe7..99aebd59902 100644 --- a/substrate/polkadot/runtime/src/lib.rs +++ b/substrate/polkadot/runtime/src/lib.rs @@ -21,6 +21,7 @@ extern crate substrate_runtime_std as rstd; #[macro_use] extern crate substrate_runtime_io as runtime_io; extern crate substrate_runtime_support as runtime_support; +#[cfg(all(feature = "std", test))] extern crate substrate_keyring as keyring; #[cfg(feature = "std")] extern crate rustc_hex; diff --git a/substrate/polkadot/runtime/src/runtime/governance.rs b/substrate/polkadot/runtime/src/runtime/governance.rs index 4ac1e17a339..b8733b9776a 100644 --- a/substrate/polkadot/runtime/src/runtime/governance.rs +++ b/substrate/polkadot/runtime/src/runtime/governance.rs @@ -147,14 +147,14 @@ mod tests { use super::*; use runtime_io::{with_externalities, twox_128, TestExternalities}; use codec::{KeyedVec, Joiner}; - use runtime_support::{one, two}; + use keyring::Keyring; use environment::with_env; use polkadot_primitives::{AccountId, Proposal}; use runtime::{staking, session}; fn new_test_ext() -> TestExternalities { - let one = one(); - let two = two(); + let one = Keyring::One.to_raw_public(); + let two = Keyring::Two.to_raw_public(); let three = [3u8; 32]; TestExternalities { storage: map![ @@ -176,8 +176,8 @@ mod tests { #[test] fn majority_voting_should_work() { - let one = one(); - let two = two(); + let one = Keyring::One.to_raw_public(); + let two = Keyring::Two.to_raw_public(); let three = [3u8; 32]; let mut t = new_test_ext(); @@ -199,8 +199,8 @@ mod tests { #[test] fn majority_voting_should_work_after_unsuccessful_previous() { - let one = one(); - let two = two(); + let one = Keyring::One.to_raw_public(); + let two = Keyring::Two.to_raw_public(); let three = [3u8; 32]; let mut t = new_test_ext(); @@ -228,8 +228,8 @@ mod tests { #[test] fn minority_voting_should_not_succeed() { - let one = one(); - let two = two(); + let one = Keyring::One.to_raw_public(); + let two = Keyring::Two.to_raw_public(); let three = [3u8; 32]; let mut t = new_test_ext(); @@ -251,8 +251,8 @@ mod tests { #[test] #[should_panic] fn old_voting_should_be_illegal() { - let one = one(); - let two = two(); + let one = Keyring::One.to_raw_public(); + let two = Keyring::Two.to_raw_public(); let three = [3u8; 32]; let mut t = new_test_ext(); @@ -275,8 +275,8 @@ mod tests { #[test] #[should_panic] fn double_voting_should_be_illegal() { - let one = one(); - let two = two(); + let one = Keyring::One.to_raw_public(); + let two = Keyring::Two.to_raw_public(); let three = [3u8; 32]; let mut t = new_test_ext(); @@ -300,8 +300,8 @@ mod tests { #[test] #[should_panic] fn over_proposing_should_be_illegal() { - let one = one(); - let two = two(); + let one = Keyring::One.to_raw_public(); + let two = Keyring::Two.to_raw_public(); let three = [3u8; 32]; let mut t = new_test_ext(); @@ -324,8 +324,8 @@ mod tests { #[test] #[should_panic] fn approving_without_proposal_should_be_illegal() { - let one = one(); - let two = two(); + let one = Keyring::One.to_raw_public(); + let two = Keyring::Two.to_raw_public(); let three = [3u8; 32]; let mut t = new_test_ext(); @@ -347,8 +347,8 @@ mod tests { #[test] #[should_panic] fn non_validator_approving_should_be_illegal() { - let one = one(); - let two = two(); + let one = Keyring::One.to_raw_public(); + let two = Keyring::Two.to_raw_public(); let three = [3u8; 32]; let four = [4u8; 32]; let mut t = new_test_ext(); diff --git a/substrate/polkadot/runtime/src/runtime/parachains.rs b/substrate/polkadot/runtime/src/runtime/parachains.rs index 56559ee3566..dd7485ddc83 100644 --- a/substrate/polkadot/runtime/src/runtime/parachains.rs +++ b/substrate/polkadot/runtime/src/runtime/parachains.rs @@ -79,7 +79,7 @@ mod tests { use super::*; use runtime_io::{with_externalities, twox_128, TestExternalities}; use codec::{KeyedVec, Joiner}; - use runtime_support::{one, two}; + use keyring::Keyring; use runtime::{consensus, session}; fn simple_setup() -> TestExternalities { diff --git a/substrate/polkadot/runtime/src/runtime/session.rs b/substrate/polkadot/runtime/src/runtime/session.rs index 9252e9774d5..a3a43d88cc1 100644 --- a/substrate/polkadot/runtime/src/runtime/session.rs +++ b/substrate/polkadot/runtime/src/runtime/session.rs @@ -139,7 +139,7 @@ mod tests { use super::internal::*; use runtime_io::{with_externalities, twox_128, TestExternalities}; use codec::{KeyedVec, Joiner}; - use runtime_support::{one, two}; + use keyring::Keyring; use environment::with_env; use polkadot_primitives::AccountId; use runtime::{consensus, session}; diff --git a/substrate/polkadot/runtime/src/runtime/staking.rs b/substrate/polkadot/runtime/src/runtime/staking.rs index b281bc5cd50..a66d43eeb90 100644 --- a/substrate/polkadot/runtime/src/runtime/staking.rs +++ b/substrate/polkadot/runtime/src/runtime/staking.rs @@ -215,15 +215,15 @@ mod tests { use runtime_io::{with_externalities, twox_128, TestExternalities}; use codec::{KeyedVec, Joiner}; - use runtime_support::{one, two}; + use keyring::Keyring; use environment::with_env; use polkadot_primitives::AccountId; use runtime::{staking, session}; #[test] fn staking_should_work() { - let one = one(); - let two = two(); + let one = Keyring::One.to_raw_public(); + let two = Keyring::Two.to_raw_public(); let three = [3u8; 32]; let four = [4u8; 32]; @@ -360,8 +360,8 @@ mod tests { #[test] fn staking_balance_works() { - let one = one(); - let two = two(); + let one = Keyring::One.to_raw_public(); + let two = Keyring::Two.to_raw_public(); let mut t = TestExternalities { storage: map![ twox_128(&one.to_keyed_vec(BALANCE_OF)).to_vec() => vec![].and(&42u64) @@ -375,8 +375,8 @@ mod tests { #[test] fn staking_balance_transfer_works() { - let one = one(); - let two = two(); + let one = Keyring::One.to_raw_public(); + let two = Keyring::Two.to_raw_public(); let mut t = TestExternalities { storage: map![ twox_128(&one.to_keyed_vec(BALANCE_OF)).to_vec() => vec![].and(&111u64) @@ -392,8 +392,8 @@ mod tests { #[test] #[should_panic] fn staking_balance_transfer_when_bonded_doesnt_work() { - let one = one(); - let two = two(); + let one = Keyring::One.to_raw_public(); + let two = Keyring::Two.to_raw_public(); let mut t = TestExternalities { storage: map![ twox_128(&one.to_keyed_vec(BALANCE_OF)).to_vec() => vec![].and(&111u64) diff --git a/substrate/polkadot/runtime/src/runtime/system.rs b/substrate/polkadot/runtime/src/runtime/system.rs index 2a8519a6832..2f8f5c25c71 100644 --- a/substrate/polkadot/runtime/src/runtime/system.rs +++ b/substrate/polkadot/runtime/src/runtime/system.rs @@ -236,7 +236,7 @@ mod tests { use runtime_io::{with_externalities, twox_128, TestExternalities}; use codec::{Joiner, KeyedVec, Slicable}; - use runtime_support::{one, two}; + use keyring::Keyring; use environment::with_env; use primitives::hexdisplay::HexDisplay; use polkadot_primitives::{Header, Digest, UncheckedTransaction, Transaction, Function}; @@ -244,8 +244,8 @@ mod tests { #[test] fn staking_balance_transfer_dispatch_works() { - let one = one(); - let two = two(); + let one = Keyring::One.to_raw_public(); + let two = Keyring::Two.to_raw_public(); let mut t = TestExternalities { storage: map![ twox_128(&one.to_keyed_vec(b"sta:bal:")).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0] @@ -268,8 +268,8 @@ mod tests { } fn new_test_ext() -> TestExternalities { - let one = one(); - let two = two(); + let one = Keyring::One.to_raw_public(); + let two = Keyring::Two.to_raw_public(); let three = [3u8; 32]; TestExternalities { storage: map![ @@ -293,8 +293,8 @@ mod tests { #[test] fn block_import_works() { - let one = one(); - let two = two(); + let one = Keyring::One.to_raw_public(); + let two = Keyring::Two.to_raw_public(); let mut t = new_test_ext(); @@ -319,8 +319,8 @@ mod tests { #[test] #[should_panic] fn block_import_of_bad_state_root_fails() { - let one = one(); - let two = two(); + let one = Keyring::One.to_raw_public(); + let two = Keyring::Two.to_raw_public(); let mut t = new_test_ext(); @@ -345,8 +345,8 @@ mod tests { #[test] #[should_panic] fn block_import_of_bad_transaction_root_fails() { - let one = one(); - let two = two(); + let one = Keyring::One.to_raw_public(); + let two = Keyring::Two.to_raw_public(); let mut t = new_test_ext(); diff --git a/substrate/polkadot/runtime/wasm/Cargo.lock b/substrate/polkadot/runtime/wasm/Cargo.lock index df8296ff092..11fe2d48f84 100644 --- a/substrate/polkadot/runtime/wasm/Cargo.lock +++ b/substrate/polkadot/runtime/wasm/Cargo.lock @@ -92,8 +92,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" name = "ed25519" version = "0.1.0" dependencies = [ + "hex-literal 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "ring 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-primitives 0.1.0", "untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -643,6 +643,7 @@ dependencies = [ name = "substrate-runtime-support" version = "0.1.0" dependencies = [ + "ed25519 0.1.0", "environmental 0.1.0", "hex-literal 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-codec 0.1.0", diff --git a/substrate/polkadot/runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.compact.wasm b/substrate/polkadot/runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.compact.wasm index 0382155efe00b8a70216123aa970a4038d6981b4..b4b77e5ec9e4c2a74a57d38ded342bd8de036607 100644 GIT binary patch delta 4199 zcmaJ^4RjRM6`uDto1N@rHv{C4gs^XS^D{|E0;n-YMJAXCVlaZJfHf@10vp06?k+!; zzy^O~563Qj9EY|X4K=`?<08=sHC3x?MTyv!?KvEqwwCU(R98!n>k+M5`*YvSX0!Oy zBs2HjpLgH8_kH)i$@^!s-anf)YQl5OR{h6lG-AvPD39lPGtXNwvLfolD}p!7a_@9^ zZ40<N13s76@9GM8`n=p?>qd{))$8%QJ2&+9b#39~yzRhty8?Z_&aS>~-T>EPPD}jU z62Y}Cu({9Y33%Lo?na?|Tj0J<U!OnV_HnH_d5DuaA!l7}RZT;sRNrp?P{~^U8`w_} z(Ij4omQkl+2;EL2h7z<)J#Ban;Snd@WxNvIOh=8CIBcVnMuP58zcBi7N*0mQvL#sk z!W=HdBZNL>e~^)C$74X$UpT5UqZi5_n2E=T>bZI-3y(?klWRXjqxAfB-$yIdHP_b| z&|T_-izS4T>T$UYp#*)a<?h*Ik{pp_UbK-s3C9f%1EUFpcqd)FWbFTHo$CA>n-B_7 zPwPFMq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6LlM(2kaM1oCxYxmvtX+<d*bFz~Fn`H(U=F_;ZS z{N1qDQx1Z55~Rg(+Cwqz6lhyOyCzOsAJc~O`86(|&+YXq6)VuH?4g4Ho#3R>y8_(< z(3n_(R<0UZ$!G3|Guh(e`eSh?S4Pg??1A%#loh$ieplxzz%;n9(Tk?>B&>Bv2UhXI z5NPKQ^pJ8Q7dcQ!c{La1cXSu>LQ94|?5}|*8&ggW#7SQV!D>x90MZcH&W|?|C!M<> z#tZq(ez45~&md3$0Cx%QCyN#-6pas;1os@=D%qMiT*&7rPvoL3rQLy&P`~n&1Bp0T P^nw*-;!qL0F6{pW*cvQ9 diff --git a/substrate/polkadot/runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.wasm b/substrate/polkadot/runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.wasm index 442401ac0613bef04e94de5eb6f253a90fd084d7..2b5124161a1f76f50f483c1c8bf74aa9942dd88a 100644 GIT binary patch delta 4193 zcmaJ^dvH@#8o%eHY0}<4Zs{xZm6O|)-nP(M7b{e;y~TDx9##=7=(L13l$6qxBoxp> zi;vyPvTpF;rlZUXW0lNUZ1k2TGwbd~MXB!W5}l5AX2s1P=ya7`!;U)4!alxpZxVvK z+iCKh?|IJmo!|G}oAGeUcsM0s#3kuj+Miyp$JofDY@^YbZZu|Ll!d4jyGNRH?fdNA zdp!0okIOdTwsm_P&H+x&+U^*z^*h}5u5JC!?wwpq_7Jc=HjmTQ)$QCf;Ne!LCnRp} zZr--Xv%~3fcpP>&*UI<o@$Bz%Io%$+i)%~EMx4y?X%8=!YHq2ls#~A_jW1>GAK^SB zh!*H>MfcFvy0MatBu&CrODZG8f=L=N5}kxOQ7_!1{7v^d!V~56q<$${LqF0l!hSRT zx1OK}6?3W^$7GXILbehsW?m`46NJuMo?v8)_%smZ3$Y3_nqTqw0z6HW=WZWM!P648 z-uVRz(CihDpnH|WE2?#9vvQ_cLMW<yDwiTOPp`K;yl`5QCneb^m`S#TBRWyX=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B1WscR5^MJ>@Uo%_EXTVi#2Ep%AZ6LjeLXey*rL)GFzs&f7S>xeL zHngNWQl>SK(;tB3mTAd_O~8^{1|fqIYo};J-wkIi<QQ-#fC{fZDel85?j&&iz+IKb z^`y8nW&A2<Fz611!kx>|ilS)w{|;~>{Pr?*JG90(%h2)_W6SycJ>Ziy&2A`VcVc<M zf1elpkB4`bAlt1yE1-8lg^gG;jK|=twQghuFGPVmcW|TO*GiBb+VaB^RMy>B!3+LH z+ED)*G}$<EawLuVTOh1dslz~xgX~;;V`<dcMKE5$=MRBwA!x<`LIZH`!G_9KEya`e mVO?|2!1gFo$ukw<<96_EDEx*Ui8xjnUS&b~I9|yXg6+S&@Gj^8 diff --git a/substrate/substrate/client/Cargo.toml b/substrate/substrate/client/Cargo.toml index be11c172333..b9e0135b9e9 100644 --- a/substrate/substrate/client/Cargo.toml +++ b/substrate/substrate/client/Cargo.toml @@ -17,3 +17,4 @@ substrate-runtime-support = { path = "../runtime-support" } substrate-serializer = { path = "../serializer" } substrate-state-machine = { path = "../state-machine" } substrate-test-runtime = { path = "../test-runtime" } +substrate-keyring = { path = "../../substrate/keyring" } diff --git a/substrate/substrate/client/src/backend.rs b/substrate/substrate/client/src/backend.rs index 0eb12cf18b2..fad0f203e8c 100644 --- a/substrate/substrate/client/src/backend.rs +++ b/substrate/substrate/client/src/backend.rs @@ -21,7 +21,7 @@ use error; use primitives::block; use blockchain::{self, BlockId}; -/// Block insertion transction. Keeps hold if the inseted block state and data. +/// Block insertion transction. Keeps hold if the inserted block state and data. pub trait BlockImportOperation { /// Associated state backend type. type State: state_machine::backend::Backend; diff --git a/substrate/substrate/client/src/error.rs b/substrate/substrate/client/src/error.rs index 0059804914e..1c97387e817 100644 --- a/substrate/substrate/client/src/error.rs +++ b/substrate/substrate/client/src/error.rs @@ -45,6 +45,18 @@ error_chain! { description("Blockchain error"), display("Blockchain: {}", e), } + + /// Invalid state data. + AuthLen { + description("authority count state error"), + display("Current state of blockchain has invalid authority count value"), + } + + /// Invalid state data. + Auth(i: u32) { + description("authority value state error"), + display("Current state of blockchain has invalid authority value for index {}", i), + } } } diff --git a/substrate/substrate/client/src/genesis.rs b/substrate/substrate/client/src/genesis.rs index ba4a30741b4..fb3e228d03f 100644 --- a/substrate/substrate/client/src/genesis.rs +++ b/substrate/substrate/client/src/genesis.rs @@ -40,49 +40,23 @@ pub fn construct_genesis_block(storage: &HashMap<Vec<u8>, Vec<u8>>) -> Block { mod tests { use super::*; use codec::{Slicable, Joiner}; - use runtime_support::{one, two, Hashable}; + use runtime_support::Hashable; + use keyring::Keyring; use test_runtime::genesismap::{GenesisConfig, additional_storage_with_genesis}; - use executor::{NativeExecutionDispatch, NativeExecutor, WasmExecutor, with_native_environment, - error}; - use state_machine::{execute, Externalities, OverlayedChanges}; + use executor::WasmExecutor; + use state_machine::{execute, OverlayedChanges}; use state_machine::backend::InMemory; - use test_runtime::{self, AccountId, Hash, Block, BlockNumber, Header, Digest, Transaction, + use test_runtime::{self, Hash, Block, BlockNumber, Header, Digest, Transaction, UncheckedTransaction}; - use ed25519::Pair; + use ed25519::{Public, Pair}; - /// A null struct which implements `NativeExecutionDispatch` feeding in the hard-coded runtime. - pub struct LocalNativeExecutionDispatch; - - impl NativeExecutionDispatch for LocalNativeExecutionDispatch { - fn native_equivalent() -> &'static [u8] { - // WARNING!!! This assumes that the runtime was built *before* the main project. Until we - // get a proper build script, this must be strictly adhered to or things will go wrong. - include_bytes!("../../test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm") - } - - fn dispatch(ext: &mut Externalities, method: &str, data: &[u8]) -> error::Result<Vec<u8>> { - with_native_environment(ext, move || test_runtime::apis::dispatch(method, data))? - .ok_or_else(|| error::ErrorKind::MethodNotFound(method.to_owned()).into()) - } - } - - fn executor() -> NativeExecutor<LocalNativeExecutionDispatch> { - NativeExecutor { _dummy: Default::default() } - } - - 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()), - _ => None, - } - } + native_executor_instance!(Executor, test_runtime::api::dispatch, include_bytes!("../../test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm")); fn construct_block(backend: &InMemory, number: BlockNumber, parent_hash: Hash, state_root: Hash, txs: Vec<Transaction>) -> (Vec<u8>, Hash) { use triehash::ordered_trie_root; let transactions = txs.into_iter().map(|tx| { - let signature = secret_for(&tx.from).unwrap() + let signature = Pair::from(Keyring::from_public(Public::from_raw(tx.from)).unwrap()) .sign(&tx.encode()); UncheckedTransaction { tx, signature } @@ -105,7 +79,7 @@ mod tests { let ret_data = execute( backend, &mut overlay, - &executor(), + &Executor::new(), "execute_transaction", &vec![].and(&header).and(tx) ).unwrap(); @@ -115,7 +89,7 @@ mod tests { let ret_data = execute( backend, &mut overlay, - &executor(), + &Executor::new(), "finalise_block", &vec![].and(&header) ).unwrap(); @@ -131,8 +105,8 @@ mod tests { genesis_hash, hex!("25e5b37074063ab75c889326246640729b40d0c86932edc527bc80db0e04fe5c").into(), vec![Transaction { - from: one(), - to: two(), + from: Keyring::One.to_raw_public(), + to: Keyring::Two.to_raw_public(), amount: 69, nonce: 0, }] @@ -142,65 +116,52 @@ mod tests { #[test] fn construct_genesis_should_work() { let mut storage = GenesisConfig::new_simple( - vec![one(), two()], 1000 + vec![Keyring::One.to_raw_public(), Keyring::Two.to_raw_public()], 1000 ).genesis_map(); let block = construct_genesis_block(&storage); let genesis_hash = block.header.blake2_256().into(); storage.extend(additional_storage_with_genesis(&block).into_iter()); - let mut overlay = OverlayedChanges::default(); let backend = InMemory::from(storage); let (b1data, _b1hash) = block1(genesis_hash, &backend); + let mut overlay = OverlayedChanges::default(); let _ = execute( &backend, &mut overlay, - &executor(), + &Executor::new(), "execute_block", &b1data ).unwrap(); - } - - #[test] - #[should_panic] - fn construct_genesis_with_bad_transaction_should_panic() { - let mut storage = GenesisConfig::new_simple( - vec![one(), two()], 68 - ).genesis_map(); - let block = construct_genesis_block(&storage); - let genesis_hash = block.header.blake2_256().into(); - storage.extend(additional_storage_with_genesis(&block).into_iter()); let mut overlay = OverlayedChanges::default(); - let backend = InMemory::from(storage); - let (b1data, _b1hash) = block1(genesis_hash, &backend); - let _ = execute( &backend, &mut overlay, - &executor(), + &WasmExecutor, "execute_block", &b1data ).unwrap(); } #[test] - fn construct_genesis_should_work_under_wasm() { + #[should_panic] + fn construct_genesis_with_bad_transaction_should_panic() { let mut storage = GenesisConfig::new_simple( - vec![one(), two()], 1000 + vec![Keyring::One.to_raw_public(), Keyring::Two.to_raw_public()], 68 ).genesis_map(); let block = construct_genesis_block(&storage); let genesis_hash = block.header.blake2_256().into(); storage.extend(additional_storage_with_genesis(&block).into_iter()); - let mut overlay = OverlayedChanges::default(); let backend = InMemory::from(storage); let (b1data, _b1hash) = block1(genesis_hash, &backend); + let mut overlay = OverlayedChanges::default(); let _ = execute( &backend, &mut overlay, - &WasmExecutor, + &Executor::new(), "execute_block", &b1data ).unwrap(); diff --git a/substrate/substrate/client/src/lib.rs b/substrate/substrate/client/src/lib.rs index 951eafbb26a..530288ca29e 100644 --- a/substrate/substrate/client/src/lib.rs +++ b/substrate/substrate/client/src/lib.rs @@ -22,10 +22,11 @@ extern crate substrate_primitives as primitives; extern crate substrate_state_machine as state_machine; extern crate substrate_serializer as ser; extern crate substrate_codec as codec; -extern crate substrate_executor as executor; +#[cfg(test)] #[macro_use] extern crate substrate_executor as executor; extern crate ed25519; #[cfg(test)] extern crate substrate_runtime_support as runtime_support; #[cfg(test)] extern crate substrate_test_runtime as test_runtime; +#[cfg(test)] extern crate substrate_keyring as keyring; extern crate triehash; extern crate parking_lot; @@ -42,8 +43,9 @@ pub mod genesis; pub use blockchain::Info as ChainInfo; pub use blockchain::BlockId; -use primitives::block; +use primitives::{block, AuthorityId}; use primitives::storage::{StorageKey, StorageData}; +use codec::{KeyedVec, Slicable}; use blockchain::Backend as BlockchainBackend; use backend::BlockImportOperation; @@ -162,7 +164,18 @@ impl<B, E> Client<B, E> where /// Get the code at a given block. pub fn code_at(&self, id: &BlockId) -> error::Result<Vec<u8>> { - self.storage(id, &StorageKey(b":code:".to_vec())).map(|data| data.0) + self.storage(id, &StorageKey(b":code".to_vec())).map(|data| data.0) + } + + /// Get the current set of authorities from storage. + pub fn authorities_at(&self, id: &BlockId) -> error::Result<Vec<AuthorityId>> { + let state = self.state_at(id)?; + (0..u32::decode(&mut state.storage(b":auth:len")?).ok_or(error::ErrorKind::AuthLen)?) + .map(|i| state.storage(&i.to_keyed_vec(b":auth:")) + .map_err(|_| error::ErrorKind::Backend) + .and_then(|mut s| AuthorityId::decode(&mut s).ok_or(error::ErrorKind::Auth(i))) + .map_err(Into::into) + ).collect() } /// Execute a call to a contract on top of state in a block of given hash. @@ -235,3 +248,37 @@ impl<B, E> Client<B, E> where self.backend.blockchain().body(*id) } } + +#[cfg(test)] +mod tests { + use super::*; + use codec::Slicable; + use keyring::Keyring; + use test_runtime::genesismap::{GenesisConfig, additional_storage_with_genesis}; + use test_runtime; + + native_executor_instance!(Executor, test_runtime::api::dispatch, include_bytes!("../../test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm")); + + #[test] + fn authorities_call_works() { + let genesis_config = GenesisConfig::new_simple(vec![ + Keyring::Alice.to_raw_public(), + Keyring::Bob.to_raw_public(), + Keyring::Charlie.to_raw_public() + ], 1000); + + let prepare_genesis = || { + let mut 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.encode().as_ref()).expect("to_vec() always gives a valid serialisation; qed"), storage.into_iter().collect()) + }; + let client = new_in_mem(Executor::new(), prepare_genesis).unwrap(); + + assert_eq!(client.authorities_at(&BlockId::Number(0)).unwrap(), vec![ + Keyring::Alice.to_raw_public(), + Keyring::Bob.to_raw_public(), + Keyring::Charlie.to_raw_public() + ]); + } +} diff --git a/substrate/substrate/ed25519/Cargo.toml b/substrate/substrate/ed25519/Cargo.toml index 6d11f67920f..1241bd69bf1 100644 --- a/substrate/substrate/ed25519/Cargo.toml +++ b/substrate/substrate/ed25519/Cargo.toml @@ -7,4 +7,4 @@ authors = ["Parity Technologies <admin@parity.io>"] ring = "0.12" untrusted = "0.5" substrate-primitives = { version = "0.1", path = "../primitives" } -rustc-hex = "1.0" +hex-literal = "0.1" diff --git a/substrate/substrate/ed25519/src/lib.rs b/substrate/substrate/ed25519/src/lib.rs index 287d83e36d9..4953aa95744 100644 --- a/substrate/substrate/ed25519/src/lib.rs +++ b/substrate/substrate/ed25519/src/lib.rs @@ -19,11 +19,10 @@ extern crate ring; extern crate substrate_primitives as primitives; extern crate untrusted; -extern crate rustc_hex; +#[macro_use] extern crate hex_literal; use ring::{rand, signature}; use primitives::hash::H512; -use rustc_hex::FromHex; /// Alias to 520-bit hash when used in the context of a signature on the relay chain. pub type Signature = H512; @@ -49,7 +48,7 @@ pub struct Pair(signature::Ed25519KeyPair); impl Public { /// A new instance from the given 32-byte `data`. - pub fn from(data: [u8; 32]) -> Self { + pub fn from_raw(data: [u8; 32]) -> Self { Public(data) } @@ -59,6 +58,23 @@ impl Public { r.copy_from_slice(data); Public(r) } + + /// Return a `Vec<u8>` filled with raw data. + pub fn to_raw_vec(self) -> Vec<u8> { + let r: &[u8; 32] = self.as_ref(); + r.to_vec() + } + + /// Return a slice filled with raw data. + pub fn as_slice(&self) -> &[u8] { + let r: &[u8; 32] = self.as_ref(); + &r[..] + } + + /// Return a slice filled with raw data. + pub fn as_array_ref(&self) -> &[u8; 32] { + self.as_ref() + } } impl AsRef<[u8; 32]> for Public { @@ -80,31 +96,29 @@ impl Pair { let pkcs8_bytes = signature::Ed25519KeyPair::generate_pkcs8(&rng).unwrap(); Pair(signature::Ed25519KeyPair::from_pkcs8(untrusted::Input::from(&pkcs8_bytes)).unwrap()) } + /// Make a new key pair from a seed phrase. pub fn from_seed(seed: &[u8; 32]) -> Pair { Pair(signature::Ed25519KeyPair::from_seed_unchecked(untrusted::Input::from(&seed[..])).unwrap()) } - /// Make a new key pair from the raw secret. - pub fn from_secret(secret: &[u8; 32]) -> Pair { - let mut pkcs8_bytes: Vec<_> = FromHex::from_hex("302e020100300506032b657004220420").unwrap(); - pkcs8_bytes.extend_from_slice(&secret[..]); - Pair(signature::Ed25519KeyPair::from_pkcs8_maybe_unchecked(untrusted::Input::from(&pkcs8_bytes)).unwrap()) - } + /// Make a new key pair from the raw secret and public key (it will check to make sure /// they correspond to each other). pub fn from_both(secret_public: &[u8; 64]) -> Option<Pair> { - let mut pkcs8_bytes: Vec<_> = FromHex::from_hex("3053020101300506032b657004220420").unwrap(); + let mut pkcs8_bytes: Vec<_> = hex!("3053020101300506032b657004220420").to_vec(); pkcs8_bytes.extend_from_slice(&secret_public[0..32]); pkcs8_bytes.extend_from_slice(&[0xa1u8, 0x23, 0x03, 0x21, 0x00]); pkcs8_bytes.extend_from_slice(&secret_public[32..64]); signature::Ed25519KeyPair::from_pkcs8_maybe_unchecked(untrusted::Input::from(&pkcs8_bytes)).ok().map(Pair) } + /// Sign a message. pub fn sign(&self, message: &[u8]) -> Signature { let mut r = [0u8; 64]; r.copy_from_slice(self.0.sign(message).as_ref()); Signature::from(r) } + /// Get the public key. pub fn public(&self) -> Public { let mut r = [0u8; 32]; @@ -126,32 +140,15 @@ pub fn verify_strong(sig: &Signature, message: &[u8], pubkey: &Public) -> bool { } } -impl From<&'static str> for Public { - fn from(hex: &'static str) -> Self { - let mut r = [0u8; 32]; - let v: Vec<_> = FromHex::from_hex(hex).unwrap(); - r.copy_from_slice(&v[0..32]); - Public(r) - } +pub trait Verifiable { + /// Verify something that acts like a signature. + fn verify(&self, message: &[u8], pubkey: &Public) -> bool; } -impl From<&'static str> for Pair { - fn from(hex: &'static str) -> Self { - let data: Vec<_> = FromHex::from_hex(hex).expect("Key pair given is static so hex should be good."); - match data.len() { - 32 => { - let mut r = [0u8; 32]; - r.copy_from_slice(&data[0..32]); - Pair::from_secret(&r) - } - 64 => { - let mut r = [0u8; 64]; - r.copy_from_slice(&data[0..64]); - Pair::from_both(&r).expect("Key pair given is static so should be good.") - } - _ => { - panic!("Key pair given is static so should be correct length."); - } - } + +impl Verifiable for Signature { + /// Verify something that acts like a signature. + fn verify(&self, message: &[u8], pubkey: &Public) -> bool { + verify_strong(&self, message, pubkey) } } @@ -161,11 +158,11 @@ mod test { #[test] fn test_vector_should_work() { - let pair: Pair = "9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60".into(); + let pair: Pair = Pair::from_seed(&hex!("9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60")); let public = pair.public(); - assert_eq!(public, "d75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a".into()); + assert_eq!(public, Public::from_raw(hex!("d75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a"))); let message = b""; - let signature: Signature = "e5564300c360ac729086e2cc806e828a84877f1eb8e5d974d873e065224901555fb8821590a33bacc61e39701cf9b46bd25bf5f0595bbe24655141438e7a100b".into(); + let signature: Signature = hex!("e5564300c360ac729086e2cc806e828a84877f1eb8e5d974d873e065224901555fb8821590a33bacc61e39701cf9b46bd25bf5f0595bbe24655141438e7a100b").into(); assert!(&pair.sign(&message[..]) == &signature); assert!(verify_strong(&signature, &message[..], &public)); } @@ -185,8 +182,8 @@ mod test { let pair = Pair::from_seed(b"12345678901234567890123456789012"); let public = pair.public(); - assert_eq!(public, "2f8c6129d816cf51c374bc7f08c3e63ed156cf78aefb4a6550d97b87997977ee".into()); - let message: Vec<_> = FromHex::from_hex("2f8c6129d816cf51c374bc7f08c3e63ed156cf78aefb4a6550d97b87997977ee00000000000000002228000000d75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a4500000000000000").unwrap(); + assert_eq!(public, Public::from_raw(hex!("2f8c6129d816cf51c374bc7f08c3e63ed156cf78aefb4a6550d97b87997977ee"))); + let message = hex!("2f8c6129d816cf51c374bc7f08c3e63ed156cf78aefb4a6550d97b87997977ee00000000000000002228000000d75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a4500000000000000"); let signature = pair.sign(&message[..]); println!("Correct signature: {}", HexDisplay::from(&signature.0)); assert!(verify_strong(&signature, &message[..], &public)); diff --git a/substrate/substrate/executor/src/lib.rs b/substrate/substrate/executor/src/lib.rs index d520048e749..1b4588db87c 100644 --- a/substrate/substrate/executor/src/lib.rs +++ b/substrate/substrate/executor/src/lib.rs @@ -57,8 +57,10 @@ macro_rules! map { #[macro_use] mod wasm_utils; mod wasm_executor; +#[macro_use] mod native_executor; pub mod error; pub use wasm_executor::WasmExecutor; pub use native_executor::{with_native_environment, NativeExecutor, NativeExecutionDispatch}; +pub use state_machine::Externalities; diff --git a/substrate/substrate/executor/src/native_executor.rs b/substrate/substrate/executor/src/native_executor.rs index 0855e78e858..99773b9f761 100644 --- a/substrate/substrate/executor/src/native_executor.rs +++ b/substrate/substrate/executor/src/native_executor.rs @@ -15,7 +15,7 @@ // along with Substrate. If not, see <http://www.gnu.org/licenses/>. use error::{Error, ErrorKind, Result}; -use state_machine::{Externalities, CodeExecutor}; +use state_machine::{CodeExecutor, Externalities}; use wasm_executor::WasmExecutor; fn safe_call<F, U>(f: F) -> Result<U> @@ -45,6 +45,7 @@ pub trait NativeExecutionDispatch { /// A generic `CodeExecutor` implementation that uses a delegate to determine wasm code equivalence /// and dispatch to native code when possible, falling back on `WasmExecutor` when not. +#[derive(Default)] pub struct NativeExecutor<D: NativeExecutionDispatch + Sync + Send> { /// Dummy field to avoid the compiler complaining about us not using `D`. pub _dummy: ::std::marker::PhantomData<D>, @@ -69,3 +70,37 @@ impl<D: NativeExecutionDispatch + Sync + Send> CodeExecutor for NativeExecutor<D } } } + +#[macro_export] +macro_rules! native_executor_instance { + (pub $name:ident, $dispatcher:path, $code:expr) => { + pub struct $name; + native_executor_instance!(IMPL $name, $dispatcher, $code); + }; + ($name:ident, $dispatcher:path, $code:expr) => { + /// A unit struct which implements `NativeExecutionDispatch` feeding in the hard-coded runtime. + struct $name; + native_executor_instance!(IMPL $name, $dispatcher, $code); + }; + (IMPL $name:ident, $dispatcher:path, $code:expr) => { + impl $crate::NativeExecutionDispatch for $name { + fn native_equivalent() -> &'static [u8] { + // WARNING!!! This assumes that the runtime was built *before* the main project. Until we + // get a proper build script, this must be strictly adhered to or things will go wrong. + $code + } + + fn dispatch(ext: &mut $crate::Externalities, method: &str, data: &[u8]) -> $crate::error::Result<Vec<u8>> { + $crate::with_native_environment(ext, move || $dispatcher(method, data))? + .ok_or_else(|| $crate::error::ErrorKind::MethodNotFound(method.to_owned()).into()) + } + } + + impl $name { + pub fn new() -> $crate::NativeExecutor<$name> { + $crate::NativeExecutor { _dummy: Default::default() } + } + } + } + +} diff --git a/substrate/substrate/keyring/Cargo.toml b/substrate/substrate/keyring/Cargo.toml new file mode 100644 index 00000000000..f59caf2caf2 --- /dev/null +++ b/substrate/substrate/keyring/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "substrate-keyring" +version = "0.1.0" +authors = ["Parity Technologies <admin@parity.io>"] + +[dependencies] +ed25519 = { path = "../ed25519" } +hex-literal = { version = "0.1.0" } diff --git a/substrate/substrate/keyring/src/lib.rs b/substrate/substrate/keyring/src/lib.rs new file mode 100644 index 00000000000..97e5ed69513 --- /dev/null +++ b/substrate/substrate/keyring/src/lib.rs @@ -0,0 +1,125 @@ +// 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/>. + +//! Support code for the runtime. + +#[macro_use] extern crate hex_literal; +extern crate ed25519; + +use ed25519::{Pair, Public, Signature}; + +/// Set of test accounts. +#[derive(Clone, Copy, PartialEq)] +pub enum Keyring { + Alice, + Bob, + Charlie, + Dave, + Eve, + Ferdie, + One, + Two, +} + +impl Keyring { + pub fn from_public(who: Public) -> Option<Keyring> { + [ + Keyring::Alice, + Keyring::Bob, + Keyring::Charlie, + Keyring::Dave, + Keyring::Eve, + Keyring::Ferdie, + Keyring::One, + Keyring::Two, + ].iter() + .map(|i| *i) + .find(|&k| Public::from(k) == who) + } + + pub fn from_raw_public(who: [u8; 32]) -> Option<Keyring> { + Self::from_public(Public::from_raw(who)) + } + + pub fn to_raw_public(self) -> [u8; 32] { + *Public::from(self).as_array_ref() + } + + pub fn to_raw_public_vec(self) -> Vec<u8> { + Public::from(self).to_raw_vec() + } + + pub fn sign(self, msg: &[u8]) -> Signature { + Pair::from(self).sign(msg) + } +} + +impl From<Keyring> for &'static str { + fn from(k: Keyring) -> Self { + match k { + Keyring::Alice => "Alice", + Keyring::Bob => "Bob", + Keyring::Charlie => "Charlie", + Keyring::Dave => "Dave", + Keyring::Eve => "Eve", + Keyring::Ferdie => "Ferdie", + Keyring::One => "one", + Keyring::Two => "two", + } + } +} + +impl From<Keyring> for Pair { + fn from(k: Keyring) -> Self { + match k { + Keyring::Alice => Pair::from_seed(b"Alice "), + Keyring::Bob => Pair::from_seed(b"Bob "), + Keyring::Charlie => Pair::from_seed(b"Charlie "), + Keyring::Dave => Pair::from_seed(b"Dave "), + Keyring::Eve => Pair::from_seed(b"Eve "), + Keyring::Ferdie => Pair::from_seed(b"Ferdie "), + Keyring::One => Pair::from_seed(b"12345678901234567890123456789012"), + Keyring::Two => Pair::from_seed(&hex!("9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60")), + } + } +} + +impl From<Keyring> for Public { + fn from(k: Keyring) -> Self { + let pair: Pair = k.into(); + pair.public() + } +} + +impl From<Keyring> for [u8; 32] { + fn from(k: Keyring) -> Self { + let pair: Pair = k.into(); + *pair.public().as_array_ref() + } +} + +#[cfg(test)] +mod tests { + use super::*; + use ed25519::Verifiable; + + #[test] + fn should_work() { + assert!(Keyring::Alice.sign(b"I am Alice!").verify(b"I am Alice!", &Keyring::Alice.into())); + assert!(!Keyring::Alice.sign(b"I am Alice!").verify(b"I am Bob!", &Keyring::Alice.into())); + assert!(!Keyring::Alice.sign(b"I am Alice!").verify(b"I am Alice!", &Keyring::Bob.into())); + } +} diff --git a/substrate/substrate/runtime-support/Cargo.toml b/substrate/substrate/runtime-support/Cargo.toml index 9e68c252ece..61a4b064c4a 100644 --- a/substrate/substrate/runtime-support/Cargo.toml +++ b/substrate/substrate/runtime-support/Cargo.toml @@ -4,6 +4,7 @@ version = "0.1.0" authors = ["Parity Technologies <admin@parity.io>"] [dependencies] +ed25519 = { path = "../ed25519", optional = true } hex-literal = { version = "0.1.0", optional = true } substrate-runtime-std = { path = "../runtime-std", default_features = false } substrate-runtime-io = { path = "../runtime-io", default_features = false } @@ -14,6 +15,7 @@ substrate-codec = { path = "../codec", default_features = false } [features] default = ["std"] std = [ + "ed25519", "hex-literal", "environmental", "substrate-primitives/std", diff --git a/substrate/substrate/runtime-support/src/lib.rs b/substrate/substrate/runtime-support/src/lib.rs index 742fcfa2371..44cebcac585 100644 --- a/substrate/substrate/runtime-support/src/lib.rs +++ b/substrate/substrate/runtime-support/src/lib.rs @@ -22,18 +22,9 @@ extern crate substrate_runtime_std as rstd; extern crate substrate_runtime_io as runtime_io; extern crate substrate_codec as codec; extern crate substrate_primitives as primitives; -#[macro_use] -#[cfg(any(feature = "std", test))] -extern crate hex_literal; pub mod storage; mod hashable; -#[macro_use] -#[cfg(feature = "std")] -mod testing; pub use self::storage::StorageVec; pub use self::hashable::Hashable; - -#[cfg(feature = "std")] -pub use self::testing::{one, two}; diff --git a/substrate/substrate/runtime-support/src/testing.rs b/substrate/substrate/runtime-support/src/testing.rs deleted file mode 100644 index 768c56a1e95..00000000000 --- a/substrate/substrate/runtime-support/src/testing.rs +++ /dev/null @@ -1,28 +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/>. - -//! Testing helpers. - -use primitives::AuthorityId; - -/// One account (to which we know the secret key). -pub fn one() -> AuthorityId { - hex!("2f8c6129d816cf51c374bc7f08c3e63ed156cf78aefb4a6550d97b87997977ee") -} -/// Another account (secret key known). -pub fn two() -> AuthorityId { - hex!("d75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a") -} diff --git a/substrate/substrate/state-machine/src/lib.rs b/substrate/substrate/state-machine/src/lib.rs index db1f0ef533b..33dd346c1cd 100644 --- a/substrate/substrate/state-machine/src/lib.rs +++ b/substrate/substrate/state-machine/src/lib.rs @@ -130,11 +130,6 @@ impl fmt::Display for ExternalitiesError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "Externalities Error") } } -fn to_keyed_vec(value: u32, mut prepend: Vec<u8>) -> Vec<u8> { - prepend.extend((0..::std::mem::size_of::<u32>()).into_iter().map(|i| (value >> (i * 8)) as u8)); - prepend -} - /// Externalities: pinned to specific active address. pub trait Externalities { /// Read storage of current contract being called. @@ -148,20 +143,6 @@ pub trait Externalities { /// Get the trie root of the current storage map. fn storage_root(&self) -> [u8; 32]; - - /// Get the current set of authorities from storage. - fn authorities(&self) -> Result<Vec<&[u8]>, ExternalitiesError> { - (0..self.storage(b":auth:len")?.into_iter() - .rev() - .fold(0, |acc, &i| (acc << 8) + (i as u32))) - .map(|i| self.storage(&to_keyed_vec(i, b":auth:".to_vec()))) - .collect() - } - - /// Get the runtime code. - fn code(&self) -> Result<&[u8], ExternalitiesError> { - self.storage(b":code") - } } /// Code execution engine. @@ -252,26 +233,6 @@ mod tests { assert!(overlayed.storage(&key).is_none()); } - #[test] - fn authorities_call_works() { - let mut ext = TestExternalities::default(); - - assert_eq!(ext.authorities(), Ok(vec![])); - - ext.set_storage(b":auth:len".to_vec(), vec![0u8; 4]); - assert_eq!(ext.authorities(), Ok(vec![])); - - ext.set_storage(b":auth:len".to_vec(), vec![1u8, 0, 0, 0]); - assert_eq!(ext.authorities(), Ok(vec![&[][..]])); - - ext.set_storage(b":auth:\0\0\0\0".to_vec(), b"first".to_vec()); - assert_eq!(ext.authorities(), Ok(vec![&b"first"[..]])); - - ext.set_storage(b":auth:len".to_vec(), vec![2u8, 0, 0, 0]); - ext.set_storage(b":auth:\x01\0\0\0".to_vec(), b"second".to_vec()); - assert_eq!(ext.authorities(), Ok(vec![&b"first"[..], &b"second"[..]])); - } - macro_rules! map { ($( $name:expr => $value:expr ),*) => ( vec![ $( ( $name, $value ) ),* ].into_iter().collect() diff --git a/substrate/substrate/test-runtime/Cargo.toml b/substrate/substrate/test-runtime/Cargo.toml index 481f32f8115..577d435b6df 100644 --- a/substrate/substrate/test-runtime/Cargo.toml +++ b/substrate/substrate/test-runtime/Cargo.toml @@ -4,21 +4,26 @@ version = "0.1.0" authors = ["Parity Technologies <admin@parity.io>"] [dependencies] -hex-literal = "0.1.0" log = { version = "0.3", optional = true } -substrate-codec = { path = "../../substrate/codec" } -substrate-runtime-std = { path = "../../substrate/runtime-std" } -substrate-runtime-io = { path = "../../substrate/runtime-io" } -substrate-runtime-support = { path = "../../substrate/runtime-support" } -substrate-primitives = { path = "../../substrate/primitives" } +hex-literal = { version = "0.1.0", optional = true } +ed25519 = { path = "../ed25519", optional = true } +substrate-keyring = { path = "../keyring", optional = true } +substrate-codec = { path = "../codec", default-features = false } +substrate-runtime-std = { path = "../runtime-std", default-features = false } +substrate-runtime-io = { path = "../runtime-io", default-features = false } +substrate-runtime-support = { path = "../runtime-support", default-features = false } +substrate-primitives = { path = "../primitives", default-features = false } [features] default = ["std"] std = [ + "log", + "hex-literal", + "ed25519", + "substrate-keyring", "substrate-codec/std", "substrate-runtime-std/std", "substrate-runtime-io/std", "substrate-runtime-support/std", "substrate-primitives/std", - "log" ] diff --git a/substrate/substrate/test-runtime/src/lib.rs b/substrate/substrate/test-runtime/src/lib.rs index 3e0f65a2b40..52fedf788f5 100644 --- a/substrate/substrate/test-runtime/src/lib.rs +++ b/substrate/substrate/test-runtime/src/lib.rs @@ -19,15 +19,15 @@ #![cfg_attr(not(feature = "std"), no_std)] extern crate substrate_runtime_std as rstd; -#[macro_use] -extern crate substrate_runtime_io as runtime_io; +#[macro_use] extern crate substrate_runtime_io as runtime_io; extern crate substrate_runtime_support as runtime_support; extern crate substrate_codec as codec; #[cfg(test)] #[macro_use] extern crate hex_literal; +#[cfg(test)] extern crate ed25519; +#[cfg(test)] extern crate substrate_keyring as keyring; #[cfg_attr(test, macro_use)] extern crate substrate_primitives as primitives; -#[cfg(feature = "std")] -pub mod genesismap; +#[cfg(feature = "std")] pub mod genesismap; pub mod system; mod transaction; mod unchecked_transaction; @@ -63,7 +63,7 @@ pub fn run_tests(mut input: &[u8]) -> Vec<u8> { [stxs.len() as u8].encode() } -pub mod apis { +pub mod api { use system; impl_stubs!( diff --git a/substrate/substrate/test-runtime/src/system.rs b/substrate/substrate/test-runtime/src/system.rs index 82a428d4589..4c98e16003c 100644 --- a/substrate/substrate/test-runtime/src/system.rs +++ b/substrate/substrate/test-runtime/src/system.rs @@ -132,24 +132,25 @@ mod tests { use runtime_io::{with_externalities, twox_128, TestExternalities}; use codec::{Joiner, KeyedVec}; - use runtime_support::{one, two}; - use ::{Header, Digest}; + use keyring::Keyring; + use ::{Header, Digest, Transaction, UncheckedTransaction}; fn new_test_ext() -> TestExternalities { - let one = one(); - let two = two(); - let three = [3u8; 32]; - TestExternalities { storage: map![ twox_128(b"latest").to_vec() => vec![69u8; 32], twox_128(b":auth:len").to_vec() => vec![].and(&3u32), - twox_128(&0u32.to_keyed_vec(b":auth:")).to_vec() => one.to_vec(), - twox_128(&1u32.to_keyed_vec(b":auth:")).to_vec() => two.to_vec(), - twox_128(&2u32.to_keyed_vec(b":auth:")).to_vec() => three.to_vec(), - twox_128(&one.to_keyed_vec(b"sta:bal:")).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0] + twox_128(&0u32.to_keyed_vec(b":auth:")).to_vec() => Keyring::Alice.to_raw_public().to_vec(), + twox_128(&1u32.to_keyed_vec(b":auth:")).to_vec() => Keyring::Bob.to_raw_public().to_vec(), + twox_128(&2u32.to_keyed_vec(b":auth:")).to_vec() => Keyring::Charlie.to_raw_public().to_vec(), + twox_128(&Keyring::Alice.to_raw_public().to_keyed_vec(b"balance:")).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0] ], } } + fn construct_signed_tx(tx: Transaction) -> UncheckedTransaction { + let signature = Keyring::from_raw_public(tx.from).unwrap().sign(&tx.encode()); + UncheckedTransaction { tx, signature } + } + #[test] fn block_import_works() { let mut t = new_test_ext(); @@ -157,7 +158,7 @@ mod tests { let h = Header { parent_hash: [69u8; 32].into(), number: 1, - state_root: hex!("89b5f5775a45310806a77f421d66bffeff190a519c55f2dcb21f251c2b714524").into(), + state_root: hex!("97dfcd1f8cbf8845fcb544f89332f1a94c1137f7d1b199ef0b0a6ed217015c3e").into(), transaction_root: hex!("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421").into(), digest: Digest { logs: vec![], }, }; @@ -171,4 +172,71 @@ mod tests { execute_block(b); }); } + + #[test] + fn block_import_with_transaction_works() { + let mut t = new_test_ext(); + + with_externalities(&mut t, || { + assert_eq!(balance_of(Keyring::Alice.to_raw_public()), 111); + assert_eq!(balance_of(Keyring::Bob.to_raw_public()), 0); + }); + + let b = Block { + header: Header { + parent_hash: [69u8; 32].into(), + number: 1, + state_root: hex!("0dd8210adaf581464cc68555814a787ed491f8c608d0a0dbbf2208a6d44190b1").into(), + transaction_root: hex!("5e44188712452f900acfa1b4bf4084753122ea1856d58187dd33374a2ca653b1").into(), + digest: Digest { logs: vec![], }, + }, + transactions: vec![ + construct_signed_tx(Transaction { + from: Keyring::Alice.to_raw_public(), + to: Keyring::Bob.to_raw_public(), + amount: 69, + nonce: 0, + }) + ], + }; + + with_externalities(&mut t, || { + execute_block(b.clone()); + + assert_eq!(balance_of(Keyring::Alice.to_raw_public()), 42); + assert_eq!(balance_of(Keyring::Bob.to_raw_public()), 69); + }); + + let b = Block { + header: Header { + parent_hash: b.header.blake2_256().into(), + number: 2, + state_root: hex!("aea7c370a9fa4075b703742c22cc4fb12759bdd7d5aa5cdd85895447f838b81b").into(), + transaction_root: hex!("9ac45fbcc93fa6a8b5a3c44f04d936d53569c72a53fbc12eb58bf884f6dbfae5").into(), + digest: Digest { logs: vec![], }, + }, + transactions: vec![ + construct_signed_tx(Transaction { + from: Keyring::Bob.to_raw_public(), + to: Keyring::Alice.to_raw_public(), + amount: 27, + nonce: 0, + }), + construct_signed_tx(Transaction { + from: Keyring::Alice.to_raw_public(), + to: Keyring::Charlie.to_raw_public(), + amount: 69, + nonce: 1, + }) + ], + }; + + with_externalities(&mut t, || { + execute_block(b); + + assert_eq!(balance_of(Keyring::Alice.to_raw_public()), 0); + assert_eq!(balance_of(Keyring::Bob.to_raw_public()), 42); + assert_eq!(balance_of(Keyring::Charlie.to_raw_public()), 69); + }); + } } diff --git a/substrate/substrate/test-runtime/wasm/Cargo.lock b/substrate/substrate/test-runtime/wasm/Cargo.lock index 0d387390319..8993d9c049a 100644 --- a/substrate/substrate/test-runtime/wasm/Cargo.lock +++ b/substrate/substrate/test-runtime/wasm/Cargo.lock @@ -92,8 +92,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" name = "ed25519" version = "0.1.0" dependencies = [ + "hex-literal 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "ring 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-primitives 0.1.0", "untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -620,6 +620,7 @@ dependencies = [ name = "substrate-runtime-support" version = "0.1.0" dependencies = [ + "ed25519 0.1.0", "environmental 0.1.0", "hex-literal 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-codec 0.1.0", @@ -645,7 +646,9 @@ dependencies = [ name = "substrate-test-runtime" version = "0.1.0" dependencies = [ + "ed25519 0.1.0", "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)", "substrate-codec 0.1.0", "substrate-primitives 0.1.0", "substrate-runtime-io 0.1.0", diff --git a/substrate/substrate/test-runtime/wasm/Cargo.toml b/substrate/substrate/test-runtime/wasm/Cargo.toml index a40af49c330..862d610a57c 100644 --- a/substrate/substrate/test-runtime/wasm/Cargo.toml +++ b/substrate/substrate/test-runtime/wasm/Cargo.toml @@ -3,28 +3,32 @@ name = "substrate-test-runtime" version = "0.1.0" authors = ["Parity Technologies <admin@parity.io>"] -[lib] -crate-type = ["cdylib"] - [dependencies] +log = { version = "0.3", optional = true } hex-literal = { version = "0.1.0", optional = true } -substrate-codec = { path = "../../../substrate/codec", default-features = false } -substrate-runtime-std = { path = "../../../substrate/runtime-std", default-features = false } -substrate-runtime-io = { path = "../../../substrate/runtime-io", default-features = false } -substrate-runtime-support = { path = "../../../substrate/runtime-support", default-features = false } -substrate-primitives = { path = "../../../substrate/primitives", default-features = false } +ed25519 = { path = "../../ed25519", optional = true } +substrate-codec = { path = "../../codec", default-features = false } +substrate-runtime-std = { path = "../../runtime-std", default-features = false } +substrate-runtime-io = { path = "../../runtime-io", default-features = false } +substrate-runtime-support = { path = "../../runtime-support", default-features = false } +substrate-primitives = { path = "../../primitives", default-features = false } [features] default = [] std = [ + "log", "hex-literal", + "ed25519", "substrate-codec/std", - "substrate-runtime-io/std", "substrate-runtime-std/std", + "substrate-runtime-io/std", "substrate-runtime-support/std", "substrate-primitives/std", ] +[lib] +crate-type = ["cdylib"] + [profile.release] panic = "abort" diff --git a/substrate/substrate/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm b/substrate/substrate/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm index 95e6b0c7f7fe14fbbfaa3505e8bce0402610b308..7713a89ab36efbd5f52bf99e39100af9b34272c4 100644 GIT binary patch delta 234 zcmZ4RlX1aM#tj=7xfxlxxw+X{S(&)mC+}u#X4Keh&lIU5Ai$u&sKB7X!~h~#1f(ZV zS2JWZn0!+01(4jN{su_S*T@8toSN~BhLbZjcK}HxEgeR~&Hh?FjFaDJJ24t<*4Np{ z$f!H{p>71D-exO3T{fVG3=?}Gxx(Z<kep!(GOp1qA4q;QGXaun=9Y{Gn-k2HSQ#}p zH`_R|F&a%i=2Xb2yV=6IhY=`t)CFjy(dKfub<CTeMy%)G+?A=qG<izKx6P_vZ@3xt VHw%SbX4<?i+fjhgZSsfe4FCp>Nb>*y delta 240 zcmZ4RlX1aM#tj=7xmg*xxw+Zdxmj76Chul!X4Kql&lIULd8L{GqtWDBYA=A~Vf8ma za)U-Dkd)GlXVjlurMUx08f)n=>Tgca>R}WRU{GLGV9;P<01+$#(vx3nJ2UET*4Np{ z$f!5@p>71D!DcHxT{fTz87B5Xa)rrzAUVSnWPYPrK9KxqW&$MD%q<y>HYb=Xu`+6G zZnkk^W7M5|%&Cx3Z?lDS4<k_Qs0+|Y-Oc50>zFsci+RJ%Xt?=y#$~3>s$T2)C;y24 c#<*j0f0W^7wx~~xo7ZJK3NX4({!qOE030+;UjP6A diff --git a/substrate/substrate/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.wasm b/substrate/substrate/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.wasm index 5003985d234677e20942e5c129dc044bcc9a6a33..ec5638e1c183ce98875d9e6fe4db58fd09e01f70 100644 GIT binary patch delta 234 zcmezHlkvk(#tlapxfxlxxw+X{S(&)mC!c3r$*8@#k||$BK!8DkQGr2&i2+2g2*^!- zu4c$+JXuox1(0OYcmpKgYh(h+NX>XglgT?ZcL2#EEgeRa&GWT-7$@84I5C=TuGiVf z$Y?OxP%nbfaC4WQE*nt84ikGI`NQNrkbGeZGVY>TK9F=YHvy7m=9Y}cn>Uy%u`=px zzHH;f#%MZO%(;-!U~`9a4<k@a)D>u?>E`2Z>zFs2My}`Id@EChY4VedZ<|ZK-f%M- VZB7ci%(VGmwxa-}+hm8D4FGi2OEmxh delta 239 zcmezHlkvk(#tlapxmg*xxw+Zdxmj76CZA_q$*8lrk||$h@=rAbM$^e!>Mww#u*Mrk z(@C0{KxUR^JfqR%Q<^(~WV4nIqtWIKT0M*c0t^a_3Je-d3?PC<KyI?Njx(dd=6aot zjEshp4fP@zjW>7c>9PS$*kNK1B!8H^2a+#LLB?M+%LkH<<|aV0%-oXEbn^ytC00i5 z&6jPQ*cc5ai#ZoE8gA}z?qLLqiMj%fG}wIHZ5{JwyVy6}j3%44GcPl3F7;Z^KiMPZ c8{>}2_oECqheds2-25-wQGn5PvO~=V0Gzl?^8f$< -- GitLab