diff --git a/pallets/gear-debug/src/mock.rs b/pallets/gear-debug/src/mock.rs index 49edcaa3a3b..b6507f33b70 100644 --- a/pallets/gear-debug/src/mock.rs +++ b/pallets/gear-debug/src/mock.rs @@ -71,32 +71,6 @@ parameter_types! { pub ReserveThreshold: BlockNumber = 1; } -impl pallet_gear::Config for Test { - type RuntimeEvent = RuntimeEvent; - type Randomness = TestRandomness; - type WeightInfo = (); - type OutgoingLimit = OutgoingLimit; - type PerformanceMultiplier = PerformanceMultiplier; - type DebugInfo = super::Pallet; - type Schedule = (); - type CodeStorage = GearProgram; - type ProgramStorage = GearProgram; - type MailboxThreshold = ConstU64<3000>; - type ReservationsLimit = ConstU64<256>; - type Messenger = GearMessenger; - type GasProvider = GearGas; - type BlockLimiter = GearGas; - type Scheduler = GearScheduler; - type QueueRunner = Gear; - type Voucher = (); - type ProgramRentFreePeriod = RentFreePeriod; - type ProgramResumeMinimalRentPeriod = ResumeMinimalPeriod; - type ProgramRentCostPerBlock = RentCostPerBlock; - type ProgramResumeSessionDuration = ResumeSessionDuration; - type ProgramRentEnabled = ConstBool; - type ProgramRentDisabledDelta = RentFreePeriod; -} - // Configure a mock runtime to test the pallet. construct_runtime!( pub enum Test where @@ -126,6 +100,7 @@ pallet_gear_program::impl_config!(Test); pallet_gear_messenger::impl_config!(Test, CurrentBlockNumber = Gear,); pallet_gear_scheduler::impl_config!(Test); pallet_gear_bank::impl_config!(Test); +pallet_gear::impl_config!(Test, DebugInfo = pallet_gear_debug::Pallet, ProgramRentEnabled = ConstBool,); pallet_gear_gas::impl_config!(Test); // Build genesis storage according to the mock runtime. diff --git a/pallets/gear-scheduler/src/mock.rs b/pallets/gear-scheduler/src/mock.rs index c50d894c9d1..ba6b8fa3423 100644 --- a/pallets/gear-scheduler/src/mock.rs +++ b/pallets/gear-scheduler/src/mock.rs @@ -76,6 +76,7 @@ pallet_gear_program::impl_config!(Test); pallet_gear_messenger::impl_config!(Test, CurrentBlockNumber = Gear,); pallet_gear_scheduler::impl_config!(Test); pallet_gear_bank::impl_config!(Test); +pallet_gear::impl_config!(Test, Schedule = GearSchedule,); pallet_gear_gas::impl_config!(Test); parameter_types! { @@ -97,32 +98,6 @@ parameter_types! { pub const GasMultiplier: common::GasMultiplier = common::GasMultiplier::ValuePerGas(25); } -impl pallet_gear::Config for Test { - type RuntimeEvent = RuntimeEvent; - type Randomness = TestRandomness; - type WeightInfo = (); - type Schedule = GearSchedule; - type OutgoingLimit = OutgoingLimit; - type PerformanceMultiplier = PerformanceMultiplier; - type DebugInfo = (); - type CodeStorage = GearProgram; - type ProgramStorage = GearProgram; - type MailboxThreshold = ConstU64<3000>; - type ReservationsLimit = ConstU64<256>; - type Messenger = GearMessenger; - type GasProvider = GearGas; - type BlockLimiter = GearGas; - type Scheduler = GearScheduler; - type QueueRunner = Gear; - type Voucher = (); - type ProgramRentFreePeriod = RentFreePeriod; - type ProgramResumeMinimalRentPeriod = ResumeMinimalPeriod; - type ProgramRentCostPerBlock = RentCostPerBlock; - type ProgramResumeSessionDuration = ResumeSessionDuration; - type ProgramRentEnabled = ConstBool; - type ProgramRentDisabledDelta = RentFreePeriod; -} - // Build genesis storage according to the mock runtime. pub fn new_test_ext() -> sp_io::TestExternalities { let mut t = system::GenesisConfig::default() diff --git a/pallets/gear/src/lib.rs b/pallets/gear/src/lib.rs index 4204074235c..0a173351c35 100644 --- a/pallets/gear/src/lib.rs +++ b/pallets/gear/src/lib.rs @@ -38,6 +38,8 @@ mod mock; #[cfg(test)] mod tests; +pub mod pallet_tests; + pub use crate::{ manager::{ExtManager, HandleKind}, pallet::*, diff --git a/pallets/gear/src/mock.rs b/pallets/gear/src/mock.rs index 1bf63b64552..16e2bbfaee6 100644 --- a/pallets/gear/src/mock.rs +++ b/pallets/gear/src/mock.rs @@ -93,6 +93,7 @@ pallet_gear_program::impl_config!(Test); pallet_gear_messenger::impl_config!(Test, CurrentBlockNumber = Gear,); pallet_gear_scheduler::impl_config!(Test); pallet_gear_bank::impl_config!(Test); +pallet_gear::impl_config!(Test, Schedule = DynamicSchedule, Voucher = GearVoucher,); pallet_gear_gas::impl_config!(Test); common::impl_pallet_balances!(Test); common::impl_pallet_authorship!(Test); @@ -163,32 +164,6 @@ parameter_types! { pub const GasMultiplier: common::GasMultiplier = common::GasMultiplier::ValuePerGas(25); } -impl pallet_gear::Config for Test { - type RuntimeEvent = RuntimeEvent; - type Randomness = TestRandomness; - type WeightInfo = pallet_gear::weights::SubstrateWeight; - type Schedule = DynamicSchedule; - type OutgoingLimit = OutgoingLimit; - type PerformanceMultiplier = PerformanceMultiplier; - type DebugInfo = (); - type CodeStorage = GearProgram; - type ProgramStorage = GearProgram; - type MailboxThreshold = ConstU64<3000>; - type ReservationsLimit = ConstU64<256>; - type Messenger = GearMessenger; - type GasProvider = GearGas; - type BlockLimiter = GearGas; - type Scheduler = GearScheduler; - type QueueRunner = Gear; - type Voucher = GearVoucher; - type ProgramRentFreePeriod = RentFreePeriod; - type ProgramResumeMinimalRentPeriod = ResumeMinimalPeriod; - type ProgramRentCostPerBlock = RentCostPerBlock; - type ProgramResumeSessionDuration = ResumeSessionDuration; - type ProgramRentEnabled = ConstBool; - type ProgramRentDisabledDelta = RentFreePeriod; -} - parameter_types! { pub const VoucherPalletId: PalletId = PalletId(*b"py/vouch"); } diff --git a/pallets/gear/src/pallet_tests.rs b/pallets/gear/src/pallet_tests.rs new file mode 100644 index 00000000000..097fa551570 --- /dev/null +++ b/pallets/gear/src/pallet_tests.rs @@ -0,0 +1,92 @@ +// This file is part of Gear. + +// Copyright (C) 2023 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#[macro_export] +macro_rules! impl_config { + ($( $tokens:tt )*) => { + #[allow(dead_code)] + type GearConfigDebugInfo = (); + #[allow(dead_code)] + type GearConfigVoucher = (); + #[allow(dead_code)] + type GearConfigProgramRentEnabled = ConstBool; + #[allow(dead_code)] + type GearConfigSchedule = (); + + mod pallet_tests_gear_config_impl { + use super::*; + + $crate::impl_config_inner!($( $tokens )*); + } + }; +} + +#[macro_export] +macro_rules! impl_config_inner { + ($runtime:ty$(,)?) => { + impl pallet_gear::Config for $runtime { + type RuntimeEvent = RuntimeEvent; + type Randomness = TestRandomness; + type WeightInfo = pallet_gear::weights::SubstrateWeight; + type Schedule = GearConfigSchedule; + type OutgoingLimit = OutgoingLimit; + type PerformanceMultiplier = PerformanceMultiplier; + type DebugInfo = GearConfigDebugInfo; + type CodeStorage = GearProgram; + type ProgramStorage = GearProgram; + type MailboxThreshold = ConstU64<3_000>; + type ReservationsLimit = ConstU64<256>; + type Messenger = GearMessenger; + type GasProvider = GearGas; + type BlockLimiter = GearGas; + type Scheduler = GearScheduler; + type QueueRunner = Gear; + type Voucher = GearConfigVoucher; + type ProgramRentFreePeriod = RentFreePeriod; + type ProgramResumeMinimalRentPeriod = ResumeMinimalPeriod; + type ProgramRentCostPerBlock = RentCostPerBlock; + type ProgramResumeSessionDuration = ResumeSessionDuration; + type ProgramRentEnabled = GearConfigProgramRentEnabled; + type ProgramRentDisabledDelta = RentFreePeriod; + } + }; + + ($runtime:ty, Schedule = $schedule:ty, $( $rest:tt )*) => { + type GearConfigSchedule = $schedule; + + $crate::impl_config_inner!($runtime, $( $rest )*); + }; + + ($runtime:ty, Voucher = $voucher:ty, $( $rest:tt )*) => { + type GearConfigVoucher = $voucher; + + $crate::impl_config_inner!($runtime, $( $rest )*); + }; + + ($runtime:ty, DebugInfo = $debug_info:ty, $( $rest:tt )*) => { + type GearConfigDebugInfo = $debug_info; + + $crate::impl_config_inner!($runtime, $( $rest )*); + }; + + ($runtime:ty, ProgramRentEnabled = $program_rent_enabled:ty, $( $rest:tt )*) => { + type GearConfigProgramRentEnabled = $program_rent_enabled; + + $crate::impl_config_inner!($runtime, $( $rest )*); + }; +} diff --git a/pallets/payment/src/mock.rs b/pallets/payment/src/mock.rs index e11b0e5cf26..c8c59a2beec 100644 --- a/pallets/payment/src/mock.rs +++ b/pallets/payment/src/mock.rs @@ -76,6 +76,7 @@ construct_runtime!( ); common::impl_pallet_system!(Test, DbWeight = (), BlockWeights = RuntimeBlockWeights,); +pallet_gear::impl_config!(Test, Schedule = GearSchedule,); pallet_gear_gas::impl_config!(Test); common::impl_pallet_balances!(Test); common::impl_pallet_authorship!(Test); @@ -121,32 +122,6 @@ parameter_types! { pub const GasMultiplier: common::GasMultiplier = common::GasMultiplier::ValuePerGas(25); } -impl pallet_gear::Config for Test { - type RuntimeEvent = RuntimeEvent; - type Randomness = TestRandomness; - type WeightInfo = (); - type Schedule = GearSchedule; - type OutgoingLimit = OutgoingLimit; - type PerformanceMultiplier = PerformanceMultiplier; - type DebugInfo = (); - type CodeStorage = GearProgram; - type ProgramStorage = GearProgram; - type MailboxThreshold = ConstU64<3000>; - type ReservationsLimit = ConstU64<256>; - type Messenger = GearMessenger; - type GasProvider = GearGas; - type BlockLimiter = GearGas; - type Scheduler = GearScheduler; - type QueueRunner = Gear; - type Voucher = (); - type ProgramRentFreePeriod = RentFreePeriod; - type ProgramResumeMinimalRentPeriod = ResumeMinimalPeriod; - type ProgramRentCostPerBlock = RentCostPerBlock; - type ProgramResumeSessionDuration = ResumeSessionDuration; - type ProgramRentEnabled = ConstBool; - type ProgramRentDisabledDelta = RentFreePeriod; -} - type NegativeImbalance = >::NegativeImbalance; pub struct DealWithFees;