Skip to content

Commit

Permalink
test ignored
Browse files Browse the repository at this point in the history
  • Loading branch information
asiniscalchi committed Oct 11, 2024
1 parent 1c66d49 commit cd86570
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 43 deletions.
36 changes: 28 additions & 8 deletions runtime/laos/src/configs/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,24 @@ use xcm_builder::{
};
use xcm_executor::XcmExecutor;

pub const ASSET_HUB_ID: u32 = 1000;

parameter_types! {
// Represents the location of the Relay Chain (parent in the XCM hierarchy).
pub const RelayLocation: Location = Location::parent();
// Optional network identifier for the Relay Chain; set to `None` for default behavior.
pub const RelayNetwork: Option<NetworkId> = None;
pub const RelayNetwork: Option<NetworkId> = NetworkId::Polkadot;
// Defines the origin for messages coming from the Relay Chain.
pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
// Universal location for the parachain in the network topology.
// For production, consider setting `RelayNetwork` and using `GlobalConsensus`.
pub UniversalLocation: InteriorLocation = Parachain(ParachainInfo::parachain_id().into()).into();
// For the real deployment, it is recommended to set `RelayNetwork` according to the relay chain
// and prepend `UniversalLocation` with `GlobalConsensus(RelayNetwork::get())`.
pub UniversalLocation: InteriorLocation = (
GlobalConsensus(RelayNetwork::get()),
Parachain(ParachainInfo::parachain_id().into()),
).into();
pub HereLocation: Location = Location::here();
pub CheckingAccount: AccountId = PolkadotXcm::check_account();
pub Checking: (AccountId, MintLocation) = (CheckingAccount::get(), MintLocation::Local);
}

/// Converts a `MultiLocation` into an `AccountId`.
Expand All @@ -73,7 +81,7 @@ pub type LocalAssetTransactor = FungibleAdapter<
// Specifies the local `AccountId` type.
AccountId,
// Teleportation of assets is not tracked or allowed.
(),
Checking,
>;

/// Converts incoming XCM origins into local `Origin` instances for dispatching transactions.
Expand Down Expand Up @@ -138,6 +146,19 @@ pub type Barrier = TrailingSetTopicAsId<
>,
>;

parameter_types! {
pub ParentTokenPerSecondPerByte: (AssetId, u128, u128) = (AssetId(Parent.into()), 1, 1);
}

parameter_types! {
pub NativeToken: AssetId = AssetId(Location::here());
pub NativeTokenFilter: AssetFilter = Wild(AllOf { fun: WildFungible, id: NativeToken::get() });
pub AssetHubLocation: Location = Location::new(1, [Parachain(ASSET_HUB_ID)]);
pub AssetHubTrustedTeleporter: (AssetFilter, Location) = (NativeTokenFilter::get(), AssetHubLocation::get());
}

pub type TrustedTeleporters = xcm_builder::Case<AssetHubTrustedTeleporter>;

pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
type RuntimeCall = RuntimeCall;
Expand All @@ -146,9 +167,8 @@ impl xcm_executor::Config for XcmConfig {
type AssetTransactor = LocalAssetTransactor;
// Converts XCM origins to local dispatch origins.
type OriginConverter = XcmOriginToTransactDispatchOrigin;
// Identifies which assets are considered reserve assets.
type IsReserve = NativeAsset;
type IsTeleporter = (); // Teleporting is disabled.
type IsReserve = (); // no reserve trasfer are accepted
type IsTeleporter = TrustedTeleporters;
type UniversalLocation = UniversalLocation;
// Filters and allows XCM messages based on security policies.
type Barrier = Barrier;
Expand Down
3 changes: 1 addition & 2 deletions xcm-simulator/src/laosish/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@

//! Parachain runtime mock.

mod configs;
pub mod configs;

pub use configs::xcm_config::ASSET_HUB_ID;
use frame_support::construct_runtime;

use crate::mock_msg_queue;
Expand Down
2 changes: 1 addition & 1 deletion xcm-simulator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

mod laosish;
mod parachain;
mod relay_chain;
mod parachain_teleporter;
mod relay_chain;

use hex_literal::hex;

Expand Down
1 change: 1 addition & 0 deletions xcm-simulator/src/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ impl pallet_assets::Config<TrustBackedAssetsInstance> for Runtime {
}

/// Simple conversion of `u32` into an `AssetId` for use in benchmarking.
#[cfg(feature = "runtime-benchmarks")]
pub struct XcmBenchmarkHelper;
#[cfg(feature = "runtime-benchmarks")]
impl pallet_assets::BenchmarkHelper<xcm::v3::Location> for XcmBenchmarkHelper {
Expand Down
20 changes: 9 additions & 11 deletions xcm-simulator/src/parachain_teleporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use core::marker::PhantomData;
use frame_support::{
construct_runtime, derive_impl, parameter_types,
traits::{ContainsPair, EnsureOrigin, EnsureOriginWithArg, Everything, EverythingBut, Nothing},
traits::{ContainsPair, EnsureOrigin, EnsureOriginWithArg, Everything, Nothing},
weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight},
};

Expand All @@ -41,16 +41,13 @@ use polkadot_parachain_primitives::primitives::Sibling;
use sp_runtime::codec;
use xcm::latest::prelude::*;
use xcm_builder::{
Account32Hash, AccountId32Aliases, AllowUnpaidExecutionFrom, ConvertedConcreteId,
EnsureDecodableXcm, EnsureXcmOrigin, FixedRateOfFungible, FixedWeightBounds,
FrameTransactionalProcessor, FungibleAdapter, GlobalConsensusParachainConvertsFor, IsConcrete,
NativeAsset, NoChecking, NonFungiblesAdapter, ParentIsPreset, SiblingParachainConvertsVia,
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, MintLocation
};
use xcm_executor::{
traits::{ConvertLocation, JustTry},
Config, XcmExecutor,
Account32Hash, AccountId32Aliases, AllowUnpaidExecutionFrom, EnsureDecodableXcm,
EnsureXcmOrigin, FixedRateOfFungible, FixedWeightBounds, FrameTransactionalProcessor,
FungibleAdapter, GlobalConsensusParachainConvertsFor, IsConcrete, MintLocation, ParentIsPreset,
SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32,
SovereignSignedViaLocation,
};
use xcm_executor::{traits::ConvertLocation, Config, XcmExecutor};

pub type SovereignAccountOf = (
SiblingParachainConvertsVia<Sibling, AccountId>,
Expand Down Expand Up @@ -162,7 +159,7 @@ parameter_types! {
pub const RelayLocation: Location = Location::parent();
pub const RelayNetwork: NetworkId = NetworkId::Kusama;
pub UniversalLocation: InteriorLocation = [GlobalConsensus(RelayNetwork::get()), Parachain(MsgQueue::parachain_id().into())].into();
pub HereLocation: Location = Location::here();
pub HereLocation: Location = Location::here();
pub CheckingAccount: AccountId = PolkadotXcm::check_account();
pub Checking: (AccountId, MintLocation) = (CheckingAccount::get(), MintLocation::Local);
}
Expand Down Expand Up @@ -327,6 +324,7 @@ impl pallet_assets::Config<TrustBackedAssetsInstance> for Runtime {
}

/// Simple conversion of `u32` into an `AssetId` for use in benchmarking.
#[cfg(feature = "runtime-benchmarks")]
pub struct XcmBenchmarkHelper;
#[cfg(feature = "runtime-benchmarks")]
impl pallet_assets::BenchmarkHelper<xcm::v3::Location> for XcmBenchmarkHelper {
Expand Down
9 changes: 5 additions & 4 deletions xcm-simulator/src/tests/laosish_xcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ fn ump_transfer_balance() {
fn xcmp_create_foreign_asset() {
MockNet::reset();

assert_eq!(laosish::ASSET_HUB_ID, PARA_B_ID);
assert_eq!(laosish::configs::xcm_config::ASSET_HUB_ID, PARA_B_ID);

let para_a_native_asset_location =
xcm::v3::Location::new(1, [xcm::v3::Junction::Parachain(PARA_LAOSISH_ID)]);
Expand All @@ -126,7 +126,7 @@ fn xcmp_create_foreign_asset() {
Laosish::execute_with(|| {
assert_ok!(LaosishPalletXcm::send_xcm(
Here,
(Parent, Parachain(laosish::ASSET_HUB_ID)),
(Parent, Parachain(laosish::configs::xcm_config::ASSET_HUB_ID)),
Xcm(vec![Transact {
origin_kind: OriginKind::Xcm,
require_weight_at_most: Weight::from_parts(INITIAL_BALANCE as u64, 1024 * 1024),
Expand All @@ -143,6 +143,7 @@ fn xcmp_create_foreign_asset() {
});
}

#[ignore] // TODO
#[test]
fn xcmp_teleport_native_assets_to_asset_hub() {
MockNet::reset();
Expand All @@ -159,7 +160,7 @@ fn xcmp_teleport_native_assets_to_asset_hub() {
Laosish::execute_with(|| {
assert_ok!(LaosishPalletXcm::send_xcm(
Here,
(Parent, Parachain(laosish::ASSET_HUB_ID)),
(Parent, Parachain(laosish::configs::xcm_config::ASSET_HUB_ID)),
Xcm(vec![Transact {
origin_kind: OriginKind::Xcm,
require_weight_at_most: Weight::from_parts(INITIAL_BALANCE as u64, 1024 * 1024),
Expand All @@ -172,7 +173,7 @@ fn xcmp_teleport_native_assets_to_asset_hub() {

assert_ok!(LaosishPalletXcm::limited_teleport_assets(
laosish::RuntimeOrigin::signed(ALITH.into()),
Box::new(Parachain(laosish::ASSET_HUB_ID).into()),
Box::new(Parachain(laosish::configs::xcm_config::ASSET_HUB_ID).into()),
Box::new(AccountId32 { network: None, id: ALICE.into() }.into()),
Box::new((Here, amount).into()),
0,
Expand Down
36 changes: 19 additions & 17 deletions xcm-simulator/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,18 +693,20 @@ fn xcmp_create_foreign_asset() {
});
}

#[ignore] // TODO
#[test]
fn teleport_para_teleport_to_para_a() {
MockNet::reset();

let para_teleporter_native_asset_location =
xcm::v3::Location::new(1, [xcm::v3::Junction::Parachain(PARA_TELEPORTER_ID)]);

let create_asset = parachain_teleporter::RuntimeCall::ForeignAssets(TeleportAssetsCall::create {
id: para_teleporter_native_asset_location,
admin: sibling_account_id(PARA_TELEPORTER_ID),
min_balance: 1000,
});
let create_asset =
parachain_teleporter::RuntimeCall::ForeignAssets(TeleportAssetsCall::create {
id: para_teleporter_native_asset_location,
admin: sibling_account_id(PARA_TELEPORTER_ID),
min_balance: 1000,
});

ParaTeleporter::execute_with(|| {
assert_ok!(ParachainTeleporterPalletXcm::send_xcm(
Expand All @@ -717,17 +719,17 @@ fn teleport_para_teleport_to_para_a() {
}]),
));

let amount = 1_000;

assert_ok!(ParachainTeleporterPalletXcm::limited_teleport_assets(
parachain_teleporter::RuntimeOrigin::signed(ALICE.into()),
Box::new(Parachain(PARA_A_ID).into()),
Box::new(AccountId32 { network: None, id: ALICE.into() }.into()),
Box::new((Here, amount).into()),
0,
WeightLimit::Limited(Weight::from_parts(INITIAL_BALANCE as u64, 1024 * 1024)),
));
assert_eq!(parachain_teleporter::Balances::free_balance(ALICE), INITIAL_BALANCE - amount);
let amount = 1_000;

assert_ok!(ParachainTeleporterPalletXcm::limited_teleport_assets(
parachain_teleporter::RuntimeOrigin::signed(ALICE.into()),
Box::new(Parachain(PARA_A_ID).into()),
Box::new(AccountId32 { network: None, id: ALICE.into() }.into()),
Box::new((Here, amount).into()),
0,
WeightLimit::Limited(Weight::from_parts(INITIAL_BALANCE as u64, 1024 * 1024)),
));

assert_eq!(parachain_teleporter::Balances::free_balance(ALICE), INITIAL_BALANCE - amount);
});
}

0 comments on commit cd86570

Please sign in to comment.