Repository: paritytech/substrate
File: frame/election-provider-multi-phase/test-staking-e2e/src/lib.rs (Rust)

Code before:
/// Related to <https://github.com/paritytech/substrate/issues/13714>.
fn set_validation_intention_after_chilled() {
	use frame_election_provider_support::SortedListProvider;
	use pallet_staking::{Event, Forcing, Nominators, ValidatorPrefs};

	let staking_builder = StakingExtBuilder::default();
	let epm_builder = EpmExtBuilder::default();

	ExtBuilder::default()
		.staking(staking_builder)
		.epm(epm_builder)
		.build_and_execute(|| {
			assert_eq!(active_era(), 0);
			// validator is part of the validator set.
			assert!(Session::validators().contains(&11));
			assert!(<Runtime as pallet_staking::Config>::VoterList::contains(&11));

			// nominate validator 11.
			assert_ok!(Staking::nominate(RuntimeOrigin::signed(20), vec![11]));
			assert_eq!(Nominators::<Runtime>::get(21).unwrap().targets, vec![11]);

			// validator is slashed. it is removed from the `VoterList` through chilling but in the
			// current era, the validator is still part of the active validator set.
			add_slash(&11);
			assert!(Session::validators().contains(&11));
			assert!(<Runtime as pallet_staking::Config>::VoterList::contains(&11) == false);
			assert_eq!(
				staking_events(),
				[
					Event::Chilled { stash: 11 },
					Event::ForceEra { mode: Forcing::ForceNew },
					Event::SlashReported {
						validator: 11,
						slash_era: 0,
						fraction: Perbill::from_percent(10)
					}
				],
			);

			// after the nominator is slashed and chilled, the nominations remain.
			assert_eq!(Nominators::<Runtime>::get(21).unwrap().targets, vec![11]);

			// validator sets intention to stake again in the same era it was chilled.
			assert_ok!(Staking::validate(RuntimeOrigin::signed(10), ValidatorPrefs::default()));

			// progress era and check that the slashed validator is still part of the validator
			// set.
			assert!(start_next_active_era().is_ok());
			assert_eq!(active_era(), 1);
			assert!(Session::validators().contains(&11));
			assert!(<Runtime as pallet_staking::Config>::VoterList::contains(&11));

Review comment (suggestion):
```suggestion
			assert!(!<Runtime as pallet_staking::Config>::VoterList::contains(&11));
```

Code after:
///
/// This behaviour is due to removing implicit chill upon slash
/// <https://github.com/paritytech/substrate/pull/12420>.
///
/// Related to <https://github.com/paritytech/substrate/issues/13714>.
fn set_validation_intention_after_chilled() {
	use frame_election_provider_support::SortedListProvider;
	use pallet_staking::{Event, Forcing, Nominators};

	let staking_builder = StakingExtBuilder::default();
	let epm_builder = EpmExtBuilder::default();

	ExtBuilder::default()
		.staking(staking_builder)
		.epm(epm_builder)
		.build_and_execute(|| {
			assert_eq!(active_era(), 0);
			// validator is part of the validator set.
			assert!(Session::validators().contains(&81));
			assert!(<Runtime as pallet_staking::Config>::VoterList::contains(&81));

			// nominate validator 81.
			assert_ok!(Staking::nominate(RuntimeOrigin::signed(21), vec![81]));
			assert_eq!(Nominators::<Runtime>::get(21).unwrap().targets, vec![81]);

			// validator is slashed. it is removed from the `VoterList` through chilling but in the
			// current era, the validator is still part of the active validator set.
			add_slash(&81);
			assert!(Session::validators().contains(&81));
			assert!(!<Runtime as pallet_staking::Config>::VoterList::contains(&81));
			assert_eq!(
				staking_events(),
				[
					Event::Chilled { stash: 81 },
					Event::ForceEra { mode: Forcing::ForceNew },
					Event::SlashReported {
						validator: 81,
						slash_era: 0,
						fraction: Perbill::from_percent(10)
					}
				],
			);

			// after the nominator is slashed and chilled, the nominations remain.
			assert_eq!(Nominators::<Runtime>::get(21).unwrap().targets, vec![81]);

			// validator sets intention to stake again in the same era it was chilled.
			assert_ok!(Staking::validate(RuntimeOrigin::signed(81), Default::default()));

			// progress era and check that the slashed validator is still part of the validator
			// set.