-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The goal of this PR is to implement storage of reward pool history. Closes #1710
- Loading branch information
1 parent
19bea84
commit 6dc96b4
Showing
6 changed files
with
98 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,74 @@ | ||
use super::mock::*; | ||
use crate::{ | ||
tests::testing_utils::{run_to_block, system_run_to_block}, | ||
CurrentEraInfo, RewardEraInfo, | ||
use super::{ | ||
mock::*, | ||
testing_utils::{run_to_block, system_run_to_block}, | ||
}; | ||
use crate::{Config, CurrentEraInfo, RewardEraInfo, RewardPoolInfo, StakingRewardPool}; | ||
use sp_core::Get; | ||
|
||
#[test] | ||
fn start_new_era_if_needed() { | ||
fn start_new_era_if_needed_updates_era_info_and_limits_reward_pool_size() { | ||
new_test_ext().execute_with(|| { | ||
CurrentEraInfo::<Test>::set(RewardEraInfo { era_index: 1, started_at: 0 }); | ||
StakingRewardPool::<Test>::insert( | ||
1, | ||
RewardPoolInfo { | ||
total_staked_token: 10_000, | ||
total_reward_pool: 1_000, | ||
unclaimed_balance: 1_000, | ||
}, | ||
); | ||
system_run_to_block(9); | ||
run_to_block(10); | ||
let mut current_era_info = CurrentEraInfo::<Test>::get(); | ||
assert_eq!(current_era_info.era_index, 2u32); | ||
assert_eq!(current_era_info.started_at, 10u32); | ||
for i in 1..4 { | ||
let block_decade = i * 10; | ||
run_to_block(block_decade); | ||
|
||
let current_era_info = CurrentEraInfo::<Test>::get(); | ||
|
||
system_run_to_block(19); | ||
run_to_block(20); | ||
current_era_info = CurrentEraInfo::<Test>::get(); | ||
assert_eq!(current_era_info.era_index, 3u32); | ||
assert_eq!(current_era_info.started_at, 20u32); | ||
let expected_era = i + 1; | ||
assert_eq!(current_era_info.era_index, expected_era); | ||
assert_eq!(current_era_info.started_at, block_decade); | ||
let past_eras_max: u32 = <Test as Config>::StakingRewardsPastErasMax::get(); | ||
assert!(StakingRewardPool::<Test>::count().le(&past_eras_max)); | ||
system_run_to_block(block_decade + 9); | ||
} | ||
}) | ||
} | ||
|
||
#[test] | ||
fn start_new_era_if_needed_updates_reward_pool() { | ||
new_test_ext().execute_with(|| { | ||
CurrentEraInfo::<Test>::set(RewardEraInfo { era_index: 1, started_at: 0 }); | ||
StakingRewardPool::<Test>::insert( | ||
1, | ||
RewardPoolInfo { | ||
total_staked_token: 10_000, | ||
total_reward_pool: 1_000, | ||
unclaimed_balance: 1_000, | ||
}, | ||
); | ||
system_run_to_block(8); | ||
|
||
// TODO: Provider boost, after staking updates reward pool info #1699 | ||
// let staker = 10_000; | ||
// let provider_msa: MessageSourceId = 1; | ||
// let stake_amount = 600u64; | ||
// setup_provider(&staker, &provider_msa, &stake_amount, ProviderBoost); | ||
|
||
system_run_to_block(9); | ||
run_to_block(10); | ||
assert_eq!(StakingRewardPool::<Test>::count(), 2); | ||
let current_reward_pool_info = StakingRewardPool::<Test>::get(2).unwrap(); | ||
assert_eq!( | ||
current_reward_pool_info, | ||
RewardPoolInfo { | ||
total_staked_token: 10_000, | ||
total_reward_pool: 1_000, | ||
unclaimed_balance: 1_000, | ||
} | ||
); | ||
|
||
// TODO: after staking updates reward pool info #1699 | ||
// system_run_to_block(19); | ||
// run_to_block(20); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters