diff --git a/substrate/Cargo.lock b/substrate/Cargo.lock index a2d998ac4495aad0183909c231813d581824c06a..6e54ac6c5e8e29b4ec61f998671d4d9a79fd0418 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 e46ed6d72525abafdd33cc097d10d9f21dd13815..b2378b684b17fcd0898c3a27dbadb1287add92f7 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 c79295823a7dda56631c4d36c43fd02a66196fbe..a16781eb69b2894916c047914ced9ccb6056d1d0 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 59e6ef270e1aa5db3bea99303e9ceca577e36407..807ff6c2cb8aa65d183cec619a767f3d8ac9694f 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 60cd4ee20d6b9f6d9ccfce10789e5b63fb367f01..cca94287b0c759b7bb078b9c4e54774bbb883904 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 7db96440a46081c25d2cda4cec6813487f829e5b..a7cef0c3cb337738867d60a767c2f804312e7929 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 c8decd0462d2dfd529c826b1eb3c53f1fe1b6592..4efe5c15e77ef0d41ab6af152f886c5a83824a45 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 6eb3a259fe7b7178056bdb38fe36a44faee41c41..99aebd5990267d5cb7f5148a511780ccbe077c4d 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 4ac1e17a3398ee601ce32323d617ae81d434b0b9..b8733b9776a3bc6dbc170eaf847e86022e5f22c9 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 56559ee3566929779e7949459049a163c70dcc13..dd7485ddc83e8a7b74e5ed177f0ab2d798fae840 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 9252e9774d5db8ee823c80b2eb8cc20db9230487..a3a43d88cc1318484a16dad18baba605a07198ee 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 b281bc5cd50e0e934961333e9c39f8ae2bbc23b7..a66d43eeb90375dc664241a72a575e8b81bccfda 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 2a8519a6832d01e4edbf31378e360da7bd5ac6ee..2f8f5c25c7124184d4b11c1a5846da86cc399c6e 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 df8296ff092ecfd3354209a8b27d3828b8d36847..11fe2d48f84d0b5e9a18b35c4795185260062dc7 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 Binary files a/substrate/polkadot/runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.compact.wasm and b/substrate/polkadot/runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.compact.wasm differ 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 Binary files a/substrate/polkadot/runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.wasm and b/substrate/polkadot/runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.wasm differ diff --git a/substrate/substrate/client/Cargo.toml b/substrate/substrate/client/Cargo.toml index be11c172333fe35369cc44f2638d659fb468ad01..b9e0135b9e97af1bd152850eff9acabe0b70da52 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 0eb12cf18b2e4a404352e353f354c70d1785bfe6..fad0f203e8c649cf8bec04436acf55f2b69c58b1 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 0059804914e9e8e2bed2645b8b36ae791f049418..1c97387e817c9e65555e1709067e7f3670ef6f2e 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 ba4a30741b4aa4e451a59477dc88050b7a358b8a..fb3e228d03f1cf1af8675faaf0bd99a9f689789d 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 951eafbb26a76ba4299c7109ab12cb09822e4c44..530288ca29edb0434cc07e3a590cd3a295f1995e 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 6d11f67920f38010fb9f599751f51f9f47837b33..1241bd69bf15d2913af2f37e77be73463655b50c 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 287d83e36d98130e9d2861f2eb148fca123ffb99..4953aa957448dfe68a17512729ed7062c695a7a2 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 d520048e749640e24fc57a715ecf498ad33d0b19..1b4588db87c708db2a58000be767015e8960c44a 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 0855e78e8586927547994134c2630e9c2bb1e193..99773b9f761ba23d9cf7d3762123a5e57bbe6030 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 0000000000000000000000000000000000000000..f59caf2caf208b9a662ccfef682bee81a4f5277c --- /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 0000000000000000000000000000000000000000..97e5ed69513656b59f08e82ab45047bd6d6ee270 --- /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 9e68c252ecef9d2555468a4bcbd1eb5b163315ff..61a4b064c4a50be8e55fa73a15e3b514de9fd67e 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 742fcfa2371f63b3dff874f3f82bd14e018e4648..44cebcac5854d28317826d6538993dcda020ef8f 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 768c56a1e95f3283c822611a394dc79940b61b80..0000000000000000000000000000000000000000 --- 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 db1f0ef533b766919c7a218a7afc079434092ff0..33dd346c1cd254bd11235b26d82d07facbe07160 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 481f32f8115ed13c68d73441152c30ac0bd80722..577d435b6df8343b9d887cfe33fc313f816adc6a 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 3e0f65a2b40483674a7eb18a09f8d720c7879ca3..52fedf788f56b66423111cef67ff4bdff4d4c22a 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 82a428d45899375a65442fc78f615368e6585625..4c98e16003c51c5a2c2957911452ce3f8138f53a 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 0d387390319fdb04fc4f5d315477e6d2f2b24214..8993d9c049a4d526ed8a9878d7e12b9b7635aab0 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 a40af49c330594f51474f78eee4d3a199c661518..862d610a57c399f0c6bfe63476cc669c5006a790 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 Binary files a/substrate/substrate/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm and b/substrate/substrate/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm differ 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 Binary files a/substrate/substrate/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.wasm and b/substrate/substrate/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.wasm differ