git.delta.rocks / unique-network / refs/commits / 784fe46a4598

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, account::CrossAccountId};29use fp_evm_mapping::EvmBackwardsAddressMapping;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 OperationalFeeMultiplier: u8 = 5;105}106107impl pallet_transaction_payment::Config for Test {108	type OnChargeTransaction = CurrencyAdapter<pallet_balances::Pallet<Test>, ()>;109	type LengthToFee = IdentityFee<u64>;110	type WeightToFee = IdentityFee<u64>;111	type FeeMultiplierUpdate = ();112	type OperationalFeeMultiplier = OperationalFeeMultiplier;113}114115parameter_types! {116	pub const MinimumPeriod: u64 = 1;117}118impl pallet_timestamp::Config for Test {119	type Moment = u64;120	type OnTimestampSet = ();121	type MinimumPeriod = MinimumPeriod;122	type WeightInfo = ();123}124125parameter_types! {126	pub const CollectionCreationPrice: u32 = 100;127	pub TreasuryAccountId: u64 = 1234;128	pub EthereumChainId: u32 = 1111;129}130131pub struct TestEvmAddressMapping;132impl AddressMapping<u64> for TestEvmAddressMapping {133	fn into_account_id(_addr: sp_core::H160) -> u64 {134		unimplemented!()135	}136}137138pub struct TestEvmBackwardsAddressMapping;139impl EvmBackwardsAddressMapping<u64> for TestEvmBackwardsAddressMapping {140	fn from_account_id(_account_id: u64) -> sp_core::H160 {141		unimplemented!()142	}143}144145#[derive(Encode, Decode, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, TypeInfo, MaxEncodedLen)]146pub struct TestCrossAccountId(u64, sp_core::H160);147impl CrossAccountId<u64> for TestCrossAccountId {148	fn as_sub(&self) -> &u64 {149		&self.0150	}151	fn as_eth(&self) -> &sp_core::H160 {152		&self.1153	}154	fn from_sub(sub: u64) -> Self {155		let mut eth = [0; 20];156		eth[12..20].copy_from_slice(&sub.to_be_bytes());157		Self(sub, sp_core::H160(eth))158	}159	fn from_eth(eth: sp_core::H160) -> Self {160		let mut sub_raw = [0; 8];161		sub_raw.copy_from_slice(&eth.0[0..8]);162		let sub = u64::from_be_bytes(sub_raw);163		Self(sub, eth)164	}165	fn conv_eq(&self, other: &Self) -> bool {166		self.as_sub() == other.as_sub()167	}168}169170impl Default for TestCrossAccountId {171	fn default() -> Self {172		Self::from_sub(0)173	}174}175176pub struct TestEtheremTransactionSender;177impl pallet_ethereum::EthereumTransactionSender for TestEtheremTransactionSender {178	fn submit_logs_transaction(_source: H160, _logs: Vec<MaybeMirroredLog>) {}179}180181impl pallet_evm_coder_substrate::Config for Test {182	type EthereumTransactionSender = TestEtheremTransactionSender;183	type GasWeightMapping = ();184}185186impl pallet_common::Config for Test {187	type Event = ();188	type Currency = Balances;189	type CollectionCreationPrice = CollectionCreationPrice;190	type TreasuryAccountId = TreasuryAccountId;191}192193impl pallet_evm::account::Config for Test {194	type CrossAccountId = TestCrossAccountId;195	type EvmAddressMapping = TestEvmAddressMapping;196	type EvmBackwardsAddressMapping = TestEvmBackwardsAddressMapping;197}198199impl pallet_fungible::Config for Test {200	type WeightInfo = ();201}202impl pallet_refungible::Config for Test {203	type WeightInfo = ();204}205impl pallet_nonfungible::Config for Test {206	type WeightInfo = ();207}208209impl pallet_template::Config for Test {210	type Event = ();211	type WeightInfo = ();212}213214// Build genesis storage according to the mock runtime.215pub fn new_test_ext() -> sp_io::TestExternalities {216	system::GenesisConfig::default()217		.build_storage::<Test>()218		.unwrap()219		.into()220}