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

difftreelog

source

pallets/unique/src/mock.rs5.3 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		Common: pallet_common::{Pallet, Storage, Event<T>},31		Fungible: pallet_fungible::{Pallet, Storage},32		Refungible: pallet_refungible::{Pallet, Storage},33		Nonfungible: pallet_nonfungible::{Pallet, Storage},34	}35);3637parameter_types! {38	pub const BlockHashCount: u64 = 250;39	pub const SS58Prefix: u8 = 42;40}4142impl system::Config for Test {43	type BaseCallFilter = Everything;44	type BlockWeights = ();45	type BlockLength = ();46	type DbWeight = ();47	type Origin = Origin;48	type Call = Call;49	type Index = u64;50	type BlockNumber = u64;51	type Hash = H256;52	type Hashing = BlakeTwo256;53	type AccountId = u64;54	type Lookup = IdentityLookup<Self::AccountId>;55	type Header = Header;56	type Event = ();57	type BlockHashCount = BlockHashCount;58	type Version = ();59	type PalletInfo = PalletInfo;60	type AccountData = pallet_balances::AccountData<u64>;61	type OnNewAccount = ();62	type OnKilledAccount = ();63	type SystemWeightInfo = ();64	type SS58Prefix = SS58Prefix;65	type OnSetCode = ();66}6768parameter_types! {69	pub const ExistentialDeposit: u64 = 1;70	pub const MaxLocks: u32 = 50;71}72//frame_system::Module<Test>;73impl pallet_balances::Config for Test {74	type AccountStore = System;75	type Balance = u64;76	type DustRemoval = ();77	type Event = ();78	type ExistentialDeposit = ExistentialDeposit;79	type WeightInfo = ();80	type MaxLocks = MaxLocks;81	type MaxReserves = ();82	type ReserveIdentifier = [u8; 8];83}8485parameter_types! {86	pub const TransactionByteFee: u64 = 1;87	pub const OperationalFeeMultiplier: u8 = 5;88}8990impl pallet_transaction_payment::Config for Test {91	type OnChargeTransaction = CurrencyAdapter<pallet_balances::Pallet<Test>, ()>;92	type TransactionByteFee = TransactionByteFee;93	type WeightToFee = IdentityFee<u64>;94	type FeeMultiplierUpdate = ();95	type OperationalFeeMultiplier = OperationalFeeMultiplier;96}9798parameter_types! {99	pub const MinimumPeriod: u64 = 1;100}101impl pallet_timestamp::Config for Test {102	type Moment = u64;103	type OnTimestampSet = ();104	type MinimumPeriod = MinimumPeriod;105	type WeightInfo = ();106}107108parameter_types! {109	pub const CollectionCreationPrice: u32 = 0;110	pub TreasuryAccountId: u64 = 1234;111	pub EthereumChainId: u32 = 1111;112}113114pub struct TestEvmAddressMapping;115impl AddressMapping<u64> for TestEvmAddressMapping {116	fn into_account_id(_addr: sp_core::H160) -> u64 {117		unimplemented!()118	}119}120121pub struct TestEvmBackwardsAddressMapping;122impl EvmBackwardsAddressMapping<u64> for TestEvmBackwardsAddressMapping {123	fn from_account_id(_account_id: u64) -> sp_core::H160 {124		unimplemented!()125	}126}127128#[derive(Encode, Decode, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, TypeInfo)]129pub struct TestCrossAccountId(u64, sp_core::H160);130impl CrossAccountId<u64> for TestCrossAccountId {131	fn as_sub(&self) -> &u64 {132		&self.0133	}134	fn as_eth(&self) -> &sp_core::H160 {135		&self.1136	}137	fn from_sub(sub: u64) -> Self {138		let mut eth = [0; 20];139		eth[12..20].copy_from_slice(&sub.to_be_bytes());140		Self(sub, sp_core::H160(eth))141	}142	fn from_eth(eth: sp_core::H160) -> Self {143		let mut sub_raw = [0; 8];144		sub_raw.copy_from_slice(&eth.0[0..8]);145		let sub = u64::from_be_bytes(sub_raw);146		Self(sub, eth)147	}148	fn conv_eq(&self, other: &Self) -> bool {149		self.as_sub() == other.as_sub()150	}151}152153impl Default for TestCrossAccountId {154	fn default() -> Self {155		Self::from_sub(0)156	}157}158159pub struct TestEtheremTransactionSender;160impl pallet_ethereum::EthereumTransactionSender for TestEtheremTransactionSender {161	fn submit_logs_transaction(162		_tx: pallet_ethereum::Transaction,163		_logs: Vec<pallet_ethereum::Log>,164	) -> Result<(), sp_runtime::DispatchError> {165		Ok(())166	}167}168169impl pallet_evm_coder_substrate::Config for Test {170	type EthereumTransactionSender = TestEtheremTransactionSender;171}172173impl pallet_common::Config for Test {174	type Event = ();175	type EvmBackwardsAddressMapping = TestEvmBackwardsAddressMapping;176	type EvmAddressMapping = TestEvmAddressMapping;177	type CrossAccountId = TestCrossAccountId;178179	type Currency = Balances;180	type CollectionCreationPrice = CollectionCreationPrice;181	type TreasuryAccountId = TreasuryAccountId;182}183184impl pallet_fungible::Config for Test {185	type WeightInfo = ();186}187impl pallet_refungible::Config for Test {188	type WeightInfo = ();189}190impl pallet_nonfungible::Config for Test {191	type WeightInfo = ();192}193194impl pallet_template::Config for Test {195	type WeightInfo = ();196}197198// Build genesis storage according to the mock runtime.199pub fn new_test_ext() -> sp_io::TestExternalities {200	system::GenesisConfig::default()201		.build_storage::<Test>()202		.unwrap()203		.into()204}