Skip to content

Commit 26f2d54

Browse files
committed
add test to confirm that reward multiplier doubles after each 10:1 reward period
1 parent 10fce79 commit 26f2d54

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

pallets/mining/rewards-allowance/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,8 +1630,7 @@ pub mod pallet {
16301630
return 0;
16311631
}
16321632

1633-
// println!("[prepared-for-payment] block: {:#?}, miner: {:#?}, date_start: {:#?} max payout: {:#?}, rewards remaining today {:?}, restored_proportion_of_daily_reward_for_miner_u128 {:?}",
1634-
// _n, miner_count, start_of_requested_date_millis, max_payout_as_u128, rewards_allowance_dhx_remaining_today_as_u128, restored_proportion_of_daily_reward_for_miner_u128);
1633+
// println!("[prepared-for-payment] block: {:#?}, miner: {:#?}, date_start: {:#?} max payout: {:#?}, rewards remaining today {:?}, restored_proportion_of_daily_reward_for_miner_u128 {:?}", _n, miner_count, start_of_requested_date_millis, max_payout_as_u128, rewards_allowance_dhx_remaining_today_as_u128, restored_proportion_of_daily_reward_for_miner_u128);
16351634

16361635
// check if miner's reward is less than or equal to: rewards_allowance_dhx_daily_remaining
16371636
if restored_proportion_of_daily_reward_for_miner_u128.clone() > 0u128 &&

pallets/mining/rewards-allowance/src/tests.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const NORMAL_AMOUNT: u128 = 25_133_000_000_000_000_000_000u128; // 25,133 DHX
2121
const LARGE_AMOUNT_DHX: u128 = 33_333_333_333_000_000_000_000_000u128; // 33,333,333.333 DHX
2222
const TWO_THOUSAND_DHX: u128 = 2_000_000_000_000_000_000_000_u128; // 2,000
2323
const FIVE_HUNDRED_DHX: u128 = 500_000_000_000_000_000_000_u128; // 500
24+
const THIRTY_DHX: u128 = 30_000_000_000_000_000_000_u128; // 30
2425
const TWENTY_DHX: u128 = 20_000_000_000_000_000_000_u128; // 20
2526
const TWO_DHX: u128 = 2_000_000_000_000_000_000_u128; // 2
2627

@@ -309,6 +310,7 @@ fn distribute_rewards(amount_bonded_each_miner: u128) {
309310
// 27th August 2021 @ 12am is 1630022400000 (start of day)
310311
Timestamp::set_timestamp(1630049371000u64);
311312
MiningRewardsAllowanceTestModule::on_initialize(2);
313+
assert_eq!(MiningRewardsAllowanceTestModule::rewards_multiplier_current_period_days_remaining(), Some((1630022400000, 1630022400000, 2u32, 2u32)));
312314
// System::on_initialize(2);
313315
// System::on_finalize(2);
314316
// System::set_block_number(2);
@@ -322,6 +324,7 @@ fn distribute_rewards(amount_bonded_each_miner: u128) {
322324
// 28th August 2021 @ 12am is 1635379200000 (start of day)
323325
Timestamp::set_timestamp(1635406274000u64);
324326
MiningRewardsAllowanceTestModule::on_initialize(3);
327+
assert_eq!(MiningRewardsAllowanceTestModule::rewards_multiplier_current_period_days_remaining(), Some((1630022400000, 1635379200000, 2u32, 1u32)));
325328

326329
// check that on_initialize has populated this storage value automatically for the start of the current date
327330
// still cooling off so no rewards distributed on this date
@@ -377,7 +380,10 @@ fn distribute_rewards(amount_bonded_each_miner: u128) {
377380
assert_eq!(MiningRewardsAllowanceTestModule::rewards_multiplier_next_change(), Some(10u32));
378381
assert_eq!(MiningRewardsAllowanceTestModule::rewards_multiplier_next_period_days(), Some(2u32));
379382
assert_eq!(MiningRewardsAllowanceTestModule::rewards_multiplier_current_period_days_total(), Some(2u32));
383+
// start of new multiplier period
380384
assert_eq!(MiningRewardsAllowanceTestModule::rewards_multiplier_current_period_days_remaining(), Some((1630281600000, 1630281600000, 2u32, 2u32)));
385+
386+
// Note - these are just notes. no further action required
381387
// Note - why is this 2u128 instead of reset back to say 5000u128 DHX (unless set do different value??
382388
// this should be reset after rewards aggregated/accumulated each day
383389
// since distribution/claiming may not be done by a user each day
@@ -391,6 +397,33 @@ fn distribute_rewards(amount_bonded_each_miner: u128) {
391397
// Update: difficult to add a test to check they are reset before next day, just check it works using the logs.
392398
// assert_eq!(MiningRewardsAllowanceTestModule::rewards_aggregated_dhx_for_all_miners_for_date(1630281600000), Some(0u128));
393399
// assert_eq!(MiningRewardsAllowanceTestModule::rewards_accumulated_dhx_for_miner_for_date((1630281600000, 1)), Some(0u128));
400+
401+
// 31th August 2021 @ ~7am is 1630393200000
402+
// 31th August 2021 @ 12am is 1630368000000 (start of day)
403+
Timestamp::set_timestamp(1630393200000u64);
404+
MiningRewardsAllowanceTestModule::on_initialize(6);
405+
// cooling off period doesn't change again unless they unbond
406+
assert_eq!(MiningRewardsAllowanceTestModule::cooling_off_period_days_remaining(1), Some((1630368000000, 0, 1)));
407+
assert_eq!(MiningRewardsAllowanceTestModule::rewards_multiplier_current_period_days_remaining(), Some((1630281600000, 1630368000000, 2u32, 1u32)));
408+
assert_eq!(MiningRewardsAllowanceTestModule::rewards_multiplier_current_change(), Some(10u32));
409+
410+
// 1st Sept 2021 @ ~7am is 1630479600000
411+
// 1st Sept 2021 @ 12am is 1630454400000 (start of day)
412+
Timestamp::set_timestamp(1630479600000u64);
413+
MiningRewardsAllowanceTestModule::on_initialize(7);
414+
assert_eq!(MiningRewardsAllowanceTestModule::cooling_off_period_days_remaining(1), Some((1630454400000, 0, 1)));
415+
assert_eq!(MiningRewardsAllowanceTestModule::rewards_multiplier_current_period_days_remaining(), Some((1630281600000, 1630454400000, 2u32, 0u32)));
416+
assert_eq!(MiningRewardsAllowanceTestModule::rewards_multiplier_current_change(), Some(10u32));
417+
418+
// 2nd Sept 2021 @ ~7am is 1630566000000
419+
// 2nd Sept 2021 @ 12am is 1630540800000 (start of day)
420+
Timestamp::set_timestamp(1630566000000u64);
421+
MiningRewardsAllowanceTestModule::on_initialize(7);
422+
assert_eq!(MiningRewardsAllowanceTestModule::cooling_off_period_days_remaining(1), Some((1630540800000, 0, 1)));
423+
// start of new multiplier period
424+
assert_eq!(MiningRewardsAllowanceTestModule::rewards_multiplier_current_period_days_remaining(), Some((1630540800000, 1630540800000, 2u32, 2u32)));
425+
// check that the min_bonded_dhx_daily doubled after 3 months (we're only doing it after 2 days in the tests though) from 20 DHX to 30 DHX
426+
assert_eq!(MiningRewardsAllowanceTestModule::min_bonded_dhx_daily(), Some(THIRTY_DHX));
394427
}
395428

396429
fn setup_bonding(amount_bonded_each_miner: u128, min_bonding_dhx_daily: u128) {

0 commit comments

Comments
 (0)