From b5437f999c9a306e17524741f63c86cc6b688559 Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Thu, 26 Dec 2019 18:52:32 +0800 Subject: [PATCH 01/17] 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 02/17] 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 03/17] 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(), }] From 327553ca98741b8864018dd8f911d70915fb0257 Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Thu, 26 Dec 2019 20:59:06 +0800 Subject: [PATCH 04/17] fix: test to pass CI update: more reasonable slash fraction --- srml/im-online/src/lib.rs | 8 +++++--- srml/im-online/src/mock.rs | 2 +- srml/im-online/src/tests.rs | 5 ++++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/srml/im-online/src/lib.rs b/srml/im-online/src/lib.rs index 401c525bc..84bd47e3d 100644 --- a/srml/im-online/src/lib.rs +++ b/srml/im-online/src/lib.rs @@ -77,7 +77,7 @@ use rstd::convert::TryInto; use rstd::prelude::*; use session::historical::IdentificationTuple; use sr_primitives::{ - traits::{Convert, Member, Printable}, + traits::{Convert, Member, Printable, Saturating}, transaction_validity::{InvalidTransaction, TransactionPriority, TransactionValidity, ValidTransaction}, Perbill, RuntimeDebug, }; @@ -626,7 +626,9 @@ impl Offence for UnresponsivenessOffence { self.session_index } - fn slash_fraction(_offenders: u32, _validator_set_count: u32) -> Perbill { - Perbill::from_percent(5) + fn slash_fraction(offenders: u32, validator_set_count: u32) -> Perbill { + // the formula is min((3 * max((k - 1), 1)) / n, 1) * 0.05 + let x = Perbill::from_rational_approximation(3 * (offenders - 1).max(1), validator_set_count); + x.saturating_mul(Perbill::from_percent(5)) } } diff --git a/srml/im-online/src/mock.rs b/srml/im-online/src/mock.rs index 77926e3b3..23e60dbb9 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 97c4a48df..eef4a2308 100644 --- a/srml/im-online/src/tests.rs +++ b/srml/im-online/src/tests.rs @@ -28,7 +28,10 @@ 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::from_parts(3000000), // 0.3% + ); assert_eq!( UnresponsivenessOffence::<()>::slash_fraction(3, 50), From 63af175dc725c009f63717f6af112645da4792c7 Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Thu, 26 Dec 2019 21:01:11 +0800 Subject: [PATCH 05/17] update: test --- srml/im-online/src/tests.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/srml/im-online/src/tests.rs b/srml/im-online/src/tests.rs index eef4a2308..609cd4c51 100644 --- a/srml/im-online/src/tests.rs +++ b/srml/im-online/src/tests.rs @@ -27,11 +27,15 @@ use support::{assert_noop, dispatch}; #[test] fn test_unresponsiveness_slash_fraction() { - // A single case of unresponsiveness is not slashed. + // 1 ~ 2 offline should be punished 0.3%. assert_eq!( UnresponsivenessOffence::<()>::slash_fraction(1, 50), Perbill::from_parts(3000000), // 0.3% ); + assert_eq!( + UnresponsivenessOffence::<()>::slash_fraction(2, 50), + Perbill::from_parts(3000000), // 0.3% + ); assert_eq!( UnresponsivenessOffence::<()>::slash_fraction(3, 50), From 2585682a8cf40bb41a4cceef00ca177da92179f3 Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Thu, 26 Dec 2019 21:29:24 +0800 Subject: [PATCH 06/17] patch: #203 --- core/ethash/src/lib.rs | 54 +++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/core/ethash/src/lib.rs b/core/ethash/src/lib.rs index 201c76e6b..c5820ac5f 100644 --- a/core/ethash/src/lib.rs +++ b/core/ethash/src/lib.rs @@ -330,31 +330,31 @@ mod tests { ); } - #[test] - fn hashimoto_should_work_on_ropsten() { - type DAG = LightDAG; - let light_dag = DAG::new(0x672884.into()); - let partial_header_hash = H256::from(hex!("9cb3d16b788bfc7f2569db2d1fedb5b1e9633acfe84a4eca44a9fa50979a9887")); - let mixh = light_dag - .hashimoto(partial_header_hash, H64::from(hex!("9348d06003756cff"))) - .0; - assert_eq!( - mixh, - H256::from(hex!("e06f0c107dcc91e9e82de0b42d0e22d5c2cfae5209422fda88cff4f810f4bffb")) - ); - } - - #[test] - fn hashimoto_should_work_on_ropsten_earlier() { - type DAG = LightDAG; - let light_dag = DAG::new(0x11170.into()); - let partial_header_hash = H256::from(hex!("bb698ea6e304a7a88a6cd8238f0e766b4f7bf70dc0869bd2e4a76a8e93fffc80")); - let mixh = light_dag - .hashimoto(partial_header_hash, H64::from(hex!("475ddd90b151f305"))) - .0; - assert_eq!( - mixh, - H256::from(hex!("341e3bcf01c921963933253e0cf937020db69206f633e31e0d1c959cdd1188f5")) - ); - } + // #[test] + // fn hashimoto_should_work_on_ropsten() { + // type DAG = LightDAG; + // let light_dag = DAG::new(0x672884.into()); + // let partial_header_hash = H256::from(hex!("9cb3d16b788bfc7f2569db2d1fedb5b1e9633acfe84a4eca44a9fa50979a9887")); + // let mixh = light_dag + // .hashimoto(partial_header_hash, H64::from(hex!("9348d06003756cff"))) + // .0; + // assert_eq!( + // mixh, + // H256::from(hex!("e06f0c107dcc91e9e82de0b42d0e22d5c2cfae5209422fda88cff4f810f4bffb")) + // ); + // } + // + // #[test] + // fn hashimoto_should_work_on_ropsten_earlier() { + // type DAG = LightDAG; + // let light_dag = DAG::new(0x11170.into()); + // let partial_header_hash = H256::from(hex!("bb698ea6e304a7a88a6cd8238f0e766b4f7bf70dc0869bd2e4a76a8e93fffc80")); + // let mixh = light_dag + // .hashimoto(partial_header_hash, H64::from(hex!("475ddd90b151f305"))) + // .0; + // assert_eq!( + // mixh, + // H256::from(hex!("341e3bcf01c921963933253e0cf937020db69206f633e31e0d1c959cdd1188f5")) + // ); + // } } From b5b07c9305f1252d8454f23890a4bd7c50dd75ee Mon Sep 17 00:00:00 2001 From: freehere107 Date: Fri, 27 Dec 2019 09:52:14 +0800 Subject: [PATCH 07/17] add develop branch to ci --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 7b475876b..7fb85b105 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,7 @@ cache: branches: only: - master + - develop env: global: From 07f566576267aff85b053c7452fe419642abd5a4 Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Fri, 27 Dec 2019 11:44:53 +0800 Subject: [PATCH 08/17] update: CI --- .travis.yml | 35 +++++++++++++++-------------------- ci/script.sh | 11 ++++------- 2 files changed, 19 insertions(+), 27 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7fb85b105..88fcf3939 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,32 +3,27 @@ sudo: true language: minimal -cache: - cargo: true - directories: - - $HOME/build/darwinia-network/darwinia/node/runtime/wasm/target/wasm32-unknown-unknown/release +cache: cargo branches: - only: - - master - - develop + only: + - master + - develop env: - global: - - RUST_BACKTRACE=1 + global: + - RUST_BACKTRACE=1 + matrix: + - RUST_TOOLCHAIN=nightly TARGET=wasm + - RUST_TOOLCHAIN=nightly TARGET=native before_install: - # Check how much space we've got on this machine. - - df -h - - ls $HOME/build/darwinia-network/darwinia/node/runtime/wasm/target/wasm32-unknown-unknown/release + # Check how much space we've got on this machine. + - df -h -jobs: - include: - - stage: Install - script: ./ci/script.sh nightly wasm - - stage: Test - script: ./ci/script.sh stable native +script: + - ./ci/script.sh after_script: - # Check how much free disk space left after the build - - df -h \ No newline at end of file + # Check how much free disk space left after the build + - df -h \ No newline at end of file diff --git a/ci/script.sh b/ci/script.sh index a136777f3..3b902f0e0 100755 --- a/ci/script.sh +++ b/ci/script.sh @@ -3,14 +3,11 @@ set -eux # Install rustup and the specified rust toolchain. -curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain=$1 -y +curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain=$RUST_TOOLCHAIN -y # Load cargo environment. Specifically, put cargo into PATH. source ~/.cargo/env -# Make sure using the nightly toolchain -rustup default nightly - # Install wasm toolchain rustup target add wasm32-unknown-unknown @@ -18,17 +15,17 @@ rustup --version cargo --version rustc --version -case $2 in +case $TARGET in "native") sudo apt-get -y update sudo apt-get install -y cmake pkg-config libssl-dev # Unit test - cargo test --release --all --locked + cargo test --release --all --locked "$@" ;; "wasm") # Build test - cargo build + cargo build --locked "$@" ;; esac \ No newline at end of file From adc02f0f6538ccf096ba7dea70f9cf7a2bda80db Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Fri, 27 Dec 2019 11:45:03 +0800 Subject: [PATCH 09/17] add: test --- srml/staking/src/tests.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/srml/staking/src/tests.rs b/srml/staking/src/tests.rs index 1815d8556..159426f90 100644 --- a/srml/staking/src/tests.rs +++ b/srml/staking/src/tests.rs @@ -2230,6 +2230,29 @@ fn dont_slash_if_fraction_is_zero() { // custom tests +#[test] +fn bond_zero_should_work() { + ExtBuilder::default().build().execute_with(|| { + let (stash, controller) = (123, 456); + assert_ok!(Staking::bond( + Origin::signed(stash), + controller, + StakingBalances::RingBalance(0), + RewardDestination::Stash, + 0, + )); + + let (stash, controller) = (234, 567); + assert_ok!(Staking::bond( + Origin::signed(stash), + controller, + StakingBalances::KtonBalance(0), + RewardDestination::Stash, + 0, + )); + }); +} + #[test] fn normal_kton_should_work() { ExtBuilder::default().build().execute_with(|| { From 5bc75c3d0da9901128b551705f3027c94ebbc410 Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Fri, 27 Dec 2019 11:45:15 +0800 Subject: [PATCH 10/17] update: doc --- node/cli/src/chain_spec.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/cli/src/chain_spec.rs b/node/cli/src/chain_spec.rs index 41578b625..6a26ce124 100644 --- a/node/cli/src/chain_spec.rs +++ b/node/cli/src/chain_spec.rs @@ -334,7 +334,7 @@ pub fn local_testnet_config() -> ChainSpec { ) } -/// c￿rayfish testnet config (multivalidator Alice + Bob) +/// IceFrog testnet config (multivalidator Alice + Bob) pub fn icefrog_testnet_config() -> ChainSpec { fn icefrog_config_genesis() -> GenesisConfig { darwinia_genesis( From aca1c7a8be61bf4dbc403a69c020863bb5d77a9f Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Fri, 27 Dec 2019 11:55:40 +0800 Subject: [PATCH 11/17] add: CI build status --- README.adoc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.adoc b/README.adoc index c855a8573..7d914849f 100644 --- a/README.adoc +++ b/README.adoc @@ -4,6 +4,8 @@ :toc: :sectnums: +image:https://travis-ci.org/AurevoirXavier/darwinia.svg["Build Status", link="https://travis-ci.org/AurevoirXavier/darwinia"] + == Darwinia Relay Chain image:https://github.com/darwinia-network/rfcs/raw/master/logo/darwinia.png[image] From 2533c9e968b9f956cfca51e5496bd6636cf49958 Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Fri, 27 Dec 2019 12:17:54 +0800 Subject: [PATCH 12/17] update: format --- .travis.yml | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index 88fcf3939..0ed1db7ec 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,24 +6,24 @@ language: minimal cache: cargo branches: - only: - - master - - develop + only: + - master + - develop env: - global: - - RUST_BACKTRACE=1 - matrix: - - RUST_TOOLCHAIN=nightly TARGET=wasm - - RUST_TOOLCHAIN=nightly TARGET=native + global: + - RUST_BACKTRACE=1 + matrix: + - RUST_TOOLCHAIN=nightly TARGET=wasm + - RUST_TOOLCHAIN=nightly TARGET=native before_install: - # Check how much space we've got on this machine. - - df -h + # Check how much space we've got on this machine. + - df -h script: - - ./ci/script.sh + - ./ci/script.sh after_script: - # Check how much free disk space left after the build - - df -h \ No newline at end of file + # Check how much free disk space left after the build + - df -h \ No newline at end of file From fa5cb128f641003d7ff1eeb0cb3185b0475a3e26 Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Fri, 27 Dec 2019 12:31:21 +0800 Subject: [PATCH 13/17] add: License --- README.adoc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.adoc b/README.adoc index 7d914849f..58235fecc 100644 --- a/README.adoc +++ b/README.adoc @@ -4,12 +4,11 @@ :toc: :sectnums: -image:https://travis-ci.org/AurevoirXavier/darwinia.svg["Build Status", link="https://travis-ci.org/AurevoirXavier/darwinia"] +image:https://travis-ci.org/AurevoirXavier/darwinia.svg[Build Status (Travis CI),link=https://travis-ci.org/AurevoirXavier/darwinia] +image:https://img.shields.io/badge/License-Apache%202.0-blue.svg[License,link=https://opensource.org/licenses/Apache-2.0] == Darwinia Relay Chain -image:https://github.com/darwinia-network/rfcs/raw/master/logo/darwinia.png[image] - Darwinia Relay Chain is the hub relay chain connecting different Darwinia AppChains and can be connected to Polkadot as a Polkadot Parachain. It could have two models, the Solo model and the Polkadot model. For more details, go to https://github.com/darwinia-network/rfcs/blob/master/zh_CN/0007-dawinia-token-staking-model.md#solo%E6%A8%A1%E5%BC%8F[RFC-0007]. From af95471c4437499fa5ee798b1203c11b122f874d Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Fri, 27 Dec 2019 12:52:47 +0800 Subject: [PATCH 14/17] update: rustfmt configuration --- rustfmt.toml => .rustfmt.toml | 10 ++++++---- core/merkle-patricia-trie/src/proof.rs | 2 +- node/cli/src/service.rs | 2 +- node/runtime/src/impls.rs | 3 ++- srml/staking/src/tests.rs | 18 ++++++++++++++---- 5 files changed, 24 insertions(+), 11 deletions(-) rename rustfmt.toml => .rustfmt.toml (77%) diff --git a/rustfmt.toml b/.rustfmt.toml similarity index 77% rename from rustfmt.toml rename to .rustfmt.toml index 5463be9e1..ba7d698ec 100644 --- a/rustfmt.toml +++ b/.rustfmt.toml @@ -1,7 +1,9 @@ -max_width = 120 -tab_spaces = 4 +hard_tabs = true reorder_imports = true reorder_modules = true -use_try_shorthand = true -hard_tabs = true +use_field_init_shorthand = true + +max_width = 120 +tab_spaces = 4 + newline_style = "Unix" \ No newline at end of file diff --git a/core/merkle-patricia-trie/src/proof.rs b/core/merkle-patricia-trie/src/proof.rs index 1d0e6758b..cd54a98a6 100644 --- a/core/merkle-patricia-trie/src/proof.rs +++ b/core/merkle-patricia-trie/src/proof.rs @@ -43,7 +43,7 @@ mod tests { #[test] fn test_encode_decode() { let nodes = vec![vec![0u8], vec![1], vec![2]]; - let expected = Proof { nodes: nodes }; + let expected = Proof { nodes }; let rlp_proof = rlp::encode(&expected); let out_proof: Proof = rlp::decode(&rlp_proof).unwrap(); println!("{:?}", out_proof); diff --git a/node/cli/src/service.rs b/node/cli/src/service.rs index 4ad0841c5..7bf554096 100644 --- a/node/cli/src/service.rs +++ b/node/cli/src/service.rs @@ -201,7 +201,7 @@ macro_rules! new_full { (true, false) => { // start the full GRANDPA voter let grandpa_config = grandpa::GrandpaParams { - config: config, + config, link: grandpa_link, network: service.network(), inherent_data_providers: inherent_data_providers.clone(), diff --git a/node/runtime/src/impls.rs b/node/runtime/src/impls.rs index c23ef634e..dd847e772 100644 --- a/node/runtime/src/impls.rs +++ b/node/runtime/src/impls.rs @@ -112,7 +112,8 @@ impl> Convert for TargetedFeeAdjustment { } else { // Proof: first_term > second_term. Safe subtraction. let negative = first_term - second_term; - multiplier.saturating_sub(negative) + multiplier + .saturating_sub(negative) // despite the fact that apply_to saturates weight (final fee cannot go below 0) // it is crucially important to stop here and don't further reduce the weight fee // multiplier. While at -1, it means that the network is so un-congested that all diff --git a/srml/staking/src/tests.rs b/srml/staking/src/tests.rs index 159426f90..20053a4c1 100644 --- a/srml/staking/src/tests.rs +++ b/srml/staking/src/tests.rs @@ -450,12 +450,20 @@ fn staking_should_work() { assert_eq_uvec!(validator_controllers(), vec![20, 10]); // Put some money in account that we'll use. - for i in 1..5 { let _ = Ring::make_free_balance_be(&i, 2000); } + for i in 1..5 { + let _ = Ring::make_free_balance_be(&i, 2000); + } // --- Block 1: start_session(1); // Add a new candidate for being a validator. account 3 controlled by 4. - assert_ok!(Staking::bond(Origin::signed(3), 4, StakingBalances::RingBalance(1500), RewardDestination::Controller, 0)); + assert_ok!(Staking::bond( + Origin::signed(3), + 4, + StakingBalances::RingBalance(1500), + RewardDestination::Controller, + 0, + )); assert_ok!(Staking::validate( Origin::signed(4), ValidatorPrefs { @@ -473,7 +481,6 @@ fn staking_should_work() { // No effects will be seen so far. Era has not been yet triggered. assert_eq_uvec!(validator_controllers(), vec![20, 10]); - // --- Block 3: the validators will now be queued. start_session(3); assert_eq!(Staking::current_era(), 1); @@ -511,7 +518,10 @@ fn staking_should_work() { }, ); // e.g. It cannot spend more than 500 that it has free from the total 2000. - assert_noop!(Ring::reserve(&3, 501), "account liquidity restrictions prevent withdrawal"); + assert_noop!( + Ring::reserve(&3, 501), + "account liquidity restrictions prevent withdrawal", + ); assert_ok!(Ring::reserve(&3, 409)); }); } From ebe19cbbf21d6bf9b5e6586f7d16e1df89ee06fa Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Fri, 27 Dec 2019 17:55:46 +0800 Subject: [PATCH 15/17] update: format --- srml/eth-backing/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/srml/eth-backing/src/lib.rs b/srml/eth-backing/src/lib.rs index 22dde944f..d7b649b3e 100644 --- a/srml/eth-backing/src/lib.rs +++ b/srml/eth-backing/src/lib.rs @@ -166,8 +166,8 @@ decl_module! { ], anonymous: false, }; - let log_entry = verified_receipt. - logs + let log_entry = verified_receipt + .logs .iter() .find(|&x| x.address == Self::deposit_redeem_address() && x.topics[0] == eth_event.signature()) .ok_or("Log Entry - NOT FOUND")?; From d54c78446633d3478a58bd42bc8443cdd3d61d17 Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Fri, 27 Dec 2019 17:56:02 +0800 Subject: [PATCH 16/17] update: genesis --- node/cli/src/chain_spec.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/node/cli/src/chain_spec.rs b/node/cli/src/chain_spec.rs index 41578b625..eed1b2500 100644 --- a/node/cli/src/chain_spec.rs +++ b/node/cli/src/chain_spec.rs @@ -277,9 +277,9 @@ pub fn darwinia_genesis( eth_backing: Some(EthBackingConfig { ring_redeem_address: hex!["dbc888d701167cbfb86486c516aafbefc3a4de6e"].into(), kton_redeem_address: hex!["dbc888d701167cbfb86486c516aafbefc3a4de6e"].into(), - deposit_redeem_address: hex!["ad52e0f67b6f44cd5b9a6f4fbc7c0f78f37e094b"].into(), - ring_locked: 2000000000, - kton_locked: 50000, + deposit_redeem_address: hex!["6ef538314829efa8386fc43386cb13b4e0a67d1e"].into(), + ring_locked: 2_000_000_000 * COIN, + kton_locked: 50_000 * COIN, ..Default::default() }), } From 1cd25e71db9f05799328a89752f37f3906cfcda0 Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Fri, 27 Dec 2019 18:02:29 +0800 Subject: [PATCH 17/17] add: logo --- README.adoc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.adoc b/README.adoc index 58235fecc..36f6487d3 100644 --- a/README.adoc +++ b/README.adoc @@ -9,6 +9,8 @@ image:https://img.shields.io/badge/License-Apache%202.0-blue.svg[License,link=ht == Darwinia Relay Chain +image:https://github.com/darwinia-network/rfcs/raw/master/logo/darwinia.png[image] + Darwinia Relay Chain is the hub relay chain connecting different Darwinia AppChains and can be connected to Polkadot as a Polkadot Parachain. It could have two models, the Solo model and the Polkadot model. For more details, go to https://github.com/darwinia-network/rfcs/blob/master/zh_CN/0007-dawinia-token-staking-model.md#solo%E6%A8%A1%E5%BC%8F[RFC-0007].