Repository: paritytech/substrate
File: frame/election-provider-multi-phase/src/unsigned.rs (Rust)

Code before:
			assert!(pool.read().transactions.len().is_zero());
			storage.clear();

			// submits!
			MultiPhase::offchain_worker(25);
			assert!(!pool.read().transactions.len().is_zero());
		})
	}

	#[test]
	fn ocw_can_submit_to_pool() {
		let (mut ext, pool) = ExtBuilder::default().build_offchainify(0);
		ext.execute_with(|| {
			roll_to_with_ocw(25);
			assert_eq!(MultiPhase::current_phase(), Phase::Unsigned((true, 25)));
			// OCW must have submitted now

			let encoded = pool.read().transactions[0].clone();
			let extrinsic: Extrinsic = Decode::decode(&mut &*encoded).unwrap();
			let call = extrinsic.call;
			assert!(matches!(call, OuterCall::MultiPhase(Call::submit_unsigned(_, _))));
		})
	}

	#[test]
	fn trim_compact_for_length_does_not_modify_when_short_enough() {
		let (mut ext, _) = ExtBuilder::default().build_offchainify(0);
		ext.execute_with(|| {
			roll_to(25);

			let RoundSnapshot { voters, ..} =
				MultiPhase::snapshot().unwrap();

			let RawSolution { mut compact, .. } = raw_solution();
			let encoded_len = compact.encode().len() as u32;
			let compact_clone = compact.clone();

			compact = MultiPhase::trim_compact_for_length(
				encoded_len,
				compact,
				voter_index_fn_linear::<Runtime>(&voters),
			).unwrap();

			assert_eq!(compact, compact_clone);
		});
	}

	#[test]
	fn trim_compact_for_length_modifies_when_too_long() {
		let (mut ext, _) = ExtBuilder::default().build_offchainify(0);
		ext.execute_with(|| {

Review comment (suggestion):
I think these two tests can be combined where you basically test 

1. `encoded_len > compact_len`
2. `encoded_len == compact_len`
3.`encoded_len < compact_len`

Code after:
	fn ocw_only_runs_when_unsigned_open_now() {
		let (mut ext, pool) = ExtBuilder::default().build_offchainify(0);
		ext.execute_with(|| {
			roll_to(25);
			assert_eq!(MultiPhase::current_phase(), Phase::Unsigned((true, 25)));

			// we must clear the offchain storage to ensure the offchain execution check doesn't get
			// in the way.
			let mut storage = StorageValueRef::persistent(&OFFCHAIN_HEAD_DB);

			MultiPhase::offchain_worker(24);
			assert!(pool.read().transactions.len().is_zero());
			storage.clear();

			MultiPhase::offchain_worker(26);
			assert!(pool.read().transactions.len().is_zero());
			storage.clear();

			// submits!
			MultiPhase::offchain_worker(25);
			assert!(!pool.read().transactions.len().is_zero());
		})
	}

	#[test]
	fn ocw_can_submit_to_pool() {
		let (mut ext, pool) = ExtBuilder::default().build_offchainify(0);
		ext.execute_with(|| {
			roll_to_with_ocw(25);
			assert_eq!(MultiPhase::current_phase(), Phase::Unsigned((true, 25)));
			// OCW must have submitted now

			let encoded = pool.read().transactions[0].clone();
			let extrinsic: Extrinsic = Decode::decode(&mut &*encoded).unwrap();
			let call = extrinsic.call;
			assert!(matches!(call, OuterCall::MultiPhase(Call::submit_unsigned(_, _))));
		})
	}

	#[test]
	fn trim_compact_length_does_not_modify_when_short_enough() {
		let mut ext = ExtBuilder::default().build();
		ext.execute_with(|| {
			roll_to(25);

			// given
			let RoundSnapshot { voters, ..} = MultiPhase::snapshot().unwrap();
			let RawSolution { mut compact, .. } = raw_solution();
			let encoded_len = compact.encode().len() as u32;
			let compact_clone = compact.clone();