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.
This commit is contained in:
Gav Wood
2018-02-12 15:30:38 +01:00
committed by Robert Habermeier
parent 72fa8f3fe2
commit f344e15bf8
38 changed files with 528 additions and 341 deletions
+1
View File
@@ -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;
@@ -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();
@@ -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 {
@@ -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};
@@ -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)
@@ -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();