|
| 1 | +// Copyright (c) 2025 Polytope Labs. |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +// you may not use this file except in compliance with the License. |
| 6 | +// You may obtain a copy of the License at |
| 7 | +// |
| 8 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +// |
| 10 | +// Unless required by applicable law or agreed to in writing, software |
| 11 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +// See the License for the specific language governing permissions and |
| 14 | +// limitations under the License. |
| 15 | +#![allow(missing_docs, dead_code)] |
| 16 | + |
| 17 | +extern crate alloc; |
| 18 | +use polkadot_sdk::{frame_support::traits::WithdrawReasons, sp_runtime::traits::ConvertInto, *}; |
| 19 | + |
| 20 | +use cumulus_pallet_parachain_system::ParachainSetCode; |
| 21 | +use frame_support::{ |
| 22 | + derive_impl, parameter_types, |
| 23 | + traits::{ConstU32, ConstU64, Get}, |
| 24 | + PalletId, |
| 25 | +}; |
| 26 | +use frame_system::{EnsureRoot, EnsureSigned, EventRecord}; |
| 27 | +use polkadot_sdk::{ |
| 28 | + pallet_session::{disabling::UpToLimitDisablingStrategy, SessionHandler}, |
| 29 | + sp_runtime::{app_crypto::AppCrypto, traits::OpaqueKeys}, |
| 30 | + xcm_simulator::{GeneralIndex, Junctions::X3, Location, PalletInstance, Parachain}, |
| 31 | +}; |
| 32 | +use sp_consensus_aura::sr25519::AuthorityId as AuraId; |
| 33 | +use sp_core::{ |
| 34 | + offchain::{testing::TestOffchainExt, OffchainDbExt, OffchainWorkerExt}, |
| 35 | + H160, H256, U256, |
| 36 | +}; |
| 37 | +use sp_runtime::{ |
| 38 | + traits::{IdentityLookup, Keccak256}, |
| 39 | + AccountId32, BuildStorage, |
| 40 | +}; |
| 41 | + |
| 42 | +use crate::asset_hub_runtime::sp_runtime::DispatchError; |
| 43 | +use pallet_xcm_gateway::xcm_utilities::ASSET_HUB_PARA_ID; |
| 44 | +use xcm_simulator::mock_message_queue; |
| 45 | +pub const ALICE: AccountId32 = AccountId32::new([1; 32]); |
| 46 | +pub const BOB: AccountId32 = AccountId32::new([2; 32]); |
| 47 | +pub const CHARLIE: AccountId32 = AccountId32::new([3; 32]); |
| 48 | +pub const DAVE: AccountId32 = AccountId32::new([4; 32]); |
| 49 | + |
| 50 | +pub const INITIAL_BALANCE: u128 = 1_000_000_000_000_000_000; |
| 51 | + |
| 52 | +type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<AssetHubTest>; |
| 53 | +type Block = frame_system::mocking::MockBlock<AssetHubTest>; |
| 54 | + |
| 55 | +frame_support::construct_runtime!( |
| 56 | + pub enum AssetHubTest { |
| 57 | + System: frame_system, |
| 58 | + ParachainSystem: cumulus_pallet_parachain_system, |
| 59 | + ParachainInfo: staging_parachain_info, |
| 60 | + Balances: pallet_balances, |
| 61 | + XcmpQueue: cumulus_pallet_xcmp_queue, |
| 62 | + MessageQueue: pallet_message_queue, |
| 63 | + PalletXcm: pallet_xcm, |
| 64 | + Assets: pallet_assets, |
| 65 | + MsgQueue: mock_message_queue |
| 66 | + } |
| 67 | +); |
| 68 | + |
| 69 | +/// Verify the the last event emitted |
| 70 | +pub fn assert_last_event<T: frame_system::Config>(generic_event: T::RuntimeEvent) { |
| 71 | + assert_eq!(last_event::<T>(), generic_event); |
| 72 | +} |
| 73 | + |
| 74 | +/// Verify the the last event emitted |
| 75 | +pub fn last_event<T: frame_system::Config>() -> T::RuntimeEvent { |
| 76 | + let events = frame_system::Pallet::<T>::events(); |
| 77 | + let EventRecord { event, .. } = &events[events.len() - 1]; |
| 78 | + event.clone() |
| 79 | +} |
| 80 | + |
| 81 | +/// Balance of an account. |
| 82 | +pub type Balance = u128; |
| 83 | +// Unit = the base number of indivisible units for balances |
| 84 | +pub const UNIT: Balance = 1_000_000_000_000; |
| 85 | +pub const MILLIUNIT: Balance = 1_000_000_000; |
| 86 | +pub const MICROUNIT: Balance = 1_000_000; |
| 87 | + |
| 88 | +/// The existential deposit. Set to 1/10 of the Connected Relay Chain. |
| 89 | +pub const EXISTENTIAL_DEPOSIT: Balance = MILLIUNIT; |
| 90 | + |
| 91 | +parameter_types! { |
| 92 | + pub const ExistentialDeposit: Balance = EXISTENTIAL_DEPOSIT; |
| 93 | +} |
| 94 | + |
| 95 | +impl pallet_balances::Config for AssetHubTest { |
| 96 | + /// The ubiquitous event type. |
| 97 | + type RuntimeEvent = RuntimeEvent; |
| 98 | + type RuntimeHoldReason = RuntimeHoldReason; |
| 99 | + type RuntimeFreezeReason = RuntimeFreezeReason; |
| 100 | + type WeightInfo = pallet_balances::weights::SubstrateWeight<AssetHubTest>; |
| 101 | + /// The type for recording an account's balance. |
| 102 | + type Balance = Balance; |
| 103 | + type DustRemoval = (); |
| 104 | + type ExistentialDeposit = ExistentialDeposit; |
| 105 | + type AccountStore = System; |
| 106 | + type ReserveIdentifier = [u8; 8]; |
| 107 | + type FreezeIdentifier = (); |
| 108 | + type MaxLocks = ConstU32<50>; |
| 109 | + type MaxReserves = ConstU32<50>; |
| 110 | + type MaxFreezes = (); |
| 111 | + type DoneSlashHandler = (); |
| 112 | +} |
| 113 | + |
| 114 | +#[derive_impl(frame_system::config_preludes::ParaChainDefaultConfig as frame_system::DefaultConfig)] |
| 115 | +impl frame_system::Config for AssetHubTest { |
| 116 | + type BaseCallFilter = frame_support::traits::Everything; |
| 117 | + type RuntimeOrigin = RuntimeOrigin; |
| 118 | + type RuntimeCall = RuntimeCall; |
| 119 | + type Hash = H256; |
| 120 | + type Hashing = Keccak256; |
| 121 | + type AccountId = AccountId32; |
| 122 | + type Lookup = IdentityLookup<Self::AccountId>; |
| 123 | + type RuntimeEvent = RuntimeEvent; |
| 124 | + type BlockHashCount = ConstU64<250>; |
| 125 | + type DbWeight = (); |
| 126 | + type BlockWeights = (); |
| 127 | + type RuntimeTask = (); |
| 128 | + type BlockLength = (); |
| 129 | + type Version = (); |
| 130 | + type Nonce = u64; |
| 131 | + type Block = Block; |
| 132 | + type PalletInfo = PalletInfo; |
| 133 | + type AccountData = pallet_balances::AccountData<Balance>; |
| 134 | + type OnNewAccount = (); |
| 135 | + type OnKilledAccount = (); |
| 136 | + type SystemWeightInfo = (); |
| 137 | + type SS58Prefix = (); |
| 138 | + type OnSetCode = ParachainSetCode<AssetHubTest>; |
| 139 | + type MaxConsumers = ConstU32<16>; |
| 140 | +} |
| 141 | + |
| 142 | +parameter_types! { |
| 143 | + pub const Decimals: u8 = 10; |
| 144 | +} |
| 145 | + |
| 146 | +pub struct NativeAssetId; |
| 147 | + |
| 148 | +impl Get<H256> for NativeAssetId { |
| 149 | + fn get() -> H256 { |
| 150 | + sp_io::hashing::keccak_256(b"BRIDGE").into() |
| 151 | + } |
| 152 | +} |
| 153 | + |
| 154 | +sp_runtime::impl_opaque_keys! { |
| 155 | + pub struct SessionKeys { |
| 156 | + pub aura: AuraId, |
| 157 | + } |
| 158 | +} |
| 159 | + |
| 160 | +pub fn register_offchain_ext(ext: &mut sp_io::TestExternalities) { |
| 161 | + let (offchain, _offchain_state) = TestOffchainExt::with_offchain_db(ext.offchain_db()); |
| 162 | + ext.register_extension(OffchainDbExt::new(offchain.clone())); |
| 163 | + ext.register_extension(OffchainWorkerExt::new(offchain)); |
| 164 | +} |
0 commit comments