git.delta.rocks / unique-network / refs/commits / 3e2337f86885

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}123124parameter_types! {125	pub const OperationalFeeMultiplier: u8 = 5;126}127128impl pallet_transaction_payment::Config for Test {129	type RuntimeEvent = RuntimeEvent;130	type OnChargeTransaction = CurrencyAdapter<pallet_balances::Pallet<Test>, ()>;131	type LengthToFee = IdentityFee<u64>;132	type WeightToFee = IdentityFee<u64>;133	type FeeMultiplierUpdate = ();134	type OperationalFeeMultiplier = OperationalFeeMultiplier;135}136137parameter_types! {138	pub const MinimumPeriod: u64 = 1;139}140impl pallet_timestamp::Config for Test {141	type Moment = u64;142	type OnTimestampSet = ();143	type MinimumPeriod = MinimumPeriod;144	type WeightInfo = ();145}146147parameter_types! {148	pub const CollectionCreationPrice: u32 = 100;149	pub TreasuryAccountId: u64 = 1234;150	pub EthereumChainId: u32 = 1111;151}152153pub struct TestEvmAddressMapping;154impl AddressMapping<u64> for TestEvmAddressMapping {155	fn into_account_id(_addr: sp_core::H160) -> u64 {156		unimplemented!()157	}158}159160pub struct TestEvmBackwardsAddressMapping;161impl BackwardsAddressMapping<u64> for TestEvmBackwardsAddressMapping {162	fn from_account_id(_account_id: u64) -> sp_core::H160 {163		unimplemented!()164	}165}166167#[derive(Encode, Decode, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, TypeInfo, MaxEncodedLen)]168pub struct TestCrossAccountId(u64, sp_core::H160, bool);169impl CrossAccountId<u64> for TestCrossAccountId {170	fn as_sub(&self) -> &u64 {171		&self.0172	}173	fn as_eth(&self) -> &sp_core::H160 {174		&self.1175	}176	fn from_sub(sub: u64) -> Self {177		let mut eth = [0; 20];178		eth[12..20].copy_from_slice(&sub.to_be_bytes());179		Self(sub, sp_core::H160(eth), true)180	}181	fn from_eth(eth: sp_core::H160) -> Self {182		let mut sub_raw = [0; 8];183		sub_raw.copy_from_slice(&eth.0[0..8]);184		let sub = u64::from_be_bytes(sub_raw);185		Self(sub, eth, false)186	}187	fn conv_eq(&self, other: &Self) -> bool {188		self.as_sub() == other.as_sub()189	}190	fn is_canonical_substrate(&self) -> bool {191		self.2192	}193}194195impl Default for TestCrossAccountId {196	fn default() -> Self {197		Self::from_sub(0)198	}199}200201parameter_types! {202	pub BlockGasLimit: U256 = 0u32.into();203	pub WeightPerGas: Weight = Weight::from_parts(20, 0);204	pub const PostBlockAndTxnHashes: PostLogContent = PostLogContent::BlockAndTxnHashes;205}206207impl pallet_ethereum::Config for Test {208	type RuntimeEvent = RuntimeEvent;209	type StateRoot = pallet_ethereum::IntermediateStateRoot<Self>;210	type PostLogContent = PostBlockAndTxnHashes;211	type ExtraDataLength = ConstU32<32>;212}213214impl pallet_evm::Config for Test {215	type WeightInfo = pallet_evm::weights::SubstrateWeight<Self>;216	type CrossAccountId = TestCrossAccountId;217	type AddressMapping = TestEvmAddressMapping;218	type BackwardsAddressMapping = TestEvmBackwardsAddressMapping;219	type RuntimeEvent = RuntimeEvent;220	type FeeCalculator = ();221	type GasWeightMapping = pallet_evm::FixedGasWeightMapping<Self>;222	type WeightPerGas = WeightPerGas;223	type CallOrigin = EnsureAddressNever<Self>;224	type WithdrawOrigin = EnsureAddressNever<Self>;225	type Currency = Balances;226	type PrecompilesType = ();227	type PrecompilesValue = ();228	type Runner = pallet_evm::runner::stack::Runner<Self>;229	type ChainId = ConstU64<0>;230	type BlockGasLimit = BlockGasLimit;231	type OnMethodCall = ();232	type OnCreate = ();233	type OnChargeTransaction = ();234	type OnCheckEvmTransaction = ();235	type FindAuthor = ();236	type BlockHashMapping = SubstrateBlockHashMapping<Self>;237	type Timestamp = Timestamp;238	type GasLimitPovSizeRatio = ConstU64<0>;239}240impl pallet_evm_coder_substrate::Config for Test {}241242impl pallet_common::Config for Test {243	type WeightInfo = ();244	type RuntimeEvent = RuntimeEvent;245	type Currency = Balances;246	type CollectionCreationPrice = CollectionCreationPrice;247	type TreasuryAccountId = TreasuryAccountId;248249	type CollectionDispatch = CollectionDispatchT<Self>;250	type EvmTokenAddressMapping = EvmTokenAddressMapping;251	type CrossTokenAddressMapping = CrossTokenAddressMapping<Self::AccountId>;252	type ContractAddress = EvmCollectionHelpersAddress;253}254255impl pallet_structure::Config for Test {256	type WeightInfo = ();257	type RuntimeEvent = RuntimeEvent;258	type RuntimeCall = RuntimeCall;259}260impl pallet_fungible::Config for Test {261	type WeightInfo = ();262}263impl pallet_refungible::Config for Test {264	type WeightInfo = ();265}266impl pallet_nonfungible::Config for Test {267	type WeightInfo = ();268}269parameter_types! {270	pub const Decimals: u8 = 18;271	pub Name: String = "Test".to_string();272	pub Symbol: String = "TST".to_string();273}274impl pallet_balances_adapter::Config for Test {275	type Inspect = Balances;276	type Mutate = Balances;277	type CurrencyBalance = <Balances as Inspect<Self::AccountId>>::Balance;278	type Decimals = Decimals;279	type Name = Name;280	type Symbol = Symbol;281	type WeightInfo = ();282}283284parameter_types! {285	// 0x6c4e9fe1ae37a41e93cee429e8e1881abdcbb54f286	pub const EvmCollectionHelpersAddress: H160 = H160([287		0x6c, 0x4e, 0x9f, 0xe1, 0xae, 0x37, 0xa4, 0x1e, 0x93, 0xce, 0xe4, 0x29, 0xe8, 0xe1, 0x88, 0x1a, 0xbd, 0xcb, 0xb5, 0x4f,288	]);289}290291impl pallet_unique::Config for Test {292	type WeightInfo = ();293	type CommonWeightInfo = CommonWeights<Self>;294	type RefungibleExtensionsWeightInfo = CommonWeights<Self>;295	type StructureWeightInfo = pallet_structure::weights::SubstrateWeight<Self>;296}297298// Build genesis storage according to the mock runtime.299pub fn new_test_ext() -> sp_io::TestExternalities {300	<system::GenesisConfig<Test>>::default()301		.build_storage()302		.unwrap()303		.into()304}