mirror of
https://git.ghostchain.io/proxmio/ghost-node.git
synced 2025-12-27 03:09:56 +00:00
tests for clap and applause events added
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
This commit is contained in:
@@ -660,7 +660,70 @@ fn should_self_applause_if_enough_received_claps() {
|
||||
});
|
||||
}
|
||||
|
||||
// TODO: check event
|
||||
#[test]
|
||||
fn should_emit_event_on_each_clap_and_on_applause() {
|
||||
let (network_id, transaction_hash, unique_transaction_hash) =
|
||||
generate_unique_hash(None, None, None, None);
|
||||
let (_, receiver, amount) = get_mocked_metadata();
|
||||
|
||||
new_test_ext().execute_with(|| {
|
||||
let commission = Perbill::from_parts(100_000_000); // 10%
|
||||
let commission_amount = commission.mul_ceil(amount);
|
||||
let amount_after_commission = amount.saturating_sub(commission_amount);
|
||||
let _ = prepare_evm_network(Some(network_id), Some(100_000_000));
|
||||
let session_index = advance_session_and_get_index();
|
||||
let storage_key = (session_index, transaction_hash, unique_transaction_hash);
|
||||
|
||||
assert_eq!(pallet::ApplausesForTransaction::<Runtime>::get(&storage_key), false);
|
||||
assert_claps_info_correct(&storage_key, &session_index, 0);
|
||||
assert_ok!(do_clap_from(session_index, network_id, 0, false));
|
||||
System::assert_last_event(RuntimeEvent::SlowClap(
|
||||
crate::Event::Clapped {
|
||||
receiver: receiver.clone(),
|
||||
authority_id: 0,
|
||||
network_id,
|
||||
transaction_hash,
|
||||
amount,
|
||||
}));
|
||||
|
||||
assert_eq!(pallet::ApplausesForTransaction::<Runtime>::get(&storage_key), false);
|
||||
assert_claps_info_correct(&storage_key, &session_index, 1);
|
||||
assert_ok!(do_clap_from(session_index, network_id, 1, false));
|
||||
let binding = System::events();
|
||||
let last_two_events = binding
|
||||
.iter()
|
||||
.rev()
|
||||
.take(5)
|
||||
.collect::<Vec<_>>();
|
||||
assert_eq!(last_two_events[0].event, RuntimeEvent::SlowClap(
|
||||
crate::Event::Applaused {
|
||||
network_id,
|
||||
receiver: receiver.clone(),
|
||||
received_amount: amount_after_commission,
|
||||
}));
|
||||
assert_eq!(last_two_events[4].event, RuntimeEvent::SlowClap(
|
||||
crate::Event::Clapped {
|
||||
receiver: receiver.clone(),
|
||||
authority_id: 1,
|
||||
network_id,
|
||||
transaction_hash,
|
||||
amount,
|
||||
}));
|
||||
|
||||
assert_eq!(pallet::ApplausesForTransaction::<Runtime>::get(&storage_key), true);
|
||||
assert_claps_info_correct(&storage_key, &session_index, 2);
|
||||
assert_ok!(do_clap_from(session_index, network_id, 2, false));
|
||||
System::assert_last_event(RuntimeEvent::SlowClap(
|
||||
crate::Event::Clapped {
|
||||
receiver: receiver.clone(),
|
||||
authority_id: 2,
|
||||
network_id,
|
||||
transaction_hash,
|
||||
amount,
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
// TODO: multiple logs will create multiple records
|
||||
// TODO: errors should be checked as much as possible
|
||||
// TODO: offences generated as expected
|
||||
|
||||
Reference in New Issue
Block a user