Skip to content

Commit

Permalink
clear previous testing framework
Browse files Browse the repository at this point in the history
  • Loading branch information
lemunozm committed Apr 16, 2024
1 parent 0bd5bfe commit d478366
Show file tree
Hide file tree
Showing 23 changed files with 51 additions and 2,534 deletions.
2 changes: 1 addition & 1 deletion ci/run-check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ case $TARGET in
;;

test-integration)
cargo test --release --package runtime-integration-tests --features fast-runtime
cargo test --release --package runtime-integration-tests
;;

lint-fmt)
Expand Down
4 changes: 2 additions & 2 deletions runtime/integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ pallet-xcm-transactor = { workspace = true, features = ["std"] }
parachain-info = { workspace = true, features = ["std"] }

[features]
# There is no need for integration test to add new features.
# Just add the required ones to default:
default = [
"development-runtime/instant-voting",
]

fast-runtime = ["development-runtime/fast-runtime"]
39 changes: 20 additions & 19 deletions runtime/integration-tests/src/generic/cases/block_rewards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,10 @@ use crate::{
utils::accounts::Keyring,
};

const STAKER: Keyring = Keyring::Alice;
const DEFAULT_COLLATORS: [Keyring; 6] = [
Keyring::Alice,
Keyring::Bob,
Keyring::Charlie,
Keyring::Dave,
Keyring::Eve,
Keyring::Ferdie,
];

crate::test_for_runtimes!(all, block_rewards_api);
fn block_rewards_api<T: Runtime>() {
const STAKER: Keyring = Keyring::Alice;

RuntimeEnv::<T>::default().parachain_state_mut(|| {
let group_id = 1u32;
let amount = 100 * CFG;
Expand Down Expand Up @@ -130,26 +122,35 @@ fn apply_and_check_session<T: Runtime>(

pallet_session::Pallet::<T>::rotate_session();

/* TODO: pending to fix. Why try_into() fails getting the reward_event?
/* TODO: pending to fix. Why try_into() fails getting the reward_event::GroupRewarded?
// The event exists in this list:
dbg!(frame_system::Pallet::<T>::events())
// But not in in this list (that is the implementation of find_event()),
// so try_into returns an Err for it.
dbg!(frame_system::Pallet::<T>::events()
.into_iter()
.rev()
.find_map(|record| record.event.try_into().ok())
.flatten());
utils::find_event::<T, _, _>(|e| match e {
pallet_rewards::Event::<_, BlockRewards>::GroupRewarded { .. } => Some(true),
_ => None,
})
.unwrap();
// But this works:
// But later, if manually I create the event as follows:
let e = T::RuntimeEventExt::from(pallet_rewards::Event::<T, BlockRewards>::GroupRewarded {
group_id: 1,
amount: 2,
});
// And I call try_into(), it works.
let re: pallet_rewards::Event<T, BlockRewards> = e.try_into().ok().unwrap();
dbg!(re);
*/

/* // Uncomment once fix the above issue
utils::find_event::<T, _, _>(|e| match e {
pallet_rewards::Event::<_, BlockRewards>::GroupRewarded { .. } => Some(true),
_ => None,
})
.unwrap();
*/

utils::find_event::<T, _, _>(|e| match e {
Expand Down
22 changes: 13 additions & 9 deletions runtime/integration-tests/src/generic/cases/liquidity_pools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,17 @@ use crate::{
genesis::Genesis,
},
},
utils::{accounts::Keyring, AUSD_CURRENCY_ID, AUSD_ED, USDT_CURRENCY_ID, USDT_ED},
utils::accounts::Keyring,
};

/// The AUSD asset id
pub const AUSD_CURRENCY_ID: CurrencyId = CurrencyId::ForeignAsset(3);
/// The USDT asset id
pub const USDT_CURRENCY_ID: CurrencyId = CurrencyId::ForeignAsset(1);

pub const AUSD_ED: Balance = 1_000_000_000;
pub const USDT_ED: Balance = 10_000;

pub mod utils {
use super::*;

Expand Down Expand Up @@ -280,7 +288,7 @@ mod development {
pub const DEFAULT_DOMAIN_ADDRESS_MOONBEAM: DomainAddress =
DomainAddress::EVM(MOONBEAM_EVM_CHAIN_ID, DEFAULT_EVM_ADDRESS_MOONBEAM);
pub const DEFAULT_OTHER_DOMAIN_ADDRESS: DomainAddress =
DomainAddress::EVM(crate::utils::MOONBEAM_EVM_CHAIN_ID, [0; 20]);
DomainAddress::EVM(MOONBEAM_EVM_CHAIN_ID, [0; 20]);

pub type LiquidityPoolMessage = Message<Domain, PoolId, TrancheId, Balance, Quantity>;

Expand Down Expand Up @@ -1002,7 +1010,7 @@ mod development {

// Finally, verify we can call pallet_liquidity_pools::Pallet::<T>::add_tranche
// successfully when given a valid pool + tranche id pair.
let new_member = DomainAddress::EVM(crate::utils::MOONBEAM_EVM_CHAIN_ID, [3; 20]);
let new_member = DomainAddress::EVM(MOONBEAM_EVM_CHAIN_ID, [3; 20]);

// Make ALICE the MembersListAdmin of this Pool
assert_ok!(pallet_permissions::Pallet::<T>::add(
Expand Down Expand Up @@ -4952,7 +4960,7 @@ mod development {
interior: X1(Parachain(T::FudgeHandle::SIBLING_ID)),
}
.into(),
crate::utils::GLMR_CURRENCY_ID,
GLMR_CURRENCY_ID,
);

assert_ok!(
Expand Down Expand Up @@ -6810,11 +6818,6 @@ mod centrifuge {
);
}

#[test]
fn _test() {
restrict_cfg_extrinsic::<crate::chain::centrifuge::Runtime>()
}

fn restrict_cfg_extrinsic<T: Runtime>() {
let mut env = RuntimeEnv::<T>::from_parachain_storage(
Genesis::default()
Expand Down Expand Up @@ -7562,6 +7565,7 @@ mod centrifuge {
crate::test_for_runtimes!([centrifuge], restrict_usdc_xcm_transfer);
crate::test_for_runtimes!([centrifuge], restrict_dot_transfer);
crate::test_for_runtimes!([centrifuge], restrict_dot_xcm_transfer);
crate::test_for_runtimes!([centrifuge], restrict_cfg_extrinsic);
crate::test_for_runtimes!([centrifuge], restrict_all);
}

Expand Down
6 changes: 5 additions & 1 deletion runtime/integration-tests/src/generic/cases/loans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use crate::{
POOL_MIN_EPOCH_TIME,
},
},
utils::{accounts::Keyring, tokens::rate_from_percent},
utils::accounts::Keyring,
};

const POOL_ADMIN: Keyring = Keyring::Admin;
Expand Down Expand Up @@ -171,6 +171,10 @@ mod common {
pub fn price_to_usd6(price: Quantity) -> Balance {
currency::price_to_currency(price, Usd6)
}

pub fn rate_from_percent(perc: u64) -> Rate {
Rate::saturating_from_rational(perc, 100)
}
}

/// Predefined loan calls for use cases
Expand Down
1 change: 0 additions & 1 deletion runtime/integration-tests/src/generic/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ pub mod utils {

mod tests {
use super::*;
struct MockEnv;

const SLOT_DURATION: Seconds = 12;
const EMPTY: [BlockNumber; 0] = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ use sp_runtime::{traits::AccountIdLookup, BuildStorage, Storage};
use sp_transaction_pool::runtime_api::TaggedTransactionQueue;
use tokio::runtime::Handle;

use crate::{generic::config::Runtime, utils::time::START_DATE};
use crate::generic::config::Runtime;

/// Start date used for timestamps in test-enviornments
/// Sat Jan 01 2022 00:00:00 GMT+0000
pub const START_DATE: u64 = 1640995200u64;

type InherentCreator<Block, InherentParachain, InherentDataProvider> = Box<
dyn CreateInherentDataProviders<
Expand Down
3 changes: 0 additions & 3 deletions runtime/integration-tests/src/generic/envs/runtime_env.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::{cell::RefCell, marker::PhantomData, mem, rc::Rc};

use cfg_primitives::{AuraId, Balance, BlockNumber, Header};
use cfg_types::ParaId;
use cumulus_primitives_core::PersistedValidationData;
use cumulus_primitives_parachain_inherent::ParachainInherentData;
use cumulus_test_relay_sproof_builder::RelayStateSproofBuilder;
Expand Down Expand Up @@ -37,7 +36,6 @@ pub struct RuntimeEnv<T: Runtime> {
parachain_ext: Rc<RefCell<sp_io::TestExternalities>>,
sibling_ext: Rc<RefCell<sp_io::TestExternalities>>,
pending_extrinsics: Vec<(Keyring, T::RuntimeCallExt)>,
pending_xcm: Vec<(ParaId, Vec<u8>)>,
_config: PhantomData<T>,
}

Expand All @@ -61,7 +59,6 @@ impl<T: Runtime> Env<T> for RuntimeEnv<T> {
parachain_ext: Self::build_externality(parachain_storage),
sibling_ext: Self::build_externality(sibling_storage),
pending_extrinsics: Vec::default(),
pending_xcm: Vec::default(),
_config: PhantomData,
}
}
Expand Down
5 changes: 0 additions & 5 deletions runtime/integration-tests/src/generic/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
// For generic modules we can reactive the unused warn disabled on lib.rs
#![warn(unused)]
// Allow dead code for utilities not used yet
#![allow(dead_code)]

pub mod env;
pub mod envs {
pub mod fudge_env;
Expand Down
25 changes: 4 additions & 21 deletions runtime/integration-tests/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(stmt_expr_attributes)]
// Copyright 2021 Centrifuge GmbH (centrifuge.io).
// This file is part of Centrifuge chain project.

Expand All @@ -11,27 +10,11 @@
// 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.

// Allow dead code for utilities not used yet
#![allow(dead_code)]
// All code in this crate is test related
#![cfg(test)]
#![allow(unused)]

mod generic;
mod rewards;
mod utils;

/// Re-exports the correct runtimes that we run the integration tests with
/// This allows all other modules to use the import of `crate::chain::{...}`
/// in order to get the right stuff from the respective runtime.
mod chain {
pub mod centrifuge {
pub use development::*;

pub mod development {
pub use development_runtime::*;
pub const PARA_ID: u32 = 2000;
}
}

pub mod relay {
pub use rococo_runtime::*;
}
}
81 changes: 0 additions & 81 deletions runtime/integration-tests/src/rewards/block/env.rs

This file was deleted.

Loading

0 comments on commit d478366

Please sign in to comment.