From b5437f999c9a306e17524741f63c86cc6b688559 Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Thu, 26 Dec 2019 18:52:32 +0800 Subject: [PATCH 1/3] try: fix ci --- ci/script.sh | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/ci/script.sh b/ci/script.sh index 67dcd4e89..578e59a3b 100755 --- a/ci/script.sh +++ b/ci/script.sh @@ -8,21 +8,27 @@ curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain=$1 -y # Load cargo environment. Specifically, put cargo into PATH. source ~/.cargo/env -rustc --version +# Make sure using the nightly toolchain +rustup default nightly + +# Install wasm toolchain +rustup target add wasm32-unknown-unknown + rustup --version cargo --version +rustc --version case $2 in - "native") - sudo apt-get -y update - sudo apt-get install -y cmake pkg-config libssl-dev - - cargo test --all --locked - ;; - - "wasm") - # Install prerequisites and build all wasm projects - ./init.sh - ./build.sh --locked - ;; + "native") + sudo apt-get -y update + sudo apt-get install -y cmake pkg-config libssl-dev + + # Unit test + cargo test --release --all --locked + ;; + + "wasm") + # Build test + cargo build + ;; esac \ No newline at end of file From 89947501095a37e50c6e6110764c8aef1462538e Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Thu, 26 Dec 2019 18:59:26 +0800 Subject: [PATCH 2/3] update: format --- ci/script.sh | 24 +++++----- srml/eth-relay/src/lib.rs | 2 +- srml/im-online/src/mock.rs | 34 ++++++------- srml/im-online/src/tests.rs | 95 ++++++++++++++++++------------------- 4 files changed, 73 insertions(+), 82 deletions(-) diff --git a/ci/script.sh b/ci/script.sh index 578e59a3b..a136777f3 100755 --- a/ci/script.sh +++ b/ci/script.sh @@ -19,16 +19,16 @@ cargo --version rustc --version case $2 in - "native") - sudo apt-get -y update - sudo apt-get install -y cmake pkg-config libssl-dev - - # Unit test - cargo test --release --all --locked - ;; - - "wasm") - # Build test - cargo build - ;; + "native") + sudo apt-get -y update + sudo apt-get install -y cmake pkg-config libssl-dev + + # Unit test + cargo test --release --all --locked + ;; + + "wasm") + # Build test + cargo build + ;; esac \ No newline at end of file diff --git a/srml/eth-relay/src/lib.rs b/srml/eth-relay/src/lib.rs index e341b3cae..2fcc138f7 100644 --- a/srml/eth-relay/src/lib.rs +++ b/srml/eth-relay/src/lib.rs @@ -7,7 +7,7 @@ use codec::{Decode, Encode}; use rstd::{result, vec::Vec}; use sr_primitives::RuntimeDebug; use support::{decl_event, decl_module, decl_storage, dispatch::Result, ensure, traits::Get}; -use system::{ensure_signed, ensure_root}; +use system::{ensure_root, ensure_signed}; use ethash::{EthereumPatch, LightDAG}; use merkle_patricia_trie::{trie::Trie, MerklePatriciaTrie, Proof}; diff --git a/srml/im-online/src/mock.rs b/srml/im-online/src/mock.rs index 4be33c44e..23e60dbb9 100644 --- a/srml/im-online/src/mock.rs +++ b/srml/im-online/src/mock.rs @@ -21,15 +21,15 @@ use std::cell::RefCell; use crate::{Module, Trait}; -use sr_primitives::Perbill; -use sr_staking_primitives::{SessionIndex, offence::ReportOffence}; -use sr_primitives::testing::{Header, UintAuthorityId, TestXt}; -use sr_primitives::traits::{IdentityLookup, BlakeTwo256, ConvertInto}; use primitives::H256; -use support::{impl_outer_origin, impl_outer_dispatch, parameter_types}; +use sr_primitives::testing::{Header, TestXt, UintAuthorityId}; +use sr_primitives::traits::{BlakeTwo256, ConvertInto, IdentityLookup}; +use sr_primitives::Perbill; +use sr_staking_primitives::{offence::ReportOffence, SessionIndex}; +use support::{impl_outer_dispatch, impl_outer_origin, parameter_types}; use {runtime_io, system}; -impl_outer_origin!{ +impl_outer_origin! { pub enum Origin for Runtime {} } @@ -45,25 +45,22 @@ thread_local! { pub struct TestOnSessionEnding; impl session::OnSessionEnding for TestOnSessionEnding { - fn on_session_ending(_ending_index: SessionIndex, _will_apply_at: SessionIndex) - -> Option> - { + fn on_session_ending(_ending_index: SessionIndex, _will_apply_at: SessionIndex) -> Option> { VALIDATORS.with(|l| l.borrow_mut().take()) } } impl session::historical::OnSessionEnding for TestOnSessionEnding { - fn on_session_ending(_ending_index: SessionIndex, _will_apply_at: SessionIndex) - -> Option<(Vec, Vec<(u64, u64)>)> - { - VALIDATORS.with(|l| l - .borrow_mut() - .take() - .map(|validators| { + fn on_session_ending( + _ending_index: SessionIndex, + _will_apply_at: SessionIndex, + ) -> Option<(Vec, Vec<(u64, u64)>)> { + VALIDATORS.with(|l| { + l.borrow_mut().take().map(|validators| { let full_identification = validators.iter().map(|v| (*v, *v)).collect(); (validators, full_identification) }) - ) + }) } } @@ -90,7 +87,6 @@ pub fn new_test_ext() -> runtime_io::TestExternalities { t.into() } - #[derive(Clone, PartialEq, Eq, Debug)] pub struct Runtime; @@ -131,7 +127,7 @@ parameter_types! { impl session::Trait for Runtime { type ShouldEndSession = session::PeriodicSessions; type OnSessionEnding = session::historical::NoteHistoricalRoot; - type SessionHandler = (ImOnline, ); + type SessionHandler = (ImOnline,); type ValidatorId = u64; type ValidatorIdOf = ConvertInto; type Keys = UintAuthorityId; diff --git a/srml/im-online/src/tests.rs b/srml/im-online/src/tests.rs index 382eb4f1d..4acca7c22 100644 --- a/srml/im-online/src/tests.rs +++ b/srml/im-online/src/tests.rs @@ -21,17 +21,14 @@ use super::*; use crate::mock::*; use offchain::testing::TestOffchainExt; -use primitives::offchain::{OpaquePeerId, OffchainExt}; -use support::{dispatch, assert_noop}; +use primitives::offchain::{OffchainExt, OpaquePeerId}; use sr_primitives::testing::UintAuthorityId; +use support::{assert_noop, dispatch}; #[test] fn test_unresponsiveness_slash_fraction() { // A single case of unresponsiveness is not slashed. - assert_eq!( - UnresponsivenessOffence::<()>::slash_fraction(1, 50), - Perbill::zero(), - ); + assert_eq!(UnresponsivenessOffence::<()>::slash_fraction(1, 50), Perbill::zero(),); assert_eq!( UnresponsivenessOffence::<()>::slash_fraction(3, 50), @@ -64,17 +61,17 @@ fn should_report_offline_validators() { // then let offences = OFFENCES.with(|l| l.replace(vec![])); - assert_eq!(offences, vec![ - (vec![], UnresponsivenessOffence { - session_index: 2, - validator_set_count: 3, - offenders: vec![ - (1, 1), - (2, 2), - (3, 3), - ], - }) - ]); + assert_eq!( + offences, + vec![( + vec![], + UnresponsivenessOffence { + session_index: 2, + validator_set_count: 3, + offenders: vec![(1, 1), (2, 2), (3, 3),], + } + )] + ); // should not report when heartbeat is sent for (idx, v) in validators.into_iter().take(4).enumerate() { @@ -84,25 +81,21 @@ fn should_report_offline_validators() { // then let offences = OFFENCES.with(|l| l.replace(vec![])); - assert_eq!(offences, vec![ - (vec![], UnresponsivenessOffence { - session_index: 3, - validator_set_count: 6, - offenders: vec![ - (5, 5), - (6, 6), - ], - }) - ]); + assert_eq!( + offences, + vec![( + vec![], + UnresponsivenessOffence { + session_index: 3, + validator_set_count: 6, + offenders: vec![(5, 5), (6, 6),], + } + )] + ); }); } -fn heartbeat( - block_number: u64, - session_index: u32, - authority_index: u32, - id: UintAuthorityId, -) -> dispatch::Result { +fn heartbeat(block_number: u64, session_index: u32, authority_index: u32, id: UintAuthorityId) -> dispatch::Result { #[allow(deprecated)] use support::unsigned::ValidateUnsigned; @@ -119,11 +112,7 @@ fn heartbeat( #[allow(deprecated)] // Allow ValidateUnsigned ImOnline::pre_dispatch(&crate::Call::heartbeat(heartbeat.clone(), signature.clone()))?; - ImOnline::heartbeat( - Origin::system(system::RawOrigin::None), - heartbeat, - signature - ) + ImOnline::heartbeat(Origin::system(system::RawOrigin::None), heartbeat, signature) } #[test] @@ -211,12 +200,15 @@ fn should_generate_heartbeats() { e => panic!("Unexpected call: {:?}", e), }; - assert_eq!(heartbeat, Heartbeat { - block_number: 2, - network_state: runtime_io::offchain::network_state().unwrap(), - session_index: 2, - authority_index: 2, - }); + assert_eq!( + heartbeat, + Heartbeat { + block_number: 2, + network_state: runtime_io::offchain::network_state().unwrap(), + session_index: 2, + authority_index: 2, + } + ); }); } @@ -314,11 +306,14 @@ fn should_not_send_a_report_if_already_online() { e => panic!("Unexpected call: {:?}", e), }; - assert_eq!(heartbeat, Heartbeat { - block_number: 4, - network_state: runtime_io::offchain::network_state().unwrap(), - session_index: 2, - authority_index: 0, - }); + assert_eq!( + heartbeat, + Heartbeat { + block_number: 4, + network_state: runtime_io::offchain::network_state().unwrap(), + session_index: 2, + authority_index: 0, + } + ); }); } From b4c245eba3bc03ab7dfce0d1e68a7c8d7579a697 Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Thu, 26 Dec 2019 19:02:05 +0800 Subject: [PATCH 3/3] remove: dangling comma --- srml/balances/src/tests.rs | 2 +- srml/im-online/src/mock.rs | 2 +- srml/im-online/src/tests.rs | 6 +++--- srml/staking/src/tests.rs | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/srml/balances/src/tests.rs b/srml/balances/src/tests.rs index 22074c77f..ffe06a03b 100644 --- a/srml/balances/src/tests.rs +++ b/srml/balances/src/tests.rs @@ -464,7 +464,7 @@ fn balance_transfer_works() { fn force_transfer_works() { ExtBuilder::default().build().execute_with(|| { let _ = Balances::deposit_creating(&1, 111); - assert_noop!(Balances::force_transfer(Some(2).into(), 1, 2, 69), "RequireRootOrigin",); + assert_noop!(Balances::force_transfer(Some(2).into(), 1, 2, 69), "RequireRootOrigin"); assert_ok!(Balances::force_transfer(RawOrigin::Root.into(), 1, 2, 69)); assert_eq!(Balances::total_balance(&1), 42); assert_eq!(Balances::total_balance(&2), 69); diff --git a/srml/im-online/src/mock.rs b/srml/im-online/src/mock.rs index 23e60dbb9..77926e3b3 100644 --- a/srml/im-online/src/mock.rs +++ b/srml/im-online/src/mock.rs @@ -127,7 +127,7 @@ parameter_types! { impl session::Trait for Runtime { type ShouldEndSession = session::PeriodicSessions; type OnSessionEnding = session::historical::NoteHistoricalRoot; - type SessionHandler = (ImOnline,); + type SessionHandler = (ImOnline); type ValidatorId = u64; type ValidatorIdOf = ConvertInto; type Keys = UintAuthorityId; diff --git a/srml/im-online/src/tests.rs b/srml/im-online/src/tests.rs index 4acca7c22..97c4a48df 100644 --- a/srml/im-online/src/tests.rs +++ b/srml/im-online/src/tests.rs @@ -28,7 +28,7 @@ use support::{assert_noop, dispatch}; #[test] fn test_unresponsiveness_slash_fraction() { // A single case of unresponsiveness is not slashed. - assert_eq!(UnresponsivenessOffence::<()>::slash_fraction(1, 50), Perbill::zero(),); + assert_eq!(UnresponsivenessOffence::<()>::slash_fraction(1, 50), Perbill::zero()); assert_eq!( UnresponsivenessOffence::<()>::slash_fraction(3, 50), @@ -68,7 +68,7 @@ fn should_report_offline_validators() { UnresponsivenessOffence { session_index: 2, validator_set_count: 3, - offenders: vec![(1, 1), (2, 2), (3, 3),], + offenders: vec![(1, 1), (2, 2), (3, 3)], } )] ); @@ -88,7 +88,7 @@ fn should_report_offline_validators() { UnresponsivenessOffence { session_index: 3, validator_set_count: 6, - offenders: vec![(5, 5), (6, 6),], + offenders: vec![(5, 5), (6, 6)], } )] ); diff --git a/srml/staking/src/tests.rs b/srml/staking/src/tests.rs index bbc2c3313..1815d8556 100644 --- a/srml/staking/src/tests.rs +++ b/srml/staking/src/tests.rs @@ -3727,7 +3727,7 @@ fn xavier_q2() { unbondings: vec![NormalLock { amount: 2, until: BondingDuration::get() + unbond_start_1, - },], + }], }), reasons: WithdrawReasons::all(), }]