git.delta.rocks / unique-network / refs/commits / 51e104f081b5

difftreelog

source

pallets/nft/src/mock.rs4.7 KiBsourcehistory
1#![allow(clippy::from_over_into)]23use crate as pallet_template;4use sp_core::H256;5use frame_support::{parameter_types, traits::Everything, weights::IdentityFee};6use sp_runtime::{7	traits::{BlakeTwo256, IdentityLookup},8	testing::Header,9};10use pallet_transaction_payment::{CurrencyAdapter};11use frame_system as system;12use pallet_evm::AddressMapping;13use crate::{EvmBackwardsAddressMapping, CrossAccountId};14use codec::{Encode, Decode};15use scale_info::TypeInfo;1617type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;18type Block = frame_system::mocking::MockBlock<Test>;1920// Configure a mock runtime to test the pallet.21frame_support::construct_runtime!(22	pub enum Test where23		Block = Block,24		NodeBlock = Block,25		UncheckedExtrinsic = UncheckedExtrinsic,26	{27		System: frame_system::{Pallet, Call, Config, Storage, Event<T>},28		TemplateModule: pallet_template::{Pallet, Call, Storage},29		Balances: pallet_balances::{Pallet, Call, Storage},30	}31);3233parameter_types! {34	pub const BlockHashCount: u64 = 250;35	pub const SS58Prefix: u8 = 42;36}3738impl system::Config for Test {39	type BaseCallFilter = Everything;40	type BlockWeights = ();41	type BlockLength = ();42	type DbWeight = ();43	type Origin = Origin;44	type Call = Call;45	type Index = u64;46	type BlockNumber = u64;47	type Hash = H256;48	type Hashing = BlakeTwo256;49	type AccountId = u64;50	type Lookup = IdentityLookup<Self::AccountId>;51	type Header = Header;52	type Event = ();53	type BlockHashCount = BlockHashCount;54	type Version = ();55	type PalletInfo = PalletInfo;56	type AccountData = pallet_balances::AccountData<u64>;57	type OnNewAccount = ();58	type OnKilledAccount = ();59	type SystemWeightInfo = ();60	type SS58Prefix = SS58Prefix;61	type OnSetCode = ();62}6364parameter_types! {65	pub const ExistentialDeposit: u64 = 1;66	pub const MaxLocks: u32 = 50;67}68//frame_system::Module<Test>;69impl pallet_balances::Config for Test {70	type AccountStore = System;71	type Balance = u64;72	type DustRemoval = ();73	type Event = ();74	type ExistentialDeposit = ExistentialDeposit;75	type WeightInfo = ();76	type MaxLocks = MaxLocks;77	type MaxReserves = ();78	type ReserveIdentifier = [u8; 8];79}8081parameter_types! {82	pub const TransactionByteFee: u64 = 1;83	pub const OperationalFeeMultiplier: u8 = 5;84}8586impl pallet_transaction_payment::Config for Test {87	type OnChargeTransaction = CurrencyAdapter<pallet_balances::Pallet<Test>, ()>;88	type TransactionByteFee = TransactionByteFee;89	type WeightToFee = IdentityFee<u64>;90	type FeeMultiplierUpdate = ();91	type OperationalFeeMultiplier = OperationalFeeMultiplier;92}9394parameter_types! {95	pub const MinimumPeriod: u64 = 1;96}97impl pallet_timestamp::Config for Test {98	type Moment = u64;99	type OnTimestampSet = ();100	type MinimumPeriod = MinimumPeriod;101	type WeightInfo = ();102}103104parameter_types! {105	pub const CollectionCreationPrice: u32 = 0;106	pub TreasuryAccountId: u64 = 1234;107	pub EthereumChainId: u32 = 1111;108}109110pub struct TestEvmAddressMapping;111impl AddressMapping<u64> for TestEvmAddressMapping {112	fn into_account_id(_addr: sp_core::H160) -> u64 {113		unimplemented!()114	}115}116117pub struct TestEvmBackwardsAddressMapping;118impl EvmBackwardsAddressMapping<u64> for TestEvmBackwardsAddressMapping {119	fn from_account_id(_account_id: u64) -> sp_core::H160 {120		unimplemented!()121	}122}123124#[derive(Encode, Decode, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, TypeInfo)]125pub struct TestCrossAccountId(u64, sp_core::H160);126impl CrossAccountId<u64> for TestCrossAccountId {127	fn from_sub(sub: u64) -> Self {128		let mut eth = [0; 20];129		eth[12..20].copy_from_slice(&sub.to_be_bytes());130		Self(sub, sp_core::H160(eth))131	}132	fn as_sub(&self) -> &u64 {133		&self.0134	}135	fn from_eth(eth: sp_core::H160) -> Self {136		let mut sub_raw = [0; 8];137		sub_raw.copy_from_slice(&eth.0[0..8]);138		let sub = u64::from_be_bytes(sub_raw);139		Self(sub, eth)140	}141	fn as_eth(&self) -> &sp_core::H160 {142		&self.1143	}144}145146pub struct TestEtheremTransactionSender;147impl pallet_ethereum::EthereumTransactionSender for TestEtheremTransactionSender {148	fn submit_logs_transaction(149		_tx: pallet_ethereum::Transaction,150		_logs: Vec<pallet_ethereum::Log>,151	) -> Result<(), sp_runtime::DispatchError> {152		Ok(())153	}154}155156impl pallet_evm_coder_substrate::Config for Test {157	type EthereumTransactionSender = TestEtheremTransactionSender;158}159160impl pallet_template::Config for Test {161	type Event = ();162	type WeightInfo = ();163	type CollectionCreationPrice = CollectionCreationPrice;164	type Currency = pallet_balances::Pallet<Test>;165	type TreasuryAccountId = TreasuryAccountId;166	type EvmAddressMapping = TestEvmAddressMapping;167	type EvmBackwardsAddressMapping = TestEvmBackwardsAddressMapping;168	type CrossAccountId = TestCrossAccountId;169}170171// Build genesis storage according to the mock runtime.172pub fn new_test_ext() -> sp_io::TestExternalities {173	system::GenesisConfig::default()174		.build_storage::<Test>()175		.unwrap()176		.into()177}