@@ -20,6 +20,7 @@ use emulated_integration_tests_common::{macros::AccountId, test_cross_chain_alia
2020use frame_support:: { traits:: ContainsPair , BoundedVec } ;
2121use xcm:: latest:: Junctions :: * ;
2222
23+ const ALLOWED : bool = true ;
2324const DENIED : bool = false ;
2425
2526const TELEPORT_FEES : bool = true ;
@@ -32,8 +33,8 @@ fn account_on_sibling_syschain_aliases_into_same_local_account() {
3233 let target = origin. clone ( ) ;
3334 let fees = WESTEND_ED * 10 ;
3435
35- PenpalA :: mint_foreign_asset (
36- <PenpalA as Chain >:: RuntimeOrigin :: signed ( PenpalAssetOwner :: get ( ) ) ,
36+ PenpalB :: mint_foreign_asset (
37+ <PenpalB as Chain >:: RuntimeOrigin :: signed ( PenpalAssetOwner :: get ( ) ) ,
3738 Location :: parent ( ) ,
3839 origin. clone ( ) ,
3940 fees * 10 ,
@@ -55,7 +56,7 @@ fn account_on_sibling_syschain_aliases_into_same_local_account() {
5556 // between People and AH: denied
5657 ( PeopleWestend , AssetHubWestend , TELEPORT_FEES , DENIED ) ,
5758 // between Penpal and AH: denied
58- ( PenpalA , AssetHubWestend , RESERVE_TRANSFER_FEES , DENIED )
59+ ( PenpalB , AssetHubWestend , RESERVE_TRANSFER_FEES , DENIED )
5960 ] ,
6061 origin,
6162 target,
@@ -70,8 +71,8 @@ fn account_on_sibling_syschain_cannot_alias_into_different_local_account() {
7071 let target: AccountId = [ 2 ; 32 ] . into ( ) ;
7172 let fees = WESTEND_ED * 10 ;
7273
73- PenpalA :: mint_foreign_asset (
74- <PenpalA as Chain >:: RuntimeOrigin :: signed ( PenpalAssetOwner :: get ( ) ) ,
74+ PenpalB :: mint_foreign_asset (
75+ <PenpalB as Chain >:: RuntimeOrigin :: signed ( PenpalAssetOwner :: get ( ) ) ,
7576 Location :: parent ( ) ,
7677 origin. clone ( ) ,
7778 fees * 10 ,
@@ -89,7 +90,7 @@ fn account_on_sibling_syschain_cannot_alias_into_different_local_account() {
8990 // between People and AH: denied
9091 ( PeopleWestend , AssetHubWestend , TELEPORT_FEES , DENIED ) ,
9192 // between Penpal and AH: denied
92- ( PenpalA , AssetHubWestend , RESERVE_TRANSFER_FEES , DENIED )
93+ ( PenpalB , AssetHubWestend , RESERVE_TRANSFER_FEES , DENIED )
9394 ] ,
9495 origin,
9596 target,
@@ -100,82 +101,177 @@ fn account_on_sibling_syschain_cannot_alias_into_different_local_account() {
100101#[ test]
101102fn aliasing_child_locations ( ) {
102103 use AssetHubWestendXcmConfig as XcmConfig ;
103- // Allows aliasing descendant of origin.
104- let origin = Location :: new ( 1 , X1 ( [ PalletInstance ( 8 ) ] . into ( ) ) ) ;
105- let target = Location :: new ( 1 , X2 ( [ PalletInstance ( 8 ) , GeneralIndex ( 9 ) ] . into ( ) ) ) ;
106- assert ! ( <XcmConfig as xcm_executor:: Config >:: Aliasers :: contains( & origin, & target) ) ;
107- let origin = Location :: new ( 1 , X1 ( [ Parachain ( 8 ) ] . into ( ) ) ) ;
108- let target =
109- Location :: new ( 1 , X2 ( [ Parachain ( 8 ) , AccountId32 { network : None , id : [ 1u8 ; 32 ] } ] . into ( ) ) ) ;
110- assert ! ( <XcmConfig as xcm_executor:: Config >:: Aliasers :: contains( & origin, & target) ) ;
111- let origin = Location :: new ( 1 , X1 ( [ Parachain ( 8 ) ] . into ( ) ) ) ;
112- let target = Location :: new ( 1 , X3 ( [ Parachain ( 8 ) , PalletInstance ( 8 ) , GeneralIndex ( 9 ) ] . into ( ) ) ) ;
113- assert ! ( <XcmConfig as xcm_executor:: Config >:: Aliasers :: contains( & origin, & target) ) ;
114-
115- // Does not allow if not descendant.
116- let origin = Location :: new ( 1 , X1 ( [ PalletInstance ( 8 ) ] . into ( ) ) ) ;
117- let target = Location :: new ( 0 , X2 ( [ PalletInstance ( 8 ) , GeneralIndex ( 9 ) ] . into ( ) ) ) ;
118- assert ! ( !<XcmConfig as xcm_executor:: Config >:: Aliasers :: contains( & origin, & target) ) ;
119- let origin = Location :: new ( 1 , X1 ( [ Parachain ( 8 ) ] . into ( ) ) ) ;
120- let target =
121- Location :: new ( 0 , X2 ( [ Parachain ( 8 ) , AccountId32 { network : None , id : [ 1u8 ; 32 ] } ] . into ( ) ) ) ;
122- assert ! ( !<XcmConfig as xcm_executor:: Config >:: Aliasers :: contains( & origin, & target) ) ;
123- let origin = Location :: new ( 1 , X1 ( [ Parachain ( 8 ) ] . into ( ) ) ) ;
124- let target = Location :: new ( 0 , X1 ( [ AccountId32 { network : None , id : [ 1u8 ; 32 ] } ] . into ( ) ) ) ;
125- assert ! ( !<XcmConfig as xcm_executor:: Config >:: Aliasers :: contains( & origin, & target) ) ;
126- let origin = Location :: new ( 1 , X1 ( [ AccountId32 { network : None , id : [ 1u8 ; 32 ] } ] . into ( ) ) ) ;
127- let target = Location :: new ( 0 , X1 ( [ AccountId32 { network : None , id : [ 1u8 ; 32 ] } ] . into ( ) ) ) ;
128- assert ! ( !<XcmConfig as xcm_executor:: Config >:: Aliasers :: contains( & origin, & target) ) ;
104+ AssetHubWestend :: execute_with ( || {
105+ // Allows aliasing descendant of origin.
106+ let origin = Location :: new ( 1 , X1 ( [ PalletInstance ( 8 ) ] . into ( ) ) ) ;
107+ let target = Location :: new ( 1 , X2 ( [ PalletInstance ( 8 ) , GeneralIndex ( 9 ) ] . into ( ) ) ) ;
108+ assert ! ( <XcmConfig as xcm_executor:: Config >:: Aliasers :: contains( & origin, & target) ) ;
109+ let origin = Location :: new ( 1 , X1 ( [ Parachain ( 8 ) ] . into ( ) ) ) ;
110+ let target = Location :: new (
111+ 1 ,
112+ X2 ( [ Parachain ( 8 ) , AccountId32 { network : None , id : [ 1u8 ; 32 ] } ] . into ( ) ) ,
113+ ) ;
114+ assert ! ( <XcmConfig as xcm_executor:: Config >:: Aliasers :: contains( & origin, & target) ) ;
115+ let origin = Location :: new ( 1 , X1 ( [ Parachain ( 8 ) ] . into ( ) ) ) ;
116+ let target =
117+ Location :: new ( 1 , X3 ( [ Parachain ( 8 ) , PalletInstance ( 8 ) , GeneralIndex ( 9 ) ] . into ( ) ) ) ;
118+ assert ! ( <XcmConfig as xcm_executor:: Config >:: Aliasers :: contains( & origin, & target) ) ;
119+
120+ // Does not allow if not descendant.
121+ let origin = Location :: new ( 1 , X1 ( [ PalletInstance ( 8 ) ] . into ( ) ) ) ;
122+ let target = Location :: new ( 0 , X2 ( [ PalletInstance ( 8 ) , GeneralIndex ( 9 ) ] . into ( ) ) ) ;
123+ assert ! ( !<XcmConfig as xcm_executor:: Config >:: Aliasers :: contains( & origin, & target) ) ;
124+ let origin = Location :: new ( 1 , X1 ( [ Parachain ( 8 ) ] . into ( ) ) ) ;
125+ let target = Location :: new (
126+ 0 ,
127+ X2 ( [ Parachain ( 8 ) , AccountId32 { network : None , id : [ 1u8 ; 32 ] } ] . into ( ) ) ,
128+ ) ;
129+ assert ! ( !<XcmConfig as xcm_executor:: Config >:: Aliasers :: contains( & origin, & target) ) ;
130+ let origin = Location :: new ( 1 , X1 ( [ Parachain ( 8 ) ] . into ( ) ) ) ;
131+ let target = Location :: new ( 0 , X1 ( [ AccountId32 { network : None , id : [ 1u8 ; 32 ] } ] . into ( ) ) ) ;
132+ assert ! ( !<XcmConfig as xcm_executor:: Config >:: Aliasers :: contains( & origin, & target) ) ;
133+ let origin = Location :: new ( 1 , X1 ( [ AccountId32 { network : None , id : [ 1u8 ; 32 ] } ] . into ( ) ) ) ;
134+ let target = Location :: new ( 0 , X1 ( [ AccountId32 { network : None , id : [ 1u8 ; 32 ] } ] . into ( ) ) ) ;
135+ assert ! ( !<XcmConfig as xcm_executor:: Config >:: Aliasers :: contains( & origin, & target) ) ;
136+ } ) ;
129137}
130138
131139#[ test]
132140fn asset_hub_root_aliases_anything ( ) {
133141 use AssetHubWestendXcmConfig as XcmConfig ;
142+ AssetHubWestend :: execute_with ( || {
143+ // Does not allow local/AH root to alias other (non-descendant) locations.
144+ let origin = Location :: new ( 0 , Here ) ;
145+
146+ let target = Location :: new ( 1 , X1 ( [ Parachain ( 2000 ) ] . into ( ) ) ) ;
147+ assert ! ( !<XcmConfig as xcm_executor:: Config >:: Aliasers :: contains( & origin, & target) ) ;
148+ let target = Location :: new ( 1 , X1 ( [ AccountId32 { network : None , id : [ 1u8 ; 32 ] } ] . into ( ) ) ) ;
149+ assert ! ( !<XcmConfig as xcm_executor:: Config >:: Aliasers :: contains( & origin, & target) ) ;
150+ let target = Location :: new (
151+ 1 ,
152+ X2 ( [ Parachain ( 8 ) , AccountId32 { network : None , id : [ 1u8 ; 32 ] } ] . into ( ) ) ,
153+ ) ;
154+ assert ! ( !<XcmConfig as xcm_executor:: Config >:: Aliasers :: contains( & origin, & target) ) ;
155+ let target =
156+ Location :: new ( 1 , X3 ( [ Parachain ( 42 ) , PalletInstance ( 8 ) , GeneralIndex ( 9 ) ] . into ( ) ) ) ;
157+ assert ! ( !<XcmConfig as xcm_executor:: Config >:: Aliasers :: contains( & origin, & target) ) ;
158+ let target = Location :: new ( 2 , X1 ( [ GlobalConsensus ( Ethereum { chain_id : 1 } ) ] . into ( ) ) ) ;
159+ assert ! ( !<XcmConfig as xcm_executor:: Config >:: Aliasers :: contains( & origin, & target) ) ;
160+ let target = Location :: new ( 2 , X2 ( [ GlobalConsensus ( Polkadot ) , Parachain ( 1000 ) ] . into ( ) ) ) ;
161+ assert ! ( !<XcmConfig as xcm_executor:: Config >:: Aliasers :: contains( & origin, & target) ) ;
162+ let target = Location :: new ( 1 , X2 ( [ PalletInstance ( 8 ) , GeneralIndex ( 9 ) ] . into ( ) ) ) ;
163+ assert ! ( !<XcmConfig as xcm_executor:: Config >:: Aliasers :: contains( & origin, & target) ) ;
164+
165+ // Other AH locations cannot alias anything.
166+ let origin = Location :: new ( 1 , X2 ( [ Parachain ( 1000 ) , GeneralIndex ( 9 ) ] . into ( ) ) ) ;
167+ assert ! ( !<XcmConfig as xcm_executor:: Config >:: Aliasers :: contains( & origin, & target) ) ;
168+ let origin = Location :: new ( 1 , X2 ( [ Parachain ( 1000 ) , PalletInstance ( 9 ) ] . into ( ) ) ) ;
169+ assert ! ( !<XcmConfig as xcm_executor:: Config >:: Aliasers :: contains( & origin, & target) ) ;
170+ let origin = Location :: new (
171+ 1 ,
172+ X2 ( [ Parachain ( 1000 ) , AccountId32 { network : None , id : [ 1u8 ; 32 ] } ] . into ( ) ) ,
173+ ) ;
174+ assert ! ( !<XcmConfig as xcm_executor:: Config >:: Aliasers :: contains( & origin, & target) ) ;
134175
135- // Does not allow local/AH root to alias other locations.
136- let origin = Location :: new ( 1 , X1 ( [ Parachain ( 1000 ) ] . into ( ) ) ) ;
137-
138- let target = Location :: new ( 1 , X1 ( [ Parachain ( 2000 ) ] . into ( ) ) ) ;
139- assert ! ( !<XcmConfig as xcm_executor:: Config >:: Aliasers :: contains( & origin, & target) ) ;
140- let target = Location :: new ( 1 , X1 ( [ AccountId32 { network : None , id : [ 1u8 ; 32 ] } ] . into ( ) ) ) ;
141- assert ! ( !<XcmConfig as xcm_executor:: Config >:: Aliasers :: contains( & origin, & target) ) ;
142- let target =
143- Location :: new ( 1 , X2 ( [ Parachain ( 8 ) , AccountId32 { network : None , id : [ 1u8 ; 32 ] } ] . into ( ) ) ) ;
144- assert ! ( !<XcmConfig as xcm_executor:: Config >:: Aliasers :: contains( & origin, & target) ) ;
145- let target = Location :: new ( 1 , X3 ( [ Parachain ( 42 ) , PalletInstance ( 8 ) , GeneralIndex ( 9 ) ] . into ( ) ) ) ;
146- assert ! ( !<XcmConfig as xcm_executor:: Config >:: Aliasers :: contains( & origin, & target) ) ;
147- let target = Location :: new ( 2 , X1 ( [ GlobalConsensus ( Ethereum { chain_id : 1 } ) ] . into ( ) ) ) ;
148- assert ! ( !<XcmConfig as xcm_executor:: Config >:: Aliasers :: contains( & origin, & target) ) ;
149- let target = Location :: new ( 2 , X2 ( [ GlobalConsensus ( Polkadot ) , Parachain ( 1000 ) ] . into ( ) ) ) ;
150- assert ! ( !<XcmConfig as xcm_executor:: Config >:: Aliasers :: contains( & origin, & target) ) ;
151- let target = Location :: new ( 0 , X2 ( [ PalletInstance ( 8 ) , GeneralIndex ( 9 ) ] . into ( ) ) ) ;
152- assert ! ( !<XcmConfig as xcm_executor:: Config >:: Aliasers :: contains( & origin, & target) ) ;
153-
154- // Other AH locations cannot alias anything.
155- let origin = Location :: new ( 1 , X2 ( [ Parachain ( 1000 ) , GeneralIndex ( 9 ) ] . into ( ) ) ) ;
156- assert ! ( !<XcmConfig as xcm_executor:: Config >:: Aliasers :: contains( & origin, & target) ) ;
157- let origin = Location :: new ( 1 , X2 ( [ Parachain ( 1000 ) , PalletInstance ( 9 ) ] . into ( ) ) ) ;
158- assert ! ( !<XcmConfig as xcm_executor:: Config >:: Aliasers :: contains( & origin, & target) ) ;
159- let origin = Location :: new (
160- 1 ,
161- X2 ( [ Parachain ( 1000 ) , AccountId32 { network : None , id : [ 1u8 ; 32 ] } ] . into ( ) ) ,
176+ // Other root locations cannot alias anything.
177+ let origin = Location :: new ( 1 , Here ) ;
178+ let target = Location :: new ( 2 , X1 ( [ GlobalConsensus ( Ethereum { chain_id : 1 } ) ] . into ( ) ) ) ;
179+ assert ! ( !<XcmConfig as xcm_executor:: Config >:: Aliasers :: contains( & origin, & target) ) ;
180+ let target = Location :: new ( 2 , X2 ( [ GlobalConsensus ( Polkadot ) , Parachain ( 1000 ) ] . into ( ) ) ) ;
181+ assert ! ( !<XcmConfig as xcm_executor:: Config >:: Aliasers :: contains( & origin, & target) ) ;
182+ let target = Location :: new ( 0 , X2 ( [ PalletInstance ( 8 ) , GeneralIndex ( 9 ) ] . into ( ) ) ) ;
183+ assert ! ( !<XcmConfig as xcm_executor:: Config >:: Aliasers :: contains( & origin, & target) ) ;
184+
185+ let origin = Location :: new ( 0 , Here ) ;
186+ let target = Location :: new ( 1 , X1 ( [ Parachain ( 2000 ) ] . into ( ) ) ) ;
187+ assert ! ( !<XcmConfig as xcm_executor:: Config >:: Aliasers :: contains( & origin, & target) ) ;
188+ let origin = Location :: new ( 1 , X1 ( [ Parachain ( 1001 ) ] . into ( ) ) ) ;
189+ assert ! ( !<XcmConfig as xcm_executor:: Config >:: Aliasers :: contains( & origin, & target) ) ;
190+ let origin = Location :: new ( 1 , X1 ( [ Parachain ( 1002 ) ] . into ( ) ) ) ;
191+ assert ! ( !<XcmConfig as xcm_executor:: Config >:: Aliasers :: contains( & origin, & target) ) ;
192+ } ) ;
193+ }
194+
195+ #[ test]
196+ fn authorized_cross_chain_aliases ( ) {
197+ // origin and target are different accounts on different chains
198+ let origin: AccountId = [ 100 ; 32 ] . into ( ) ;
199+ let bad_origin: AccountId = [ 150 ; 32 ] . into ( ) ;
200+ let target: AccountId = [ 200 ; 32 ] . into ( ) ;
201+ let fees = WESTEND_ED * 10 ;
202+
203+ let pal_admin = <PenpalB as Chain >:: RuntimeOrigin :: signed ( PenpalAssetOwner :: get ( ) ) ;
204+ PenpalB :: mint_foreign_asset ( pal_admin. clone ( ) , Location :: parent ( ) , origin. clone ( ) , fees * 10 ) ;
205+ PenpalB :: mint_foreign_asset ( pal_admin, Location :: parent ( ) , bad_origin. clone ( ) , fees * 10 ) ;
206+ AssetHubWestend :: fund_accounts ( vec ! [ ( target. clone( ) , fees * 10 ) ] ) ;
207+
208+ // let's authorize `origin` on Penpal to alias `target` on AssetHub
209+ AssetHubWestend :: execute_with ( || {
210+ let penpal_origin = Location :: new (
211+ 1 ,
212+ X2 ( [
213+ Parachain ( PenpalB :: para_id ( ) . into ( ) ) ,
214+ AccountId32 {
215+ network : Some ( ByGenesis ( WESTEND_GENESIS_HASH ) ) ,
216+ id : origin. clone ( ) . into ( ) ,
217+ } ,
218+ ]
219+ . into ( ) ) ,
220+ ) ;
221+ // `target` adds `penpal_origin` as authorized alias
222+ assert_ok ! ( <AssetHubWestend as AssetHubWestendPallet >:: PolkadotXcm :: add_authorized_alias(
223+ <AssetHubWestend as Chain >:: RuntimeOrigin :: signed( target. clone( ) ) ,
224+ Box :: new( penpal_origin. into( ) ) ,
225+ None
226+ ) ) ;
227+ } ) ;
228+ // Verify that unauthorized `bad_origin` cannot alias into `target`, from any chain.
229+ test_cross_chain_alias ! (
230+ vec![
231+ // between BH and AssetHub: denied
232+ ( BridgeHubWestend , AssetHubWestend , TELEPORT_FEES , DENIED ) ,
233+ // between Collectives and AssetHub: denied
234+ ( CollectivesWestend , AssetHubWestend , TELEPORT_FEES , DENIED ) ,
235+ // between People and AssetHub: denied
236+ ( PeopleWestend , AssetHubWestend , TELEPORT_FEES , DENIED ) ,
237+ // between Penpal and AssetHub: denied
238+ ( PenpalB , AssetHubWestend , RESERVE_TRANSFER_FEES , DENIED )
239+ ] ,
240+ bad_origin,
241+ target,
242+ fees
243+ ) ;
244+ // Verify that only authorized `penpal::origin` can alias into `target`, while `origin` on other
245+ // chains cannot.
246+ test_cross_chain_alias ! (
247+ vec![
248+ // between BH and AssetHub: denied
249+ ( BridgeHubWestend , AssetHubWestend , TELEPORT_FEES , DENIED ) ,
250+ // between Collectives and AssetHub: denied
251+ ( CollectivesWestend , AssetHubWestend , TELEPORT_FEES , DENIED ) ,
252+ // between People and AssetHub: denied
253+ ( PeopleWestend , AssetHubWestend , TELEPORT_FEES , DENIED ) ,
254+ // between Penpal and AssetHub: allowed
255+ ( PenpalB , AssetHubWestend , RESERVE_TRANSFER_FEES , ALLOWED )
256+ ] ,
257+ origin,
258+ target,
259+ fees
260+ ) ;
261+ // remove authorization for `origin` on Penpal to alias `target` on AssetHub
262+ AssetHubWestend :: execute_with ( || {
263+ // `target` removes all authorized aliases
264+ assert_ok ! (
265+ <AssetHubWestend as AssetHubWestendPallet >:: PolkadotXcm :: remove_all_authorized_aliases(
266+ <AssetHubWestend as Chain >:: RuntimeOrigin :: signed( target. clone( ) )
267+ )
268+ ) ;
269+ } ) ;
270+ // Verify `penpal::origin` can no longer alias into `target` on AssetHub.
271+ test_cross_chain_alias ! (
272+ vec![ ( PenpalB , AssetHubWestend , RESERVE_TRANSFER_FEES , DENIED ) ] ,
273+ origin,
274+ target,
275+ fees
162276 ) ;
163- assert ! ( !<XcmConfig as xcm_executor:: Config >:: Aliasers :: contains( & origin, & target) ) ;
164-
165- // Other root locations cannot alias anything.
166- let origin = Location :: new ( 1 , Here ) ;
167- let target = Location :: new ( 2 , X1 ( [ GlobalConsensus ( Ethereum { chain_id : 1 } ) ] . into ( ) ) ) ;
168- assert ! ( !<XcmConfig as xcm_executor:: Config >:: Aliasers :: contains( & origin, & target) ) ;
169- let target = Location :: new ( 2 , X2 ( [ GlobalConsensus ( Polkadot ) , Parachain ( 1000 ) ] . into ( ) ) ) ;
170- assert ! ( !<XcmConfig as xcm_executor:: Config >:: Aliasers :: contains( & origin, & target) ) ;
171- let target = Location :: new ( 0 , X2 ( [ PalletInstance ( 8 ) , GeneralIndex ( 9 ) ] . into ( ) ) ) ;
172- assert ! ( !<XcmConfig as xcm_executor:: Config >:: Aliasers :: contains( & origin, & target) ) ;
173-
174- let origin = Location :: new ( 0 , Here ) ;
175- let target = Location :: new ( 1 , X1 ( [ Parachain ( 2000 ) ] . into ( ) ) ) ;
176- assert ! ( !<XcmConfig as xcm_executor:: Config >:: Aliasers :: contains( & origin, & target) ) ;
177- let origin = Location :: new ( 1 , X1 ( [ Parachain ( 1001 ) ] . into ( ) ) ) ;
178- assert ! ( !<XcmConfig as xcm_executor:: Config >:: Aliasers :: contains( & origin, & target) ) ;
179- let origin = Location :: new ( 1 , X1 ( [ Parachain ( 1002 ) ] . into ( ) ) ) ;
180- assert ! ( !<XcmConfig as xcm_executor:: Config >:: Aliasers :: contains( & origin, & target) ) ;
181277}
0 commit comments