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

tests for staking module #212

Merged
merged 11 commits into from
Jan 6, 2020
4 changes: 2 additions & 2 deletions srml/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ impl<T: Trait> Module<T> {
ledger
}

// TODO: doc
// update the ledger while bonding ring and compute the kton should return
fn bond_helper_in_ring(
stash: &T::AccountId,
controller: &T::AccountId,
Expand Down Expand Up @@ -1217,7 +1217,7 @@ impl<T: Trait> Module<T> {
Self::update_ledger(&controller, &mut ledger, StakingBalances::RingBalance(value));
}

// TODO: doc
// update the ledger while bonding controller with kton
fn bond_helper_in_kton(
controller: &T::AccountId,
value: KtonBalance<T>,
Expand Down
13 changes: 13 additions & 0 deletions srml/staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,19 @@ pub fn current_total_payout_for_duration(duration: u64) -> Balance {
).0
}

pub fn compute_power(ring_amount: u128, kton_amount: u128) -> Power {
fn calc_power<S: rstd::convert::TryInto<u128>>(active: S, pool: S) -> Power {
const HALF_POWER_COUNT: u128 = 1_000_000_000 / 2;

Perquintill::from_rational_approximation(
active.saturated_into::<Power>(),
pool.saturated_into::<Power>().max(1),
) * HALF_POWER_COUNT
}

calc_power(ring_amount, Staking::ring_pool()) + calc_power(kton_amount, Staking::kton_pool())
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate with power_of to some extend.

pub fn reward_all_elected() {
let rewards = <Module<Test>>::current_elected()
.iter()
Expand Down
Loading