Skip to content

Commit

Permalink
remove generic module
Browse files Browse the repository at this point in the history
  • Loading branch information
lemunozm committed Jun 26, 2024
1 parent cbf8691 commit 90a283e
Show file tree
Hide file tree
Showing 38 changed files with 458 additions and 532 deletions.
Original file line number Diff line number Diff line change
@@ -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/<file.rs>` 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.
16 changes: 16 additions & 0 deletions runtime/integration-tests/src/cases.rs
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: Runtime>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use staging_xcm::{
VersionedLocation,
};

use crate::generic::{
use crate::{
config::Runtime,
env::Env,
envs::runtime_env::RuntimeEnv,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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])]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -458,7 +455,7 @@ mod utils {
DEFAULT_VALIDITY,
)),
) {
crate::generic::utils::pool::give_role::<T>(
crate::utils::pool::give_role::<T>(
investor.clone(),
pool_id,
PoolRole::TrancheInvestor(default_tranche_id::<T>(pool_id), DEFAULT_VALIDITY),
Expand Down Expand Up @@ -551,7 +548,7 @@ mod utils {
);

// Make investor the MembersListAdmin of this Pool
crate::generic::utils::pool::give_role::<T>(
crate::utils::pool::give_role::<T>(
investor.clone(),
pool_id,
PoolRole::TrancheInvestor(default_tranche_id::<T>(pool_id), DEFAULT_VALIDITY),
Expand Down Expand Up @@ -661,20 +658,16 @@ mod utils {
<T as frame_system::Config>::RuntimeOrigin::root(),
Feeder::root(),
));
crate::generic::utils::oracle::update_feeders::<T>(
POOL_ADMIN.id(),
POOL_ID,
[Feeder::root()],
);
crate::utils::oracle::update_feeders::<T>(POOL_ADMIN.id(), POOL_ID, [Feeder::root()]);

if enable_foreign_to_pool_pair {
crate::generic::utils::oracle::feed_from_root::<T>(
crate::utils::oracle::feed_from_root::<T>(
OracleKey::ConversionRatio(foreign_currency, pool_currency),
Ratio::one(),
);
}
if enable_pool_to_foreign_pair {
crate::generic::utils::oracle::feed_from_root::<T>(
crate::utils::oracle::feed_from_root::<T>(
OracleKey::ConversionRatio(pool_currency, foreign_currency),
Ratio::one(),
);
Expand Down Expand Up @@ -743,7 +736,7 @@ mod add_allow_upgrade {
);

// Whitelist destination as TrancheInvestor of this Pool
crate::generic::utils::pool::give_role::<T>(
crate::utils::pool::give_role::<T>(
AccountConverter::convert(new_member.clone()),
pool_id,
PoolRole::TrancheInvestor(default_tranche_id::<T>(pool_id), DEFAULT_VALIDITY),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand All @@ -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<T: Runtime>(evm: &mut impl EvmEnv<T>, name: &str) -> GeneralCurrencyIndexType {
Expand Down Expand Up @@ -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<T: Runtime>() {
Expand Down Expand Up @@ -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,
};
Expand Down
Loading

0 comments on commit 90a283e

Please sign in to comment.