git.delta.rocks / unique-network / refs/commits / 5259d552fbda

difftreelog

source

pallets/nft/src/mock.rs4.5 KiBsourcehistory
1#![allow(clippy::from_over_into)]23use crate as pallet_template;4use sp_core::H256;5use frame_support::{parameter_types, 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};1516type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;17type Block = frame_system::mocking::MockBlock<Test>;1819// Configure a mock runtime to test the pallet.20frame_support::construct_runtime!(21	pub enum Test where22		Block = Block,23		NodeBlock = Block,24		UncheckedExtrinsic = UncheckedExtrinsic,25	{26		System: frame_system::{Pallet, Call, Config, Storage, Event<T>},27		TemplateModule: pallet_template::{Pallet, Call, Storage},28		Balances: pallet_balances::{Pallet, Call, Storage},29	}30);3132parameter_types! {33	pub const BlockHashCount: u64 = 250;34	pub const SS58Prefix: u8 = 42;35}3637impl system::Config for Test {38	type BaseCallFilter = ();39	type BlockWeights = ();40	type BlockLength = ();41	type DbWeight = ();42	type Origin = Origin;43	type Call = Call;44	type Index = u64;45	type BlockNumber = u64;46	type Hash = H256;47	type Hashing = BlakeTwo256;48	type AccountId = u64;49	type Lookup = IdentityLookup<Self::AccountId>;50	type Header = Header;51	type Event = ();52	type BlockHashCount = BlockHashCount;53	type Version = ();54	type PalletInfo = PalletInfo;55	type AccountData = pallet_balances::AccountData<u64>;56	type OnNewAccount = ();57	type OnKilledAccount = ();58	type SystemWeightInfo = ();59	type SS58Prefix = SS58Prefix;60	type OnSetCode = ();61}6263parameter_types! {64	pub const ExistentialDeposit: u64 = 1;65	pub const MaxLocks: u32 = 50;66}67//frame_system::Module<Test>;68impl pallet_balances::Config for Test {69	type AccountStore = System;70	type Balance = u64;71	type DustRemoval = ();72	type Event = ();73	type ExistentialDeposit = ExistentialDeposit;74	type WeightInfo = ();75	type MaxLocks = MaxLocks;76	type MaxReserves = ();77	type ReserveIdentifier = [u8; 8];78}7980parameter_types! {81	pub const TransactionByteFee: u64 = 1;82}8384impl pallet_transaction_payment::Config for Test {85	type OnChargeTransaction = CurrencyAdapter<pallet_balances::Pallet<Test>, ()>;86	type TransactionByteFee = TransactionByteFee;87	type WeightToFee = IdentityFee<u64>;88	type FeeMultiplierUpdate = ();89}9091parameter_types! {92	pub const MinimumPeriod: u64 = 1;93}94impl pallet_timestamp::Config for Test {95	type Moment = u64;96	type OnTimestampSet = ();97	type MinimumPeriod = MinimumPeriod;98	type WeightInfo = ();99}100101parameter_types! {102	pub const CollectionCreationPrice: u32 = 0;103	pub TreasuryAccountId: u64 = 1234;104	pub EthereumChainId: u32 = 1111;105}106107pub struct TestEvmAddressMapping;108impl AddressMapping<u64> for TestEvmAddressMapping {109	fn into_account_id(_addr: sp_core::H160) -> u64 {110		unimplemented!()111	}112}113114pub struct TestEvmBackwardsAddressMapping;115impl EvmBackwardsAddressMapping<u64> for TestEvmBackwardsAddressMapping {116	fn from_account_id(_account_id: u64) -> sp_core::H160 {117		unimplemented!()118	}119}120121#[derive(Encode, Decode, Clone, PartialEq, Eq, PartialOrd, Ord, Debug)]122pub struct TestCrossAccountId(u64, sp_core::H160);123impl CrossAccountId<u64> for TestCrossAccountId {124	fn from_sub(sub: u64) -> Self {125		let mut eth = [0; 20];126		eth[12..20].copy_from_slice(&sub.to_be_bytes());127		Self(sub, sp_core::H160(eth))128	}129	fn as_sub(&self) -> &u64 {130		&self.0131	}132	fn from_eth(_eth: sp_core::H160) -> Self {133		unimplemented!()134	}135	fn as_eth(&self) -> &sp_core::H160 {136		&self.1137	}138}139140pub struct TestEtheremTransactionSender;141impl pallet_ethereum::EthereumTransactionSender for TestEtheremTransactionSender {142	fn submit_logs_transaction(143		_tx: pallet_ethereum::Transaction,144		_logs: Vec<pallet_ethereum::Log>,145	) -> Result<(), sp_runtime::DispatchError> {146		Ok(())147	}148}149150impl pallet_evm_coder_substrate::Config for Test {151	type EthereumTransactionSender = TestEtheremTransactionSender;152}153154impl pallet_template::Config for Test {155	type Event = ();156	type WeightInfo = ();157	type CollectionCreationPrice = CollectionCreationPrice;158	type Currency = pallet_balances::Pallet<Test>;159	type TreasuryAccountId = TreasuryAccountId;160	type EvmAddressMapping = TestEvmAddressMapping;161	type EvmBackwardsAddressMapping = TestEvmBackwardsAddressMapping;162	type CrossAccountId = TestCrossAccountId;163}164165// Build genesis storage according to the mock runtime.166pub fn new_test_ext() -> sp_io::TestExternalities {167	system::GenesisConfig::default()168		.build_storage::<Test>()169		.unwrap()170		.into()171}