1#![allow(clippy::from_over_into)]23use crate as pallet_template;4use sp_core::H256;5use frame_support::{parameter_types, weights::IdentityFee};6use sp_runtime::{7 traits::{BlakeTwo256, IdentityLookup},8 testing::Header,9 Perbill,10};11use pallet_transaction_payment::{CurrencyAdapter};12use frame_system as system;13use pallet_evm::AddressMapping;14use crate::{EvmBackwardsAddressMapping, CrossAccountId};15use codec::{Encode, Decode};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 }31);3233parameter_types! {34 pub const BlockHashCount: u64 = 250;35 pub const SS58Prefix: u8 = 42;36}3738impl system::Config for Test {39 type BaseCallFilter = ();40 type BlockWeights = ();41 type BlockLength = ();42 type DbWeight = ();43 type Origin = Origin;44 type Call = Call;45 type Index = u64;46 type BlockNumber = u64;47 type Hash = H256;48 type Hashing = BlakeTwo256;49 type AccountId = u64;50 type Lookup = IdentityLookup<Self::AccountId>;51 type Header = Header;52 type Event = ();53 type BlockHashCount = BlockHashCount;54 type Version = ();55 type PalletInfo = PalletInfo;56 type AccountData = pallet_balances::AccountData<u64>;57 type OnNewAccount = ();58 type OnKilledAccount = ();59 type SystemWeightInfo = ();60 type SS58Prefix = SS58Prefix;61 type OnSetCode = ();62}6364parameter_types! {65 pub const ExistentialDeposit: u64 = 1;66 pub const MaxLocks: u32 = 50;67}6869impl pallet_balances::Config for Test {70 type AccountStore = System;71 type Balance = u64;72 type DustRemoval = ();73 type Event = ();74 type ExistentialDeposit = ExistentialDeposit;75 type WeightInfo = ();76 type MaxLocks = MaxLocks;77 type MaxReserves = ();78 type ReserveIdentifier = [u8; 8];79}8081parameter_types! {82 pub const TransactionByteFee: u64 = 1;83}8485impl pallet_transaction_payment::Config for Test {86 type OnChargeTransaction = CurrencyAdapter<pallet_balances::Pallet<Test>, ()>;87 type TransactionByteFee = TransactionByteFee;88 type WeightToFee = IdentityFee<u64>;89 type FeeMultiplierUpdate = ();90}9192parameter_types! {93 pub const MinimumPeriod: u64 = 1;94}95impl pallet_timestamp::Config for Test {96 type Moment = u64;97 type OnTimestampSet = ();98 type MinimumPeriod = MinimumPeriod;99 type WeightInfo = ();100}101102type Timestamp = pallet_timestamp::Pallet<Test>;103type Randomness = pallet_randomness_collective_flip::Pallet<Test>;104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140parameter_types! {141 pub const CollectionCreationPrice: u32 = 0;142 pub TreasuryAccountId: u64 = 1234;143 pub EthereumChainId: u32 = 1111;144}145146pub struct TestEvmAddressMapping;147impl AddressMapping<u64> for TestEvmAddressMapping {148 fn into_account_id(_addr: sp_core::H160) -> u64 {149 unimplemented!()150 }151}152153pub struct TestEvmBackwardsAddressMapping;154impl EvmBackwardsAddressMapping<u64> for TestEvmBackwardsAddressMapping {155 fn from_account_id(_account_id: u64) -> sp_core::H160 {156 unimplemented!()157 }158}159160#[derive(Encode, Decode, Clone, PartialEq, Eq, PartialOrd, Ord, Debug)]161pub struct TestCrossAccountId(u64, sp_core::H160);162impl CrossAccountId<u64> for TestCrossAccountId {163 fn from_sub(sub: u64) -> Self {164 let mut eth = [0; 20];165 eth[12..20].copy_from_slice(&sub.to_be_bytes());166 Self(sub, sp_core::H160(eth))167 }168 fn as_sub(&self) -> &u64 {169 &self.0170 }171 fn from_eth(_eth: sp_core::H160) -> Self {172 unimplemented!()173 }174 fn as_eth(&self) -> &sp_core::H160 {175 &self.1176 }177}178179pub struct TestEtheremTransactionSender;180impl pallet_ethereum::EthereumTransactionSender for TestEtheremTransactionSender {181 fn submit_logs_transaction(182 _tx: pallet_ethereum::Transaction,183 _logs: Vec<pallet_ethereum::Log>,184 ) -> Result<(), sp_runtime::DispatchError> {185 Ok(())186 }187}188189impl pallet_template::Config for Test {190 type Event = ();191 type WeightInfo = ();192 type CollectionCreationPrice = CollectionCreationPrice;193 type Currency = pallet_balances::Pallet<Test>;194 type TreasuryAccountId = TreasuryAccountId;195 type EvmAddressMapping = TestEvmAddressMapping;196 type EvmBackwardsAddressMapping = TestEvmBackwardsAddressMapping;197 type CrossAccountId = TestCrossAccountId;198 type EthereumChainId = EthereumChainId;199 type EthereumTransactionSender = TestEtheremTransactionSender;200}201202203pub fn new_test_ext() -> sp_io::TestExternalities {204 system::GenesisConfig::default()205 .build_storage::<Test>()206 .unwrap()207 .into()208}