---
# System prepended metadata

title: EPM integration tests
tags: [' FRAME', parity, ' staking']

---

---
title: EPM integration tests
tags: parity, FRAME, staking
---

# EPM integration tests

Related to
- https://github.com/paritytech/substrate/issues/9057
- https://github.com/paritytech/substrate/pull/12972


**Goals**:
- Improve integration tests coverage for EPM, staking and related pallets;
- Test different edge and incident cases
    - EPM flow incidents
    - DataProvider incidents, insufficient data 
- Set up testbed in Versi to tests against different network conditions; 
- Document potential incident cases and how to solve them IRL;


### Testing scenarios
**1. Replicate the [Kusama incident](https://hackmd.io/Dt1L-JMtRc2y5FiOQik88A)**

**Root problem**: New session starts, staking is in `Forcing::ForceNew` due to slashes and calls into `EPM::elect()`. If EPM is in `Phase::Off` or the `Phase::Signed` has started recently, the solution queue may be empty as the election snapshot and/or solution for the era does not exist yet. As the election fails (and if the fallback election fails too), the EPM enters in emergency mode until a new solution is forced by `ForceOrigin`.

 - 1.1. Kusama incident: `staking::SessionManager::new_session()` triggered a new election after slashes happened:
 
    1. Slash enough validators in an era so that the list of offenders is larger than `T::OffendingValidatorsThreshold`.
	    - Expected behaviour: staking sets `Forcing::ForceNew`
    2. New session starts, `staking::SessionManager::new_session()` is called.
	    - Expected behaviour: since `Forcing::ForceNew` is set, `fn try_trigger_new_era` is called, which calls into `<T::ElectionProvider>::elect()`
    3. If EPM is in `Phase::Off` (or `Phase::Signed` and solution queue is still empty), the feasibility test does not complete. 
	    - Expected behaviour: if `T::Fallback` fails, the election fails; EPM phase goes to `Phase::Emergency`.

**Related**:
- 1.2. EPM failing with empty snapshot
- 1.3. EPM failing with non-empty snapshot

**2. Large validator slash events**
- 2.1. Slash validator set 10% each era (+ document what happens).
- 2.2. Slashing event decreases score below `MinUntrustedScore`.

**3. OCW miner behavior**
- 3.1. No OCW miner solution during signed phase; No unsigned submission.

**4. Emergency phase**
- 4.1. During emergency phase, slash a % of the validators/nominators in the static snapshot.

---
