Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lemunozm committed Jun 13, 2024
1 parent 1770f11 commit 02ca1ad
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ use pallet_liquidity_pools_gateway::{Call as LiquidityPoolsGatewayCall, GatewayO
use pallet_pool_system::tranches::{TrancheInput, TrancheLoc, TrancheType};
use parity_scale_codec::Encode;
use polkadot_core_primitives::BlakeTwo256;
use polkadot_parachain_primitives::primitives::{Id, ValidationCode};
use polkadot_runtime_parachains::{
paras,
paras::{ParaGenesisArgs, ParaKind},
};
use polkadot_parachain_primitives::primitives::Id;
use runtime_common::{
account_conversion::AccountConverter,
foreign_investments::IdentityPoolCurrencyConverter,
Expand Down
30 changes: 17 additions & 13 deletions runtime/integration-tests/src/generic/cases/proxy.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
use cfg_primitives::Balance;
use cfg_types::{tokens::CrossChainTransferability, xcm::XcmMetadata};
use frame_support::{assert_err, assert_ok, traits::Get};
use cfg_types::tokens::{AssetMetadata, CurrencyId};
use frame_support::{assert_err, assert_ok};
use frame_system::RawOrigin;
use sp_runtime::{traits::StaticLookup, DispatchResult};
use staging_xcm::{
prelude::Parachain,
v4::{Junction, Location, WeightLimit},
VersionedLocation,
};
use staging_xcm::v4::WeightLimit;

use crate::{
generic::{
Expand All @@ -18,9 +14,9 @@ use crate::{
runtime_env::RuntimeEnv,
},
utils::{
self,
currency::{cfg, register_currency, usd6, CurrencyInfo, Usd6},
currency::{cfg, usd6, CurrencyInfo, CustomCurrency, Usd6},
genesis::{self, Genesis},
xcm::{account_location, enable_para_to_sibling_communication, transferable_metadata},
},
},
utils::accounts::Keyring,
Expand Down Expand Up @@ -55,20 +51,28 @@ fn configure_proxy_and_transfer<T: Runtime>(proxy_type: T::ProxyType) -> Dispatc
fn configure_proxy_and_x_transfer<T: Runtime + FudgeSupport>(
proxy_type: T::ProxyType,
) -> DispatchResult {
let curr = CustomCurrency(Usd6.id(), transferable_metadata::<T>(6));
let curr = CustomCurrency(
CurrencyId::ForeignAsset(1),
AssetMetadata {
decimals: 6,
..transferable_metadata(Some(T::FudgeHandle::PARA_ID))
},
);

let mut env = FudgeEnv::<T>::from_parachain_storage(
Genesis::default()
.add(genesis::balances::<T>(FOR_FEES))
.add(genesis::tokens::<T>(vec![(curr.id(), INITIAL)]))
.add(genesis::assets::<T>(vec![(curr.id(), curr.metadata())]))
.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: Usd6.id(),
currency_id: curr.id(),
amount: TRANSFER_AMOUNT,
dest: account_location(1, T::FudgeHandle::SIBLING_ID, TO.id()),
dest: account_location(1, Some(T::FudgeHandle::SIBLING_ID), TO.id()),
dest_weight_limit: WeightLimit::Unlimited,
}
.into();
Expand Down
78 changes: 40 additions & 38 deletions runtime/integration-tests/src/generic/cases/xtransfers.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use cfg_types::tokens::{AssetMetadata, CurrencyId};
use cfg_types::tokens::{AssetMetadata, CurrencyId, CurrencyId::Native};
use frame_support::{assert_ok, dispatch::RawOrigin};
use orml_traits::MultiCurrency;
use staging_xcm::v4::{Junction::*, Junctions::Here, Location, WeightLimit};
use staging_xcm::v4::{Junction::*, Junctions::Here, WeightLimit};

use crate::{
generic::{
Expand All @@ -27,9 +27,19 @@ const TRANSFER: u32 = 20;

type Relay<T> = FudgeRelayRuntime<T>;

fn create_transfeable_currency(decimals: u32, para_id: Option<u32>) -> CustomCurrency {
CustomCurrency(
CurrencyId::ForeignAsset(1),
AssetMetadata {
decimals,
..transferable_metadata(para_id)
},
)
}

#[test_runtimes(all)]
fn para_to_sibling_with_foreign_to_foreign_tokens<T: Runtime + FudgeSupport>() {
let curr = CustomCurrency(CurrencyId::ForeignAsset(1), transferable_metadata::<T>(6));
let curr = create_transfeable_currency(6, Some(T::FudgeHandle::PARA_ID));

let mut env = FudgeEnv::<T>::from_storage(
Default::default(),
Expand Down Expand Up @@ -71,17 +81,16 @@ fn para_to_sibling_with_foreign_to_foreign_tokens<T: Runtime + FudgeSupport>() {

#[test_runtimes(all)]
fn para_to_sibling_with_native_to_foreign_tokens<T: Runtime + FudgeSupport>() {
let metadata = transferable_metadata::<T>(18);
let xnative = CustomCurrency(CurrencyId::ForeignAsset(1), metadata.clone());
let curr = create_transfeable_currency(18, Some(T::FudgeHandle::PARA_ID));

let mut env = FudgeEnv::<T>::from_storage(
Default::default(),
Genesis::default()
.add(genesis::balances::<T>(cfg(INITIAL)))
.add(genesis::assets::<T>([(CurrencyId::Native, &metadata)]))
.add(genesis::assets::<T>([(Native, &curr.metadata())]))
.storage(),
Genesis::default()
.add(genesis::assets::<T>([(xnative.id(), &metadata)]))
.add(genesis::assets::<T>([(curr.id(), &curr.metadata())]))
.storage(),
);

Expand All @@ -90,7 +99,7 @@ fn para_to_sibling_with_native_to_foreign_tokens<T: Runtime + FudgeSupport>() {
env.parachain_state_mut(|| {
assert_ok!(orml_xtokens::Pallet::<T>::transfer(
RawOrigin::Signed(Keyring::Alice.id()).into(),
CurrencyId::Native,
Native,
cfg(TRANSFER),
account_location(1, Some(T::FudgeHandle::SIBLING_ID), Keyring::Bob.id()),
WeightLimit::Unlimited,
Expand All @@ -106,25 +115,24 @@ fn para_to_sibling_with_native_to_foreign_tokens<T: Runtime + FudgeSupport>() {

env.sibling_state_mut(|| {
assert_eq!(
orml_tokens::Pallet::<T>::free_balance(xnative.id(), &Keyring::Bob.id()),
xnative.val(TRANSFER)
orml_tokens::Pallet::<T>::free_balance(curr.id(), &Keyring::Bob.id()),
curr.val(TRANSFER)
);
});
}

#[test_runtimes(all)]
fn para_to_sibling_with_foreign_to_native_tokens<T: Runtime + FudgeSupport>() {
let metadata = transferable_metadata::<T>(18);
let xnative = CustomCurrency(CurrencyId::ForeignAsset(1), metadata.clone());
let curr = create_transfeable_currency(18, Some(T::FudgeHandle::PARA_ID));

let mut env = FudgeEnv::<T>::from_storage(
Default::default(),
Genesis::default()
.add(genesis::tokens::<T>([(xnative.id(), xnative.val(INITIAL))]))
.add(genesis::assets::<T>([(xnative.id(), &metadata)]))
.add(genesis::tokens::<T>([(curr.id(), curr.val(INITIAL))]))
.add(genesis::assets::<T>([(curr.id(), &curr.metadata())]))
.storage(),
Genesis::default()
.add(genesis::assets::<T>([(CurrencyId::Native, &metadata)]))
.add(genesis::assets::<T>([(Native, &curr.metadata())]))
.storage(),
);

Expand All @@ -133,15 +141,15 @@ fn para_to_sibling_with_foreign_to_native_tokens<T: Runtime + FudgeSupport>() {
env.parachain_state_mut(|| {
assert_ok!(orml_xtokens::Pallet::<T>::transfer(
RawOrigin::Signed(Keyring::Alice.id()).into(),
xnative.id(),
xnative.val(TRANSFER),
curr.id(),
curr.val(TRANSFER),
account_location(1, Some(T::FudgeHandle::SIBLING_ID), Keyring::Bob.id()),
WeightLimit::Unlimited,
));

assert_eq!(
orml_tokens::Pallet::<T>::free_balance(xnative.id(), &Keyring::Alice.id()),
xnative.val(INITIAL) - xnative.val(TRANSFER)
orml_tokens::Pallet::<T>::free_balance(curr.id(), &Keyring::Alice.id()),
curr.val(INITIAL) - curr.val(TRANSFER)
);
});

Expand All @@ -156,21 +164,15 @@ fn para_to_sibling_with_foreign_to_native_tokens<T: Runtime + FudgeSupport>() {
}

#[test_runtimes(all)]
fn from_to_relay_using_relay_native_tokens<T: Runtime + FudgeSupport>() {
let xrelay = CustomCurrency(
CurrencyId::ForeignAsset(1),
AssetMetadata {
location: Some(Location::parent().into()),
..transferable_metadata::<T>(10)
},
);
fn para_from_to_relay_using_relay_native_tokens<T: Runtime + FudgeSupport>() {
let curr = create_transfeable_currency(10, None);

let mut env = FudgeEnv::<T>::from_storage(
Genesis::default()
.add(genesis::balances::<Relay<T>>(xrelay.val(INITIAL)))
.add(genesis::balances::<Relay<T>>(curr.val(INITIAL)))
.storage(),
Genesis::default()
.add(genesis::assets::<T>([(xrelay.id(), &xrelay.metadata())]))
.add(genesis::assets::<T>([(curr.id(), &curr.metadata())]))
.storage(),
Default::default(),
);
Expand All @@ -183,22 +185,22 @@ fn from_to_relay_using_relay_native_tokens<T: Runtime + FudgeSupport>() {
RawOrigin::Signed(Keyring::Alice.id()).into(),
Box::new(Parachain(T::FudgeHandle::PARA_ID).into()),
account_location(0, None, Keyring::Bob.id()),
Box::new((Here, xrelay.val(TRANSFER)).into()),
Box::new((Here, curr.val(TRANSFER)).into()),
0,
));

assert_eq!(
pallet_balances::Pallet::<Relay<T>>::free_balance(&Keyring::Alice.id()),
(xrelay.val(INITIAL) - xrelay.val(TRANSFER)).approx(0.01)
(curr.val(INITIAL) - curr.val(TRANSFER)).approx(0.01)
);
});

env.pass(Blocks::ByNumber(2));

env.parachain_state_mut(|| {
assert_eq!(
orml_tokens::Pallet::<T>::free_balance(xrelay.id(), &Keyring::Bob.id()),
xrelay.val(TRANSFER)
orml_tokens::Pallet::<T>::free_balance(curr.id(), &Keyring::Bob.id()),
curr.val(TRANSFER)
);
});

Expand All @@ -208,15 +210,15 @@ fn from_to_relay_using_relay_native_tokens<T: Runtime + FudgeSupport>() {
env.parachain_state_mut(|| {
assert_ok!(orml_xtokens::Pallet::<T>::transfer(
RawOrigin::Signed(Keyring::Bob.id()).into(),
xrelay.id(),
xrelay.val(TRANSFER / 2),
curr.id(),
curr.val(TRANSFER / 2),
account_location(1, None, Keyring::Alice.id()),
WeightLimit::Unlimited,
));

assert_eq!(
orml_tokens::Pallet::<T>::free_balance(xrelay.id(), &Keyring::Bob.id()),
(xrelay.val(TRANSFER) - xrelay.val(TRANSFER / 2)).approx(0.01)
orml_tokens::Pallet::<T>::free_balance(curr.id(), &Keyring::Bob.id()),
(curr.val(TRANSFER) - curr.val(TRANSFER / 2)).approx(0.01)
);
});

Expand All @@ -225,7 +227,7 @@ fn from_to_relay_using_relay_native_tokens<T: Runtime + FudgeSupport>() {
env.relay_state_mut(|| {
assert_eq!(
pallet_balances::Pallet::<Relay<T>>::free_balance(&Keyring::Alice.id()),
(xrelay.val(INITIAL) - xrelay.val(TRANSFER) + xrelay.val(TRANSFER / 2)).approx(0.01)
(curr.val(INITIAL) - curr.val(TRANSFER) + curr.val(TRANSFER / 2)).approx(0.01)
);
});
}
4 changes: 4 additions & 0 deletions runtime/integration-tests/src/generic/utils/currency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ impl CurrencyInfo for CustomCurrency {
fn custom(&self) -> CustomMetadata {
self.1.additional
}

fn metadata(&self) -> AssetMetadata {
self.1.clone()
}
}

impl CustomCurrency {
Expand Down
10 changes: 7 additions & 3 deletions runtime/integration-tests/src/generic/utils/xcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,14 @@ pub fn account_location(
}))
}

pub fn transferable_metadata<T: FudgeSupport>(decimals: u32) -> AssetMetadata {
pub fn transferable_metadata(origina_para_id: Option<u32>) -> AssetMetadata {
let location = match para_id {
Some(para_id) => Location::new(1, Parachain(origin_para_id)),
None => Location::parent(),
};

AssetMetadata {
decimals,
location: Some(Location::new(1, Parachain(T::FudgeHandle::PARA_ID)).into()),
location: Some(VersionedLocation::V4(location)),
additional: CustomMetadata {
transferability: CrossChainTransferability::xcm_with_fees(0),
..Default::default()
Expand Down

0 comments on commit 02ca1ad

Please sign in to comment.