Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Commit

Permalink
Refactor CreateAssetCall as structure & Move to common
Browse files Browse the repository at this point in the history
  • Loading branch information
yrong committed Jan 17, 2024
1 parent d8787fb commit 7a58ab4
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 23 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

5 changes: 5 additions & 0 deletions cumulus/parachains/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ cumulus-primitives-core = { path = "../../primitives/core", default-features = f
cumulus-primitives-utility = { path = "../../primitives/utility", default-features = false }
parachain-info = { package = "staging-parachain-info", path = "../pallets/parachain-info", default-features = false }

# Snowbridge
snowbridge-router-primitives = { path = "../../../../parachain/primitives/router", default-features = false }

[dev-dependencies]
pallet-authorship = { path = "../../../substrate/frame/authorship", default-features = false }
sp-io = { path = "../../../substrate/primitives/io", default-features = false }
Expand Down Expand Up @@ -75,6 +78,7 @@ std = [
"polkadot-primitives/std",
"rococo-runtime-constants/std",
"scale-info/std",
"snowbridge-router-primitives/std",
"sp-consensus-aura/std",
"sp-core/std",
"sp-io/std",
Expand All @@ -96,6 +100,7 @@ runtime-benchmarks = [
"pallet-collator-selection/runtime-benchmarks",
"pallet-message-queue/runtime-benchmarks",
"polkadot-primitives/runtime-benchmarks",
"snowbridge-router-primitives/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
]
10 changes: 9 additions & 1 deletion cumulus/parachains/common/src/rococo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ pub mod consensus {
}

pub mod snowbridge {
use frame_support::parameter_types;
use crate::rococo::currency::{EXISTENTIAL_DEPOSIT, UNITS};
use frame_support::{parameter_types, weights::Weight};
use snowbridge_router_primitives::inbound::CreateAssetCallInfo;
use xcm::opaque::lts::NetworkId;

/// The pallet index of the Ethereum inbound queue pallet in the bridge hub runtime.
Expand All @@ -128,5 +130,11 @@ pub mod snowbridge {
parameter_types! {
/// Network and location for the Ethereum chain.
pub EthereumNetwork: NetworkId = NetworkId::Ethereum { chain_id: 11155111 };
pub const CreateAssetCall: CreateAssetCallInfo = CreateAssetCallInfo {
call_index: [53,0],
asset_deposit: (UNITS / 10) + EXISTENTIAL_DEPOSIT,
min_balance: 1,
transact_weight_at_most: Weight::from_parts(400_000_000, 8_000)
};
}
}
Original file line number Diff line number Diff line change
@@ -1,37 +1,34 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2023 Snowfork <[email protected]>

pub use asset_hub_rococo_runtime::{Runtime, RuntimeCall};
use asset_hub_rococo_runtime::Runtime;
pub use asset_hub_rococo_runtime::RuntimeCall;
use codec::Encode;
use frame_support::instances::Instance2;
use parachains_common::rococo::snowbridge::CreateAssetCall;
use snowbridge_router_primitives::inbound::CreateAssetCallInfo;
use sp_runtime::MultiAddress;
use xcm::latest::prelude::*;

#[test]
fn test_foreign_create_asset_call_compatibility() {
// assert_eq!(
// RuntimeCall::ForeignAssets(pallet_assets::Call::create {
// id: MultiLocation::default(),
// admin: MultiAddress::Id([0; 32].into()),
// min_balance: 1,
// })
// .encode(),
// snowbridge_router_primitives::inbound::Call::ForeignAssets(
// snowbridge_router_primitives::inbound::ForeignAssetsCall::create {
// id: MultiLocation::default(),
// admin: MultiAddress::Id([0; 32].into()),
// min_balance: 1,
// }
// )
// .encode()
// );
let call = &RuntimeCall::ForeignAssets(pallet_assets::Call::create {
id: MultiLocation::default(),
admin: MultiAddress::Id([0; 32].into()),
min_balance: 1,
})
.encode();
let call_index = &call[..2];
let snowbridge_call: CreateAssetCallInfo = CreateAssetCall::get();
assert_eq!(call_index, snowbridge_call.call_index);
}

#[test]
fn check_foreign_create_asset_call_with_sane_weight() {
use pallet_assets::WeightInfo;
let actual = <Runtime as pallet_assets::Config<Instance2>>::WeightInfo::create();
let max_weight = snowbridge_router_primitives::inbound::FOREIGN_CREATE_ASSET_WEIGHT_AT_MOST;
let snowbridge_call: CreateAssetCallInfo = CreateAssetCall::get();
let max_weight = snowbridge_call.transact_weight_at_most;
assert!(
actual.all_lte(max_weight),
"max_weight: {:?} should be adjusted to actual {:?}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -500,8 +500,6 @@ parameter_types! {
}

parameter_types! {
pub const CreateAssetCall: [u8;2] = [53, 0];
pub const CreateAssetDeposit: u128 = (UNITS / 10) + EXISTENTIAL_DEPOSIT;
pub const InboundQueuePalletInstance: u8 = parachains_common::rococo::snowbridge::INBOUND_QUEUE_PALLET_INDEX;
pub Parameters: PricingParameters<u128> = PricingParameters {
exchange_rate: FixedU128::from_rational(1, 400),
Expand Down Expand Up @@ -561,8 +559,7 @@ impl snowbridge_pallet_inbound_queue::Config for Runtime {
#[cfg(feature = "runtime-benchmarks")]
type Helper = Runtime;
type MessageConverter = MessageToXcm<
CreateAssetCall,
CreateAssetDeposit,
parachains_common::rococo::snowbridge::CreateAssetCall,
InboundQueuePalletInstance,
AccountId,
Balance,
Expand Down

0 comments on commit 7a58ab4

Please sign in to comment.