git.delta.rocks / unique-network / refs/commits / 4b0f7ea4ecce

difftreelog

source

runtime/tests/src/lib.rs8.1 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, 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 up_data_structs::mapping::{CrossTokenAddressMapping, EvmTokenAddressMapping};3940#[path = "../../common/dispatch.rs"]41mod dispatch;4243use dispatch::CollectionDispatchT;4445#[path = "../../common/weights.rs"]46mod weights;4748use weights::CommonWeights;4950type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;51type Block = frame_system::mocking::MockBlock<Test>;5253#[cfg(test)]54mod tests;5556// Configure a mock runtime to test the pallet.57frame_support::construct_runtime!(58	pub enum Test where59		Block = Block,60		NodeBlock = Block,61		UncheckedExtrinsic = UncheckedExtrinsic,62	{63		System: frame_system,64		Unique: pallet_unique::{Pallet, Call, Storage, Event<T>},65		Balances: pallet_balances::{Pallet, Call, Storage, Event<T>},66		Common: pallet_common::{Pallet, Storage, Event<T>},67		Fungible: pallet_fungible::{Pallet, Storage},68		Refungible: pallet_refungible::{Pallet, Storage},69		Nonfungible: pallet_nonfungible::{Pallet, Storage},70		Structure: pallet_structure::{Pallet, Storage, Event<T>},71		TransactionPayment: pallet_transaction_payment::{Pallet, Storage, Event<T>},72		Ethereum: pallet_ethereum::{Pallet, Config, Call, Storage, Event, Origin},73		EVM: pallet_evm::{Pallet, Config, Call, Storage, Event<T>},74	}75);7677parameter_types! {78	pub const BlockHashCount: u64 = 250;79	pub const SS58Prefix: u8 = 42;80}8182impl system::Config for Test {83	type Event = Event;84	type BaseCallFilter = Everything;85	type BlockWeights = ();86	type BlockLength = ();87	type DbWeight = ();88	type Origin = Origin;89	type Call = Call;90	type Index = u64;91	type BlockNumber = u64;92	type Hash = H256;93	type Hashing = BlakeTwo256;94	type AccountId = u64;95	type Lookup = IdentityLookup<Self::AccountId>;96	type Header = Header;97	type BlockHashCount = BlockHashCount;98	type Version = ();99	type PalletInfo = PalletInfo;100	type AccountData = pallet_balances::AccountData<u64>;101	type OnNewAccount = ();102	type OnKilledAccount = ();103	type SystemWeightInfo = ();104	type SS58Prefix = SS58Prefix;105	type OnSetCode = ();106	type MaxConsumers = ConstU32<16>;107}108109parameter_types! {110	pub const ExistentialDeposit: u64 = 1;111	pub const MaxLocks: u32 = 50;112}113//frame_system::Module<Test>;114impl pallet_balances::Config for Test {115	type Event = Event;116	type AccountStore = System;117	type Balance = u64;118	type DustRemoval = ();119	type ExistentialDeposit = ExistentialDeposit;120	type WeightInfo = ();121	type MaxLocks = MaxLocks;122	type MaxReserves = ();123	type ReserveIdentifier = [u8; 8];124}125126parameter_types! {127	pub const OperationalFeeMultiplier: u8 = 5;128}129130impl pallet_transaction_payment::Config for Test {131	type Event = Event;132	type OnChargeTransaction = CurrencyAdapter<pallet_balances::Pallet<Test>, ()>;133	type LengthToFee = IdentityFee<u64>;134	type WeightToFee = IdentityFee<u64>;135	type FeeMultiplierUpdate = ();136	type OperationalFeeMultiplier = OperationalFeeMultiplier;137}138139parameter_types! {140	pub const MinimumPeriod: u64 = 1;141}142impl pallet_timestamp::Config for Test {143	type Moment = u64;144	type OnTimestampSet = ();145	type MinimumPeriod = MinimumPeriod;146	type WeightInfo = ();147}148149parameter_types! {150	pub const CollectionCreationPrice: u32 = 100;151	pub TreasuryAccountId: u64 = 1234;152	pub EthereumChainId: u32 = 1111;153}154155pub struct TestEvmAddressMapping;156impl AddressMapping<u64> for TestEvmAddressMapping {157	fn into_account_id(_addr: sp_core::H160) -> u64 {158		unimplemented!()159	}160}161162pub struct TestEvmBackwardsAddressMapping;163impl EvmBackwardsAddressMapping<u64> for TestEvmBackwardsAddressMapping {164	fn from_account_id(_account_id: u64) -> sp_core::H160 {165		unimplemented!()166	}167}168169#[derive(Encode, Decode, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, TypeInfo, MaxEncodedLen)]170pub struct TestCrossAccountId(u64, sp_core::H160, bool);171impl CrossAccountId<u64> for TestCrossAccountId {172	fn as_sub(&self) -> &u64 {173		&self.0174	}175	fn as_eth(&self) -> &sp_core::H160 {176		&self.1177	}178	fn from_sub(sub: u64) -> Self {179		let mut eth = [0; 20];180		eth[12..20].copy_from_slice(&sub.to_be_bytes());181		Self(sub, sp_core::H160(eth), true)182	}183	fn from_eth(eth: sp_core::H160) -> Self {184		let mut sub_raw = [0; 8];185		sub_raw.copy_from_slice(&eth.0[0..8]);186		let sub = u64::from_be_bytes(sub_raw);187		Self(sub, eth, false)188	}189	fn conv_eq(&self, other: &Self) -> bool {190		self.as_sub() == other.as_sub()191	}192	fn is_canonical_substrate(&self) -> bool {193		self.2194	}195}196197impl Default for TestCrossAccountId {198	fn default() -> Self {199		Self::from_sub(0)200	}201}202203parameter_types! {204	pub BlockGasLimit: U256 = 0u32.into();205}206207impl pallet_ethereum::Config for Test {208	type Event = Event;209	type StateRoot = pallet_ethereum::IntermediateStateRoot<Self>;210}211212impl pallet_evm::Config for Test {213	type Event = Event;214	type FeeCalculator = ();215	type GasWeightMapping = ();216	type CallOrigin = EnsureAddressNever<Self::CrossAccountId>;217	type WithdrawOrigin = EnsureAddressNever<Self::CrossAccountId>;218	type AddressMapping = TestEvmAddressMapping;219	type Currency = Balances;220	type PrecompilesType = ();221	type PrecompilesValue = ();222	type Runner = pallet_evm::runner::stack::Runner<Self>;223	type ChainId = ConstU64<0>;224	type BlockGasLimit = BlockGasLimit;225	type OnMethodCall = ();226	type OnCreate = ();227	type OnChargeTransaction = ();228	type FindAuthor = ();229	type BlockHashMapping = SubstrateBlockHashMapping<Self>;230	type TransactionValidityHack = ();231}232impl pallet_evm_coder_substrate::Config for Test {}233234impl pallet_common::Config for Test {235	type WeightInfo = ();236	type Event = Event;237	type Currency = Balances;238	type CollectionCreationPrice = CollectionCreationPrice;239	type TreasuryAccountId = TreasuryAccountId;240241	type CollectionDispatch = CollectionDispatchT<Self>;242	type EvmTokenAddressMapping = EvmTokenAddressMapping;243	type CrossTokenAddressMapping = CrossTokenAddressMapping<Self::AccountId>;244	type ContractAddress = EvmCollectionHelpersAddress;245}246247impl pallet_evm::account::Config for Test {248	type CrossAccountId = TestCrossAccountId;249	type EvmAddressMapping = TestEvmAddressMapping;250	type EvmBackwardsAddressMapping = TestEvmBackwardsAddressMapping;251}252253impl pallet_structure::Config for Test {254	type WeightInfo = ();255	type Event = Event;256	type Call = Call;257}258impl pallet_fungible::Config for Test {259	type WeightInfo = ();260}261impl pallet_refungible::Config for Test {262	type WeightInfo = ();263}264impl pallet_nonfungible::Config for Test {265	type WeightInfo = ();266}267268parameter_types! {269	// 0x6c4e9fe1ae37a41e93cee429e8e1881abdcbb54f270	pub const EvmCollectionHelpersAddress: H160 = H160([271		0x6c, 0x4e, 0x9f, 0xe1, 0xae, 0x37, 0xa4, 0x1e, 0x93, 0xce, 0xe4, 0x29, 0xe8, 0xe1, 0x88, 0x1a, 0xbd, 0xcb, 0xb5, 0x4f,272	]);273}274275impl pallet_unique::Config for Test {276	type Event = Event;277	type WeightInfo = ();278	type CommonWeightInfo = CommonWeights<Self>;279	type RefungibleExtensionsWeightInfo = CommonWeights<Self>;280}281282// Build genesis storage according to the mock runtime.283pub fn new_test_ext() -> sp_io::TestExternalities {284	system::GenesisConfig::default()285		.build_storage::<Test>()286		.unwrap()287		.into()288}