Skip to content

Commit

Permalink
integration-test: Add LP eth usdc test via LP pallet
Browse files Browse the repository at this point in the history
  • Loading branch information
cdamian committed Nov 29, 2023
1 parent b081918 commit 9b5d60b
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 6 deletions.
93 changes: 90 additions & 3 deletions runtime/integration-tests/src/generic/cases/liquidity_pools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1796,14 +1796,20 @@ mod centrifuge {
}

mod restricted_transfers {
use cfg_types::locations::Location;
use frame_support::{pallet_prelude::GenesisBuild, traits::fungibles::Mutate};
use cfg_types::{
domain_address::{Domain, DomainAddress},
locations::Location,
};
use frame_support::{pallet_prelude::GenesisBuild, traits::fungibles::Mutate, BoundedVec};
use liquidity_pools_gateway_routers::{
DomainRouter, EthereumXCMRouter, XCMRouter, XcmDomain,
};
use polkadot_parachain::primitives::ValidationCode;
use polkadot_runtime_parachains::{
paras,
paras::{ParaGenesisArgs, ParaKind},
};
use sp_core::Hasher;
use sp_core::{Hasher, H160};
use sp_runtime::traits::BlakeTwo256;

use super::*;
Expand Down Expand Up @@ -1925,6 +1931,86 @@ mod centrifuge {
});
}

fn restrict_lp_eth_usdc_lp_transfer<T: Runtime + FudgeSupport>() {
let mut env = FudgeEnv::<T>::from_parachain_storage(
Genesis::default()
.add(genesis::balances::<T>(cfg(10)))
.add(orml_tokens::GenesisConfig::<T> {
balances: vec![(
Keyring::Alice.to_account_id(),
LP_ETH_USDC,
T::ExistentialDeposit::get() + lp_eth_usdc(TRANSFER_AMOUNT),
)],
})
.storage(),
);

setup_xcm(&mut env);

env.parachain_state_mut(|| {
register_usdc::<T>();
register_lp_eth_usdc::<T>();

assert_ok!(orml_tokens::Pallet::<T>::set_balance(
<T as frame_system::Config>::RuntimeOrigin::root(),
<T as pallet_liquidity_pools_gateway::Config>::Sender::get().into(),
USDC,
usdc(1_000),
0,
));

let router = DomainRouter::EthereumXCM(EthereumXCMRouter::<T> {
router: XCMRouter {
xcm_domain: XcmDomain {
location: Box::new(
MultiLocation::new(1, X1(Parachain(T::FudgeHandle::SIBLING_ID)))
.into(),
),
ethereum_xcm_transact_call_index: BoundedVec::truncate_from(vec![
38, 0,
]),
contract_address: H160::from_low_u64_be(11),
max_gas_limit: 700_000,
transact_required_weight_at_most: Default::default(),
overall_weight: Default::default(),
fee_currency: USDC,
fee_amount: usdc(1),
},
_marker: Default::default(),
},
_marker: Default::default(),
});

assert_ok!(
pallet_liquidity_pools_gateway::Pallet::<T>::set_domain_router(
<T as frame_system::Config>::RuntimeOrigin::root(),
Domain::EVM(1),
router,
)
);

let receiver = H160::from_slice(
&<sp_runtime::AccountId32 as AsRef<[u8; 32]>>::as_ref(
&Keyring::Charlie.to_account_id(),
)[0..20],
);

assert_ok!(pallet_liquidity_pools::Pallet::<T>::transfer(
RawOrigin::Signed(Keyring::Alice.into()).into(),
LP_ETH_USDC,
DomainAddress::EVM(1, receiver.into()),
lp_eth_usdc(TRANSFER_AMOUNT),
));

let domain_acc = Domain::convert(Domain::EVM(1));

assert_eq!(
orml_tokens::Pallet::<T>::free_balance(LP_ETH_USDC, &domain_acc),
lp_eth_usdc(TRANSFER_AMOUNT),
);
});
}

fn restrict_usdc_transfer<T: Runtime>() {
let mut env = RuntimeEnv::<T>::from_parachain_storage(
Genesis::default()
Expand Down Expand Up @@ -2286,6 +2372,7 @@ mod centrifuge {
}

crate::test_for_runtimes!([centrifuge], restrict_lp_eth_usdc_transfer);
crate::test_for_runtimes!([centrifuge], restrict_lp_eth_usdc_lp_transfer);
crate::test_for_runtimes!([centrifuge], restrict_usdc_transfer);
crate::test_for_runtimes!([centrifuge], restrict_usdc_xcm_transfer);
crate::test_for_runtimes!([centrifuge], restrict_dot_transfer);
Expand Down
19 changes: 17 additions & 2 deletions runtime/integration-tests/src/generic/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ use cfg_types::{
use codec::Codec;
use fp_self_contained::{SelfContainedCall, UncheckedExtrinsic};
use frame_support::{
dispatch::{DispatchInfo, GetDispatchInfo, PostDispatchInfo},
traits::IsType,
dispatch::{DispatchInfo, GetDispatchInfo, PostDispatchInfo, RawOrigin},
traits::{IsType, OriginTrait},
Parameter,
};
use liquidity_pools_gateway_routers::DomainRouter;
use pallet_liquidity_pools::Router;
use pallet_transaction_payment::CurrencyAdapter;
use runtime_common::{
apis,
Expand Down Expand Up @@ -49,6 +51,7 @@ pub trait Runtime:
RuntimeEvent = Self::RuntimeEventExt,
BlockNumber = BlockNumber,
Lookup = AccountIdLookup<AccountId, ()>,
RuntimeOrigin = Self::RuntimeOriginExt,
> + pallet_pool_system::Config<
CurrencyId = CurrencyId,
Balance = Balance,
Expand Down Expand Up @@ -100,6 +103,11 @@ pub trait Runtime:
+ pallet_restricted_tokens::Config<Balance = Balance, CurrencyId = CurrencyId>
+ pallet_restricted_xtokens::Config
+ pallet_transfer_allowlist::Config<CurrencyId = CurrencyId, Location = Location>
+ pallet_liquidity_pools::Config<CurrencyId = CurrencyId, Balance = Balance>
+ pallet_liquidity_pools_gateway::Config<Router = DomainRouter<Self>>
+ pallet_xcm_transactor::Config<CurrencyId = CurrencyId>
+ pallet_ethereum::Config
+ pallet_ethereum_transaction::Config
{
/// Just the RuntimeCall type, but redefined with extra bounds.
/// You can add `From` bounds in order to convert pallet calls to
Expand Down Expand Up @@ -139,6 +147,13 @@ pub trait Runtime:
+ From<pallet_pool_system::Event<Self>>
+ From<orml_oracle::Event<Self>>;

type RuntimeOriginExt: Into<Result<RawOrigin<Self::AccountId>, <Self as frame_system::Config>::RuntimeOrigin>>
+ From<RawOrigin<Self::AccountId>>
+ Clone
+ OriginTrait<Call = <Self as frame_system::Config>::RuntimeCall>
+ From<pallet_ethereum::RawOrigin>
+ Into<Result<pallet_ethereum::Origin, <Self as frame_system::Config>::RuntimeOrigin>>;

/// Block used by the runtime
type Block: Block<
Hash = H256,
Expand Down
2 changes: 1 addition & 1 deletion runtime/integration-tests/src/generic/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl<Event> Blocks<Event> {
}

/// Define an environment behavior
pub trait Env<T: Runtime> {
pub trait Env<T: Runtime>: Default {
/// Load the environment from a parachain storage
fn from_parachain_storage(parachain_storage: Storage) -> Self;

Expand Down
1 change: 1 addition & 0 deletions runtime/integration-tests/src/generic/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ macro_rules! impl_runtime {
type MaxTranchesExt = $runtime_path::MaxTranches;
type RuntimeCallExt = $runtime_path::RuntimeCall;
type RuntimeEventExt = $runtime_path::RuntimeEvent;
type RuntimeOriginExt = $runtime_path::RuntimeOrigin;

const KIND: RuntimeKind = RuntimeKind::$kind;
}
Expand Down

0 comments on commit 9b5d60b

Please sign in to comment.