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

difftreelog

source

runtime/tests/src/lib.rs8.8 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>;101102	type RuntimeTask = ();103104	type SingleBlockMigrations = ();105	type MultiBlockMigrator = ();106	type PreInherents = ();107	type PostInherents = ();108	type PostTransactions = ();109}110111parameter_types! {112	pub const ExistentialDeposit: u64 = 1;113	pub const MaxLocks: u32 = 50;114}115//frame_system::Module<Test>;116impl pallet_balances::Config for Test {117	type RuntimeEvent = RuntimeEvent;118	type AccountStore = System;119	type Balance = u64;120	type DustRemoval = ();121	type ExistentialDeposit = ExistentialDeposit;122	type WeightInfo = ();123	type MaxLocks = MaxLocks;124	type MaxReserves = ();125	type ReserveIdentifier = [u8; 8];126	type MaxFreezes = MaxLocks;127	type FreezeIdentifier = [u8; 8];128	type RuntimeHoldReason = RuntimeHoldReason;129	type RuntimeFreezeReason = RuntimeFreezeReason;130}131132parameter_types! {133	pub const OperationalFeeMultiplier: u8 = 5;134}135136impl pallet_transaction_payment::Config for Test {137	type RuntimeEvent = RuntimeEvent;138	type OnChargeTransaction = CurrencyAdapter<pallet_balances::Pallet<Test>, ()>;139	type LengthToFee = IdentityFee<u64>;140	type WeightToFee = IdentityFee<u64>;141	type FeeMultiplierUpdate = ();142	type OperationalFeeMultiplier = OperationalFeeMultiplier;143}144145parameter_types! {146	pub const MinimumPeriod: u64 = 1;147}148impl pallet_timestamp::Config for Test {149	type Moment = u64;150	type OnTimestampSet = ();151	type MinimumPeriod = MinimumPeriod;152	type WeightInfo = ();153}154155parameter_types! {156	pub const CollectionCreationPrice: u32 = 100;157	pub TreasuryAccountId: u64 = 1234;158	pub EthereumChainId: u32 = 1111;159}160161pub struct TestEvmAddressMapping;162impl AddressMapping<u64> for TestEvmAddressMapping {163	fn into_account_id(_addr: sp_core::H160) -> u64 {164		unimplemented!()165	}166}167168pub struct TestEvmBackwardsAddressMapping;169impl BackwardsAddressMapping<u64> for TestEvmBackwardsAddressMapping {170	fn from_account_id(_account_id: u64) -> sp_core::H160 {171		unimplemented!()172	}173}174175#[derive(Encode, Decode, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, TypeInfo, MaxEncodedLen)]176pub struct TestCrossAccountId(u64, sp_core::H160, bool);177impl CrossAccountId<u64> for TestCrossAccountId {178	fn as_sub(&self) -> &u64 {179		&self.0180	}181	fn as_eth(&self) -> &sp_core::H160 {182		&self.1183	}184	fn from_sub(sub: u64) -> Self {185		let mut eth = [0; 20];186		eth[12..20].copy_from_slice(&sub.to_be_bytes());187		Self(sub, sp_core::H160(eth), true)188	}189	fn from_eth(eth: sp_core::H160) -> Self {190		let mut sub_raw = [0; 8];191		sub_raw.copy_from_slice(&eth.0[0..8]);192		let sub = u64::from_be_bytes(sub_raw);193		Self(sub, eth, false)194	}195	fn conv_eq(&self, other: &Self) -> bool {196		self.as_sub() == other.as_sub()197	}198	fn is_canonical_substrate(&self) -> bool {199		self.2200	}201}202203impl Default for TestCrossAccountId {204	fn default() -> Self {205		Self::from_sub(0)206	}207}208209parameter_types! {210	pub BlockGasLimit: U256 = 0u32.into();211	pub WeightPerGas: Weight = Weight::from_parts(20, 0);212	pub const PostBlockAndTxnHashes: PostLogContent = PostLogContent::BlockAndTxnHashes;213}214215impl pallet_ethereum::Config for Test {216	type RuntimeEvent = RuntimeEvent;217	type StateRoot = pallet_ethereum::IntermediateStateRoot<Self>;218	type PostLogContent = PostBlockAndTxnHashes;219	type ExtraDataLength = ConstU32<32>;220}221222impl pallet_evm::Config for Test {223	type WeightInfo = pallet_evm::weights::SubstrateWeight<Self>;224	type CrossAccountId = TestCrossAccountId;225	type AddressMapping = TestEvmAddressMapping;226	type BackwardsAddressMapping = TestEvmBackwardsAddressMapping;227	type RuntimeEvent = RuntimeEvent;228	type FeeCalculator = ();229	type GasWeightMapping = pallet_evm::FixedGasWeightMapping<Self>;230	type WeightPerGas = WeightPerGas;231	type CallOrigin = EnsureAddressNever<Self>;232	type WithdrawOrigin = EnsureAddressNever<Self>;233	type Currency = Balances;234	type PrecompilesType = ();235	type PrecompilesValue = ();236	type Runner = pallet_evm::runner::stack::Runner<Self>;237	type ChainId = ConstU64<0>;238	type BlockGasLimit = BlockGasLimit;239	type OnMethodCall = ();240	type OnCreate = ();241	type OnChargeTransaction = ();242	type OnCheckEvmTransaction = ();243	type FindAuthor = ();244	type BlockHashMapping = SubstrateBlockHashMapping<Self>;245	type Timestamp = Timestamp;246	type GasLimitPovSizeRatio = ConstU64<0>;247	type SuicideQuickClearLimit = ConstU32<0>;248}249impl pallet_evm_coder_substrate::Config for Test {}250251impl pallet_common::Config for Test {252	type WeightInfo = ();253	type RuntimeEvent = RuntimeEvent;254	type Currency = Balances;255	type CollectionCreationPrice = CollectionCreationPrice;256	type TreasuryAccountId = TreasuryAccountId;257258	type CollectionDispatch = CollectionDispatchT<Self>;259	type EvmTokenAddressMapping = EvmTokenAddressMapping;260	type CrossTokenAddressMapping = CrossTokenAddressMapping<Self::AccountId>;261	type ContractAddress = EvmCollectionHelpersAddress;262}263264impl pallet_structure::Config for Test {265	type WeightInfo = ();266	type RuntimeEvent = RuntimeEvent;267	type RuntimeCall = RuntimeCall;268}269impl pallet_fungible::Config for Test {270	type WeightInfo = ();271}272impl pallet_refungible::Config for Test {273	type WeightInfo = ();274}275impl pallet_nonfungible::Config for Test {276	type WeightInfo = ();277}278parameter_types! {279	pub const Decimals: u8 = 18;280	pub Name: String = "Test".to_string();281	pub Symbol: String = "TST".to_string();282}283impl pallet_balances_adapter::Config for Test {284	type Inspect = Balances;285	type Mutate = Balances;286	type CurrencyBalance = <Balances as Inspect<Self::AccountId>>::Balance;287	type Decimals = Decimals;288	type Name = Name;289	type Symbol = Symbol;290	type WeightInfo = ();291}292293parameter_types! {294	// 0x6c4e9fe1ae37a41e93cee429e8e1881abdcbb54f295	pub const EvmCollectionHelpersAddress: H160 = H160([296		0x6c, 0x4e, 0x9f, 0xe1, 0xae, 0x37, 0xa4, 0x1e, 0x93, 0xce, 0xe4, 0x29, 0xe8, 0xe1, 0x88, 0x1a, 0xbd, 0xcb, 0xb5, 0x4f,297	]);298}299300impl pallet_unique::Config for Test {301	type WeightInfo = ();302	type CommonWeightInfo = CommonWeights<Self>;303	type RefungibleExtensionsWeightInfo = CommonWeights<Self>;304	type StructureWeightInfo = pallet_structure::weights::SubstrateWeight<Self>;305}306307// Build genesis storage according to the mock runtime.308pub fn new_test_ext() -> sp_io::TestExternalities {309	<system::GenesisConfig<Test>>::default()310		.build_storage()311		.unwrap()312		.into()313}