git.delta.rocks / unique-network / refs/commits / 2dfd73643010

difftreelog

source

pallets/unique/src/mock.rs6.2 KiBsourcehistory
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617#![allow(clippy::from_over_into)]1819use crate as pallet_template;20use sp_core::{H160, H256};21use frame_support::{parameter_types, traits::Everything, weights::IdentityFee};22use sp_runtime::{23	traits::{BlakeTwo256, IdentityLookup},24	testing::Header,25};26use pallet_transaction_payment::{CurrencyAdapter};27use frame_system as system;28use pallet_evm::{AddressMapping, runner::stack::MaybeMirroredLog};29use pallet_common::account::{EvmBackwardsAddressMapping, CrossAccountId};30use codec::{Encode, Decode, MaxEncodedLen};31use scale_info::TypeInfo;32use up_data_structs::ConstU32;3334type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;35type Block = frame_system::mocking::MockBlock<Test>;3637// Configure a mock runtime to test the pallet.38frame_support::construct_runtime!(39	pub enum Test where40		Block = Block,41		NodeBlock = Block,42		UncheckedExtrinsic = UncheckedExtrinsic,43	{44		System: frame_system::{Pallet, Call, Config, Storage, Event<T>},45		TemplateModule: pallet_template::{Pallet, Call, Storage},46		Balances: pallet_balances::{Pallet, Call, Storage},47		Common: pallet_common::{Pallet, Storage, Event<T>},48		Fungible: pallet_fungible::{Pallet, Storage},49		Refungible: pallet_refungible::{Pallet, Storage},50		Nonfungible: pallet_nonfungible::{Pallet, Storage},51	}52);5354parameter_types! {55	pub const BlockHashCount: u64 = 250;56	pub const SS58Prefix: u8 = 42;57}5859impl system::Config for Test {60	type BaseCallFilter = Everything;61	type BlockWeights = ();62	type BlockLength = ();63	type DbWeight = ();64	type Origin = Origin;65	type Call = Call;66	type Index = u64;67	type BlockNumber = u64;68	type Hash = H256;69	type Hashing = BlakeTwo256;70	type AccountId = u64;71	type Lookup = IdentityLookup<Self::AccountId>;72	type Header = Header;73	type Event = ();74	type BlockHashCount = BlockHashCount;75	type Version = ();76	type PalletInfo = PalletInfo;77	type AccountData = pallet_balances::AccountData<u64>;78	type OnNewAccount = ();79	type OnKilledAccount = ();80	type SystemWeightInfo = ();81	type SS58Prefix = SS58Prefix;82	type OnSetCode = ();83	type MaxConsumers = ConstU32<16>;84}8586parameter_types! {87	pub const ExistentialDeposit: u64 = 1;88	pub const MaxLocks: u32 = 50;89}90//frame_system::Module<Test>;91impl pallet_balances::Config for Test {92	type AccountStore = System;93	type Balance = u64;94	type DustRemoval = ();95	type Event = ();96	type ExistentialDeposit = ExistentialDeposit;97	type WeightInfo = ();98	type MaxLocks = MaxLocks;99	type MaxReserves = ();100	type ReserveIdentifier = [u8; 8];101}102103parameter_types! {104	pub const TransactionByteFee: u64 = 1;105	pub const OperationalFeeMultiplier: u8 = 5;106}107108impl pallet_transaction_payment::Config for Test {109	type OnChargeTransaction = CurrencyAdapter<pallet_balances::Pallet<Test>, ()>;110	type TransactionByteFee = TransactionByteFee;111	type WeightToFee = IdentityFee<u64>;112	type FeeMultiplierUpdate = ();113	type OperationalFeeMultiplier = OperationalFeeMultiplier;114}115116parameter_types! {117	pub const MinimumPeriod: u64 = 1;118}119impl pallet_timestamp::Config for Test {120	type Moment = u64;121	type OnTimestampSet = ();122	type MinimumPeriod = MinimumPeriod;123	type WeightInfo = ();124}125126parameter_types! {127	pub const CollectionCreationPrice: u32 = 100;128	pub TreasuryAccountId: u64 = 1234;129	pub EthereumChainId: u32 = 1111;130}131132pub struct TestEvmAddressMapping;133impl AddressMapping<u64> for TestEvmAddressMapping {134	fn into_account_id(_addr: sp_core::H160) -> u64 {135		unimplemented!()136	}137}138139pub struct TestEvmBackwardsAddressMapping;140impl EvmBackwardsAddressMapping<u64> for TestEvmBackwardsAddressMapping {141	fn from_account_id(_account_id: u64) -> sp_core::H160 {142		unimplemented!()143	}144}145146#[derive(Encode, Decode, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, TypeInfo, MaxEncodedLen)]147pub struct TestCrossAccountId(u64, sp_core::H160);148impl CrossAccountId<u64> for TestCrossAccountId {149	fn as_sub(&self) -> &u64 {150		&self.0151	}152	fn as_eth(&self) -> &sp_core::H160 {153		&self.1154	}155	fn from_sub(sub: u64) -> Self {156		let mut eth = [0; 20];157		eth[12..20].copy_from_slice(&sub.to_be_bytes());158		Self(sub, sp_core::H160(eth))159	}160	fn from_eth(eth: sp_core::H160) -> Self {161		let mut sub_raw = [0; 8];162		sub_raw.copy_from_slice(&eth.0[0..8]);163		let sub = u64::from_be_bytes(sub_raw);164		Self(sub, eth)165	}166	fn conv_eq(&self, other: &Self) -> bool {167		self.as_sub() == other.as_sub()168	}169}170171impl Default for TestCrossAccountId {172	fn default() -> Self {173		Self::from_sub(0)174	}175}176177pub struct TestEtheremTransactionSender;178impl pallet_ethereum::EthereumTransactionSender for TestEtheremTransactionSender {179	fn submit_logs_transaction(180		_source: H160,181		_tx: pallet_ethereum::Transaction,182		_logs: Vec<MaybeMirroredLog>,183	) {184	}185}186187impl pallet_evm_coder_substrate::Config for Test {188	type EthereumTransactionSender = TestEtheremTransactionSender;189	type GasWeightMapping = ();190}191192impl pallet_common::Config for Test {193	type Event = ();194	type EvmBackwardsAddressMapping = TestEvmBackwardsAddressMapping;195	type EvmAddressMapping = TestEvmAddressMapping;196	type CrossAccountId = TestCrossAccountId;197198	type Currency = Balances;199	type CollectionCreationPrice = CollectionCreationPrice;200	type TreasuryAccountId = TreasuryAccountId;201}202203impl pallet_fungible::Config for Test {204	type WeightInfo = ();205}206impl pallet_refungible::Config for Test {207	type WeightInfo = ();208}209impl pallet_nonfungible::Config for Test {210	type WeightInfo = ();211}212213impl pallet_template::Config for Test {214	type Event = ();215	type WeightInfo = ();216}217218// Build genesis storage according to the mock runtime.219pub fn new_test_ext() -> sp_io::TestExternalities {220	system::GenesisConfig::default()221		.build_storage::<Test>()222		.unwrap()223		.into()224}