Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/github_actions/actions/upload-art…
Browse files Browse the repository at this point in the history
…ifact-4.0.0
  • Loading branch information
wischli authored Jan 2, 2024
2 parents 2825839 + 53c920c commit 467c1ce
Show file tree
Hide file tree
Showing 6 changed files with 365 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ use crate::{
utils::{accounts::Keyring, AUSD_CURRENCY_ID, AUSD_ED, USDT_CURRENCY_ID, USDT_ED},
};

mod utils {
pub mod utils {
use super::*;

pub fn parachain_account(id: u32) -> AccountId {
Expand Down
325 changes: 325 additions & 0 deletions runtime/integration-tests/src/generic/cases/proxy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,325 @@
use cfg_primitives::Balance;
use frame_support::{assert_err, assert_ok, traits::Get};
use frame_system::RawOrigin;
use sp_runtime::{traits::StaticLookup, DispatchResult};
use xcm::{
prelude::Parachain,
v3::{Junction, Junctions::*, MultiLocation, WeightLimit},
VersionedMultiLocation,
};

use crate::{
generic::{
cases::liquidity_pools::utils::setup_xcm,
config::Runtime,
env::Env,
envs::{
fudge_env::{handle::FudgeHandle, FudgeEnv, FudgeSupport},
runtime_env::RuntimeEnv,
},
utils::{
self,
currency::{cfg, register_currency, usd6, CurrencyInfo, Usd6},
genesis::{self, Genesis},
},
},
utils::accounts::Keyring,
};

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);

fn configure_proxy_and_transfer<T: Runtime>(proxy_type: T::ProxyType) -> DispatchResult {
let env = RuntimeEnv::<T>::from_parachain_storage(
Genesis::<T>::default()
.add(genesis::balances(T::ExistentialDeposit::get() + FOR_FEES))
.add(genesis::tokens(vec![(Usd6::ID, Usd6::ED)]))
.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)
}

fn configure_proxy_and_x_transfer<T: Runtime + FudgeSupport>(
proxy_type: T::ProxyType,
) -> DispatchResult {
let mut env = FudgeEnv::<T>::from_parachain_storage(
Genesis::default()
.add(genesis::balances::<T>(
T::ExistentialDeposit::get() + FOR_FEES,
))
.add(genesis::tokens(vec![(Usd6::ID, Usd6::ED)]))
.storage(),
);

setup_xcm(&mut env);

env.parachain_state_mut(|| {
register_currency::<T, Usd6>(Some(VersionedMultiLocation::V3(MultiLocation::new(
1,
X1(Parachain(T::FudgeHandle::SIBLING_ID)),
))));
});

let call = pallet_restricted_xtokens::Call::transfer {
currency_id: Usd6::ID,
amount: TRANSFER_AMOUNT,
dest: Box::new(
MultiLocation::new(
1,
X2(
Parachain(T::FudgeHandle::SIBLING_ID),
Junction::AccountId32 {
id: TO.into(),
network: None,
},
),
)
.into(),
),
dest_weight_limit: WeightLimit::Unlimited,
}
.into();

configure_proxy_and_call::<T>(env, proxy_type, call)
}

fn configure_proxy_and_call<T: Runtime>(
mut env: impl Env<T>,
proxy_type: T::ProxyType,
call: T::RuntimeCallExt,
) -> DispatchResult {
env.parachain_state_mut(|| {
utils::give_tokens::<T>(FROM.id(), Usd6::ID, TRANSFER_AMOUNT);

// Register PROXY as proxy of FROM
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(
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),
_ => None,
})
.unwrap()
}

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
));
}

fn development_transfer_with_proxy_borrow<T: Runtime>()
where
T: pallet_proxy::Config<ProxyType = development_runtime::ProxyType>,
{
assert_err!(
configure_proxy_and_transfer::<T>(development_runtime::ProxyType::Borrow),
frame_system::Error::<T>::CallFiltered,
);
}

fn development_transfer_with_proxy_invest<T: Runtime>()
where
T: pallet_proxy::Config<ProxyType = development_runtime::ProxyType>,
{
assert_err!(
configure_proxy_and_transfer::<T>(development_runtime::ProxyType::Invest),
frame_system::Error::<T>::CallFiltered,
);
}

fn development_x_transfer_with_proxy_transfer<T: Runtime + FudgeSupport>()
where
T: pallet_proxy::Config<ProxyType = development_runtime::ProxyType>,
{
assert_ok!(configure_proxy_and_x_transfer::<T>(
development_runtime::ProxyType::Transfer
));
}

fn development_x_transfer_with_proxy_borrow<T: Runtime + FudgeSupport>()
where
T: pallet_proxy::Config<ProxyType = development_runtime::ProxyType>,
{
assert_err!(
configure_proxy_and_x_transfer::<T>(development_runtime::ProxyType::Borrow),
frame_system::Error::<T>::CallFiltered,
);
}

fn development_x_transfer_with_proxy_invest<T: Runtime + FudgeSupport>()
where
T: pallet_proxy::Config<ProxyType = development_runtime::ProxyType>,
{
assert_err!(
configure_proxy_and_x_transfer::<T>(development_runtime::ProxyType::Invest),
frame_system::Error::<T>::CallFiltered,
);
}

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
));
}

fn altair_transfer_with_proxy_borrow<T: Runtime>()
where
T: pallet_proxy::Config<ProxyType = altair_runtime::ProxyType>,
{
assert_err!(
configure_proxy_and_transfer::<T>(altair_runtime::ProxyType::Borrow),
frame_system::Error::<T>::CallFiltered,
);
}

fn altair_transfer_with_proxy_invest<T: Runtime>()
where
T: pallet_proxy::Config<ProxyType = altair_runtime::ProxyType>,
{
assert_err!(
configure_proxy_and_transfer::<T>(altair_runtime::ProxyType::Invest),
frame_system::Error::<T>::CallFiltered,
);
}

fn altair_x_transfer_with_proxy_transfer<T: Runtime + FudgeSupport>()
where
T: pallet_proxy::Config<ProxyType = altair_runtime::ProxyType>,
{
assert_ok!(configure_proxy_and_x_transfer::<T>(
altair_runtime::ProxyType::Transfer
));
}

fn altair_x_transfer_with_proxy_borrow<T: Runtime + FudgeSupport>()
where
T: pallet_proxy::Config<ProxyType = altair_runtime::ProxyType>,
{
assert_err!(
configure_proxy_and_x_transfer::<T>(altair_runtime::ProxyType::Borrow),
frame_system::Error::<T>::CallFiltered,
);
}

fn altair_x_transfer_with_proxy_invest<T: Runtime + FudgeSupport>()
where
T: pallet_proxy::Config<ProxyType = altair_runtime::ProxyType>,
{
assert_err!(
configure_proxy_and_x_transfer::<T>(altair_runtime::ProxyType::Invest),
frame_system::Error::<T>::CallFiltered,
);
}

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
));
}

fn centrifuge_transfer_with_proxy_borrow<T: Runtime>()
where
T: pallet_proxy::Config<ProxyType = centrifuge_runtime::ProxyType>,
{
assert_err!(
configure_proxy_and_transfer::<T>(centrifuge_runtime::ProxyType::Borrow),
frame_system::Error::<T>::CallFiltered,
);
}

fn centrifuge_transfer_with_proxy_invest<T: Runtime>()
where
T: pallet_proxy::Config<ProxyType = centrifuge_runtime::ProxyType>,
{
assert_err!(
configure_proxy_and_transfer::<T>(centrifuge_runtime::ProxyType::Invest),
frame_system::Error::<T>::CallFiltered,
);
}

fn centrifuge_x_transfer_with_proxy_transfer<T: Runtime + FudgeSupport>()
where
T: pallet_proxy::Config<ProxyType = centrifuge_runtime::ProxyType>,
{
assert_ok!(configure_proxy_and_x_transfer::<T>(
centrifuge_runtime::ProxyType::Transfer
));
}

fn centrifuge_x_transfer_with_proxy_borrow<T: Runtime + FudgeSupport>()
where
T: pallet_proxy::Config<ProxyType = centrifuge_runtime::ProxyType>,
{
assert_err!(
configure_proxy_and_x_transfer::<T>(centrifuge_runtime::ProxyType::Borrow),
frame_system::Error::<T>::CallFiltered,
);
}

fn centrifuge_x_transfer_with_proxy_invest<T: Runtime + FudgeSupport>()
where
T: pallet_proxy::Config<ProxyType = centrifuge_runtime::ProxyType>,
{
assert_err!(
configure_proxy_and_x_transfer::<T>(centrifuge_runtime::ProxyType::Invest),
frame_system::Error::<T>::CallFiltered,
);
}

crate::test_for_runtimes!([development], development_transfer_with_proxy_transfer);
crate::test_for_runtimes!([development], development_transfer_with_proxy_borrow);
crate::test_for_runtimes!([development], development_transfer_with_proxy_invest);
crate::test_for_runtimes!([development], development_x_transfer_with_proxy_transfer);
crate::test_for_runtimes!([development], development_x_transfer_with_proxy_borrow);
crate::test_for_runtimes!([development], development_x_transfer_with_proxy_invest);

crate::test_for_runtimes!([altair], altair_transfer_with_proxy_transfer);
crate::test_for_runtimes!([altair], altair_transfer_with_proxy_borrow);
crate::test_for_runtimes!([altair], altair_transfer_with_proxy_invest);
crate::test_for_runtimes!([altair], altair_x_transfer_with_proxy_transfer);
crate::test_for_runtimes!([altair], altair_x_transfer_with_proxy_borrow);
crate::test_for_runtimes!([altair], altair_x_transfer_with_proxy_invest);

crate::test_for_runtimes!([centrifuge], centrifuge_transfer_with_proxy_transfer);
crate::test_for_runtimes!([centrifuge], centrifuge_transfer_with_proxy_borrow);
crate::test_for_runtimes!([centrifuge], centrifuge_transfer_with_proxy_invest);
crate::test_for_runtimes!([centrifuge], centrifuge_x_transfer_with_proxy_transfer);
crate::test_for_runtimes!([centrifuge], centrifuge_x_transfer_with_proxy_borrow);
crate::test_for_runtimes!([centrifuge], centrifuge_x_transfer_with_proxy_invest);
6 changes: 6 additions & 0 deletions runtime/integration-tests/src/generic/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ pub trait Runtime:
CollectionId = PoolId,
> + orml_xtokens::Config<CurrencyId = CurrencyId, Balance = Balance>
+ pallet_xcm::Config
+ pallet_proxy::Config<RuntimeCall = Self::RuntimeCallExt>
+ pallet_restricted_tokens::Config<Balance = Balance, CurrencyId = CurrencyId>
+ pallet_restricted_xtokens::Config
+ pallet_transfer_allowlist::Config<CurrencyId = CurrencyId, Location = Location>
Expand Down Expand Up @@ -159,7 +160,10 @@ pub trait Runtime:
+ From<cumulus_pallet_parachain_system::Call<Self>>
+ From<pallet_oracle_feed::Call<Self>>
+ From<pallet_oracle_data_collection::Call<Self>>
+ From<pallet_restricted_tokens::Call<Self>>
+ From<pallet_restricted_xtokens::Call<Self>>
+ From<pallet_preimage::Call<Self>>
+ From<pallet_proxy::Call<Self>>
+ From<pallet_collective::Call<Self, CouncilCollective>>
+ From<pallet_democracy::Call<Self>>
+ From<pallet_liquidity_pools_gateway::Call<Self>>;
Expand All @@ -177,6 +181,7 @@ pub trait Runtime:
+ TryInto<pallet_loans::Event<Self>>
+ TryInto<pallet_pool_system::Event<Self>>
+ TryInto<pallet_liquidity_pools_gateway::Event<Self>>
+ TryInto<pallet_proxy::Event<Self>>
+ From<frame_system::Event<Self>>
+ From<pallet_balances::Event<Self>>
+ From<pallet_investments::Event<Self>>
Expand All @@ -192,6 +197,7 @@ pub trait Runtime:
+ From<pallet_order_book::Event<Self>>
+ From<pallet_preimage::Event<Self>>
+ From<pallet_collective::Event<Self, CouncilCollective>>
+ From<pallet_proxy::Event<Self>>
+ From<pallet_democracy::Event<Self>>;

type RuntimeOriginExt: Into<Result<RawOrigin<Self::AccountId>, <Self as frame_system::Config>::RuntimeOrigin>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ pub trait FudgeHandle<T: Runtime> {
storage: Storage,
session_keys: <Self::RelayRuntime as pallet_session::Config>::Keys,
) -> RelaychainBuilder<Self::RelayConstructApi, Self::RelayRuntime> {
crate::utils::logs::init_logs();

sp_tracing::enter_span!(sp_tracing::Level::INFO, "Relay - StartUp");

let code = Self::RELAY_CODE.expect("ESSENTIAL: WASM is built.");
Expand Down
3 changes: 1 addition & 2 deletions runtime/integration-tests/src/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ mod cases {
mod investments;
mod liquidity_pools;
mod loans;
mod proxy;
}

/// Generate tests for the specified runtimes or all runtimes.
Expand Down Expand Up @@ -62,8 +63,6 @@ macro_rules! test_for_runtimes {
$(
#[tokio::test]
async fn $runtime_name() {
crate::utils::logs::init_logs();

$test_name::<$runtime_name::Runtime>()
}
)*
Expand Down
Loading

0 comments on commit 467c1ce

Please sign in to comment.