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

difftreelog

source

runtime/tests/src/lib.rs8.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 frame_support::{20	pallet_prelude::Weight,21	parameter_types,22	traits::{fungible::Inspect, ConstU32, ConstU64, Everything},23	weights::IdentityFee,24};25use frame_system as system;26use pallet_ethereum::PostLogContent;27use pallet_evm::{28	account::CrossAccountId, AddressMapping, BackwardsAddressMapping, EnsureAddressNever,29	SubstrateBlockHashMapping,30};31use pallet_transaction_payment::CurrencyAdapter;32use parity_scale_codec::{Decode, Encode, MaxEncodedLen};33use scale_info::TypeInfo;34use sp_core::{H160, H256, U256};35use sp_runtime::{36	traits::{BlakeTwo256, IdentityLookup},37	BuildStorage,38};39use up_data_structs::mapping::{CrossTokenAddressMapping, EvmTokenAddressMapping};4041mod dispatch;4243use dispatch::CollectionDispatchT;4445mod weights;4647use weights::CommonWeights;4849type Block = frame_system::mocking::MockBlockU32<Test>;5051#[cfg(test)]52mod tests;5354// Configure a mock runtime to test the pallet.55frame_support::construct_runtime!(56	pub enum Test {57		System: frame_system,58		Timestamp: pallet_timestamp,59		Unique: pallet_unique,60		Balances: pallet_balances,61		Common: pallet_common,62		Fungible: pallet_fungible,63		Refungible: pallet_refungible,64		Nonfungible: pallet_nonfungible,65		Structure: pallet_structure,66		TransactionPayment: pallet_transaction_payment,67		Ethereum: pallet_ethereum,68		EVM: pallet_evm,69	}70);7172parameter_types! {73	pub const BlockHashCount: u32 = 250;74	pub const SS58Prefix: u8 = 42;75}7677impl system::Config for Test {78	type RuntimeEvent = RuntimeEvent;79	type BaseCallFilter = Everything;80	type Block = Block;81	type BlockWeights = ();82	type BlockLength = ();83	type DbWeight = ();84	type RuntimeOrigin = RuntimeOrigin;85	type RuntimeCall = RuntimeCall;86	type Nonce = u64;87	type Hash = H256;88	type Hashing = BlakeTwo256;89	type AccountId = u64;90	type Lookup = IdentityLookup<Self::AccountId>;91	type BlockHashCount = BlockHashCount;92	type Version = ();93	type PalletInfo = PalletInfo;94	type AccountData = pallet_balances::AccountData<u64>;95	type OnNewAccount = ();96	type OnKilledAccount = ();97	type SystemWeightInfo = ();98	type SS58Prefix = SS58Prefix;99	type OnSetCode = ();100	type MaxConsumers = ConstU32<16>;101}102103parameter_types! {104	pub const ExistentialDeposit: u64 = 1;105	pub const MaxLocks: u32 = 50;106}107//frame_system::Module<Test>;108impl pallet_balances::Config for Test {109	type RuntimeEvent = RuntimeEvent;110	type AccountStore = System;111	type Balance = u64;112	type DustRemoval = ();113	type ExistentialDeposit = ExistentialDeposit;114	type WeightInfo = ();115	type MaxLocks = MaxLocks;116	type MaxReserves = ();117	type ReserveIdentifier = [u8; 8];118	type MaxFreezes = MaxLocks;119	type FreezeIdentifier = [u8; 8];120	type MaxHolds = MaxLocks;121	type RuntimeHoldReason = RuntimeHoldReason;122	type RuntimeFreezeReason = RuntimeFreezeReason;123}124125parameter_types! {126	pub const OperationalFeeMultiplier: u8 = 5;127}128129impl pallet_transaction_payment::Config for Test {130	type RuntimeEvent = RuntimeEvent;131	type OnChargeTransaction = CurrencyAdapter<pallet_balances::Pallet<Test>, ()>;132	type LengthToFee = IdentityFee<u64>;133	type WeightToFee = IdentityFee<u64>;134	type FeeMultiplierUpdate = ();135	type OperationalFeeMultiplier = OperationalFeeMultiplier;136}137138parameter_types! {139	pub const MinimumPeriod: u64 = 1;140}141impl pallet_timestamp::Config for Test {142	type Moment = u64;143	type OnTimestampSet = ();144	type MinimumPeriod = MinimumPeriod;145	type WeightInfo = ();146}147148parameter_types! {149	pub const CollectionCreationPrice: u32 = 100;150	pub TreasuryAccountId: u64 = 1234;151	pub EthereumChainId: u32 = 1111;152}153154pub struct TestEvmAddressMapping;155impl AddressMapping<u64> for TestEvmAddressMapping {156	fn into_account_id(_addr: sp_core::H160) -> u64 {157		unimplemented!()158	}159}160161pub struct TestEvmBackwardsAddressMapping;162impl BackwardsAddressMapping<u64> for TestEvmBackwardsAddressMapping {163	fn from_account_id(_account_id: u64) -> sp_core::H160 {164		unimplemented!()165	}166}167168#[derive(Encode, Decode, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, TypeInfo, MaxEncodedLen)]169pub struct TestCrossAccountId(u64, sp_core::H160, bool);170impl CrossAccountId<u64> for TestCrossAccountId {171	fn as_sub(&self) -> &u64 {172		&self.0173	}174	fn as_eth(&self) -> &sp_core::H160 {175		&self.1176	}177	fn from_sub(sub: u64) -> Self {178		let mut eth = [0; 20];179		eth[12..20].copy_from_slice(&sub.to_be_bytes());180		Self(sub, sp_core::H160(eth), true)181	}182	fn from_eth(eth: sp_core::H160) -> Self {183		let mut sub_raw = [0; 8];184		sub_raw.copy_from_slice(&eth.0[0..8]);185		let sub = u64::from_be_bytes(sub_raw);186		Self(sub, eth, false)187	}188	fn conv_eq(&self, other: &Self) -> bool {189		self.as_sub() == other.as_sub()190	}191	fn is_canonical_substrate(&self) -> bool {192		self.2193	}194}195196impl Default for TestCrossAccountId {197	fn default() -> Self {198		Self::from_sub(0)199	}200}201202parameter_types! {203	pub BlockGasLimit: U256 = 0u32.into();204	pub WeightPerGas: Weight = Weight::from_parts(20, 0);205	pub const PostBlockAndTxnHashes: PostLogContent = PostLogContent::BlockAndTxnHashes;206}207208impl pallet_ethereum::Config for Test {209	type RuntimeEvent = RuntimeEvent;210	type StateRoot = pallet_ethereum::IntermediateStateRoot<Self>;211	type PostLogContent = PostBlockAndTxnHashes;212	type ExtraDataLength = ConstU32<32>;213}214215impl pallet_evm::Config for Test {216	type WeightInfo = pallet_evm::weights::SubstrateWeight<Self>;217	type CrossAccountId = TestCrossAccountId;218	type AddressMapping = TestEvmAddressMapping;219	type BackwardsAddressMapping = TestEvmBackwardsAddressMapping;220	type RuntimeEvent = RuntimeEvent;221	type FeeCalculator = ();222	type GasWeightMapping = pallet_evm::FixedGasWeightMapping<Self>;223	type WeightPerGas = WeightPerGas;224	type CallOrigin = EnsureAddressNever<Self>;225	type WithdrawOrigin = EnsureAddressNever<Self>;226	type Currency = Balances;227	type PrecompilesType = ();228	type PrecompilesValue = ();229	type Runner = pallet_evm::runner::stack::Runner<Self>;230	type ChainId = ConstU64<0>;231	type BlockGasLimit = BlockGasLimit;232	type OnMethodCall = ();233	type OnCreate = ();234	type OnChargeTransaction = ();235	type OnCheckEvmTransaction = ();236	type FindAuthor = ();237	type BlockHashMapping = SubstrateBlockHashMapping<Self>;238	type Timestamp = Timestamp;239	type GasLimitPovSizeRatio = ConstU64<0>;240}241impl pallet_evm_coder_substrate::Config for Test {}242243impl pallet_common::Config for Test {244	type WeightInfo = ();245	type RuntimeEvent = RuntimeEvent;246	type Currency = Balances;247	type CollectionCreationPrice = CollectionCreationPrice;248	type TreasuryAccountId = TreasuryAccountId;249250	type CollectionDispatch = CollectionDispatchT<Self>;251	type EvmTokenAddressMapping = EvmTokenAddressMapping;252	type CrossTokenAddressMapping = CrossTokenAddressMapping<Self::AccountId>;253	type ContractAddress = EvmCollectionHelpersAddress;254}255256impl pallet_structure::Config for Test {257	type WeightInfo = ();258	type RuntimeEvent = RuntimeEvent;259	type RuntimeCall = RuntimeCall;260}261impl pallet_fungible::Config for Test {262	type WeightInfo = ();263}264impl pallet_refungible::Config for Test {265	type WeightInfo = ();266}267impl pallet_nonfungible::Config for Test {268	type WeightInfo = ();269}270parameter_types! {271	pub const Decimals: u8 = 18;272	pub Name: String = "Test".to_string();273	pub Symbol: String = "TST".to_string();274}275impl pallet_balances_adapter::Config for Test {276	type Inspect = Balances;277	type Mutate = Balances;278	type CurrencyBalance = <Balances as Inspect<Self::AccountId>>::Balance;279	type Decimals = Decimals;280	type Name = Name;281	type Symbol = Symbol;282	type WeightInfo = ();283}284285parameter_types! {286	// 0x6c4e9fe1ae37a41e93cee429e8e1881abdcbb54f287	pub const EvmCollectionHelpersAddress: H160 = H160([288		0x6c, 0x4e, 0x9f, 0xe1, 0xae, 0x37, 0xa4, 0x1e, 0x93, 0xce, 0xe4, 0x29, 0xe8, 0xe1, 0x88, 0x1a, 0xbd, 0xcb, 0xb5, 0x4f,289	]);290}291292impl pallet_unique::Config for Test {293	type WeightInfo = ();294	type CommonWeightInfo = CommonWeights<Self>;295	type RefungibleExtensionsWeightInfo = CommonWeights<Self>;296	type StructureWeightInfo = pallet_structure::weights::SubstrateWeight<Self>;297}298299// Build genesis storage according to the mock runtime.300pub fn new_test_ext() -> sp_io::TestExternalities {301	<system::GenesisConfig<Test>>::default()302		.build_storage()303		.unwrap()304		.into()305}