Skip to content

Commit

Permalink
feat: allow different assets for delivery fees
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscoaguirre committed Jul 24, 2024
1 parent bb0e969 commit 5939ba2
Show file tree
Hide file tree
Showing 17 changed files with 760 additions and 76 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ use sp_core::{sr25519, storage::Storage};
use emulated_integration_tests_common::{
accounts, build_genesis_storage, collators, get_account_id_from_seed,
PenpalSiblingSovereignAccount, PenpalTeleportableAssetLocation, RESERVABLE_ASSET_ID,
SAFE_XCM_VERSION,
SAFE_XCM_VERSION, USDT_ID,
};
use parachains_common::{AccountId, Balance};

pub const PARA_ID: u32 = 1000;
pub const ED: Balance = testnet_parachains_constants::westend::currency::EXISTENTIAL_DEPOSIT;
pub const USDT_ED: Balance = 70_000;

parameter_types! {
pub AssetHubWestendAssetOwner: AccountId = get_account_id_from_seed::<sr25519::Public>("Alice");
Expand Down Expand Up @@ -64,7 +65,10 @@ pub fn genesis() -> Storage {
..Default::default()
},
assets: asset_hub_westend_runtime::AssetsConfig {
assets: vec![(RESERVABLE_ASSET_ID, AssetHubWestendAssetOwner::get(), true, ED)],
assets: vec![
(RESERVABLE_ASSET_ID, AssetHubWestendAssetOwner::get(), true, ED),
(USDT_ID, AssetHubWestendAssetOwner::get(), true, USDT_ED),
],
..Default::default()
},
foreign_assets: asset_hub_westend_runtime::ForeignAssetsConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ use emulated_integration_tests_common::{
accounts, build_genesis_storage, collators, get_account_id_from_seed, SAFE_XCM_VERSION,
};
use parachains_common::{AccountId, Balance};
use penpal_runtime::xcm_config::{LocalReservableFromAssetHub, RelayLocation};
use penpal_runtime::xcm_config::{LocalReservableFromAssetHub, RelayLocation, UsdtFromAssetHub};
// Penpal
pub const PARA_ID_A: u32 = 2000;
pub const PARA_ID_B: u32 = 2001;
pub const ED: Balance = penpal_runtime::EXISTENTIAL_DEPOSIT;
pub const USDT_ED: Balance = 70_000;

parameter_types! {
pub PenpalSudoAccount: AccountId = get_account_id_from_seed::<sr25519::Public>("Alice");
Expand Down Expand Up @@ -80,6 +81,8 @@ pub fn genesis(para_id: u32) -> Storage {
(RelayLocation::get(), PenpalAssetOwner::get(), true, ED),
// Sufficient AssetHub asset representation
(LocalReservableFromAssetHub::get(), PenpalAssetOwner::get(), true, ED),
// USDT from AssetHub
(UsdtFromAssetHub::get(), PenpalAssetOwner::get(), true, USDT_ED),
],
..Default::default()
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ decl_test_parachains! {
PolkadotXcm: penpal_runtime::PolkadotXcm,
Assets: penpal_runtime::Assets,
ForeignAssets: penpal_runtime::ForeignAssets,
AssetConversion: penpal_runtime::AssetConversion,
Balances: penpal_runtime::Balances,
}
},
Expand All @@ -76,6 +77,7 @@ decl_test_parachains! {
PolkadotXcm: penpal_runtime::PolkadotXcm,
Assets: penpal_runtime::Assets,
ForeignAssets: penpal_runtime::ForeignAssets,
AssetConversion: penpal_runtime::AssetConversion,
Balances: penpal_runtime::Balances,
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ mod imports {
CustomizableAssetFromSystemAssetHub as PenpalCustomizableAssetFromSystemAssetHub,
LocalReservableFromAssetHub as PenpalLocalReservableFromAssetHub,
LocalTeleportableToAssetHub as PenpalLocalTeleportableToAssetHub,
UsdtFromAssetHub as PenpalUsdtFromAssetHub,
},
PenpalAParaPallet as PenpalAPallet, PenpalAssetOwner,
PenpalBParaPallet as PenpalBPallet,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@

use crate::imports::*;
use emulated_integration_tests_common::accounts::{ALICE, BOB};
use frame_support::traits::fungibles::{Create, Inspect, Mutate};
use frame_support::traits::fungibles::{Inspect, Mutate};
use polkadot_runtime_common::impls::VersionedLocatableAsset;
use xcm_executor::traits::ConvertLocation;

#[test]
fn create_and_claim_treasury_spend() {
const ASSET_ID: u32 = 1984;
const ASSET_ID: u32 = 1984; // USDT already created at genesis.
const SPEND_AMOUNT: u128 = 1_000_000;
// treasury location from a sibling parachain.
let treasury_location: Location =
Expand All @@ -44,13 +44,7 @@ fn create_and_claim_treasury_spend() {
AssetHubWestend::execute_with(|| {
type Assets = <AssetHubWestend as AssetHubWestendPallet>::Assets;

// create an asset class and mint some assets to the treasury account.
assert_ok!(<Assets as Create<_>>::create(
ASSET_ID,
treasury_account.clone(),
true,
SPEND_AMOUNT / 2
));
// USDT already created at genesis.
assert_ok!(<Assets as Mutate<_>>::mint_into(ASSET_ID, &treasury_account, SPEND_AMOUNT * 4));
// beneficiary has zero balance.
assert_eq!(<Assets as Inspect<_>>::balance(ASSET_ID, &alice,), 0u128,);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -613,10 +613,10 @@ fn transfer_foreign_assets_from_para_to_para_through_asset_hub() {
<ForeignAssets as Inspect<_>>::balance(roc_at_westend_parachains, &receiver)
});

// Sender's balance is reduced by amount sent plus delivery fees
// Sender's balance is reduced by amount sent.
assert!(sender_wnds_after < sender_wnds_before - wnd_to_send);
assert_eq!(sender_rocs_after, sender_rocs_before - roc_to_send);
// Sovereign accounts on reserve are changed accordingly
// Sovereign accounts on reserve are changed accordingly.
assert_eq!(
wnds_in_sender_reserve_on_ah_after,
wnds_in_sender_reserve_on_ah_before - wnd_to_send
Expand All @@ -630,7 +630,7 @@ fn transfer_foreign_assets_from_para_to_para_through_asset_hub() {
rocs_in_receiver_reserve_on_ah_after,
rocs_in_receiver_reserve_on_ah_before + roc_to_send
);
// Receiver's balance is increased
// Receiver's balance is increased by amount sent minus delivery fees.
assert!(receiver_wnds_after > receiver_wnds_before);
assert_eq!(receiver_rocs_after, receiver_rocs_before + roc_to_send);
}
Expand Down
Loading

0 comments on commit 5939ba2

Please sign in to comment.