-
Notifications
You must be signed in to change notification settings - Fork 645
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
x3c41a
wants to merge
93
commits into
xcm-pay-fees
Choose a base branch
from
xcm-sac-1
base: xcm-pay-fees
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+5,724
−71
Open
Xcm SetAssetClaimer 1 #5585
Changes from all commits
Commits
Show all changes
93 commits
Select commit
Hold shift + click to select a range
b1e850e
Added SetAssetClaimer instruction
x3c41a 1a77953
added prdoc
x3c41a eca1375
added missing column
x3c41a 09046e6
fixed prdoc: added crates
x3c41a 7c8e2a4
Update SetAssetClaimer description
x3c41a 0a8d2f9
Formated SetAssetClaimer
x3c41a 497bb95
Removed v3::MultiLocation
x3c41a d68ac96
changed asset claimer variable name from camel case to snake case
x3c41a 2dd1718
initialized XCMExecutor with an empty asset_claimer
x3c41a 69c9570
Added missing instructions coverter
x3c41a 17e758c
applied linter suggestions
x3c41a 1cd2822
applied linter suggestions[2]
x3c41a d070cd7
fixed type mismatch and other compilation errs
x3c41a 64cc40e
added missing implementation (or todo!() ) for AssetHubWestendXcmWeight
x3c41a 953463c
few minor refactors
x3c41a e2b0777
unit tests in progress
x3c41a 236e91f
Added unit test for SetAssetClaimer
x3c41a 5abbdf6
[WIP] set_asset_claimer e2e test
x3c41a 5a7c195
Implemented pay_fees for the testnets
x3c41a 6800d9f
WIP e2e tests - claimAssets step
x3c41a b5a2cd0
Fixed dispatch
x3c41a 2fec6d4
finished first SAC e2e single chain test
x3c41a 0ff7c67
benchmarks initial commit
x3c41a 4f8aada
Reverted cumulus/parachains/runtimes/assets/asset-hub-westend/src/wei…
x3c41a 7c8df66
add made-up benchmarks to all runtimes
x3c41a 7f4412e
removed commented instruction
x3c41a c8cddbb
added set_asset_claimer to pallet_xcm WeightInfo trait and implemente…
x3c41a 38f3691
resolved merge conflicts
x3c41a cfb23bf
Added unit test for SetAssetClaimer
x3c41a 5ced85a
resolved merge conflicts[3]
x3c41a ef911c5
resolved merge conflicts[4]
x3c41a 84ad4ce
reverted cumulus/parachains/runtimes/assets/asset-hub-westend/src/wei…
x3c41a dd39a1b
fixed benchmark
x3c41a 69362da
removed unused file and import
x3c41a e21cae1
Merge remote-tracking branch 'origin/xcm-pay-fees' into xcm-sac-1
x3c41a 416fe4a
added missing fn definition to trait
x3c41a 9b364a6
added westhub sac weights
x3c41a aa0d457
removed unused sender_account
x3c41a 18576bb
added sac to people-westend
x3c41a 8c3e3c3
added sac to runtimes/collectives/collectives-westend/src/weights/pal…
x3c41a ebd9668
added sac to rococo runtime
x3c41a 139a066
added sac to all the weights/xcm_pallet
x3c41a 68efec5
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=we…
43a1231
Added SetAssetClaimer instruction
x3c41a 1d71fb7
added prdoc
x3c41a 224a6d6
added missing column
x3c41a 5c035cc
fixed prdoc: added crates
x3c41a bfe7627
Update SetAssetClaimer description
x3c41a 802ece4
Formated SetAssetClaimer
x3c41a ee9e8d5
Removed v3::MultiLocation
x3c41a 3be8339
changed asset claimer variable name from camel case to snake case
x3c41a 202d4d1
initialized XCMExecutor with an empty asset_claimer
x3c41a 455678d
Added missing instructions coverter
x3c41a 3d47c4b
applied linter suggestions
x3c41a d4a7004
applied linter suggestions[2]
x3c41a c4da6f1
fixed type mismatch and other compilation errs
x3c41a 8212c5b
added missing implementation (or todo!() ) for AssetHubWestendXcmWeight
x3c41a a43735d
few minor refactors
x3c41a 50e566d
unit tests in progress
x3c41a cb2fc15
Added unit test for SetAssetClaimer
x3c41a d89fb70
[WIP] set_asset_claimer e2e test
x3c41a aff5fd4
Implemented pay_fees for the testnets
x3c41a 13b5619
WIP e2e tests - claimAssets step
x3c41a 129d8cb
Fixed dispatch
x3c41a 737943c
finished first SAC e2e single chain test
x3c41a 465bd7e
benchmarks initial commit
x3c41a 80d7e6e
Reverted cumulus/parachains/runtimes/assets/asset-hub-westend/src/wei…
x3c41a 1754578
add made-up benchmarks to all runtimes
x3c41a c0081ae
removed commented instruction
x3c41a 0db627d
added set_asset_claimer to pallet_xcm WeightInfo trait and implemente…
x3c41a 89a8ee2
resolved merge conflicts
x3c41a 7a487a0
Added unit test for SetAssetClaimer
x3c41a fdd45af
resolved merge conflicts[3]
x3c41a e467e4a
resolved merge conflicts[4]
x3c41a 145de1e
reverted cumulus/parachains/runtimes/assets/asset-hub-westend/src/wei…
x3c41a 571510c
fixed benchmark
x3c41a 97b2e51
removed unused file and import
x3c41a d8c4651
added missing fn definition to trait
x3c41a c44584f
added westhub sac weights
x3c41a 7d1c21f
removed unused sender_account
x3c41a 9920ddf
added sac to people-westend
x3c41a fc997ec
added sac to runtimes/collectives/collectives-westend/src/weights/pal…
x3c41a 2135b58
added sac to rococo runtime
x3c41a 687271a
added sac to all the weights/xcm_pallet
x3c41a 582a397
added _ to all the unused location
x3c41a 71ba3d7
updated westend benchmarks
x3c41a 9ad82b7
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=we…
b02c831
fixed e2e tests
x3c41a 660cfcc
changed benchmark values for all the set_asset_claimers
x3c41a 5ac4e7e
WIP: multi-chain set asset claimer test
x3c41a b35d56b
added HashedDescription conversion to BridgeHub
x3c41a 833ce02
WIP: merging set_asset_claimer tests
x3c41a ec4854a
trying to add bridge_hub_westend_runtime to asset_hub_westend tests
x3c41a File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
285 changes: 285 additions & 0 deletions
285
.../integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/set_asset_claimer.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
}) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.