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

difftreelog

source

pallets/nft/src/mock.rs5.1 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 pallet_common::account::{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 as_sub(&self) -> &u64 {128		&self.0129	}130	fn as_eth(&self) -> &sp_core::H160 {131		&self.1132	}133	fn from_sub(sub: u64) -> Self {134		let mut eth = [0; 20];135		eth[12..20].copy_from_slice(&sub.to_be_bytes());136		Self(sub, sp_core::H160(eth))137	}138	fn from_eth(eth: sp_core::H160) -> Self {139		let mut sub_raw = [0; 8];140		sub_raw.copy_from_slice(&eth.0[0..8]);141		let sub = u64::from_be_bytes(sub_raw);142		Self(sub, eth)143	}144	fn conv_eq(&self, other: &Self) -> bool {145		self.as_sub() == other.as_sub()146	}147}148149impl Default for TestCrossAccountId {150	fn default() -> Self {151		Self::from_sub(0)152	}153}154155156pub struct TestEtheremTransactionSender;157impl pallet_ethereum::EthereumTransactionSender for TestEtheremTransactionSender {158	fn submit_logs_transaction(159		_tx: pallet_ethereum::Transaction,160		_logs: Vec<pallet_ethereum::Log>,161	) -> Result<(), sp_runtime::DispatchError> {162		Ok(())163	}164}165166impl pallet_evm_coder_substrate::Config for Test {167	type EthereumTransactionSender = TestEtheremTransactionSender;168}169170impl pallet_common::Config for Test {171	type Event = ();172	type EvmBackwardsAddressMapping = TestEvmBackwardsAddressMapping;173	type EvmAddressMapping = TestEvmAddressMapping;174	type CrossAccountId = TestCrossAccountId;175176	type Currency = Balances;177	type CollectionCreationPrice = CollectionCreationPrice;178	type TreasuryAccountId = TreasuryAccountId;179}180181impl pallet_fungible::Config for Test {182	type WeightInfo = ();183}184impl pallet_refungible::Config for Test {185	type WeightInfo = ();186}187impl pallet_nonfungible::Config for Test {188	type WeightInfo = ();189}190191impl pallet_template::Config for Test {192	type WeightInfo = ();193}194195// Build genesis storage according to the mock runtime.196pub fn new_test_ext() -> sp_io::TestExternalities {197	system::GenesisConfig::default()198		.build_storage::<Test>()199		.unwrap()200		.into()201}