From 5a4a5b78ed0e3dbbe6449e330964502b2175f273 Mon Sep 17 00:00:00 2001 From: str-mv Date: Tue, 09 Mar 2021 11:51:38 +0000 Subject: [PATCH] Unit tests fix --- --- a/pallets/nft/src/mock.rs +++ b/pallets/nft/src/mock.rs @@ -1,43 +1,44 @@ -// Creating mock runtime here - -use crate::{Module, Config}; - -use frame_support::{ - impl_outer_origin, parameter_types, - weights::{Weight, IdentityFee}, +use crate as pallet_template; +use sp_core::H256; +use frame_support::{ + parameter_types, + weights::IdentityFee, }; -use frame_system as system; -use system::limits::{BlockLength, BlockWeights}; -use transaction_payment::{self, CurrencyAdapter}; -use sp_core::H256; use sp_runtime::{ - testing::Header, - traits::{BlakeTwo256, IdentityLookup}, - Perbill, + traits::{BlakeTwo256, IdentityLookup}, + testing::Header, + Perbill, }; -use pallet_contracts::WeightInfo; -pub use pallet_balances; +use pallet_transaction_payment::{ CurrencyAdapter}; +use frame_system as system; + +type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; +type Block = frame_system::mocking::MockBlock; -impl_outer_origin! { - pub enum Origin for Test {} -} +// Configure a mock runtime to test the pallet. +frame_support::construct_runtime!( + pub enum Test where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic, + { + System: frame_system::{Module, Call, Config, Storage, Event}, + TemplateModule: pallet_template::{Module, Call, Storage}, + } +); -// For testing the pallet, we construct most of a mock runtime. This means -// first constructing a configuration type (`Test`) which `impl`s each of the -// configuration traits of pallets we want to use. -#[derive(Clone, Eq, PartialEq)] -pub struct Test; parameter_types! { - pub const BlockHashCount: u64 = 250; - pub TestBlockWeights: BlockWeights = BlockWeights::default(); - pub TestBlockLength: BlockLength = BlockLength::default(); - pub SS58Prefix: u8 = 0; + pub const BlockHashCount: u64 = 250; + pub const SS58Prefix: u8 = 42; } impl system::Config for Test { type BaseCallFilter = (); + type BlockWeights = (); + type BlockLength = (); + type DbWeight = (); type Origin = Origin; - type Call = (); + type Call = Call; type Index = u64; type BlockNumber = u64; type Hash = H256; @@ -47,24 +48,20 @@ type Header = Header; type Event = (); type BlockHashCount = BlockHashCount; - type BlockWeights = TestBlockWeights; - type DbWeight = (); - type BlockLength = TestBlockLength; type Version = (); - type PalletInfo = (); + type PalletInfo = PalletInfo; type AccountData = pallet_balances::AccountData; type OnNewAccount = (); type OnKilledAccount = (); - type SS58Prefix = SS58Prefix; type SystemWeightInfo = (); + type SS58Prefix = SS58Prefix; } parameter_types! { pub const ExistentialDeposit: u64 = 1; pub const MaxLocks: u32 = 50; } - -type System = frame_system::Module; +//frame_system::Module; impl pallet_balances::Config for Test { type AccountStore = System; type Balance = u64; @@ -79,13 +76,12 @@ pub const TransactionByteFee: u64 = 1; } -impl transaction_payment::Config for Test { +impl pallet_transaction_payment::Config for Test { type OnChargeTransaction = CurrencyAdapter, ()>; type TransactionByteFee = TransactionByteFee; type WeightToFee = IdentityFee; type FeeMultiplierUpdate = (); } - parameter_types! { pub const MinimumPeriod: u64 = 1; @@ -110,12 +106,8 @@ pub const SignedClaimHandicap: u32 = 2; pub const MaxDepth: u32 = 32; pub const MaxValueSize: u32 = 16 * 1024; - pub DeletionWeightLimit: Weight = Perbill::from_percent(10) * - TestBlockWeights::get().max_block; - pub DeletionQueueDepth: u32 = ((DeletionWeightLimit::get() / ( - ::WeightInfo::on_initialize_per_queue_item(1) - - ::WeightInfo::on_initialize_per_queue_item(0) - )) / 5) as u32; + pub DeletionWeightLimit: u64 = u64::MAX;//Perbill::from_percent(10); + pub DeletionQueueDepth: u32 = 10; } impl pallet_contracts::Config for Test { @@ -136,23 +128,17 @@ type DeletionQueueDepth = DeletionQueueDepth; type MaxValueSize = MaxValueSize; type ChainExtension = (); + type MaxCodeSize = (); type WeightPrice = (); type WeightInfo = pallet_contracts::weights::SubstrateWeight; } -impl Config for Test { +impl pallet_template::Config for Test { type Event = (); type WeightInfo = (); - } -pub type TemplateModule = Module; - -// This function basically just builds a genesis storage key/value store according to -// our desired mockup. +// Build genesis storage according to the mock runtime. pub fn new_test_ext() -> sp_io::TestExternalities { - system::GenesisConfig::default() - .build_storage::() - .unwrap() - .into() -} + system::GenesisConfig::default().build_storage::().unwrap().into() +} \ No newline at end of file -- gitstuff