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

difftreelog

source

pallets/nft/src/mock.rs5.9 KiBsourcehistory
1use crate as pallet_template;2use sp_core::H256;3use frame_support::{ 4	parameter_types,5	weights::IdentityFee,6};7use sp_runtime::{8	traits::{BlakeTwo256, IdentityLookup}, 9	testing::Header, 10	Perbill,11};12use pallet_transaction_payment::{ CurrencyAdapter};13use frame_system as system;14use pallet_evm::AddressMapping;15use crate::{EvmBackwardsAddressMapping, CrossAccountId};16use codec::{Encode, Decode};1718type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;19type Block = frame_system::mocking::MockBlock<Test>; 2021// Configure a mock runtime to test the pallet.22frame_support::construct_runtime!(23	pub enum Test where24		Block = Block,25		NodeBlock = Block,26		UncheckedExtrinsic = UncheckedExtrinsic,27	{28		System: frame_system::{Pallet, Call, Config, Storage, Event<T>},29		TemplateModule: pallet_template::{Pallet, Call, Storage},30		Balances: pallet_balances::{Pallet, Call, Storage},31	}32);3334parameter_types! {35	pub const BlockHashCount: u64 = 250;36	pub const SS58Prefix: u8 = 42;37}3839impl system::Config for Test {40	type BaseCallFilter = ();41	type BlockWeights = ();42	type BlockLength = ();43	type DbWeight = ();44	type Origin = Origin;45	type Call = Call;46	type Index = u64;47	type BlockNumber = u64;48	type Hash = H256;49	type Hashing = BlakeTwo256;50	type AccountId = u64;51	type Lookup = IdentityLookup<Self::AccountId>;52	type Header = Header;53	type Event = ();54	type BlockHashCount = BlockHashCount;55	type Version = ();56	type PalletInfo = PalletInfo;57	type AccountData = pallet_balances::AccountData<u64>;58	type OnNewAccount = ();59	type OnKilledAccount = ();60	type SystemWeightInfo = ();61	type SS58Prefix = SS58Prefix;62    type OnSetCode = ();63}6465parameter_types! {66	pub const ExistentialDeposit: u64 = 1;67	pub const MaxLocks: u32 = 50;68}69//frame_system::Module<Test>;70impl pallet_balances::Config for Test {71    type AccountStore = System;72    type Balance = u64;73    type DustRemoval = ();74    type Event = ();75	type ExistentialDeposit = ExistentialDeposit;76	type WeightInfo = ();77	type MaxLocks = MaxLocks;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}100101type Timestamp = pallet_timestamp::Pallet<Test>;102type Randomness = pallet_randomness_collective_flip::Pallet<Test>;103104parameter_types! {105	pub const TombstoneDeposit: u64 = 1;106	pub const DepositPerContract: u64 = 1;107	pub const DepositPerStorageByte: u64 = 1;108	pub const DepositPerStorageItem: u64 = 1;109	pub RentFraction: Perbill = Perbill::from_rational(1u32, 30 * 24 * 60 * 10);110	pub const SurchargeReward: u64 = 1;111	pub const SignedClaimHandicap: u32 = 2;112	pub DeletionWeightLimit: u64 = u64::MAX;//Perbill::from_percent(10);113	pub DeletionQueueDepth: u32 = 10;114	pub Schedule: pallet_contracts::Schedule<Test> = Default::default();115}116117impl pallet_contracts::Config for Test {118	type Time = Timestamp;119	type Randomness = Randomness;120	type Currency = pallet_balances::Pallet<Test>;121	type Event = ();122	type RentPayment = ();123	type SignedClaimHandicap = SignedClaimHandicap;124	type TombstoneDeposit = TombstoneDeposit;125	type DepositPerContract = DepositPerContract;126	type DepositPerStorageByte = DepositPerStorageByte;127	type DepositPerStorageItem = DepositPerStorageItem;128	type RentFraction = RentFraction;129	type SurchargeReward = SurchargeReward;130	type DeletionWeightLimit = DeletionWeightLimit;131	type DeletionQueueDepth = DeletionQueueDepth;132	type ChainExtension = ();133	type WeightPrice = ();134	type WeightInfo = pallet_contracts::weights::SubstrateWeight<Self>;135    type Schedule = Schedule;136    type CallStack = [pallet_contracts::Frame<Self>; 31];137}138139parameter_types! {140	pub const CollectionCreationPrice: u32 = 0;141    pub TreasuryAccountId: u64 = 1234;142    pub EthereumChainId: u32 = 1111;143}144145pub struct TestEvmAddressMapping;146impl AddressMapping<u64> for TestEvmAddressMapping {147    fn into_account_id(addr: sp_core::H160) -> u64 {148        unimplemented!()149    }150}151152pub struct TestEvmBackwardsAddressMapping;153impl EvmBackwardsAddressMapping<u64> for TestEvmBackwardsAddressMapping {154    fn from_account_id(account_id: u64) -> sp_core::H160 {155        unimplemented!()156    }157}158159#[derive(Encode, Decode, Clone, PartialEq, Eq, PartialOrd, Ord, Debug)]160pub struct TestCrossAccountId(u64, sp_core::H160);161impl CrossAccountId<u64> for TestCrossAccountId {162    fn from_sub(sub: u64) -> Self {163        let mut eth = [0; 20];164        eth[12..20].copy_from_slice(&sub.to_be_bytes());165        Self(sub, sp_core::H160(eth))166    }167    fn as_sub(&self) -> &u64 {168        &self.0169    }170    fn from_eth(eth: sp_core::H160) -> Self {171        unimplemented!()172    }173    fn as_eth(&self) -> &sp_core::H160 {174        &self.1175    }176}177178pub struct TestEtheremTransactionSender;179impl pallet_ethereum::EthereumTransactionSender for TestEtheremTransactionSender {180    fn submit_logs_transaction(tx: pallet_ethereum::Transaction, logs: Vec<pallet_ethereum::Log>) -> Result<(), sp_runtime::DispatchError> {181        Ok(())182    }183}184185impl pallet_template::Config for Test {186	type Event = ();187	type WeightInfo = ();188	type CollectionCreationPrice = CollectionCreationPrice;189    type Currency = pallet_balances::Pallet<Test>;190    type TreasuryAccountId = TreasuryAccountId;191    type EvmAddressMapping = TestEvmAddressMapping;192    type EvmBackwardsAddressMapping = TestEvmBackwardsAddressMapping;193    type CrossAccountId = TestCrossAccountId;194    type EthereumChainId = EthereumChainId;195    type EthereumTransactionSender = TestEtheremTransactionSender;196}197198// Build genesis storage according to the mock runtime.199pub fn new_test_ext() -> sp_io::TestExternalities {200	system::GenesisConfig::default().build_storage::<Test>().unwrap().into()201}