From cadd771ff1e3f6b07a5637c7a6e68434c52b4ab4 Mon Sep 17 00:00:00 2001 From: ron Date: Tue, 23 Jan 2024 20:50:32 +0800 Subject: [PATCH 1/6] Register token with inbound fixture --- .../bridges/bridge-hub-rococo/Cargo.toml | 2 +- .../bridge-hub-rococo/src/tests/snowbridge.rs | 24 +++++++++++++------ .../bridge-hubs/bridge-hub-rococo/Cargo.toml | 1 + .../bridge-hubs/bridge-hub-rococo/src/lib.rs | 7 ------ 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/Cargo.toml b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/Cargo.toml index a7d3bfe2fcbd..f16cb43ffc17 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/Cargo.toml @@ -49,5 +49,5 @@ asset-hub-rococo-runtime = { path = "../../../../../runtimes/assets/asset-hub-ro snowbridge-core = { path = "../../../../../../../../parachain/primitives/core", default-features = false } snowbridge-router-primitives = { path = "../../../../../../../../parachain/primitives/router", default-features = false } snowbridge-pallet-system = { path = "../../../../../../../../parachain/pallets/system", default-features = false } -snowbridge-pallet-inbound-queue = { path = "../../../../../../../../parachain/pallets/inbound-queue", default-features = false } snowbridge-pallet-outbound-queue = { path = "../../../../../../../../parachain/pallets/outbound-queue", default-features = false } +snowbridge-pallet-inbound-queue = { path = "../../../../../../../../parachain/pallets/inbound-queue", features = ["test-helpers"] } diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/snowbridge.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/snowbridge.rs index 944be9c399ff..86363b791015 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/snowbridge.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/snowbridge.rs @@ -13,12 +13,15 @@ // See the License for the specific language governing permissions and // limitations under the License. use crate::*; +use bridge_hub_rococo_runtime::EthereumBeaconClient; use codec::{Decode, Encode}; use emulated_integration_tests_common::xcm_emulator::ConvertLocation; use frame_support::pallet_prelude::TypeInfo; use hex_literal::hex; use parachains_common::rococo::snowbridge::EthereumNetwork; +use rococo_westend_system_emulated_network::BridgeHubRococoParaSender as BridgeHubRococoSender; use snowbridge_core::outbound::OperatingMode; +use snowbridge_pallet_inbound_queue::fixtures::make_create_message; use snowbridge_pallet_system; use snowbridge_router_primitives::inbound::{ Command, Destination, GlobalConsensusEthereumConvertsFor, MessageV1, VersionedMessage, @@ -191,17 +194,24 @@ fn register_weth_token_from_ethereum_to_asset_hub() { BridgeHubRococo::execute_with(|| { type RuntimeEvent = ::RuntimeEvent; + type RuntimeOrigin = ::RuntimeOrigin; type EthereumInboundQueue = ::EthereumInboundQueue; - let message = VersionedMessage::V1(MessageV1 { - chain_id: CHAIN_ID, - command: Command::RegisterToken { token: WETH.into(), fee: XCM_FEE }, - }); - let (xcm, fee) = EthereumInboundQueue::do_convert(message_id, message).unwrap(); - assert_ok!(EthereumInboundQueue::burn_fees(AssetHubRococo::para_id().into(), fee)); + let create_message = make_create_message(); - let _ = EthereumInboundQueue::send_xcm(xcm, AssetHubRococo::para_id().into()).unwrap(); + EthereumBeaconClient::store_execution_header( + create_message.message.proof.block_hash, + create_message.execution_header, + 0, + H256::default(), + ); + + EthereumInboundQueue::submit( + RuntimeOrigin::signed(BridgeHubRococoSender::get()), + create_message.message, + ) + .unwrap(); assert_expected_events!( BridgeHubRococo, diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml index 5eac8468bfc1..0e89fd99acc0 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml @@ -249,6 +249,7 @@ runtime-benchmarks = [ "parachains-common/runtime-benchmarks", "polkadot-parachain-primitives/runtime-benchmarks", "polkadot-runtime-common/runtime-benchmarks", + "snowbridge-beacon-primitives/runtime-benchmarks", "snowbridge-core/runtime-benchmarks", "snowbridge-pallet-ethereum-client/runtime-benchmarks", "snowbridge-pallet-inbound-queue/runtime-benchmarks", diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index 553a45aeb3fb..287436f05bc0 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -490,13 +490,6 @@ impl pallet_utility::Config for Runtime { } // Ethereum Bridge - -#[cfg(not(feature = "runtime-benchmarks"))] -parameter_types! { - pub storage EthereumGatewayAddress: H160 = H160::zero(); -} - -#[cfg(feature = "runtime-benchmarks")] parameter_types! { pub storage EthereumGatewayAddress: H160 = H160(hex_literal::hex!("EDa338E4dC46038493b885327842fD3E301CaB39")); } From e5baadadab289091c2176681ea7265354b90b66c Mon Sep 17 00:00:00 2001 From: ron Date: Wed, 24 Jan 2024 00:25:36 +0800 Subject: [PATCH 2/6] Import snowbridge-pallet-inbound-queue-fixtures --- Cargo.lock | 16 ++++++++++++++++ .../tests/bridges/bridge-hub-rococo/Cargo.toml | 3 ++- .../bridge-hub-rococo/src/tests/snowbridge.rs | 9 ++++----- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cf5e7f67ec88..a4ea8838ca1d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1988,6 +1988,7 @@ dependencies = [ "scale-info", "snowbridge-core", "snowbridge-pallet-inbound-queue", + "snowbridge-pallet-inbound-queue-fixtures", "snowbridge-pallet-outbound-queue", "snowbridge-pallet-system", "snowbridge-router-primitives", @@ -17745,6 +17746,7 @@ dependencies = [ "snowbridge-beacon-primitives", "snowbridge-core", "snowbridge-ethereum", + "snowbridge-pallet-inbound-queue-fixtures", "snowbridge-router-primitives", "sp-core", "sp-io", @@ -17755,6 +17757,20 @@ dependencies = [ "staging-xcm-executor", ] +[[package]] +name = "snowbridge-pallet-inbound-queue-fixtures" +version = "0.9.0" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "hex-literal", + "snowbridge-beacon-primitives", + "snowbridge-core", + "sp-core", + "sp-std 8.0.0", +] + [[package]] name = "snowbridge-pallet-outbound-queue" version = "0.9.0" diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/Cargo.toml b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/Cargo.toml index f16cb43ffc17..1972eb5091f7 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/Cargo.toml @@ -50,4 +50,5 @@ snowbridge-core = { path = "../../../../../../../../parachain/primitives/core", snowbridge-router-primitives = { path = "../../../../../../../../parachain/primitives/router", default-features = false } snowbridge-pallet-system = { path = "../../../../../../../../parachain/pallets/system", default-features = false } snowbridge-pallet-outbound-queue = { path = "../../../../../../../../parachain/pallets/outbound-queue", default-features = false } -snowbridge-pallet-inbound-queue = { path = "../../../../../../../../parachain/pallets/inbound-queue", features = ["test-helpers"] } +snowbridge-pallet-inbound-queue = { path = "../../../../../../../../parachain/pallets/inbound-queue", default-features = false } +snowbridge-pallet-inbound-queue-fixtures = { path = "../../../../../../../../parachain/pallets/inbound-queue/fixtures" } diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/snowbridge.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/snowbridge.rs index 86363b791015..a27de68c1e6d 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/snowbridge.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/snowbridge.rs @@ -21,7 +21,7 @@ use hex_literal::hex; use parachains_common::rococo::snowbridge::EthereumNetwork; use rococo_westend_system_emulated_network::BridgeHubRococoParaSender as BridgeHubRococoSender; use snowbridge_core::outbound::OperatingMode; -use snowbridge_pallet_inbound_queue::fixtures::make_create_message; +use snowbridge_pallet_inbound_queue_fixtures::make_register_asset_message; use snowbridge_pallet_system; use snowbridge_router_primitives::inbound::{ Command, Destination, GlobalConsensusEthereumConvertsFor, MessageV1, VersionedMessage, @@ -190,15 +190,13 @@ fn register_weth_token_from_ethereum_to_asset_hub() { // Fund AssetHub sovereign account so that it can pay execution fees. BridgeHubRococo::fund_para_sovereign(AssetHubRococo::para_id().into(), INITIAL_FUND); - let message_id: H256 = [1; 32].into(); - BridgeHubRococo::execute_with(|| { type RuntimeEvent = ::RuntimeEvent; type RuntimeOrigin = ::RuntimeOrigin; type EthereumInboundQueue = ::EthereumInboundQueue; - let create_message = make_create_message(); + let create_message = make_register_asset_message(); EthereumBeaconClient::store_execution_header( create_message.message.proof.block_hash, @@ -446,7 +444,8 @@ fn send_weth_asset_from_asset_hub_to_ethereum() { command: Command::RegisterToken { token: WETH.into(), fee: XCM_FEE }, }); // Converts the versioned message to XCM - let (xcm, _) = EthereumInboundQueue::do_convert(message_id_register_token, message).unwrap(); + let (xcm, _) = + EthereumInboundQueue::do_convert(message_id_register_token, message).unwrap(); let _ = EthereumInboundQueue::send_xcm(xcm, AssetHubRococo::para_id().into()).unwrap(); // Check that the register token message was sent using xcm From 8fc508eaf60f8fdb3d11c47445dd80236bb9a8f4 Mon Sep 17 00:00:00 2001 From: ron Date: Wed, 24 Jan 2024 08:39:05 +0800 Subject: [PATCH 3/6] Cleanup Cargo.toml --- .../parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml index 0e89fd99acc0..5eac8468bfc1 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml @@ -249,7 +249,6 @@ runtime-benchmarks = [ "parachains-common/runtime-benchmarks", "polkadot-parachain-primitives/runtime-benchmarks", "polkadot-runtime-common/runtime-benchmarks", - "snowbridge-beacon-primitives/runtime-benchmarks", "snowbridge-core/runtime-benchmarks", "snowbridge-pallet-ethereum-client/runtime-benchmarks", "snowbridge-pallet-inbound-queue/runtime-benchmarks", From 977cb9f6175d19987e0d545ec4c25b217b0ee12c Mon Sep 17 00:00:00 2001 From: ron Date: Wed, 24 Jan 2024 12:43:05 +0800 Subject: [PATCH 4/6] Update emulated test --- .../bridge-hub-rococo/src/tests/snowbridge.rs | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/snowbridge.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/snowbridge.rs index a27de68c1e6d..cc05f83e5489 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/snowbridge.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/snowbridge.rs @@ -21,7 +21,7 @@ use hex_literal::hex; use parachains_common::rococo::snowbridge::EthereumNetwork; use rococo_westend_system_emulated_network::BridgeHubRococoParaSender as BridgeHubRococoSender; use snowbridge_core::outbound::OperatingMode; -use snowbridge_pallet_inbound_queue_fixtures::make_register_asset_message; +use snowbridge_pallet_inbound_queue_fixtures::register_asset::make_register_asset_message; use snowbridge_pallet_system; use snowbridge_router_primitives::inbound::{ Command, Destination, GlobalConsensusEthereumConvertsFor, MessageV1, VersionedMessage, @@ -196,18 +196,18 @@ fn register_weth_token_from_ethereum_to_asset_hub() { type EthereumInboundQueue = ::EthereumInboundQueue; - let create_message = make_register_asset_message(); + let register_asset_message = make_register_asset_message(); EthereumBeaconClient::store_execution_header( - create_message.message.proof.block_hash, - create_message.execution_header, + register_asset_message.message.proof.block_hash, + register_asset_message.execution_header, 0, H256::default(), ); EthereumInboundQueue::submit( RuntimeOrigin::signed(BridgeHubRococoSender::get()), - create_message.message, + register_asset_message.message, ) .unwrap(); @@ -358,17 +358,24 @@ fn send_token_from_ethereum_to_asset_hub() { BridgeHubRococo::execute_with(|| { type RuntimeEvent = ::RuntimeEvent; + type RuntimeOrigin = ::RuntimeOrigin; type EthereumInboundQueue = ::EthereumInboundQueue; - // Construct RegisterToken message - let message = VersionedMessage::V1(MessageV1 { - chain_id: CHAIN_ID, - command: Command::RegisterToken { token: WETH.into(), fee: XCM_FEE }, - }); - // Convert the message to XCM - let (xcm, _) = EthereumInboundQueue::do_convert(message_id, message).unwrap(); - // Send the XCM - let _ = EthereumInboundQueue::send_xcm(xcm, AssetHubRococo::para_id().into()).unwrap(); + + let register_asset_message = make_register_asset_message(); + + EthereumBeaconClient::store_execution_header( + register_asset_message.message.proof.block_hash, + register_asset_message.execution_header, + 0, + H256::default(), + ); + + EthereumInboundQueue::submit( + RuntimeOrigin::signed(BridgeHubRococoSender::get()), + register_asset_message.message, + ) + .unwrap(); // Construct SendToken message let message = VersionedMessage::V1(MessageV1 { From d3b3e97f68bf6fec24f736242dffd5c7e227133b Mon Sep 17 00:00:00 2001 From: ron Date: Wed, 24 Jan 2024 14:27:43 +0800 Subject: [PATCH 5/6] Fix emulated test --- .../emulated/common/src/lib.rs | 2 +- .../bridge-hub-rococo/src/tests/snowbridge.rs | 33 ++++++++++--------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/common/src/lib.rs b/cumulus/parachains/integration-tests/emulated/common/src/lib.rs index ad69d5576aae..882a188e0f75 100644 --- a/cumulus/parachains/integration-tests/emulated/common/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/common/src/lib.rs @@ -100,7 +100,7 @@ pub mod accounts { pub const CHARLIE: &str = "Charlie"; pub const DAVE: &str = "Dave"; pub const EVE: &str = "Eve"; - pub const FERDIE: &str = "Ferdei"; + pub const FERDIE: &str = "Ferdie"; pub const ALICE_STASH: &str = "Alice//stash"; pub const BOB_STASH: &str = "Bob//stash"; pub const CHARLIE_STASH: &str = "Charlie//stash"; diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/snowbridge.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/snowbridge.rs index cc05f83e5489..7d1ad311b6b5 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/snowbridge.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/snowbridge.rs @@ -21,7 +21,9 @@ use hex_literal::hex; use parachains_common::rococo::snowbridge::EthereumNetwork; use rococo_westend_system_emulated_network::BridgeHubRococoParaSender as BridgeHubRococoSender; use snowbridge_core::outbound::OperatingMode; -use snowbridge_pallet_inbound_queue_fixtures::register_asset::make_register_asset_message; +use snowbridge_pallet_inbound_queue_fixtures::{ + register_asset::make_register_asset_message, send_token::make_send_token_message, +}; use snowbridge_pallet_system; use snowbridge_router_primitives::inbound::{ Command, Destination, GlobalConsensusEthereumConvertsFor, MessageV1, VersionedMessage, @@ -354,8 +356,6 @@ fn send_token_from_ethereum_to_asset_hub() { // Fund ethereum sovereign on AssetHub AssetHubRococo::fund_accounts(vec![(AssetHubRococoReceiver::get(), INITIAL_FUND)]); - let message_id: H256 = [1; 32].into(); - BridgeHubRococo::execute_with(|| { type RuntimeEvent = ::RuntimeEvent; type RuntimeOrigin = ::RuntimeOrigin; @@ -378,19 +378,20 @@ fn send_token_from_ethereum_to_asset_hub() { .unwrap(); // Construct SendToken message - let message = VersionedMessage::V1(MessageV1 { - chain_id: CHAIN_ID, - command: Command::SendToken { - token: WETH.into(), - destination: Destination::AccountId32 { id: AssetHubRococoReceiver::get().into() }, - amount: 1_000_000_000, - fee: XCM_FEE, - }, - }); - // Convert the message to XCM - let (xcm, _) = EthereumInboundQueue::do_convert(message_id, message).unwrap(); - // Send the XCM - let _ = EthereumInboundQueue::send_xcm(xcm, AssetHubRococo::para_id().into()).unwrap(); + let send_token_message = make_send_token_message(); + + EthereumBeaconClient::store_execution_header( + send_token_message.message.proof.block_hash, + send_token_message.execution_header, + 0, + H256::default(), + ); + + EthereumInboundQueue::submit( + RuntimeOrigin::signed(BridgeHubRococoSender::get()), + send_token_message.message, + ) + .unwrap(); // Check that the message was sent assert_expected_events!( From e4f4d59e87ff8b34a6288ba62716eb31a02eb2de Mon Sep 17 00:00:00 2001 From: ron Date: Wed, 24 Jan 2024 16:31:52 +0800 Subject: [PATCH 6/6] Rename to register_token --- .../tests/bridges/bridge-hub-rococo/src/tests/snowbridge.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/snowbridge.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/snowbridge.rs index 7d1ad311b6b5..27c4ee830064 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/snowbridge.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/snowbridge.rs @@ -22,7 +22,7 @@ use parachains_common::rococo::snowbridge::EthereumNetwork; use rococo_westend_system_emulated_network::BridgeHubRococoParaSender as BridgeHubRococoSender; use snowbridge_core::outbound::OperatingMode; use snowbridge_pallet_inbound_queue_fixtures::{ - register_asset::make_register_asset_message, send_token::make_send_token_message, + register_token::make_register_token_message, send_token::make_send_token_message, }; use snowbridge_pallet_system; use snowbridge_router_primitives::inbound::{ @@ -198,7 +198,7 @@ fn register_weth_token_from_ethereum_to_asset_hub() { type EthereumInboundQueue = ::EthereumInboundQueue; - let register_asset_message = make_register_asset_message(); + let register_asset_message = make_register_token_message(); EthereumBeaconClient::store_execution_header( register_asset_message.message.proof.block_hash, @@ -362,7 +362,7 @@ fn send_token_from_ethereum_to_asset_hub() { type EthereumInboundQueue = ::EthereumInboundQueue; - let register_asset_message = make_register_asset_message(); + let register_asset_message = make_register_token_message(); EthereumBeaconClient::store_execution_header( register_asset_message.message.proof.block_hash,