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

Xcm SetAssetClaimer 1 #5585

Open
wants to merge 93 commits into
base: xcm-pay-fees
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
b1e850e
Added SetAssetClaimer instruction
x3c41a Aug 20, 2024
1a77953
added prdoc
x3c41a Aug 20, 2024
eca1375
added missing column
x3c41a Aug 20, 2024
09046e6
fixed prdoc: added crates
x3c41a Aug 20, 2024
7c8e2a4
Update SetAssetClaimer description
x3c41a Aug 20, 2024
0a8d2f9
Formated SetAssetClaimer
x3c41a Aug 20, 2024
497bb95
Removed v3::MultiLocation
x3c41a Aug 20, 2024
d68ac96
changed asset claimer variable name from camel case to snake case
x3c41a Aug 20, 2024
2dd1718
initialized XCMExecutor with an empty asset_claimer
x3c41a Aug 20, 2024
69c9570
Added missing instructions coverter
x3c41a Aug 20, 2024
17e758c
applied linter suggestions
x3c41a Aug 20, 2024
1cd2822
applied linter suggestions[2]
x3c41a Aug 20, 2024
d070cd7
fixed type mismatch and other compilation errs
x3c41a Aug 21, 2024
64cc40e
added missing implementation (or todo!() ) for AssetHubWestendXcmWeight
x3c41a Aug 21, 2024
953463c
few minor refactors
x3c41a Aug 21, 2024
e2b0777
unit tests in progress
x3c41a Aug 26, 2024
236e91f
Added unit test for SetAssetClaimer
x3c41a Aug 26, 2024
5abbdf6
[WIP] set_asset_claimer e2e test
x3c41a Aug 28, 2024
5a7c195
Implemented pay_fees for the testnets
x3c41a Aug 28, 2024
6800d9f
WIP e2e tests - claimAssets step
x3c41a Aug 30, 2024
b5a2cd0
Fixed dispatch
x3c41a Aug 30, 2024
2fec6d4
finished first SAC e2e single chain test
x3c41a Sep 2, 2024
0ff7c67
benchmarks initial commit
x3c41a Sep 2, 2024
4f8aada
Reverted cumulus/parachains/runtimes/assets/asset-hub-westend/src/wei…
x3c41a Sep 3, 2024
7c8df66
add made-up benchmarks to all runtimes
x3c41a Sep 3, 2024
7f4412e
removed commented instruction
x3c41a Sep 3, 2024
c8cddbb
added set_asset_claimer to pallet_xcm WeightInfo trait and implemente…
x3c41a Sep 3, 2024
38f3691
resolved merge conflicts
x3c41a Sep 3, 2024
cfb23bf
Added unit test for SetAssetClaimer
x3c41a Aug 26, 2024
5ced85a
resolved merge conflicts[3]
x3c41a Sep 3, 2024
ef911c5
resolved merge conflicts[4]
x3c41a Sep 3, 2024
84ad4ce
reverted cumulus/parachains/runtimes/assets/asset-hub-westend/src/wei…
x3c41a Sep 3, 2024
dd39a1b
fixed benchmark
x3c41a Sep 3, 2024
69362da
removed unused file and import
x3c41a Sep 4, 2024
e21cae1
Merge remote-tracking branch 'origin/xcm-pay-fees' into xcm-sac-1
x3c41a Sep 5, 2024
416fe4a
added missing fn definition to trait
x3c41a Sep 5, 2024
9b364a6
added westhub sac weights
x3c41a Sep 5, 2024
aa0d457
removed unused sender_account
x3c41a Sep 5, 2024
18576bb
added sac to people-westend
x3c41a Sep 5, 2024
8c3e3c3
added sac to runtimes/collectives/collectives-westend/src/weights/pal…
x3c41a Sep 5, 2024
ebd9668
added sac to rococo runtime
x3c41a Sep 5, 2024
139a066
added sac to all the weights/xcm_pallet
x3c41a Sep 5, 2024
68efec5
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=we…
Sep 5, 2024
43a1231
Added SetAssetClaimer instruction
x3c41a Aug 20, 2024
1d71fb7
added prdoc
x3c41a Aug 20, 2024
224a6d6
added missing column
x3c41a Aug 20, 2024
5c035cc
fixed prdoc: added crates
x3c41a Aug 20, 2024
bfe7627
Update SetAssetClaimer description
x3c41a Aug 20, 2024
802ece4
Formated SetAssetClaimer
x3c41a Aug 20, 2024
ee9e8d5
Removed v3::MultiLocation
x3c41a Aug 20, 2024
3be8339
changed asset claimer variable name from camel case to snake case
x3c41a Aug 20, 2024
202d4d1
initialized XCMExecutor with an empty asset_claimer
x3c41a Aug 20, 2024
455678d
Added missing instructions coverter
x3c41a Aug 20, 2024
3d47c4b
applied linter suggestions
x3c41a Aug 20, 2024
d4a7004
applied linter suggestions[2]
x3c41a Aug 20, 2024
c4da6f1
fixed type mismatch and other compilation errs
x3c41a Aug 21, 2024
8212c5b
added missing implementation (or todo!() ) for AssetHubWestendXcmWeight
x3c41a Aug 21, 2024
a43735d
few minor refactors
x3c41a Aug 21, 2024
50e566d
unit tests in progress
x3c41a Aug 26, 2024
cb2fc15
Added unit test for SetAssetClaimer
x3c41a Aug 26, 2024
d89fb70
[WIP] set_asset_claimer e2e test
x3c41a Aug 28, 2024
aff5fd4
Implemented pay_fees for the testnets
x3c41a Aug 28, 2024
13b5619
WIP e2e tests - claimAssets step
x3c41a Aug 30, 2024
129d8cb
Fixed dispatch
x3c41a Aug 30, 2024
737943c
finished first SAC e2e single chain test
x3c41a Sep 2, 2024
465bd7e
benchmarks initial commit
x3c41a Sep 2, 2024
80d7e6e
Reverted cumulus/parachains/runtimes/assets/asset-hub-westend/src/wei…
x3c41a Sep 3, 2024
1754578
add made-up benchmarks to all runtimes
x3c41a Sep 3, 2024
c0081ae
removed commented instruction
x3c41a Sep 3, 2024
0db627d
added set_asset_claimer to pallet_xcm WeightInfo trait and implemente…
x3c41a Sep 3, 2024
89a8ee2
resolved merge conflicts
x3c41a Sep 3, 2024
7a487a0
Added unit test for SetAssetClaimer
x3c41a Aug 26, 2024
fdd45af
resolved merge conflicts[3]
x3c41a Sep 3, 2024
e467e4a
resolved merge conflicts[4]
x3c41a Sep 3, 2024
145de1e
reverted cumulus/parachains/runtimes/assets/asset-hub-westend/src/wei…
x3c41a Sep 3, 2024
571510c
fixed benchmark
x3c41a Sep 3, 2024
97b2e51
removed unused file and import
x3c41a Sep 4, 2024
d8c4651
added missing fn definition to trait
x3c41a Sep 5, 2024
c44584f
added westhub sac weights
x3c41a Sep 5, 2024
7d1c21f
removed unused sender_account
x3c41a Sep 5, 2024
9920ddf
added sac to people-westend
x3c41a Sep 5, 2024
fc997ec
added sac to runtimes/collectives/collectives-westend/src/weights/pal…
x3c41a Sep 5, 2024
2135b58
added sac to rococo runtime
x3c41a Sep 5, 2024
687271a
added sac to all the weights/xcm_pallet
x3c41a Sep 5, 2024
582a397
added _ to all the unused location
x3c41a Sep 5, 2024
71ba3d7
updated westend benchmarks
x3c41a Sep 5, 2024
9ad82b7
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=we…
Sep 5, 2024
b02c831
fixed e2e tests
x3c41a Sep 5, 2024
660cfcc
changed benchmark values for all the set_asset_claimers
x3c41a Sep 5, 2024
5ac4e7e
WIP: multi-chain set asset claimer test
x3c41a Sep 18, 2024
b35d56b
added HashedDescription conversion to BridgeHub
x3c41a Sep 18, 2024
833ce02
WIP: merging set_asset_claimer tests
x3c41a Sep 19, 2024
ec4854a
trying to add bridge_hub_westend_runtime to asset_hub_westend tests
x3c41a Sep 19, 2024
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 @@ -50,6 +50,7 @@ decl_test_parachains! {
MessageOrigin: cumulus_primitives_core::AggregateMessageOrigin,
},
pallets = {
System: penpal_runtime::System,
PolkadotXcm: penpal_runtime::PolkadotXcm,
Assets: penpal_runtime::Assets,
ForeignAssets: penpal_runtime::ForeignAssets,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ mod imports {
genesis::{AssetHubWestendAssetOwner, ED as ASSET_HUB_WESTEND_ED},
AssetHubWestendParaPallet as AssetHubWestendPallet,
},
bridge_hub_westend_emulated_chain::{
bridge_hub_westend_runtime::{
xcm_config::{
self as bhw_xcm_config,
XcmConfig as BridgeHubWestendXcmConfig,
},
},
},
collectives_westend_emulated_chain::CollectivesWestendParaPallet as CollectivesWestendPallet,
penpal_emulated_chain::{
penpal_runtime::xcm_config::{
Expand Down Expand Up @@ -98,6 +106,8 @@ mod imports {
pub type ParaToParaThroughRelayTest = Test<PenpalA, PenpalB, Westend>;
pub type ParaToParaThroughAHTest = Test<PenpalA, PenpalB, AssetHubWestend>;
pub type RelayToParaThroughAHTest = Test<Westend, PenpalA, AssetHubWestend>;
pub type BridgeToAssetHubTest = Test<BridgeHubWestend, AssetHubWestend>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub type BridgeToAssetHubTest = Test<BridgeHubWestend, AssetHubWestend>;
pub type BridgeHubToAssetHubTest = Test<BridgeHubWestend, AssetHubWestend>;

pub type AssetHubToBridgeHubTest = Test<AssetHubWestend, BridgeHubWestend>;
}

#[cfg(test)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ mod swap;
mod teleport;
mod treasury;
mod xcm_fee_estimation;
mod set_asset_claimer;
mod set_asset_claimer_multichain;
Original file line number Diff line number Diff line change
@@ -0,0 +1,285 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! Tests related to claiming assets trapped during XCM execution.

use emulated_integration_tests_common::accounts::{ALICE, BOB, CHARLIE};
use emulated_integration_tests_common::impls::AccountId32;
use emulated_integration_tests_common::xcm_emulator::log;
use crate::{
imports::*,
};

use frame_support::{sp_runtime::{traits::Dispatchable}, assert_ok, LOG_TARGET};
use westend_system_emulated_network::penpal_emulated_chain::penpal_runtime;
use westend_system_emulated_network::asset_hub_westend_emulated_chain::asset_hub_westend_runtime;
use westend_system_emulated_network::westend_emulated_chain::westend_runtime::xcm_config::AssetHub;
use xcm_executor::traits::ConvertLocation;
use crate::imports::ahw_xcm_config::{LocationToAccountId, UniversalLocation};

#[test]
fn test_set_asset_claimer_within_a_chain() {
let (alice_account, alice_location) = account_and_location(ALICE);
let (bob_account, bob_location) = account_and_location(BOB);

PenpalA::execute_with(|| {
type System = <PenpalA as PenpalAPallet>::System;
type RuntimeOrigin = <PenpalA as Chain>::RuntimeOrigin;
assert_ok!(System::set_storage(
RuntimeOrigin::root(),
vec![(penpal_runtime::xcm_config::RelayNetworkId::key().to_vec(), NetworkId::Westend.encode())]
));
});

let amount_to_send = 16_000_000_000_000;
let native_asset_location = RelayLocation::get();
let assets: Assets = (Parent, amount_to_send).into();

fund_account(&alice_account, amount_to_send * 2);
assert_eq!(query_balance(&alice_account, &native_asset_location), amount_to_send * 2);

let test_args = TestContext {
sender: alice_account.clone(),
receiver: bob_account.clone(),
args: TestArgs::new_para(
bob_location.clone(),
bob_account.clone(),
amount_to_send,
assets.clone(),
None,
0,
),
};
let test = ParaToParaThroughAHTest::new(test_args);
execute_test(test.clone(), bob_location.clone(), transfer_assets);

let alice_assets_after = query_balance(&alice_account, &native_asset_location);
assert_eq!(alice_assets_after, amount_to_send);

let test_args = TestContext {
sender: bob_account.clone(),
receiver: alice_account.clone(),
args: TestArgs::new_para(
alice_location.clone(),
alice_account.clone(),
amount_to_send,
assets.clone(),
None,
0,
),
};
let test = ParaToParaThroughAHTest::new(test_args);
execute_test(test.clone(), bob_location.clone(), claim_assets);

let bob_assets_after = query_balance(&bob_account, &native_asset_location);
assert_eq!(bob_assets_after, amount_to_send);
}

fn account_and_location(account: &str) -> (AccountId32, Location) {
let account_id = PenpalA::account_id_of(account);
let account_clone = account_id.clone();
let location: Location = [Junction::AccountId32 { network: Some(Westend), id: account_id.into() }].into();
(account_clone, location)
}

fn fund_account(account: &AccountId, amount: u128) {
let asset_owner = PenpalAssetOwner::get();
PenpalA::mint_foreign_asset(
<PenpalA as Chain>::RuntimeOrigin::signed(asset_owner),
Location::parent(),
account.clone(),
amount,
);
}

fn query_balance(account: &AccountId, asset_location: &Location) -> u128 {
PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(asset_location.clone(), account)
})
}

fn execute_test(
test: ParaToParaThroughAHTest,
claimer: Location,
xcm_fn: impl Fn(ParaToParaThroughAHTest, Location) -> <PenpalA as Chain>::RuntimeCall,
) {
let call = xcm_fn(test.clone(), claimer.clone());
PenpalA::execute_with(|| {
assert!(call.dispatch(test.signed_origin).is_ok());
});
}

fn transfer_assets(
test: ParaToParaThroughAHTest,
claimer: Location
) -> <PenpalA as Chain>::RuntimeCall {
type RuntimeCall = <PenpalA as Chain>::RuntimeCall;

let local_xcm = Xcm::<RuntimeCall>::builder_unsafe()
.set_asset_claimer(claimer.clone())
.withdraw_asset(test.args.assets.clone())
.clear_origin()
.build();

RuntimeCall::PolkadotXcm(pallet_xcm::Call::execute {
message: bx!(VersionedXcm::from(local_xcm)),
max_weight: Weight::from_parts(4_000_000_000_000, 300_000),
})
}

fn claim_assets(
test: ParaToParaThroughAHTest,
claimer: Location
) -> <PenpalA as Chain>::RuntimeCall {
type RuntimeCall = <PenpalA as Chain>::RuntimeCall;

let local_xcm = Xcm::<RuntimeCall>::builder_unsafe()
.claim_asset(test.args.assets.clone(), Here)
.deposit_asset(AllCounted(test.args.assets.len() as u32), claimer)
.build();

RuntimeCall::PolkadotXcm(pallet_xcm::Call::execute {
message: bx!(VersionedXcm::from(local_xcm)),
max_weight: Weight::from_parts(4_000_000_000_000, 300_000),
})
}

#[test]
fn test_sac_between_the_chains() {
let alice = AssetHubWestend::account_id_of(ALICE);
let bob = BridgeHubWestend::account_id_of(BOB);
let destination = AssetHubWestend::sibling_location_of(BridgeHubWestend::para_id());
let bob_location = Location::new(0, Junction::AccountId32 { network: Some(Westend), id: bob.clone().into() });

let amount_to_send = 16_000_000_000_000u128;
BridgeHubWestend::fund_accounts(vec![(
bob.clone(),
amount_to_send * 2,
)]);
let balance = <BridgeHubWestend as Chain>::account_data_of(bob.clone()).free;

let assets: Assets = (Parent, amount_to_send).into();
let test_args = TestContext {
sender: bob.clone(),
receiver: alice.clone(),
args: TestArgs::new_para(
bob_location.clone(),
bob.clone(),
amount_to_send,
assets.clone(),
None,
0,
),
};
let test = BridgeToAssetHubTest::new(test_args);
let alice_on_ah = Location::new(
1,
[
Parachain(1000),
Junction::AccountId32 {
network: Some(Westend),
id: alice.clone().into()}],
);

execute_bob_bh_test(test.clone(), alice_on_ah.clone(), trap_assets_bh);

let balance = <BridgeHubWestend as Chain>::account_data_of(bob.clone()).free;


let amount_to_send = 16_000_000_000_000u128;
AssetHubWestend::fund_accounts(vec![(
alice.clone(),
amount_to_send * 2,
)]);

println!("before LocationToAccountId");
// let alLoc = LocationToAccountId::convert_location(&alice_on_ah).unwrap();
// println!("alice Loc is: {:?}", alLoc);
// // let balance = <BridgeHubWestend as Chain>::account_data_of(alLoc.clone()).free;
// println!("[AH] Alice balance before {:?}", balance);

// let test_args = TestContext {
// sender: alice.clone(),
// receiver: bob.clone(),
// args: TestArgs::new_para(
// destination.clone(),
// bob.clone(),
// amount_to_send,
// assets.clone(),
// None,
// 0,
// ),
// };
// let alice_on_ah = Location::new(
// 1,
// [
// Parachain(1000),
// Junction::AccountId32 {
// network: Some(Westend),
// id: alice.clone().into()}],
// );
// let test = AssetHubToBridgeHubTest::new(test_args);
// let bridge_hub = AssetHubWestend::sibling_location_of(
// BridgeHubWestend::para_id()
// ).into();
// let xcm_there = Xcm::<()>::builder_unsafe()
// .claim_asset(test.args.assets.clone(), Here)
// .pay_fees((Parent, 15_000_000_000_000u128))
// .deposit_asset(All, alice_on_ah.clone())
// .build();
// AssetHubWestend::execute_with(|| {
// assert_ok!(<AssetHubWestend as AssetHubWestendPallet>::PolkadotXcm::send(
// test.signed_origin,
// bx!(bridge_hub),
// bx!(VersionedXcm::from(xcm_there)),
// ));
// });
//
//
// let alLoc = ahw_xcm_config::LocationToAccountId::convert_location(&alice_on_ah).unwrap();
// let balance = <BridgeHubWestend as Chain>::account_data_of(alLoc).free;
// println!("[AH] Alice balance after {:?}", balance);

}

fn execute_bob_bh_test(
test: BridgeToAssetHubTest,
claimer: Location,
xcm_fn: impl Fn(BridgeToAssetHubTest, Location) -> <BridgeHubWestend as Chain>::RuntimeCall,
) {
let call = xcm_fn(test.clone(), claimer.clone());
BridgeHubWestend::execute_with(|| {
assert!(call.dispatch(test.signed_origin).is_ok());
});
}

fn trap_assets_bh(
test: BridgeToAssetHubTest,
claimer: Location
) -> <BridgeHubWestend as Chain>::RuntimeCall {
type RuntimeCall = <BridgeHubWestend as Chain>::RuntimeCall;

let local_xcm = Xcm::<RuntimeCall>::builder_unsafe()
.set_asset_claimer(claimer.clone())
.withdraw_asset(test.args.assets.clone())
.clear_origin()
.build();

RuntimeCall::PolkadotXcm(pallet_xcm::Call::execute {
message: bx!(VersionedXcm::from(local_xcm)),
max_weight: Weight::from_parts(4_000_000_000_000, 700_000),
})
}
Loading
Loading