1#![allow(clippy::from_over_into)]23use crate as pallet_template;4use sp_core::{H160, H256};5use frame_support::{parameter_types, traits::Everything, weights::IdentityFee};6use sp_runtime::{7 traits::{BlakeTwo256, IdentityLookup},8 testing::Header,9};10use pallet_transaction_payment::{CurrencyAdapter};11use frame_system as system;12use pallet_evm::{AddressMapping, runner::stack::MaybeMirroredLog};13use pallet_common::account::{EvmBackwardsAddressMapping, CrossAccountId};14use codec::{Encode, Decode, MaxEncodedLen};15use scale_info::TypeInfo;16use up_data_structs::ConstU32;1718type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;19type Block = frame_system::mocking::MockBlock<Test>;202122frame_support::construct_runtime!(23 pub enum Test where24 Block = Block,25 NodeBlock = Block,26 UncheckedExtrinsic = UncheckedExtrinsic,27 {28 System: frame_system::{Pallet, Call, Config, Storage, Event<T>},29 TemplateModule: pallet_template::{Pallet, Call, Storage},30 Balances: pallet_balances::{Pallet, Call, Storage},31 Common: pallet_common::{Pallet, Storage, Event<T>},32 Fungible: pallet_fungible::{Pallet, Storage},33 Refungible: pallet_refungible::{Pallet, Storage},34 Nonfungible: pallet_nonfungible::{Pallet, Storage},35 }36);3738parameter_types! {39 pub const BlockHashCount: u64 = 250;40 pub const SS58Prefix: u8 = 42;41}4243impl system::Config for Test {44 type BaseCallFilter = Everything;45 type BlockWeights = ();46 type BlockLength = ();47 type DbWeight = ();48 type Origin = Origin;49 type Call = Call;50 type Index = u64;51 type BlockNumber = u64;52 type Hash = H256;53 type Hashing = BlakeTwo256;54 type AccountId = u64;55 type Lookup = IdentityLookup<Self::AccountId>;56 type Header = Header;57 type Event = ();58 type BlockHashCount = BlockHashCount;59 type Version = ();60 type PalletInfo = PalletInfo;61 type AccountData = pallet_balances::AccountData<u64>;62 type OnNewAccount = ();63 type OnKilledAccount = ();64 type SystemWeightInfo = ();65 type SS58Prefix = SS58Prefix;66 type OnSetCode = ();67 type MaxConsumers = ConstU32<16>;68}6970parameter_types! {71 pub const ExistentialDeposit: u64 = 1;72 pub const MaxLocks: u32 = 50;73}7475impl pallet_balances::Config for Test {76 type AccountStore = System;77 type Balance = u64;78 type DustRemoval = ();79 type Event = ();80 type ExistentialDeposit = ExistentialDeposit;81 type WeightInfo = ();82 type MaxLocks = MaxLocks;83 type MaxReserves = ();84 type ReserveIdentifier = [u8; 8];85}8687parameter_types! {88 pub const TransactionByteFee: u64 = 1;89 pub const OperationalFeeMultiplier: u8 = 5;90}9192impl pallet_transaction_payment::Config for Test {93 type OnChargeTransaction = CurrencyAdapter<pallet_balances::Pallet<Test>, ()>;94 type TransactionByteFee = TransactionByteFee;95 type WeightToFee = IdentityFee<u64>;96 type FeeMultiplierUpdate = ();97 type OperationalFeeMultiplier = OperationalFeeMultiplier;98}99100parameter_types! {101 pub const MinimumPeriod: u64 = 1;102}103impl pallet_timestamp::Config for Test {104 type Moment = u64;105 type OnTimestampSet = ();106 type MinimumPeriod = MinimumPeriod;107 type WeightInfo = ();108}109110parameter_types! {111 pub const CollectionCreationPrice: u32 = 100;112 pub TreasuryAccountId: u64 = 1234;113 pub EthereumChainId: u32 = 1111;114}115116pub struct TestEvmAddressMapping;117impl AddressMapping<u64> for TestEvmAddressMapping {118 fn into_account_id(_addr: sp_core::H160) -> u64 {119 unimplemented!()120 }121}122123pub struct TestEvmBackwardsAddressMapping;124impl EvmBackwardsAddressMapping<u64> for TestEvmBackwardsAddressMapping {125 fn from_account_id(_account_id: u64) -> sp_core::H160 {126 unimplemented!()127 }128}129130#[derive(Encode, Decode, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, TypeInfo, MaxEncodedLen)]131pub struct TestCrossAccountId(u64, sp_core::H160);132impl CrossAccountId<u64> for TestCrossAccountId {133 fn as_sub(&self) -> &u64 {134 &self.0135 }136 fn as_eth(&self) -> &sp_core::H160 {137 &self.1138 }139 fn from_sub(sub: u64) -> Self {140 let mut eth = [0; 20];141 eth[12..20].copy_from_slice(&sub.to_be_bytes());142 Self(sub, sp_core::H160(eth))143 }144 fn from_eth(eth: sp_core::H160) -> Self {145 let mut sub_raw = [0; 8];146 sub_raw.copy_from_slice(ð.0[0..8]);147 let sub = u64::from_be_bytes(sub_raw);148 Self(sub, eth)149 }150 fn conv_eq(&self, other: &Self) -> bool {151 self.as_sub() == other.as_sub()152 }153}154155impl Default for TestCrossAccountId {156 fn default() -> Self {157 Self::from_sub(0)158 }159}160161pub struct TestEtheremTransactionSender;162impl pallet_ethereum::EthereumTransactionSender for TestEtheremTransactionSender {163 fn submit_logs_transaction(164 _source: H160,165 _tx: pallet_ethereum::Transaction,166 _logs: Vec<MaybeMirroredLog>,167 ) {168 }169}170171impl pallet_evm_coder_substrate::Config for Test {172 type EthereumTransactionSender = TestEtheremTransactionSender;173 type GasWeightMapping = ();174}175176impl pallet_common::Config for Test {177 type Event = ();178 type EvmBackwardsAddressMapping = TestEvmBackwardsAddressMapping;179 type EvmAddressMapping = TestEvmAddressMapping;180 type CrossAccountId = TestCrossAccountId;181182 type Currency = Balances;183 type CollectionCreationPrice = CollectionCreationPrice;184 type TreasuryAccountId = TreasuryAccountId;185}186187impl pallet_fungible::Config for Test {188 type WeightInfo = ();189}190impl pallet_refungible::Config for Test {191 type WeightInfo = ();192}193impl pallet_nonfungible::Config for Test {194 type WeightInfo = ();195}196197impl pallet_template::Config for Test {198 type Event = ();199 type WeightInfo = ();200}201202203pub fn new_test_ext() -> sp_io::TestExternalities {204 system::GenesisConfig::default()205 .build_storage::<Test>()206 .unwrap()207 .into()208}