Repository: paritytech/substrate
File: frame/asset-conversion/src/benchmarking.rs (Rust)

Code before:
	let lp_token = get_lp_token_id::<T>();

	(lp_token, caller, caller_lookup)
}

fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) {
	let events = frame_system::Pallet::<T>::events();
	let system_event: <T as frame_system::Config>::RuntimeEvent = generic_event.into();
	// compare to the last event record
	let frame_system::EventRecord { event, .. } = &events[events.len() - 1];
	assert_eq!(event, &system_event);
}

benchmarks! {
	where_clause {
		where
			T::AssetBalance: From<u128> + Into<u128>,
			T::Currency: Unbalanced<T::AccountId>,
			T::Balance: From<u128> + Into<u128>,
			T::Assets: Create<T::AccountId> + Mutate<T::AccountId>,
			T::PoolAssetId: Into<u32>,
	}

	create_pool {
		let asset1 = T::MultiAssetIdConverter::get_native();
		let asset2 = T::BenchmarkHelper::mutliasset_id(0_u32);
		let (caller, _) = create_asset::<T>(&asset2);
	}: _(SystemOrigin::Signed(caller.clone()), asset1.clone(), asset2.clone())
	verify {
		let lp_token = get_lp_token_id::<T>();
		let pool_id = (asset1.clone(), asset2.clone());
		assert_last_event::<T>(Event::PoolCreated {
			creator: caller.clone(),
			pool_account: AssetConversion::<T>::get_pool_account(&pool_id),
			pool_id,
			lp_token }.into()
		);
	}

	add_liquidity {
		let asset1 = T::MultiAssetIdConverter::get_native();
		let asset2 = T::BenchmarkHelper::mutliasset_id(0);
		let (lp_token, caller, _) = create_asset_and_pool::<T>(&asset1, &asset2);
		let ed: u128 = T::Currency::minimum_balance().into();
		let add_amount = 1000 + ed;
	}: _(SystemOrigin::Signed(caller.clone()), asset1.clone(), asset2.clone(), add_amount.into(), 1000.into(), 0.into(), 0.into(), caller.clone())
	verify {
		let pool_id = (asset1.clone(), asset2.clone());
		let lp_minted = AssetConversion::<T>::calc_lp_amount_for_zero_supply(&add_amount.into(), &1000.into()).unwrap().into();
		assert_eq!(
			T::PoolAssets::balance(lp_token, &caller),

Review comment (refactor):
```suggestion
		let asset2 = T::BenchmarkHelper::mutliasset_id(0);
```

Code after:
	));
	let lp_token = get_lp_token_id::<T>();

	(lp_token, caller, caller_lookup)
}

fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) {
	let events = frame_system::Pallet::<T>::events();
	let system_event: <T as frame_system::Config>::RuntimeEvent = generic_event.into();
	// compare to the last event record
	let frame_system::EventRecord { event, .. } = &events[events.len() - 1];
	assert_eq!(event, &system_event);
}

benchmarks! {
	where_clause {
		where
			T::AssetBalance: From<u128> + Into<u128>,
			T::Currency: Unbalanced<T::AccountId>,
			T::Balance: From<u128> + Into<u128>,
			T::Assets: Create<T::AccountId> + Mutate<T::AccountId>,
			T::PoolAssetId: Into<u32>,
	}

	create_pool {
		let asset1 = T::MultiAssetIdConverter::get_native();
		let asset2 = T::BenchmarkHelper::multiasset_id(0);
		let (caller, _) = create_asset::<T>(&asset2);
	}: _(SystemOrigin::Signed(caller.clone()), asset1.clone(), asset2.clone())
	verify {
		let lp_token = get_lp_token_id::<T>();
		let pool_id = (asset1.clone(), asset2.clone());
		assert_last_event::<T>(Event::PoolCreated {
			creator: caller.clone(),
			pool_account: AssetConversion::<T>::get_pool_account(&pool_id),
			pool_id,
			lp_token,
		}.into());
	}

	add_liquidity {
		let asset1 = T::MultiAssetIdConverter::get_native();
		let asset2 = T::BenchmarkHelper::multiasset_id(0);
		let (lp_token, caller, _) = create_asset_and_pool::<T>(&asset1, &asset2);
		let ed: u128 = T::Currency::minimum_balance().into();
		let add_amount = 1000 + ed;
	}: _(SystemOrigin::Signed(caller.clone()), asset1.clone(), asset2.clone(), add_amount.into(), 1000.into(), 0.into(), 0.into(), caller.clone())
	verify {
		let pool_id = (asset1.clone(), asset2.clone());
		let lp_minted = AssetConversion::<T>::calc_lp_amount_for_zero_supply(&add_amount.into(), &1000.into()).unwrap().into();
		assert_eq!(