mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 17:31:03 +00:00
Replicate e2e integration test as emulated (#2958)
* Allow functions to work over both parachains and relay chains * additional references * import * backup * refactoring para and relay traits * use runtime crates to build types * decouple ProcessMessage * decouple ProcessMessage 2 * dmp and xcmp handlers decouple * backup * refactor done * common int values working * added global ext with mutex * works for two mutex * single mutex and remove condvar * global test ext done * failing moving test_ext because relay block num * relay_block_number issue fixed * backup * Test working with assertions * assertions get Test as arg * DispatchArgs as generic * clean up * backup * teleports for asset-hub-kusama done * improve assert_expected_events macro * rename Test generics * check assertions for tuples * test assertions redone * reserve_transfer_assets done * send transact done * hrmp test for paras * hrmp channels test done * hrmp channels test done 2 * before modifying test dispatch * reserve tests done & Test dispatch fixed * reserve transfer local asset * force_create_and_mint_asset * force create and mint done * tests done * fix imports in common * common events refactored * add option to events attributes * asset-hub-polkadot tests done * asset-hub-westend half done * relay chain events move to common * remove failing send tests for asset-hub-westend * added events to bridge-hub-rococo * added events to collectives-polkadot * cargo clean up * fix asset-hub-westend tests * ".git/.scripts/commands/fmt/fmt.sh" * fix clippy * ".git/.scripts/commands/fmt/fmt.sh" * Removed unnecessary deps * Extracted some commonality for Kusama/Polkadot (which will be reused also for BridgeHubs) (#2971) * Extracted some commonality for Kusama/Polkadot (which will be reused also for BridgeHubs) * AssetHubRococo should better use AssetHubKusama runtime * add fund_account --------- Co-authored-by: NachoPal <ignacio.palacios.santos@gmail.com> * address comments * rename event assertion helpers * clean comments * address comments 2 * ".git/.scripts/commands/fmt/fmt.sh" --------- Co-authored-by: Giles Cope <gilescope@gmail.com> Co-authored-by: command-bot <> Co-authored-by: Branislav Kontur <bkontur@gmail.com>
This commit is contained in:
@@ -16,31 +16,86 @@
|
||||
|
||||
pub use codec::Encode;
|
||||
pub use frame_support::{
|
||||
assert_ok, instances::Instance1, pallet_prelude::Weight, traits::fungibles::Inspect,
|
||||
assert_err, assert_ok,
|
||||
instances::{Instance1, Instance2},
|
||||
pallet_prelude::Weight,
|
||||
sp_runtime::{AccountId32, DispatchError, DispatchResult, ModuleError, MultiAddress},
|
||||
traits::{fungibles::Inspect, OriginTrait},
|
||||
BoundedVec,
|
||||
};
|
||||
pub use integration_tests_common::{
|
||||
constants::{
|
||||
accounts::{ALICE, BOB},
|
||||
polkadot::ED as POLKADOT_ED,
|
||||
asset_hub_westend::ED as ASSET_HUB_WESTEND_ED,
|
||||
westend::ED as WESTEND_ED,
|
||||
PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V3,
|
||||
},
|
||||
AccountId, AssetHubWestend, AssetHubWestendPallet, AssetHubWestendReceiver,
|
||||
AssetHubWestendSender, Collectives, CollectivesPallet, CollectivesReceiver, CollectivesSender,
|
||||
PenpalWestend, PenpalWestendPallet, PenpalWestendReceiver, PenpalWestendSender, Westend,
|
||||
lazy_static::lazy_static,
|
||||
xcm_transact_paid_execution, xcm_transact_unpaid_execution, AssetHubWestend,
|
||||
AssetHubWestendPallet, AssetHubWestendReceiver, AssetHubWestendSender, Collectives,
|
||||
CollectivesPallet, CollectivesReceiver, CollectivesSender, PenpalWestendA,
|
||||
PenpalWestendAPallet, PenpalWestendAReceiver, PenpalWestendASender, Westend, WestendMockNet,
|
||||
WestendPallet, WestendReceiver, WestendSender,
|
||||
};
|
||||
pub use parachains_common::{AccountId, Balance};
|
||||
pub use polkadot_core_primitives::InboundDownwardMessage;
|
||||
pub use polkadot_parachain::primitives::{HrmpChannelId, Id};
|
||||
pub use polkadot_runtime_parachains::inclusion::{AggregateMessageOrigin, UmpQueueId};
|
||||
pub use xcm::{
|
||||
prelude::*,
|
||||
v3::{
|
||||
Error,
|
||||
NetworkId::{Kusama as KusamaId, Polkadot as PolkadotId},
|
||||
},
|
||||
v3::{Error, NetworkId::Westend as WestendId},
|
||||
DoubleEncoded,
|
||||
};
|
||||
pub use xcm_emulator::{
|
||||
assert_expected_events, bx, cumulus_pallet_dmp_queue, helpers::weight_within_threshold,
|
||||
Parachain as Para, RelayChain as Relay, TestExt,
|
||||
AccountId32Junction, Chain, ParaId, Parachain as Para, RelayChain as Relay, Test, TestArgs,
|
||||
TestContext, TestExt, TestExternalities,
|
||||
};
|
||||
|
||||
pub const ASSET_ID: u32 = 1;
|
||||
pub const ASSET_MIN_BALANCE: u128 = 1000;
|
||||
// `Assets` pallet index
|
||||
pub const ASSETS_PALLET_ID: u8 = 50;
|
||||
|
||||
pub type RelayToSystemParaTest = Test<Westend, AssetHubWestend>;
|
||||
pub type SystemParaToRelayTest = Test<AssetHubWestend, Westend>;
|
||||
pub type SystemParaToParaTest = Test<AssetHubWestend, PenpalWestendA>;
|
||||
|
||||
/// Returns a `TestArgs` instance to de used for the Relay Chain accross integraton tests
|
||||
pub fn relay_test_args(amount: Balance) -> TestArgs {
|
||||
TestArgs {
|
||||
dest: Westend::child_location_of(AssetHubWestend::para_id()),
|
||||
beneficiary: AccountId32Junction {
|
||||
network: None,
|
||||
id: AssetHubWestendReceiver::get().into(),
|
||||
}
|
||||
.into(),
|
||||
amount,
|
||||
assets: (Here, amount).into(),
|
||||
asset_id: None,
|
||||
fee_asset_item: 0,
|
||||
weight_limit: WeightLimit::Unlimited,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a `TestArgs` instance to de used for the System Parachain accross integraton tests
|
||||
pub fn system_para_test_args(
|
||||
dest: MultiLocation,
|
||||
beneficiary_id: AccountId32,
|
||||
amount: Balance,
|
||||
assets: MultiAssets,
|
||||
asset_id: Option<u32>,
|
||||
) -> TestArgs {
|
||||
TestArgs {
|
||||
dest,
|
||||
beneficiary: AccountId32Junction { network: None, id: beneficiary_id.into() }.into(),
|
||||
amount,
|
||||
assets,
|
||||
asset_id,
|
||||
fee_asset_item: 0,
|
||||
weight_limit: WeightLimit::Unlimited,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
+2
-1
@@ -15,6 +15,7 @@
|
||||
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
mod reserve_transfer;
|
||||
mod send;
|
||||
mod set_xcm_versions;
|
||||
mod swap;
|
||||
mod teleport;
|
||||
mod transact;
|
||||
|
||||
+389
-60
@@ -16,66 +16,395 @@
|
||||
|
||||
use crate::*;
|
||||
|
||||
#[test]
|
||||
fn reserve_transfer_native_asset_from_relay_to_assets() {
|
||||
// Init tests variables
|
||||
let amount = POLKADOT_ED * 1000;
|
||||
let relay_sender_balance_before = Westend::account_data_of(WestendSender::get()).free;
|
||||
let para_receiver_balance_before =
|
||||
AssetHubWestend::account_data_of(AssetHubWestendReceiver::get()).free;
|
||||
fn relay_origin_assertions(t: RelayToSystemParaTest) {
|
||||
type RuntimeEvent = <Westend as Chain>::RuntimeEvent;
|
||||
|
||||
let origin = <Westend as Relay>::RuntimeOrigin::signed(WestendSender::get());
|
||||
let assets_para_destination: VersionedMultiLocation =
|
||||
Westend::child_location_of(AssetHubWestend::para_id()).into();
|
||||
let beneficiary: VersionedMultiLocation =
|
||||
AccountId32 { network: None, id: AssetHubWestendReceiver::get().into() }.into();
|
||||
let native_assets: VersionedMultiAssets = (Here, amount).into();
|
||||
let fee_asset_item = 0;
|
||||
let weight_limit = WeightLimit::Unlimited;
|
||||
Westend::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(629_384_000, 6_196)));
|
||||
|
||||
// Send XCM message from Relay Chain
|
||||
Westend::execute_with(|| {
|
||||
assert_ok!(<Westend as WestendPallet>::XcmPallet::limited_reserve_transfer_assets(
|
||||
origin,
|
||||
bx!(assets_para_destination),
|
||||
bx!(beneficiary),
|
||||
bx!(native_assets),
|
||||
fee_asset_item,
|
||||
weight_limit,
|
||||
));
|
||||
|
||||
type RuntimeEvent = <Westend as Relay>::RuntimeEvent;
|
||||
|
||||
assert_expected_events!(
|
||||
Westend,
|
||||
vec![
|
||||
RuntimeEvent::XcmPallet(pallet_xcm::Event::Attempted { outcome: Outcome::Complete(weight) }) => {
|
||||
weight: weight_within_threshold((REF_TIME_THRESHOLD, PROOF_SIZE_THRESHOLD), Weight::from_parts(629_384_000, 6196), *weight),
|
||||
},
|
||||
]
|
||||
);
|
||||
});
|
||||
|
||||
// Receive XCM message in Assets Parachain
|
||||
AssetHubWestend::execute_with(|| {
|
||||
type RuntimeEvent = <AssetHubWestend as Para>::RuntimeEvent;
|
||||
|
||||
assert_expected_events!(
|
||||
AssetHubWestend,
|
||||
vec![
|
||||
RuntimeEvent::DmpQueue(cumulus_pallet_dmp_queue::Event::ExecutedDownward {
|
||||
outcome: Outcome::Incomplete(_, Error::UntrustedReserveLocation),
|
||||
..
|
||||
}) => {},
|
||||
]
|
||||
);
|
||||
});
|
||||
|
||||
// Check if balances are updated accordingly in Relay Chain and Assets Parachain
|
||||
let relay_sender_balance_after = Westend::account_data_of(WestendSender::get()).free;
|
||||
let para_sender_balance_after =
|
||||
AssetHubWestend::account_data_of(AssetHubWestendReceiver::get()).free;
|
||||
|
||||
assert_eq!(relay_sender_balance_before - amount, relay_sender_balance_after);
|
||||
assert_eq!(para_sender_balance_after, para_receiver_balance_before);
|
||||
assert_expected_events!(
|
||||
Westend,
|
||||
vec![
|
||||
// Amount to reserve transfer is transferred to System Parachain's Sovereign account
|
||||
RuntimeEvent::Balances(pallet_balances::Event::Transfer { from, to, amount }) => {
|
||||
from: *from == t.sender.account_id,
|
||||
to: *to == Westend::sovereign_account_id_of(
|
||||
t.args.dest
|
||||
),
|
||||
amount: *amount == t.args.amount,
|
||||
},
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
fn system_para_dest_assertions_incomplete(_t: RelayToSystemParaTest) {
|
||||
AssetHubWestend::assert_dmp_queue_incomplete(
|
||||
Some(Weight::from_parts(1_000_000_000, 0)),
|
||||
Some(Error::UntrustedReserveLocation),
|
||||
);
|
||||
}
|
||||
|
||||
fn system_para_to_relay_assertions(_t: SystemParaToRelayTest) {
|
||||
AssetHubWestend::assert_xcm_pallet_attempted_error(Some(XcmError::Barrier))
|
||||
}
|
||||
|
||||
fn system_para_to_para_assertions(t: SystemParaToParaTest) {
|
||||
type RuntimeEvent = <AssetHubWestend as Chain>::RuntimeEvent;
|
||||
|
||||
AssetHubWestend::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(
|
||||
676_119_000,
|
||||
6196,
|
||||
)));
|
||||
|
||||
assert_expected_events!(
|
||||
AssetHubWestend,
|
||||
vec![
|
||||
// Amount to reserve transfer is transferred to Parachain's Sovereing account
|
||||
RuntimeEvent::Balances(
|
||||
pallet_balances::Event::Transfer { from, to, amount }
|
||||
) => {
|
||||
from: *from == t.sender.account_id,
|
||||
to: *to == AssetHubWestend::sovereign_account_id_of(
|
||||
t.args.dest
|
||||
),
|
||||
amount: *amount == t.args.amount,
|
||||
},
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
fn system_para_to_para_assets_assertions(t: SystemParaToParaTest) {
|
||||
type RuntimeEvent = <AssetHubWestend as Chain>::RuntimeEvent;
|
||||
|
||||
AssetHubWestend::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(
|
||||
676_119_000,
|
||||
6196,
|
||||
)));
|
||||
|
||||
assert_expected_events!(
|
||||
AssetHubWestend,
|
||||
vec![
|
||||
// Amount to reserve transfer is transferred to Parachain's Sovereing account
|
||||
RuntimeEvent::Assets(
|
||||
pallet_assets::Event::Transferred { asset_id, from, to, amount }
|
||||
) => {
|
||||
asset_id: *asset_id == ASSET_ID,
|
||||
from: *from == t.sender.account_id,
|
||||
to: *to == AssetHubWestend::sovereign_account_id_of(
|
||||
t.args.dest
|
||||
),
|
||||
amount: *amount == t.args.amount,
|
||||
},
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
fn relay_limited_reserve_transfer_assets(t: RelayToSystemParaTest) -> DispatchResult {
|
||||
<Westend as WestendPallet>::XcmPallet::limited_reserve_transfer_assets(
|
||||
t.signed_origin,
|
||||
bx!(t.args.dest.into()),
|
||||
bx!(t.args.beneficiary.into()),
|
||||
bx!(t.args.assets.into()),
|
||||
t.args.fee_asset_item,
|
||||
t.args.weight_limit,
|
||||
)
|
||||
}
|
||||
|
||||
fn relay_reserve_transfer_assets(t: RelayToSystemParaTest) -> DispatchResult {
|
||||
<Westend as WestendPallet>::XcmPallet::reserve_transfer_assets(
|
||||
t.signed_origin,
|
||||
bx!(t.args.dest.into()),
|
||||
bx!(t.args.beneficiary.into()),
|
||||
bx!(t.args.assets.into()),
|
||||
t.args.fee_asset_item,
|
||||
)
|
||||
}
|
||||
|
||||
fn system_para_limited_reserve_transfer_assets(t: SystemParaToRelayTest) -> DispatchResult {
|
||||
<AssetHubWestend as AssetHubWestendPallet>::PolkadotXcm::limited_reserve_transfer_assets(
|
||||
t.signed_origin,
|
||||
bx!(t.args.dest.into()),
|
||||
bx!(t.args.beneficiary.into()),
|
||||
bx!(t.args.assets.into()),
|
||||
t.args.fee_asset_item,
|
||||
t.args.weight_limit,
|
||||
)
|
||||
}
|
||||
|
||||
fn system_para_reserve_transfer_assets(t: SystemParaToRelayTest) -> DispatchResult {
|
||||
<AssetHubWestend as AssetHubWestendPallet>::PolkadotXcm::reserve_transfer_assets(
|
||||
t.signed_origin,
|
||||
bx!(t.args.dest.into()),
|
||||
bx!(t.args.beneficiary.into()),
|
||||
bx!(t.args.assets.into()),
|
||||
t.args.fee_asset_item,
|
||||
)
|
||||
}
|
||||
|
||||
fn system_para_to_para_limited_reserve_transfer_assets(t: SystemParaToParaTest) -> DispatchResult {
|
||||
<AssetHubWestend as AssetHubWestendPallet>::PolkadotXcm::limited_reserve_transfer_assets(
|
||||
t.signed_origin,
|
||||
bx!(t.args.dest.into()),
|
||||
bx!(t.args.beneficiary.into()),
|
||||
bx!(t.args.assets.into()),
|
||||
t.args.fee_asset_item,
|
||||
t.args.weight_limit,
|
||||
)
|
||||
}
|
||||
|
||||
fn system_para_to_para_reserve_transfer_assets(t: SystemParaToParaTest) -> DispatchResult {
|
||||
<AssetHubWestend as AssetHubWestendPallet>::PolkadotXcm::reserve_transfer_assets(
|
||||
t.signed_origin,
|
||||
bx!(t.args.dest.into()),
|
||||
bx!(t.args.beneficiary.into()),
|
||||
bx!(t.args.assets.into()),
|
||||
t.args.fee_asset_item,
|
||||
)
|
||||
}
|
||||
|
||||
/// Limited Reserve Transfers of native asset from Relay Chain to the System Parachain shouldn't work
|
||||
#[test]
|
||||
fn limited_reserve_transfer_native_asset_from_relay_to_system_para_fails() {
|
||||
// Init values for Relay Chain
|
||||
let amount_to_send: Balance = WESTEND_ED * 1000;
|
||||
let test_args = TestContext {
|
||||
sender: WestendSender::get(),
|
||||
receiver: AssetHubWestendReceiver::get(),
|
||||
args: relay_test_args(amount_to_send),
|
||||
};
|
||||
|
||||
let mut test = RelayToSystemParaTest::new(test_args);
|
||||
|
||||
let sender_balance_before = test.sender.balance;
|
||||
let receiver_balance_before = test.receiver.balance;
|
||||
|
||||
test.set_assertion::<Westend>(relay_origin_assertions);
|
||||
test.set_assertion::<AssetHubWestend>(system_para_dest_assertions_incomplete);
|
||||
test.set_dispatchable::<Westend>(relay_limited_reserve_transfer_assets);
|
||||
test.assert();
|
||||
|
||||
let sender_balance_after = test.sender.balance;
|
||||
let receiver_balance_after = test.receiver.balance;
|
||||
|
||||
assert_eq!(sender_balance_before - amount_to_send, sender_balance_after);
|
||||
assert_eq!(receiver_balance_before, receiver_balance_after);
|
||||
}
|
||||
|
||||
/// Limited Reserve Transfers of native asset from System Parachain to Relay Chain shoudln't work
|
||||
#[test]
|
||||
fn limited_reserve_transfer_native_asset_from_system_para_to_relay_fails() {
|
||||
// Init values for System Parachain
|
||||
let destination = AssetHubWestend::parent_location();
|
||||
let beneficiary_id = WestendReceiver::get();
|
||||
let amount_to_send: Balance = ASSET_HUB_WESTEND_ED * 1000;
|
||||
let assets = (Parent, amount_to_send).into();
|
||||
|
||||
let test_args = TestContext {
|
||||
sender: AssetHubWestendSender::get(),
|
||||
receiver: WestendReceiver::get(),
|
||||
args: system_para_test_args(destination, beneficiary_id, amount_to_send, assets, None),
|
||||
};
|
||||
|
||||
let mut test = SystemParaToRelayTest::new(test_args);
|
||||
|
||||
let sender_balance_before = test.sender.balance;
|
||||
let receiver_balance_before = test.receiver.balance;
|
||||
|
||||
test.set_assertion::<AssetHubWestend>(system_para_to_relay_assertions);
|
||||
test.set_dispatchable::<AssetHubWestend>(system_para_limited_reserve_transfer_assets);
|
||||
test.assert();
|
||||
|
||||
let sender_balance_after = test.sender.balance;
|
||||
let receiver_balance_after = test.receiver.balance;
|
||||
|
||||
assert_eq!(sender_balance_before, sender_balance_after);
|
||||
assert_eq!(receiver_balance_before, receiver_balance_after);
|
||||
}
|
||||
|
||||
/// Reserve Transfers of native asset from Relay Chain to the System Parachain shouldn't work
|
||||
#[test]
|
||||
fn reserve_transfer_native_asset_from_relay_to_system_para_fails() {
|
||||
// Init values for Relay Chain
|
||||
let amount_to_send: Balance = WESTEND_ED * 1000;
|
||||
let test_args = TestContext {
|
||||
sender: WestendSender::get(),
|
||||
receiver: AssetHubWestendReceiver::get(),
|
||||
args: relay_test_args(amount_to_send),
|
||||
};
|
||||
|
||||
let mut test = RelayToSystemParaTest::new(test_args);
|
||||
|
||||
let sender_balance_before = test.sender.balance;
|
||||
let receiver_balance_before = test.receiver.balance;
|
||||
|
||||
test.set_assertion::<Westend>(relay_origin_assertions);
|
||||
test.set_assertion::<AssetHubWestend>(system_para_dest_assertions_incomplete);
|
||||
test.set_dispatchable::<Westend>(relay_reserve_transfer_assets);
|
||||
test.assert();
|
||||
|
||||
let sender_balance_after = test.sender.balance;
|
||||
let receiver_balance_after = test.receiver.balance;
|
||||
|
||||
assert_eq!(sender_balance_before - amount_to_send, sender_balance_after);
|
||||
assert_eq!(receiver_balance_before, receiver_balance_after);
|
||||
}
|
||||
|
||||
/// Reserve Transfers of native asset from System Parachain to Relay Chain shouldn't work
|
||||
#[test]
|
||||
fn reserve_transfer_native_asset_from_system_para_to_relay_fails() {
|
||||
// Init values for System Parachain
|
||||
let destination = AssetHubWestend::parent_location();
|
||||
let beneficiary_id = WestendReceiver::get();
|
||||
let amount_to_send: Balance = ASSET_HUB_WESTEND_ED * 1000;
|
||||
let assets = (Parent, amount_to_send).into();
|
||||
|
||||
let test_args = TestContext {
|
||||
sender: AssetHubWestendSender::get(),
|
||||
receiver: WestendReceiver::get(),
|
||||
args: system_para_test_args(destination, beneficiary_id, amount_to_send, assets, None),
|
||||
};
|
||||
|
||||
let mut test = SystemParaToRelayTest::new(test_args);
|
||||
|
||||
let sender_balance_before = test.sender.balance;
|
||||
let receiver_balance_before = test.receiver.balance;
|
||||
|
||||
test.set_assertion::<AssetHubWestend>(system_para_to_relay_assertions);
|
||||
test.set_dispatchable::<AssetHubWestend>(system_para_reserve_transfer_assets);
|
||||
test.assert();
|
||||
|
||||
let sender_balance_after = test.sender.balance;
|
||||
let receiver_balance_after = test.receiver.balance;
|
||||
|
||||
assert_eq!(sender_balance_before, sender_balance_after);
|
||||
assert_eq!(receiver_balance_before, receiver_balance_after);
|
||||
}
|
||||
|
||||
/// Limited Reserve Transfers of native asset from System Parachain to Parachain should work
|
||||
#[test]
|
||||
fn limited_reserve_transfer_native_asset_from_system_para_to_para() {
|
||||
// Init values for System Parachain
|
||||
let destination = AssetHubWestend::sibling_location_of(PenpalWestendA::para_id());
|
||||
let beneficiary_id = PenpalWestendAReceiver::get();
|
||||
let amount_to_send: Balance = ASSET_HUB_WESTEND_ED * 1000;
|
||||
let assets = (Parent, amount_to_send).into();
|
||||
|
||||
let test_args = TestContext {
|
||||
sender: AssetHubWestendSender::get(),
|
||||
receiver: PenpalWestendAReceiver::get(),
|
||||
args: system_para_test_args(destination, beneficiary_id, amount_to_send, assets, None),
|
||||
};
|
||||
|
||||
let mut test = SystemParaToParaTest::new(test_args);
|
||||
|
||||
let sender_balance_before = test.sender.balance;
|
||||
|
||||
test.set_assertion::<AssetHubWestend>(system_para_to_para_assertions);
|
||||
// TODO: Add assertion for Penpal runtime. Right now message is failing with `UntrustedReserveLocation`
|
||||
test.set_dispatchable::<AssetHubWestend>(system_para_to_para_limited_reserve_transfer_assets);
|
||||
test.assert();
|
||||
|
||||
let sender_balance_after = test.sender.balance;
|
||||
|
||||
assert_eq!(sender_balance_before - amount_to_send, sender_balance_after);
|
||||
// TODO: Check receiver balance when Penpal runtime is improved to propery handle reserve transfers
|
||||
}
|
||||
|
||||
/// Reserve Transfers of native asset from System Parachain to Parachain should work
|
||||
#[test]
|
||||
fn reserve_transfer_native_asset_from_system_para_to_para() {
|
||||
// Init values for System Parachain
|
||||
let destination = AssetHubWestend::sibling_location_of(PenpalWestendA::para_id());
|
||||
let beneficiary_id = PenpalWestendAReceiver::get();
|
||||
let amount_to_send: Balance = ASSET_HUB_WESTEND_ED * 1000;
|
||||
let assets = (Parent, amount_to_send).into();
|
||||
|
||||
let test_args = TestContext {
|
||||
sender: AssetHubWestendSender::get(),
|
||||
receiver: PenpalWestendAReceiver::get(),
|
||||
args: system_para_test_args(destination, beneficiary_id, amount_to_send, assets, None),
|
||||
};
|
||||
|
||||
let mut test = SystemParaToParaTest::new(test_args);
|
||||
|
||||
let sender_balance_before = test.sender.balance;
|
||||
|
||||
test.set_assertion::<AssetHubWestend>(system_para_to_para_assertions);
|
||||
// TODO: Add assertion for Penpal runtime. Right now message is failing with `UntrustedReserveLocation`
|
||||
test.set_dispatchable::<AssetHubWestend>(system_para_to_para_reserve_transfer_assets);
|
||||
test.assert();
|
||||
|
||||
let sender_balance_after = test.sender.balance;
|
||||
|
||||
assert_eq!(sender_balance_before - amount_to_send, sender_balance_after);
|
||||
// TODO: Check receiver balance when Penpal runtime is improved to propery handle reserve transfers
|
||||
}
|
||||
|
||||
/// Limited Reserve Transfers of a local asset from System Parachain to Parachain should work
|
||||
#[test]
|
||||
fn limited_reserve_transfer_asset_from_system_para_to_para() {
|
||||
// Force create asset from Relay Chain and mint assets for System Parachain's sender account
|
||||
AssetHubWestend::force_create_and_mint_asset(
|
||||
ASSET_ID,
|
||||
ASSET_MIN_BALANCE,
|
||||
true,
|
||||
AssetHubWestendSender::get(),
|
||||
ASSET_MIN_BALANCE * 1000000,
|
||||
);
|
||||
|
||||
// Init values for System Parachain
|
||||
let destination = AssetHubWestend::sibling_location_of(PenpalWestendA::para_id());
|
||||
let beneficiary_id = PenpalWestendAReceiver::get();
|
||||
let amount_to_send = ASSET_MIN_BALANCE * 1000;
|
||||
let assets =
|
||||
(X2(PalletInstance(ASSETS_PALLET_ID), GeneralIndex(ASSET_ID.into())), amount_to_send)
|
||||
.into();
|
||||
|
||||
let system_para_test_args = TestContext {
|
||||
sender: AssetHubWestendSender::get(),
|
||||
receiver: PenpalWestendAReceiver::get(),
|
||||
args: system_para_test_args(destination, beneficiary_id, amount_to_send, assets, None),
|
||||
};
|
||||
|
||||
let mut system_para_test = SystemParaToParaTest::new(system_para_test_args);
|
||||
|
||||
system_para_test.set_assertion::<AssetHubWestend>(system_para_to_para_assets_assertions);
|
||||
// TODO: Add assertions when Penpal is able to manage assets
|
||||
system_para_test
|
||||
.set_dispatchable::<AssetHubWestend>(system_para_to_para_limited_reserve_transfer_assets);
|
||||
system_para_test.assert();
|
||||
}
|
||||
|
||||
/// Reserve Transfers of a local asset from System Parachain to Parachain should work
|
||||
#[test]
|
||||
fn reserve_transfer_asset_from_system_para_to_para() {
|
||||
// Force create asset from Relay Chain and mint assets for System Parachain's sender account
|
||||
AssetHubWestend::force_create_and_mint_asset(
|
||||
ASSET_ID,
|
||||
ASSET_MIN_BALANCE,
|
||||
true,
|
||||
AssetHubWestendSender::get(),
|
||||
ASSET_MIN_BALANCE * 1000000,
|
||||
);
|
||||
|
||||
// Init values for System Parachain
|
||||
let destination = AssetHubWestend::sibling_location_of(PenpalWestendA::para_id());
|
||||
let beneficiary_id = PenpalWestendAReceiver::get();
|
||||
let amount_to_send = ASSET_MIN_BALANCE * 1000;
|
||||
let assets =
|
||||
(X2(PalletInstance(ASSETS_PALLET_ID), GeneralIndex(ASSET_ID.into())), amount_to_send)
|
||||
.into();
|
||||
|
||||
let system_para_test_args = TestContext {
|
||||
sender: AssetHubWestendSender::get(),
|
||||
receiver: PenpalWestendAReceiver::get(),
|
||||
args: system_para_test_args(destination, beneficiary_id, amount_to_send, assets, None),
|
||||
};
|
||||
|
||||
let mut system_para_test = SystemParaToParaTest::new(system_para_test_args);
|
||||
|
||||
system_para_test.set_assertion::<AssetHubWestend>(system_para_to_para_assets_assertions);
|
||||
// TODO: Add assertions when Penpal is able to manage assets
|
||||
system_para_test
|
||||
.set_dispatchable::<AssetHubWestend>(system_para_to_para_reserve_transfer_assets);
|
||||
system_para_test.assert();
|
||||
}
|
||||
|
||||
+141
@@ -0,0 +1,141 @@
|
||||
// Copyright Parity Technologies (UK) Ltd.
|
||||
// This file is part of Cumulus.
|
||||
|
||||
// Cumulus is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Cumulus is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::*;
|
||||
|
||||
/// Relay Chain should be able to execute `Transact` instructions in System Parachain
|
||||
/// when `OriginKind::Superuser` and signer is `sudo`
|
||||
#[test]
|
||||
fn send_transact_sudo_from_relay_to_system_para_works() {
|
||||
// Init tests variables
|
||||
let root_origin = <Westend as Chain>::RuntimeOrigin::root();
|
||||
let system_para_destination = Westend::child_location_of(AssetHubWestend::para_id()).into();
|
||||
let asset_owner: AccountId = AssetHubWestendSender::get().into();
|
||||
let xcm = AssetHubWestend::force_create_asset_xcm(
|
||||
OriginKind::Superuser,
|
||||
ASSET_ID,
|
||||
asset_owner.clone(),
|
||||
true,
|
||||
1000,
|
||||
);
|
||||
// Send XCM message from Relay Chain
|
||||
Westend::execute_with(|| {
|
||||
assert_ok!(<Westend as WestendPallet>::XcmPallet::send(
|
||||
root_origin,
|
||||
bx!(system_para_destination),
|
||||
bx!(xcm),
|
||||
));
|
||||
|
||||
Westend::assert_xcm_pallet_sent();
|
||||
});
|
||||
|
||||
// Receive XCM message in Assets Parachain
|
||||
AssetHubWestend::execute_with(|| {
|
||||
type RuntimeEvent = <AssetHubWestend as Chain>::RuntimeEvent;
|
||||
|
||||
AssetHubWestend::assert_dmp_queue_complete(Some(Weight::from_parts(
|
||||
1_019_445_000,
|
||||
200_000,
|
||||
)));
|
||||
|
||||
assert_expected_events!(
|
||||
AssetHubWestend,
|
||||
vec![
|
||||
RuntimeEvent::Assets(pallet_assets::Event::ForceCreated { asset_id, owner }) => {
|
||||
asset_id: *asset_id == ASSET_ID,
|
||||
owner: *owner == asset_owner,
|
||||
},
|
||||
]
|
||||
);
|
||||
|
||||
assert!(<AssetHubWestend as AssetHubWestendPallet>::Assets::asset_exists(ASSET_ID));
|
||||
});
|
||||
}
|
||||
|
||||
/// Parachain should be able to send XCM paying its fee with sufficient asset
|
||||
/// in the System Parachain
|
||||
#[test]
|
||||
fn send_xcm_from_para_to_system_para_paying_fee_with_assets_works() {
|
||||
let para_sovereign_account = AssetHubWestend::sovereign_account_id_of(
|
||||
AssetHubWestend::sibling_location_of(PenpalWestendA::para_id()),
|
||||
);
|
||||
|
||||
// Force create and mint assets for Parachain's sovereign account
|
||||
AssetHubWestend::force_create_and_mint_asset(
|
||||
ASSET_ID,
|
||||
ASSET_MIN_BALANCE,
|
||||
true,
|
||||
para_sovereign_account.clone(),
|
||||
ASSET_MIN_BALANCE * 1000000000,
|
||||
);
|
||||
|
||||
// We just need a call that can pass the `SafeCallFilter`
|
||||
// Call values are not relevant
|
||||
let call = AssetHubWestend::force_create_asset_call(
|
||||
ASSET_ID,
|
||||
para_sovereign_account.clone(),
|
||||
true,
|
||||
ASSET_MIN_BALANCE,
|
||||
);
|
||||
|
||||
let origin_kind = OriginKind::SovereignAccount;
|
||||
let fee_amount = ASSET_MIN_BALANCE * 1000000;
|
||||
let native_asset =
|
||||
(X2(PalletInstance(ASSETS_PALLET_ID), GeneralIndex(ASSET_ID.into())), fee_amount).into();
|
||||
|
||||
let root_origin = <PenpalWestendA as Chain>::RuntimeOrigin::root();
|
||||
let system_para_destination =
|
||||
PenpalWestendA::sibling_location_of(AssetHubWestend::para_id()).into();
|
||||
let xcm = xcm_transact_paid_execution(
|
||||
call,
|
||||
origin_kind,
|
||||
native_asset,
|
||||
para_sovereign_account.clone(),
|
||||
);
|
||||
|
||||
PenpalWestendA::execute_with(|| {
|
||||
assert_ok!(<PenpalWestendA as PenpalWestendAPallet>::PolkadotXcm::send(
|
||||
root_origin,
|
||||
bx!(system_para_destination),
|
||||
bx!(xcm),
|
||||
));
|
||||
|
||||
AssetHubWestend::assert_xcm_pallet_sent();
|
||||
});
|
||||
|
||||
AssetHubWestend::execute_with(|| {
|
||||
type RuntimeEvent = <AssetHubWestend as Chain>::RuntimeEvent;
|
||||
|
||||
AssetHubWestend::assert_xcmp_queue_success(Some(Weight::from_parts(
|
||||
2_176_414_000,
|
||||
203_593,
|
||||
)));
|
||||
|
||||
assert_expected_events!(
|
||||
AssetHubWestend,
|
||||
vec![
|
||||
RuntimeEvent::Assets(pallet_assets::Event::Burned { asset_id, owner, balance }) => {
|
||||
asset_id: *asset_id == ASSET_ID,
|
||||
owner: *owner == para_sovereign_account,
|
||||
balance: *balance == fee_amount,
|
||||
},
|
||||
RuntimeEvent::Assets(pallet_assets::Event::Issued { asset_id, .. }) => {
|
||||
asset_id: *asset_id == ASSET_ID,
|
||||
},
|
||||
]
|
||||
);
|
||||
});
|
||||
}
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
// Copyright Parity Technologies (UK) Ltd.
|
||||
// This file is part of Cumulus.
|
||||
|
||||
// Cumulus is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Cumulus is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::*;
|
||||
|
||||
#[test]
|
||||
fn relay_sets_system_para_xcm_supported_version() {
|
||||
// Init tests variables
|
||||
let sudo_origin = <Westend as Chain>::RuntimeOrigin::root();
|
||||
let system_para_destination: MultiLocation =
|
||||
Westend::child_location_of(AssetHubWestend::para_id());
|
||||
|
||||
// Relay Chain sets supported version for Asset Parachain
|
||||
Westend::execute_with(|| {
|
||||
assert_ok!(<Westend as WestendPallet>::XcmPallet::force_xcm_version(
|
||||
sudo_origin,
|
||||
bx!(system_para_destination),
|
||||
XCM_V3
|
||||
));
|
||||
|
||||
type RuntimeEvent = <Westend as Chain>::RuntimeEvent;
|
||||
|
||||
assert_expected_events!(
|
||||
Westend,
|
||||
vec![
|
||||
RuntimeEvent::XcmPallet(pallet_xcm::Event::SupportedVersionChanged {
|
||||
location,
|
||||
version: XCM_V3
|
||||
}) => { location: *location == system_para_destination, },
|
||||
]
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn system_para_sets_relay_xcm_supported_version() {
|
||||
// Init test variables
|
||||
let sudo_origin = <Westend as Chain>::RuntimeOrigin::root();
|
||||
let parent_location = AssetHubWestend::parent_location();
|
||||
let system_para_destination: VersionedMultiLocation =
|
||||
Westend::child_location_of(AssetHubWestend::para_id()).into();
|
||||
let call = <AssetHubWestend as Chain>::RuntimeCall::PolkadotXcm(pallet_xcm::Call::<
|
||||
<AssetHubWestend as Chain>::Runtime,
|
||||
>::force_xcm_version {
|
||||
location: bx!(parent_location),
|
||||
version: XCM_V3,
|
||||
})
|
||||
.encode()
|
||||
.into();
|
||||
let origin_kind = OriginKind::Superuser;
|
||||
|
||||
let xcm = xcm_transact_unpaid_execution(call, origin_kind);
|
||||
|
||||
// System Parachain sets supported version for Relay Chain throught it
|
||||
Westend::execute_with(|| {
|
||||
assert_ok!(<Westend as WestendPallet>::XcmPallet::send(
|
||||
sudo_origin,
|
||||
bx!(system_para_destination),
|
||||
bx!(xcm),
|
||||
));
|
||||
|
||||
Westend::assert_xcm_pallet_sent();
|
||||
});
|
||||
|
||||
// System Parachain receive the XCM message
|
||||
AssetHubWestend::execute_with(|| {
|
||||
type RuntimeEvent = <AssetHubWestend as Chain>::RuntimeEvent;
|
||||
|
||||
AssetHubWestend::assert_dmp_queue_complete(Some(Weight::from_parts(
|
||||
1_019_210_000,
|
||||
200_000,
|
||||
)));
|
||||
|
||||
assert_expected_events!(
|
||||
AssetHubWestend,
|
||||
vec![
|
||||
RuntimeEvent::PolkadotXcm(pallet_xcm::Event::SupportedVersionChanged {
|
||||
location,
|
||||
version: XCM_V3
|
||||
}) => { location: *location == parent_location, },
|
||||
]
|
||||
);
|
||||
});
|
||||
}
|
||||
+35
-43
@@ -1,23 +1,18 @@
|
||||
use crate::*;
|
||||
use frame_support::{instances::Instance2, BoundedVec};
|
||||
use sp_runtime::{DispatchError, ModuleError};
|
||||
use xcm_emulator::Parachain;
|
||||
|
||||
#[test]
|
||||
fn swap_locally_on_chain_using_local_assets() {
|
||||
const ASSET_ID: u32 = 1;
|
||||
|
||||
let asset_native = Box::new(asset_hub_westend_runtime::xcm_config::WestendLocation::get());
|
||||
let asset_one = Box::new(MultiLocation {
|
||||
parents: 0,
|
||||
interior: X2(PalletInstance(50), GeneralIndex(ASSET_ID.into())),
|
||||
interior: X2(PalletInstance(ASSETS_PALLET_ID), GeneralIndex(ASSET_ID.into())),
|
||||
});
|
||||
|
||||
AssetHubWestend::execute_with(|| {
|
||||
type RuntimeEvent = <AssetHubWestend as Parachain>::RuntimeEvent;
|
||||
type RuntimeEvent = <AssetHubWestend as Chain>::RuntimeEvent;
|
||||
|
||||
assert_ok!(<AssetHubWestend as AssetHubWestendPallet>::Assets::create(
|
||||
<AssetHubWestend as Parachain>::RuntimeOrigin::signed(AssetHubWestendSender::get()),
|
||||
<AssetHubWestend as Chain>::RuntimeOrigin::signed(AssetHubWestendSender::get()),
|
||||
ASSET_ID.into(),
|
||||
AssetHubWestendSender::get().into(),
|
||||
1000,
|
||||
@@ -25,14 +20,14 @@ fn swap_locally_on_chain_using_local_assets() {
|
||||
assert!(<AssetHubWestend as AssetHubWestendPallet>::Assets::asset_exists(ASSET_ID));
|
||||
|
||||
assert_ok!(<AssetHubWestend as AssetHubWestendPallet>::Assets::mint(
|
||||
<AssetHubWestend as Parachain>::RuntimeOrigin::signed(AssetHubWestendSender::get()),
|
||||
<AssetHubWestend as Chain>::RuntimeOrigin::signed(AssetHubWestendSender::get()),
|
||||
ASSET_ID.into(),
|
||||
AssetHubWestendSender::get().into(),
|
||||
3_000_000_000_000,
|
||||
));
|
||||
|
||||
assert_ok!(<AssetHubWestend as AssetHubWestendPallet>::AssetConversion::create_pool(
|
||||
<AssetHubWestend as Parachain>::RuntimeOrigin::signed(AssetHubWestendSender::get()),
|
||||
<AssetHubWestend as Chain>::RuntimeOrigin::signed(AssetHubWestendSender::get()),
|
||||
asset_native.clone(),
|
||||
asset_one.clone(),
|
||||
));
|
||||
@@ -45,7 +40,7 @@ fn swap_locally_on_chain_using_local_assets() {
|
||||
);
|
||||
|
||||
assert_ok!(<AssetHubWestend as AssetHubWestendPallet>::AssetConversion::add_liquidity(
|
||||
<AssetHubWestend as Parachain>::RuntimeOrigin::signed(AssetHubWestendSender::get()),
|
||||
<AssetHubWestend as Chain>::RuntimeOrigin::signed(AssetHubWestendSender::get()),
|
||||
asset_native.clone(),
|
||||
asset_one.clone(),
|
||||
1_000_000_000_000,
|
||||
@@ -65,7 +60,7 @@ fn swap_locally_on_chain_using_local_assets() {
|
||||
let path = BoundedVec::<_, _>::truncate_from(vec![asset_native.clone(), asset_one.clone()]);
|
||||
|
||||
assert_ok!(<AssetHubWestend as AssetHubWestendPallet>::AssetConversion::swap_exact_tokens_for_tokens(
|
||||
<AssetHubWestend as Parachain>::RuntimeOrigin::signed(AssetHubWestendSender::get()),
|
||||
<AssetHubWestend as Chain>::RuntimeOrigin::signed(AssetHubWestendSender::get()),
|
||||
path,
|
||||
100,
|
||||
1,
|
||||
@@ -84,7 +79,7 @@ fn swap_locally_on_chain_using_local_assets() {
|
||||
);
|
||||
|
||||
assert_ok!(<AssetHubWestend as AssetHubWestendPallet>::AssetConversion::remove_liquidity(
|
||||
<AssetHubWestend as Parachain>::RuntimeOrigin::signed(AssetHubWestendSender::get()),
|
||||
<AssetHubWestend as Chain>::RuntimeOrigin::signed(AssetHubWestendSender::get()),
|
||||
asset_native,
|
||||
asset_one,
|
||||
1414213562273 - 2_000_000_000, // all but the 2 EDs can't be retrieved.
|
||||
@@ -99,14 +94,13 @@ fn swap_locally_on_chain_using_local_assets() {
|
||||
fn swap_locally_on_chain_using_foreign_assets() {
|
||||
use frame_support::weights::WeightToFee;
|
||||
|
||||
const ASSET_ID: u32 = 1;
|
||||
let asset_native = Box::new(asset_hub_westend_runtime::xcm_config::WestendLocation::get());
|
||||
|
||||
let foreign_asset1_at_asset_hub_westend = Box::new(MultiLocation {
|
||||
parents: 1,
|
||||
interior: X3(
|
||||
Parachain(PenpalWestend::para_id().into()),
|
||||
PalletInstance(50),
|
||||
Parachain(PenpalWestendA::para_id().into()),
|
||||
PalletInstance(ASSETS_PALLET_ID),
|
||||
GeneralIndex(ASSET_ID.into()),
|
||||
),
|
||||
});
|
||||
@@ -116,18 +110,18 @@ fn swap_locally_on_chain_using_foreign_assets() {
|
||||
.into();
|
||||
|
||||
let penpal_location =
|
||||
MultiLocation { parents: 1, interior: X1(Parachain(PenpalWestend::para_id().into())) };
|
||||
MultiLocation { parents: 1, interior: X1(Parachain(PenpalWestendA::para_id().into())) };
|
||||
|
||||
// 1. Create asset on penpal:
|
||||
PenpalWestend::execute_with(|| {
|
||||
assert_ok!(<PenpalWestend as PenpalWestendPallet>::Assets::create(
|
||||
<PenpalWestend as Parachain>::RuntimeOrigin::signed(PenpalWestendSender::get()),
|
||||
PenpalWestendA::execute_with(|| {
|
||||
assert_ok!(<PenpalWestendA as PenpalWestendAPallet>::Assets::create(
|
||||
<PenpalWestendA as Chain>::RuntimeOrigin::signed(PenpalWestendASender::get()),
|
||||
ASSET_ID.into(),
|
||||
PenpalWestendSender::get().into(),
|
||||
PenpalWestendASender::get().into(),
|
||||
1000,
|
||||
));
|
||||
|
||||
assert!(<PenpalWestend as PenpalWestendPallet>::Assets::asset_exists(ASSET_ID));
|
||||
assert!(<PenpalWestendA as PenpalWestendAPallet>::Assets::asset_exists(ASSET_ID));
|
||||
});
|
||||
|
||||
// 2. Create foreign asset on asset_hub_westend:
|
||||
@@ -137,21 +131,21 @@ fn swap_locally_on_chain_using_foreign_assets() {
|
||||
let sov_penpal_on_asset_hub_westend = AssetHubWestend::sovereign_account_id_of(penpal_location);
|
||||
|
||||
AssetHubWestend::fund_accounts(vec![
|
||||
(AssetHubWestendSender::get(), 5_000_000), // An account to swap dot for something else.
|
||||
(sov_penpal_on_asset_hub_westend.clone(), 1000_000_000_000_000_000),
|
||||
(AssetHubWestendSender::get().into(), 5_000_000 * WESTEND_ED),
|
||||
(sov_penpal_on_asset_hub_westend.clone().into(), 1000_000_000_000_000_000 * WESTEND_ED),
|
||||
]);
|
||||
|
||||
let sov_penpal_on_asset_hub_westend_as_location: MultiLocation = MultiLocation {
|
||||
parents: 0,
|
||||
interior: X1(AccountId32 {
|
||||
interior: X1(AccountId32Junction {
|
||||
network: None,
|
||||
id: sov_penpal_on_asset_hub_westend.clone().into(),
|
||||
}),
|
||||
};
|
||||
|
||||
let call_foreign_assets_create =
|
||||
<AssetHubWestend as Para>::RuntimeCall::ForeignAssets(pallet_assets::Call::<
|
||||
<AssetHubWestend as Para>::Runtime,
|
||||
<AssetHubWestend as Chain>::RuntimeCall::ForeignAssets(pallet_assets::Call::<
|
||||
<AssetHubWestend as Chain>::Runtime,
|
||||
Instance2,
|
||||
>::create {
|
||||
id: *foreign_asset1_at_asset_hub_westend,
|
||||
@@ -183,18 +177,18 @@ fn swap_locally_on_chain_using_foreign_assets() {
|
||||
]));
|
||||
|
||||
// Send XCM message from penpal => asset_hub_westend
|
||||
let sudo_penpal_origin = <PenpalWestend as Parachain>::RuntimeOrigin::root();
|
||||
PenpalWestend::execute_with(|| {
|
||||
assert_ok!(<PenpalWestend as PenpalWestendPallet>::PolkadotXcm::send(
|
||||
let sudo_penpal_origin = <PenpalWestendA as Chain>::RuntimeOrigin::root();
|
||||
PenpalWestendA::execute_with(|| {
|
||||
assert_ok!(<PenpalWestendA as PenpalWestendAPallet>::PolkadotXcm::send(
|
||||
sudo_penpal_origin.clone(),
|
||||
bx!(assets_para_destination.clone()),
|
||||
bx!(xcm),
|
||||
));
|
||||
|
||||
type RuntimeEvent = <PenpalWestend as Parachain>::RuntimeEvent;
|
||||
type RuntimeEvent = <PenpalWestendA as Chain>::RuntimeEvent;
|
||||
|
||||
assert_expected_events!(
|
||||
PenpalWestend,
|
||||
PenpalWestendA,
|
||||
vec![
|
||||
RuntimeEvent::PolkadotXcm(pallet_xcm::Event::Sent { .. }) => {},
|
||||
]
|
||||
@@ -212,10 +206,10 @@ fn swap_locally_on_chain_using_foreign_assets() {
|
||||
// (While it might be nice to use batch,
|
||||
// currently that's disabled due to safe call filters.)
|
||||
|
||||
type RuntimeEvent = <AssetHubWestend as Parachain>::RuntimeEvent;
|
||||
type RuntimeEvent = <AssetHubWestend as Chain>::RuntimeEvent;
|
||||
// 3. Mint foreign asset (in reality this should be a teleport or some such)
|
||||
assert_ok!(<AssetHubWestend as AssetHubWestendPallet>::ForeignAssets::mint(
|
||||
<AssetHubWestend as Parachain>::RuntimeOrigin::signed(
|
||||
<AssetHubWestend as Chain>::RuntimeOrigin::signed(
|
||||
sov_penpal_on_asset_hub_westend.clone().into()
|
||||
),
|
||||
*foreign_asset1_at_asset_hub_westend,
|
||||
@@ -232,7 +226,7 @@ fn swap_locally_on_chain_using_foreign_assets() {
|
||||
|
||||
// 4. Create pool:
|
||||
assert_ok!(<AssetHubWestend as AssetHubWestendPallet>::AssetConversion::create_pool(
|
||||
<AssetHubWestend as Parachain>::RuntimeOrigin::signed(AssetHubWestendSender::get()),
|
||||
<AssetHubWestend as Chain>::RuntimeOrigin::signed(AssetHubWestendSender::get()),
|
||||
asset_native.clone(),
|
||||
foreign_asset1_at_asset_hub_westend.clone(),
|
||||
));
|
||||
@@ -246,7 +240,7 @@ fn swap_locally_on_chain_using_foreign_assets() {
|
||||
|
||||
// 5. Add liquidity:
|
||||
assert_ok!(<AssetHubWestend as AssetHubWestendPallet>::AssetConversion::add_liquidity(
|
||||
<AssetHubWestend as Parachain>::RuntimeOrigin::signed(
|
||||
<AssetHubWestend as Chain>::RuntimeOrigin::signed(
|
||||
sov_penpal_on_asset_hub_westend.clone()
|
||||
),
|
||||
asset_native.clone(),
|
||||
@@ -274,7 +268,7 @@ fn swap_locally_on_chain_using_foreign_assets() {
|
||||
]);
|
||||
|
||||
assert_ok!(<AssetHubWestend as AssetHubWestendPallet>::AssetConversion::swap_exact_tokens_for_tokens(
|
||||
<AssetHubWestend as Parachain>::RuntimeOrigin::signed(AssetHubWestendSender::get()),
|
||||
<AssetHubWestend as Chain>::RuntimeOrigin::signed(AssetHubWestendSender::get()),
|
||||
path,
|
||||
100000,
|
||||
1000,
|
||||
@@ -294,7 +288,7 @@ fn swap_locally_on_chain_using_foreign_assets() {
|
||||
|
||||
// 7. Remove liquidity
|
||||
assert_ok!(<AssetHubWestend as AssetHubWestendPallet>::AssetConversion::remove_liquidity(
|
||||
<AssetHubWestend as Parachain>::RuntimeOrigin::signed(
|
||||
<AssetHubWestend as Chain>::RuntimeOrigin::signed(
|
||||
sov_penpal_on_asset_hub_westend.clone()
|
||||
),
|
||||
asset_native,
|
||||
@@ -309,8 +303,6 @@ fn swap_locally_on_chain_using_foreign_assets() {
|
||||
|
||||
#[test]
|
||||
fn cannot_create_pool_from_pool_assets() {
|
||||
const ASSET_ID: u32 = 1;
|
||||
|
||||
let asset_native = Box::new(asset_hub_westend_runtime::xcm_config::WestendLocation::get());
|
||||
let mut asset_one = asset_hub_westend_runtime::xcm_config::PoolAssetsPalletLocation::get();
|
||||
asset_one.append_with(GeneralIndex(ASSET_ID.into())).expect("pool assets");
|
||||
@@ -319,7 +311,7 @@ fn cannot_create_pool_from_pool_assets() {
|
||||
let pool_owner_account_id = asset_hub_westend_runtime::AssetConversionOrigin::get();
|
||||
|
||||
assert_ok!(<AssetHubWestend as AssetHubWestendPallet>::PoolAssets::create(
|
||||
<AssetHubWestend as Parachain>::RuntimeOrigin::signed(pool_owner_account_id.clone()),
|
||||
<AssetHubWestend as Chain>::RuntimeOrigin::signed(pool_owner_account_id.clone()),
|
||||
ASSET_ID.into(),
|
||||
pool_owner_account_id.clone().into(),
|
||||
1000,
|
||||
@@ -327,7 +319,7 @@ fn cannot_create_pool_from_pool_assets() {
|
||||
assert!(<AssetHubWestend as AssetHubWestendPallet>::PoolAssets::asset_exists(ASSET_ID));
|
||||
|
||||
assert_ok!(<AssetHubWestend as AssetHubWestendPallet>::PoolAssets::mint(
|
||||
<AssetHubWestend as Parachain>::RuntimeOrigin::signed(pool_owner_account_id),
|
||||
<AssetHubWestend as Chain>::RuntimeOrigin::signed(pool_owner_account_id),
|
||||
ASSET_ID.into(),
|
||||
AssetHubWestendSender::get().into(),
|
||||
3_000_000_000_000,
|
||||
@@ -335,7 +327,7 @@ fn cannot_create_pool_from_pool_assets() {
|
||||
|
||||
assert_matches::assert_matches!(
|
||||
<AssetHubWestend as AssetHubWestendPallet>::AssetConversion::create_pool(
|
||||
<AssetHubWestend as Parachain>::RuntimeOrigin::signed(AssetHubWestendSender::get()),
|
||||
<AssetHubWestend as Chain>::RuntimeOrigin::signed(AssetHubWestendSender::get()),
|
||||
asset_native.clone(),
|
||||
Box::new(asset_one),
|
||||
),
|
||||
|
||||
+341
-57
@@ -16,63 +16,347 @@
|
||||
|
||||
use crate::*;
|
||||
|
||||
#[test]
|
||||
fn teleport_native_assets_from_relay_to_assets_para() {
|
||||
// Init tests variables
|
||||
let amount = POLKADOT_ED * 1000;
|
||||
let relay_sender_balance_before = Westend::account_data_of(WestendSender::get()).free;
|
||||
let para_receiver_balance_before =
|
||||
AssetHubWestend::account_data_of(AssetHubWestendReceiver::get()).free;
|
||||
fn relay_origin_assertions(t: RelayToSystemParaTest) {
|
||||
type RuntimeEvent = <Westend as Chain>::RuntimeEvent;
|
||||
|
||||
let origin = <Westend as Relay>::RuntimeOrigin::signed(WestendSender::get());
|
||||
let assets_para_destination: VersionedMultiLocation =
|
||||
Westend::child_location_of(AssetHubWestend::para_id()).into();
|
||||
let beneficiary: VersionedMultiLocation =
|
||||
AccountId32 { network: None, id: AssetHubWestendReceiver::get().into() }.into();
|
||||
let native_assets: VersionedMultiAssets = (Here, amount).into();
|
||||
let fee_asset_item = 0;
|
||||
let weight_limit = WeightLimit::Unlimited;
|
||||
Westend::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(632_207_000, 7_186)));
|
||||
|
||||
// Send XCM message from Relay Chain
|
||||
Westend::execute_with(|| {
|
||||
assert_ok!(<Westend as WestendPallet>::XcmPallet::limited_teleport_assets(
|
||||
origin,
|
||||
bx!(assets_para_destination),
|
||||
bx!(beneficiary),
|
||||
bx!(native_assets),
|
||||
fee_asset_item,
|
||||
weight_limit,
|
||||
));
|
||||
|
||||
type RuntimeEvent = <Westend as Relay>::RuntimeEvent;
|
||||
|
||||
assert_expected_events!(
|
||||
Westend,
|
||||
vec![
|
||||
RuntimeEvent::XcmPallet(pallet_xcm::Event::Attempted { outcome: Outcome::Complete { .. } }) => {},
|
||||
]
|
||||
);
|
||||
});
|
||||
|
||||
// Receive XCM message in Assets Parachain
|
||||
AssetHubWestend::execute_with(|| {
|
||||
type RuntimeEvent = <AssetHubWestend as Para>::RuntimeEvent;
|
||||
|
||||
assert_expected_events!(
|
||||
AssetHubWestend,
|
||||
vec![
|
||||
RuntimeEvent::Balances(pallet_balances::Event::Deposit { who, .. }) => {
|
||||
who: *who == AssetHubWestendReceiver::get().into(),
|
||||
},
|
||||
]
|
||||
);
|
||||
});
|
||||
|
||||
// Check if balances are updated accordingly in Relay Chain and Assets Parachain
|
||||
let relay_sender_balance_after = Westend::account_data_of(WestendSender::get()).free;
|
||||
let para_sender_balance_after =
|
||||
AssetHubWestend::account_data_of(AssetHubWestendReceiver::get()).free;
|
||||
|
||||
assert_eq!(relay_sender_balance_before - amount, relay_sender_balance_after);
|
||||
assert!(para_sender_balance_after > para_receiver_balance_before);
|
||||
assert_expected_events!(
|
||||
Westend,
|
||||
vec![
|
||||
// Amount to teleport is withdrawn from Sender
|
||||
RuntimeEvent::Balances(pallet_balances::Event::Withdraw { who, amount }) => {
|
||||
who: *who == t.sender.account_id,
|
||||
amount: *amount == t.args.amount,
|
||||
},
|
||||
// Amount to teleport is deposited in Relay's `CheckAccount`
|
||||
RuntimeEvent::Balances(pallet_balances::Event::Deposit { who, amount }) => {
|
||||
who: *who == <Westend as WestendPallet>::XcmPallet::check_account(),
|
||||
amount: *amount == t.args.amount,
|
||||
},
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
fn relay_dest_assertions(t: SystemParaToRelayTest) {
|
||||
type RuntimeEvent = <Westend as Chain>::RuntimeEvent;
|
||||
|
||||
Westend::assert_ump_queue_processed(
|
||||
true,
|
||||
Some(AssetHubWestend::para_id()),
|
||||
Some(Weight::from_parts(308_222_000, 7_186)),
|
||||
);
|
||||
|
||||
assert_expected_events!(
|
||||
Westend,
|
||||
vec![
|
||||
// Amount is witdrawn from Relay Chain's `CheckAccount`
|
||||
RuntimeEvent::Balances(pallet_balances::Event::Withdraw { who, amount }) => {
|
||||
who: *who == <Westend as WestendPallet>::XcmPallet::check_account(),
|
||||
amount: *amount == t.args.amount,
|
||||
},
|
||||
// Amount minus fees are deposited in Receiver's account
|
||||
RuntimeEvent::Balances(pallet_balances::Event::Deposit { who, .. }) => {
|
||||
who: *who == t.receiver.account_id,
|
||||
},
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
fn relay_dest_assertions_fail(_t: SystemParaToRelayTest) {
|
||||
Westend::assert_ump_queue_processed(
|
||||
false,
|
||||
Some(AssetHubWestend::para_id()),
|
||||
Some(Weight::from_parts(148_705_000, 3_593)),
|
||||
);
|
||||
}
|
||||
|
||||
fn para_origin_assertions(t: SystemParaToRelayTest) {
|
||||
type RuntimeEvent = <AssetHubWestend as Chain>::RuntimeEvent;
|
||||
|
||||
AssetHubWestend::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(
|
||||
533_910_000,
|
||||
7167,
|
||||
)));
|
||||
|
||||
AssetHubWestend::assert_parachain_system_ump_sent();
|
||||
|
||||
assert_expected_events!(
|
||||
AssetHubWestend,
|
||||
vec![
|
||||
// Amount is withdrawn from Sender's account
|
||||
RuntimeEvent::Balances(pallet_balances::Event::Withdraw { who, amount }) => {
|
||||
who: *who == t.sender.account_id,
|
||||
amount: *amount == t.args.amount,
|
||||
},
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
fn para_dest_assertions(t: RelayToSystemParaTest) {
|
||||
type RuntimeEvent = <AssetHubWestend as Chain>::RuntimeEvent;
|
||||
|
||||
AssetHubWestend::assert_dmp_queue_complete(Some(Weight::from_parts(164_733_000, 0)));
|
||||
|
||||
assert_expected_events!(
|
||||
AssetHubWestend,
|
||||
vec![
|
||||
// Amount minus fees are deposited in Receiver's account
|
||||
RuntimeEvent::Balances(pallet_balances::Event::Deposit { who, .. }) => {
|
||||
who: *who == t.receiver.account_id,
|
||||
},
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
fn relay_limited_teleport_assets(t: RelayToSystemParaTest) -> DispatchResult {
|
||||
<Westend as WestendPallet>::XcmPallet::limited_teleport_assets(
|
||||
t.signed_origin,
|
||||
bx!(t.args.dest.into()),
|
||||
bx!(t.args.beneficiary.into()),
|
||||
bx!(t.args.assets.into()),
|
||||
t.args.fee_asset_item,
|
||||
t.args.weight_limit,
|
||||
)
|
||||
}
|
||||
|
||||
fn relay_teleport_assets(t: RelayToSystemParaTest) -> DispatchResult {
|
||||
<Westend as WestendPallet>::XcmPallet::teleport_assets(
|
||||
t.signed_origin,
|
||||
bx!(t.args.dest.into()),
|
||||
bx!(t.args.beneficiary.into()),
|
||||
bx!(t.args.assets.into()),
|
||||
t.args.fee_asset_item,
|
||||
)
|
||||
}
|
||||
|
||||
fn system_para_limited_teleport_assets(t: SystemParaToRelayTest) -> DispatchResult {
|
||||
<AssetHubWestend as AssetHubWestendPallet>::PolkadotXcm::limited_teleport_assets(
|
||||
t.signed_origin,
|
||||
bx!(t.args.dest.into()),
|
||||
bx!(t.args.beneficiary.into()),
|
||||
bx!(t.args.assets.into()),
|
||||
t.args.fee_asset_item,
|
||||
t.args.weight_limit,
|
||||
)
|
||||
}
|
||||
|
||||
// TODO: Uncomment when https://github.com/paritytech/polkadot/pull/7424 is merged
|
||||
// fn system_para_teleport_assets(t: SystemParaToRelayTest) -> DispatchResult {
|
||||
// <AssetHubWestend as AssetHubWestendPallet>::PolkadotXcm::teleport_assets(
|
||||
// t.signed_origin,
|
||||
// bx!(t.args.dest),
|
||||
// bx!(t.args.beneficiary),
|
||||
// bx!(t.args.assets),
|
||||
// t.args.fee_asset_item,
|
||||
// )
|
||||
// }
|
||||
|
||||
/// Limited Teleport of native asset from Relay Chain to the System Parachain should work
|
||||
#[test]
|
||||
fn limited_teleport_native_assets_from_relay_to_system_para_works() {
|
||||
// Init values for Relay Chain
|
||||
let amount_to_send: Balance = WESTEND_ED * 1000;
|
||||
let test_args = TestContext {
|
||||
sender: WestendSender::get(),
|
||||
receiver: AssetHubWestendReceiver::get(),
|
||||
args: relay_test_args(amount_to_send),
|
||||
};
|
||||
|
||||
let mut test = RelayToSystemParaTest::new(test_args);
|
||||
|
||||
let sender_balance_before = test.sender.balance;
|
||||
let receiver_balance_before = test.receiver.balance;
|
||||
|
||||
test.set_assertion::<Westend>(relay_origin_assertions);
|
||||
test.set_assertion::<AssetHubWestend>(para_dest_assertions);
|
||||
test.set_dispatchable::<Westend>(relay_limited_teleport_assets);
|
||||
test.assert();
|
||||
|
||||
let sender_balance_after = test.sender.balance;
|
||||
let receiver_balance_after = test.receiver.balance;
|
||||
|
||||
// Sender's balance is reduced
|
||||
assert_eq!(sender_balance_before - amount_to_send, sender_balance_after);
|
||||
// Receiver's balance is increased
|
||||
assert!(receiver_balance_after > receiver_balance_before);
|
||||
}
|
||||
|
||||
/// Limited Teleport of native asset from System Parachain to Relay Chain
|
||||
/// should work when there is enough balance in Relay Chain's `CheckAccount`
|
||||
#[test]
|
||||
fn limited_teleport_native_assets_back_from_system_para_to_relay_works() {
|
||||
// Dependency - Relay Chain's `CheckAccount` should have enough balance
|
||||
limited_teleport_native_assets_from_relay_to_system_para_works();
|
||||
|
||||
// Init values for Relay Chain
|
||||
let amount_to_send: Balance = ASSET_HUB_WESTEND_ED * 1000;
|
||||
let destination = AssetHubWestend::parent_location();
|
||||
let beneficiary_id = WestendReceiver::get();
|
||||
let assets = (Parent, amount_to_send).into();
|
||||
|
||||
let test_args = TestContext {
|
||||
sender: AssetHubWestendSender::get(),
|
||||
receiver: WestendReceiver::get(),
|
||||
args: system_para_test_args(destination, beneficiary_id, amount_to_send, assets, None),
|
||||
};
|
||||
|
||||
let mut test = SystemParaToRelayTest::new(test_args);
|
||||
|
||||
let sender_balance_before = test.sender.balance;
|
||||
let receiver_balance_before = test.receiver.balance;
|
||||
|
||||
test.set_assertion::<AssetHubWestend>(para_origin_assertions);
|
||||
test.set_assertion::<Westend>(relay_dest_assertions);
|
||||
test.set_dispatchable::<AssetHubWestend>(system_para_limited_teleport_assets);
|
||||
test.assert();
|
||||
|
||||
let sender_balance_after = test.sender.balance;
|
||||
let receiver_balance_after = test.receiver.balance;
|
||||
|
||||
// Sender's balance is reduced
|
||||
assert_eq!(sender_balance_before - amount_to_send, sender_balance_after);
|
||||
// Receiver's balance is increased
|
||||
assert!(receiver_balance_after > receiver_balance_before);
|
||||
}
|
||||
|
||||
/// Limited Teleport of native asset from System Parachain to Relay Chain
|
||||
/// should't work when there is not enough balance in Relay Chain's `CheckAccount`
|
||||
#[test]
|
||||
fn limited_teleport_native_assets_from_system_para_to_relay_fails() {
|
||||
// Init values for Relay Chain
|
||||
let amount_to_send: Balance = ASSET_HUB_WESTEND_ED * 1000;
|
||||
let destination = AssetHubWestend::parent_location().into();
|
||||
let beneficiary_id = WestendReceiver::get().into();
|
||||
let assets = (Parent, amount_to_send).into();
|
||||
|
||||
let test_args = TestContext {
|
||||
sender: AssetHubWestendSender::get(),
|
||||
receiver: WestendReceiver::get(),
|
||||
args: system_para_test_args(destination, beneficiary_id, amount_to_send, assets, None),
|
||||
};
|
||||
|
||||
let mut test = SystemParaToRelayTest::new(test_args);
|
||||
|
||||
let sender_balance_before = test.sender.balance;
|
||||
let receiver_balance_before = test.receiver.balance;
|
||||
|
||||
test.set_assertion::<AssetHubWestend>(para_origin_assertions);
|
||||
test.set_assertion::<Westend>(relay_dest_assertions_fail);
|
||||
test.set_dispatchable::<AssetHubWestend>(system_para_limited_teleport_assets);
|
||||
test.assert();
|
||||
|
||||
let sender_balance_after = test.sender.balance;
|
||||
let receiver_balance_after = test.receiver.balance;
|
||||
|
||||
// Sender's balance is reduced
|
||||
assert_eq!(sender_balance_before - amount_to_send, sender_balance_after);
|
||||
// Receiver's balance does not change
|
||||
assert_eq!(receiver_balance_after, receiver_balance_before);
|
||||
}
|
||||
|
||||
/// Teleport of native asset from Relay Chain to the System Parachain should work
|
||||
#[test]
|
||||
fn teleport_native_assets_from_relay_to_system_para_works() {
|
||||
// Init values for Relay Chain
|
||||
let amount_to_send: Balance = WESTEND_ED * 1000;
|
||||
let test_args = TestContext {
|
||||
sender: WestendSender::get(),
|
||||
receiver: AssetHubWestendReceiver::get(),
|
||||
args: relay_test_args(amount_to_send),
|
||||
};
|
||||
|
||||
let mut test = RelayToSystemParaTest::new(test_args);
|
||||
|
||||
let sender_balance_before = test.sender.balance;
|
||||
let receiver_balance_before = test.receiver.balance;
|
||||
|
||||
test.set_assertion::<Westend>(relay_origin_assertions);
|
||||
test.set_assertion::<AssetHubWestend>(para_dest_assertions);
|
||||
test.set_dispatchable::<Westend>(relay_teleport_assets);
|
||||
test.assert();
|
||||
|
||||
let sender_balance_after = test.sender.balance;
|
||||
let receiver_balance_after = test.receiver.balance;
|
||||
|
||||
// Sender's balance is reduced
|
||||
assert_eq!(sender_balance_before - amount_to_send, sender_balance_after);
|
||||
// Receiver's balance is increased
|
||||
assert!(receiver_balance_after > receiver_balance_before);
|
||||
}
|
||||
|
||||
// TODO: Uncomment when https://github.com/paritytech/polkadot/pull/7424 is merged
|
||||
|
||||
// Right now it is failing in the Relay Chain with a
|
||||
// `messageQueue.ProcessingFailed` event `error: Unsupported`.
|
||||
// The reason is the `Weigher` in `pallet_xcm` is not properly calculating the `remote_weight`
|
||||
// and it cause an `Overweight` error in `AllowTopLevelPaidExecutionFrom` barrier
|
||||
|
||||
// /// Teleport of native asset from System Parachains to the Relay Chain
|
||||
// /// should work when there is enough balance in Relay Chain's `CheckAccount`
|
||||
// #[test]
|
||||
// fn teleport_native_assets_back_from_system_para_to_relay_works() {
|
||||
// // Dependency - Relay Chain's `CheckAccount` should have enough balance
|
||||
// teleport_native_assets_from_relay_to_system_para_works();
|
||||
|
||||
// // Init values for Relay Chain
|
||||
// let amount_to_send: Balance = ASSET_HUB_WESTEND_ED * 1000;
|
||||
// let test_args = TestContext {
|
||||
// sender: AssetHubWestendSender::get(),
|
||||
// receiver: WestendReceiver::get(),
|
||||
// args: get_para_dispatch_args(amount_to_send),
|
||||
// };
|
||||
|
||||
// let mut test = SystemParaToRelayTest::new(test_args);
|
||||
|
||||
// let sender_balance_before = test.sender.balance;
|
||||
// let receiver_balance_before = test.receiver.balance;
|
||||
|
||||
// test.set_assertion::<AssetHubWestend>(para_origin_assertions);
|
||||
// test.set_assertion::<Westend>(relay_dest_assertions);
|
||||
// test.set_dispatchable::<AssetHubWestend>(system_para_teleport_assets);
|
||||
// test.assert();
|
||||
|
||||
// let sender_balance_after = test.sender.balance;
|
||||
// let receiver_balance_after = test.receiver.balance;
|
||||
|
||||
// // Sender's balance is reduced
|
||||
// assert_eq!(sender_balance_before - amount_to_send, sender_balance_after);
|
||||
// // Receiver's balance is increased
|
||||
// assert!(receiver_balance_after > receiver_balance_before);
|
||||
// }
|
||||
|
||||
// /// Teleport of native asset from System Parachain to Relay Chain
|
||||
// /// shouldn't work when there is not enough balance in Relay Chain's `CheckAccount`
|
||||
// #[test]
|
||||
// fn teleport_native_assets_from_system_para_to_relay_fails() {
|
||||
// // Init values for Relay Chain
|
||||
// let amount_to_send: Balance = ASSET_HUB_WESTEND_ED * 1000;
|
||||
// let assets = (Parent, amount_to_send).into();
|
||||
//
|
||||
// let test_args = TestContext {
|
||||
// sender: AssetHubWestendSender::get(),
|
||||
// receiver: WestendReceiver::get(),
|
||||
// args: system_para_test_args(amount_to_send),
|
||||
// assets,
|
||||
// None
|
||||
// };
|
||||
|
||||
// let mut test = SystemParaToRelayTest::new(test_args);
|
||||
|
||||
// let sender_balance_before = test.sender.balance;
|
||||
// let receiver_balance_before = test.receiver.balance;
|
||||
|
||||
// test.set_assertion::<AssetHubWestend>(para_origin_assertions);
|
||||
// test.set_assertion::<Westend>(relay_dest_assertions);
|
||||
// test.set_dispatchable::<AssetHubWestend>(system_para_teleport_assets);
|
||||
// test.assert();
|
||||
|
||||
// let sender_balance_after = test.sender.balance;
|
||||
// let receiver_balance_after = test.receiver.balance;
|
||||
|
||||
// // Sender's balance is reduced
|
||||
// assert_eq!(sender_balance_before - amount_to_send, sender_balance_after);
|
||||
// // Receiver's balance does not change
|
||||
// assert_eq!(receiver_balance_after, receiver_balance_before);
|
||||
// }
|
||||
|
||||
-74
@@ -1,74 +0,0 @@
|
||||
// Copyright Parity Technologies (UK) Ltd.
|
||||
// This file is part of Cumulus.
|
||||
|
||||
// Cumulus is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Cumulus is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::*;
|
||||
|
||||
#[test]
|
||||
fn transact_sudo_from_relay_to_assets_para() {
|
||||
// Init tests variables
|
||||
// Call to be executed in Assets Parachain
|
||||
const ASSET_ID: u32 = 1;
|
||||
|
||||
let call = <AssetHubWestend as Para>::RuntimeCall::Assets(pallet_assets::Call::<
|
||||
<AssetHubWestend as Para>::Runtime,
|
||||
Instance1,
|
||||
>::force_create {
|
||||
id: ASSET_ID.into(),
|
||||
is_sufficient: true,
|
||||
min_balance: 1000,
|
||||
owner: AssetHubWestendSender::get().into(),
|
||||
})
|
||||
.encode()
|
||||
.into();
|
||||
|
||||
// XcmPallet send arguments
|
||||
let sudo_origin = <Westend as Relay>::RuntimeOrigin::root();
|
||||
let assets_para_destination: VersionedMultiLocation =
|
||||
Westend::child_location_of(AssetHubWestend::para_id()).into();
|
||||
|
||||
let weight_limit = WeightLimit::Unlimited;
|
||||
let require_weight_at_most = Weight::from_parts(1000000000, 200000);
|
||||
let origin_kind = OriginKind::Superuser;
|
||||
let check_origin = None;
|
||||
|
||||
let xcm = VersionedXcm::from(Xcm(vec![
|
||||
UnpaidExecution { weight_limit, check_origin },
|
||||
Transact { require_weight_at_most, origin_kind, call },
|
||||
]));
|
||||
|
||||
// Send XCM message from Relay Chain
|
||||
Westend::execute_with(|| {
|
||||
assert_ok!(<Westend as WestendPallet>::XcmPallet::send(
|
||||
sudo_origin,
|
||||
bx!(assets_para_destination),
|
||||
bx!(xcm),
|
||||
));
|
||||
|
||||
type RuntimeEvent = <Westend as Relay>::RuntimeEvent;
|
||||
|
||||
assert_expected_events!(
|
||||
Westend,
|
||||
vec![
|
||||
RuntimeEvent::XcmPallet(pallet_xcm::Event::Sent { .. }) => {},
|
||||
]
|
||||
);
|
||||
});
|
||||
|
||||
// Receive XCM message in Assets Parachain
|
||||
AssetHubWestend::execute_with(|| {
|
||||
assert!(<AssetHubWestend as AssetHubWestendPallet>::Assets::asset_exists(ASSET_ID));
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user