Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Add Bridges to xcm-emulator #2812

Merged
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
832ea95
rename bridge hub + BridgeMessages type
NachoPal Jun 15, 2023
2e1e065
bridge base
NachoPal Jun 18, 2023
5d8dda1
bridge string approach
NachoPal Jun 19, 2023
ee1a0d2
add decl_test_bridges macro
NachoPal Jun 19, 2023
0714c47
outbound lanes on the way
NachoPal Jun 20, 2023
7e22c13
get & dispatch mock bridge done
NachoPal Jun 21, 2023
ab15f33
fix bridge errors + log::debug for messages
NachoPal Jun 21, 2023
1c71eb4
clean up
NachoPal Jun 22, 2023
ea9606f
update source OutboundLaneData
NachoPal Jun 22, 2023
a478ae6
rococo & wococo added
NachoPal Jun 22, 2023
d53b674
sender_receiver_accounts_parameter_types macro
NachoPal Jun 23, 2023
281f5a5
sender_receiver_accounts_parameter_types macro 2
NachoPal Jun 23, 2023
1463d22
fixed multi parachain + example on the way
NachoPal Jun 23, 2023
d39deeb
working but router error
NachoPal Jun 27, 2023
6e91b96
bridge working
NachoPal Jun 27, 2023
97bb46a
refactor NetworkComponent
NachoPal Jun 29, 2023
e9d3a07
make it generic
NachoPal Jun 29, 2023
b0cbf79
working as generic
NachoPal Jun 30, 2023
4ea717b
clean up
NachoPal Jun 30, 2023
7ca9ecb
last bit
NachoPal Jul 3, 2023
8e645b7
merge master
NachoPal Jul 3, 2023
420c779
".git/.scripts/commands/fmt/fmt.sh"
Jul 3, 2023
f9675bc
fix bridge hub handler name
NachoPal Jul 3, 2023
0dbb673
fix conflict
NachoPal Jul 3, 2023
d0d6eb2
".git/.scripts/commands/fmt/fmt.sh"
Jul 3, 2023
5830ec2
add AssetConversion back for AssetHubWestend
NachoPal Jul 3, 2023
52281b5
Update xcm/xcm-emulator/src/lib.rs
NachoPal Jul 4, 2023
4cd02c5
add LaneId wrapper
NachoPal Jul 4, 2023
92e8f20
update substrate
NachoPal Jul 4, 2023
82c20a9
fix wrapper conversion
NachoPal Jul 4, 2023
17c0612
remove duplicate in workspace
NachoPal Jul 4, 2023
e9ff40d
Revert "update substrate"
NachoPal Jul 4, 2023
1f9bc13
".git/.scripts/commands/fmt/fmt.sh"
Jul 4, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ members = [
"parachains/integration-tests/emulated/assets/asset-hub-kusama",
"parachains/integration-tests/emulated/assets/asset-hub-polkadot",
"parachains/integration-tests/emulated/assets/asset-hub-westend",
"parachains/integration-tests/emulated/bridges/bridge-hub-rococo",
"parachains/integration-tests/emulated/collectives/collectives-polkadot",
"parachains/integration-tests/emulated/bridges/bridge-hub-rococo",
"test/client",
"test/relay-sproof-builder",
"test/relay-validation-worker-provider",
Expand Down
12 changes: 12 additions & 0 deletions bridges/primitives/messages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,18 @@ impl TypeId for LaneId {
const TYPE_ID: [u8; 4] = *b"blan";
}

impl From<LaneId> for u32 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NachoPal @svyatonik
I am not sure about this, can we move this out of bridges substree?
Because then we need to backport it back to bridges repo and also in new version LaneId has a different type: https://github.com/paritytech/parity-bridges-common/pull/2221/files#diff-836b204328629e6af4b33c2a34ae41191cab06cf89c066e31bdb7085314fcda1L185-R203

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed there's probably a better way to do this.

Copy link
Contributor Author

@NachoPal NachoPal Jul 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is implementing From for LaneId or the fact that LaneId is going to change? I do not think it is harmful to implement an extra From for a new type.

I could try to locally (as part of the BridgeHubMessageHandler impl) wrap LaneId in a new type and implement the From trait for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could try to locally (as part of the BridgeHubMessageHandler impl) wrap LaneId in a new type and implement the From trait for it.

@bkontur @gilescope Check it out

fn from(lane_id: LaneId) -> u32 {
u32::from_be_bytes(lane_id.0)
}
}

impl From<u32> for LaneId {
fn from(id: u32) -> LaneId {
LaneId(id.to_be_bytes())
}
}

/// Message nonce. Valid messages will never have 0 nonce.
pub type MessageNonce = u64;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ pub use integration_tests_common::{
PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V3,
},
AccountId, AssetHubKusama, AssetHubKusamaPallet, AssetHubKusamaReceiver, AssetHubKusamaSender,
BHKusama, BHKusamaPallet, BHKusamaReceiver, BHKusamaSender, BHPolkadot, BHPolkadotPallet,
BHPolkadotReceiver, BHPolkadotSender, Collectives, CollectivesPallet, CollectivesReceiver,
CollectivesSender, Kusama, KusamaMockNet, KusamaPallet, KusamaReceiver, KusamaSender,
PenpalKusama, PenpalKusamaReceiver, PenpalKusamaSender, PenpalPolkadot, PenpalPolkadotReceiver,
PenpalPolkadotSender, Polkadot, PolkadotMockNet, PolkadotPallet, PolkadotReceiver,
PolkadotSender,
BridgeHubKusama, BridgeHubKusamaPallet, BridgeHubKusamaReceiver, BridgeHubKusamaSender,
BridgeHubPolkadot, BridgeHubPolkadotPallet, BridgeHubPolkadotReceiver, BridgeHubPolkadotSender,
Collectives, CollectivesPallet, CollectivesReceiver, CollectivesSender, Kusama, KusamaMockNet,
KusamaPallet, KusamaReceiver, KusamaSender, PenpalKusama, PenpalKusamaReceiver,
PenpalKusamaSender, PenpalPolkadot, PenpalPolkadotReceiver, PenpalPolkadotSender, Polkadot,
PolkadotMockNet, PolkadotPallet, PolkadotReceiver, PolkadotSender,
};
pub use polkadot_core_primitives::InboundDownwardMessage;
pub use xcm::{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ pub use integration_tests_common::{
},
AccountId, AssetHubKusama, AssetHubKusamaPallet, AssetHubKusamaReceiver, AssetHubKusamaSender,
AssetHubPolkadot, AssetHubPolkadotPallet, AssetHubPolkadotReceiver, AssetHubPolkadotSender,
BHKusama, BHKusamaPallet, BHKusamaReceiver, BHKusamaSender, BHPolkadot, BHPolkadotPallet,
BHPolkadotReceiver, BHPolkadotSender, Collectives, CollectivesPallet, CollectivesReceiver,
CollectivesSender, Kusama, KusamaMockNet, KusamaPallet, KusamaReceiver, KusamaSender,
PenpalKusama, PenpalKusamaReceiver, PenpalKusamaSender, PenpalPolkadot, PenpalPolkadotReceiver,
PenpalPolkadotSender, Polkadot, PolkadotMockNet, PolkadotPallet, PolkadotReceiver,
PolkadotSender,
BridgeHubKusama, BridgeHubKusamaPallet, BridgeHubKusamaReceiver, BridgeHubKusamaSender,
BridgeHubPolkadot, BridgeHubPolkadotPallet, BridgeHubPolkadotReceiver, BridgeHubPolkadotSender,
Collectives, CollectivesPallet, CollectivesReceiver, CollectivesSender, Kusama, KusamaMockNet,
KusamaPallet, KusamaReceiver, KusamaSender, PenpalKusama, PenpalKusamaReceiver,
PenpalKusamaSender, PenpalPolkadot, PenpalPolkadotReceiver, PenpalPolkadotSender, Polkadot,
PolkadotMockNet, PolkadotPallet, PolkadotReceiver, PolkadotSender,
};
pub use polkadot_core_primitives::InboundDownwardMessage;
pub use xcm::{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[package]
name = "bridge-hub-rococo-integration-tests"
version = "1.0.0"
authors = ["Parity Technologies <[email protected]>"]
edition = "2021"
description = "Bridge Hub Rococo runtime integration tests with xcm-emulator"

[dependencies]
codec = { package = "parity-scale-codec", version = "3.4.0", default-features = false }

# Substrate
sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master" }
frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master" }
frame-system = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master" }
sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master" }
sp-weights = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master" }
pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master" }
pallet-assets = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master" }

# Polkadot
polkadot-core-primitives = { default-features = false, git = "https://github.com/paritytech/polkadot", branch = "master" }
polkadot-parachain = { default-features = false, git = "https://github.com/paritytech/polkadot", branch = "master" }
polkadot-runtime-parachains = { git = "https://github.com/paritytech/polkadot", branch = "master" }
polkadot-runtime = { git = "https://github.com/paritytech/polkadot", branch = "master" }
xcm = { default-features = false, git = "https://github.com/paritytech/polkadot", branch = "master" }
xcm-executor = { default-features = false, git = "https://github.com/paritytech/polkadot", branch = "master" }
pallet-xcm = { default-features = false, git = "https://github.com/paritytech/polkadot", branch = "master" }

# Cumulus
parachains-common = { path = "../../../../common" }
cumulus-pallet-xcmp-queue = { default-features = false, path = "../../../../../pallets/xcmp-queue" }
bridge-hub-rococo-runtime = { path = "../../../../runtimes/bridge-hubs/bridge-hub-rococo" }
pallet-bridge-messages = { default-features = false, path = "../../../../../bridges/modules/messages" }
bp-messages = { default-features = false, path = "../../../../../bridges/primitives/messages" }

# Local
xcm-emulator = { default-features = false, path = "../../../../../xcm/xcm-emulator" }
integration-tests-common = { default-features = false, path = "../../common" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright Parity Technologies (UK) Ltd.
// This file is part of Cumulus.

// Cumulus is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Cumulus is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.

pub use bp_messages::LaneId;
pub use codec::Encode;
pub use frame_support::{assert_ok, pallet_prelude::Weight};
pub use integration_tests_common::{
constants::{
accounts::{ALICE, BOB},
rococo::{ED as ROCOCO_ED, ED as WOCOCO_ED},
PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V3,
},
AccountId, AssetHubWococo, BridgeHubPolkadot, BridgeHubPolkadotPallet,
BridgeHubPolkadotReceiver, BridgeHubPolkadotSender, BridgeHubRococo, BridgeHubRococoPallet,
BridgeHubRococoReceiver, BridgeHubRococoSender, BridgeHubWococo, Collectives,
CollectivesPallet, CollectivesReceiver, CollectivesSender, Kusama, KusamaPallet,
PenpalPolkadot, PenpalPolkadotReceiver, PenpalPolkadotSender, Polkadot, PolkadotMockNet,
PolkadotPallet, PolkadotReceiver, PolkadotSender, Rococo, RococoMockNet, RococoPallet,
RococoReceiver, RococoSender,
};
// pub use polkadot_core_primitives::InboundDownwardMessage;
pub use xcm::{
prelude::*,
v3::{
Error,
NetworkId::{Rococo as RococoId, Wococo as WococoId},
},
};
pub use xcm_emulator::{
assert_expected_events, bx, cumulus_pallet_dmp_queue, helpers::weight_within_threshold,
Parachain as Para, RelayChain as Relay, TestExt,
};

#[cfg(test)]
mod tests;
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// Copyright Parity Technologies (UK) Ltd.
// This file is part of Cumulus.

// Cumulus is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Cumulus is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.

use crate::*;

#[test]
fn example() {
// Init tests variables
// XcmPallet send arguments
let sudo_origin = <Rococo as Relay>::RuntimeOrigin::root();
let destination = Rococo::child_location_of(BridgeHubRococo::para_id()).into();
let weight_limit = WeightLimit::Unlimited;
let check_origin = None;

let remote_xcm = Xcm(vec![ClearOrigin]);

let xcm = VersionedXcm::from(Xcm(vec![
UnpaidExecution { weight_limit, check_origin },
ExportMessage {
network: WococoId,
destination: X1(Parachain(AssetHubWococo::para_id().into())),
xcm: remote_xcm,
},
]));

//Rococo Global Consensus
// Send XCM message from Relay Chain to Brid Hub source Parachain
Rococo::execute_with(|| {
assert_ok!(<Rococo as RococoPallet>::XcmPallet::send(
sudo_origin,
bx!(destination),
bx!(xcm),
));

type RuntimeEvent = <Rococo as Relay>::RuntimeEvent;

assert_expected_events!(
Rococo,
vec![
RuntimeEvent::XcmPallet(pallet_xcm::Event::Sent { .. }) => {},
]
);
});
// Receive XCM message in Bridge Hub source Parachain
BridgeHubRococo::execute_with(|| {
type RuntimeEvent = <BridgeHubRococo as Para>::RuntimeEvent;

assert_expected_events!(
BridgeHubRococo,
vec![
RuntimeEvent::DmpQueue(cumulus_pallet_dmp_queue::Event::ExecutedDownward {
outcome: Outcome::Complete(_),
..
}) => {},
RuntimeEvent::BridgeWococoMessages(pallet_bridge_messages::Event::MessageAccepted {
lane_id: LaneId([0, 0, 0, 1]),
nonce: 1,
}) => {},
]
);
});

// Wococo GLobal Consensus
// Receive XCM message in Bridge Hub target Parachain
BridgeHubWococo::execute_with(|| {
type RuntimeEvent = <BridgeHubWococo as Para>::RuntimeEvent;

assert_expected_events!(
BridgeHubWococo,
vec![
RuntimeEvent::XcmpQueue(cumulus_pallet_xcmp_queue::Event::XcmpMessageSent { .. }) => {},
]
);
});
// Receive embeded XCM message within `ExportMessage` in Parachain destination
AssetHubWococo::execute_with(|| {
type RuntimeEvent = <AssetHubWococo as Para>::RuntimeEvent;

assert_expected_events!(
AssetHubWococo,
vec![
RuntimeEvent::XcmpQueue(cumulus_pallet_xcmp_queue::Event::Fail { .. }) => {},
]
);
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright Parity Technologies (UK) Ltd.
// This file is part of Cumulus.

// Cumulus is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Cumulus is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.

mod example;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "collectives-polkadot-it"
name = "collectives-polkadot-integration-tests"
version = "0.1.0"
authors = ["Parity Technologies <[email protected]>"]
edition = "2021"
Expand Down
10 changes: 9 additions & 1 deletion parachains/integration-tests/emulated/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pallet-balances = { default-features = false, git = "https://github.com/parityte
pallet-assets = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master" }
pallet-staking = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master" }
pallet-im-online = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master" }
beefy-primitives = { package = "sp-consensus-beefy", git = "https://github.com/paritytech/substrate", branch = "master" }

# Polkadot
polkadot-core-primitives = { default-features = false, git = "https://github.com/paritytech/polkadot", branch = "master" }
Expand All @@ -32,7 +33,9 @@ polkadot-runtime = { git = "https://github.com/paritytech/polkadot", branch = "m
polkadot-runtime-constants = { git = "https://github.com/paritytech/polkadot", branch = "master" }
kusama-runtime = { git = "https://github.com/paritytech/polkadot", branch = "master" }
kusama-runtime-constants = { git = "https://github.com/paritytech/polkadot", branch = "master" }
westend-runtime = { git = "https://github.com/paritytech/polkadot", branch = "master" }
rococo-runtime = { git = "https://github.com/paritytech/polkadot", branch = "master" }
rococo-runtime-constants = { git = "https://github.com/paritytech/polkadot", branch = "master" }
westend-runtime = { git = "https://github.com/paritytech/polkadot", branch = "master" }
westend-runtime-constants = { git = "https://github.com/paritytech/polkadot", branch = "master" }
xcm = { default-features = false, git = "https://github.com/paritytech/polkadot", branch = "master" }
xcm-executor = { default-features = false, git = "https://github.com/paritytech/polkadot", branch = "master" }
Expand All @@ -49,7 +52,12 @@ asset-hub-westend-runtime = { path = "../../../runtimes/assets/asset-hub-westend
collectives-polkadot-runtime = { path = "../../../runtimes/collectives/collectives-polkadot" }
bridge-hub-kusama-runtime = { path = "../../../runtimes/bridge-hubs/bridge-hub-kusama" }
bridge-hub-polkadot-runtime = { path = "../../../runtimes/bridge-hubs/bridge-hub-polkadot" }
bridge-hub-rococo-runtime = { path = "../../../runtimes/bridge-hubs/bridge-hub-rococo" }
xcm-emulator = { default-features = false, path = "../../../../xcm/xcm-emulator" }
bp-messages = { path = "../../../../bridges/primitives/messages"}
bp-runtime = { path = "../../../../bridges/primitives/runtime"}
pallet-bridge-messages = { path = "../../../../bridges/modules/messages" }
bridge-runtime-common = { path = "../../../../bridges/bin/runtime-common"}

[features]
runtime-benchmarks = [
Expand Down
Loading