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

fix rebase errors and formatting

parent 4cf251fa
No related branches found
No related tags found
1 merge request!216Add end2end test for offences
Pipeline #34902 passed
This commit is part of merge request !216. Comments created here will be created in the context of that merge request.
...@@ -23,7 +23,6 @@ use frame_support::traits::{Get, PalletInfo, StorageInfo, StorageInfoTrait}; ...@@ -23,7 +23,6 @@ use frame_support::traits::{Get, PalletInfo, StorageInfo, StorageInfoTrait};
use frame_support::{assert_noop, assert_ok}; use frame_support::{assert_noop, assert_ok};
use frame_support::{StorageHasher, Twox128}; use frame_support::{StorageHasher, Twox128};
use gdev_runtime::*; use gdev_runtime::*;
use pallet_duniter_wot::IdtyRemovalWotReason;
use pallet_membership::MembershipRemovalReason; use pallet_membership::MembershipRemovalReason;
use sp_core::Encode; use sp_core::Encode;
use sp_keyring::AccountKeyring; use sp_keyring::AccountKeyring;
......
...@@ -21,6 +21,7 @@ use frame_support::assert_ok; ...@@ -21,6 +21,7 @@ use frame_support::assert_ok;
use frame_support::traits::ValidatorSet; use frame_support::traits::ValidatorSet;
use frame_support::traits::ValidatorSetWithIdentification; use frame_support::traits::ValidatorSetWithIdentification;
use gdev_runtime::*; use gdev_runtime::*;
use pallet_im_online as im_online;
use pallet_im_online::UnresponsivenessOffence; use pallet_im_online::UnresponsivenessOffence;
use pallet_session::historical::IdentificationTuple; use pallet_session::historical::IdentificationTuple;
use sp_runtime::traits::Convert; use sp_runtime::traits::Convert;
...@@ -29,38 +30,44 @@ use sp_staking::offence::ReportOffence; ...@@ -29,38 +30,44 @@ use sp_staking::offence::ReportOffence;
#[test] #[test]
fn test_imonline_offence() { fn test_imonline_offence() {
ExtBuilder::new(1, 3, 4).build().execute_with(|| { ExtBuilder::new(1, 3, 4).build().execute_with(|| {
run_to_block(1); run_to_block(1);
let session_index = Session::current_index(); let session_index = Session::current_index();
let current_validators= <Runtime as pallet_im_online::Config>::ValidatorSet::validators(); let current_validators = <Runtime as im_online::Config>::ValidatorSet::validators();
// Construct an offence where all validators (member: 1) are offenders // Construct an offence where all validators (member: 1) are offenders
let offenders = current_validators let offenders = current_validators
.into_iter() .into_iter()
.enumerate() .enumerate()
.filter_map(|(_, id)| { .filter_map(|(_, id)| {
<<Runtime as pallet_im_online::Config>::ValidatorSet as ValidatorSetWithIdentification<sp_runtime::AccountId32>>::IdentificationOf::convert( <<Runtime as im_online::Config>::ValidatorSet as ValidatorSetWithIdentification<
id.clone() sp_runtime::AccountId32,
).map(|full_id| (id, full_id)) >>::IdentificationOf::convert(id.clone())
}) .map(|full_id| (id, full_id))
.collect::<Vec<IdentificationTuple<Runtime>>>(); })
let keys = ImOnline::keys(); .collect::<Vec<IdentificationTuple<Runtime>>>();
let validator_set_count = keys.len() as u32; let keys = ImOnline::keys();
let offence = UnresponsivenessOffence { session_index, validator_set_count, offenders }; let validator_set_count = keys.len() as u32;
assert_ok!(<Runtime as pallet_im_online::Config>::ReportUnresponsiveness::report_offence(vec![], offence)); let offence = UnresponsivenessOffence {
// An offence is deposited session_index,
System::assert_has_event(RuntimeEvent::Offences( validator_set_count,
pallet_offences::Event::Offence { offenders,
kind: *b"im-online:offlin", };
timeslot: vec![0, 0, 0, 0], assert_ok!(
}, <Runtime as pallet_im_online::Config>::ReportUnresponsiveness::report_offence(
)); vec![],
// Offenders are punished offence
)
);
// An offence is deposited
System::assert_has_event(RuntimeEvent::Offences(pallet_offences::Event::Offence {
kind: *b"im-online:offlin",
timeslot: vec![0, 0, 0, 0],
}));
// Offenders are punished
System::assert_has_event(RuntimeEvent::AuthorityMembers( System::assert_has_event(RuntimeEvent::AuthorityMembers(
pallet_authority_members::Event::MemberGoOffline { pallet_authority_members::Event::MemberGoOffline { member: 1 },
member: 1
},
)); ));
assert_eq!(AuthorityMembers::blacklist().len(), 0); assert_eq!(AuthorityMembers::blacklist().len(), 0);
}) })
} }
#[test] #[test]
fn test_grandpa_offence() { fn test_grandpa_offence() {
......
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