Skip to content

Commit

Permalink
bridge tests: send bridged assets from random parachain to bridged as…
Browse files Browse the repository at this point in the history
…set hub (paritytech#4870)

- Send bridged WNDs: Penpal Rococo -> AH Rococo -> AH Westend
- Send bridged ROCs: Penpal Westend -> AH Westend -> AH Rococo

The tests send both ROCs and WNDs, for each direction the native asset
is only used to pay for the transport fees on the local AssetHub, and
are not sent over the bridge.

Including the native asset won't be necessary anymore once we get paritytech#4375.

---------

Signed-off-by: Adrian Catangiu <[email protected]>
Co-authored-by: command-bot <>
  • Loading branch information
acatangiu authored Jul 3, 2024
1 parent 6b9d14a commit 98ce675
Show file tree
Hide file tree
Showing 42 changed files with 632 additions and 356 deletions.
16 changes: 0 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

pub use asset_hub_rococo_runtime;

pub mod genesis;

// Substrate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

pub use asset_hub_westend_runtime;

pub mod genesis;

// Substrate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@

pub mod genesis;

pub use bridge_hub_rococo_runtime::{
xcm_config::XcmConfig as BridgeHubRococoXcmConfig, EthereumBeaconClient, EthereumInboundQueue,
RuntimeOrigin as BridgeHubRococoRuntimeOrigin,
};

// Substrate
use frame_support::traits::OnInitialize;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

pub mod genesis;

pub use bridge_hub_westend_runtime::xcm_config::XcmConfig as BridgeHubWestendXcmConfig;

// Substrate
use frame_support::traits::OnInitialize;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

pub use collectives_westend_runtime;

pub mod genesis;

// Substrate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// 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.
pub use people_rococo_runtime;

pub mod genesis;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// 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.
pub use people_westend_runtime;

pub mod genesis;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

pub use penpal_runtime::{self, xcm_config::RelayNetworkId as PenpalRelayNetworkId};

mod genesis;
pub use genesis::{genesis, PenpalAssetOwner, PenpalSudoAccount, ED, PARA_ID_A, PARA_ID_B};
pub use penpal_runtime::xcm_config::{
CustomizableAssetFromSystemAssetHub, RelayNetworkId as PenpalRelayNetworkId,
};

// Substrate
use frame_support::traits::OnInitialize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// 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.
pub use rococo_runtime;

pub mod genesis;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// 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.
pub use westend_runtime;

pub mod genesis;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,12 @@ pallet-utility = { workspace = true }
xcm = { workspace = true }
pallet-xcm = { workspace = true }
xcm-executor = { workspace = true }
rococo-runtime = { workspace = true }
polkadot-runtime-common = { workspace = true, default-features = true }
rococo-runtime-constants = { workspace = true, default-features = true }

# Cumulus
asset-test-utils = { workspace = true, default-features = true }
cumulus-pallet-parachain-system = { workspace = true }
parachains-common = { workspace = true, default-features = true }
asset-hub-rococo-runtime = { workspace = true, default-features = true }
penpal-runtime = { workspace = true }
emulated-integration-tests-common = { workspace = true }
rococo-system-emulated-network = { workspace = true }
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,36 @@ mod imports {
pub use parachains_common::Balance;
pub use rococo_system_emulated_network::{
asset_hub_rococo_emulated_chain::{
asset_hub_rococo_runtime::{
xcm_config::{
self as ahr_xcm_config, TokenLocation as RelayLocation,
XcmConfig as AssetHubRococoXcmConfig,
},
AssetConversionOrigin as AssetHubRococoAssetConversionOrigin,
},
genesis::{AssetHubRococoAssetOwner, ED as ASSET_HUB_ROCOCO_ED},
AssetHubRococoParaPallet as AssetHubRococoPallet,
},
penpal_emulated_chain::{
penpal_runtime::xcm_config::{
CustomizableAssetFromSystemAssetHub as PenpalCustomizableAssetFromSystemAssetHub,
LocalReservableFromAssetHub as PenpalLocalReservableFromAssetHub,
LocalTeleportableToAssetHub as PenpalLocalTeleportableToAssetHub,
},
PenpalAParaPallet as PenpalAPallet, PenpalAssetOwner,
PenpalBParaPallet as PenpalBPallet, ED as PENPAL_ED,
},
rococo_emulated_chain::{genesis::ED as ROCOCO_ED, RococoRelayPallet as RococoPallet},
rococo_emulated_chain::{
genesis::ED as ROCOCO_ED,
rococo_runtime::{
governance as rococo_governance,
xcm_config::{
UniversalLocation as RococoUniversalLocation, XcmConfig as RococoXcmConfig,
},
OriginCaller as RococoOriginCaller,
},
RococoRelayPallet as RococoPallet,
},
AssetHubRococoPara as AssetHubRococo, AssetHubRococoParaReceiver as AssetHubRococoReceiver,
AssetHubRococoParaSender as AssetHubRococoSender, BridgeHubRococoPara as BridgeHubRococo,
BridgeHubRococoParaReceiver as BridgeHubRococoReceiver, PenpalAPara as PenpalA,
Expand All @@ -62,18 +84,6 @@ mod imports {
RococoRelayReceiver as RococoReceiver, RococoRelaySender as RococoSender,
};

// Runtimes
pub use asset_hub_rococo_runtime::xcm_config::{
TokenLocation as RelayLocation, XcmConfig as AssetHubRococoXcmConfig,
};
pub use penpal_runtime::xcm_config::{
LocalReservableFromAssetHub as PenpalLocalReservableFromAssetHub,
LocalTeleportableToAssetHub as PenpalLocalTeleportableToAssetHub,
};
pub use rococo_runtime::xcm_config::{
UniversalLocation as RococoUniversalLocation, XcmConfig as RococoXcmConfig,
};

pub const ASSET_ID: u32 = 3;
pub const ASSET_MIN_BALANCE: u128 = 1000;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ fn transfer_foreign_assets_from_asset_hub_to_para() {
assert_ok!(<PenpalA as Chain>::System::set_storage(
<PenpalA as Chain>::RuntimeOrigin::root(),
vec![(
penpal_runtime::xcm_config::CustomizableAssetFromSystemAssetHub::key().to_vec(),
PenpalCustomizableAssetFromSystemAssetHub::key().to_vec(),
Location::new(2, [GlobalConsensus(Westend)]).encode(),
)],
));
Expand Down Expand Up @@ -300,7 +300,7 @@ fn transfer_foreign_assets_from_para_to_asset_hub() {
assert_ok!(<PenpalA as Chain>::System::set_storage(
<PenpalA as Chain>::RuntimeOrigin::root(),
vec![(
penpal_runtime::xcm_config::CustomizableAssetFromSystemAssetHub::key().to_vec(),
PenpalCustomizableAssetFromSystemAssetHub::key().to_vec(),
Location::new(2, [GlobalConsensus(Westend)]).encode(),
)],
));
Expand Down Expand Up @@ -454,7 +454,7 @@ fn transfer_foreign_assets_from_para_to_para_through_asset_hub() {
assert_ok!(<PenpalB as Chain>::System::set_storage(
<PenpalB as Chain>::RuntimeOrigin::root(),
vec![(
penpal_runtime::xcm_config::CustomizableAssetFromSystemAssetHub::key().to_vec(),
PenpalCustomizableAssetFromSystemAssetHub::key().to_vec(),
Location::new(2, [GlobalConsensus(Westend)]).encode(),
)],
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ use crate::imports::*;

#[test]
fn swap_locally_on_chain_using_local_assets() {
let asset_native = Box::new(
v3::Location::try_from(asset_hub_rococo_runtime::xcm_config::TokenLocation::get())
.expect("conversion works"),
);
let asset_native = Box::new(v3::Location::try_from(RelayLocation::get()).unwrap());
let asset_one = Box::new(v3::Location::new(
0,
[
Expand Down Expand Up @@ -230,12 +227,12 @@ fn swap_locally_on_chain_using_foreign_assets() {

#[test]
fn cannot_create_pool_from_pool_assets() {
let asset_native = asset_hub_rococo_runtime::xcm_config::TokenLocation::get();
let mut asset_one = asset_hub_rococo_runtime::xcm_config::PoolAssetsPalletLocation::get();
let asset_native = RelayLocation::get();
let mut asset_one = ahr_xcm_config::PoolAssetsPalletLocation::get();
asset_one.append_with(GeneralIndex(ASSET_ID.into())).expect("pool assets");

AssetHubRococo::execute_with(|| {
let pool_owner_account_id = asset_hub_rococo_runtime::AssetConversionOrigin::get();
let pool_owner_account_id = AssetHubRococoAssetConversionOrigin::get();

assert_ok!(<AssetHubRococo as AssetHubRococoPallet>::PoolAssets::create(
<AssetHubRococo as Chain>::RuntimeOrigin::signed(pool_owner_account_id.clone()),
Expand All @@ -255,8 +252,8 @@ fn cannot_create_pool_from_pool_assets() {
assert_matches::assert_matches!(
<AssetHubRococo as AssetHubRococoPallet>::AssetConversion::create_pool(
<AssetHubRococo as Chain>::RuntimeOrigin::signed(AssetHubRococoSender::get()),
Box::new(v3::Location::try_from(asset_native).expect("conversion works")),
Box::new(v3::Location::try_from(asset_one).expect("conversion works")),
Box::new(v3::Location::try_from(asset_native).unwrap()),
Box::new(v3::Location::try_from(asset_one).unwrap()),
),
Err(DispatchError::Module(ModuleError{index: _, error: _, message})) => assert_eq!(message, Some("Unknown"))
);
Expand All @@ -265,9 +262,7 @@ fn cannot_create_pool_from_pool_assets() {

#[test]
fn pay_xcm_fee_with_some_asset_swapped_for_native() {
let asset_native =
v3::Location::try_from(asset_hub_rococo_runtime::xcm_config::TokenLocation::get())
.expect("conversion works");
let asset_native = v3::Location::try_from(RelayLocation::get()).unwrap();
let asset_one = xcm::v3::Location {
parents: 0,
interior: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use frame_support::{
};
use parachains_common::AccountId;
use polkadot_runtime_common::impls::VersionedLocatableAsset;
use rococo_runtime::OriginCaller;
use rococo_runtime_constants::currency::GRAND;
use xcm_executor::traits::ConvertLocation;

Expand Down Expand Up @@ -67,7 +66,7 @@ fn spend_roc_on_asset_hub() {
let treasury_location: Location = (Parent, PalletInstance(18)).into();

let teleport_call = RuntimeCall::Utility(pallet_utility::Call::<Runtime>::dispatch_as {
as_origin: bx!(OriginCaller::system(RawOrigin::Signed(treasury_account))),
as_origin: bx!(RococoOriginCaller::system(RawOrigin::Signed(treasury_account))),
call: bx!(RuntimeCall::XcmPallet(pallet_xcm::Call::<Runtime>::teleport_assets {
dest: bx!(VersionedLocation::V4(asset_hub_location.clone())),
beneficiary: bx!(VersionedLocation::V4(treasury_location)),
Expand Down Expand Up @@ -99,7 +98,7 @@ fn spend_roc_on_asset_hub() {
// Fund Alice account from Rococo Treasury account on Asset Hub.

let treasury_origin: RuntimeOrigin =
rococo_runtime::governance::pallet_custom_origins::Origin::Treasurer.into();
rococo_governance::pallet_custom_origins::Origin::Treasurer.into();

let alice_location: Location =
[Junction::AccountId32 { network: None, id: Rococo::account_id_of(ALICE).into() }]
Expand Down Expand Up @@ -168,10 +167,7 @@ fn create_and_claim_treasury_spend_in_usdt() {
let treasury_location: Location = Location::new(1, PalletInstance(18));
// treasury account on a sibling parachain.
let treasury_account =
asset_hub_rococo_runtime::xcm_config::LocationToAccountId::convert_location(
&treasury_location,
)
.unwrap();
ahr_xcm_config::LocationToAccountId::convert_location(&treasury_location).unwrap();
let asset_hub_location =
v3::Location::new(0, v3::Junction::Parachain(AssetHubRococo::para_id().into()));
let root = <Rococo as Chain>::RuntimeOrigin::root();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,9 @@ xcm = { workspace = true }
xcm-executor = { workspace = true }
pallet-xcm = { workspace = true }
xcm-runtime-apis = { workspace = true }
westend-runtime = { workspace = true }

# Cumulus
parachains-common = { workspace = true, default-features = true }
penpal-runtime = { workspace = true }
asset-hub-westend-runtime = { workspace = true }
asset-test-utils = { workspace = true, default-features = true }
cumulus-pallet-xcmp-queue = { workspace = true }
cumulus-pallet-parachain-system = { workspace = true }
Expand Down
Loading

0 comments on commit 98ce675

Please sign in to comment.