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

Refactoring create asset and add CI tests to cover #1112

Closed
wants to merge 6 commits into from
Closed
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
9 changes: 8 additions & 1 deletion .github/workflows/parachain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions parachain/Cargo.lock

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

21 changes: 9 additions & 12 deletions parachain/pallets/inbound-queue/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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<CreateAssetCall, InboundQueuePalletInstance, AccountId, Balance>;
type PricingParameters = Parameters;
type ChannelLookup = MockChannelLookup;
#[cfg(feature = "runtime-benchmarks")]
Expand Down
72 changes: 33 additions & 39 deletions parachain/primitives/router/src/inbound/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -83,24 +83,27 @@ pub enum Destination {
},
}

pub struct MessageToXcm<
CreateAssetCall,
CreateAssetDeposit,
InboundQueuePalletInstance,
AccountId,
Balance,
> where
CreateAssetCall: Get<CallIndex>,
CreateAssetDeposit: Get<u128>,
/// 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,
}
Comment on lines +86 to +97
Copy link
Contributor Author

Choose a reason for hiding this comment

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

So we add a CallInfo structure for the create asset and make it runtime config(without any hard coded params anymore), meanwhile we add runtime tests in asset-hub to check the call_index and transact_weight_at_most all as expected.


pub struct MessageToXcm<CreateAssetCall, InboundQueuePalletInstance, AccountId, Balance>
where
CreateAssetCall: Get<CreateAssetCallInfo>,
InboundQueuePalletInstance: Get<u8>,
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.
Expand All @@ -118,19 +121,10 @@ pub trait ConvertMessage {
fn convert(message: VersionedMessage) -> Result<(Xcm<()>, Self::Balance), ConvertMessageError>;
}

pub type CallIndex = [u8; 2];

impl<CreateAssetCall, CreateAssetDeposit, InboundQueuePalletInstance, AccountId, Balance>
ConvertMessage
for MessageToXcm<
CreateAssetCall,
CreateAssetDeposit,
InboundQueuePalletInstance,
AccountId,
Balance,
> where
CreateAssetCall: Get<CallIndex>,
CreateAssetDeposit: Get<u128>,
impl<CreateAssetCall, InboundQueuePalletInstance, AccountId, Balance> ConvertMessage
for MessageToXcm<CreateAssetCall, InboundQueuePalletInstance, AccountId, Balance>
where
CreateAssetCall: Get<CreateAssetCallInfo>,
InboundQueuePalletInstance: Get<u8>,
Balance: BalanceT + From<u128>,
AccountId: Into<[u8; 32]>,
Expand All @@ -150,28 +144,28 @@ impl<CreateAssetCall, CreateAssetDeposit, InboundQueuePalletInstance, AccountId,
}
}

impl<CreateAssetCall, CreateAssetDeposit, InboundQueuePalletInstance, AccountId, Balance>
MessageToXcm<CreateAssetCall, CreateAssetDeposit, InboundQueuePalletInstance, AccountId, Balance>
impl<CreateAssetCall, InboundQueuePalletInstance, AccountId, Balance>
MessageToXcm<CreateAssetCall, InboundQueuePalletInstance, AccountId, Balance>
where
CreateAssetCall: Get<CallIndex>,
CreateAssetDeposit: Get<u128>,
CreateAssetCall: Get<CreateAssetCallInfo>,
InboundQueuePalletInstance: Get<u8>,
Balance: BalanceT + From<u128>,
AccountId: Into<[u8; 32]>,
{
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![
Expand All @@ -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(),
Expand Down
2 changes: 0 additions & 2 deletions parachain/primitives/router/src/inbound/tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use super::GlobalConsensusEthereumConvertsFor;
use crate::inbound::CallIndex;
use frame_support::parameter_types;
use hex_literal::hex;
use xcm::v3::prelude::*;
Expand All @@ -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;
Expand Down
Loading