Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[tests] make emulated setup closer to ecosystem reality #5301

Merged
merged 2 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub fn genesis() -> Storage {
},
assets: asset_hub_rococo_runtime::AssetsConfig {
assets: vec![
(RESERVABLE_ASSET_ID, AssetHubRococoAssetOwner::get(), true, ED),
(RESERVABLE_ASSET_ID, AssetHubRococoAssetOwner::get(), false, ED),
(USDT_ID, AssetHubRococoAssetOwner::get(), true, ED),
],
..Default::default()
Expand All @@ -81,7 +81,7 @@ pub fn genesis() -> Storage {
(
PenpalTeleportableAssetLocation::get(),
PenpalSiblingSovereignAccount::get(),
true,
false,
ED,
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ 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};

Expand Down Expand Up @@ -65,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(), false, ED),
(USDT_ID, AssetHubWestendAssetOwner::get(), true, ED),
],
..Default::default()
},
foreign_assets: asset_hub_westend_runtime::ForeignAssetsConfig {
Expand All @@ -74,7 +77,7 @@ pub fn genesis() -> Storage {
(
PenpalTeleportableAssetLocation::get(),
PenpalSiblingSovereignAccount::get(),
true,
false,
ED,
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ 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;
Expand Down Expand Up @@ -81,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 Asset Hub
(UsdtFromAssetHub::get(), PenpalAssetOwner::get(), true, ED),
],
..Default::default()
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ fn reserve_transfer_assets_from_system_para_to_para() {
);
}

/// Reserve Transfers of a foreign asset and native asset from Parachain to System Para should
/// Reserve Transfers of a random asset and native asset from Parachain to System Para should
/// work
#[test]
fn reserve_transfer_assets_from_para_to_system_para() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
// limitations under the License.

use crate::imports::*;
use emulated_integration_tests_common::accounts::{ALICE, BOB};
use emulated_integration_tests_common::{
accounts::{ALICE, BOB},
USDT_ID,
};
use frame_support::{
dispatch::RawOrigin,
sp_runtime::traits::Dispatchable,
Expand Down Expand Up @@ -161,7 +164,6 @@ fn spend_roc_on_asset_hub() {

#[test]
fn create_and_claim_treasury_spend_in_usdt() {
const ASSET_ID: u32 = 1984;
const SPEND_AMOUNT: u128 = 10_000_000;
// treasury location from a sibling parachain.
let treasury_location: Location = Location::new(1, PalletInstance(18));
Expand All @@ -175,7 +177,7 @@ fn create_and_claim_treasury_spend_in_usdt() {
let asset_kind = VersionedLocatableAsset::V3 {
location: asset_hub_location,
asset_id: v3::AssetId::Concrete(
(v3::Junction::PalletInstance(50), v3::Junction::GeneralIndex(ASSET_ID.into())).into(),
(v3::Junction::PalletInstance(50), v3::Junction::GeneralIndex(USDT_ID.into())).into(),
),
};
// treasury spend beneficiary.
Expand All @@ -187,9 +189,9 @@ fn create_and_claim_treasury_spend_in_usdt() {
type Assets = <AssetHubRococo as AssetHubRococoPallet>::Assets;

// USDT created at genesis, mint some assets to the treasury account.
assert_ok!(<Assets as Mutate<_>>::mint_into(ASSET_ID, &treasury_account, SPEND_AMOUNT * 4));
assert_ok!(<Assets as Mutate<_>>::mint_into(USDT_ID, &treasury_account, SPEND_AMOUNT * 4));
// beneficiary has zero balance.
assert_eq!(<Assets as FungiblesInspect<_>>::balance(ASSET_ID, &alice,), 0u128,);
assert_eq!(<Assets as FungiblesInspect<_>>::balance(USDT_ID, &alice,), 0u128,);
});

Rococo::execute_with(|| {
Expand Down Expand Up @@ -231,7 +233,7 @@ fn create_and_claim_treasury_spend_in_usdt() {
AssetHubRococo,
vec![
RuntimeEvent::Assets(pallet_assets::Event::Transferred { asset_id: id, from, to, amount }) => {
id: id == &ASSET_ID,
id: id == &USDT_ID,
from: from == &treasury_account,
to: to == &alice,
amount: amount == &SPEND_AMOUNT,
Expand All @@ -241,7 +243,7 @@ fn create_and_claim_treasury_spend_in_usdt() {
]
);
// beneficiary received the assets from the treasury.
assert_eq!(<Assets as FungiblesInspect<_>>::balance(ASSET_ID, &alice,), SPEND_AMOUNT,);
assert_eq!(<Assets as FungiblesInspect<_>>::balance(USDT_ID, &alice,), SPEND_AMOUNT,);
});

Rococo::execute_with(|| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@
// limitations under the License.

use crate::imports::*;
use emulated_integration_tests_common::accounts::{ALICE, BOB};
use frame_support::traits::fungibles::{Create, Inspect, Mutate};
use emulated_integration_tests_common::{
accounts::{ALICE, BOB},
USDT_ID,
};
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 SPEND_AMOUNT: u128 = 1_000_000;
const SPEND_AMOUNT: u128 = 1_000_000_000;
// treasury location from a sibling parachain.
let treasury_location: Location =
Location::new(1, [Parachain(CollectivesWestend::para_id().into()), PalletInstance(65)]);
Expand All @@ -34,7 +36,7 @@ fn create_and_claim_treasury_spend() {
// asset kind to be spent from the treasury.
let asset_kind = VersionedLocatableAsset::V4 {
location: asset_hub_location,
asset_id: AssetId((PalletInstance(50), GeneralIndex(ASSET_ID.into())).into()),
asset_id: AssetId((PalletInstance(50), GeneralIndex(USDT_ID.into())).into()),
};
// treasury spend beneficiary.
let alice: AccountId = Westend::account_id_of(ALICE);
Expand All @@ -44,16 +46,10 @@ 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
));
assert_ok!(<Assets as Mutate<_>>::mint_into(ASSET_ID, &treasury_account, SPEND_AMOUNT * 4));
// USDT created at genesis, mint some assets to the fellowship treasury account.
assert_ok!(<Assets as Mutate<_>>::mint_into(USDT_ID, &treasury_account, SPEND_AMOUNT * 4));
// beneficiary has zero balance.
assert_eq!(<Assets as Inspect<_>>::balance(ASSET_ID, &alice,), 0u128,);
assert_eq!(<Assets as Inspect<_>>::balance(USDT_ID, &alice,), 0u128,);
});

CollectivesWestend::execute_with(|| {
Expand Down Expand Up @@ -96,7 +92,7 @@ fn create_and_claim_treasury_spend() {
AssetHubWestend,
vec![
RuntimeEvent::Assets(pallet_assets::Event::Transferred { asset_id: id, from, to, amount }) => {
id: id == &ASSET_ID,
id: id == &USDT_ID,
from: from == &treasury_account,
to: to == &alice,
amount: amount == &SPEND_AMOUNT,
Expand All @@ -106,7 +102,7 @@ fn create_and_claim_treasury_spend() {
]
);
// beneficiary received the assets from the treasury.
assert_eq!(<Assets as Inspect<_>>::balance(ASSET_ID, &alice,), SPEND_AMOUNT,);
assert_eq!(<Assets as Inspect<_>>::balance(USDT_ID, &alice,), SPEND_AMOUNT,);
});

CollectivesWestend::execute_with(|| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ fn reserve_transfer_assets_from_system_para_to_para() {
);
}

/// Reserve Transfers of a foreign asset and native asset from Parachain to System Para should
/// Reserve Transfers of a random asset and native asset from Parachain to System Para should
/// work
#[test]
fn reserve_transfer_assets_from_para_to_system_para() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@
// limitations under the License.

use crate::imports::*;
use emulated_integration_tests_common::accounts::{ALICE, BOB};
use frame_support::traits::fungibles::{Create, Inspect, Mutate};
use emulated_integration_tests_common::{
accounts::{ALICE, BOB},
USDT_ID,
};
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 SPEND_AMOUNT: u128 = 1_000_000;
const SPEND_AMOUNT: u128 = 1_000_000_000;
// treasury location from a sibling parachain.
let treasury_location: Location = Location::new(1, PalletInstance(37));
// treasury account on a sibling parachain.
Expand All @@ -33,7 +35,7 @@ fn create_and_claim_treasury_spend() {
// asset kind to be spend from the treasury.
let asset_kind = VersionedLocatableAsset::V4 {
location: asset_hub_location,
asset_id: AssetId([PalletInstance(50), GeneralIndex(ASSET_ID.into())].into()),
asset_id: AssetId([PalletInstance(50), GeneralIndex(USDT_ID.into())].into()),
};
// treasury spend beneficiary.
let alice: AccountId = Westend::account_id_of(ALICE);
Expand All @@ -43,16 +45,10 @@ 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
));
assert_ok!(<Assets as Mutate<_>>::mint_into(ASSET_ID, &treasury_account, SPEND_AMOUNT * 4));
// USDT created at genesis, mint some assets to the treasury account.
assert_ok!(<Assets as Mutate<_>>::mint_into(USDT_ID, &treasury_account, SPEND_AMOUNT * 4));
// beneficiary has zero balance.
assert_eq!(<Assets as Inspect<_>>::balance(ASSET_ID, &alice,), 0u128,);
assert_eq!(<Assets as Inspect<_>>::balance(USDT_ID, &alice,), 0u128,);
});

Westend::execute_with(|| {
Expand Down Expand Up @@ -94,7 +90,7 @@ fn create_and_claim_treasury_spend() {
AssetHubWestend,
vec![
RuntimeEvent::Assets(pallet_assets::Event::Transferred { asset_id: id, from, to, amount }) => {
id: id == &ASSET_ID,
id: id == &USDT_ID,
from: from == &treasury_account,
to: to == &alice,
amount: amount == &SPEND_AMOUNT,
Expand All @@ -104,7 +100,7 @@ fn create_and_claim_treasury_spend() {
]
);
// beneficiary received the assets from the treasury.
assert_eq!(<Assets as Inspect<_>>::balance(ASSET_ID, &alice,), SPEND_AMOUNT,);
assert_eq!(<Assets as Inspect<_>>::balance(USDT_ID, &alice,), SPEND_AMOUNT,);
});

Westend::execute_with(|| {
Expand Down
4 changes: 4 additions & 0 deletions cumulus/parachains/runtimes/testing/penpal/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,10 @@ parameter_types! {
1,
[Parachain(ASSET_HUB_ID), PalletInstance(ASSETS_PALLET_ID), GeneralIndex(RESERVABLE_ASSET_ID.into())]
);
pub UsdtFromAssetHub: Location = Location::new(
1,
[Parachain(ASSET_HUB_ID), PalletInstance(ASSETS_PALLET_ID), GeneralIndex(1984)]
);

/// The Penpal runtime is utilized for testing with various environment setups.
/// This storage item provides the opportunity to customize testing scenarios
Expand Down
Loading