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

runtime test for create asset in AH #99

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
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
@@ -0,0 +1,38 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2023 Snowfork <[email protected]>

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() {
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 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 {:?}",
max_weight,
actual
);
}
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
Loading