Skip to content

Commit

Permalink
remove fudge from proxy tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lemunozm committed Jun 17, 2024
1 parent 5a832ad commit de3760a
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: Runtime + FudgeSupport>() {
Expand Down
170 changes: 79 additions & 91 deletions runtime/integration-tests/src/generic/cases/proxy.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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,
Expand All @@ -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<T: Runtime>(proxy_type: T::ProxyType) -> DispatchResult {
let env = RuntimeEnv::<T>::from_parachain_storage(
Genesis::default()
.add(genesis::balances::<T>(FOR_FEES))
.add(genesis::tokens::<T>(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::<T>(env, proxy_type, call)
enum TransferKind {
Local,
Xcm,
}

fn configure_proxy_and_x_transfer<T: Runtime + FudgeSupport>(
proxy_type: T::ProxyType,
) -> DispatchResult {
fn run_test<T: Runtime>(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::<T>::from_parachain_storage(
let mut env = RuntimeEnv::<T>::from_parachain_storage(
Genesis::default()
.add(genesis::balances::<T>(FOR_FEES))
.add(genesis::tokens::<T>(vec![(curr.id(), INITIAL)]))
.add(genesis::balances::<T>(cfg(1))) // For fees
.add(genesis::tokens::<T>(vec![(curr.id(), curr.val(1000))]))
.add(genesis::assets::<T>(vec![(curr.id(), curr.metadata())]))
.storage(),
);

enable_para_to_sibling_communication::<T>(&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::<T>(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<T: Runtime>(
mut env: impl Env<T>,
proxy_type: T::ProxyType,
call: T::RuntimeCallExt,
) -> DispatchResult {
env.parachain_state_mut(|| {
// Register PROXY as proxy of FROM
pallet_proxy::Pallet::<T>::add_proxy(
assert_ok!(pallet_proxy::Pallet::<T>::add_proxy(
RawOrigin::Signed(FROM.id()).into(),
T::Lookup::unlookup(PROXY.id()),
proxy_type,
0,
)
.unwrap();
));

// Acts as FROM using PROXY
pallet_proxy::Pallet::<T>::proxy(
assert_ok!(pallet_proxy::Pallet::<T>::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::<T>::ProxyExecuted { result } => Some(result),
pallet_proxy::Event::<T>::ProxyExecuted { result } => {
if result == Err(orml_xtokens::Error::<T>::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()
Expand All @@ -117,8 +99,9 @@ fn development_transfer_with_proxy_transfer<T: Runtime>()
where
T: pallet_proxy::Config<ProxyType = development_runtime::ProxyType>,
{
assert_ok!(configure_proxy_and_transfer::<T>(
development_runtime::ProxyType::Transfer
assert_ok!(run_test::<T>(
development_runtime::ProxyType::Transfer,
TransferKind::Local
));
}

Expand All @@ -128,7 +111,7 @@ where
T: pallet_proxy::Config<ProxyType = development_runtime::ProxyType>,
{
assert_err!(
configure_proxy_and_transfer::<T>(development_runtime::ProxyType::Borrow),
run_test::<T>(development_runtime::ProxyType::Borrow, TransferKind::Local),
frame_system::Error::<T>::CallFiltered,
);
}
Expand All @@ -139,39 +122,40 @@ where
T: pallet_proxy::Config<ProxyType = development_runtime::ProxyType>,
{
assert_err!(
configure_proxy_and_transfer::<T>(development_runtime::ProxyType::Invest),
run_test::<T>(development_runtime::ProxyType::Invest, TransferKind::Local),
frame_system::Error::<T>::CallFiltered,
);
}

#[test_runtimes([development])]
fn development_x_transfer_with_proxy_transfer<T: Runtime + FudgeSupport>()
fn development_x_transfer_with_proxy_transfer<T: Runtime>()
where
T: pallet_proxy::Config<ProxyType = development_runtime::ProxyType>,
{
assert_ok!(configure_proxy_and_x_transfer::<T>(
development_runtime::ProxyType::Transfer
assert_ok!(run_test::<T>(
development_runtime::ProxyType::Transfer,
TransferKind::Xcm
));
}

#[test_runtimes([development])]
fn development_x_transfer_with_proxy_borrow<T: Runtime + FudgeSupport>()
fn development_x_transfer_with_proxy_borrow<T: Runtime>()
where
T: pallet_proxy::Config<ProxyType = development_runtime::ProxyType>,
{
assert_err!(
configure_proxy_and_x_transfer::<T>(development_runtime::ProxyType::Borrow),
run_test::<T>(development_runtime::ProxyType::Borrow, TransferKind::Xcm),
frame_system::Error::<T>::CallFiltered,
);
}

#[test_runtimes([development])]
fn development_x_transfer_with_proxy_invest<T: Runtime + FudgeSupport>()
fn development_x_transfer_with_proxy_invest<T: Runtime>()
where
T: pallet_proxy::Config<ProxyType = development_runtime::ProxyType>,
{
assert_err!(
configure_proxy_and_x_transfer::<T>(development_runtime::ProxyType::Invest),
run_test::<T>(development_runtime::ProxyType::Invest, TransferKind::Xcm),
frame_system::Error::<T>::CallFiltered,
);
}
Expand All @@ -181,8 +165,9 @@ fn altair_transfer_with_proxy_transfer<T: Runtime>()
where
T: pallet_proxy::Config<ProxyType = altair_runtime::ProxyType>,
{
assert_ok!(configure_proxy_and_transfer::<T>(
altair_runtime::ProxyType::Transfer
assert_ok!(run_test::<T>(
altair_runtime::ProxyType::Transfer,
TransferKind::Local
));
}

Expand All @@ -192,7 +177,7 @@ where
T: pallet_proxy::Config<ProxyType = altair_runtime::ProxyType>,
{
assert_err!(
configure_proxy_and_transfer::<T>(altair_runtime::ProxyType::Borrow),
run_test::<T>(altair_runtime::ProxyType::Borrow, TransferKind::Local),
frame_system::Error::<T>::CallFiltered,
);
}
Expand All @@ -203,39 +188,40 @@ where
T: pallet_proxy::Config<ProxyType = altair_runtime::ProxyType>,
{
assert_err!(
configure_proxy_and_transfer::<T>(altair_runtime::ProxyType::Invest),
run_test::<T>(altair_runtime::ProxyType::Invest, TransferKind::Local),
frame_system::Error::<T>::CallFiltered,
);
}

#[test_runtimes([altair])]
fn altair_x_transfer_with_proxy_transfer<T: Runtime + FudgeSupport>()
fn altair_x_transfer_with_proxy_transfer<T: Runtime>()
where
T: pallet_proxy::Config<ProxyType = altair_runtime::ProxyType>,
{
assert_ok!(configure_proxy_and_x_transfer::<T>(
altair_runtime::ProxyType::Transfer
assert_ok!(run_test::<T>(
altair_runtime::ProxyType::Transfer,
TransferKind::Xcm
));
}

#[test_runtimes([altair])]
fn altair_x_transfer_with_proxy_borrow<T: Runtime + FudgeSupport>()
fn altair_x_transfer_with_proxy_borrow<T: Runtime>()
where
T: pallet_proxy::Config<ProxyType = altair_runtime::ProxyType>,
{
assert_err!(
configure_proxy_and_x_transfer::<T>(altair_runtime::ProxyType::Borrow),
run_test::<T>(altair_runtime::ProxyType::Borrow, TransferKind::Xcm),
frame_system::Error::<T>::CallFiltered,
);
}

#[test_runtimes([altair])]
fn altair_x_transfer_with_proxy_invest<T: Runtime + FudgeSupport>()
fn altair_x_transfer_with_proxy_invest<T: Runtime>()
where
T: pallet_proxy::Config<ProxyType = altair_runtime::ProxyType>,
{
assert_err!(
configure_proxy_and_x_transfer::<T>(altair_runtime::ProxyType::Invest),
run_test::<T>(altair_runtime::ProxyType::Invest, TransferKind::Xcm),
frame_system::Error::<T>::CallFiltered,
);
}
Expand All @@ -245,8 +231,9 @@ fn centrifuge_transfer_with_proxy_transfer<T: Runtime>()
where
T: pallet_proxy::Config<ProxyType = centrifuge_runtime::ProxyType>,
{
assert_ok!(configure_proxy_and_transfer::<T>(
centrifuge_runtime::ProxyType::Transfer
assert_ok!(run_test::<T>(
centrifuge_runtime::ProxyType::Transfer,
TransferKind::Local
));
}

Expand All @@ -256,7 +243,7 @@ where
T: pallet_proxy::Config<ProxyType = centrifuge_runtime::ProxyType>,
{
assert_err!(
configure_proxy_and_transfer::<T>(centrifuge_runtime::ProxyType::Borrow),
run_test::<T>(centrifuge_runtime::ProxyType::Borrow, TransferKind::Local),
frame_system::Error::<T>::CallFiltered,
);
}
Expand All @@ -267,39 +254,40 @@ where
T: pallet_proxy::Config<ProxyType = centrifuge_runtime::ProxyType>,
{
assert_err!(
configure_proxy_and_transfer::<T>(centrifuge_runtime::ProxyType::Invest),
run_test::<T>(centrifuge_runtime::ProxyType::Invest, TransferKind::Local),
frame_system::Error::<T>::CallFiltered,
);
}

#[test_runtimes([centrifuge])]
fn centrifuge_x_transfer_with_proxy_transfer<T: Runtime + FudgeSupport>()
fn centrifuge_x_transfer_with_proxy_transfer<T: Runtime>()
where
T: pallet_proxy::Config<ProxyType = centrifuge_runtime::ProxyType>,
{
assert_ok!(configure_proxy_and_x_transfer::<T>(
centrifuge_runtime::ProxyType::Transfer
assert_ok!(run_test::<T>(
centrifuge_runtime::ProxyType::Transfer,
TransferKind::Xcm
));
}

#[test_runtimes([centrifuge])]
fn centrifuge_x_transfer_with_proxy_borrow<T: Runtime + FudgeSupport>()
fn centrifuge_x_transfer_with_proxy_borrow<T: Runtime>()
where
T: pallet_proxy::Config<ProxyType = centrifuge_runtime::ProxyType>,
{
assert_err!(
configure_proxy_and_x_transfer::<T>(centrifuge_runtime::ProxyType::Borrow),
run_test::<T>(centrifuge_runtime::ProxyType::Borrow, TransferKind::Xcm),
frame_system::Error::<T>::CallFiltered,
);
}

#[test_runtimes([centrifuge])]
fn centrifuge_x_transfer_with_proxy_invest<T: Runtime + FudgeSupport>()
fn centrifuge_x_transfer_with_proxy_invest<T: Runtime>()
where
T: pallet_proxy::Config<ProxyType = centrifuge_runtime::ProxyType>,
{
assert_err!(
configure_proxy_and_x_transfer::<T>(centrifuge_runtime::ProxyType::Invest),
run_test::<T>(centrifuge_runtime::ProxyType::Invest, TransferKind::Xcm),
frame_system::Error::<T>::CallFiltered,
);
}

0 comments on commit de3760a

Please sign in to comment.