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;13use pallet_common::account::{EvmBackwardsAddressMapping, CrossAccountId};14use codec::{Encode, Decode};15use scale_info::TypeInfo;1617type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;18type Block = frame_system::mocking::MockBlock<Test>;192021frame_support::construct_runtime!(22 pub enum Test where23 Block = Block,24 NodeBlock = Block,25 UncheckedExtrinsic = UncheckedExtrinsic,26 {27 System: frame_system::{Pallet, Call, Config, Storage, Event<T>},28 TemplateModule: pallet_template::{Pallet, Call, Storage},29 Balances: pallet_balances::{Pallet, Call, Storage},30 Common: pallet_common::{Pallet, Storage, Event<T>},31 Fungible: pallet_fungible::{Pallet, Storage},32 Refungible: pallet_refungible::{Pallet, Storage},33 Nonfungible: pallet_nonfungible::{Pallet, Storage},34 }35);3637parameter_types! {38 pub const BlockHashCount: u64 = 250;39 pub const SS58Prefix: u8 = 42;40}4142impl system::Config for Test {43 type BaseCallFilter = Everything;44 type BlockWeights = ();45 type BlockLength = ();46 type DbWeight = ();47 type Origin = Origin;48 type Call = Call;49 type Index = u64;50 type BlockNumber = u64;51 type Hash = H256;52 type Hashing = BlakeTwo256;53 type AccountId = u64;54 type Lookup = IdentityLookup<Self::AccountId>;55 type Header = Header;56 type Event = ();57 type BlockHashCount = BlockHashCount;58 type Version = ();59 type PalletInfo = PalletInfo;60 type AccountData = pallet_balances::AccountData<u64>;61 type OnNewAccount = ();62 type OnKilledAccount = ();63 type SystemWeightInfo = ();64 type SS58Prefix = SS58Prefix;65 type OnSetCode = ();66}6768parameter_types! {69 pub const ExistentialDeposit: u64 = 1;70 pub const MaxLocks: u32 = 50;71}7273impl pallet_balances::Config for Test {74 type AccountStore = System;75 type Balance = u64;76 type DustRemoval = ();77 type Event = ();78 type ExistentialDeposit = ExistentialDeposit;79 type WeightInfo = ();80 type MaxLocks = MaxLocks;81 type MaxReserves = ();82 type ReserveIdentifier = [u8; 8];83}8485parameter_types! {86 pub const TransactionByteFee: u64 = 1;87 pub const OperationalFeeMultiplier: u8 = 5;88}8990impl pallet_transaction_payment::Config for Test {91 type OnChargeTransaction = CurrencyAdapter<pallet_balances::Pallet<Test>, ()>;92 type TransactionByteFee = TransactionByteFee;93 type WeightToFee = IdentityFee<u64>;94 type FeeMultiplierUpdate = ();95 type OperationalFeeMultiplier = OperationalFeeMultiplier;96}9798parameter_types! {99 pub const MinimumPeriod: u64 = 1;100}101impl pallet_timestamp::Config for Test {102 type Moment = u64;103 type OnTimestampSet = ();104 type MinimumPeriod = MinimumPeriod;105 type WeightInfo = ();106}107108parameter_types! {109 pub const CollectionCreationPrice: u32 = 0;110 pub TreasuryAccountId: u64 = 1234;111 pub EthereumChainId: u32 = 1111;112}113114pub struct TestEvmAddressMapping;115impl AddressMapping<u64> for TestEvmAddressMapping {116 fn into_account_id(_addr: sp_core::H160) -> u64 {117 unimplemented!()118 }119}120121pub struct TestEvmBackwardsAddressMapping;122impl EvmBackwardsAddressMapping<u64> for TestEvmBackwardsAddressMapping {123 fn from_account_id(_account_id: u64) -> sp_core::H160 {124 unimplemented!()125 }126}127128#[derive(Encode, Decode, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, TypeInfo)]129pub struct TestCrossAccountId(u64, sp_core::H160);130impl CrossAccountId<u64> for TestCrossAccountId {131 fn as_sub(&self) -> &u64 {132 &self.0133 }134 fn as_eth(&self) -> &sp_core::H160 {135 &self.1136 }137 fn from_sub(sub: u64) -> Self {138 let mut eth = [0; 20];139 eth[12..20].copy_from_slice(&sub.to_be_bytes());140 Self(sub, sp_core::H160(eth))141 }142 fn from_eth(eth: sp_core::H160) -> Self {143 let mut sub_raw = [0; 8];144 sub_raw.copy_from_slice(ð.0[0..8]);145 let sub = u64::from_be_bytes(sub_raw);146 Self(sub, eth)147 }148 fn conv_eq(&self, other: &Self) -> bool {149 self.as_sub() == other.as_sub()150 }151}152153impl Default for TestCrossAccountId {154 fn default() -> Self {155 Self::from_sub(0)156 }157}158159pub struct TestEtheremTransactionSender;160impl pallet_ethereum::EthereumTransactionSender for TestEtheremTransactionSender {161 fn submit_logs_transaction(162 _source: H160,163 _tx: pallet_ethereum::Transaction,164 _logs: Vec<pallet_ethereum::Log>,165 ) {166 }167}168169impl pallet_evm_coder_substrate::Config for Test {170 type EthereumTransactionSender = TestEtheremTransactionSender;171 type GasWeightMapping = ();172}173174impl pallet_common::Config for Test {175 type Event = ();176 type EvmBackwardsAddressMapping = TestEvmBackwardsAddressMapping;177 type EvmAddressMapping = TestEvmAddressMapping;178 type CrossAccountId = TestCrossAccountId;179180 type Currency = Balances;181 type CollectionCreationPrice = CollectionCreationPrice;182 type TreasuryAccountId = TreasuryAccountId;183}184185impl pallet_fungible::Config for Test {186 type WeightInfo = ();187}188impl pallet_refungible::Config for Test {189 type WeightInfo = ();190}191impl pallet_nonfungible::Config for Test {192 type WeightInfo = ();193}194195impl pallet_template::Config for Test {196 type Event = ();197 type WeightInfo = ();198}199200201pub fn new_test_ext() -> sp_io::TestExternalities {202 system::GenesisConfig::default()203 .build_storage::<Test>()204 .unwrap()205 .into()206}