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}7879parameter_types! {80 pub const TransactionByteFee: u64 = 1;81}8283impl pallet_transaction_payment::Config for Test {84 type OnChargeTransaction = CurrencyAdapter<pallet_balances::Pallet<Test>, ()>;85 type TransactionByteFee = TransactionByteFee;86 type WeightToFee = IdentityFee<u64>;87 type FeeMultiplierUpdate = ();88}8990parameter_types! {91 pub const MinimumPeriod: u64 = 1;92}93impl pallet_timestamp::Config for Test {94 type Moment = u64;95 type OnTimestampSet = ();96 type MinimumPeriod = MinimumPeriod;97 type WeightInfo = ();98}99100type Timestamp = pallet_timestamp::Pallet<Test>;101type Randomness = pallet_randomness_collective_flip::Pallet<Test>;102103parameter_types! {104 pub const TombstoneDeposit: u64 = 1;105 pub const DepositPerContract: u64 = 1;106 pub const DepositPerStorageByte: u64 = 1;107 pub const DepositPerStorageItem: u64 = 1;108 pub RentFraction: Perbill = Perbill::from_rational(1u32, 30 * 24 * 60 * 10);109 pub const SurchargeReward: u64 = 1;110 pub const SignedClaimHandicap: u32 = 2;111 pub DeletionWeightLimit: u64 = u64::MAX;112 pub DeletionQueueDepth: u32 = 10;113 pub Schedule: pallet_contracts::Schedule<Test> = Default::default();114}115116impl pallet_contracts::Config for Test {117 type Time = Timestamp;118 type Randomness = Randomness;119 type Currency = pallet_balances::Pallet<Test>;120 type Event = ();121 type RentPayment = ();122 type SignedClaimHandicap = SignedClaimHandicap;123 type TombstoneDeposit = TombstoneDeposit;124 type DepositPerContract = DepositPerContract;125 type DepositPerStorageByte = DepositPerStorageByte;126 type DepositPerStorageItem = DepositPerStorageItem;127 type RentFraction = RentFraction;128 type SurchargeReward = SurchargeReward;129 type DeletionWeightLimit = DeletionWeightLimit;130 type DeletionQueueDepth = DeletionQueueDepth;131 type ChainExtension = ();132 type WeightPrice = ();133 type WeightInfo = pallet_contracts::weights::SubstrateWeight<Self>;134 type Schedule = Schedule;135 type CallStack = [pallet_contracts::Frame<Self>; 31];136}137138parameter_types! {139 pub const CollectionCreationPrice: u32 = 0;140 pub TreasuryAccountId: u64 = 1234;141 pub EthereumChainId: u32 = 1111;142}143144pub struct TestEvmAddressMapping;145impl AddressMapping<u64> for TestEvmAddressMapping {146 fn into_account_id(_addr: sp_core::H160) -> u64 {147 unimplemented!()148 }149}150151pub struct TestEvmBackwardsAddressMapping;152impl EvmBackwardsAddressMapping<u64> for TestEvmBackwardsAddressMapping {153 fn from_account_id(_account_id: u64) -> sp_core::H160 {154 unimplemented!()155 }156}157158#[derive(Encode, Decode, Clone, PartialEq, Eq, PartialOrd, Ord, Debug)]159pub struct TestCrossAccountId(u64, sp_core::H160);160impl CrossAccountId<u64> for TestCrossAccountId {161 fn from_sub(sub: u64) -> Self {162 let mut eth = [0; 20];163 eth[12..20].copy_from_slice(&sub.to_be_bytes());164 Self(sub, sp_core::H160(eth))165 }166 fn as_sub(&self) -> &u64 {167 &self.0168 }169 fn from_eth(_eth: sp_core::H160) -> Self {170 unimplemented!()171 }172 fn as_eth(&self) -> &sp_core::H160 {173 &self.1174 }175}176177pub struct TestEtheremTransactionSender;178impl pallet_ethereum::EthereumTransactionSender for TestEtheremTransactionSender {179 fn submit_logs_transaction(180 _tx: pallet_ethereum::Transaction,181 _logs: Vec<pallet_ethereum::Log>,182 ) -> Result<(), sp_runtime::DispatchError> {183 Ok(())184 }185}186187impl pallet_template::Config for Test {188 type Event = ();189 type WeightInfo = ();190 type CollectionCreationPrice = CollectionCreationPrice;191 type Currency = pallet_balances::Pallet<Test>;192 type TreasuryAccountId = TreasuryAccountId;193 type EvmAddressMapping = TestEvmAddressMapping;194 type EvmBackwardsAddressMapping = TestEvmBackwardsAddressMapping;195 type CrossAccountId = TestCrossAccountId;196 type EthereumChainId = EthereumChainId;197 type EthereumTransactionSender = TestEtheremTransactionSender;198}199200201pub fn new_test_ext() -> sp_io::TestExternalities {202 system::GenesisConfig::default()203 .build_storage::<Test>()204 .unwrap()205 .into()206}