Skip to content
Snippets Groups Projects
Unverified Commit d11deac8 authored by bgallois's avatar bgallois
Browse files

add end2end test babe offences

parent 3b47c197
No related branches found
No related tags found
1 merge request!216Add end2end test for offences
This commit is part of merge request !216. Comments created here will be created in the context of that merge request.
......@@ -1392,3 +1392,43 @@ fn test_grandpa_offence() {
));
})
}
#[test]
fn test_babe_offence() {
ExtBuilder::new(1, 3, 4).build().execute_with(|| {
run_to_block(1);
let session_index = Session::current_index();
let current_validators = <Runtime as pallet_im_online::Config>::ValidatorSet::validators();
// Construct an offence where all validators (member: 1) are offenders
let mut offenders = current_validators
.into_iter()
.enumerate()
.filter_map(|(_, id)| {
<Runtime as pallet_session::historical::Config>::FullIdentificationOf::convert(
id.clone(),
)
.map(|full_id| (id, full_id))
})
.collect::<Vec<IdentificationTuple<Runtime>>>();
let keys = ImOnline::keys();
let validator_set_count = keys.len() as u32;
let offence = pallet_babe::EquivocationOffence {
slot: 0u64.into(),
session_index,
validator_set_count,
offender: offenders.pop().unwrap().into(),
};
let _ = Offences::report_offence(vec![], offence);
// An offence is deposited
System::assert_has_event(RuntimeEvent::Offences(pallet_offences::Event::Offence {
kind: *b"babe:equivocatio",
timeslot: vec![0, 0, 0, 0, 0, 0, 0, 0],
}));
// Offenders are punished
System::assert_has_event(RuntimeEvent::AuthorityMembers(
pallet_authority_members::Event::MemberGoOffline { member: 1 },
));
System::assert_has_event(RuntimeEvent::AuthorityMembers(
pallet_authority_members::Event::MemberAddedToBlacklist { member: 1 },
));
})
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment