diff --git a/runtime/integration-tests/src/generic/README.md b/runtime/integration-tests/src/README.md similarity index 71% rename from runtime/integration-tests/src/generic/README.md rename to runtime/integration-tests/src/README.md index 403192b0dc..9e84267658 100644 --- a/runtime/integration-tests/src/generic/README.md +++ b/runtime/integration-tests/src/README.md @@ -1,23 +1,21 @@ # Runtime Generic tests -The aim of this module is to make integration-tests independently for all runtimes at once. - You can choose the environment for each of your use cases: - - `RuntimeEnv`: Simple environment that acts as a wrapper over the runtime - - `FudgeEnv`: Advanced environment that use a client and connect the runtime to a relay chain. + - `RuntimeEnv`: Simple environment that acts as a wrapper over the runtime (< 1sec per test case) + - `FudgeEnv`: Advanced environment that use a client and connect the runtime to a relay chain. (> 1min per test case) -Both environment uses the same interface so jumping from one to the another should be something "smooth". +Both environment uses the "same" interface so jumping from one to the another should be something "smooth". ## Where I start? - Create a new file in `cases/` for the use case you want to test. -- Maybe you need to update the `Runtime` trait in `config.rs` file with extra information from your new pallet. +- Maybe you need to update the `Runtime` trait in `config.rs` file with extra information from a new pallet. This could imply: - Adding bounds to the `Runtime` trait with your new pallet. - Adding bounds to `T::RuntimeCallExt` to support calls from your pallet. - Adding bounds to `T::EventExt` to support events from your pallet. - Adding bounds to `T::Api` to support new api calls. - You can add `GenesisBuild` builders for setting the initial state of your pallet for others in `utils/genesis.rs`. - Please be as generic and simple as possible to leave others to compose its own requirement using your method, + Please be **as much generic and simple** as possible to leave others to compose its own requirement using your method, without hidden initializations. - You can add any utility that helps to initialize states for others under `utils` folder. Again, focus in simplity but without side effects or hidden / non-obvious state changes. diff --git a/runtime/integration-tests/src/cases.rs b/runtime/integration-tests/src/cases.rs new file mode 100644 index 0000000000..0e7eec6162 --- /dev/null +++ b/runtime/integration-tests/src/cases.rs @@ -0,0 +1,16 @@ +mod account_derivation; +mod assets; +mod block_rewards; +mod currency_conversions; +mod ethereum_transaction; +mod example; +mod investments; +mod liquidity_pools; +mod loans; +mod lp; +mod oracles; +mod precompile; +mod proxy; +mod restricted_transfers; +mod routers; +mod xcm_transfers; diff --git a/runtime/integration-tests/src/generic/cases/account_derivation.rs b/runtime/integration-tests/src/cases/account_derivation.rs similarity index 98% rename from runtime/integration-tests/src/generic/cases/account_derivation.rs rename to runtime/integration-tests/src/cases/account_derivation.rs index a6bf2cbf4b..745450d7bb 100644 --- a/runtime/integration-tests/src/generic/cases/account_derivation.rs +++ b/runtime/integration-tests/src/cases/account_derivation.rs @@ -20,7 +20,7 @@ use staging_xcm::v4::{ Location, NetworkId, }; -use crate::generic::{config::Runtime, env::Env, envs::runtime_env::RuntimeEnv}; +use crate::{config::Runtime, env::Env, envs::runtime_env::RuntimeEnv}; const KEY_20: [u8; 20] = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, diff --git a/runtime/integration-tests/src/generic/cases/assets.rs b/runtime/integration-tests/src/cases/assets.rs similarity index 91% rename from runtime/integration-tests/src/generic/cases/assets.rs rename to runtime/integration-tests/src/cases/assets.rs index 093cb4f842..9ae8147d0e 100644 --- a/runtime/integration-tests/src/generic/cases/assets.rs +++ b/runtime/integration-tests/src/cases/assets.rs @@ -2,10 +2,7 @@ use cfg_types::tokens::{default_metadata, CurrencyId}; use frame_support::{assert_noop, assert_ok, dispatch::RawOrigin}; use sp_runtime::{DispatchError, DispatchError::BadOrigin}; -use crate::{ - generic::{config::Runtime, env::Env, envs::runtime_env::RuntimeEnv}, - utils::orml_asset_registry, -}; +use crate::{config::Runtime, env::Env, envs::runtime_env::RuntimeEnv, utils::orml_asset_registry}; #[test_runtimes(all)] fn authority_configured() { diff --git a/runtime/integration-tests/src/generic/cases/block_rewards.rs b/runtime/integration-tests/src/cases/block_rewards.rs similarity index 96% rename from runtime/integration-tests/src/generic/cases/block_rewards.rs rename to runtime/integration-tests/src/cases/block_rewards.rs index 020a724423..adbcdd4c80 100644 --- a/runtime/integration-tests/src/generic/cases/block_rewards.rs +++ b/runtime/integration-tests/src/cases/block_rewards.rs @@ -9,17 +9,15 @@ use runtime_common::{ use sp_runtime::traits::{Get, Zero}; use crate::{ - generic::{ - config::{Runtime, RuntimeKind}, - env::Env, - envs::runtime_env::RuntimeEnv, - utils, - utils::{ - currency::cfg, - genesis::{self, Genesis}, - }, + config::{Runtime, RuntimeKind}, + env::Env, + envs::runtime_env::RuntimeEnv, + utils, + utils::{ + accounts::{default_accounts, Keyring}, + currency::cfg, + genesis::{self, Genesis}, }, - utils::accounts::{default_accounts, Keyring}, }; #[test_runtimes(all)] diff --git a/runtime/integration-tests/src/generic/cases/currency_conversions.rs b/runtime/integration-tests/src/cases/currency_conversions.rs similarity index 99% rename from runtime/integration-tests/src/generic/cases/currency_conversions.rs rename to runtime/integration-tests/src/cases/currency_conversions.rs index 4cbed8080f..6c657b3459 100644 --- a/runtime/integration-tests/src/generic/cases/currency_conversions.rs +++ b/runtime/integration-tests/src/cases/currency_conversions.rs @@ -7,7 +7,7 @@ use staging_xcm::{ VersionedLocation, }; -use crate::generic::{ +use crate::{ config::Runtime, env::Env, envs::runtime_env::RuntimeEnv, diff --git a/runtime/integration-tests/src/generic/cases/ethereum_transaction.rs b/runtime/integration-tests/src/cases/ethereum_transaction.rs similarity index 99% rename from runtime/integration-tests/src/generic/cases/ethereum_transaction.rs rename to runtime/integration-tests/src/cases/ethereum_transaction.rs index bdf4c43bbe..1d00a2d44a 100644 --- a/runtime/integration-tests/src/generic/cases/ethereum_transaction.rs +++ b/runtime/integration-tests/src/cases/ethereum_transaction.rs @@ -5,7 +5,7 @@ use frame_support::{assert_err, assert_ok}; use pallet_evm::{ExitReason, ExitSucceed}; use sp_core::{H160, U256}; -use crate::generic::{ +use crate::{ config::Runtime, env::Env, envs::runtime_env::RuntimeEnv, diff --git a/runtime/integration-tests/src/generic/cases/example.rs b/runtime/integration-tests/src/cases/example.rs similarity index 95% rename from runtime/integration-tests/src/generic/cases/example.rs rename to runtime/integration-tests/src/cases/example.rs index 2268081251..9979c95a71 100644 --- a/runtime/integration-tests/src/generic/cases/example.rs +++ b/runtime/integration-tests/src/cases/example.rs @@ -4,16 +4,13 @@ use frame_support::traits::Get; use sp_api::runtime_decl_for_core::CoreV4; use crate::{ - generic::{ - config::Runtime, - env::{Blocks, Env}, - envs::{ - fudge_env::{FudgeEnv, FudgeSupport}, - runtime_env::RuntimeEnv, - }, - utils::genesis::Genesis, + config::Runtime, + env::{Blocks, Env}, + envs::{ + fudge_env::{FudgeEnv, FudgeSupport}, + runtime_env::RuntimeEnv, }, - utils::accounts::Keyring, + utils::{accounts::Keyring, genesis::Genesis}, }; #[test_runtimes([development, altair, centrifuge])] diff --git a/runtime/integration-tests/src/generic/cases/investments.rs b/runtime/integration-tests/src/cases/investments.rs similarity index 95% rename from runtime/integration-tests/src/generic/cases/investments.rs rename to runtime/integration-tests/src/cases/investments.rs index 3f2869ff3e..4e49f806f0 100644 --- a/runtime/integration-tests/src/generic/cases/investments.rs +++ b/runtime/integration-tests/src/cases/investments.rs @@ -12,18 +12,16 @@ use runtime_common::apis::{ use sp_core::Get; use crate::{ - generic::{ - config::Runtime, - env::{Blocks, Env}, - envs::runtime_env::RuntimeEnv, - utils::{ - self, - currency::{cfg, usd6, CurrencyInfo, Usd6}, - genesis::{self, Genesis}, - pool::POOL_MIN_EPOCH_TIME, - }, + config::Runtime, + env::{Blocks, Env}, + envs::runtime_env::RuntimeEnv, + utils::{ + self, + accounts::Keyring, + currency::{cfg, usd6, CurrencyInfo, Usd6}, + genesis::{self, Genesis}, + pool::POOL_MIN_EPOCH_TIME, }, - utils::accounts::Keyring, }; const POOL_ADMIN: Keyring = Keyring::Admin; diff --git a/runtime/integration-tests/src/generic/cases/liquidity_pools.rs b/runtime/integration-tests/src/cases/liquidity_pools.rs similarity index 99% rename from runtime/integration-tests/src/generic/cases/liquidity_pools.rs rename to runtime/integration-tests/src/cases/liquidity_pools.rs index e51699a7c4..db171c340e 100644 --- a/runtime/integration-tests/src/generic/cases/liquidity_pools.rs +++ b/runtime/integration-tests/src/cases/liquidity_pools.rs @@ -46,13 +46,10 @@ use staging_xcm::{ }; use crate::{ - generic::{ - config::Runtime, - env::Env, - envs::fudge_env::{handle::SIBLING_ID, FudgeEnv, FudgeSupport}, - utils::{genesis, genesis::Genesis}, - }, - utils::{accounts::Keyring, orml_asset_registry}, + config::Runtime, + env::Env, + envs::fudge_env::{handle::SIBLING_ID, FudgeEnv, FudgeSupport}, + utils::{accounts::Keyring, genesis, genesis::Genesis, orml_asset_registry}, }; /// The AUSD asset id @@ -458,7 +455,7 @@ mod utils { DEFAULT_VALIDITY, )), ) { - crate::generic::utils::pool::give_role::( + crate::utils::pool::give_role::( investor.clone(), pool_id, PoolRole::TrancheInvestor(default_tranche_id::(pool_id), DEFAULT_VALIDITY), @@ -551,7 +548,7 @@ mod utils { ); // Make investor the MembersListAdmin of this Pool - crate::generic::utils::pool::give_role::( + crate::utils::pool::give_role::( investor.clone(), pool_id, PoolRole::TrancheInvestor(default_tranche_id::(pool_id), DEFAULT_VALIDITY), @@ -661,20 +658,16 @@ mod utils { ::RuntimeOrigin::root(), Feeder::root(), )); - crate::generic::utils::oracle::update_feeders::( - POOL_ADMIN.id(), - POOL_ID, - [Feeder::root()], - ); + crate::utils::oracle::update_feeders::(POOL_ADMIN.id(), POOL_ID, [Feeder::root()]); if enable_foreign_to_pool_pair { - crate::generic::utils::oracle::feed_from_root::( + crate::utils::oracle::feed_from_root::( OracleKey::ConversionRatio(foreign_currency, pool_currency), Ratio::one(), ); } if enable_pool_to_foreign_pair { - crate::generic::utils::oracle::feed_from_root::( + crate::utils::oracle::feed_from_root::( OracleKey::ConversionRatio(pool_currency, foreign_currency), Ratio::one(), ); @@ -743,7 +736,7 @@ mod add_allow_upgrade { ); // Whitelist destination as TrancheInvestor of this Pool - crate::generic::utils::pool::give_role::( + crate::utils::pool::give_role::( AccountConverter::convert(new_member.clone()), pool_id, PoolRole::TrancheInvestor(default_tranche_id::(pool_id), DEFAULT_VALIDITY), diff --git a/runtime/integration-tests/src/generic/cases/loans.rs b/runtime/integration-tests/src/cases/loans.rs similarity index 98% rename from runtime/integration-tests/src/generic/cases/loans.rs rename to runtime/integration-tests/src/cases/loans.rs index 61f6ce7349..91fdda814a 100644 --- a/runtime/integration-tests/src/generic/cases/loans.rs +++ b/runtime/integration-tests/src/cases/loans.rs @@ -34,18 +34,16 @@ use sp_runtime::FixedPointNumber; use sp_std::collections::btree_map::BTreeMap; use crate::{ - generic::{ - config::Runtime, - env::{Blocks, Env}, - envs::runtime_env::RuntimeEnv, - utils::{ - self, - currency::{self, cfg, usd6, CurrencyInfo, Usd6}, - genesis::{self, Genesis}, - pool::POOL_MIN_EPOCH_TIME, - }, + config::Runtime, + env::{Blocks, Env}, + envs::runtime_env::RuntimeEnv, + utils::{ + self, + accounts::Keyring, + currency::{self, cfg, usd6, CurrencyInfo, Usd6}, + genesis::{self, Genesis}, + pool::POOL_MIN_EPOCH_TIME, }, - utils::accounts::Keyring, }; const POOL_ADMIN: Keyring = Keyring::Admin; diff --git a/runtime/integration-tests/src/generic/cases/lp/investments.rs b/runtime/integration-tests/src/cases/lp/investments.rs similarity index 97% rename from runtime/integration-tests/src/generic/cases/lp/investments.rs rename to runtime/integration-tests/src/cases/lp/investments.rs index 773524a346..131e893ac8 100644 --- a/runtime/integration-tests/src/generic/cases/lp/investments.rs +++ b/runtime/integration-tests/src/cases/lp/investments.rs @@ -17,15 +17,13 @@ use sp_core::U256; use sp_runtime::traits::Zero; use crate::{ - generic::{ - cases::lp::{ - self, names, setup_full, - utils::{pool_c_tranche_1_id, Decoder}, - DECIMALS_6, POOL_C, - }, - config::Runtime, - env::{Blocks, Env, EnvEvmExtension, EvmEnv}, + cases::lp::{ + self, names, setup_full, + utils::{pool_c_tranche_1_id, Decoder}, + DECIMALS_6, POOL_C, }, + config::Runtime, + env::{Blocks, Env, EnvEvmExtension, EvmEnv}, utils::accounts::Keyring, }; @@ -40,13 +38,10 @@ mod utils { use sp_core::U256; use crate::{ - generic::{ - cases::lp::{investments::DEFAULT_INVESTMENT_AMOUNT, names, utils::Decoder}, - config::Runtime, - env::EvmEnv, - utils::{collect_investments, pool::close_epoch}, - }, - utils::accounts::Keyring, + cases::lp::{investments::DEFAULT_INVESTMENT_AMOUNT, names, utils::Decoder}, + config::Runtime, + env::EvmEnv, + utils::{accounts::Keyring, collect_investments, pool::close_epoch}, }; pub fn index_lp(evm: &mut impl EvmEnv, name: &str) -> GeneralCurrencyIndexType { @@ -168,7 +163,7 @@ mod utils { mod with_pool_currency { use super::{utils, *}; - use crate::generic::cases::lp::utils as lp_utils; + use crate::cases::lp::utils as lp_utils; #[test_runtimes(all)] fn currency_invest() { @@ -344,7 +339,7 @@ mod with_foreign_currency { }; use super::{utils, *}; - use crate::generic::cases::lp::{ + use crate::cases::lp::{ investments::utils::close_and_collect, utils as lp_utils, utils::pool_a_tranche_1_id, POOL_A, }; diff --git a/runtime/integration-tests/src/generic/cases/lp/mod.rs b/runtime/integration-tests/src/cases/lp/mod.rs similarity index 97% rename from runtime/integration-tests/src/generic/cases/lp/mod.rs rename to runtime/integration-tests/src/cases/lp/mod.rs index 87669e43ec..f3f1ec9188 100644 --- a/runtime/integration-tests/src/generic/cases/lp/mod.rs +++ b/runtime/integration-tests/src/cases/lp/mod.rs @@ -36,23 +36,19 @@ use sp_core::Get; use sp_runtime::traits::{BlakeTwo256, Hash}; use crate::{ - generic::{ - cases::lp::utils::{ - pool_a_tranche_1_id, pool_b_tranche_1_id, pool_b_tranche_2_id, Decoder, - }, - config::Runtime, - env::{Blocks, Env, EnvEvmExtension, EvmEnv}, - envs::runtime_env::RuntimeEnv, - utils::{ - currency::{register_currency, CurrencyInfo}, - genesis, - genesis::Genesis, - give_balance, - oracle::set_order_book_feeder, - tokens::evm_balances, - }, + cases::lp::utils::{pool_a_tranche_1_id, pool_b_tranche_1_id, pool_b_tranche_2_id, Decoder}, + config::Runtime, + env::{Blocks, Env, EnvEvmExtension, EvmEnv}, + envs::runtime_env::RuntimeEnv, + utils::{ + accounts::{default_investors, Keyring}, + currency::{register_currency, CurrencyInfo}, + genesis, + genesis::Genesis, + give_balance, + oracle::set_order_book_feeder, + tokens::evm_balances, }, - utils::accounts::{default_investors, Keyring}, }; pub mod investments; @@ -83,12 +79,9 @@ pub mod utils { }; use crate::{ - generic::{ - cases::lp::{EVM_DOMAIN_CHAIN_ID, POOL_A, POOL_B, POOL_C}, - config::Runtime, - utils::{evm::receipt_ok, last_event, pool::get_tranche_ids}, - }, - utils::accounts::Keyring, + cases::lp::{EVM_DOMAIN_CHAIN_ID, POOL_A, POOL_B, POOL_C}, + config::Runtime, + utils::{accounts::Keyring, evm::receipt_ok, last_event, pool::get_tranche_ids}, }; pub fn remote_account_of( @@ -1435,11 +1428,7 @@ pub fn setup_tranches(evm: &mut impl EvmEnv) { /// * Pool A with 1 tranche /// * Pool B with 2 tranches pub fn setup_pools(_evm: &mut impl EvmEnv) { - crate::generic::utils::pool::create_one_tranched::( - Keyring::Admin.into(), - POOL_A, - LocalUSDC.id(), - ); + crate::utils::pool::create_one_tranched::(Keyring::Admin.into(), POOL_A, LocalUSDC.id()); assert_ok!(pallet_liquidity_pools::Pallet::::add_pool( OriginFor::::signed(Keyring::Admin.into()), @@ -1449,11 +1438,7 @@ pub fn setup_pools(_evm: &mut impl EvmEnv) { utils::process_outbound::(utils::verify_outbound_success::); - crate::generic::utils::pool::create_two_tranched::( - Keyring::Admin.into(), - POOL_B, - LocalUSDC.id(), - ); + crate::utils::pool::create_two_tranched::(Keyring::Admin.into(), POOL_B, LocalUSDC.id()); assert_ok!(pallet_liquidity_pools::Pallet::::add_pool( OriginFor::::signed(Keyring::Admin.into()), @@ -1461,7 +1446,7 @@ pub fn setup_pools(_evm: &mut impl EvmEnv) { Domain::EVM(EVM_DOMAIN_CHAIN_ID) )); - crate::generic::utils::pool::create_one_tranched::(Keyring::Admin.into(), POOL_C, USDC.id()); + crate::utils::pool::create_one_tranched::(Keyring::Admin.into(), POOL_C, USDC.id()); assert_ok!(pallet_liquidity_pools::Pallet::::add_pool( OriginFor::::signed(Keyring::Admin.into()), @@ -1701,13 +1686,13 @@ pub fn setup_currencies(evm: &mut impl EvmEnv) { pub fn setup_investors(evm: &mut impl EvmEnv) { default_investors().into_iter().for_each(|investor| { // Allow investor to locally invest - crate::generic::utils::pool::give_role::( + crate::utils::pool::give_role::( investor.into(), POOL_A, PoolRole::TrancheInvestor(pool_a_tranche_1_id::(), SECONDS_PER_YEAR), ); // Centrifuge Chain setup: Add permissions and dispatch LP message - crate::generic::utils::pool::give_role::( + crate::utils::pool::give_role::( AccountConverter::convert_evm_address(EVM_DOMAIN_CHAIN_ID, investor.into()), POOL_A, PoolRole::TrancheInvestor(pool_a_tranche_1_id::(), SECONDS_PER_YEAR), @@ -1721,12 +1706,12 @@ pub fn setup_investors(evm: &mut impl EvmEnv) { )); // Allow investor to locally invest - crate::generic::utils::pool::give_role::( + crate::utils::pool::give_role::( investor.into(), POOL_B, PoolRole::TrancheInvestor(pool_b_tranche_1_id::(), SECONDS_PER_YEAR), ); - crate::generic::utils::pool::give_role::( + crate::utils::pool::give_role::( AccountConverter::convert_evm_address(EVM_DOMAIN_CHAIN_ID, investor.into()), POOL_B, PoolRole::TrancheInvestor(pool_b_tranche_1_id::(), SECONDS_PER_YEAR), @@ -1740,12 +1725,12 @@ pub fn setup_investors(evm: &mut impl EvmEnv) { )); // Allow investor to locally invest - crate::generic::utils::pool::give_role::( + crate::utils::pool::give_role::( investor.into(), POOL_B, PoolRole::TrancheInvestor(pool_b_tranche_2_id::(), SECONDS_PER_YEAR), ); - crate::generic::utils::pool::give_role::( + crate::utils::pool::give_role::( AccountConverter::convert_evm_address(EVM_DOMAIN_CHAIN_ID, investor.into()), POOL_B, PoolRole::TrancheInvestor(pool_b_tranche_2_id::(), SECONDS_PER_YEAR), @@ -1759,12 +1744,12 @@ pub fn setup_investors(evm: &mut impl EvmEnv) { )); // Allow investor to locally invest - crate::generic::utils::pool::give_role::( + crate::utils::pool::give_role::( investor.into(), POOL_C, PoolRole::TrancheInvestor(utils::pool_c_tranche_1_id::(), SECONDS_PER_YEAR), ); - crate::generic::utils::pool::give_role::( + crate::utils::pool::give_role::( AccountConverter::convert_evm_address(EVM_DOMAIN_CHAIN_ID, investor.into()), POOL_C, PoolRole::TrancheInvestor(utils::pool_c_tranche_1_id::(), SECONDS_PER_YEAR), diff --git a/runtime/integration-tests/src/generic/cases/lp/pool_management.rs b/runtime/integration-tests/src/cases/lp/pool_management.rs similarity index 97% rename from runtime/integration-tests/src/generic/cases/lp/pool_management.rs rename to runtime/integration-tests/src/cases/lp/pool_management.rs index e4ec810d97..6950fae46b 100644 --- a/runtime/integration-tests/src/generic/cases/lp/pool_management.rs +++ b/runtime/integration-tests/src/cases/lp/pool_management.rs @@ -25,17 +25,17 @@ use runtime_common::account_conversion::AccountConverter; use sp_runtime::FixedPointNumber; use crate::{ - generic::{ - cases::lp::{ - names, utils, - utils::{pool_a_tranche_1_id, Decoder}, - LocalUSDC, EVM_DOMAIN_CHAIN_ID, POOL_A, USDC, - }, - config::Runtime, - env::{EnvEvmExtension, EvmEnv}, - utils::currency::{register_currency, CurrencyInfo}, + cases::lp::{ + names, utils, + utils::{pool_a_tranche_1_id, Decoder}, + LocalUSDC, EVM_DOMAIN_CHAIN_ID, POOL_A, USDC, + }, + config::Runtime, + env::{EnvEvmExtension, EvmEnv}, + utils::{ + accounts::Keyring, + currency::{register_currency, CurrencyInfo}, }, - utils::accounts::Keyring, }; #[test_runtimes(all)] @@ -133,11 +133,7 @@ fn add_pool() { const POOL: PoolId = 1; env.state_mut(|evm| { - crate::generic::utils::pool::create_one_tranched::( - Keyring::Admin.into(), - POOL, - LocalUSDC.id(), - ); + crate::utils::pool::create_one_tranched::(Keyring::Admin.into(), POOL, LocalUSDC.id()); assert_ok!(pallet_liquidity_pools::Pallet::::add_pool( OriginFor::::signed(Keyring::Admin.into()), @@ -387,7 +383,7 @@ fn update_member() { }); env.state_mut(|_| { - crate::generic::utils::pool::give_role::( + crate::utils::pool::give_role::( AccountConverter::convert_evm_address(EVM_DOMAIN_CHAIN_ID, Keyring::Bob.into()), POOL_A, PoolRole::TrancheInvestor(pool_a_tranche_1_id::(), SECONDS_PER_YEAR), diff --git a/runtime/integration-tests/src/generic/cases/lp/transfers.rs b/runtime/integration-tests/src/cases/lp/transfers.rs similarity index 95% rename from runtime/integration-tests/src/generic/cases/lp/transfers.rs rename to runtime/integration-tests/src/cases/lp/transfers.rs index 0aff7d8415..a267c1a541 100644 --- a/runtime/integration-tests/src/generic/cases/lp/transfers.rs +++ b/runtime/integration-tests/src/cases/lp/transfers.rs @@ -23,17 +23,14 @@ use sp_core::ByteArray; use sp_runtime::traits::Convert; use crate::{ - generic::{ - cases::lp::{ - self, names, - utils::{as_h160_32bytes, pool_a_tranche_1_id, Decoder}, - LocalUSDC, DECIMALS_6, DEFAULT_BALANCE, EVM_DOMAIN_CHAIN_ID, POOL_A, USDC, - }, - config::Runtime, - env::{Blocks, Env, EnvEvmExtension, EvmEnv}, - utils::{currency::CurrencyInfo, give_tokens, invest_and_collect}, + cases::lp::{ + self, names, + utils::{as_h160_32bytes, pool_a_tranche_1_id, Decoder}, + LocalUSDC, DECIMALS_6, DEFAULT_BALANCE, EVM_DOMAIN_CHAIN_ID, POOL_A, USDC, }, - utils::accounts::Keyring, + config::Runtime, + env::{Blocks, Env, EnvEvmExtension, EvmEnv}, + utils::{accounts::Keyring, currency::CurrencyInfo, give_tokens, invest_and_collect}, }; // The default amount of invested stable coins diff --git a/runtime/integration-tests/src/generic/cases/oracles.rs b/runtime/integration-tests/src/cases/oracles.rs similarity index 99% rename from runtime/integration-tests/src/generic/cases/oracles.rs rename to runtime/integration-tests/src/cases/oracles.rs index d194c50ea8..12860cd147 100644 --- a/runtime/integration-tests/src/generic/cases/oracles.rs +++ b/runtime/integration-tests/src/cases/oracles.rs @@ -23,7 +23,7 @@ mod ratio_provider { use runtime_common::oracle::Feeder; use sp_runtime::{traits::One, FixedPointNumber}; - use crate::generic::{ + use crate::{ config::Runtime, env::Env, envs::runtime_env::RuntimeEnv, diff --git a/runtime/integration-tests/src/generic/cases/precompile.rs b/runtime/integration-tests/src/cases/precompile.rs similarity index 99% rename from runtime/integration-tests/src/generic/cases/precompile.rs rename to runtime/integration-tests/src/cases/precompile.rs index d7f71c405a..92086d3629 100644 --- a/runtime/integration-tests/src/generic/cases/precompile.rs +++ b/runtime/integration-tests/src/cases/precompile.rs @@ -15,7 +15,7 @@ use runtime_common::evm::precompile::LP_AXELAR_GATEWAY; use sp_core::{H160, H256, U256}; use sp_runtime::traits::{BlakeTwo256, Hash}; -use crate::generic::{ +use crate::{ config::Runtime, env::Env, envs::runtime_env::RuntimeEnv, diff --git a/runtime/integration-tests/src/generic/cases/proxy.rs b/runtime/integration-tests/src/cases/proxy.rs similarity index 96% rename from runtime/integration-tests/src/generic/cases/proxy.rs rename to runtime/integration-tests/src/cases/proxy.rs index a1ce753c5e..a3b1cb2268 100644 --- a/runtime/integration-tests/src/generic/cases/proxy.rs +++ b/runtime/integration-tests/src/cases/proxy.rs @@ -5,17 +5,15 @@ use sp_runtime::{traits::StaticLookup, DispatchResult}; use staging_xcm::v4::WeightLimit; use crate::{ - generic::{ - config::Runtime, - env::Env, - envs::runtime_env::RuntimeEnv, - utils::{ - currency::{cfg, CurrencyInfo, CustomCurrency}, - genesis::{self, Genesis}, - xcm::{account_location, transferable_metadata}, - }, + config::Runtime, + env::Env, + envs::runtime_env::RuntimeEnv, + utils::{ + accounts::Keyring, + currency::{cfg, CurrencyInfo, CustomCurrency}, + genesis::{self, Genesis}, + xcm::{account_location, transferable_metadata}, }, - utils::accounts::Keyring, }; const FROM: Keyring = Keyring::Charlie; diff --git a/runtime/integration-tests/src/generic/cases/restricted_transfers.rs b/runtime/integration-tests/src/cases/restricted_transfers.rs similarity index 97% rename from runtime/integration-tests/src/generic/cases/restricted_transfers.rs rename to runtime/integration-tests/src/cases/restricted_transfers.rs index 30f3e2d6e7..b1699afed5 100644 --- a/runtime/integration-tests/src/generic/cases/restricted_transfers.rs +++ b/runtime/integration-tests/src/cases/restricted_transfers.rs @@ -29,18 +29,16 @@ use staging_xcm::{ }; use crate::{ - generic::{ - config::Runtime, - env::Env, - envs::runtime_env::RuntimeEnv, - utils::{ - currency::{cfg, CurrencyInfo, CustomCurrency}, - genesis, - genesis::Genesis, - xcm::{account_location, transferable_metadata}, - }, + config::Runtime, + env::Env, + envs::runtime_env::RuntimeEnv, + utils::{ + accounts::Keyring, + currency::{cfg, CurrencyInfo, CustomCurrency}, + genesis, + genesis::Genesis, + xcm::{account_location, transferable_metadata}, }, - utils::accounts::Keyring, }; mod local { diff --git a/runtime/integration-tests/src/generic/cases/routers.rs b/runtime/integration-tests/src/cases/routers.rs similarity index 93% rename from runtime/integration-tests/src/generic/cases/routers.rs rename to runtime/integration-tests/src/cases/routers.rs index 7abb3bf99a..eb07d58409 100644 --- a/runtime/integration-tests/src/generic/cases/routers.rs +++ b/runtime/integration-tests/src/cases/routers.rs @@ -20,19 +20,17 @@ use sp_runtime::{ use staging_xcm::v4::{Junction::*, Location}; use crate::{ - generic::{ - config::Runtime, - env::{Blocks, Env}, - envs::fudge_env::{handle::SIBLING_ID, FudgeEnv, FudgeSupport}, - utils::{ - self, - currency::{cfg, CurrencyInfo, CustomCurrency}, - genesis, - genesis::Genesis, - xcm::{enable_para_to_sibling_communication, transferable_metadata}, - }, + config::Runtime, + env::{Blocks, Env}, + envs::fudge_env::{handle::SIBLING_ID, FudgeEnv, FudgeSupport}, + utils::{ + self, + accounts::Keyring, + currency::{cfg, CurrencyInfo, CustomCurrency}, + genesis, + genesis::Genesis, + xcm::{enable_para_to_sibling_communication, transferable_metadata}, }, - utils::accounts::Keyring, }; const INITIAL: Balance = 100; diff --git a/runtime/integration-tests/src/generic/cases/xcm_transfers.rs b/runtime/integration-tests/src/cases/xcm_transfers.rs similarity index 92% rename from runtime/integration-tests/src/generic/cases/xcm_transfers.rs rename to runtime/integration-tests/src/cases/xcm_transfers.rs index 04f471144b..093ff65441 100644 --- a/runtime/integration-tests/src/generic/cases/xcm_transfers.rs +++ b/runtime/integration-tests/src/cases/xcm_transfers.rs @@ -4,25 +4,24 @@ use orml_traits::MultiCurrency; use staging_xcm::v4::{Junction::*, Junctions::Here, WeightLimit}; use crate::{ - generic::{ - config::Runtime, - env::{Blocks, Env}, - envs::fudge_env::{ - handle::{PARA_ID, SIBLING_ID}, - FudgeEnv, FudgeSupport, RelayRuntime, - }, - utils::{ - currency::{cfg, CurrencyInfo, CustomCurrency}, - genesis, - genesis::Genesis, - xcm::{ - account_location, enable_para_to_relay_communication, - enable_para_to_sibling_communication, enable_relay_to_para_communication, - transferable_metadata, - }, + config::Runtime, + env::{Blocks, Env}, + envs::fudge_env::{ + handle::{PARA_ID, SIBLING_ID}, + FudgeEnv, FudgeSupport, RelayRuntime, + }, + utils::{ + accounts::Keyring, + approx::Approximate, + currency::{cfg, CurrencyInfo, CustomCurrency}, + genesis, + genesis::Genesis, + xcm::{ + account_location, enable_para_to_relay_communication, + enable_para_to_sibling_communication, enable_relay_to_para_communication, + transferable_metadata, }, }, - utils::{accounts::Keyring, approx::Approximate}, }; const INITIAL: u32 = 100; diff --git a/runtime/integration-tests/src/generic/config.rs b/runtime/integration-tests/src/config.rs similarity index 100% rename from runtime/integration-tests/src/generic/config.rs rename to runtime/integration-tests/src/config.rs diff --git a/runtime/integration-tests/src/generic/env.rs b/runtime/integration-tests/src/env.rs similarity index 98% rename from runtime/integration-tests/src/generic/env.rs rename to runtime/integration-tests/src/env.rs index ea28267154..5d42e8c2db 100644 --- a/runtime/integration-tests/src/generic/env.rs +++ b/runtime/integration-tests/src/env.rs @@ -12,11 +12,11 @@ use sp_runtime::{ use sp_std::ops::Range; use crate::{ - generic::{ - config::Runtime, - utils::evm::{ContractInfo, DeployedContractInfo}, + config::Runtime, + utils::{ + accounts::Keyring, + evm::{ContractInfo, DeployedContractInfo}, }, - utils::accounts::Keyring, }; /// Used by Env::pass() to determine how many blocks should be passed diff --git a/runtime/integration-tests/src/generic/envs/evm_env.rs b/runtime/integration-tests/src/envs/evm_env.rs similarity index 97% rename from runtime/integration-tests/src/generic/envs/evm_env.rs rename to runtime/integration-tests/src/envs/evm_env.rs index cdcf52cc59..b753474a7b 100644 --- a/runtime/integration-tests/src/generic/envs/evm_env.rs +++ b/runtime/integration-tests/src/envs/evm_env.rs @@ -6,16 +6,14 @@ use sp_core::{H160, U256}; use sp_runtime::DispatchError; use crate::{ - generic::{ - config::Runtime, - env, - utils::{ - evm, - evm::{ContractInfo, DeployedContractInfo}, - ESSENTIAL, - }, + config::Runtime, + env, + utils::{ + accounts::Keyring, + evm, + evm::{ContractInfo, DeployedContractInfo}, + ESSENTIAL, }, - utils::accounts::Keyring, }; const GAS_LIMIT: u64 = 105_000_000; diff --git a/runtime/integration-tests/src/generic/envs/fudge_env.rs b/runtime/integration-tests/src/envs/fudge_env.rs similarity index 97% rename from runtime/integration-tests/src/generic/envs/fudge_env.rs rename to runtime/integration-tests/src/envs/fudge_env.rs index 4c9cc28d0c..87cb2cc993 100644 --- a/runtime/integration-tests/src/generic/envs/fudge_env.rs +++ b/runtime/integration-tests/src/envs/fudge_env.rs @@ -11,10 +11,8 @@ use sp_core::H256; use sp_runtime::{DispatchError, Storage}; use crate::{ - generic::{ - config::Runtime, - env::{utils, Env}, - }, + config::Runtime, + env::{utils, Env}, utils::accounts::Keyring, }; @@ -154,7 +152,7 @@ mod tests { use cfg_primitives::CFG; use super::*; - use crate::generic::{env::Blocks, utils::genesis::Genesis}; + use crate::{env::Blocks, utils::genesis::Genesis}; #[test_runtimes(all)] fn correct_nonce_for_submit_later() { diff --git a/runtime/integration-tests/src/generic/envs/fudge_env/handle.rs b/runtime/integration-tests/src/envs/fudge_env/handle.rs similarity index 99% rename from runtime/integration-tests/src/generic/envs/fudge_env/handle.rs rename to runtime/integration-tests/src/envs/fudge_env/handle.rs index 07d3af10e7..f22330c9d4 100644 --- a/runtime/integration-tests/src/generic/envs/fudge_env/handle.rs +++ b/runtime/integration-tests/src/envs/fudge_env/handle.rs @@ -27,7 +27,7 @@ use sp_runtime::{BuildStorage, Storage}; use sp_transaction_pool::runtime_api::TaggedTransactionQueue; use tokio::runtime::Handle; -use crate::generic::config::Runtime; +use crate::config::Runtime; /// Start date used for timestamps in test-enviornments /// Sat Jan 01 2022 00:00:00 GMT+0000 diff --git a/runtime/integration-tests/src/generic/envs/runtime_env.rs b/runtime/integration-tests/src/envs/runtime_env.rs similarity index 98% rename from runtime/integration-tests/src/generic/envs/runtime_env.rs rename to runtime/integration-tests/src/envs/runtime_env.rs index 3a339b8eb2..dc066afb86 100644 --- a/runtime/integration-tests/src/generic/envs/runtime_env.rs +++ b/runtime/integration-tests/src/envs/runtime_env.rs @@ -24,11 +24,9 @@ use sp_runtime::{ use sp_timestamp::Timestamp; use crate::{ - generic::{ - config::Runtime, - env::{utils, Env, EnvEvmExtension}, - envs::evm_env::EvmEnv, - }, + config::Runtime, + env::{utils, Env, EnvEvmExtension}, + envs::evm_env::EvmEnv, utils::accounts::Keyring, }; @@ -308,7 +306,7 @@ mod tests { use cfg_primitives::CFG; use super::*; - use crate::generic::{env::Blocks, utils::genesis::Genesis}; + use crate::{env::Blocks, utils::genesis::Genesis}; #[test_runtimes(all)] fn correct_nonce_for_submit_now() { diff --git a/runtime/integration-tests/src/generic/mod.rs b/runtime/integration-tests/src/generic/mod.rs deleted file mode 100644 index 1cad23441d..0000000000 --- a/runtime/integration-tests/src/generic/mod.rs +++ /dev/null @@ -1,62 +0,0 @@ -pub mod env; -pub mod envs { - pub mod evm_env; - pub mod fudge_env; - pub mod runtime_env; -} -pub mod config; -mod impls; -pub mod utils; - -// Test cases -mod cases { - mod account_derivation; - mod assets; - mod block_rewards; - mod currency_conversions; - mod ethereum_transaction; - mod example; - mod investments; - mod liquidity_pools; - mod loans; - mod lp; - mod oracles; - mod precompile; - mod proxy; - mod restricted_transfers; - mod routers; - mod xcm_transfers; -} - -/// Generate tests for the specified runtimes or all runtimes. -/// Usage. Used as building block for #[test_runtimes] procedural macro. -/// -/// NOTE: Do not use it direclty, use `#[test_runtimes]` proc macro instead -#[macro_export] -macro_rules! __test_for_runtimes { - ( [ $($runtime_name:ident),* ], $test_name:ident ) => { - #[cfg(test)] - mod $test_name { - use super::*; - - #[allow(unused)] - use development_runtime as development; - - #[allow(unused)] - use altair_runtime as altair; - - #[allow(unused)] - use centrifuge_runtime as centrifuge; - - $( - #[tokio::test] - async fn $runtime_name() { - $test_name::<$runtime_name::Runtime>() - } - )* - } - }; - ( all , $test_name:ident ) => { - $crate::__test_for_runtimes!([development, altair, centrifuge], $test_name); - }; -} diff --git a/runtime/integration-tests/src/generic/utils/mod.rs b/runtime/integration-tests/src/generic/utils/mod.rs deleted file mode 100644 index ddc868451d..0000000000 --- a/runtime/integration-tests/src/generic/utils/mod.rs +++ /dev/null @@ -1,227 +0,0 @@ -//! PLEASE be as much generic as possible because no domain or use cases are -//! considered at util level and below modules. If you need utilities related to -//! your use case, add them under `cases/`. -//! -//! Trying to use methods that map to real extrinsic will make easy life to -//! frontend applications, having a source of the real calls they can replicate -//! to simulate some scenarios. -//! -//! Divide this utilities into files when it grows - -pub mod currency; -pub mod evm; -pub mod genesis; -pub mod pool; -pub mod tokens; -pub mod xcm; - -use cfg_primitives::{AccountId, Balance, CollectionId, ItemId, PoolId, TrancheId}; -use cfg_traits::{investments::TrancheCurrency as _, Seconds, TimeAsSecs}; -use cfg_types::{ - fixed_point::Ratio, - oracles::OracleKey, - tokens::{CurrencyId, TrancheCurrency}, -}; -use frame_system::RawOrigin; -use pallet_oracle_collection::types::CollectionInfo; -use runtime_common::oracle::Feeder; -use sp_runtime::traits::StaticLookup; - -use crate::{ - generic::{config::Runtime, utils::pool::close_epoch}, - utils::accounts::Keyring, -}; - -pub const ESSENTIAL: &str = - "Essential part of the test codebase failed. Assumed infallible under sane circumstances"; - -pub fn now_secs() -> Seconds { - as TimeAsSecs>::now() -} - -pub fn find_event(f: impl Fn(E) -> Option) -> Option -where - T::RuntimeEventExt: TryInto, -{ - frame_system::Pallet::::events() - .into_iter() - .rev() - .find_map(|record| record.event.try_into().map(|e| f(e)).ok()) - .flatten() -} - -pub fn last_event() -> E -where - T::RuntimeEventExt: TryInto, -{ - frame_system::Pallet::::events() - .pop() - .unwrap() - .event - .try_into() - .ok() - .unwrap() -} - -pub fn give_nft(dest: AccountId, (collection_id, item_id): (CollectionId, ItemId)) { - pallet_uniques::Pallet::::force_create( - RawOrigin::Root.into(), - collection_id, - T::Lookup::unlookup(dest.clone()), - true, - ) - .unwrap(); - - pallet_uniques::Pallet::::mint( - RawOrigin::Signed(dest.clone()).into(), - collection_id, - item_id, - T::Lookup::unlookup(dest), - ) - .unwrap() -} - -pub fn give_balance(dest: AccountId, amount: Balance) { - let data = pallet_balances::Account::::get(dest.clone()); - pallet_balances::Pallet::::force_set_balance( - RawOrigin::Root.into(), - T::Lookup::unlookup(dest), - data.free + amount, - ) - .unwrap(); -} - -pub fn give_tokens(dest: AccountId, currency_id: CurrencyId, amount: Balance) { - let data = orml_tokens::Accounts::::get(dest.clone(), currency_id); - orml_tokens::Pallet::::set_balance( - RawOrigin::Root.into(), - T::Lookup::unlookup(dest), - currency_id, - data.free + amount, - data.reserved, - ) - .unwrap(); -} - -pub fn invest( - investor: AccountId, - pool_id: PoolId, - tranche_id: TrancheId, - amount: Balance, -) { - pallet_investments::Pallet::::update_invest_order( - RawOrigin::Signed(investor).into(), - TrancheCurrency::generate(pool_id, tranche_id), - amount, - ) - .unwrap(); -} - -pub fn redeem( - investor: AccountId, - pool_id: PoolId, - tranche_id: TrancheId, - amount: Balance, -) { - pallet_investments::Pallet::::update_redeem_order( - RawOrigin::Signed(investor).into(), - TrancheCurrency::generate(pool_id, tranche_id), - amount, - ) - .unwrap(); -} - -pub fn collect_investments( - investor: AccountId, - pool_id: PoolId, - tranche_id: TrancheId, -) { - pallet_investments::Pallet::::collect_investments( - RawOrigin::Signed(investor).into(), - TrancheCurrency::generate(pool_id, tranche_id), - ) - .unwrap(); -} - -pub fn collect_redemptions( - investor: AccountId, - pool_id: PoolId, - tranche_id: TrancheId, -) { - pallet_investments::Pallet::::collect_redemptions( - RawOrigin::Signed(investor).into(), - TrancheCurrency::generate(pool_id, tranche_id), - ) - .unwrap(); -} - -pub fn invest_and_collect( - investor: AccountId, - admin: Keyring, - pool_id: PoolId, - tranche_id: TrancheId, - amount: Balance, -) { - invest::(investor.clone(), pool_id, tranche_id, amount); - close_epoch::(admin.into(), pool_id); - collect_investments::(investor, pool_id, tranche_id); -} - -pub fn last_change_id() -> T::Hash { - find_event::(|e| match e { - pallet_pool_system::Event::::ProposedChange { change_id, .. } => Some(change_id), - _ => None, - }) - .unwrap() -} - -pub mod oracle { - use frame_support::traits::OriginTrait; - - use super::*; - - pub fn set_order_book_feeder(origin: T::RuntimeOriginExt) { - pallet_order_book::Pallet::::set_market_feeder( - T::RuntimeOriginExt::root(), - Feeder(origin.into_caller()), - ) - .unwrap() - } - - pub fn feed_from_root(key: OracleKey, value: Ratio) { - pallet_oracle_feed::Pallet::::feed(RawOrigin::Root.into(), key, value).unwrap(); - } - - pub fn update_feeders( - admin: AccountId, - pool_id: PoolId, - feeders: impl IntoIterator>, - ) { - pallet_oracle_collection::Pallet::::propose_update_collection_info( - RawOrigin::Signed(admin.clone()).into(), - pool_id, - CollectionInfo { - feeders: pallet_oracle_collection::util::feeders_from(feeders).unwrap(), - ..Default::default() - }, - ) - .unwrap(); - - let change_id = last_change_id::(); - - pallet_oracle_collection::Pallet::::apply_update_collection_info( - RawOrigin::Signed(admin).into(), //or any account - pool_id, - change_id, - ) - .unwrap(); - } - - pub fn update_collection(any: AccountId, pool_id: PoolId) { - pallet_oracle_collection::Pallet::::update_collection( - RawOrigin::Signed(any).into(), - pool_id, - ) - .unwrap(); - } -} diff --git a/runtime/integration-tests/src/generic/impls.rs b/runtime/integration-tests/src/impls.rs similarity index 97% rename from runtime/integration-tests/src/generic/impls.rs rename to runtime/integration-tests/src/impls.rs index 8c0791ac0d..27db638e2c 100644 --- a/runtime/integration-tests/src/generic/impls.rs +++ b/runtime/integration-tests/src/impls.rs @@ -10,7 +10,7 @@ macro_rules! impl_runtime { const _: () = { use sp_core::sr25519::Public; - use crate::generic::config::{Runtime, RuntimeKind}; + use crate::config::{Runtime, RuntimeKind}; impl Runtime for $runtime_path::Runtime { type Api = Self; @@ -53,7 +53,7 @@ macro_rules! impl_fudge_support { use sp_api::ConstructRuntimeApi; use sp_runtime::Storage; - use crate::generic::envs::fudge_env::{ + use crate::envs::fudge_env::{ handle::{ FudgeHandle, ParachainBuilder, ParachainClient, RelayClient, RelaychainBuilder, PARA_ID, SIBLING_ID, @@ -74,7 +74,7 @@ macro_rules! impl_fudge_support { pub sibling: ParachainBuilder<$parachain_path::Block, $parachain_path::RuntimeApi>, } - // Implement for T only one time when fudge::companion + // TODO: Implement for T only one time when fudge::companion // supports generic in the struct signature. impl FudgeHandle<$parachain_path::Runtime> for $fudge_companion_type { type ParachainApi = <$parachain_path::RuntimeApi as ConstructRuntimeApi< diff --git a/runtime/integration-tests/src/lib.rs b/runtime/integration-tests/src/lib.rs index 76a1eb4c3f..459781a7e1 100644 --- a/runtime/integration-tests/src/lib.rs +++ b/runtime/integration-tests/src/lib.rs @@ -20,5 +20,46 @@ #[macro_use] extern crate runtime_integration_tests_proc_macro; -mod generic; +mod cases; +mod env; mod utils; +mod envs { + pub mod evm_env; + pub mod fudge_env; + pub mod runtime_env; +} +mod config; +mod impls; + +/// Generate tests for the specified runtimes or all runtimes. +/// Usage. Used as building block for #[test_runtimes] procedural macro. +/// +/// NOTE: Do not use it direclty, use `#[test_runtimes]` proc macro instead +#[macro_export] +macro_rules! __test_for_runtimes { + ( [ $($runtime_name:ident),* ], $test_name:ident ) => { + #[cfg(test)] + mod $test_name { + use super::*; + + #[allow(unused)] + use development_runtime as development; + + #[allow(unused)] + use altair_runtime as altair; + + #[allow(unused)] + use centrifuge_runtime as centrifuge; + + $( + #[tokio::test] + async fn $runtime_name() { + $test_name::<$runtime_name::Runtime>() + } + )* + } + }; + ( all , $test_name:ident ) => { + $crate::__test_for_runtimes!([development, altair, centrifuge], $test_name); + }; +} diff --git a/runtime/integration-tests/src/generic/utils/currency.rs b/runtime/integration-tests/src/utils/currency.rs similarity index 99% rename from runtime/integration-tests/src/generic/utils/currency.rs rename to runtime/integration-tests/src/utils/currency.rs index 40e0a3d2da..9cad254c4d 100644 --- a/runtime/integration-tests/src/generic/utils/currency.rs +++ b/runtime/integration-tests/src/utils/currency.rs @@ -7,7 +7,7 @@ use frame_support::{assert_ok, traits::OriginTrait}; use sp_runtime::FixedPointNumber; use staging_xcm::VersionedLocation; -use crate::generic::config::Runtime; +use crate::config::Runtime; const fn amount_pow(amount: Balance, exp: u32) -> Balance { amount * 10u128.pow(exp) diff --git a/runtime/integration-tests/src/generic/utils/evm.rs b/runtime/integration-tests/src/utils/evm.rs similarity index 99% rename from runtime/integration-tests/src/generic/utils/evm.rs rename to runtime/integration-tests/src/utils/evm.rs index 9b486e4fec..4c91a4aef9 100644 --- a/runtime/integration-tests/src/generic/utils/evm.rs +++ b/runtime/integration-tests/src/utils/evm.rs @@ -12,7 +12,7 @@ use pallet_evm::FeeCalculator; use runtime_common::account_conversion::AccountConverter; use sp_runtime::traits::Get; -use crate::generic::{config::Runtime, utils::ESSENTIAL}; +use crate::{config::Runtime, utils::ESSENTIAL}; /// Liquidity-Pool solidity artifacts generated by build-script. /// All needed contracts can be loaded from here. diff --git a/runtime/integration-tests/src/generic/utils/genesis.rs b/runtime/integration-tests/src/utils/genesis.rs similarity index 99% rename from runtime/integration-tests/src/generic/utils/genesis.rs rename to runtime/integration-tests/src/utils/genesis.rs index 1648a95ba7..d6a721d0b5 100644 --- a/runtime/integration-tests/src/generic/utils/genesis.rs +++ b/runtime/integration-tests/src/utils/genesis.rs @@ -11,7 +11,7 @@ use sp_core::Get; use sp_runtime::{BuildStorage, FixedPointNumber, Storage}; use crate::{ - generic::config::Runtime, + config::Runtime, utils::accounts::{default_accounts, Keyring}, }; diff --git a/runtime/integration-tests/src/utils/mod.rs b/runtime/integration-tests/src/utils/mod.rs index 3ee465c7a6..3dc636ce3d 100644 --- a/runtime/integration-tests/src/utils/mod.rs +++ b/runtime/integration-tests/src/utils/mod.rs @@ -10,8 +10,33 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. +// Divide this utilities into files when it grows + pub mod accounts; +pub mod currency; +pub mod evm; +pub mod genesis; pub mod logs; +pub mod pool; +pub mod tokens; +pub mod xcm; + +use cfg_primitives::{AccountId, Balance, CollectionId, ItemId, PoolId, TrancheId}; +use cfg_traits::{investments::TrancheCurrency as _, Seconds, TimeAsSecs}; +use cfg_types::{ + fixed_point::Ratio, + oracles::OracleKey, + tokens::{CurrencyId, TrancheCurrency}, +}; +use frame_system::RawOrigin; +use pallet_oracle_collection::types::CollectionInfo; +use runtime_common::oracle::Feeder; +use sp_runtime::traits::StaticLookup; + +use crate::{ + config::Runtime, + utils::{accounts::Keyring, pool::close_epoch}, +}; pub mod orml_asset_registry { // orml_asset_registry has remove the reexport of all pallet stuff, @@ -82,3 +107,197 @@ pub mod approx { assert_ne!(1000u128, 1500.approx(0.1)); } } + +pub const ESSENTIAL: &str = + "Essential part of the test codebase failed. Assumed infallible under sane circumstances"; + +pub fn now_secs() -> Seconds { + as TimeAsSecs>::now() +} + +pub fn find_event(f: impl Fn(E) -> Option) -> Option +where + T::RuntimeEventExt: TryInto, +{ + frame_system::Pallet::::events() + .into_iter() + .rev() + .find_map(|record| record.event.try_into().map(|e| f(e)).ok()) + .flatten() +} + +pub fn last_event() -> E +where + T::RuntimeEventExt: TryInto, +{ + frame_system::Pallet::::events() + .pop() + .unwrap() + .event + .try_into() + .ok() + .unwrap() +} + +pub fn give_nft(dest: AccountId, (collection_id, item_id): (CollectionId, ItemId)) { + pallet_uniques::Pallet::::force_create( + RawOrigin::Root.into(), + collection_id, + T::Lookup::unlookup(dest.clone()), + true, + ) + .unwrap(); + + pallet_uniques::Pallet::::mint( + RawOrigin::Signed(dest.clone()).into(), + collection_id, + item_id, + T::Lookup::unlookup(dest), + ) + .unwrap() +} + +pub fn give_balance(dest: AccountId, amount: Balance) { + let data = pallet_balances::Account::::get(dest.clone()); + pallet_balances::Pallet::::force_set_balance( + RawOrigin::Root.into(), + T::Lookup::unlookup(dest), + data.free + amount, + ) + .unwrap(); +} + +pub fn give_tokens(dest: AccountId, currency_id: CurrencyId, amount: Balance) { + let data = orml_tokens::Accounts::::get(dest.clone(), currency_id); + orml_tokens::Pallet::::set_balance( + RawOrigin::Root.into(), + T::Lookup::unlookup(dest), + currency_id, + data.free + amount, + data.reserved, + ) + .unwrap(); +} + +pub fn invest( + investor: AccountId, + pool_id: PoolId, + tranche_id: TrancheId, + amount: Balance, +) { + pallet_investments::Pallet::::update_invest_order( + RawOrigin::Signed(investor).into(), + TrancheCurrency::generate(pool_id, tranche_id), + amount, + ) + .unwrap(); +} + +pub fn redeem( + investor: AccountId, + pool_id: PoolId, + tranche_id: TrancheId, + amount: Balance, +) { + pallet_investments::Pallet::::update_redeem_order( + RawOrigin::Signed(investor).into(), + TrancheCurrency::generate(pool_id, tranche_id), + amount, + ) + .unwrap(); +} + +pub fn collect_investments( + investor: AccountId, + pool_id: PoolId, + tranche_id: TrancheId, +) { + pallet_investments::Pallet::::collect_investments( + RawOrigin::Signed(investor).into(), + TrancheCurrency::generate(pool_id, tranche_id), + ) + .unwrap(); +} + +pub fn collect_redemptions( + investor: AccountId, + pool_id: PoolId, + tranche_id: TrancheId, +) { + pallet_investments::Pallet::::collect_redemptions( + RawOrigin::Signed(investor).into(), + TrancheCurrency::generate(pool_id, tranche_id), + ) + .unwrap(); +} + +pub fn invest_and_collect( + investor: AccountId, + admin: Keyring, + pool_id: PoolId, + tranche_id: TrancheId, + amount: Balance, +) { + invest::(investor.clone(), pool_id, tranche_id, amount); + close_epoch::(admin.into(), pool_id); + collect_investments::(investor, pool_id, tranche_id); +} + +pub fn last_change_id() -> T::Hash { + find_event::(|e| match e { + pallet_pool_system::Event::::ProposedChange { change_id, .. } => Some(change_id), + _ => None, + }) + .unwrap() +} + +pub mod oracle { + use frame_support::traits::OriginTrait; + + use super::*; + + pub fn set_order_book_feeder(origin: T::RuntimeOriginExt) { + pallet_order_book::Pallet::::set_market_feeder( + T::RuntimeOriginExt::root(), + Feeder(origin.into_caller()), + ) + .unwrap() + } + + pub fn feed_from_root(key: OracleKey, value: Ratio) { + pallet_oracle_feed::Pallet::::feed(RawOrigin::Root.into(), key, value).unwrap(); + } + + pub fn update_feeders( + admin: AccountId, + pool_id: PoolId, + feeders: impl IntoIterator>, + ) { + pallet_oracle_collection::Pallet::::propose_update_collection_info( + RawOrigin::Signed(admin.clone()).into(), + pool_id, + CollectionInfo { + feeders: pallet_oracle_collection::util::feeders_from(feeders).unwrap(), + ..Default::default() + }, + ) + .unwrap(); + + let change_id = last_change_id::(); + + pallet_oracle_collection::Pallet::::apply_update_collection_info( + RawOrigin::Signed(admin).into(), //or any account + pool_id, + change_id, + ) + .unwrap(); + } + + pub fn update_collection(any: AccountId, pool_id: PoolId) { + pallet_oracle_collection::Pallet::::update_collection( + RawOrigin::Signed(any).into(), + pool_id, + ) + .unwrap(); + } +} diff --git a/runtime/integration-tests/src/generic/utils/pool.rs b/runtime/integration-tests/src/utils/pool.rs similarity index 98% rename from runtime/integration-tests/src/generic/utils/pool.rs rename to runtime/integration-tests/src/utils/pool.rs index f22f10fe8d..ffa4fca521 100644 --- a/runtime/integration-tests/src/generic/utils/pool.rs +++ b/runtime/integration-tests/src/utils/pool.rs @@ -25,7 +25,7 @@ use sp_runtime::{ FixedPointNumber, FixedPointOperand, Perquintill, }; -use crate::generic::config::{Runtime, RuntimeKind}; +use crate::config::{Runtime, RuntimeKind}; pub const POOL_MIN_EPOCH_TIME: Seconds = 24; diff --git a/runtime/integration-tests/src/generic/utils/tokens.rs b/runtime/integration-tests/src/utils/tokens.rs similarity index 95% rename from runtime/integration-tests/src/generic/utils/tokens.rs rename to runtime/integration-tests/src/utils/tokens.rs index 8ea7ab93d2..5f10b5b955 100644 --- a/runtime/integration-tests/src/generic/utils/tokens.rs +++ b/runtime/integration-tests/src/utils/tokens.rs @@ -15,7 +15,7 @@ use cfg_primitives::Balance; use cfg_types::tokens::CurrencyId; use frame_support::traits::{fungible::Mutate as _, fungibles::Mutate as _}; -use crate::{generic::config::Runtime, utils::accounts::default_accounts}; +use crate::{config::Runtime, utils::accounts::default_accounts}; pub fn evm_balances(balance: Balance) { let mut accounts = Vec::new(); diff --git a/runtime/integration-tests/src/generic/utils/xcm.rs b/runtime/integration-tests/src/utils/xcm.rs similarity index 99% rename from runtime/integration-tests/src/generic/utils/xcm.rs rename to runtime/integration-tests/src/utils/xcm.rs index 0380bf0ddf..615c283109 100644 --- a/runtime/integration-tests/src/generic/utils/xcm.rs +++ b/runtime/integration-tests/src/utils/xcm.rs @@ -10,7 +10,7 @@ use staging_xcm::{ VersionedLocation, }; -use crate::generic::{ +use crate::{ config::Runtime, env::{Blocks, Env}, envs::fudge_env::{