git.delta.rocks / unique-network / refs/commits / 38470585a7b3

difftreelog

source

runtime/tests/src/lib.rs7.5 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 unique_runtime_common::{dispatch::CollectionDispatchT, weights::CommonWeights};39use up_data_structs::mapping::{CrossTokenAddressMapping, EvmTokenAddressMapping};4041type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;42type Block = frame_system::mocking::MockBlock<Test>;4344#[cfg(test)]45mod tests;4647// Configure a mock runtime to test the pallet.48frame_support::construct_runtime!(49	pub enum Test where50		Block = Block,51		NodeBlock = Block,52		UncheckedExtrinsic = UncheckedExtrinsic,53	{54		System: frame_system::{Pallet, Call, Config, Storage, Event<T>},55		Unique: pallet_unique::{Pallet, Call, Storage},56		Balances: pallet_balances::{Pallet, Call, Storage},57		Common: pallet_common::{Pallet, Storage, Event<T>},58		Fungible: pallet_fungible::{Pallet, Storage},59		Refungible: pallet_refungible::{Pallet, Storage},60		Nonfungible: pallet_nonfungible::{Pallet, Storage},61		EVM: pallet_evm::{Pallet, Config, Call, Storage, Event<T>},62	}63);6465parameter_types! {66	pub const BlockHashCount: u64 = 250;67	pub const SS58Prefix: u8 = 42;68}6970impl system::Config for Test {71	type BaseCallFilter = Everything;72	type BlockWeights = ();73	type BlockLength = ();74	type DbWeight = ();75	type Origin = Origin;76	type Call = Call;77	type Index = u64;78	type BlockNumber = u64;79	type Hash = H256;80	type Hashing = BlakeTwo256;81	type AccountId = u64;82	type Lookup = IdentityLookup<Self::AccountId>;83	type Header = Header;84	type Event = ();85	type BlockHashCount = BlockHashCount;86	type Version = ();87	type PalletInfo = PalletInfo;88	type AccountData = pallet_balances::AccountData<u64>;89	type OnNewAccount = ();90	type OnKilledAccount = ();91	type SystemWeightInfo = ();92	type SS58Prefix = SS58Prefix;93	type OnSetCode = ();94	type MaxConsumers = ConstU32<16>;95}9697parameter_types! {98	pub const ExistentialDeposit: u64 = 1;99	pub const MaxLocks: u32 = 50;100}101//frame_system::Module<Test>;102impl pallet_balances::Config for Test {103	type AccountStore = System;104	type Balance = u64;105	type DustRemoval = ();106	type Event = ();107	type ExistentialDeposit = ExistentialDeposit;108	type WeightInfo = ();109	type MaxLocks = MaxLocks;110	type MaxReserves = ();111	type ReserveIdentifier = [u8; 8];112}113114parameter_types! {115	pub const OperationalFeeMultiplier: u8 = 5;116}117118impl pallet_transaction_payment::Config for Test {119	type OnChargeTransaction = CurrencyAdapter<pallet_balances::Pallet<Test>, ()>;120	type LengthToFee = IdentityFee<u64>;121	type WeightToFee = IdentityFee<u64>;122	type FeeMultiplierUpdate = ();123	type OperationalFeeMultiplier = OperationalFeeMultiplier;124}125126parameter_types! {127	pub const MinimumPeriod: u64 = 1;128}129impl pallet_timestamp::Config for Test {130	type Moment = u64;131	type OnTimestampSet = ();132	type MinimumPeriod = MinimumPeriod;133	type WeightInfo = ();134}135136parameter_types! {137	pub const CollectionCreationPrice: u32 = 100;138	pub TreasuryAccountId: u64 = 1234;139	pub EthereumChainId: u32 = 1111;140}141142pub struct TestEvmAddressMapping;143impl AddressMapping<u64> for TestEvmAddressMapping {144	fn into_account_id(_addr: sp_core::H160) -> u64 {145		unimplemented!()146	}147}148149pub struct TestEvmBackwardsAddressMapping;150impl EvmBackwardsAddressMapping<u64> for TestEvmBackwardsAddressMapping {151	fn from_account_id(_account_id: u64) -> sp_core::H160 {152		unimplemented!()153	}154}155156#[derive(Encode, Decode, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, TypeInfo, MaxEncodedLen)]157pub struct TestCrossAccountId(u64, sp_core::H160);158impl CrossAccountId<u64> for TestCrossAccountId {159	fn as_sub(&self) -> &u64 {160		&self.0161	}162	fn as_eth(&self) -> &sp_core::H160 {163		&self.1164	}165	fn from_sub(sub: u64) -> Self {166		let mut eth = [0; 20];167		eth[12..20].copy_from_slice(&sub.to_be_bytes());168		Self(sub, sp_core::H160(eth))169	}170	fn from_eth(eth: sp_core::H160) -> Self {171		let mut sub_raw = [0; 8];172		sub_raw.copy_from_slice(&eth.0[0..8]);173		let sub = u64::from_be_bytes(sub_raw);174		Self(sub, eth)175	}176	fn conv_eq(&self, other: &Self) -> bool {177		self.as_sub() == other.as_sub()178	}179}180181impl Default for TestCrossAccountId {182	fn default() -> Self {183		Self::from_sub(0)184	}185}186187parameter_types! {188	pub BlockGasLimit: U256 = 0u32.into();189}190191impl pallet_evm::Config for Test {192	type Event = ();193	type FeeCalculator = ();194	type GasWeightMapping = ();195	type CallOrigin = EnsureAddressNever<Self::CrossAccountId>;196	type WithdrawOrigin = EnsureAddressNever<Self::CrossAccountId>;197	type AddressMapping = TestEvmAddressMapping;198	type Currency = Balances;199	type PrecompilesType = ();200	type PrecompilesValue = ();201	type Runner = pallet_evm::runner::stack::Runner<Self>;202	type ChainId = ConstU64<0>;203	type BlockGasLimit = BlockGasLimit;204	type OnMethodCall = ();205	type OnCreate = ();206	type OnChargeTransaction = ();207	type FindAuthor = ();208	type BlockHashMapping = SubstrateBlockHashMapping<Self>;209	type TransactionValidityHack = ();210}211impl pallet_evm_coder_substrate::Config for Test {}212213impl pallet_common::Config for Test {214	type WeightInfo = ();215	type Event = ();216	type Currency = Balances;217	type CollectionCreationPrice = CollectionCreationPrice;218	type TreasuryAccountId = TreasuryAccountId;219220	type CollectionDispatch = CollectionDispatchT<Self>;221	type EvmTokenAddressMapping = EvmTokenAddressMapping;222	type CrossTokenAddressMapping = CrossTokenAddressMapping<Self::AccountId>;223	type ContractAddress = EvmCollectionHelpersAddress;224}225226impl pallet_evm::account::Config for Test {227	type CrossAccountId = TestCrossAccountId;228	type EvmAddressMapping = TestEvmAddressMapping;229	type EvmBackwardsAddressMapping = TestEvmBackwardsAddressMapping;230}231232impl pallet_structure::Config for Test {233	type WeightInfo = ();234	type Event = ();235	type Call = Call;236}237impl pallet_fungible::Config for Test {238	type WeightInfo = ();239}240impl pallet_refungible::Config for Test {241	type WeightInfo = ();242}243impl pallet_nonfungible::Config for Test {244	type WeightInfo = ();245}246247parameter_types! {248	// 0x6c4e9fe1ae37a41e93cee429e8e1881abdcbb54f249	pub const EvmCollectionHelpersAddress: H160 = H160([250		0x6c, 0x4e, 0x9f, 0xe1, 0xae, 0x37, 0xa4, 0x1e, 0x93, 0xce, 0xe4, 0x29, 0xe8, 0xe1, 0x88, 0x1a, 0xbd, 0xcb, 0xb5, 0x4f,251	]);252}253254impl pallet_unique::Config for Test {255	type Event = ();256	type WeightInfo = ();257	type CommonWeightInfo = CommonWeights<Self>;258}259260// Build genesis storage according to the mock runtime.261pub fn new_test_ext() -> sp_io::TestExternalities {262	system::GenesisConfig::default()263		.build_storage::<Test>()264		.unwrap()265		.into()266}