git.delta.rocks / unique-network / refs/commits / 5a4a5b78ed0e

difftreelog

Unit tests fix

str-mv2021-03-09parent: #2eedf45.patch.diff
in: master

1 file changed

modifiedpallets/nft/src/mock.rsdiffbeforeafterboth
before · pallets/nft/src/mock.rs
1// Creating mock runtime here23use crate::{Module, Config};45use frame_support::{6    impl_outer_origin, parameter_types,7    weights::{Weight, IdentityFee},8};9use frame_system as system;10use system::limits::{BlockLength, BlockWeights};11use transaction_payment::{self, CurrencyAdapter};12use sp_core::H256;13use sp_runtime::{14    testing::Header,15    traits::{BlakeTwo256, IdentityLookup},16    Perbill,17};18use pallet_contracts::WeightInfo;19pub use pallet_balances;2021impl_outer_origin! {22    pub enum Origin for Test {}23}2425// For testing the pallet, we construct most of a mock runtime. This means26// first constructing a configuration type (`Test`) which `impl`s each of the27// configuration traits of pallets we want to use.28#[derive(Clone, Eq, PartialEq)]29pub struct Test;30parameter_types! {31    pub const BlockHashCount: u64 = 250;32	pub TestBlockWeights: BlockWeights = BlockWeights::default();33	pub TestBlockLength: BlockLength = BlockLength::default();34	pub SS58Prefix: u8 = 0;35}3637impl system::Config for Test {38	type BaseCallFilter = ();39	type Origin = Origin;40	type Call = ();41	type Index = u64;42	type BlockNumber = u64;43	type Hash = H256;44	type Hashing = BlakeTwo256;45	type AccountId = u64;46	type Lookup = IdentityLookup<Self::AccountId>;47	type Header = Header;48	type Event = ();49	type BlockHashCount = BlockHashCount;50	type BlockWeights = TestBlockWeights;51	type DbWeight = ();52	type BlockLength = TestBlockLength;53	type Version = ();54	type PalletInfo = ();55	type AccountData = pallet_balances::AccountData<u64>;56	type OnNewAccount = ();57	type OnKilledAccount = ();58	type SS58Prefix = SS58Prefix;59	type SystemWeightInfo = ();60}6162parameter_types! {63	pub const ExistentialDeposit: u64 = 1;64	pub const MaxLocks: u32 = 50;65}6667type System = 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}7778parameter_types! {79	pub const TransactionByteFee: u64 = 1;80}8182impl transaction_payment::Config for Test {83	type OnChargeTransaction = CurrencyAdapter<pallet_balances::Module<Test>, ()>;84	type TransactionByteFee = TransactionByteFee;85	type WeightToFee = IdentityFee<u64>;86	type FeeMultiplierUpdate = ();87}888990parameter_types! {91	pub const MinimumPeriod: u64 = 1;92}93impl pallet_timestamp::Config for Test {94	type Moment = u64;95	type OnTimestampSet = ();96	type MinimumPeriod = MinimumPeriod;97	type WeightInfo = ();98}99100type Timestamp = pallet_timestamp::Module<Test>;101type Randomness = pallet_randomness_collective_flip::Module<Test>;102103parameter_types! {104	pub const TombstoneDeposit: u64 = 1;105	pub const DepositPerContract: u64 = 1;106	pub const DepositPerStorageByte: u64 = 1;107	pub const DepositPerStorageItem: u64 = 1;108	pub RentFraction: Perbill = Perbill::from_rational_approximation(1u32, 30 * 24 * 60 * 10);109	pub const SurchargeReward: u64 = 1;110	pub const SignedClaimHandicap: u32 = 2;111	pub const MaxDepth: u32 = 32;112	pub const MaxValueSize: u32 = 16 * 1024;113	pub DeletionWeightLimit: Weight = Perbill::from_percent(10) *114		TestBlockWeights::get().max_block;115	pub DeletionQueueDepth: u32 = ((DeletionWeightLimit::get() / (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}120121impl pallet_contracts::Config for Test {122	type Time = Timestamp;123	type Randomness = Randomness;124	type Currency = pallet_balances::Module<Test>;125	type Event = ();126	type RentPayment = ();127	type SignedClaimHandicap = SignedClaimHandicap;128	type TombstoneDeposit = TombstoneDeposit;129	type DepositPerContract = DepositPerContract;130	type DepositPerStorageByte = DepositPerStorageByte;131	type DepositPerStorageItem = DepositPerStorageItem;132	type RentFraction = RentFraction;133	type SurchargeReward = SurchargeReward;134	type DeletionWeightLimit = DeletionWeightLimit;135	type MaxDepth = MaxDepth;136	type DeletionQueueDepth = DeletionQueueDepth;137	type MaxValueSize = MaxValueSize;138	type ChainExtension = ();139	type WeightPrice = ();140	type WeightInfo = pallet_contracts::weights::SubstrateWeight<Self>;141}142143impl Config for Test {144	type Event = ();145	type WeightInfo = ();146147}148pub type TemplateModule = Module<Test>;149150151// This function basically just builds a genesis storage key/value store according to152// our desired mockup.153pub fn new_test_ext() -> sp_io::TestExternalities {154    system::GenesisConfig::default()155        .build_storage::<Test>()156        .unwrap()157        .into()158}
after · pallets/nft/src/mock.rs
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;1415type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;16type Block = frame_system::mocking::MockBlock<Test>; 1718// Configure a mock runtime to test the pallet.19frame_support::construct_runtime!(20	pub enum Test where21		Block = Block,22		NodeBlock = Block,23		UncheckedExtrinsic = UncheckedExtrinsic,24	{25		System: frame_system::{Module, Call, Config, Storage, Event<T>},26		TemplateModule: pallet_template::{Module, Call, Storage},27	}28);2930parameter_types! {31	pub const BlockHashCount: u64 = 250;32	pub const SS58Prefix: u8 = 42;33}3435impl system::Config for Test {36	type BaseCallFilter = ();37	type BlockWeights = ();38	type BlockLength = ();39	type DbWeight = ();40	type Origin = Origin;41	type Call = Call;42	type Index = u64;43	type BlockNumber = u64;44	type Hash = H256;45	type Hashing = BlakeTwo256;46	type AccountId = u64;47	type Lookup = IdentityLookup<Self::AccountId>;48	type Header = Header;49	type Event = ();50	type BlockHashCount = BlockHashCount;51	type Version = ();52	type PalletInfo = PalletInfo;53	type AccountData = pallet_balances::AccountData<u64>;54	type OnNewAccount = ();55	type OnKilledAccount = ();56	type SystemWeightInfo = ();57	type SS58Prefix = SS58Prefix;58}5960parameter_types! {61	pub const ExistentialDeposit: u64 = 1;62	pub const MaxLocks: u32 = 50;63}64//frame_system::Module<Test>;65impl pallet_balances::Config for Test {66    type AccountStore = System;67    type Balance = u64;68    type DustRemoval = ();69    type Event = ();70	type ExistentialDeposit = ExistentialDeposit;71	type WeightInfo = ();72	type MaxLocks = MaxLocks;73}7475parameter_types! {76	pub const TransactionByteFee: u64 = 1;77}7879impl pallet_transaction_payment::Config for Test {80	type OnChargeTransaction = CurrencyAdapter<pallet_balances::Module<Test>, ()>;81	type TransactionByteFee = TransactionByteFee;82	type WeightToFee = IdentityFee<u64>;83	type FeeMultiplierUpdate = ();84}8586parameter_types! {87	pub const MinimumPeriod: u64 = 1;88}89impl pallet_timestamp::Config for Test {90	type Moment = u64;91	type OnTimestampSet = ();92	type MinimumPeriod = MinimumPeriod;93	type WeightInfo = ();94}9596type Timestamp = pallet_timestamp::Module<Test>;97type Randomness = pallet_randomness_collective_flip::Module<Test>;9899parameter_types! {100	pub const TombstoneDeposit: u64 = 1;101	pub const DepositPerContract: u64 = 1;102	pub const DepositPerStorageByte: u64 = 1;103	pub const DepositPerStorageItem: u64 = 1;104	pub RentFraction: Perbill = Perbill::from_rational_approximation(1u32, 30 * 24 * 60 * 10);105	pub const SurchargeReward: u64 = 1;106	pub const SignedClaimHandicap: u32 = 2;107	pub const MaxDepth: u32 = 32;108	pub const MaxValueSize: u32 = 16 * 1024;109	pub DeletionWeightLimit: u64 = u64::MAX;//Perbill::from_percent(10);110	pub DeletionQueueDepth: u32 = 10;111}112113impl pallet_contracts::Config for Test {114	type Time = Timestamp;115	type Randomness = Randomness;116	type Currency = pallet_balances::Module<Test>;117	type Event = ();118	type RentPayment = ();119	type SignedClaimHandicap = SignedClaimHandicap;120	type TombstoneDeposit = TombstoneDeposit;121	type DepositPerContract = DepositPerContract;122	type DepositPerStorageByte = DepositPerStorageByte;123	type DepositPerStorageItem = DepositPerStorageItem;124	type RentFraction = RentFraction;125	type SurchargeReward = SurchargeReward;126	type DeletionWeightLimit = DeletionWeightLimit;127	type MaxDepth = MaxDepth;128	type DeletionQueueDepth = DeletionQueueDepth;129	type MaxValueSize = MaxValueSize;130	type ChainExtension = ();131	type MaxCodeSize = ();132	type WeightPrice = ();133	type WeightInfo = pallet_contracts::weights::SubstrateWeight<Self>;134}135136impl pallet_template::Config for Test {137	type Event = ();138	type WeightInfo = ();139}140141// Build genesis storage according to the mock runtime.142pub fn new_test_ext() -> sp_io::TestExternalities {143	system::GenesisConfig::default().build_storage::<Test>().unwrap().into()144}