diff --git a/.maintain/ci/build_script.sh b/.maintain/ci/build_script.sh index 071af53e9..b3f8d64e2 100755 --- a/.maintain/ci/build_script.sh +++ b/.maintain/ci/build_script.sh @@ -14,7 +14,7 @@ case $TARGET in # Without WASM "native") # There is some issue to build on ci server with SKIP_WASM_BUILD=1 - cargo build --release --all --locked "$@" + cargo build --all --locked "$@" echo -e "\e[0;32m +-------------+ \n\e[0;32m | Native Pass | \n\e[0;32m +-------------+ \e[0m" ;; diff --git a/.maintain/ci/darwinia_test_script.sh b/.maintain/ci/darwinia_test_script.sh index dcd85e674..29b7ae7e7 100755 --- a/.maintain/ci/darwinia_test_script.sh +++ b/.maintain/ci/darwinia_test_script.sh @@ -15,7 +15,7 @@ case $TARGET in # Without WASM "native") # There is some issue to build on ci server with SKIP_WASM_BUILD=1 - cargo test -p darwinia-${1} + TARGET=native cargo test -p darwinia-${1} echo -e "\e[0;32m +------------+ \n\e[0;32m | ${1} Pass | \n\e[0;32m +------------+ \e[0m" ;; diff --git a/.travis.yml b/.travis.yml index 493b9fa0b..0daa5bd6d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,11 +2,6 @@ language: rust rust: - nightly -cache: - cargo: true - directories: - - target - branches: only: - master @@ -19,12 +14,11 @@ env: before_install: # Check how much space we've got on this machine. - df -h - # TODO: cache the toolchain - rustup target add wasm32-unknown-unknown jobs: include: - - stage: Check + - stage: Check & Prepare script: .maintain/ci/fmt_script.sh - stage: Build @@ -51,10 +45,6 @@ jobs: env: RUST_TOOLCHAIN=nightly TARGET=native script: .maintain/ci/test_script.sh - # clean up cache - - stage: Cleanup - script: cargo clean - after_script: # Check how much free disk space left after the build - df -h diff --git a/frame/balances/kton/src/mock.rs b/frame/balances/kton/src/mock.rs index 5c7288c8a..4fdd97b54 100644 --- a/frame/balances/kton/src/mock.rs +++ b/frame/balances/kton/src/mock.rs @@ -1,5 +1,6 @@ use std::cell::RefCell; +use darwinia_ring as ring; use frame_support::{impl_outer_origin, parameter_types, weights::Weight}; use sp_core::H256; use sp_io; @@ -14,7 +15,6 @@ use sp_runtime::{ }; use crate::*; -use darwinia_ring as ring; pub type AccountId = u64; pub type Balance = u128; diff --git a/frame/balances/ring/src/mock.rs b/frame/balances/ring/src/mock.rs index 47595b5ac..408fff866 100644 --- a/frame/balances/ring/src/mock.rs +++ b/frame/balances/ring/src/mock.rs @@ -29,6 +29,8 @@ use sp_runtime::{ }; use std::cell::RefCell; +pub type Ring = Module; + use frame_system as system; impl_outer_origin! { pub enum Origin for Test {} @@ -88,6 +90,7 @@ impl frame_system::Trait for Test { type Version = (); type ModuleToIndex = (); } + parameter_types! { pub const TransactionBaseFee: u64 = 0; pub const TransactionByteFee: u64 = 1; diff --git a/frame/balances/ring/src/tests.rs b/frame/balances/ring/src/tests.rs index 0986b7fe7..bfd4ca331 100644 --- a/frame/balances/ring/src/tests.rs +++ b/frame/balances/ring/src/tests.rs @@ -16,18 +16,18 @@ //! Tests for the module. +use sp_runtime::traits::SignedExtension; + use super::*; +use crate::mock::*; +use crate::mock::{info_from_weight, Balances, ExtBuilder, System, Test, CALL}; +use darwinia_support::{LockIdentifier, LockableCurrency, NormalLock, WithdrawLock, WithdrawReason, WithdrawReasons}; use frame_support::{ assert_err, assert_noop, assert_ok, - traits::{ - Currency, ExistenceRequirement::AllowDeath, LockIdentifier, LockableCurrency, ReservableCurrency, - WithdrawReason, WithdrawReasons, - }, + traits::{Currency, ExistenceRequirement::AllowDeath, ReservableCurrency}, }; use frame_system::RawOrigin; -use mock::{info_from_weight, Balances, ExtBuilder, System, Test, CALL}; use pallet_transaction_payment::ChargeTransactionPayment; -use sp_runtime::traits::{BadOrigin, SignedExtension}; const ID_1: LockIdentifier = *b"1 "; const ID_2: LockIdentifier = *b"2 "; @@ -41,7 +41,15 @@ fn basic_locking_should_work() { .build() .execute_with(|| { assert_eq!(Balances::free_balance(&1), 10); - Balances::set_lock(ID_1, &1, 9, u64::max_value(), WithdrawReasons::all()); + Ring::set_lock( + ID_1, + &1, + WithdrawLock::Normal(NormalLock { + amount: 9, + until: u64::max_value(), + }), + WithdrawReasons::all(), + ); assert_noop!( >::transfer(&1, &2, 5, AllowDeath), Error::::LiquidityRestrictions @@ -56,7 +64,15 @@ fn partial_locking_should_work() { .monied(true) .build() .execute_with(|| { - Balances::set_lock(ID_1, &1, 5, u64::max_value(), WithdrawReasons::all()); + Ring::set_lock( + ID_1, + &1, + WithdrawLock::Normal(NormalLock { + amount: 5, + until: u64::max_value(), + }), + WithdrawReasons::all(), + ); assert_ok!(>::transfer(&1, &2, 1, AllowDeath)); }); } @@ -68,7 +84,15 @@ fn lock_removal_should_work() { .monied(true) .build() .execute_with(|| { - Balances::set_lock(ID_1, &1, u64::max_value(), u64::max_value(), WithdrawReasons::all()); + Ring::set_lock( + ID_1, + &1, + WithdrawLock::Normal(NormalLock { + amount: u64::max_value(), + until: u64::max_value(), + }), + WithdrawReasons::all(), + ); Balances::remove_lock(ID_1, &1); assert_ok!(>::transfer(&1, &2, 1, AllowDeath)); }); @@ -81,8 +105,24 @@ fn lock_replacement_should_work() { .monied(true) .build() .execute_with(|| { - Balances::set_lock(ID_1, &1, u64::max_value(), u64::max_value(), WithdrawReasons::all()); - Balances::set_lock(ID_1, &1, 5, u64::max_value(), WithdrawReasons::all()); + Ring::set_lock( + ID_1, + &1, + WithdrawLock::Normal(NormalLock { + amount: u64::max_value(), + until: u64::max_value(), + }), + WithdrawReasons::all(), + ); + Ring::set_lock( + ID_1, + &1, + WithdrawLock::Normal(NormalLock { + amount: 5, + until: u64::max_value(), + }), + WithdrawReasons::all(), + ); assert_ok!(>::transfer(&1, &2, 1, AllowDeath)); }); } @@ -94,8 +134,24 @@ fn double_locking_should_work() { .monied(true) .build() .execute_with(|| { - Balances::set_lock(ID_1, &1, 5, u64::max_value(), WithdrawReasons::all()); - Balances::set_lock(ID_2, &1, 5, u64::max_value(), WithdrawReasons::all()); + Ring::set_lock( + ID_1, + &1, + WithdrawLock::Normal(NormalLock { + amount: 5, + until: u64::max_value(), + }), + WithdrawReasons::all(), + ); + Ring::set_lock( + ID_2, + &1, + WithdrawLock::Normal(NormalLock { + amount: 5, + until: u64::max_value(), + }), + WithdrawReasons::all(), + ); assert_ok!(>::transfer(&1, &2, 1, AllowDeath)); }); } @@ -107,35 +163,31 @@ fn combination_locking_should_work() { .monied(true) .build() .execute_with(|| { - Balances::set_lock(ID_1, &1, u64::max_value(), 0, WithdrawReasons::none()); - Balances::set_lock(ID_2, &1, 0, u64::max_value(), WithdrawReasons::none()); - Balances::set_lock(ID_3, &1, 0, 0, WithdrawReasons::all()); - assert_ok!(>::transfer(&1, &2, 1, AllowDeath)); - }); -} - -#[test] -fn lock_value_extension_should_work() { - ExtBuilder::default() - .existential_deposit(1) - .monied(true) - .build() - .execute_with(|| { - Balances::set_lock(ID_1, &1, 5, u64::max_value(), WithdrawReasons::all()); - assert_noop!( - >::transfer(&1, &2, 6, AllowDeath), - Error::::LiquidityRestrictions + Ring::set_lock( + ID_1, + &1, + WithdrawLock::Normal(NormalLock { + amount: u64::max_value(), + until: 0, + }), + WithdrawReasons::none(), ); - Balances::extend_lock(ID_1, &1, 2, u64::max_value(), WithdrawReasons::all()); - assert_noop!( - >::transfer(&1, &2, 6, AllowDeath), - Error::::LiquidityRestrictions + Ring::set_lock( + ID_2, + &1, + WithdrawLock::Normal(NormalLock { + amount: 0, + until: u64::max_value(), + }), + WithdrawReasons::none(), ); - Balances::extend_lock(ID_1, &1, 8, u64::max_value(), WithdrawReasons::all()); - assert_noop!( - >::transfer(&1, &2, 3, AllowDeath), - Error::::LiquidityRestrictions + Ring::set_lock( + ID_3, + &1, + WithdrawLock::Normal(NormalLock { amount: 0, until: 0 }), + WithdrawReasons::all(), ); + assert_ok!(>::transfer(&1, &2, 1, AllowDeath)); }); } @@ -146,7 +198,15 @@ fn lock_reasons_should_work() { .monied(true) .build() .execute_with(|| { - Balances::set_lock(ID_1, &1, 10, u64::max_value(), WithdrawReason::Transfer.into()); + Ring::set_lock( + ID_1, + &1, + WithdrawLock::Normal(NormalLock { + amount: 10, + until: u64::max_value(), + }), + WithdrawReason::Transfer.into(), + ); assert_noop!( >::transfer(&1, &2, 1, AllowDeath), Error::::LiquidityRestrictions @@ -162,7 +222,15 @@ fn lock_reasons_should_work() { ) .is_ok()); - Balances::set_lock(ID_1, &1, 10, u64::max_value(), WithdrawReason::Reserve.into()); + Ring::set_lock( + ID_1, + &1, + WithdrawLock::Normal(NormalLock { + amount: 10, + until: u64::max_value(), + }), + WithdrawReason::Reserve.into(), + ); assert_ok!(>::transfer(&1, &2, 1, AllowDeath)); assert_noop!( >::reserve(&1, 1), @@ -177,11 +245,13 @@ fn lock_reasons_should_work() { ) .is_ok()); - Balances::set_lock( + Ring::set_lock( ID_1, &1, - 10, - u64::max_value(), + WithdrawLock::Normal(NormalLock { + amount: 10, + until: u64::max_value(), + }), WithdrawReason::TransactionPayment.into(), ); assert_ok!(>::transfer(&1, &2, 1, AllowDeath)); @@ -204,7 +274,12 @@ fn lock_block_number_should_work() { .monied(true) .build() .execute_with(|| { - Balances::set_lock(ID_1, &1, 10, 2, WithdrawReasons::all()); + Ring::set_lock( + ID_1, + &1, + WithdrawLock::Normal(NormalLock { amount: 10, until: 2 }), + WithdrawReasons::all(), + ); assert_noop!( >::transfer(&1, &2, 1, AllowDeath), Error::::LiquidityRestrictions @@ -215,57 +290,6 @@ fn lock_block_number_should_work() { }); } -#[test] -fn lock_block_number_extension_should_work() { - ExtBuilder::default() - .existential_deposit(1) - .monied(true) - .build() - .execute_with(|| { - Balances::set_lock(ID_1, &1, 10, 2, WithdrawReasons::all()); - assert_noop!( - >::transfer(&1, &2, 6, AllowDeath), - Error::::LiquidityRestrictions - ); - Balances::extend_lock(ID_1, &1, 10, 1, WithdrawReasons::all()); - assert_noop!( - >::transfer(&1, &2, 6, AllowDeath), - Error::::LiquidityRestrictions - ); - System::set_block_number(2); - Balances::extend_lock(ID_1, &1, 10, 8, WithdrawReasons::all()); - assert_noop!( - >::transfer(&1, &2, 3, AllowDeath), - Error::::LiquidityRestrictions - ); - }); -} - -#[test] -fn lock_reasons_extension_should_work() { - ExtBuilder::default() - .existential_deposit(1) - .monied(true) - .build() - .execute_with(|| { - Balances::set_lock(ID_1, &1, 10, 10, WithdrawReason::Transfer.into()); - assert_noop!( - >::transfer(&1, &2, 6, AllowDeath), - Error::::LiquidityRestrictions - ); - Balances::extend_lock(ID_1, &1, 10, 10, WithdrawReasons::none()); - assert_noop!( - >::transfer(&1, &2, 6, AllowDeath), - Error::::LiquidityRestrictions - ); - Balances::extend_lock(ID_1, &1, 10, 10, WithdrawReason::Reserve.into()); - assert_noop!( - >::transfer(&1, &2, 6, AllowDeath), - Error::::LiquidityRestrictions - ); - }); -} - #[test] fn default_indexing_on_new_accounts_should_not_work2() { ExtBuilder::default() @@ -395,7 +419,10 @@ 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), BadOrigin,); + assert_err!( + Balances::force_transfer(Some(2).into(), 1, 2, 69), + DispatchError::BadOrigin, + ); 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);