Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve xcm integration test #13

Merged
merged 3 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 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 @@ -7,32 +7,41 @@ license = "Apache-2.0"
description = "Bridge Hub Rococo runtime integration tests with xcm-emulator"
publish = false

[lib]
doctest = false

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

# Substrate
frame-support = { path = "../../../../../../substrate/frame/support", default-features = false}
frame-support = { path = "../../../../../../substrate/frame/support", default-features = false }
pallet-assets = { path = "../../../../../../substrate/frame/assets", default-features = false }

# Polkadot
polkadot-core-primitives = { path = "../../../../../../polkadot/core-primitives", default-features = false}
polkadot-parachain-primitives = { path = "../../../../../../polkadot/parachain", default-features = false}
polkadot-core-primitives = { path = "../../../../../../polkadot/core-primitives", default-features = false }
polkadot-parachain-primitives = { path = "../../../../../../polkadot/parachain", default-features = false }
polkadot-runtime-parachains = { path = "../../../../../../polkadot/runtime/parachains" }
xcm = { package = "staging-xcm", path = "../../../../../../polkadot/xcm", default-features = false}
pallet-xcm = { path = "../../../../../../polkadot/xcm/pallet-xcm", default-features = false}
xcm-executor = { package = "staging-xcm-executor", path = "../../../../../../polkadot/xcm/xcm-executor", default-features = false}
xcm = { package = "staging-xcm", path = "../../../../../../polkadot/xcm", default-features = false }
pallet-xcm = { path = "../../../../../../polkadot/xcm/pallet-xcm", default-features = false }
xcm-executor = { package = "staging-xcm-executor", path = "../../../../../../polkadot/xcm/xcm-executor", default-features = false }

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

# Local
xcm-emulator = { path = "../../../../../xcm/xcm-emulator", default-features = false}
integration-tests-common = { path = "../../common", default-features = false}
xcm-emulator = { path = "../../../../../xcm/xcm-emulator", default-features = false }
integration-tests-common = { path = "../../common", default-features = false }

# Snowbridge
snowbridge-control = { path = "../../../../../../../parachain/pallets/control" }
snowbridge-core = { path = "../../../../../../../parachain/primitives/core", default-features = false }
snowbridge-router-primitives = { path = "../../../../../../../parachain/primitives/router", default-features = false }
snowbridge-control = { path = "../../../../../../../parachain/pallets/control", default-features = false }
snowbridge-inbound-queue = { path = "../../../../../../../parachain/pallets/inbound-queue", default-features = false }
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,26 @@
// limitations under the License.

use crate::*;
use hex_literal::hex;
use integration_tests_common::BridgeHubRococoPallet;
use snowbridge_control;
use snowbridge_router_primitives::inbound::{Command, MessageV1, VersionedMessage};

#[test]
fn create_agent() {
BridgeHubRococo::fund_accounts(vec![(
BridgeHubRococo::sovereign_account_id_of(MultiLocation {
parents: 1,
interior: X1(Parachain(1000)),
}),
5_000_000 * ROCOCO_ED,
)]);

let sudo_origin = <Rococo as Chain>::RuntimeOrigin::root();
let destination = Rococo::child_location_of(BridgeHubRococo::para_id()).into();

let remote_xcm = VersionedXcm::from(Xcm(vec![
UnpaidExecution { weight_limit: WeightLimit::Unlimited, check_origin: None },
UnpaidExecution { weight_limit: Unlimited, check_origin: None },
DescendOrigin(X1(Parachain(1000))),
Transact {
require_weight_at_most: 3000000000.into(),
Expand Down Expand Up @@ -71,30 +81,50 @@ fn create_agent() {

#[test]
fn create_channel() {
let source_location = MultiLocation { parents: 1, interior: X1(Parachain(1000)) };

BridgeHubRococo::fund_accounts(vec![(
BridgeHubRococo::sovereign_account_id_of(source_location),
5_000_000 * ROCOCO_ED,
)]);

let sudo_origin = <Rococo as Chain>::RuntimeOrigin::root();
let destination = Rococo::child_location_of(BridgeHubRococo::para_id()).into();
let destination: VersionedMultiLocation =
Rococo::child_location_of(BridgeHubRococo::para_id()).into();

let remote_xcm = VersionedXcm::from(Xcm(vec![
UnpaidExecution { weight_limit: WeightLimit::Unlimited, check_origin: None },
let create_agent_xcm = VersionedXcm::from(Xcm(vec![
UnpaidExecution { weight_limit: Unlimited, check_origin: None },
DescendOrigin(X1(Parachain(1000))),
Transact {
require_weight_at_most: 8000000000.into(),
require_weight_at_most: 3000000000.into(),
origin_kind: OriginKind::Xcm,
call: vec![51, 2].into(),
call: vec![51, 1].into(),
},
]));

//BridgeHubRococo::execute_with(|| { // TODO Create agent in storage
// <BridgeHubRococo as BridgeHubRococoPallet>::EthereumControl::create_agent(sudo_origin);
//});
let create_channel_xcm = VersionedXcm::from(Xcm(vec![
UnpaidExecution { weight_limit: Unlimited, check_origin: None },
DescendOrigin(X1(Parachain(1000))),
Transact {
require_weight_at_most: 3000000000.into(),
origin_kind: OriginKind::Xcm,
call: vec![51, 2].into(),
},
]));

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

assert_ok!(<Rococo as RococoPallet>::XcmPallet::send(
sudo_origin,
bx!(destination),
bx!(remote_xcm),
bx!(create_channel_xcm),
));

type RuntimeEvent = <Rococo as Chain>::RuntimeEvent;
Expand Down Expand Up @@ -124,3 +154,54 @@ fn create_channel() {
);
});
}

#[test]
fn register_token() {
BridgeHubRococo::fund_accounts(vec![(
BridgeHubRococo::sovereign_account_id_of(MultiLocation {
parents: 1,
interior: X1(Parachain(1000)),
}),
5_000_000 * ROCOCO_ED,
)]);

// Fund gateway sovereign in asset hub
AssetHubRococo::fund_accounts(vec![(
hex!("c9794dd8013efb2ad83f668845c62b373c16ad33971745731408058e4d0c6ff5").into(),
5_000_000_000_000 * ROCOCO_ED,
)]);

BridgeHubRococo::execute_with(|| {
type RuntimeEvent = <BridgeHubRococo as Chain>::RuntimeEvent;
type EthereumInboundQueue =
<BridgeHubRococo as BridgeHubRococoPallet>::EthereumInboundQueue;
let message = VersionedMessage::V1(MessageV1 {
chain_id: 15,
command: Command::RegisterToken {
gateway: hex!("EDa338E4dC46038493b885327842fD3E301CaB39").into(),
token: hex!("87d1f7fdfEe7f651FaBc8bFCB6E086C278b77A7d").into(),
},
});
let xcm = EthereumInboundQueue::do_convert(message).unwrap();
let _ = EthereumInboundQueue::send_xcm(xcm, 1000.into()).unwrap();

assert_expected_events!(
BridgeHubRococo,
vec![
RuntimeEvent::XcmpQueue(cumulus_pallet_xcmp_queue::Event::XcmpMessageSent { .. }) => {},
]
);
});

AssetHubRococo::execute_with(|| {
type RuntimeEvent = <AssetHubRococo as Chain>::RuntimeEvent;

assert_expected_events!(
AssetHubRococo,
vec![
RuntimeEvent::ForeignAssets(pallet_assets::Event::Created { .. }) => {},
RuntimeEvent::XcmpQueue(cumulus_pallet_xcmp_queue::Event::Success { .. }) => {},
]
);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ decl_test_parachains! {
PolkadotXcm: bridge_hub_rococo_runtime::PolkadotXcm,
Balances: bridge_hub_rococo_runtime::Balances,
EthereumControl: bridge_hub_rococo_runtime::EthereumControl,
EthereumInboundQueue: bridge_hub_rococo_runtime::EthereumInboundQueue,
}
},
// AssetHubRococo
Expand Down
Loading