git.delta.rocks / unique-network / refs/commits / a034a2ffeb66

difftreelog

source

runtime/tests/src/lib.rs7.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 sp_core::{H256, U256};20use frame_support::{21	parameter_types,22	traits::{Everything, ConstU32, ConstU64},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::{32	AddressMapping, account::CrossAccountId, EnsureAddressNever, SubstrateBlockHashMapping,33};34use fp_evm_mapping::EvmBackwardsAddressMapping;35use parity_scale_codec::{Encode, Decode, MaxEncodedLen};36use scale_info::TypeInfo;3738use unique_runtime_common::{dispatch::CollectionDispatchT, weights::CommonWeights};39use up_data_structs::mapping::{CrossTokenAddressMapping, EvmTokenAddressMapping};4041type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;42type Block = frame_system::mocking::MockBlock<Test>;4344#[cfg(test)]45mod tests;4647// Configure a mock runtime to test the pallet.48frame_support::construct_runtime!(49	pub enum Test where50		Block = Block,51		NodeBlock = Block,52		UncheckedExtrinsic = UncheckedExtrinsic,53	{54		System: frame_system::{Pallet, Call, Config, Storage, Event<T>},55		Unique: pallet_unique::{Pallet, Call, Storage},56		Balances: pallet_balances::{Pallet, Call, Storage},57		Common: pallet_common::{Pallet, Storage, Event<T>},58		Fungible: pallet_fungible::{Pallet, Storage},59		Refungible: pallet_refungible::{Pallet, Storage},60		Nonfungible: pallet_nonfungible::{Pallet, Storage},61	}62);6364parameter_types! {65	pub const BlockHashCount: u64 = 250;66	pub const SS58Prefix: u8 = 42;67}6869impl system::Config for Test {70	type BaseCallFilter = Everything;71	type BlockWeights = ();72	type BlockLength = ();73	type DbWeight = ();74	type Origin = Origin;75	type Call = Call;76	type Index = u64;77	type BlockNumber = u64;78	type Hash = H256;79	type Hashing = BlakeTwo256;80	type AccountId = u64;81	type Lookup = IdentityLookup<Self::AccountId>;82	type Header = Header;83	type Event = ();84	type BlockHashCount = BlockHashCount;85	type Version = ();86	type PalletInfo = PalletInfo;87	type AccountData = pallet_balances::AccountData<u64>;88	type OnNewAccount = ();89	type OnKilledAccount = ();90	type SystemWeightInfo = ();91	type SS58Prefix = SS58Prefix;92	type OnSetCode = ();93	type MaxConsumers = ConstU32<16>;94}9596parameter_types! {97	pub const ExistentialDeposit: u64 = 1;98	pub const MaxLocks: u32 = 50;99}100//frame_system::Module<Test>;101impl pallet_balances::Config for Test {102	type AccountStore = System;103	type Balance = u64;104	type DustRemoval = ();105	type Event = ();106	type ExistentialDeposit = ExistentialDeposit;107	type WeightInfo = ();108	type MaxLocks = MaxLocks;109	type MaxReserves = ();110	type ReserveIdentifier = [u8; 8];111}112113parameter_types! {114	pub const OperationalFeeMultiplier: u8 = 5;115}116117impl pallet_transaction_payment::Config for Test {118	type OnChargeTransaction = CurrencyAdapter<pallet_balances::Pallet<Test>, ()>;119	type LengthToFee = IdentityFee<u64>;120	type WeightToFee = IdentityFee<u64>;121	type FeeMultiplierUpdate = ();122	type OperationalFeeMultiplier = OperationalFeeMultiplier;123}124125parameter_types! {126	pub const MinimumPeriod: u64 = 1;127}128impl pallet_timestamp::Config for Test {129	type Moment = u64;130	type OnTimestampSet = ();131	type MinimumPeriod = MinimumPeriod;132	type WeightInfo = ();133}134135parameter_types! {136	pub const CollectionCreationPrice: u32 = 100;137	pub TreasuryAccountId: u64 = 1234;138	pub EthereumChainId: u32 = 1111;139}140141pub struct TestEvmAddressMapping;142impl AddressMapping<u64> for TestEvmAddressMapping {143	fn into_account_id(_addr: sp_core::H160) -> u64 {144		unimplemented!()145	}146}147148pub struct TestEvmBackwardsAddressMapping;149impl EvmBackwardsAddressMapping<u64> for TestEvmBackwardsAddressMapping {150	fn from_account_id(_account_id: u64) -> sp_core::H160 {151		unimplemented!()152	}153}154155#[derive(Encode, Decode, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, TypeInfo, MaxEncodedLen)]156pub struct TestCrossAccountId(u64, sp_core::H160);157impl CrossAccountId<u64> for TestCrossAccountId {158	fn as_sub(&self) -> &u64 {159		&self.0160	}161	fn as_eth(&self) -> &sp_core::H160 {162		&self.1163	}164	fn from_sub(sub: u64) -> Self {165		let mut eth = [0; 20];166		eth[12..20].copy_from_slice(&sub.to_be_bytes());167		Self(sub, sp_core::H160(eth))168	}169	fn from_eth(eth: sp_core::H160) -> Self {170		let mut sub_raw = [0; 8];171		sub_raw.copy_from_slice(&eth.0[0..8]);172		let sub = u64::from_be_bytes(sub_raw);173		Self(sub, eth)174	}175	fn conv_eq(&self, other: &Self) -> bool {176		self.as_sub() == other.as_sub()177	}178}179180impl Default for TestCrossAccountId {181	fn default() -> Self {182		Self::from_sub(0)183	}184}185186parameter_types! {187	pub BlockGasLimit: U256 = 0u32.into();188}189190impl pallet_evm::Config for Test {191	type Event = ();192	type FeeCalculator = ();193	type GasWeightMapping = ();194	type CallOrigin = EnsureAddressNever<Self::CrossAccountId>;195	type WithdrawOrigin = EnsureAddressNever<Self::CrossAccountId>;196	type AddressMapping = TestEvmAddressMapping;197	type Currency = Balances;198	type PrecompilesType = ();199	type PrecompilesValue = ();200	type Runner = pallet_evm::runner::stack::Runner<Self>;201	type ChainId = ConstU64<0>;202	type BlockGasLimit = BlockGasLimit;203	type OnMethodCall = ();204	type OnCreate = ();205	type OnChargeTransaction = ();206	type FindAuthor = ();207	type BlockHashMapping = SubstrateBlockHashMapping<Self>;208	type TransactionValidityHack = ();209}210impl pallet_evm_coder_substrate::Config for Test {211	type GasWeightMapping = ();212}213214impl pallet_common::Config for Test {215	type WeightInfo = ();216	type Event = ();217	type Currency = Balances;218	type CollectionCreationPrice = CollectionCreationPrice;219	type TreasuryAccountId = TreasuryAccountId;220221	type CollectionDispatch = CollectionDispatchT<Self>;222	type EvmTokenAddressMapping = EvmTokenAddressMapping;223	type CrossTokenAddressMapping = CrossTokenAddressMapping<Self::AccountId>;224}225226impl pallet_evm::account::Config for Test {227	type CrossAccountId = TestCrossAccountId;228	type EvmAddressMapping = TestEvmAddressMapping;229	type EvmBackwardsAddressMapping = TestEvmBackwardsAddressMapping;230}231232impl pallet_structure::Config for Test {233	type WeightInfo = ();234	type Event = ();235	type Call = Call;236}237impl pallet_fungible::Config for Test {238	type WeightInfo = ();239}240impl pallet_refungible::Config for Test {241	type WeightInfo = ();242}243impl pallet_nonfungible::Config for Test {244	type WeightInfo = ();245}246247impl pallet_unique::Config for Test {248	type Event = ();249	type WeightInfo = ();250	type CommonWeightInfo = CommonWeights<Self>;251}252253// Build genesis storage according to the mock runtime.254pub fn new_test_ext() -> sp_io::TestExternalities {255	system::GenesisConfig::default()256		.build_storage::<Test>()257		.unwrap()258		.into()259}