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

difftreelog

source

runtime/tests/src/lib.rs9.0 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, fungible::Inspect},23	weights::IdentityFee,24	pallet_prelude::Weight,25};26use sp_runtime::{27	traits::{BlakeTwo256, IdentityLookup},28	testing::Header,29};30use pallet_transaction_payment::CurrencyAdapter;31use frame_system as system;32use pallet_evm::{33	AddressMapping, account::CrossAccountId, EnsureAddressNever, SubstrateBlockHashMapping,34	BackwardsAddressMapping,35};36use pallet_ethereum::PostLogContent;37use codec::{Encode, Decode, MaxEncodedLen};38use scale_info::TypeInfo;3940use up_data_structs::mapping::{CrossTokenAddressMapping, EvmTokenAddressMapping};4142#[path = "../../common/dispatch.rs"]43mod dispatch;4445use dispatch::CollectionDispatchT;4647#[path = "../../common/weights/mod.rs"]48mod weights;4950use weights::CommonWeights;5152type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;53type Block = frame_system::mocking::MockBlock<Test>;5455#[cfg(test)]56mod tests;5758// Configure a mock runtime to test the pallet.59frame_support::construct_runtime!(60	pub enum Test where61		Block = Block,62		NodeBlock = Block,63		UncheckedExtrinsic = UncheckedExtrinsic,64	{65		System: frame_system,66		Timestamp: pallet_timestamp,67		Unique: pallet_unique::{Pallet, Call, Storage},68		Balances: pallet_balances::{Pallet, Call, Storage, Event<T>},69		Common: pallet_common::{Pallet, Storage, Event<T>},70		Fungible: pallet_fungible::{Pallet, Storage},71		Refungible: pallet_refungible::{Pallet, Storage},72		Nonfungible: pallet_nonfungible::{Pallet, Storage},73		Structure: pallet_structure::{Pallet, Storage, Event<T>},74		TransactionPayment: pallet_transaction_payment::{Pallet, Storage, Event<T>},75		Ethereum: pallet_ethereum::{Pallet, Config, Call, Storage, Event, Origin},76		EVM: pallet_evm::{Pallet, Config, Call, Storage, Event<T>},77	}78);7980parameter_types! {81	pub const BlockHashCount: u64 = 250;82	pub const SS58Prefix: u8 = 42;83}8485impl system::Config for Test {86	type RuntimeEvent = RuntimeEvent;87	type BaseCallFilter = Everything;88	type BlockWeights = ();89	type BlockLength = ();90	type DbWeight = ();91	type RuntimeOrigin = RuntimeOrigin;92	type RuntimeCall = RuntimeCall;93	type Index = u64;94	type BlockNumber = u64;95	type Hash = H256;96	type Hashing = BlakeTwo256;97	type AccountId = u64;98	type Lookup = IdentityLookup<Self::AccountId>;99	type Header = Header;100	type BlockHashCount = BlockHashCount;101	type Version = ();102	type PalletInfo = PalletInfo;103	type AccountData = pallet_balances::AccountData<u64>;104	type OnNewAccount = ();105	type OnKilledAccount = ();106	type SystemWeightInfo = ();107	type SS58Prefix = SS58Prefix;108	type OnSetCode = ();109	type MaxConsumers = ConstU32<16>;110}111112parameter_types! {113	pub const ExistentialDeposit: u64 = 1;114	pub const MaxLocks: u32 = 50;115}116//frame_system::Module<Test>;117impl pallet_balances::Config for Test {118	type RuntimeEvent = RuntimeEvent;119	type AccountStore = System;120	type Balance = u64;121	type DustRemoval = ();122	type ExistentialDeposit = ExistentialDeposit;123	type WeightInfo = ();124	type MaxLocks = MaxLocks;125	type MaxReserves = ();126	type ReserveIdentifier = [u8; 8];127	type MaxFreezes = MaxLocks;128	type FreezeIdentifier = [u8; 8];129	type MaxHolds = MaxLocks;130	type HoldIdentifier = [u8; 8];131}132133parameter_types! {134	pub const OperationalFeeMultiplier: u8 = 5;135}136137impl pallet_transaction_payment::Config for Test {138	type RuntimeEvent = RuntimeEvent;139	type OnChargeTransaction = CurrencyAdapter<pallet_balances::Pallet<Test>, ()>;140	type LengthToFee = IdentityFee<u64>;141	type WeightToFee = IdentityFee<u64>;142	type FeeMultiplierUpdate = ();143	type OperationalFeeMultiplier = OperationalFeeMultiplier;144}145146parameter_types! {147	pub const MinimumPeriod: u64 = 1;148}149impl pallet_timestamp::Config for Test {150	type Moment = u64;151	type OnTimestampSet = ();152	type MinimumPeriod = MinimumPeriod;153	type WeightInfo = ();154}155156parameter_types! {157	pub const CollectionCreationPrice: u32 = 100;158	pub TreasuryAccountId: u64 = 1234;159	pub EthereumChainId: u32 = 1111;160}161162pub struct TestEvmAddressMapping;163impl AddressMapping<u64> for TestEvmAddressMapping {164	fn into_account_id(_addr: sp_core::H160) -> u64 {165		unimplemented!()166	}167}168169pub struct TestEvmBackwardsAddressMapping;170impl BackwardsAddressMapping<u64> for TestEvmBackwardsAddressMapping {171	fn from_account_id(_account_id: u64) -> sp_core::H160 {172		unimplemented!()173	}174}175176#[derive(Encode, Decode, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, TypeInfo, MaxEncodedLen)]177pub struct TestCrossAccountId(u64, sp_core::H160, bool);178impl CrossAccountId<u64> for TestCrossAccountId {179	fn as_sub(&self) -> &u64 {180		&self.0181	}182	fn as_eth(&self) -> &sp_core::H160 {183		&self.1184	}185	fn from_sub(sub: u64) -> Self {186		let mut eth = [0; 20];187		eth[12..20].copy_from_slice(&sub.to_be_bytes());188		Self(sub, sp_core::H160(eth), true)189	}190	fn from_eth(eth: sp_core::H160) -> Self {191		let mut sub_raw = [0; 8];192		sub_raw.copy_from_slice(&eth.0[0..8]);193		let sub = u64::from_be_bytes(sub_raw);194		Self(sub, eth, false)195	}196	fn conv_eq(&self, other: &Self) -> bool {197		self.as_sub() == other.as_sub()198	}199	fn is_canonical_substrate(&self) -> bool {200		self.2201	}202}203204impl Default for TestCrossAccountId {205	fn default() -> Self {206		Self::from_sub(0)207	}208}209210parameter_types! {211	pub BlockGasLimit: U256 = 0u32.into();212	pub WeightPerGas: Weight = Weight::from_parts(20, 0);213	pub const PostBlockAndTxnHashes: PostLogContent = PostLogContent::BlockAndTxnHashes;214}215216impl pallet_ethereum::Config for Test {217	type RuntimeEvent = RuntimeEvent;218	type StateRoot = pallet_ethereum::IntermediateStateRoot<Self>;219	type PostLogContent = PostBlockAndTxnHashes;220	type ExtraDataLength = ConstU32<32>;221}222223impl pallet_evm::Config for Test {224	type WeightInfo = pallet_evm::weights::SubstrateWeight<Self>;225	type CrossAccountId = TestCrossAccountId;226	type AddressMapping = TestEvmAddressMapping;227	type BackwardsAddressMapping = TestEvmBackwardsAddressMapping;228	type RuntimeEvent = RuntimeEvent;229	type FeeCalculator = ();230	type GasWeightMapping = pallet_evm::FixedGasWeightMapping<Self>;231	type WeightPerGas = WeightPerGas;232	type CallOrigin = EnsureAddressNever<Self>;233	type WithdrawOrigin = EnsureAddressNever<Self>;234	type Currency = Balances;235	type PrecompilesType = ();236	type PrecompilesValue = ();237	type Runner = pallet_evm::runner::stack::Runner<Self>;238	type ChainId = ConstU64<0>;239	type BlockGasLimit = BlockGasLimit;240	type OnMethodCall = ();241	type OnCreate = ();242	type OnChargeTransaction = ();243	type FindAuthor = ();244	type BlockHashMapping = SubstrateBlockHashMapping<Self>;245	type TransactionValidityHack = ();246	type Timestamp = Timestamp;247	type GasLimitPovSizeRatio = ConstU64<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}305306// Build genesis storage according to the mock runtime.307pub fn new_test_ext() -> sp_io::TestExternalities {308	system::GenesisConfig::default()309		.build_storage::<Test>()310		.unwrap()311		.into()312}