diff --git a/runtime/integration-tests/src/generic/cases/example.rs b/runtime/integration-tests/src/generic/cases/example.rs index ce9f3383bf..0e99907f03 100644 --- a/runtime/integration-tests/src/generic/cases/example.rs +++ b/runtime/integration-tests/src/generic/cases/example.rs @@ -23,8 +23,7 @@ fn transfer_balance() { // Set up all GenesisConfig for your initial state // You can choose `RuntimeEnv` by `FudgeEnv` to make it working with fudge // environment. - let mut env = RuntimeEnv::::from_storage( - Default::default(), + let mut env = RuntimeEnv::::from_parachain_storage( Genesis::default() .add(pallet_balances::GenesisConfig:: { balances: vec![( @@ -33,7 +32,6 @@ fn transfer_balance() { )], }) .storage(), - Genesis::::default().storage(), ); // Call an extrinsic that would be processed immediately @@ -76,8 +74,7 @@ fn fudge_transfer_balance() { const TRANSFER: Balance = 1000 * CFG; const FOR_FEES: Balance = 1 * CFG; - let mut env = FudgeEnv::::from_storage( - Default::default(), + let mut env = FudgeEnv::::from_parachain_storage( Genesis::default() .add(pallet_balances::GenesisConfig:: { balances: vec![( @@ -86,7 +83,6 @@ fn fudge_transfer_balance() { )], }) .storage(), - Genesis::::default().storage(), ); env.submit_later( @@ -133,8 +129,7 @@ fn fudge_transfer_balance() { } fn call_api() { - let env = - RuntimeEnv::::from_storage(Default::default(), Default::default(), Default::default()); + let env = RuntimeEnv::::default(); env.parachain_state(|| { // If imported the trait: sp_api::runtime_decl_for_core::CoreV4, @@ -147,8 +142,7 @@ fn call_api() { } fn fudge_call_api() { - let env = - FudgeEnv::::from_storage(Default::default(), Default::default(), Default::default()); + let env = FudgeEnv::::default(); // Exclusive from fudge environment. // It uses a client to access the runtime api. @@ -164,8 +158,7 @@ fn fudge_call_api() { } fn pass_time_one_block() { - let mut env = - RuntimeEnv::::from_storage(Default::default(), Default::default(), Default::default()); + let mut env = RuntimeEnv::::default(); let before = env.parachain_state(|| pallet_timestamp::Pallet::::get()); diff --git a/runtime/integration-tests/src/generic/cases/investments.rs b/runtime/integration-tests/src/generic/cases/investments.rs index 9b2f6c586b..8fb446dd41 100644 --- a/runtime/integration-tests/src/generic/cases/investments.rs +++ b/runtime/integration-tests/src/generic/cases/investments.rs @@ -38,14 +38,12 @@ mod common { use super::*; pub fn initialize_state_for_investments, T: Runtime>() -> E { - let mut env = E::from_storage( - Default::default(), + let mut env = E::from_parachain_storage( Genesis::::default() .add(genesis::balances(T::ExistentialDeposit::get() + FOR_FEES)) .add(genesis::assets(vec![Usd6::ID])) .add(genesis::tokens(vec![(Usd6::ID, Usd6::ED)])) .storage(), - Genesis::::default().storage(), ); env.parachain_state_mut(|| { diff --git a/runtime/integration-tests/src/generic/cases/liquidity_pools.rs b/runtime/integration-tests/src/generic/cases/liquidity_pools.rs index de6cf5e36c..973f8c4ac9 100644 --- a/runtime/integration-tests/src/generic/cases/liquidity_pools.rs +++ b/runtime/integration-tests/src/generic/cases/liquidity_pools.rs @@ -406,12 +406,10 @@ mod altair { } fn test_air_transfers_to_and_from_sibling() { - let mut env = FudgeEnv::::from_storage( - Default::default(), + let mut env = FudgeEnv::::from_parachain_storage( Genesis::default() .add(genesis::balances::(air(10))) .storage(), - Default::default(), ); setup_xcm(&mut env); @@ -486,11 +484,7 @@ mod altair { } fn transfer_ausd_to_altair() { - let mut env = FudgeEnv::::from_storage( - Default::default(), - Default::default(), - Default::default(), - ); + let mut env = FudgeEnv::::default(); setup_xcm(&mut env); @@ -649,11 +643,7 @@ mod altair { } fn transfer_ksm_to_and_from_relay_chain() { - let mut env = FudgeEnv::::from_storage( - Default::default(), - Default::default(), - Default::default(), - ); + let mut env = FudgeEnv::::default(); let transfer_amount: Balance = ksm(2); let currency_id = CurrencyId::ForeignAsset(3001); @@ -717,12 +707,10 @@ mod altair { } fn transfer_foreign_sibling_to_altair() { - let mut env = FudgeEnv::::from_storage( - Default::default(), + let mut env = FudgeEnv::::from_parachain_storage( Genesis::default() .add(genesis::balances::(air(10))) .storage(), - Default::default(), ); setup_xcm(&mut env); @@ -938,11 +926,7 @@ mod altair { use super::*; fn register_air_works() { - let mut env = FudgeEnv::::from_storage( - Default::default(), - Default::default(), - Default::default(), - ); + let mut env = FudgeEnv::::default(); env.parachain_state_mut(|| { let meta: AssetMetadata = AssetMetadata { @@ -969,11 +953,7 @@ mod altair { } fn register_foreign_asset_works() { - let mut env = FudgeEnv::::from_storage( - Default::default(), - Default::default(), - Default::default(), - ); + let mut env = FudgeEnv::::default(); env.parachain_state_mut(|| { let meta: AssetMetadata = AssetMetadata { @@ -1004,11 +984,7 @@ mod altair { // Verify that registering tranche tokens is not allowed through extrinsics fn register_tranche_asset_blocked() { - let mut env = FudgeEnv::::from_storage( - Default::default(), - Default::default(), - Default::default(), - ); + let mut env = FudgeEnv::::default(); env.parachain_state_mut(|| { let meta: AssetMetadata = AssetMetadata { @@ -1049,11 +1025,7 @@ mod altair { use super::*; fn convert_air() { - let mut env = FudgeEnv::::from_storage( - Default::default(), - Default::default(), - Default::default(), - ); + let mut env = FudgeEnv::::default(); assert_eq!(parachains::kusama::altair::AIR_KEY.to_vec(), vec![0, 1]); @@ -1089,11 +1061,7 @@ mod altair { /// Verify that Tranche tokens are not handled by the CurrencyIdConvert /// since we don't allow Tranche tokens to be transferable through XCM. fn convert_tranche() { - let mut env = FudgeEnv::::from_storage( - Default::default(), - Default::default(), - Default::default(), - ); + let mut env = FudgeEnv::::default(); let tranche_currency = CurrencyId::Tranche(401, [0; 16]); let tranche_id = @@ -1126,11 +1094,7 @@ mod altair { } fn convert_ausd() { - let mut env = FudgeEnv::::from_storage( - Default::default(), - Default::default(), - Default::default(), - ); + let mut env = FudgeEnv::::default(); env.parachain_state_mut(|| { assert_eq!(parachains::kusama::karura::AUSD_KEY, &[0, 129]); @@ -1158,11 +1122,7 @@ mod altair { } fn convert_ksm() { - let mut env = FudgeEnv::::from_storage( - Default::default(), - Default::default(), - Default::default(), - ); + let mut env = FudgeEnv::::default(); let ksm_location: MultiLocation = MultiLocation::parent().into(); @@ -1182,11 +1142,7 @@ mod altair { } fn convert_unkown_multilocation() { - let mut env = FudgeEnv::::from_storage( - Default::default(), - Default::default(), - Default::default(), - ); + let mut env = FudgeEnv::::default(); let unknown_location: MultiLocation = MultiLocation::new( 1, @@ -1199,11 +1155,7 @@ mod altair { } fn convert_unsupported_currency() { - let mut env = FudgeEnv::::from_storage( - Default::default(), - Default::default(), - Default::default(), - ); + let mut env = FudgeEnv::::default(); env.parachain_state_mut(|| { assert_eq!( @@ -1569,11 +1521,7 @@ mod centrifuge { use super::*; fn register_cfg_works() { - let mut env = FudgeEnv::::from_storage( - Default::default(), - Default::default(), - Default::default(), - ); + let mut env = FudgeEnv::::default(); env.parachain_state_mut(|| { let meta: AssetMetadata = AssetMetadata { @@ -1600,11 +1548,7 @@ mod centrifuge { } fn register_foreign_asset_works() { - let mut env = FudgeEnv::::from_storage( - Default::default(), - Default::default(), - Default::default(), - ); + let mut env = FudgeEnv::::default(); env.parachain_state_mut(|| { let meta: AssetMetadata = AssetMetadata { @@ -1635,11 +1579,7 @@ mod centrifuge { // Verify that registering tranche tokens is not allowed through extrinsics fn register_tranche_asset_blocked() { - let mut env = FudgeEnv::::from_storage( - Default::default(), - Default::default(), - Default::default(), - ); + let mut env = FudgeEnv::::default(); env.parachain_state_mut(|| { let meta: AssetMetadata = AssetMetadata { @@ -1680,11 +1620,7 @@ mod centrifuge { use super::*; fn convert_cfg() { - let mut env = FudgeEnv::::from_storage( - Default::default(), - Default::default(), - Default::default(), - ); + let mut env = FudgeEnv::::default(); assert_eq!(parachains::polkadot::centrifuge::CFG_KEY, &[0, 1]); @@ -1722,11 +1658,7 @@ mod centrifuge { /// v2 MultiLocation, that `CurrencyIdConvert` can look it up given an /// identical location in XCM v3. fn convert_cfg_xcm_v2() { - let mut env = FudgeEnv::::from_storage( - Default::default(), - Default::default(), - Default::default(), - ); + let mut env = FudgeEnv::::default(); assert_eq!(parachains::polkadot::centrifuge::CFG_KEY, &[0, 1]); @@ -1764,11 +1696,7 @@ mod centrifuge { /// Verify that a registered token that is NOT XCM transferable is /// filtered out by CurrencyIdConvert as expected. fn convert_no_xcm_token() { - let mut env = FudgeEnv::::from_storage( - Default::default(), - Default::default(), - Default::default(), - ); + let mut env = FudgeEnv::::default(); env.parachain_state_mut(|| { register_no_xcm_token::(); @@ -1781,11 +1709,7 @@ mod centrifuge { } fn convert_ausd() { - let mut env = FudgeEnv::::from_storage( - Default::default(), - Default::default(), - Default::default(), - ); + let mut env = FudgeEnv::::default(); assert_eq!(parachains::polkadot::acala::AUSD_KEY, &[0, 1]); @@ -1813,11 +1737,7 @@ mod centrifuge { } fn convert_dot() { - let mut env = FudgeEnv::::from_storage( - Default::default(), - Default::default(), - Default::default(), - ); + let mut env = FudgeEnv::::default(); let dot_location: MultiLocation = MultiLocation::parent(); @@ -1837,11 +1757,7 @@ mod centrifuge { } fn convert_unknown_multilocation() { - let mut env = FudgeEnv::::from_storage( - Default::default(), - Default::default(), - Default::default(), - ); + let mut env = FudgeEnv::::default(); let unknown_location: MultiLocation = MultiLocation::new( 1, @@ -1857,11 +1773,7 @@ mod centrifuge { } fn convert_unsupported_currency() { - let mut env = FudgeEnv::::from_storage( - Default::default(), - Default::default(), - Default::default(), - ); + let mut env = FudgeEnv::::default(); env.parachain_state_mut(|| { assert_eq!( @@ -1924,8 +1836,7 @@ mod centrifuge { } fn restrict_lp_eth_usdc_transfer() { - let mut env = RuntimeEnv::::from_storage( - Default::default(), + let mut env = RuntimeEnv::::from_parachain_storage( Genesis::default() .add(genesis::balances::(cfg(10))) .add(orml_tokens::GenesisConfig:: { @@ -1936,7 +1847,6 @@ mod centrifuge { )], }) .storage(), - Genesis::::default().storage(), ); env.parachain_state_mut(|| { @@ -2016,8 +1926,7 @@ mod centrifuge { } fn restrict_usdc_transfer() { - let mut env = RuntimeEnv::::from_storage( - Default::default(), + let mut env = RuntimeEnv::::from_parachain_storage( Genesis::default() .add(genesis::balances::(cfg(10))) .add(orml_tokens::GenesisConfig:: { @@ -2028,7 +1937,6 @@ mod centrifuge { )], }) .storage(), - Genesis::::default().storage(), ); env.parachain_state_mut(|| { @@ -2207,8 +2115,7 @@ mod centrifuge { } fn restrict_dot_transfer() { - let mut env = RuntimeEnv::::from_storage( - Default::default(), + let mut env = RuntimeEnv::::from_parachain_storage( Genesis::default() .add(genesis::balances::(cfg(10))) .add(orml_tokens::GenesisConfig:: { @@ -2219,7 +2126,6 @@ mod centrifuge { )], }) .storage(), - Genesis::::default().storage(), ); env.parachain_state_mut(|| { @@ -2296,12 +2202,10 @@ mod centrifuge { } fn restrict_dot_xcm_transfer() { - let mut env = FudgeEnv::::from_storage( - Default::default(), + let mut env = FudgeEnv::::from_parachain_storage( Genesis::default() .add(genesis::balances::(cfg(10))) .storage(), - Default::default(), ); transfer_dot_from_relay_chain(&mut env); @@ -2498,12 +2402,10 @@ mod centrifuge { } fn test_cfg_transfers_to_and_from_sibling() { - let mut env = FudgeEnv::::from_storage( - Default::default(), + let mut env = FudgeEnv::::from_parachain_storage( Genesis::default() .add(genesis::balances::(cfg(10))) .storage(), - Default::default(), ); setup_xcm(&mut env); @@ -2579,11 +2481,7 @@ mod centrifuge { } fn transfer_ausd_to_centrifuge() { - let mut env = FudgeEnv::::from_storage( - Default::default(), - Default::default(), - Default::default(), - ); + let mut env = FudgeEnv::::default(); setup_xcm(&mut env); @@ -2676,11 +2574,7 @@ mod centrifuge { } fn transfer_dot_to_and_from_relay_chain() { - let mut env = FudgeEnv::::from_storage( - Default::default(), - Default::default(), - Default::default(), - ); + let mut env = FudgeEnv::::default(); transfer_dot_from_relay_chain(&mut env); @@ -2732,12 +2626,10 @@ mod centrifuge { } fn transfer_foreign_sibling_to_centrifuge() { - let mut env = FudgeEnv::::from_storage( - Default::default(), + let mut env = FudgeEnv::::from_parachain_storage( Genesis::default() .add(genesis::balances::(cfg(10))) .storage(), - Default::default(), ); setup_xcm(&mut env); @@ -2956,11 +2848,7 @@ mod all { use super::*; fn xtokens_transfer() { - let mut env = FudgeEnv::::from_storage( - Default::default(), - Default::default(), - Default::default(), - ); + let mut env = FudgeEnv::::default(); env.parachain_state_mut(|| { assert_noop!( @@ -2989,11 +2877,7 @@ mod all { } fn xtokens_transfer_multiasset() { - let mut env = FudgeEnv::::from_storage( - Default::default(), - Default::default(), - Default::default(), - ); + let mut env = FudgeEnv::::default(); let tranche_currency = CurrencyId::Tranche(401, [0; 16]); let tranche_id = @@ -3040,11 +2924,7 @@ mod all { } fn xtokens_transfer_multiassets() { - let mut env = FudgeEnv::::from_storage( - Default::default(), - Default::default(), - Default::default(), - ); + let mut env = FudgeEnv::::default(); let tranche_currency = CurrencyId::Tranche(401, [0; 16]); let tranche_id = diff --git a/runtime/integration-tests/src/generic/cases/loans.rs b/runtime/integration-tests/src/generic/cases/loans.rs index c31647a745..dbe0327ec7 100644 --- a/runtime/integration-tests/src/generic/cases/loans.rs +++ b/runtime/integration-tests/src/generic/cases/loans.rs @@ -66,14 +66,12 @@ mod common { use super::*; pub fn initialize_state_for_loans, T: Runtime>() -> E { - let mut env = E::from_storage( - Default::default(), + let mut env = E::from_parachain_storage( Genesis::::default() .add(genesis::balances(T::ExistentialDeposit::get() + FOR_FEES)) .add(genesis::assets(vec![Usd6::ID])) .add(genesis::tokens(vec![(Usd6::ID, Usd6::ED)])) .storage(), - Genesis::::default().storage(), ); env.parachain_state_mut(|| { diff --git a/runtime/integration-tests/src/generic/env.rs b/runtime/integration-tests/src/generic/env.rs index a469443fff..adda8b3087 100644 --- a/runtime/integration-tests/src/generic/env.rs +++ b/runtime/integration-tests/src/generic/env.rs @@ -60,6 +60,9 @@ impl Blocks { /// Define an environment behavior pub trait Env { + /// Load the environment from a parachain storage + fn from_parachain_storage(parachain_storage: Storage) -> Self; + /// Load the environment from a storage fn from_storage( relay_storage: Storage, diff --git a/runtime/integration-tests/src/generic/envs/fudge_env.rs b/runtime/integration-tests/src/generic/envs/fudge_env.rs index b56e1cd039..ea0f6663ef 100644 --- a/runtime/integration-tests/src/generic/envs/fudge_env.rs +++ b/runtime/integration-tests/src/generic/envs/fudge_env.rs @@ -30,7 +30,17 @@ pub struct FudgeEnv { nonce_storage: HashMap, } +impl Default for FudgeEnv { + fn default() -> Self { + Self::from_storage(Default::default(), Default::default(), Default::default()) + } +} + impl Env for FudgeEnv { + fn from_parachain_storage(parachain_storage: Storage) -> Self { + Self::from_storage(Default::default(), parachain_storage, Default::default()) + } + fn from_storage( relay_storage: Storage, parachain_storage: Storage, @@ -143,14 +153,12 @@ mod tests { use crate::generic::{env::Blocks, utils::genesis::Genesis}; fn correct_nonce_for_submit_later() { - let mut env = FudgeEnv::::from_storage( - Default::default(), + let mut env = FudgeEnv::::from_parachain_storage( Genesis::default() .add(pallet_balances::GenesisConfig:: { balances: vec![(Keyring::Alice.to_account_id(), 1 * CFG)], }) .storage(), - Genesis::::default().storage(), ); env.submit_later( diff --git a/runtime/integration-tests/src/generic/envs/runtime_env.rs b/runtime/integration-tests/src/generic/envs/runtime_env.rs index dc8ab15d3d..aa9188c644 100644 --- a/runtime/integration-tests/src/generic/envs/runtime_env.rs +++ b/runtime/integration-tests/src/generic/envs/runtime_env.rs @@ -35,7 +35,17 @@ pub struct RuntimeEnv { _config: PhantomData, } +impl Default for RuntimeEnv { + fn default() -> Self { + Self::from_storage(Default::default(), Default::default(), Default::default()) + } +} + impl Env for RuntimeEnv { + fn from_parachain_storage(parachain_storage: Storage) -> Self { + Self::from_storage(Default::default(), parachain_storage, Default::default()) + } + fn from_storage( mut _relay_storage: Storage, mut parachain_storage: Storage, @@ -248,14 +258,12 @@ mod tests { use crate::generic::{env::Blocks, utils::genesis::Genesis}; fn correct_nonce_for_submit_now() { - let mut env = RuntimeEnv::::from_storage( - Default::default(), + let mut env = RuntimeEnv::::from_parachain_storage( Genesis::default() .add(pallet_balances::GenesisConfig:: { balances: vec![(Keyring::Alice.to_account_id(), 1 * CFG)], }) .storage(), - Genesis::::default().storage(), ); env.submit_now( @@ -272,14 +280,12 @@ mod tests { } fn correct_nonce_for_submit_later() { - let mut env = RuntimeEnv::::from_storage( - Default::default(), + let mut env = RuntimeEnv::::from_parachain_storage( Genesis::default() .add(pallet_balances::GenesisConfig:: { balances: vec![(Keyring::Alice.to_account_id(), 1 * CFG)], }) .storage(), - Genesis::::default().storage(), ); env.submit_later(