Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

(fix): Send back xcDOT to AssetHub from Moonbeam #2938

Merged
merged 14 commits into from
Sep 12, 2024
8 changes: 4 additions & 4 deletions Cargo.lock

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

26 changes: 13 additions & 13 deletions precompiles/xtokens/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ fn transfer_self_reserve_works() {
weight: 4_000_000,
},
)
.expect_cost(2000)
.expect_cost(3000)
.expect_no_logs()
.execute_returns(());

Expand Down Expand Up @@ -139,7 +139,7 @@ fn transfer_to_reserve_works() {
weight: 4_000_000,
},
)
.expect_cost(3000)
.expect_cost(4000)
.expect_no_logs()
.execute_returns(());

Expand Down Expand Up @@ -186,7 +186,7 @@ fn transfer_to_reserve_with_unlimited_weight_works() {
weight: u64::MAX,
},
)
.expect_cost(3000)
.expect_cost(4000)
.expect_no_logs()
.execute_returns(());

Expand Down Expand Up @@ -235,7 +235,7 @@ fn transfer_to_reserve_with_fee_works() {
weight: 4_000_000,
},
)
.expect_cost(3000)
.expect_cost(4000)
.expect_no_logs()
.execute_returns(());

Expand Down Expand Up @@ -290,7 +290,7 @@ fn transfer_non_reserve_to_non_reserve_works() {
weight: 4_000_000,
},
)
.expect_cost(3000)
.expect_cost(4000)
.expect_no_logs()
.execute_returns(());

Expand Down Expand Up @@ -339,7 +339,7 @@ fn transfer_non_reserve_to_non_reserve_with_fee_works() {
weight: 4_000_000,
},
)
.expect_cost(3000)
.expect_cost(4000)
.expect_no_logs()
.execute_returns(());

Expand Down Expand Up @@ -394,7 +394,7 @@ fn transfer_multi_asset_to_reserve_works() {
weight: 4_000_000,
},
)
.expect_cost(3000)
.expect_cost(4000)
.expect_no_logs()
.execute_returns(());

Expand Down Expand Up @@ -442,7 +442,7 @@ fn transfer_multi_asset_self_reserve_works() {
weight: 4_000_000,
},
)
.expect_cost(2000)
.expect_cost(3000)
.expect_no_logs()
.execute_returns(());

Expand Down Expand Up @@ -490,7 +490,7 @@ fn transfer_multi_asset_self_reserve_with_fee_works() {
weight: 4_000_000,
},
)
.expect_cost(2000)
.expect_cost(3000)
.expect_no_logs()
.execute_returns(());

Expand Down Expand Up @@ -542,7 +542,7 @@ fn transfer_multi_asset_non_reserve_to_non_reserve() {
weight: 4_000_000,
},
)
.expect_cost(3000)
.expect_cost(4000)
.expect_no_logs()
.execute_returns(());

Expand Down Expand Up @@ -591,7 +591,7 @@ fn transfer_multi_asset_non_reserve_to_non_reserve_with_fee() {
weight: 4_000_000,
},
)
.expect_cost(3000)
.expect_cost(4000)
.expect_no_logs()
.execute_returns(());

Expand Down Expand Up @@ -645,7 +645,7 @@ fn transfer_multi_currencies() {
weight: 4_000_000,
},
)
.expect_cost(3000)
.expect_cost(4000)
.expect_no_logs()
.execute_returns(());

Expand Down Expand Up @@ -718,7 +718,7 @@ fn transfer_multi_assets() {
weight: 4_000_000,
},
)
.expect_cost(3000)
.expect_cost(4000)
.expect_no_logs()
.execute_returns(());

Expand Down
6 changes: 3 additions & 3 deletions runtime/moonbase/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1568,7 +1568,7 @@ fn xtokens_precompiles_transfer() {
weight: 4_000_000,
},
)
.expect_cost(348090)
.expect_cost(348298)
.expect_no_logs()
// We expect an evm subcall ERC20.burnFrom
.with_subcall_handle(move |subcall| {
Expand Down Expand Up @@ -1659,7 +1659,7 @@ fn xtokens_precompiles_transfer_multiasset() {
weight: 4_000_000,
},
)
.expect_cost(348090)
.expect_cost(348298)
.expect_no_logs()
// We expect an evm subcall ERC20.burnFrom
.with_subcall_handle(move |subcall| {
Expand Down Expand Up @@ -1743,7 +1743,7 @@ fn xtokens_precompiles_transfer_native() {
weight: 4_000_000,
},
)
.expect_cost(16000)
.expect_cost(16208)
.expect_no_logs()
.execute_returns(());
})
Expand Down
6 changes: 3 additions & 3 deletions runtime/moonbase/tests/xcm_mock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ decl_test_parachain! {
Runtime = statemint_like::Runtime,
XcmpMessageHandler = statemint_like::MsgQueue,
DmpMessageHandler = statemint_like::MsgQueue,
new_ext = statemint_ext(4),
new_ext = statemint_ext(1000),
}
}

Expand All @@ -118,7 +118,7 @@ decl_test_relay_chain! {
XcmConfig = relay_chain::XcmConfig,
MessageQueue = relay_chain::MessageQueue,
System = relay_chain::System,
new_ext = relay_ext(vec![1, 2, 3, 4]),
new_ext = relay_ext(vec![1, 2, 3, 1000]),
}
}

Expand All @@ -129,7 +129,7 @@ decl_test_network! {
(1, ParaA),
(2, ParaB),
(3, ParaC),
(4, Statemint),
(1000, Statemint),
],
}
}
Expand Down
37 changes: 28 additions & 9 deletions runtime/moonbase/tests/xcm_mock/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ use xcm::latest::{
};
use xcm_builder::{
AccountKey20Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom,
AllowTopLevelPaidExecutionFrom, ConvertedConcreteId, EnsureXcmOrigin, FixedRateOfFungible,
FixedWeightBounds, FungibleAdapter as XcmCurrencyAdapter, FungiblesAdapter, IsConcrete,
NoChecking, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative,
SiblingParachainConvertsVia, SignedAccountKey20AsNative, SovereignSignedViaLocation,
TakeWeightCredit, WithComputedOrigin,
AllowTopLevelPaidExecutionFrom, Case, ConvertedConcreteId, EnsureXcmOrigin,
FixedRateOfFungible, FixedWeightBounds, FungibleAdapter as XcmCurrencyAdapter,
FungiblesAdapter, IsConcrete, NoChecking, ParentAsSuperuser, ParentIsPreset,
RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
SignedAccountKey20AsNative, SovereignSignedViaLocation, TakeWeightCredit, WithComputedOrigin,
};
use xcm_executor::{traits::JustTry, Config, XcmExecutor};

Expand Down Expand Up @@ -330,6 +330,18 @@ parameter_types! {
].into()
};
pub const MaxAssetsIntoHolding: u32 = 64;

pub AssetHubLocation: Location = Location::new(1, [Parachain(1000)]);
pub const RelayLocation: Location = Location::parent();
pub RelayLocationFilter: AssetFilter = Wild(AllOf {
fun: WildFungible,
id: xcm::prelude::AssetId(RelayLocation::get()),
});

pub RelayChainNativeAssetFromAssetHub: (AssetFilter, Location) = (
RelayLocationFilter::get(),
AssetHubLocation::get()
);
}

use frame_system::RawOrigin;
Expand All @@ -338,15 +350,22 @@ use sp_runtime::DispatchErrorWithPostInfo;
use xcm_executor::traits::CallDispatcher;
moonbeam_runtime_common::impl_moonbeam_xcm_call!();

type Reserves = (
// Relaychain (DOT) from Asset Hub
Case<RelayChainNativeAssetFromAssetHub>,
// Assets which the reserve is the same as the origin.
orml_xcm_support::MultiNativeAsset<
xcm_primitives::AbsoluteAndRelativeReserve<SelfLocationAbsolute>,
>,
);

pub struct XcmConfig;
impl Config for XcmConfig {
type RuntimeCall = RuntimeCall;
type XcmSender = XcmRouter;
type AssetTransactor = AssetTransactors;
type OriginConverter = XcmOriginToTransactDispatchOrigin;
type IsReserve = orml_xcm_support::MultiNativeAsset<
xcm_primitives::AbsoluteAndRelativeReserve<SelfLocationAbsolute>,
>;
type IsReserve = Reserves;
type IsTeleporter = ();
type UniversalLocation = UniversalLocation;
type Barrier = XcmBarrier;
Expand Down Expand Up @@ -430,7 +449,7 @@ parameter_types! {
parameter_type_with_key! {
pub ParachainMinFee: |location: Location| -> Option<u128> {
match (location.parents, location.first_interior()) {
(1, Some(Parachain(4u32))) => Some(50u128),
(1, Some(Parachain(1000u32))) => Some(50u128),
_ => None,
}
};
Expand Down
2 changes: 1 addition & 1 deletion runtime/moonbase/tests/xcm_mock/relay_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ pub type XcmBarrier = (

parameter_types! {
pub Kusama: AssetFilter = Wild(AllOf { fun: WildFungible, id: AssetId(KsmLocation::get()) });
pub Statemine: Location = Parachain(4).into();
pub Statemine: Location = Parachain(1000).into();
pub KusamaForStatemine: (AssetFilter, Location) = (Kusama::get(), Statemine::get());
}

Expand Down
37 changes: 32 additions & 5 deletions runtime/moonbase/tests/xcm_mock/statemint_like.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,17 @@

use frame_support::{
construct_runtime, parameter_types,
traits::{AsEnsureOriginWithArg, Contains, Everything, Nothing},
traits::{AsEnsureOriginWithArg, Contains, ContainsPair, Everything, Get, Nothing},
weights::Weight,
};
use frame_system::{EnsureRoot, EnsureSigned};

use polkadot_core_primitives::BlockNumber as RelayBlockNumber;
use sp_core::H256;
use sp_runtime::{
traits::{ConstU32, Hash, IdentityLookup},
AccountId32,
};

use polkadot_core_primitives::BlockNumber as RelayBlockNumber;

use polkadot_parachain::primitives::Id as ParaId;
use polkadot_parachain::primitives::Sibling;
use sp_std::convert::TryFrom;
Expand Down Expand Up @@ -290,8 +288,37 @@ pub type Barrier = (
parameter_types! {
pub MatcherLocation: Location = Location::here();
pub const MaxAssetsIntoHolding: u32 = 64;
pub const RelayTokenLocation: Location = Location::parent();
}

// Copied from:
//
// https://github.com/paritytech/polkadot-sdk/blob/f4eb41773611008040c9d4d8a8e6b7323eccfca1/cumulus
// /parachains/common/src/xcm_config.rs#L118
//
// without the extra check for the system parachain, because we don't need it in tests.
//
// That checks ensures that our paraId is lower than ~1900.
// If we keep it enabled our tests will fail given that our paraIds are 1, 2, 3 and so on.
Agusrodri marked this conversation as resolved.
Show resolved Hide resolved
pub struct ConcreteAssetFromSystem<AssetLocation>(sp_std::marker::PhantomData<AssetLocation>);
impl<AssetLocation: Get<Location>> ContainsPair<Asset, Location>
for ConcreteAssetFromSystem<AssetLocation>
{
fn contains(asset: &Asset, origin: &Location) -> bool {
let is_system = match origin.unpack() {
// The Relay Chain
(1, []) => true,
// System parachain
(1, [Parachain(_id)]) => false,
// Others
_ => false,
};
asset.id.0 == AssetLocation::get() && is_system
}
}

pub type TrustedTeleporters = (ConcreteAssetFromSystem<RelayTokenLocation>,);

pub struct XcmConfig;
impl Config for XcmConfig {
type RuntimeCall = RuntimeCall;
Expand All @@ -300,7 +327,7 @@ impl Config for XcmConfig {
type OriginConverter = XcmOriginToTransactDispatchOrigin;
type IsReserve =
orml_xcm_support::MultiNativeAsset<orml_traits::location::RelativeReserveProvider>;
type IsTeleporter = ();
type IsTeleporter = TrustedTeleporters;
type UniversalLocation = UniversalLocation;
type Barrier = Barrier;
type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;
Expand Down
Loading
Loading