diff --git a/.github/workflows/parachain.yml b/.github/workflows/parachain.yml index ca1ff77cda..a13cbdcd95 100644 --- a/.github/workflows/parachain.yml +++ b/.github/workflows/parachain.yml @@ -233,13 +233,20 @@ jobs: repo-token: ${{ secrets.GITHUB_TOKEN }} - name: setup rust toolchain run: rustup show - - name: snowbridge runtime tests + - name: snowbridge runtime tests in bridge-hub working-directory: polkadot-sdk run: > RUST_LOG=xcm=trace cargo test --package bridge-hub-rococo-runtime --test snowbridge -- --nocapture + - name: snowbridge runtime tests in asset-hub + working-directory: polkadot-sdk + run: > + RUST_LOG=xcm=trace cargo test + --package asset-hub-rococo-runtime + --test snowbridge + -- --nocapture integration-tests: needs: check diff --git a/parachain/Cargo.lock b/parachain/Cargo.lock index 70f685f423..30175f54a9 100644 --- a/parachain/Cargo.lock +++ b/parachain/Cargo.lock @@ -6190,6 +6190,7 @@ dependencies = [ "rococo-runtime-constants", "scale-info", "smallvec", + "snowbridge-router-primitives", "sp-consensus-aura", "sp-core", "sp-io", diff --git a/parachain/pallets/inbound-queue/src/mock.rs b/parachain/pallets/inbound-queue/src/mock.rs index 5b73d8de86..8bda666fc7 100644 --- a/parachain/pallets/inbound-queue/src/mock.rs +++ b/parachain/pallets/inbound-queue/src/mock.rs @@ -14,7 +14,7 @@ use snowbridge_core::{ inbound::{Log, Proof, VerificationError}, meth, Channel, ChannelId, PricingParameters, Rewards, StaticLookup, }; -use snowbridge_router_primitives::inbound::MessageToXcm; +use snowbridge_router_primitives::inbound::{CreateAssetCallInfo, MessageToXcm}; use sp_core::{H160, H256}; use sp_runtime::{ traits::{BlakeTwo256, IdentifyAccount, IdentityLookup, Verify}, @@ -138,10 +138,12 @@ const GATEWAY_ADDRESS: [u8; 20] = hex!["eda338e4dc46038493b885327842fd3e301cab39 parameter_types! { pub const EthereumNetwork: xcm::v3::NetworkId = xcm::v3::NetworkId::Ethereum { chain_id: 11155111 }; pub const GatewayAddress: H160 = H160(GATEWAY_ADDRESS); - pub const CreateAssetCall: [u8;2] = [53, 0]; - pub const CreateAssetExecutionFee: u128 = 2_000_000_000; - pub const CreateAssetDeposit: u128 = 100_000_000_000; - pub const SendTokenExecutionFee: u128 = 1_000_000_000; + pub const CreateAssetCall: CreateAssetCallInfo = CreateAssetCallInfo { + call_index: [53,0], + asset_deposit: 100_000_000_000, + min_balance: 1, + transact_weight_at_most:Weight::from_parts(400_000_000, 8_000) + }; pub const InitialFund: u128 = 1_000_000_000_000; pub const InboundQueuePalletInstance: u8 = 80; } @@ -256,13 +258,8 @@ impl inbound_queue::Config for Test { type XcmSender = MockXcmSender; type WeightInfo = (); type GatewayAddress = GatewayAddress; - type MessageConverter = MessageToXcm< - CreateAssetCall, - CreateAssetDeposit, - InboundQueuePalletInstance, - AccountId, - Balance, - >; + type MessageConverter = + MessageToXcm; type PricingParameters = Parameters; type ChannelLookup = MockChannelLookup; #[cfg(feature = "runtime-benchmarks")] diff --git a/parachain/primitives/router/src/inbound/mod.rs b/parachain/primitives/router/src/inbound/mod.rs index a07e0eae5d..0552637c52 100644 --- a/parachain/primitives/router/src/inbound/mod.rs +++ b/parachain/primitives/router/src/inbound/mod.rs @@ -16,7 +16,7 @@ use sp_std::prelude::*; use xcm::prelude::{Junction::AccountKey20, *}; use xcm_executor::traits::ConvertLocation; -const MINIMUM_DEPOSIT: u128 = 1; +pub type CallIndex = [u8; 2]; /// Messages from Ethereum are versioned. This is because in future, /// we may want to evolve the protocol so that the ethereum side sends XCM messages directly. @@ -83,24 +83,27 @@ pub enum Destination { }, } -pub struct MessageToXcm< - CreateAssetCall, - CreateAssetDeposit, - InboundQueuePalletInstance, - AccountId, - Balance, -> where - CreateAssetCall: Get, - CreateAssetDeposit: Get, +/// CallInfo required to create the foreign asset +#[derive(Clone, Encode, Decode, RuntimeDebug)] +pub struct CreateAssetCallInfo { + /// Index of the create call + pub call_index: CallIndex, + /// Deposit required to create the asset + pub asset_deposit: u128, + /// Minimal balance of the asset + pub min_balance: u128, + /// Weight required for the xcm transact + pub transact_weight_at_most: Weight, +} + +pub struct MessageToXcm +where + CreateAssetCall: Get, + InboundQueuePalletInstance: Get, + AccountId: Into<[u8; 32]>, Balance: BalanceT, { - _phantom: PhantomData<( - CreateAssetCall, - CreateAssetDeposit, - InboundQueuePalletInstance, - AccountId, - Balance, - )>, + _phantom: PhantomData<(CreateAssetCall, InboundQueuePalletInstance, AccountId, Balance)>, } /// Reason why a message conversion failed. @@ -118,19 +121,10 @@ pub trait ConvertMessage { fn convert(message: VersionedMessage) -> Result<(Xcm<()>, Self::Balance), ConvertMessageError>; } -pub type CallIndex = [u8; 2]; - -impl - ConvertMessage - for MessageToXcm< - CreateAssetCall, - CreateAssetDeposit, - InboundQueuePalletInstance, - AccountId, - Balance, - > where - CreateAssetCall: Get, - CreateAssetDeposit: Get, +impl ConvertMessage + for MessageToXcm +where + CreateAssetCall: Get, InboundQueuePalletInstance: Get, Balance: BalanceT + From, AccountId: Into<[u8; 32]>, @@ -150,11 +144,10 @@ impl - MessageToXcm +impl + MessageToXcm where - CreateAssetCall: Get, - CreateAssetDeposit: Get, + CreateAssetCall: Get, InboundQueuePalletInstance: Get, Balance: BalanceT + From, AccountId: Into<[u8; 32]>, @@ -162,16 +155,17 @@ where fn convert_register_token(chain_id: u64, token: H160, fee: u128) -> (Xcm<()>, Balance) { let network = Ethereum { chain_id }; let xcm_fee: MultiAsset = (MultiLocation::parent(), fee).into(); - let deposit: MultiAsset = (MultiLocation::parent(), CreateAssetDeposit::get()).into(); + let call_info = CreateAssetCall::get(); + let deposit: MultiAsset = (MultiLocation::parent(), call_info.asset_deposit).into(); - let total_amount = fee + CreateAssetDeposit::get(); + let total_amount = fee + call_info.asset_deposit; let total: MultiAsset = (MultiLocation::parent(), total_amount).into(); let bridge_location: MultiLocation = (Parent, Parent, GlobalConsensus(network)).into(); let owner = GlobalConsensusEthereumConvertsFor::<[u8; 32]>::from_chain_id(&chain_id); let asset_id = Self::convert_token_address(network, token); - let create_call_index: [u8; 2] = CreateAssetCall::get(); + let create_call_index = call_info.call_index; let inbound_queue_pallet_index = InboundQueuePalletInstance::get(); let xcm: Xcm<()> = vec![ @@ -188,12 +182,12 @@ where // Call create_asset on foreign assets pallet. Transact { origin_kind: OriginKind::Xcm, - require_weight_at_most: Weight::from_parts(400_000_000, 8_000), + require_weight_at_most: call_info.transact_weight_at_most, call: ( create_call_index, asset_id, MultiAddress::<[u8; 32], ()>::Id(owner), - MINIMUM_DEPOSIT, + call_info.min_balance, ) .encode() .into(), diff --git a/parachain/primitives/router/src/inbound/tests.rs b/parachain/primitives/router/src/inbound/tests.rs index 8c96c13cf2..9f793af5c5 100644 --- a/parachain/primitives/router/src/inbound/tests.rs +++ b/parachain/primitives/router/src/inbound/tests.rs @@ -1,5 +1,4 @@ use super::GlobalConsensusEthereumConvertsFor; -use crate::inbound::CallIndex; use frame_support::parameter_types; use hex_literal::hex; use xcm::v3::prelude::*; @@ -10,7 +9,6 @@ const NETWORK: NetworkId = Ethereum { chain_id: 11155111 }; parameter_types! { pub EthereumNetwork: NetworkId = NETWORK; - pub const CreateAssetCall: CallIndex = [1, 1]; pub const CreateAssetExecutionFee: u128 = 123; pub const CreateAssetDeposit: u128 = 891; pub const SendTokenExecutionFee: u128 = 592; diff --git a/polkadot-sdk b/polkadot-sdk index 5c804ff125..238ac8f2ea 160000 --- a/polkadot-sdk +++ b/polkadot-sdk @@ -1 +1 @@ -Subproject commit 5c804ff125b2a7b9765c4c035560157c985b7a4a +Subproject commit 238ac8f2eab94db17f1b1d6ad3e1c339da6ad327