diff --git a/cumulus/parachains/runtimes/assets/common/src/matching.rs b/cumulus/parachains/runtimes/assets/common/src/matching.rs index c8f8d0a7df708..d6ecc3ec99f04 100644 --- a/cumulus/parachains/runtimes/assets/common/src/matching.rs +++ b/cumulus/parachains/runtimes/assets/common/src/matching.rs @@ -58,6 +58,8 @@ impl> ContainsPair } } +/// Checks if `a` is from the expected global consensus network. Checks that `MultiLocation-a` +/// starts with `MultiLocation-b`, and that network is a foreign consensus system. pub struct FromNetwork( sp_std::marker::PhantomData<(UniversalLocation, ExpectedNetworkId)>, ); @@ -72,6 +74,7 @@ impl, ExpectedNetworkId: Get network_id == ExpectedNetworkId::get(), Err(e) => { @@ -85,6 +88,7 @@ impl, ExpectedNetworkId: Get::contains(&asset, &origin)); + + // asset and origin from local consensus fails + let asset: MultiLocation = ( + Parent, + Parent, + GlobalConsensus(Rococo), + Parachain(1000), + PalletInstance(1), + GeneralIndex(1), + ) + .into(); + let origin: MultiLocation = + (Parent, Parent, GlobalConsensus(Rococo), Parachain(1000)).into(); + assert!(!FromNetwork::::contains(&asset, &origin)); + + // asset and origin from here fails + let asset: MultiLocation = (PalletInstance(1), GeneralIndex(1)).into(); + let origin: MultiLocation = Here.into(); + assert!(!FromNetwork::::contains(&asset, &origin)); + + // asset from different consensus fails + let asset: MultiLocation = ( + Parent, + Parent, + GlobalConsensus(Polkadot), + Parachain(1000), + PalletInstance(1), + GeneralIndex(1), + ) + .into(); + let origin: MultiLocation = + (Parent, Parent, GlobalConsensus(Wococo), Parachain(1000)).into(); + assert!(!FromNetwork::::contains(&asset, &origin)); + + // origin from different consensus fails + let asset: MultiLocation = ( + Parent, + Parent, + GlobalConsensus(Wococo), + Parachain(1000), + PalletInstance(1), + GeneralIndex(1), + ) + .into(); + let origin: MultiLocation = + (Parent, Parent, GlobalConsensus(Polkadot), Parachain(1000)).into(); + assert!(!FromNetwork::::contains(&asset, &origin)); + + // asset and origin from unexpected consensus fails + let asset: MultiLocation = ( + Parent, + Parent, + GlobalConsensus(Polkadot), + Parachain(1000), + PalletInstance(1), + GeneralIndex(1), + ) + .into(); + let origin: MultiLocation = + (Parent, Parent, GlobalConsensus(Polkadot), Parachain(1000)).into(); + assert!(!FromNetwork::::contains(&asset, &origin)); + } +}