Skip to content

Commit

Permalink
Merge pull request #212 from readlnh/develop
Browse files Browse the repository at this point in the history
tests for staking module
  • Loading branch information
hackfisher authored Jan 6, 2020
2 parents 04e5021 + 4fb160c commit a5ba7ae
Show file tree
Hide file tree
Showing 3 changed files with 890 additions and 757 deletions.
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())
}

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

0 comments on commit a5ba7ae

Please sign in to comment.