difftreelog
Unit tests fix
in: master
1 file changed
pallets/nft/src/mock.rsdiffbeforeafterboth1// Creating mock runtime here23use crate::{Module, Config};1use crate as pallet_template;42use sp_core::H256;5use frame_support::{3use frame_support::{ 6 impl_outer_origin, parameter_types,4 parameter_types,7 weights::{Weight, IdentityFee},5 weights::IdentityFee,8};6};9use frame_system as system;10use system::limits::{BlockLength, BlockWeights};7use sp_runtime::{8 traits::{BlakeTwo256, IdentityLookup}, 9 testing::Header, 10 Perbill,11};11use transaction_payment::{self, CurrencyAdapter};12use pallet_transaction_payment::{ CurrencyAdapter};12use sp_core::H256;13use frame_system as system;13use sp_runtime::{1414 testing::Header,15type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;15 traits::{BlakeTwo256, IdentityLookup},16 Perbill,17};18use pallet_contracts::WeightInfo;16type Block = frame_system::mocking::MockBlock<Test>; 19pub use pallet_balances;172018// Configure a mock runtime to test the pallet.21impl_outer_origin! {19frame_support::construct_runtime!(22 pub enum Origin for Test {}20 pub enum Test where23}21 Block = Block,2422 NodeBlock = Block,25// For testing the pallet, we construct most of a mock runtime. This means23 UncheckedExtrinsic = UncheckedExtrinsic,26// first constructing a configuration type (`Test`) which `impl`s each of the24 {27// configuration traits of pallets we want to use.25 System: frame_system::{Module, Call, Config, Storage, Event<T>},28#[derive(Clone, Eq, PartialEq)]26 TemplateModule: pallet_template::{Module, Call, Storage},27 }29pub struct Test;28);2930parameter_types! {30parameter_types! {31 pub const BlockHashCount: u64 = 250;31 pub const BlockHashCount: u64 = 250;32 pub TestBlockWeights: BlockWeights = BlockWeights::default();33 pub TestBlockLength: BlockLength = BlockLength::default();34 pub SS58Prefix: u8 = 0;32 pub const SS58Prefix: u8 = 42;35}33}363437impl system::Config for Test {35impl system::Config for Test {38 type BaseCallFilter = ();36 type BaseCallFilter = ();37 type BlockWeights = ();38 type BlockLength = ();39 type DbWeight = ();39 type Origin = Origin;40 type Origin = Origin;40 type Call = ();41 type Call = Call;41 type Index = u64;42 type Index = u64;42 type BlockNumber = u64;43 type BlockNumber = u64;43 type Hash = H256;44 type Hash = H256;47 type Header = Header;48 type Header = Header;48 type Event = ();49 type Event = ();49 type BlockHashCount = BlockHashCount;50 type BlockHashCount = BlockHashCount;50 type BlockWeights = TestBlockWeights;51 type DbWeight = ();52 type BlockLength = TestBlockLength;53 type Version = ();51 type Version = ();54 type PalletInfo = ();52 type PalletInfo = PalletInfo;55 type AccountData = pallet_balances::AccountData<u64>;53 type AccountData = pallet_balances::AccountData<u64>;56 type OnNewAccount = ();54 type OnNewAccount = ();57 type OnKilledAccount = ();55 type OnKilledAccount = ();58 type SS58Prefix = SS58Prefix;56 type SystemWeightInfo = ();59 type SystemWeightInfo = ();57 type SS58Prefix = SS58Prefix;60}58}615962parameter_types! {60parameter_types! {63 pub const ExistentialDeposit: u64 = 1;61 pub const ExistentialDeposit: u64 = 1;64 pub const MaxLocks: u32 = 50;62 pub const MaxLocks: u32 = 50;65}63}6664//frame_system::Module<Test>;67type System = frame_system::Module<Test>;68impl pallet_balances::Config for Test {65impl pallet_balances::Config for Test {69 type AccountStore = System;66 type AccountStore = System;70 type Balance = u64;67 type Balance = u64;79 pub const TransactionByteFee: u64 = 1;76 pub const TransactionByteFee: u64 = 1;80}77}817882impl transaction_payment::Config for Test {79impl pallet_transaction_payment::Config for Test {83 type OnChargeTransaction = CurrencyAdapter<pallet_balances::Module<Test>, ()>;80 type OnChargeTransaction = CurrencyAdapter<pallet_balances::Module<Test>, ()>;84 type TransactionByteFee = TransactionByteFee;81 type TransactionByteFee = TransactionByteFee;85 type WeightToFee = IdentityFee<u64>;82 type WeightToFee = IdentityFee<u64>;110 pub const SignedClaimHandicap: u32 = 2;106 pub const SignedClaimHandicap: u32 = 2;111 pub const MaxDepth: u32 = 32;107 pub const MaxDepth: u32 = 32;112 pub const MaxValueSize: u32 = 16 * 1024;108 pub const MaxValueSize: u32 = 16 * 1024;113 pub DeletionWeightLimit: Weight = Perbill::from_percent(10) *109 pub DeletionWeightLimit: u64 = u64::MAX;//Perbill::from_percent(10);114 TestBlockWeights::get().max_block;115 pub DeletionQueueDepth: u32 = ((DeletionWeightLimit::get() / (110 pub DeletionQueueDepth: u32 = 10;116 <Test as pallet_contracts::Config>::WeightInfo::on_initialize_per_queue_item(1) -117 <Test as pallet_contracts::Config>::WeightInfo::on_initialize_per_queue_item(0)118 )) / 5) as u32;119}111}120112121impl pallet_contracts::Config for Test {113impl pallet_contracts::Config for Test {136 type DeletionQueueDepth = DeletionQueueDepth;128 type DeletionQueueDepth = DeletionQueueDepth;137 type MaxValueSize = MaxValueSize;129 type MaxValueSize = MaxValueSize;138 type ChainExtension = ();130 type ChainExtension = ();131 type MaxCodeSize = ();139 type WeightPrice = ();132 type WeightPrice = ();140 type WeightInfo = pallet_contracts::weights::SubstrateWeight<Self>;133 type WeightInfo = pallet_contracts::weights::SubstrateWeight<Self>;141}134}142135143impl Config for Test {136impl pallet_template::Config for Test {144 type Event = ();137 type Event = ();145 type WeightInfo = ();138 type WeightInfo = ();146147}139}148pub type TemplateModule = Module<Test>;140149141// Build genesis storage according to the mock runtime.150151// This function basically just builds a genesis storage key/value store according to152// our desired mockup.153pub fn new_test_ext() -> sp_io::TestExternalities {142pub fn new_test_ext() -> sp_io::TestExternalities {154 system::GenesisConfig::default()143 system::GenesisConfig::default().build_storage::<Test>().unwrap().into()155 .build_storage::<Test>()