diff --git a/state-chain/pallets/cf-lp/src/benchmarking.rs b/state-chain/pallets/cf-lp/src/benchmarking.rs index f8982ebbd20..379ee699824 100644 --- a/state-chain/pallets/cf-lp/src/benchmarking.rs +++ b/state-chain/pallets/cf-lp/src/benchmarking.rs @@ -1,14 +1,19 @@ #![cfg(feature = "runtime-benchmarks")] +#[cfg(test)] +mod mock; + use super::*; use cf_chains::{address::EncodedAddress, benchmarking_value::BenchmarkValue}; -use cf_primitives::Asset; -use cf_traits::AccountRoleRegistry; +use cf_primitives::{Asset, FLIPPERINOS_PER_FLIP}; +use cf_traits::{AccountRoleRegistry, FeePayment}; use frame_benchmarking::v2::*; use frame_support::{assert_ok, traits::OnNewAccount}; use frame_system::RawOrigin; -#[benchmarks] +#[benchmarks( + where ::Amount: From +)] mod benchmarks { use super::*; use sp_std::vec; @@ -22,6 +27,8 @@ mod benchmarks { RawOrigin::Signed(caller.clone()).into(), EncodedAddress::Eth(Default::default()), )); + // A non-zero balance is required to pay for the channel opening fee. + T::FeePayment::mint_to_account(&caller, (5 * FLIPPERINOS_PER_FLIP).into()); #[extrinsic_call] request_liquidity_deposit_address(RawOrigin::Signed(caller), Asset::Eth, 0); diff --git a/state-chain/pallets/cf-lp/src/lib.rs b/state-chain/pallets/cf-lp/src/lib.rs index 9426927b11c..b440a8ea67e 100644 --- a/state-chain/pallets/cf-lp/src/lib.rs +++ b/state-chain/pallets/cf-lp/src/lib.rs @@ -65,6 +65,12 @@ pub mod pallet { /// Benchmark weights type WeightInfo: WeightInfo; + + #[cfg(feature = "runtime-benchmarks")] + type FeePayment: cf_traits::FeePayment< + Amount = ::Amount, + AccountId = ::AccountId, + >; } #[pallet::error] diff --git a/state-chain/pallets/cf-lp/src/mock.rs b/state-chain/pallets/cf-lp/src/mock.rs index cf618247e35..7af9a21cd2e 100644 --- a/state-chain/pallets/cf-lp/src/mock.rs +++ b/state-chain/pallets/cf-lp/src/mock.rs @@ -13,6 +13,8 @@ use cf_traits::{ }, AccountRoleRegistry, }; +#[cfg(feature = "runtime-benchmarks")] +use fee_payment::MockFeePayment; use frame_support::{assert_ok, parameter_types, sp_runtime::app_crypto::sp_core::H160}; use frame_system as system; use sp_core::H256; @@ -99,6 +101,8 @@ impl crate::Config for Test { type SafeMode = MockRuntimeSafeMode; type WeightInfo = (); type PoolApi = Self; + #[cfg(feature = "runtime-benchmarks")] + type FeePayment = MockFeePayment; } pub const LP_ACCOUNT: [u8; 32] = [1u8; 32]; diff --git a/state-chain/pallets/cf-swapping/src/benchmarking.rs b/state-chain/pallets/cf-swapping/src/benchmarking.rs index 91157129a28..ebbc1bb1fbe 100644 --- a/state-chain/pallets/cf-swapping/src/benchmarking.rs +++ b/state-chain/pallets/cf-swapping/src/benchmarking.rs @@ -3,7 +3,8 @@ use super::*; use cf_chains::{address::EncodedAddress, benchmarking_value::BenchmarkValue}; -use cf_traits::AccountRoleRegistry; +use cf_primitives::FLIPPERINOS_PER_FLIP; +use cf_traits::{AccountRoleRegistry, FeePayment}; use frame_benchmarking::v2::*; use frame_support::{ assert_ok, @@ -11,7 +12,9 @@ use frame_support::{ }; use frame_system::RawOrigin; -#[benchmarks] +#[benchmarks( + where ::Amount: From +)] mod benchmarks { use super::*; use sp_std::vec; @@ -21,6 +24,8 @@ mod benchmarks { let caller: T::AccountId = whitelisted_caller(); ::OnNewAccount::on_new_account(&caller); assert_ok!(T::AccountRoleRegistry::register_as_broker(&caller)); + // A non-zero balance is required to pay for the channel opening fee. + T::FeePayment::mint_to_account(&caller, (5 * FLIPPERINOS_PER_FLIP).into()); let origin = RawOrigin::Signed(caller); let call = Call::::request_swap_deposit_address { diff --git a/state-chain/pallets/cf-swapping/src/lib.rs b/state-chain/pallets/cf-swapping/src/lib.rs index 6585e680b8d..a48da637268 100644 --- a/state-chain/pallets/cf-swapping/src/lib.rs +++ b/state-chain/pallets/cf-swapping/src/lib.rs @@ -226,6 +226,12 @@ pub mod pallet { /// The Weight information. type WeightInfo: WeightInfo; + + #[cfg(feature = "runtime-benchmarks")] + type FeePayment: cf_traits::FeePayment< + Amount = ::Amount, + AccountId = ::AccountId, + >; } #[pallet::pallet] diff --git a/state-chain/pallets/cf-swapping/src/mock.rs b/state-chain/pallets/cf-swapping/src/mock.rs index 12e954fe302..d7748b8aaca 100644 --- a/state-chain/pallets/cf-swapping/src/mock.rs +++ b/state-chain/pallets/cf-swapping/src/mock.rs @@ -11,6 +11,8 @@ use cf_traits::{ }, AccountRoleRegistry, SwappingApi, }; +#[cfg(feature = "runtime-benchmarks")] +use fee_payment::MockFeePayment; use frame_support::{pallet_prelude::DispatchError, parameter_types, weights::Weight}; use frame_system as system; use sp_core::H256; @@ -139,6 +141,8 @@ impl pallet_cf_swapping::Config for Test { type SwappingApi = MockSwappingApi; type SafeMode = MockRuntimeSafeMode; type WeightInfo = MockWeightInfo; + #[cfg(feature = "runtime-benchmarks")] + type FeePayment = MockFeePayment; } pub const ALICE: ::AccountId = 123u64; diff --git a/state-chain/runtime/src/lib.rs b/state-chain/runtime/src/lib.rs index 1ba929509ab..4a7a0689e30 100644 --- a/state-chain/runtime/src/lib.rs +++ b/state-chain/runtime/src/lib.rs @@ -234,6 +234,8 @@ impl pallet_cf_swapping::Config for Runtime { type AddressConverter = ChainAddressConverter; type SafeMode = RuntimeSafeMode; type WeightInfo = pallet_cf_swapping::weights::PalletWeight; + #[cfg(feature = "runtime-benchmarks")] + type FeePayment = Flip; } impl pallet_cf_vaults::Config for Runtime { @@ -348,6 +350,8 @@ impl pallet_cf_lp::Config for Runtime { type SafeMode = RuntimeSafeMode; type PoolApi = LiquidityPools; type WeightInfo = pallet_cf_lp::weights::PalletWeight; + #[cfg(feature = "runtime-benchmarks")] + type FeePayment = Flip; } impl pallet_cf_account_roles::Config for Runtime {