diff --git a/runtime/integration-tests/src/generic/cases/liquidity_pools.rs b/runtime/integration-tests/src/generic/cases/liquidity_pools.rs index 31022ab729..22ca3c7a13 100644 --- a/runtime/integration-tests/src/generic/cases/liquidity_pools.rs +++ b/runtime/integration-tests/src/generic/cases/liquidity_pools.rs @@ -3871,7 +3871,7 @@ mod foreign_investments { mod transfers { use super::*; - // TODO: Must be moved to lp/transfers.rs (?) + // TODO: Must be moved to lp/transfers.rs (?) or to UT? It seems more an UT. #[test_runtimes([development])] fn transfer_non_tranche_tokens_from_local() { diff --git a/runtime/integration-tests/src/generic/cases/proxy.rs b/runtime/integration-tests/src/generic/cases/proxy.rs index 8fa276a305..a1ce753c5e 100644 --- a/runtime/integration-tests/src/generic/cases/proxy.rs +++ b/runtime/integration-tests/src/generic/cases/proxy.rs @@ -1,4 +1,3 @@ -use cfg_primitives::Balance; use cfg_types::tokens::{AssetMetadata, CurrencyId}; use frame_support::{assert_err, assert_ok}; use frame_system::RawOrigin; @@ -9,14 +8,11 @@ use crate::{ generic::{ config::Runtime, env::Env, - envs::{ - fudge_env::{handle::FudgeHandle, FudgeEnv, FudgeSupport}, - runtime_env::RuntimeEnv, - }, + envs::runtime_env::RuntimeEnv, utils::{ - currency::{cfg, usd6, CurrencyInfo, CustomCurrency, Usd6}, + currency::{cfg, CurrencyInfo, CustomCurrency}, genesis::{self, Genesis}, - xcm::{account_location, enable_para_to_sibling_communication, transferable_metadata}, + xcm::{account_location, transferable_metadata}, }, }, utils::accounts::Keyring, @@ -26,87 +22,73 @@ const FROM: Keyring = Keyring::Charlie; const PROXY: Keyring = Keyring::Alice; const TO: Keyring = Keyring::Bob; -const FOR_FEES: Balance = cfg(1); -const TRANSFER_AMOUNT: Balance = usd6(100); -const INITIAL: Balance = usd6(1000) + TRANSFER_AMOUNT; - -fn configure_proxy_and_transfer(proxy_type: T::ProxyType) -> DispatchResult { - let env = RuntimeEnv::::from_parachain_storage( - Genesis::default() - .add(genesis::balances::(FOR_FEES)) - .add(genesis::tokens::(vec![(Usd6.id(), INITIAL)])) - .storage(), - ); - - let call = pallet_restricted_tokens::Call::transfer { - currency_id: Usd6.id(), - amount: TRANSFER_AMOUNT, - dest: T::Lookup::unlookup(TO.id()), - } - .into(); - - configure_proxy_and_call::(env, proxy_type, call) +enum TransferKind { + Local, + Xcm, } -fn configure_proxy_and_x_transfer( - proxy_type: T::ProxyType, -) -> DispatchResult { +fn run_test(proxy_type: T::ProxyType, transfer_kind: TransferKind) -> DispatchResult { + let para_id = 1234; let curr = CustomCurrency( CurrencyId::ForeignAsset(1), AssetMetadata { decimals: 6, - ..transferable_metadata(Some(T::FudgeHandle::PARA_ID)) + ..transferable_metadata(Some(para_id)) }, ); - let mut env = FudgeEnv::::from_parachain_storage( + let mut env = RuntimeEnv::::from_parachain_storage( Genesis::default() - .add(genesis::balances::(FOR_FEES)) - .add(genesis::tokens::(vec![(curr.id(), INITIAL)])) + .add(genesis::balances::(cfg(1))) // For fees + .add(genesis::tokens::(vec![(curr.id(), curr.val(1000))])) .add(genesis::assets::(vec![(curr.id(), curr.metadata())])) .storage(), ); - enable_para_to_sibling_communication::(&mut env); - - let call = pallet_restricted_xtokens::Call::transfer { - currency_id: curr.id(), - amount: TRANSFER_AMOUNT, - dest: account_location(1, Some(T::FudgeHandle::SIBLING_ID), TO.id()), - dest_weight_limit: WeightLimit::Unlimited, - } - .into(); - - configure_proxy_and_call::(env, proxy_type, call) -} + let call = match transfer_kind { + TransferKind::Local => pallet_restricted_tokens::Call::transfer { + currency_id: curr.id(), + amount: curr.val(100), + dest: T::Lookup::unlookup(TO.id()), + } + .into(), + TransferKind::Xcm => pallet_restricted_xtokens::Call::transfer { + currency_id: curr.id(), + amount: curr.val(100), + dest: account_location(1, Some(para_id), TO.id()), + dest_weight_limit: WeightLimit::Unlimited, + } + .into(), + }; -fn configure_proxy_and_call( - mut env: impl Env, - proxy_type: T::ProxyType, - call: T::RuntimeCallExt, -) -> DispatchResult { env.parachain_state_mut(|| { // Register PROXY as proxy of FROM - pallet_proxy::Pallet::::add_proxy( + assert_ok!(pallet_proxy::Pallet::::add_proxy( RawOrigin::Signed(FROM.id()).into(), T::Lookup::unlookup(PROXY.id()), proxy_type, 0, - ) - .unwrap(); + )); // Acts as FROM using PROXY - pallet_proxy::Pallet::::proxy( + assert_ok!(pallet_proxy::Pallet::::proxy( RawOrigin::Signed(PROXY.id()).into(), T::Lookup::unlookup(FROM.id()), None, Box::new(call), - ) - .unwrap(); + )); }); env.find_event(|e| match e { - pallet_proxy::Event::::ProxyExecuted { result } => Some(result), + pallet_proxy::Event::::ProxyExecuted { result } => { + if result == Err(orml_xtokens::Error::::XcmExecutionFailed.into()) { + // We have not configured XCM, so if we reach the sending phase though xcm we + // can assert that proxy was filtered correctly. + Some(Ok(())) + } else { + Some(result) + } + } _ => None, }) .unwrap() @@ -117,8 +99,9 @@ fn development_transfer_with_proxy_transfer() where T: pallet_proxy::Config, { - assert_ok!(configure_proxy_and_transfer::( - development_runtime::ProxyType::Transfer + assert_ok!(run_test::( + development_runtime::ProxyType::Transfer, + TransferKind::Local )); } @@ -128,7 +111,7 @@ where T: pallet_proxy::Config, { assert_err!( - configure_proxy_and_transfer::(development_runtime::ProxyType::Borrow), + run_test::(development_runtime::ProxyType::Borrow, TransferKind::Local), frame_system::Error::::CallFiltered, ); } @@ -139,39 +122,40 @@ where T: pallet_proxy::Config, { assert_err!( - configure_proxy_and_transfer::(development_runtime::ProxyType::Invest), + run_test::(development_runtime::ProxyType::Invest, TransferKind::Local), frame_system::Error::::CallFiltered, ); } #[test_runtimes([development])] -fn development_x_transfer_with_proxy_transfer() +fn development_x_transfer_with_proxy_transfer() where T: pallet_proxy::Config, { - assert_ok!(configure_proxy_and_x_transfer::( - development_runtime::ProxyType::Transfer + assert_ok!(run_test::( + development_runtime::ProxyType::Transfer, + TransferKind::Xcm )); } #[test_runtimes([development])] -fn development_x_transfer_with_proxy_borrow() +fn development_x_transfer_with_proxy_borrow() where T: pallet_proxy::Config, { assert_err!( - configure_proxy_and_x_transfer::(development_runtime::ProxyType::Borrow), + run_test::(development_runtime::ProxyType::Borrow, TransferKind::Xcm), frame_system::Error::::CallFiltered, ); } #[test_runtimes([development])] -fn development_x_transfer_with_proxy_invest() +fn development_x_transfer_with_proxy_invest() where T: pallet_proxy::Config, { assert_err!( - configure_proxy_and_x_transfer::(development_runtime::ProxyType::Invest), + run_test::(development_runtime::ProxyType::Invest, TransferKind::Xcm), frame_system::Error::::CallFiltered, ); } @@ -181,8 +165,9 @@ fn altair_transfer_with_proxy_transfer() where T: pallet_proxy::Config, { - assert_ok!(configure_proxy_and_transfer::( - altair_runtime::ProxyType::Transfer + assert_ok!(run_test::( + altair_runtime::ProxyType::Transfer, + TransferKind::Local )); } @@ -192,7 +177,7 @@ where T: pallet_proxy::Config, { assert_err!( - configure_proxy_and_transfer::(altair_runtime::ProxyType::Borrow), + run_test::(altair_runtime::ProxyType::Borrow, TransferKind::Local), frame_system::Error::::CallFiltered, ); } @@ -203,39 +188,40 @@ where T: pallet_proxy::Config, { assert_err!( - configure_proxy_and_transfer::(altair_runtime::ProxyType::Invest), + run_test::(altair_runtime::ProxyType::Invest, TransferKind::Local), frame_system::Error::::CallFiltered, ); } #[test_runtimes([altair])] -fn altair_x_transfer_with_proxy_transfer() +fn altair_x_transfer_with_proxy_transfer() where T: pallet_proxy::Config, { - assert_ok!(configure_proxy_and_x_transfer::( - altair_runtime::ProxyType::Transfer + assert_ok!(run_test::( + altair_runtime::ProxyType::Transfer, + TransferKind::Xcm )); } #[test_runtimes([altair])] -fn altair_x_transfer_with_proxy_borrow() +fn altair_x_transfer_with_proxy_borrow() where T: pallet_proxy::Config, { assert_err!( - configure_proxy_and_x_transfer::(altair_runtime::ProxyType::Borrow), + run_test::(altair_runtime::ProxyType::Borrow, TransferKind::Xcm), frame_system::Error::::CallFiltered, ); } #[test_runtimes([altair])] -fn altair_x_transfer_with_proxy_invest() +fn altair_x_transfer_with_proxy_invest() where T: pallet_proxy::Config, { assert_err!( - configure_proxy_and_x_transfer::(altair_runtime::ProxyType::Invest), + run_test::(altair_runtime::ProxyType::Invest, TransferKind::Xcm), frame_system::Error::::CallFiltered, ); } @@ -245,8 +231,9 @@ fn centrifuge_transfer_with_proxy_transfer() where T: pallet_proxy::Config, { - assert_ok!(configure_proxy_and_transfer::( - centrifuge_runtime::ProxyType::Transfer + assert_ok!(run_test::( + centrifuge_runtime::ProxyType::Transfer, + TransferKind::Local )); } @@ -256,7 +243,7 @@ where T: pallet_proxy::Config, { assert_err!( - configure_proxy_and_transfer::(centrifuge_runtime::ProxyType::Borrow), + run_test::(centrifuge_runtime::ProxyType::Borrow, TransferKind::Local), frame_system::Error::::CallFiltered, ); } @@ -267,39 +254,40 @@ where T: pallet_proxy::Config, { assert_err!( - configure_proxy_and_transfer::(centrifuge_runtime::ProxyType::Invest), + run_test::(centrifuge_runtime::ProxyType::Invest, TransferKind::Local), frame_system::Error::::CallFiltered, ); } #[test_runtimes([centrifuge])] -fn centrifuge_x_transfer_with_proxy_transfer() +fn centrifuge_x_transfer_with_proxy_transfer() where T: pallet_proxy::Config, { - assert_ok!(configure_proxy_and_x_transfer::( - centrifuge_runtime::ProxyType::Transfer + assert_ok!(run_test::( + centrifuge_runtime::ProxyType::Transfer, + TransferKind::Xcm )); } #[test_runtimes([centrifuge])] -fn centrifuge_x_transfer_with_proxy_borrow() +fn centrifuge_x_transfer_with_proxy_borrow() where T: pallet_proxy::Config, { assert_err!( - configure_proxy_and_x_transfer::(centrifuge_runtime::ProxyType::Borrow), + run_test::(centrifuge_runtime::ProxyType::Borrow, TransferKind::Xcm), frame_system::Error::::CallFiltered, ); } #[test_runtimes([centrifuge])] -fn centrifuge_x_transfer_with_proxy_invest() +fn centrifuge_x_transfer_with_proxy_invest() where T: pallet_proxy::Config, { assert_err!( - configure_proxy_and_x_transfer::(centrifuge_runtime::ProxyType::Invest), + run_test::(centrifuge_runtime::ProxyType::Invest, TransferKind::Xcm), frame_system::Error::::CallFiltered, ); }