Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test/staking #293

Merged
merged 6 commits into from
Feb 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ jobs:
env: RUST_TOOLCHAIN=nightly-2020-02-07 TARGET=native RING
script: .maintain/ci/darwinia_test_script.sh ring

# TODO: remove this, when staking test case upgrade ready
allow_failures:
- stage: Darwinia Test
env: RUST_TOOLCHAIN=nightly-2020-02-07 TARGET=native STAKING
script: .maintain/ci/darwinia_test_script.sh staking

# TODO: remove this when overall test case ready
allow_failures:
- stage: Overall Test
env: RUST_TOOLCHAIN=nightly-2020-02-07 TARGET=native
script: .maintain/ci/test_script.sh
Expand Down
6 changes: 4 additions & 2 deletions frame/chainrelay/eth/backing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ decl_module! {

<MomentT<T>>::saturated_from(Moment::try_from(month)? as _)
};
// TODO: Check the time unit in seconds or milliseconds
// https://github.com/evolutionlandorg/bank/blob/master/contracts/GringottsBankV2.sol#L178
// The start_at here is in seconds, will be converted to milliseconds later in on_deposit_redeem
let start_at = {
let start_at = result
.params[3]
Expand All @@ -238,7 +239,8 @@ decl_module! {
<MomentT<T>>::saturated_from(Moment::try_from(start_at)? as _)
};
let redeemed_ring = {
// TODO: div 10**18 and mul 10**9
// The decimal in Ethereum is 10**18, and the decimal in Darwinia is 10**9,
// div 10**18 and mul 10**9
let amount = result.params[5]
.value
.clone()
Expand Down
6 changes: 3 additions & 3 deletions frame/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1887,8 +1887,8 @@ impl<T: Trait> Module<T> {
let validators = Self::current_elected();
let (total_payout, max_payout) = inflation::compute_total_payout::<T>(
era_duration,
T::Time::now() - T::GenesisTime::get(),
T::Cap::get() - T::RingCurrency::total_issuance(),
now - T::GenesisTime::get(),
T::Cap::get().saturating_sub(T::RingCurrency::total_issuance()),
PayoutFraction::get(),
);
let mut total_imbalance = <RingPositiveImbalance<T>>::zero();
Expand Down Expand Up @@ -2378,7 +2378,7 @@ impl<T: Trait> OnDepositRedeem<T::AccountId> for Module<T> {
let controller = Self::bonded(&stash).ok_or(<Error<T>>::NotStash)?;
let ledger = Self::ledger(&controller).ok_or(<Error<T>>::NotController)?;

// TODO: Issue #169, checking the timestamp unit difference between Ethereum and Darwinia
// The timestamp unit is different between Ethereum and Darwinia, converting from seconds to milliseconds
let start_time = start_time * 1000;
let promise_month = months.min(36);

Expand Down
22 changes: 14 additions & 8 deletions frame/staking/src/mock.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
//! Test utilities

use std::{
cell::RefCell,
collections::HashSet,
time::{SystemTime, UNIX_EPOCH},
};
use std::{cell::RefCell, collections::HashSet};

use frame_support::{
assert_ok, impl_outer_origin, parameter_types,
Expand All @@ -15,6 +11,7 @@ use frame_support::{
use sp_core::{crypto::key_types, H256};
use sp_io;
use sp_runtime::{
print,
testing::{Header, UintAuthorityId},
traits::{IdentityLookup, OnInitialize, OpaqueKeys, SaturatedConversion},
{KeyTypeId, Perbill},
Expand All @@ -28,7 +25,7 @@ use crate::*;

pub type AccountId = u64;
pub type BlockNumber = u64;
pub type Balance = u64;
pub type Balance = u128;

pub type System = system::Module<Test>;
pub type Session = pallet_session::Module<Test>;
Expand All @@ -43,7 +40,8 @@ pub const MICRO: Balance = 1_000 * NANO;
pub const MILLI: Balance = 1_000 * MICRO;
pub const COIN: Balance = 1_000 * MILLI;

pub const CAP: Balance = 1_000_000_000 * COIN;
pub const CAP: Balance = 10_000_000_000 * COIN;
pub const GENESIS_TIME: Moment = 0;
pub const TOTAL_POWER: Power = 1_000_000_000;

thread_local! {
Expand Down Expand Up @@ -203,7 +201,7 @@ parameter_types! {

pub const Cap: Balance = CAP;
pub const TotalPower: Power = TOTAL_POWER;
pub const GenesisTime: Moment = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_millis() as _;
pub const GenesisTime: Moment = GENESIS_TIME;
}
impl Trait for Test {
type Time = pallet_timestamp::Module<Self>;
Expand Down Expand Up @@ -419,6 +417,14 @@ pub fn check_exposure(stash: AccountId) {
// );
}

pub fn assert_ledger_consistent(stash: u64) {
assert_is_stash(stash);
let ledger = Staking::ledger(stash - 1).unwrap();

assert_eq!(ledger.active_ring, ledger.ring_staking_lock.staking_amount);
assert_eq!(ledger.active_kton, ledger.kton_staking_lock.staking_amount);
}

/// Check that for each nominator: slashable_balance > sum(used_balance)
/// Note: we might not consume all of a nominator's balance, but we MUST NOT over spend it.
pub fn check_nominator_exposure(stash: AccountId) {
Expand Down
Loading