diff --git a/runtime/gdev/tests/integration_tests.rs b/runtime/gdev/tests/integration_tests.rs index d9e2e90a4e78d79fa23f58222c719f8ae844b0c1..f6b7cef6b49620184694e7e411ded339540d5915 100644 --- a/runtime/gdev/tests/integration_tests.rs +++ b/runtime/gdev/tests/integration_tests.rs @@ -1414,3 +1414,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 }, + )); + }) +}