Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aurexav committed Nov 6, 2023
1 parent 49b007a commit 74a6dfe
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
14 changes: 3 additions & 11 deletions pallet/staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,7 @@ impl darwinia_staking::OnSessionEnd<Runtime> for OnDarwiniaSessionEnd {
}

fn reward(who: &AccountId, amount: Balance) -> sp_runtime::DispatchResult {
if let Err(e) = Balances::deposit_into_existing(who, amount) {
// TODO: log
// log::error!("[runtime::staking] reward error: {:?}", e);
}
let _ = Balances::deposit_into_existing(who, amount);

Ok(())
}
Expand All @@ -334,17 +331,12 @@ impl darwinia_staking::OnSessionEnd<Runtime> for OnCrabSessionEnd {
}

fn reward(who: &AccountId, amount: Balance) -> sp_runtime::DispatchResult {
if let Err(e) = <Balances as Currency<AccountId>>::transfer(
<Balances as Currency<AccountId>>::transfer(
&Treasury::account_id(),
who,
amount,
frame_support::traits::ExistenceRequirement::KeepAlive,
) {
// TODO: log
// log::error!("[runtime::staking] reward error: {:?}", e);
}

Ok(())
)
}
}
impl darwinia_staking::Config for Runtime {
Expand Down
25 changes: 25 additions & 0 deletions pallet/staking/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,31 @@ fn payout_should_work() {
Balances::free_balance(&Treasury::account_id()),
1_000_000 * UNIT - rewards.iter().sum::<Balance>()
);

dbg!(Balances::free_balance(&Treasury::account_id()));
assert_ok!(Balances::transfer_all(
RuntimeOrigin::signed(Treasury::account_id()),
Default::default(),
false
));
dbg!(Balances::free_balance(&Treasury::account_id()));
Staking::reward_by_ids(&[(1, 20)]);
System::reset_events();
new_session();

assert_eq!(
System::events()
.into_iter()
.filter_map(|e| match e.event {
RuntimeEvent::Staking(e @ Event::Unpaied { .. }) => Some(e),
_ => None,
})
.collect::<Vec<_>>(),
vec![
Event::Unpaied { staker: 6, amount: 7499999997000000000000 },
Event::Unpaied { staker: 1, amount: 2499999994000000000000 }
]
);
});
}

Expand Down

0 comments on commit 74a6dfe

Please sign in to comment.