From e4f9f96da145a7cf2ce07123c5653779ee352aa5 Mon Sep 17 00:00:00 2001 From: cdamian <17934949+cdamian@users.noreply.github.com> Date: Mon, 30 Oct 2023 14:01:22 +0100 Subject: [PATCH] integration-tests: Drop unnecessary envs and funcs from development tests --- .../liquidity_pools/pallet/development/mod.rs | 1 - .../pallet/development/setup.rs | 95 +-------- .../pallet/development/test_net.rs | 187 ------------------ .../liquidity_pools/add_allow_upgrade.rs | 1 - .../liquidity_pools/foreign_investments.rs | 18 +- .../tests/liquidity_pools/setup.rs | 11 +- .../tests/liquidity_pools/transfers.rs | 1 - .../development/tests/routers/ethereum_xcm.rs | 6 +- .../pallet/development/transfers.rs | 7 +- 9 files changed, 25 insertions(+), 302 deletions(-) delete mode 100644 runtime/integration-tests/src/liquidity_pools/pallet/development/test_net.rs diff --git a/runtime/integration-tests/src/liquidity_pools/pallet/development/mod.rs b/runtime/integration-tests/src/liquidity_pools/pallet/development/mod.rs index 17909ac383..e42269b27a 100644 --- a/runtime/integration-tests/src/liquidity_pools/pallet/development/mod.rs +++ b/runtime/integration-tests/src/liquidity_pools/pallet/development/mod.rs @@ -1,4 +1,3 @@ mod setup; -mod test_net; mod tests; mod transfers; diff --git a/runtime/integration-tests/src/liquidity_pools/pallet/development/setup.rs b/runtime/integration-tests/src/liquidity_pools/pallet/development/setup.rs index e5429ffcd4..10e3c66dd8 100644 --- a/runtime/integration-tests/src/liquidity_pools/pallet/development/setup.rs +++ b/runtime/integration-tests/src/liquidity_pools/pallet/development/setup.rs @@ -16,92 +16,7 @@ use cfg_types::{domain_address::Domain, tokens::CustomMetadata}; use frame_support::traits::GenesisBuild; use orml_traits::asset_registry::AssetMetadata; -use crate::utils::env::PARA_ID_SIBLING; - -/// Accounts -pub const ALICE: [u8; 32] = [4u8; 32]; -pub const BOB: [u8; 32] = [5u8; 32]; -pub const CHARLIE: [u8; 32] = [6u8; 32]; - -pub const TEST_DOMAIN: Domain = Domain::EVM(1284); - -/// A PARA ID used for a sibling parachain emulating Moonbeam. -/// It must be one that doesn't collide with any other in use. -pub const PARA_ID_MOONBEAM: u32 = 2023; - -pub struct ExtBuilder { - balances: Vec<(AccountId, CurrencyId, Balance)>, - parachain_id: u32, -} - -impl Default for ExtBuilder { - fn default() -> Self { - Self { - balances: vec![], - parachain_id: parachains::polkadot::centrifuge::ID, - } - } -} - -impl ExtBuilder { - pub fn balances(mut self, balances: Vec<(AccountId, CurrencyId, Balance)>) -> Self { - self.balances = balances; - self - } - - pub fn parachain_id(mut self, parachain_id: u32) -> Self { - self.parachain_id = parachain_id; - self - } - - pub fn build(self) -> sp_io::TestExternalities { - let mut t = frame_system::GenesisConfig::default() - .build_storage::() - .unwrap(); - let native_currency_id = development_runtime::NativeToken::get(); - pallet_balances::GenesisConfig:: { - balances: self - .balances - .clone() - .into_iter() - .filter(|(_, currency_id, _)| *currency_id == native_currency_id) - .map(|(account_id, _, initial_balance)| (account_id, initial_balance)) - .collect::>(), - } - .assimilate_storage(&mut t) - .unwrap(); - - orml_tokens::GenesisConfig:: { - balances: self - .balances - .into_iter() - .filter(|(_, currency_id, _)| *currency_id != native_currency_id) - .collect::>(), - } - .assimilate_storage(&mut t) - .unwrap(); - - >::assimilate_storage( - ¶chain_info::GenesisConfig { - parachain_id: self.parachain_id.into(), - }, - &mut t, - ) - .unwrap(); - - >::assimilate_storage( - &pallet_xcm::GenesisConfig { - safe_xcm_version: Some(2), - }, - &mut t, - ) - .unwrap(); - - let mut ext = sp_io::TestExternalities::new(t); - ext.execute_with(|| System::set_block_number(1)); - ext - } -} +use crate::{chain::centrifuge::PARA_ID, utils::env::PARA_ID_SIBLING}; pub fn cfg(amount: Balance) -> Balance { amount * dollar(currency_decimals::NATIVE) @@ -111,12 +26,12 @@ pub fn dollar(decimals: u32) -> Balance { 10u128.saturating_pow(decimals) } -pub fn moonbeam_account() -> AccountId { - parachain_account(PARA_ID_SIBLING) +pub fn centrifuge_account() -> AccountId { + parachain_account(PARA_ID) } -pub fn centrifuge_account() -> AccountId { - parachain_account(parachains::polkadot::centrifuge::ID) +pub fn sibling_account() -> AccountId { + parachain_account(PARA_ID_SIBLING) } fn parachain_account(id: u32) -> AccountId { diff --git a/runtime/integration-tests/src/liquidity_pools/pallet/development/test_net.rs b/runtime/integration-tests/src/liquidity_pools/pallet/development/test_net.rs deleted file mode 100644 index d4255745d2..0000000000 --- a/runtime/integration-tests/src/liquidity_pools/pallet/development/test_net.rs +++ /dev/null @@ -1,187 +0,0 @@ -// Copyright 2021 Centrifuge GmbH (centrifuge.io). -// This file is part of Centrifuge chain project. - -// Centrifuge is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version (see http://www.gnu.org/licenses). - -// Centrifuge is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -//! Relay chain and parachains emulation. - -use cfg_primitives::{parachains, AccountId}; -use cfg_types::tokens::CurrencyId; -use cumulus_primitives_core::ParaId; -use frame_support::{traits::GenesisBuild, weights::Weight}; -use polkadot_parachain::primitives::Id; -use polkadot_primitives::{BlockNumber, MAX_CODE_SIZE, MAX_POV_SIZE}; -use polkadot_runtime_parachains::{ - configuration::HostConfiguration, - paras::{ParaGenesisArgs, ParaKind}, -}; -use sp_runtime::traits::AccountIdConversion; -use xcm_simulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain, TestExt}; - -use super::setup::{cfg, ExtBuilder, ALICE, BOB, PARA_ID_MOONBEAM}; -use crate::utils::{ - AUSD_CURRENCY_ID, AUSD_ED, GLMR_CURRENCY_ID, GLMR_ED, USDT_CURRENCY_ID, USDT_ED, -}; - -decl_test_relay_chain! { - pub struct RelayChain { - Runtime = polkadot_runtime::Runtime, - RuntimeCall = polkadot_runtime::RuntimeCall, - RuntimeEvent = polkadot_runtime::RuntimeEvent, - XcmConfig = polkadot_runtime::xcm_config::XcmConfig, - MessageQueue = polkadot_runtime::MessageQueue, - System = polkadot_runtime::System, - new_ext = relay_ext(), - } -} - -decl_test_parachain! { - pub struct Development { - Runtime = development_runtime::Runtime, - XcmpMessageHandler = development_runtime::XcmpQueue, - DmpMessageHandler = development_runtime::DmpQueue, - new_ext = para_ext(parachains::polkadot::centrifuge::ID), - } -} - -decl_test_parachain! { - pub struct Moonbeam { - Runtime = development_runtime::Runtime, - XcmpMessageHandler = development_runtime::XcmpQueue, - DmpMessageHandler = development_runtime::DmpQueue, - new_ext = para_ext(PARA_ID_MOONBEAM), - } -} - -decl_test_network! { - pub struct TestNet { - relay_chain = RelayChain, - parachains = vec![ - // N.B: Ideally, we could use the defined para id constants but doing so - // fails with: "error: arbitrary expressions aren't allowed in patterns" - - // Be sure to use `parachains::polkadot::centrifuge::ID` - (2031, Development), - // Be sure to use `PARA_ID_MOONBEAM` - (2023, Moonbeam), - ], - } -} - -pub fn relay_ext() -> sp_io::TestExternalities { - use polkadot_runtime::{Runtime, System}; - - let mut t = frame_system::GenesisConfig::default() - .build_storage::() - .unwrap(); - - pallet_balances::GenesisConfig:: { - balances: vec![ - (AccountId::from(ALICE), cfg(2002)), - ( - ParaId::from(parachains::polkadot::centrifuge::ID).into_account_truncating(), - cfg(7), - ), - ( - ParaId::from(PARA_ID_MOONBEAM).into_account_truncating(), - cfg(7), - ), - ], - } - .assimilate_storage(&mut t) - .unwrap(); - - polkadot_runtime_parachains::configuration::GenesisConfig:: { - config: default_parachains_host_configuration(), - } - .assimilate_storage(&mut t) - .unwrap(); - - >::assimilate_storage(&polkadot_runtime_parachains::paras::GenesisConfig { - paras: vec![ - ( - Id::from(parachains::polkadot::centrifuge::ID), - ParaGenesisArgs { - genesis_head: Default::default(), - validation_code: vec![1].into(), - para_kind: ParaKind::Parachain, - }, - ), - ( - Id::from(PARA_ID_MOONBEAM), - ParaGenesisArgs { - genesis_head: Default::default(), - validation_code: vec![2].into(), - para_kind: ParaKind::Parachain, - }, - ), - ], - }, &mut t).unwrap(); - - >::assimilate_storage( - &pallet_xcm::GenesisConfig { - safe_xcm_version: Some(2), - }, - &mut t, - ) - .unwrap(); - - let mut ext = sp_io::TestExternalities::new(t); - - ext.execute_with(|| { - polkadot_runtime_parachains::hrmp::Pallet::::force_open_hrmp_channel( - polkadot_runtime::RuntimeOrigin::root(), - Id::from(parachains::polkadot::centrifuge::ID), - Id::from(PARA_ID_MOONBEAM), - 10, - 1024, - ) - .unwrap(); - - polkadot_runtime_parachains::hrmp::Pallet::::force_process_hrmp_open( - polkadot_runtime::RuntimeOrigin::root(), - 0, - ) - .unwrap(); - - System::set_block_number(1); - }); - ext -} - -pub fn para_ext(parachain_id: u32) -> sp_io::TestExternalities { - ExtBuilder::default() - .balances(vec![ - (AccountId::from(ALICE), CurrencyId::Native, cfg(10_000)), - (AccountId::from(BOB), CurrencyId::Native, cfg(10_000)), - (AccountId::from(ALICE), AUSD_CURRENCY_ID, AUSD_ED), - (AccountId::from(BOB), AUSD_CURRENCY_ID, AUSD_ED), - (AccountId::from(ALICE), USDT_CURRENCY_ID, USDT_ED), - (AccountId::from(BOB), USDT_CURRENCY_ID, USDT_ED), - (AccountId::from(ALICE), GLMR_CURRENCY_ID, GLMR_ED), - (AccountId::from(BOB), GLMR_CURRENCY_ID, GLMR_ED), - ]) - .parachain_id(parachain_id) - .build() -} - -fn default_parachains_host_configuration() -> HostConfiguration { - HostConfiguration { - hrmp_channel_max_capacity: u32::MAX, - hrmp_channel_max_total_size: u32::MAX, - hrmp_max_parachain_inbound_channels: 10, - hrmp_max_parachain_outbound_channels: 10, - hrmp_channel_max_message_size: u32::MAX, - // Changed to avoid aritmetic errors within hrmp_close - max_downward_message_size: 100_000u32, - ..Default::default() - } -} diff --git a/runtime/integration-tests/src/liquidity_pools/pallet/development/tests/liquidity_pools/add_allow_upgrade.rs b/runtime/integration-tests/src/liquidity_pools/pallet/development/tests/liquidity_pools/add_allow_upgrade.rs index 1963987c18..1a00fecef4 100644 --- a/runtime/integration-tests/src/liquidity_pools/pallet/development/tests/liquidity_pools/add_allow_upgrade.rs +++ b/runtime/integration-tests/src/liquidity_pools/pallet/development/tests/liquidity_pools/add_allow_upgrade.rs @@ -66,7 +66,6 @@ use crate::{ }, liquidity_pools::pallet::development::{ setup::dollar, - test_net::{Development, Moonbeam, RelayChain, TestNet}, tests::liquidity_pools::setup::{ asset_metadata, create_ausd_pool, create_currency_pool, enable_liquidity_pool_transferability, get_default_moonbeam_native_token_location, diff --git a/runtime/integration-tests/src/liquidity_pools/pallet/development/tests/liquidity_pools/foreign_investments.rs b/runtime/integration-tests/src/liquidity_pools/pallet/development/tests/liquidity_pools/foreign_investments.rs index 7392b3275a..3a5f2bcc6e 100644 --- a/runtime/integration-tests/src/liquidity_pools/pallet/development/tests/liquidity_pools/foreign_investments.rs +++ b/runtime/integration-tests/src/liquidity_pools/pallet/development/tests/liquidity_pools/foreign_investments.rs @@ -74,7 +74,6 @@ use crate::{ }, liquidity_pools::pallet::development::{ setup::dollar, - test_net::{Development, Moonbeam, RelayChain, TestNet}, tests::liquidity_pools::{ foreign_investments::setup::{ do_initial_increase_investment, do_initial_increase_redemption, @@ -1978,10 +1977,7 @@ mod mismatching_currencies { use super::*; use crate::{ liquidity_pools::pallet::development::tests::{ - liquidity_pools::foreign_investments::setup::{ - enable_usdt_trading, min_fulfillment_amount, - }, - register_usdt, + liquidity_pools::foreign_investments::setup::enable_usdt_trading, register_usdt, }, utils::{GLMR_CURRENCY_ID, USDT_CURRENCY_ID}, }; @@ -2564,7 +2560,7 @@ mod mismatching_currencies { TokenSwapReason::Investment ); assert_ok!(Investments::collect_redemptions_for( - RuntimeOrigin::signed(CHARLIE.into()), + RuntimeOrigin::signed(Keyring::Charlie.into()), investor.clone(), default_investment_id() )); @@ -2630,7 +2626,7 @@ mod mismatching_currencies { } )); assert_ok!(Investments::collect_redemptions_for( - RuntimeOrigin::signed(CHARLIE.into()), + RuntimeOrigin::signed(Keyring::Charlie.into()), investor.clone(), default_investment_id() )); @@ -2844,7 +2840,7 @@ mod mismatching_currencies { } )); assert_ok!(Investments::collect_redemptions_for( - RuntimeOrigin::signed(CHARLIE.into()), + RuntimeOrigin::signed(Keyring::Charlie.into()), investor.clone(), default_investment_id() )); @@ -2917,7 +2913,7 @@ mod mismatching_currencies { } )); assert_ok!(Investments::collect_redemptions_for( - RuntimeOrigin::signed(CHARLIE.into()), + RuntimeOrigin::signed(Keyring::Charlie.into()), investor.clone(), default_investment_id() )); @@ -2989,7 +2985,7 @@ mod mismatching_currencies { } )); assert_ok!(Investments::collect_redemptions_for( - RuntimeOrigin::signed(CHARLIE.into()), + RuntimeOrigin::signed(Keyring::Charlie.into()), investor.clone(), default_investment_id() )); @@ -3262,7 +3258,7 @@ mod mismatching_currencies { default_investment_id() )); assert_ok!(Investments::collect_redemptions_for( - RuntimeOrigin::signed(CHARLIE.into()), + RuntimeOrigin::signed(Keyring::Charlie.into()), investor.clone(), default_investment_id() )); diff --git a/runtime/integration-tests/src/liquidity_pools/pallet/development/tests/liquidity_pools/setup.rs b/runtime/integration-tests/src/liquidity_pools/pallet/development/tests/liquidity_pools/setup.rs index d305e5228a..df88e967dd 100644 --- a/runtime/integration-tests/src/liquidity_pools/pallet/development/tests/liquidity_pools/setup.rs +++ b/runtime/integration-tests/src/liquidity_pools/pallet/development/tests/liquidity_pools/setup.rs @@ -38,6 +38,7 @@ use frame_support::{ fungibles::{Balanced, Mutate}, Get, PalletInfo, }, + weights::Weight, }; use fudge::primitives::Chain; use liquidity_pools_gateway_routers::{ @@ -72,7 +73,12 @@ use crate::{ }, relay::{Hrmp as RelayHrmp, RuntimeOrigin as RelayRuntimeOrigin}, }, - utils::{AUSD_CURRENCY_ID, GLMR_CURRENCY_ID, GLMR_ED, MOONBEAM_EVM_CHAIN_ID}, + liquidity_pools::pallet::development::{setup::dollar, tests::register_ausd}, + utils::{ + accounts::Keyring, + env::{TestEnv, PARA_ID_SIBLING}, + AUSD_CURRENCY_ID, GLMR_CURRENCY_ID, MOONBEAM_EVM_CHAIN_ID, + }, }; // 10 GLMR (18 decimals) @@ -89,9 +95,6 @@ pub const DEFAULT_SIBLING_LOCATION: MultiLocation = MultiLocation { parents: 1, interior: X1(Parachain(PARA_ID_SIBLING)), }; -use frame_support::weights::Weight; - -use crate::utils::env::{TestEnv, PARA_ID_SIBLING}; pub type LiquidityPoolMessage = Message; diff --git a/runtime/integration-tests/src/liquidity_pools/pallet/development/tests/liquidity_pools/transfers.rs b/runtime/integration-tests/src/liquidity_pools/pallet/development/tests/liquidity_pools/transfers.rs index 089936f854..d59100e226 100644 --- a/runtime/integration-tests/src/liquidity_pools/pallet/development/tests/liquidity_pools/transfers.rs +++ b/runtime/integration-tests/src/liquidity_pools/pallet/development/tests/liquidity_pools/transfers.rs @@ -55,7 +55,6 @@ use crate::{ }, liquidity_pools::pallet::development::{ setup::dollar, - test_net::{Development, Moonbeam, RelayChain, TestNet}, tests::liquidity_pools::setup::{ asset_metadata, create_ausd_pool, create_currency_pool, enable_liquidity_pool_transferability, diff --git a/runtime/integration-tests/src/liquidity_pools/pallet/development/tests/routers/ethereum_xcm.rs b/runtime/integration-tests/src/liquidity_pools/pallet/development/tests/routers/ethereum_xcm.rs index 9ff76ced7b..dbc8c33e6e 100644 --- a/runtime/integration-tests/src/liquidity_pools/pallet/development/tests/routers/ethereum_xcm.rs +++ b/runtime/integration-tests/src/liquidity_pools/pallet/development/tests/routers/ethereum_xcm.rs @@ -43,9 +43,7 @@ use crate::{ PARA_ID, }, liquidity_pools::pallet::development::{ - setup::{dollar, TEST_DOMAIN}, - test_net::{Development, Moonbeam, RelayChain, TestNet}, - tests, + setup::dollar, tests::{ liquidity_pools::setup::{setup_test_env, DEFAULT_SIBLING_LOCATION}, routers::axelar_evm::TEST_EVM_CHAIN, @@ -54,6 +52,8 @@ use crate::{ utils::{accounts::Keyring, env, env::PARA_ID_SIBLING, genesis, GLMR_CURRENCY_ID}, }; +const TEST_DOMAIN: Domain = Domain::EVM(1); + #[tokio::test] async fn submit_ethereum_xcm() { submit_test_fn(get_ethereum_xcm_router_fn()); diff --git a/runtime/integration-tests/src/liquidity_pools/pallet/development/transfers.rs b/runtime/integration-tests/src/liquidity_pools/pallet/development/transfers.rs index 51f6f5e103..d9fc7c1b7e 100644 --- a/runtime/integration-tests/src/liquidity_pools/pallet/development/transfers.rs +++ b/runtime/integration-tests/src/liquidity_pools/pallet/development/transfers.rs @@ -54,8 +54,7 @@ use crate::{ }, liquidity_pools::pallet::{ development::{ - setup::{centrifuge_account, cfg, moonbeam_account}, - test_net::{Development, Moonbeam, RelayChain, TestNet}, + setup::{centrifuge_account, cfg, sibling_account}, tests::register_ausd, }, xcm_metadata, @@ -119,7 +118,7 @@ fn transfer_cfg_to_sibling(env: &mut TestEnv) { Balances::free_balance(&Keyring::Alice.into()), alice_initial_balance ); - assert_eq!(Balances::free_balance(&moonbeam_account()), 0); + assert_eq!(Balances::free_balance(&sibling_account()), 0); assert_ok!(OrmlAssetRegistry::register_asset( RuntimeOrigin::root(), @@ -195,7 +194,7 @@ fn transfer_cfg_to_sibling(env: &mut TestEnv) { ); // Verify that the amount transferred is now part of the sibling account here - assert_eq!(Balances::free_balance(&moonbeam_account()), transfer_amount); + assert_eq!(Balances::free_balance(&sibling_account()), transfer_amount); }); env.evolve().unwrap();