Skip to content

Commit d67afca

Browse files
committed
fixed tests that were using incorrect value for min_bonded_dhx_daily and rewards_allowance_dhx_daily so not reducing remaining. fix by funding treasury in tests so rewards paid
1 parent c338381 commit d67afca

File tree

3 files changed

+90
-71
lines changed

3 files changed

+90
-71
lines changed

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ pub mod pallet {
6565
},
6666
};
6767

68-
pub const default_bonded_amount: u128 = 25_133_000_000_000_000_000_000u128;
68+
// this is only a default for test purposes and fallback.
69+
// set this to 0u128 in production
70+
pub const default_bonded_amount_u128: u128 = 25_133_000_000_000_000_000_000u128;
6971

7072
// type BalanceOf<T> = <T as pallet_balances::Config>::Balance;
7173
type BalanceOf<T> = <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
@@ -786,7 +788,7 @@ pub mod pallet {
786788
// half of 5000 DHX daily allowance (of 2500 DHX), but in that case we split the rewards
787789
// (i.e. 25,133 DHX locked at 10:1 gives 2513 DHX reward)
788790

789-
let mut locks_first_amount_as_u128 = default_bonded_amount.clone();
791+
let mut locks_first_amount_as_u128 = default_bonded_amount_u128.clone();
790792
let locked_vec = <pallet_balances::Pallet<T>>::locks(miner.clone()).into_inner();
791793
if locked_vec.len() != 0 {
792794
// println!("locked_vec: {:?}", locked_vec);
@@ -1277,6 +1279,9 @@ pub mod pallet {
12771279
// we could just divide both numbers by 1000000000000000000, so we'd have say 5000 and 1 instead,
12781280
// since we're just using these values to get a multiplier output.
12791281

1282+
println!("000 {:?}", rewards_allowance_dhx_daily_u128);
1283+
println!("001 {:?}", rewards_aggregated_dhx_daily_as_u128);
1284+
12801285
let mut manageable_rewards_allowance_dhx_daily_u128 = 0u128;
12811286
if let Some(_manageable_rewards_allowance_dhx_daily_u128) =
12821287
rewards_allowance_dhx_daily_u128.clone().checked_div(1000000000000000000u128) {
@@ -1328,7 +1333,7 @@ pub mod pallet {
13281333
}
13291334
}
13301335
log::info!("distribution_multiplier_for_day_fixed128 {:#?}", distribution_multiplier_for_day_fixed128);
1331-
// println!("[multiplier] block: {:#?}, miner: {:#?}, date_start: {:#?} distribution_multiplier_for_day_fixed128: {:#?}", _n, miner_count, start_of_requested_date_millis, distribution_multiplier_for_day_fixed128);
1336+
println!("[multiplier] block: {:#?}, miner: {:#?}, date_start: {:#?} distribution_multiplier_for_day_fixed128: {:#?}", _n, miner_count, start_of_requested_date_millis, distribution_multiplier_for_day_fixed128);
13321337

13331338
// Initialise outside the loop as we need this value after the loop after we finish iterating through all the miners
13341339
let mut rewards_allowance_dhx_remaining_today_as_u128 = 0u128;
@@ -1374,6 +1379,7 @@ pub mod pallet {
13741379
continue;
13751380
}
13761381
log::info!("daily_reward_for_miner_as_u128: {:?}", daily_reward_for_miner_as_u128.clone());
1382+
println!("0 {:?}", daily_reward_for_miner_as_u128);
13771383

13781384
let mut manageable_daily_reward_for_miner_as_u128 = 0u128;
13791385
if let Some(_manageable_daily_reward_for_miner_as_u128) =
@@ -1383,6 +1389,7 @@ pub mod pallet {
13831389
log::error!("Unable to divide daily_reward_for_miner_as_u128 to make it smaller");
13841390
return 0;
13851391
}
1392+
println!("1 {:?}", manageable_daily_reward_for_miner_as_u128);
13861393

13871394
// Multiply, handling overflow
13881395
// TODO - probably have to initialise below proportion_of_daily_reward_for_miner_fixed128 to 0u128,
@@ -1402,7 +1409,7 @@ pub mod pallet {
14021409
}
14031410
}
14041411
log::info!("proportion_of_daily_reward_for_miner_fixed128: {:?}", proportion_of_daily_reward_for_miner_fixed128.clone());
1405-
1412+
println!("2 {:?}", proportion_of_daily_reward_for_miner_fixed128);
14061413
// round down to nearest integer. we need to round down, because if we round up then if there are
14071414
// 3x registered miners with 5000 DHX rewards allowance per day then they would each get 1667 rewards,
14081415
// but there would only be 1666 remaining after the first two, so the last one would miss out.
@@ -1419,7 +1426,7 @@ pub mod pallet {
14191426
return 0;
14201427
}
14211428

1422-
// println!("[rewards] block: {:#?}, miner: {:#?}, date_start: {:#?} restored_proportion_of_daily_reward_for_miner_u128: {:#?}", _n, miner_count, start_of_requested_date_millis, restored_proportion_of_daily_reward_for_miner_u128);
1429+
println!("[rewards] block: {:#?}, miner: {:#?}, date_start: {:#?} restored_proportion_of_daily_reward_for_miner_u128: {:#?}", _n, miner_count, start_of_requested_date_millis, restored_proportion_of_daily_reward_for_miner_u128);
14231430

14241431
let treasury_account_id: T::AccountId = <pallet_treasury::Pallet<T>>::account_id();
14251432
let max_payout = pallet_balances::Pallet::<T>::usable_balance(treasury_account_id.clone());
@@ -1467,6 +1474,9 @@ pub mod pallet {
14671474
return 0;
14681475
}
14691476

1477+
println!("[prepared-for-payment] block: {:#?}, miner: {:#?}, date_start: {:#?} max payout: {:#?}, rewards remaining today {:?}, restored_proportion_of_daily_reward_for_miner_u128 {:?}",
1478+
_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);
1479+
14701480
// check if miner's reward is less than or equal to: rewards_allowance_dhx_daily_remaining
14711481
if restored_proportion_of_daily_reward_for_miner_u128.clone() > 0u128 &&
14721482
rewards_allowance_dhx_remaining_today_as_u128.clone() >= restored_proportion_of_daily_reward_for_miner_u128.clone() &&
@@ -1529,7 +1539,7 @@ pub mod pallet {
15291539
new_rewards_allowance_dhx_remaining_today.clone(),
15301540
);
15311541

1532-
// println!("[paid] block: {:#?}, miner: {:#?}, date_start: {:#?} new_rewards_allowance_dhx_remaining_today: {:#?}", _n, miner_count, start_of_requested_date_millis, new_rewards_allowance_dhx_remaining_today);
1542+
println!("[paid] block: {:#?}, miner: {:#?}, date_start: {:#?} new_rewards_allowance_dhx_remaining_today: {:#?}", _n, miner_count, start_of_requested_date_millis, new_rewards_allowance_dhx_remaining_today);
15331543

15341544
// emit event with reward payment history rather than bloating storage
15351545
Self::deposit_event(Event::TransferredRewardsAllowanceDHXToMinerForDate(

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -444,8 +444,8 @@ impl MiningRewardsAllowanceConfig for Test {
444444
pub type SysEvent = frame_system::Event<Test>;
445445
pub type DemocracyEvent = pallet_democracy::Event<Test>;
446446

447-
pub const INIT_DAO_BALANCE: u128 = 30_000_000_000_000_000_000_000_000u128;
448-
pub const TOTAL_SUPPLY: u128 = 100_000_000_000_000_000_000_000_000u128;
447+
pub const INIT_DAO_BALANCE_DHX: u128 = 30_000_000_000_000_000_000_000_000u128;
448+
pub const TOTAL_SUPPLY_DHX: u128 = 100_000_000_000_000_000_000_000_000u128;
449449
pub const TEN_DHX: u128 = 10_000_000_000_000_000_000u128;
450450

451451
// This function basically just builds a genesis storage key/value store according to
@@ -454,11 +454,12 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
454454
let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
455455
pallet_balances::GenesisConfig::<Test> {
456456
balances: vec![
457-
(0, INIT_DAO_BALANCE),
457+
(0, TEN_DHX),
458458
(1, TEN_DHX),
459459
(2, TEN_DHX),
460460
(3, TEN_DHX),
461-
(100, TOTAL_SUPPLY)],
461+
(100, TOTAL_SUPPLY_DHX),
462+
],
462463
}
463464
.assimilate_storage(&mut t)
464465
.unwrap();

0 commit comments

Comments
 (0)