git.delta.rocks / unique-network / refs/commits / 599b5140ca91

difftreelog

source

runtime/tests/src/lib.rs6.6 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 sp_core::{H160, H256};20use frame_support::{21	parameter_types,22	traits::{Everything, ConstU32},23	weights::IdentityFee,24};25use sp_runtime::{26	traits::{BlakeTwo256, IdentityLookup},27	testing::Header,28};29use pallet_transaction_payment::{CurrencyAdapter};30use frame_system as system;31use pallet_evm::{AddressMapping, runner::stack::MaybeMirroredLog, account::CrossAccountId};32use fp_evm_mapping::EvmBackwardsAddressMapping;33use parity_scale_codec::{Encode, Decode, MaxEncodedLen};34use scale_info::TypeInfo;3536use unique_runtime_common::{dispatch::CollectionDispatchT, weights::CommonWeights};37use up_data_structs::mapping::{CrossTokenAddressMapping, EvmTokenAddressMapping};3839type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;40type Block = frame_system::mocking::MockBlock<Test>;4142#[cfg(test)]43mod tests;4445// Configure a mock runtime to test the pallet.46frame_support::construct_runtime!(47	pub enum Test where48		Block = Block,49		NodeBlock = Block,50		UncheckedExtrinsic = UncheckedExtrinsic,51	{52		System: frame_system::{Pallet, Call, Config, Storage, Event<T>},53		Unique: pallet_unique::{Pallet, Call, Storage},54		Balances: pallet_balances::{Pallet, Call, Storage},55		Common: pallet_common::{Pallet, Storage, Event<T>},56		Fungible: pallet_fungible::{Pallet, Storage},57		Refungible: pallet_refungible::{Pallet, Storage},58		Nonfungible: pallet_nonfungible::{Pallet, Storage},59	}60);6162parameter_types! {63	pub const BlockHashCount: u64 = 250;64	pub const SS58Prefix: u8 = 42;65}6667impl system::Config for Test {68	type BaseCallFilter = Everything;69	type BlockWeights = ();70	type BlockLength = ();71	type DbWeight = ();72	type Origin = Origin;73	type Call = Call;74	type Index = u64;75	type BlockNumber = u64;76	type Hash = H256;77	type Hashing = BlakeTwo256;78	type AccountId = u64;79	type Lookup = IdentityLookup<Self::AccountId>;80	type Header = Header;81	type Event = ();82	type BlockHashCount = BlockHashCount;83	type Version = ();84	type PalletInfo = PalletInfo;85	type AccountData = pallet_balances::AccountData<u64>;86	type OnNewAccount = ();87	type OnKilledAccount = ();88	type SystemWeightInfo = ();89	type SS58Prefix = SS58Prefix;90	type OnSetCode = ();91	type MaxConsumers = ConstU32<16>;92}9394parameter_types! {95	pub const ExistentialDeposit: u64 = 1;96	pub const MaxLocks: u32 = 50;97}98//frame_system::Module<Test>;99impl pallet_balances::Config for Test {100	type AccountStore = System;101	type Balance = u64;102	type DustRemoval = ();103	type Event = ();104	type ExistentialDeposit = ExistentialDeposit;105	type WeightInfo = ();106	type MaxLocks = MaxLocks;107	type MaxReserves = ();108	type ReserveIdentifier = [u8; 8];109}110111parameter_types! {112	pub const OperationalFeeMultiplier: u8 = 5;113}114115impl pallet_transaction_payment::Config for Test {116	type OnChargeTransaction = CurrencyAdapter<pallet_balances::Pallet<Test>, ()>;117	type LengthToFee = IdentityFee<u64>;118	type WeightToFee = IdentityFee<u64>;119	type FeeMultiplierUpdate = ();120	type OperationalFeeMultiplier = OperationalFeeMultiplier;121}122123parameter_types! {124	pub const MinimumPeriod: u64 = 1;125}126impl pallet_timestamp::Config for Test {127	type Moment = u64;128	type OnTimestampSet = ();129	type MinimumPeriod = MinimumPeriod;130	type WeightInfo = ();131}132133parameter_types! {134	pub const CollectionCreationPrice: u32 = 100;135	pub TreasuryAccountId: u64 = 1234;136	pub EthereumChainId: u32 = 1111;137}138139pub struct TestEvmAddressMapping;140impl AddressMapping<u64> for TestEvmAddressMapping {141	fn into_account_id(_addr: sp_core::H160) -> u64 {142		unimplemented!()143	}144}145146pub struct TestEvmBackwardsAddressMapping;147impl EvmBackwardsAddressMapping<u64> for TestEvmBackwardsAddressMapping {148	fn from_account_id(_account_id: u64) -> sp_core::H160 {149		unimplemented!()150	}151}152153#[derive(Encode, Decode, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, TypeInfo, MaxEncodedLen)]154pub struct TestCrossAccountId(u64, sp_core::H160);155impl CrossAccountId<u64> for TestCrossAccountId {156	fn as_sub(&self) -> &u64 {157		&self.0158	}159	fn as_eth(&self) -> &sp_core::H160 {160		&self.1161	}162	fn from_sub(sub: u64) -> Self {163		let mut eth = [0; 20];164		eth[12..20].copy_from_slice(&sub.to_be_bytes());165		Self(sub, sp_core::H160(eth))166	}167	fn from_eth(eth: sp_core::H160) -> Self {168		let mut sub_raw = [0; 8];169		sub_raw.copy_from_slice(&eth.0[0..8]);170		let sub = u64::from_be_bytes(sub_raw);171		Self(sub, eth)172	}173	fn conv_eq(&self, other: &Self) -> bool {174		self.as_sub() == other.as_sub()175	}176}177178impl Default for TestCrossAccountId {179	fn default() -> Self {180		Self::from_sub(0)181	}182}183184pub struct TestEtheremTransactionSender;185impl pallet_ethereum::EthereumTransactionSender for TestEtheremTransactionSender {186	fn submit_logs_transaction(_source: H160, _logs: Vec<MaybeMirroredLog>) {}187}188189impl pallet_evm_coder_substrate::Config for Test {190	type EthereumTransactionSender = TestEtheremTransactionSender;191	type GasWeightMapping = ();192}193194impl pallet_common::Config for Test {195	type Event = ();196	type Currency = Balances;197	type CollectionCreationPrice = CollectionCreationPrice;198	type TreasuryAccountId = TreasuryAccountId;199200	type CollectionDispatch = CollectionDispatchT<Self>;201	type EvmTokenAddressMapping = EvmTokenAddressMapping;202	type CrossTokenAddressMapping = CrossTokenAddressMapping<Self::AccountId>;203}204205impl pallet_evm::account::Config for Test {206	type CrossAccountId = TestCrossAccountId;207	type EvmAddressMapping = TestEvmAddressMapping;208	type EvmBackwardsAddressMapping = TestEvmBackwardsAddressMapping;209}210211impl pallet_structure::Config for Test {212	type WeightInfo = ();213	type Event = ();214	type Call = Call;215}216impl pallet_fungible::Config for Test {217	type WeightInfo = ();218}219impl pallet_refungible::Config for Test {220	type WeightInfo = ();221}222impl pallet_nonfungible::Config for Test {223	type WeightInfo = ();224}225226impl pallet_unique::Config for Test {227	type Event = ();228	type WeightInfo = ();229	type CommonWeightInfo = CommonWeights<Self>;230}231232// Build genesis storage according to the mock runtime.233pub fn new_test_ext() -> sp_io::TestExternalities {234	system::GenesisConfig::default()235		.build_storage::<Test>()236		.unwrap()237		.into()238}