This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
add integration tests to xcm-builder #3537
Merged
Merged
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
5018eb5
add integration tests to xcm-builder
apopiak 29b7b04
add an integration test for reserve_transfer_assets
apopiak ee9b9c7
add query holding and teleport tests
apopiak 7a09753
formatting
apopiak d1539f6
add to barrier doc comments and fix doc tests warnings
apopiak d9ebc77
use more realistic barrier for integration tests
apopiak ec426b9
improve imports
apopiak 32b67ca
adjust base xcm weight and existential deposit to be in line with Kusama
apopiak 7881628
remove AnyNetwork
apopiak 5e8507f
add more comments and remove unnecessary code
apopiak cea48f9
Merge branch 'apopiak/xcm-integration-tests' of github.com:paritytech…
apopiak 24b79ec
move mock into separate file
apopiak 4aba2d6
reduce imports
apopiak 114ef4e
update cargo.lock
apopiak 97fb7a8
remove reserve transfer test from xcm builder integration tests
apopiak 21a7e74
reword barrier doc comment
apopiak aababe1
elaborate on QueryHolding test scenario
apopiak 2b63830
add an integration test for reserve based transfers from parachain to…
apopiak eed0fbc
add teleport tests
apopiak dc2a1bf
fix failing teleport filter tests
apopiak 5dd3744
Update xcm/xcm-builder/src/integration_tests.rs
apopiak 3b63468
Update xcm/xcm-builder/src/integration_tests.rs
apopiak 26e7f53
Update xcm/xcm-builder/src/integration_tests.rs
apopiak 4bd50a7
Move integration tests to tests/ directory
KiChjang 75d0971
Merge remote-tracking branch 'origin/master' into apopiak/xcm-integra…
KiChjang f8a4847
Fix merge
KiChjang e3605c5
Replace All wildcard with a concrete seed amount
KiChjang 4266a94
Rename SEED_AMOUNT to REGISTER_AMOUNT
KiChjang 412ce69
Fix compilation error
KiChjang 72975eb
Check for teleport destination first before checking out assets
KiChjang 0d17e0a
Fix unit test
KiChjang 304fd94
Do not run tests in integration mock
KiChjang ab81960
Add a permissive assets filter for teleportation
KiChjang 2fba6af
Remove check for teleport location in InitiateTeleport XCM
KiChjang fd51b75
Remove defunct test
KiChjang 1f15e4b
Apply suggestions from code review
apopiak dcd947b
Reword comment
apopiak 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
adjust base xcm weight and existential deposit to be in line with Kusama
- Loading branch information
commit 32b67ca4127c8800f722a972846b136c9d833e8b
There are no files selected for viewing
This file contains hidden or 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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -19,13 +19,17 @@ use xcm_builder::{ | |||||
| ChildParachainConvertsVia, ChildSystemParachainAsSuperuser, | ||||||
| CurrencyAdapter as XcmCurrencyAdapter, FixedRateOfConcreteFungible, FixedWeightBounds, | ||||||
| IsConcrete, LocationInverter, SignedAccountId32AsNative, SignedToAccountId32, | ||||||
| SovereignSignedViaLocation, TakeWeightCredit | ||||||
| SovereignSignedViaLocation, TakeWeightCredit, IsChildSystemParachain, AllowUnpaidExecutionFrom | ||||||
| }; | ||||||
| use crate::mock; | ||||||
|
|
||||||
| pub type AccountId = AccountId32; | ||||||
| pub type Balance = u128; | ||||||
|
|
||||||
| // copied from kusama constants | ||||||
| pub const UNITS: Balance = 1_000_000_000_000; | ||||||
| pub const CENTS: Balance = UNITS / 30_000; | ||||||
|
|
||||||
| parameter_types! { | ||||||
| pub const BlockHashCount: u64 = 250; | ||||||
| } | ||||||
|
|
@@ -57,7 +61,7 @@ impl frame_system::Config for Runtime { | |||||
| } | ||||||
|
|
||||||
| parameter_types! { | ||||||
| pub ExistentialDeposit: Balance = 1; | ||||||
| pub ExistentialDeposit: Balance = 1 * CENTS; | ||||||
| pub const MaxLocks: u32 = 50; | ||||||
| pub const MaxReserves: u32 = 50; | ||||||
| } | ||||||
|
|
@@ -78,19 +82,20 @@ impl shared::Config for Runtime {} | |||||
|
|
||||||
| impl configuration::Config for Runtime {} | ||||||
|
|
||||||
| // aims to closely emulate the Kusama XcmConfig | ||||||
| parameter_types! { | ||||||
| pub const KsmLocation: MultiLocation = MultiLocation::Null; | ||||||
| pub const KusamaNetwork: NetworkId = NetworkId::Kusama; | ||||||
| pub const AnyNetwork: NetworkId = NetworkId::Any; | ||||||
| pub Ancestry: MultiLocation = MultiLocation::Null; | ||||||
| pub UnitWeightCost: Weight = 1_000; | ||||||
| pub CheckAccount: AccountId = XcmPallet::check_account(); | ||||||
| } | ||||||
|
|
||||||
| pub type SovereignAccountOf = | ||||||
| (ChildParachainConvertsVia<ParaId, AccountId>, AccountId32Aliases<KusamaNetwork, AccountId>); | ||||||
|
|
||||||
| pub type LocalAssetTransactor = | ||||||
| XcmCurrencyAdapter<Balances, IsConcrete<KsmLocation>, SovereignAccountOf, AccountId, ()>; | ||||||
| XcmCurrencyAdapter<Balances, IsConcrete<KsmLocation>, SovereignAccountOf, AccountId, CheckAccount>; | ||||||
|
|
||||||
| type LocalOriginConverter = ( | ||||||
| SovereignSignedViaLocation<SovereignAccountOf, Origin>, | ||||||
|
|
@@ -100,11 +105,16 @@ type LocalOriginConverter = ( | |||||
| ); | ||||||
|
|
||||||
| parameter_types! { | ||||||
| pub const BaseXcmWeight: Weight = 1_000; | ||||||
| pub const BaseXcmWeight: Weight = 1_000_000_000; | ||||||
| pub KsmPerSecond: (MultiLocation, u128) = (KsmLocation::get(), 1); | ||||||
| } | ||||||
|
|
||||||
| pub type Barrier = (TakeWeightCredit, AllowTopLevelPaidExecutionFrom<All<MultiLocation>>); | ||||||
| pub type Barrier = ( | ||||||
| TakeWeightCredit, | ||||||
| AllowTopLevelPaidExecutionFrom<All<MultiLocation>>, | ||||||
| // Unused/Untested | ||||||
| AllowUnpaidExecutionFrom<IsChildSystemParachain<ParaId>>, | ||||||
| ); | ||||||
|
|
||||||
| pub struct XcmConfig; | ||||||
| impl xcm_executor::Config for XcmConfig { | ||||||
|
|
@@ -169,13 +179,11 @@ pub const ALICE: AccountId = AccountId::new([0u8; 32]); | |||||
| pub const PARA_ID: u32 = 2000; | ||||||
| pub const INITIAL_BALANCE: u128 = 100_000_000_000; | ||||||
|
|
||||||
| pub fn kusama_like_ext() -> sp_io::TestExternalities { | ||||||
| pub fn kusama_like_with_balances(balances: Vec<(AccountId, Balance)>) -> sp_io::TestExternalities { | ||||||
| let mut t = frame_system::GenesisConfig::default().build_storage::<Runtime>().unwrap(); | ||||||
|
|
||||||
| let parachain_acc: AccountId = ParaId::from(PARA_ID).into_account(); | ||||||
|
|
||||||
| pallet_balances::GenesisConfig::<Runtime> { | ||||||
| balances: vec![(ALICE, INITIAL_BALANCE), (parachain_acc, INITIAL_BALANCE)], | ||||||
| balances, | ||||||
| } | ||||||
| .assimilate_storage(&mut t) | ||||||
| .unwrap(); | ||||||
|
|
@@ -244,24 +252,27 @@ fn buy_execution<C>(debt: Weight) -> Order<C> { | |||||
| #[test] | ||||||
| fn withdraw_and_deposit_works() { | ||||||
| use xcm::opaque::v0::prelude::*; | ||||||
apopiak marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| kusama_like_ext().execute_with(|| { | ||||||
| let para_acc: AccountId = ParaId::from(PARA_ID).into_account(); | ||||||
| let balances = vec![(ALICE, INITIAL_BALANCE), (para_acc.clone(), INITIAL_BALANCE)]; | ||||||
| kusama_like_with_balances(balances).execute_with(|| { | ||||||
| let other_para_id = 3000; | ||||||
| let amount = 5_000_000; | ||||||
| let amount = 10 * ExistentialDeposit::get(); | ||||||
| let weight = 3 * BaseXcmWeight::get(); | ||||||
| let r = XcmExecutor::<XcmConfig>::execute_xcm( | ||||||
| Parachain(PARA_ID).into(), | ||||||
| Xcm::WithdrawAsset { | ||||||
| assets: vec![ConcreteFungible { id: Null, amount }], | ||||||
| effects: vec![ | ||||||
| buy_execution(3_000), | ||||||
| buy_execution(weight), | ||||||
| Order::DepositAsset { | ||||||
| assets: vec![All], | ||||||
| dest: Parachain(other_para_id).into(), | ||||||
| }, | ||||||
| ], | ||||||
| }, | ||||||
| 2_000_000, | ||||||
| weight, | ||||||
| ); | ||||||
| assert_eq!(r, Outcome::Complete(3_000)); | ||||||
| assert_eq!(r, Outcome::Complete(weight)); | ||||||
| let other_para_acc: AccountId = ParaId::from(other_para_id).into_account(); | ||||||
| assert_eq!(Balances::free_balance(other_para_acc), amount); | ||||||
apopiak marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| }); | ||||||
|
|
@@ -270,9 +281,12 @@ fn withdraw_and_deposit_works() { | |||||
| #[test] | ||||||
| fn reserve_transfer_assets_works() { | ||||||
| use xcm::opaque::v0::prelude::*; | ||||||
| kusama_like_ext().execute_with(|| { | ||||||
| let amount = 5_000_000; | ||||||
| let dest_weight = 2_000_000; | ||||||
| let para_acc: AccountId = ParaId::from(PARA_ID).into_account(); | ||||||
| let balances = vec![(ALICE, INITIAL_BALANCE), (para_acc.clone(), INITIAL_BALANCE)]; | ||||||
| kusama_like_with_balances(balances).execute_with(|| { | ||||||
| let amount = 10 * ExistentialDeposit::get(); | ||||||
| // We just assume that the destination uses the same base weight for XCM | ||||||
| let dest_weight = 2 * BaseXcmWeight::get(); | ||||||
| assert_ok!(XcmPallet::reserve_transfer_assets( | ||||||
| Origin::signed(ALICE), | ||||||
| Parachain(PARA_ID).into(), | ||||||
|
|
@@ -282,7 +296,6 @@ fn reserve_transfer_assets_works() { | |||||
| )); | ||||||
|
|
||||||
| assert_eq!(Balances::free_balance(ALICE), INITIAL_BALANCE - amount); | ||||||
| let para_acc: AccountId = ParaId::from(PARA_ID).into_account(); | ||||||
| assert_eq!(Balances::free_balance(para_acc), INITIAL_BALANCE + amount); | ||||||
| assert_eq!( | ||||||
| mock::sent_xcm(), | ||||||
|
|
@@ -310,16 +323,19 @@ fn reserve_transfer_assets_works() { | |||||
| #[test] | ||||||
| fn query_holding_works() { | ||||||
| use xcm::opaque::v0::prelude::*; | ||||||
| kusama_like_ext().execute_with(|| { | ||||||
| let para_acc: AccountId = ParaId::from(PARA_ID).into_account(); | ||||||
| let balances = vec![(ALICE, INITIAL_BALANCE), (para_acc.clone(), INITIAL_BALANCE)]; | ||||||
| kusama_like_with_balances(balances).execute_with(|| { | ||||||
| let other_para_id = 3000; | ||||||
| let amount = 5_000_000; | ||||||
| let amount = 10 * ExistentialDeposit::get(); | ||||||
| let query_id = 1234; | ||||||
| let weight = 4 * BaseXcmWeight::get(); | ||||||
| let r = XcmExecutor::<XcmConfig>::execute_xcm( | ||||||
| Parachain(PARA_ID).into(), | ||||||
| Xcm::WithdrawAsset { | ||||||
| assets: vec![ConcreteFungible { id: Null, amount }], | ||||||
| effects: vec![ | ||||||
| buy_execution(4_000), | ||||||
| buy_execution(weight), | ||||||
| Order::QueryHolding { | ||||||
| query_id, | ||||||
| dest: Parachain(PARA_ID).into(), | ||||||
|
|
@@ -331,12 +347,11 @@ fn query_holding_works() { | |||||
| }, | ||||||
| ], | ||||||
| }, | ||||||
| 2_000_000, | ||||||
| weight, | ||||||
| ); | ||||||
| assert_eq!(r, Outcome::Complete(4_000)); | ||||||
| assert_eq!(r, Outcome::Complete(weight)); | ||||||
| let other_para_acc: AccountId = ParaId::from(other_para_id).into_account(); | ||||||
| assert_eq!(Balances::free_balance(other_para_acc), amount); | ||||||
| let para_acc: AccountId = ParaId::from(PARA_ID).into_account(); | ||||||
| assert_eq!(Balances::free_balance(para_acc), INITIAL_BALANCE - amount); | ||||||
| assert_eq!( | ||||||
| mock::sent_xcm(), | ||||||
|
|
@@ -357,30 +372,32 @@ fn query_holding_works() { | |||||
| #[test] | ||||||
| fn teleport_to_statemine_works() { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Teleport already implies trusting, so I think this naming change isn't necessary. |
||||||
| use xcm::opaque::v0::prelude::*; | ||||||
| kusama_like_ext().execute_with(|| { | ||||||
| let para_acc: AccountId = ParaId::from(PARA_ID).into_account(); | ||||||
| let balances = vec![(ALICE, INITIAL_BALANCE), (para_acc.clone(), INITIAL_BALANCE)]; | ||||||
| kusama_like_with_balances(balances).execute_with(|| { | ||||||
| let statemine_id = 1000; | ||||||
| let amount = 5_000_000; | ||||||
| let amount = 10 * ExistentialDeposit::get(); | ||||||
| let teleport_effects = vec![ | ||||||
| buy_execution(0), | ||||||
| Order::DepositAsset { assets: vec![All], dest: Parachain(PARA_ID).into() }, | ||||||
| ]; | ||||||
| let weight = 3 * BaseXcmWeight::get(); | ||||||
| let r = XcmExecutor::<XcmConfig>::execute_xcm( | ||||||
apopiak marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| Parachain(PARA_ID).into(), | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this not be called |
||||||
| Xcm::WithdrawAsset { | ||||||
| assets: vec![ConcreteFungible { id: Null, amount }], | ||||||
| effects: vec![ | ||||||
| buy_execution(3_000), | ||||||
| buy_execution(weight), | ||||||
| Order::InitiateTeleport { | ||||||
| assets: vec![All], | ||||||
| dest: Parachain(statemine_id).into(), | ||||||
| effects: teleport_effects.clone(), | ||||||
| }, | ||||||
| ], | ||||||
| }, | ||||||
| 2_000_000, | ||||||
| weight, | ||||||
| ); | ||||||
| assert_eq!(r, Outcome::Complete(3_000)); | ||||||
| let para_acc: AccountId = ParaId::from(PARA_ID).into_account(); | ||||||
| assert_eq!(r, Outcome::Complete(weight)); | ||||||
| assert_eq!(Balances::free_balance(para_acc), INITIAL_BALANCE - amount); | ||||||
apopiak marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| assert_eq!( | ||||||
| mock::sent_xcm(), | ||||||
|
|
||||||
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.
Uh oh!
There was an error while loading. Please reload this page.