From 5f1948a09be77e624bf0b44ab7335cac9ab89b77 Mon Sep 17 00:00:00 2001 From: Georgy Shepelev Date: Wed, 8 Nov 2023 09:18:56 +0400 Subject: [PATCH 1/6] chore: Macros to ease Config implementations in pallet tests (#3463) --- Cargo.lock | 1 + common/Cargo.toml | 1 + common/src/lib.rs | 3 + common/src/pallet_tests.rs | 149 +++++++++++++++++++++ pallets/gas/src/lib.rs | 9 ++ pallets/gas/src/mock.rs | 64 ++------- pallets/gear-bank/Cargo.toml | 1 + pallets/gear-bank/src/lib.rs | 11 ++ pallets/gear-bank/src/mock.rs | 73 ++-------- pallets/gear-debug/Cargo.toml | 1 + pallets/gear-debug/src/mock.rs | 136 ++----------------- pallets/gear-messenger/Cargo.toml | 1 + pallets/gear-messenger/src/lib.rs | 2 + pallets/gear-messenger/src/mock.rs | 56 +------- pallets/gear-messenger/src/pallet_tests.rs | 47 +++++++ pallets/gear-program/Cargo.toml | 1 + pallets/gear-program/src/lib.rs | 2 + pallets/gear-program/src/mock.rs | 105 ++------------- pallets/gear-program/src/pallet_tests.rs | 27 ++++ pallets/gear-scheduler/Cargo.toml | 1 + pallets/gear-scheduler/src/lib.rs | 14 ++ pallets/gear-scheduler/src/mock.rs | 137 ++----------------- pallets/gear-voucher/Cargo.toml | 1 + pallets/gear-voucher/src/mock.rs | 45 +------ pallets/gear/Cargo.toml | 1 + pallets/gear/src/lib.rs | 2 + pallets/gear/src/mock.rs | 142 ++------------------ pallets/gear/src/pallet_tests.rs | 92 +++++++++++++ pallets/payment/Cargo.toml | 1 + pallets/payment/src/mock.rs | 138 ++----------------- pallets/staking-rewards/Cargo.toml | 1 + pallets/staking-rewards/src/mock.rs | 81 ++--------- 32 files changed, 470 insertions(+), 876 deletions(-) create mode 100644 common/src/pallet_tests.rs create mode 100644 pallets/gear-messenger/src/pallet_tests.rs create mode 100644 pallets/gear-program/src/pallet_tests.rs create mode 100644 pallets/gear/src/pallet_tests.rs diff --git a/Cargo.lock b/Cargo.lock index 6a8d750bd2d..2798fd5a74f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7809,6 +7809,7 @@ dependencies = [ "frame-executive", "frame-support", "frame-system", + "gear-common", "impl-trait-for-tuples", "log", "pallet-authorship", diff --git a/common/Cargo.toml b/common/Cargo.toml index 7bdfcb6a03c..e5b5cbbc57f 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -45,6 +45,7 @@ std = [ "sp-io/std", "sp-arithmetic/std", "frame-support/std", + "frame-system/std", "primitive-types/std", "gear-wasm-instrument?/std", ] diff --git a/common/src/lib.rs b/common/src/lib.rs index 6f295e18115..0f700e56d72 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -39,6 +39,9 @@ pub mod gas_provider; #[cfg(feature = "runtime-benchmarks")] pub mod benchmarking; +#[cfg(feature = "std")] +pub mod pallet_tests; + use core::fmt; use frame_support::{ codec::{self, Decode, Encode}, diff --git a/common/src/pallet_tests.rs b/common/src/pallet_tests.rs new file mode 100644 index 00000000000..f58e8844998 --- /dev/null +++ b/common/src/pallet_tests.rs @@ -0,0 +1,149 @@ +// 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 . + +//! Module contains macros that help to implement Config type +//! for various pallets of Substrate. +//! All used types should be in scope. + +use frame_support::{pallet_prelude::*, weights::RuntimeDbWeight}; +use frame_system::limits::BlockWeights; +use sp_arithmetic::Perbill; + +#[macro_export] +macro_rules! impl_pallet_balances { + ($runtime:ty) => { + impl pallet_balances::Config for $runtime { + type MaxLocks = (); + type MaxReserves = (); + type ReserveIdentifier = [u8; 8]; + type Balance = Balance; + type DustRemoval = (); + type RuntimeEvent = RuntimeEvent; + type ExistentialDeposit = ExistentialDeposit; + type AccountStore = System; + type WeightInfo = (); + } + }; +} + +pub const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75); +pub const MAX_BLOCK: u64 = 250_000_000_000; + +frame_support::parameter_types! { + pub RuntimeBlockWeights: BlockWeights = BlockWeights::with_sensible_defaults( + Weight::from_parts(MAX_BLOCK, u64::MAX), + NORMAL_DISPATCH_RATIO, + ); + pub const SS58Prefix: u8 = 42; + pub const DbWeight: RuntimeDbWeight = RuntimeDbWeight { read: 1_110, write: 2_300 }; + pub const MinimumPeriod: u64 = 500; +} + +#[macro_export] +macro_rules! impl_pallet_system { + ($( $tokens:tt )*) => { + #[allow(dead_code)] + type SystemConfigDbWeight = $crate::pallet_tests::DbWeight; + #[allow(dead_code)] + type SystemConfigBlockWeights = $crate::pallet_tests::RuntimeBlockWeights; + + mod pallet_tests_system_config_impl { + use super::*; + + $crate::impl_pallet_system_inner!($( $tokens )*); + } + }; +} + +#[macro_export] +macro_rules! impl_pallet_system_inner { + ($runtime:ty$(,)?) => { + impl frame_system::Config for $runtime { + type BaseCallFilter = frame_support::traits::Everything; + type BlockWeights = SystemConfigBlockWeights; + type BlockLength = (); + type DbWeight = SystemConfigDbWeight; + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; + type Index = u64; + type BlockNumber = BlockNumber; + type Hash = H256; + type Hashing = BlakeTwo256; + type AccountId = AccountId; + type Lookup = IdentityLookup; + type Header = generic::Header; + type RuntimeEvent = RuntimeEvent; + type BlockHashCount = BlockHashCount; + type Version = (); + type PalletInfo = PalletInfo; + type AccountData = pallet_balances::AccountData; + type OnNewAccount = (); + type OnKilledAccount = (); + type SystemWeightInfo = (); + type SS58Prefix = $crate::pallet_tests::SS58Prefix; + type OnSetCode = (); + type MaxConsumers = frame_support::traits::ConstU32<16>; + } + }; + + ($runtime:ty, DbWeight = $db_weight:ty $(, $( $rest:tt )*)?) => { + type SystemConfigDbWeight = $db_weight; + + $crate::impl_pallet_system_inner!($runtime, $($( $rest )*)?); + }; + + ($runtime:ty, BlockWeights = $block_weights:ty $(, $( $rest:tt )*)?) => { + type SystemConfigBlockWeights = $block_weights; + + $crate::impl_pallet_system_inner!($runtime, $($( $rest )*)?); + }; +} + +#[macro_export] +macro_rules! impl_pallet_timestamp { + ($runtime:ty) => { + impl pallet_timestamp::Config for Test { + type Moment = u64; + type OnTimestampSet = (); + type MinimumPeriod = $crate::pallet_tests::MinimumPeriod; + type WeightInfo = (); + } + }; +} + +#[macro_export] +macro_rules! impl_pallet_authorship { + ($runtime:ty, EventHandler = $event_handler:ty) => { + pub struct FixedBlockAuthor; + + impl FindAuthor for FixedBlockAuthor { + fn find_author<'a, I: 'a>(_: I) -> Option { + Some(BLOCK_AUTHOR) + } + } + + impl pallet_authorship::Config for $runtime { + type FindAuthor = FixedBlockAuthor; + type EventHandler = $event_handler; + } + }; + + ($runtime:ty) => { + $crate::impl_pallet_authorship!($runtime, EventHandler = ()); + }; +} diff --git a/pallets/gas/src/lib.rs b/pallets/gas/src/lib.rs index db681e5ca60..21775b42b7d 100644 --- a/pallets/gas/src/lib.rs +++ b/pallets/gas/src/lib.rs @@ -145,6 +145,15 @@ type AccountIdOf = ::AccountId; /// The current storage version. const STORAGE_VERSION: StorageVersion = StorageVersion::new(3); +#[macro_export] +macro_rules! impl_config { + ($runtime:ty) => { + impl pallet_gear_gas::Config for $runtime { + type BlockGasLimit = BlockGasLimit; + } + }; +} + #[frame_support::pallet] pub mod pallet { use super::*; diff --git a/pallets/gas/src/mock.rs b/pallets/gas/src/mock.rs index af98db3f605..ad38d831d75 100644 --- a/pallets/gas/src/mock.rs +++ b/pallets/gas/src/mock.rs @@ -16,12 +16,12 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate as pallet_gas; +use crate as pallet_gear_gas; use frame_support::{construct_runtime, parameter_types, weights::constants::RocksDbWeight}; use frame_system as system; use primitive_types::H256; use sp_runtime::{ - testing::Header, + generic, traits::{BlakeTwo256, IdentityLookup}, }; use sp_std::convert::{TryFrom, TryInto}; @@ -31,6 +31,7 @@ type Block = frame_system::mocking::MockBlock; type AccountId = u64; type BlockNumber = u64; type Balance = u128; +type BlockGasLimit = (); pub const ALICE: AccountId = 1; pub const BOB: AccountId = 2; @@ -45,69 +46,22 @@ construct_runtime!( { System: system, GearMessenger: pallet_gear_messenger, - Gas: pallet_gas, + GearGas: pallet_gear_gas, Balances: pallet_balances, } ); -impl pallet_balances::Config for Test { - type MaxLocks = (); - type MaxReserves = (); - type ReserveIdentifier = [u8; 8]; - type Balance = Balance; - type DustRemoval = (); - type RuntimeEvent = RuntimeEvent; - type ExistentialDeposit = ExistentialDeposit; - type AccountStore = System; - type WeightInfo = (); -} +common::impl_pallet_system!(Test, DbWeight = RocksDbWeight, BlockWeights = ()); +pallet_gear_messenger::impl_config!(Test, CurrentBlockNumber = GearBlockNumber); +pallet_gear_gas::impl_config!(Test); +common::impl_pallet_balances!(Test); parameter_types! { - pub const BlockHashCount: u64 = 250; - pub const SS58Prefix: u8 = 42; + pub const BlockHashCount: BlockNumber = 250; pub const ExistentialDeposit: Balance = 1; -} - -impl system::Config for Test { - type BaseCallFilter = frame_support::traits::Everything; - type BlockWeights = (); - type BlockLength = (); - type DbWeight = RocksDbWeight; - type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; - type Index = u64; - type BlockNumber = BlockNumber; - type Hash = H256; - type Hashing = BlakeTwo256; - type AccountId = AccountId; - type Lookup = IdentityLookup; - type Header = Header; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = BlockHashCount; - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type SS58Prefix = SS58Prefix; - type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; -} - -parameter_types! { pub const GearBlockNumber: BlockNumber = 100; } -impl pallet_gear_messenger::Config for Test { - type BlockLimiter = Gas; - type CurrentBlockNumber = GearBlockNumber; -} - -impl pallet_gas::Config for Test { - type BlockGasLimit = (); -} - // 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-bank/Cargo.toml b/pallets/gear-bank/Cargo.toml index 7075b18ace2..0db24956ff8 100644 --- a/pallets/gear-bank/Cargo.toml +++ b/pallets/gear-bank/Cargo.toml @@ -23,6 +23,7 @@ pallet-authorship.workspace = true sp-runtime.workspace = true [dev-dependencies] +common = { workspace = true, features = ["std"] } primitive-types.workspace = true # Substrate deps diff --git a/pallets/gear-bank/src/lib.rs b/pallets/gear-bank/src/lib.rs index 7254daa1e56..240eae05b74 100644 --- a/pallets/gear-bank/src/lib.rs +++ b/pallets/gear-bank/src/lib.rs @@ -30,6 +30,17 @@ pub use pallet::*; use frame_support::traits::{Currency, StorageVersion}; +#[macro_export] +macro_rules! impl_config { + ($runtime:ty) => { + impl pallet_gear_bank::Config for $runtime { + type Currency = Balances; + type BankAddress = BankAddress; + type GasMultiplier = GasMultiplier; + } + }; +} + pub(crate) type AccountIdOf = ::AccountId; pub(crate) type BalanceOf = as Currency>>::Balance; pub(crate) type CurrencyOf = ::Currency; diff --git a/pallets/gear-bank/src/mock.rs b/pallets/gear-bank/src/mock.rs index 21182ff87e5..c20e4bf6fd2 100644 --- a/pallets/gear-bank/src/mock.rs +++ b/pallets/gear-bank/src/mock.rs @@ -18,21 +18,19 @@ use crate as pallet_gear_bank; use frame_support::{ - construct_runtime, parameter_types, - traits::{Everything, FindAuthor}, - weights::constants::RocksDbWeight, + construct_runtime, parameter_types, traits::FindAuthor, weights::constants::RocksDbWeight, }; use frame_system::mocking::{MockBlock, MockUncheckedExtrinsic}; -use pallet_balances::AccountData; use primitive_types::H256; use sp_io::TestExternalities; use sp_runtime::{ - testing::Header, - traits::{BlakeTwo256, ConstU32, IdentityLookup}, + generic, + traits::{BlakeTwo256, IdentityLookup}, }; pub type AccountId = u8; pub type Balance = u128; +type BlockNumber = u64; mod consts { #![allow(unused)] @@ -62,7 +60,7 @@ pub use consts::*; parameter_types! { pub const BankAddress: AccountId = BANK_ADDRESS; pub const GasMultiplier: common::GasMultiplier = common::GasMultiplier::ValuePerGas(VALUE_PER_GAS); - pub const BlockHashCount: u64 = 250; + pub const BlockHashCount: BlockNumber = 250; pub const ExistentialDeposit: Balance = EXISTENTIAL_DEPOSIT; } @@ -79,63 +77,10 @@ construct_runtime!( } ); -impl frame_system::Config for Test { - type BaseCallFilter = Everything; - type BlockWeights = (); - type BlockLength = (); - type DbWeight = RocksDbWeight; - type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; - type Index = u64; - type BlockNumber = u64; - type Hash = H256; - type Hashing = BlakeTwo256; - type AccountId = AccountId; - type Lookup = IdentityLookup; - type Header = Header; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = BlockHashCount; - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = (); - type MaxConsumers = ConstU32<16>; -} - -pub struct FixedBlockAuthor; - -impl FindAuthor for FixedBlockAuthor { - fn find_author<'a, I: 'a>(_: I) -> Option { - Some(BLOCK_AUTHOR) - } -} - -impl pallet_authorship::Config for Test { - type FindAuthor = FixedBlockAuthor; - type EventHandler = (); -} - -impl pallet_balances::Config for Test { - type MaxLocks = (); - type MaxReserves = (); - type ReserveIdentifier = [u8; 8]; - type Balance = Balance; - type DustRemoval = (); - type RuntimeEvent = RuntimeEvent; - type ExistentialDeposit = ExistentialDeposit; - type AccountStore = System; - type WeightInfo = (); -} - -impl pallet_gear_bank::Config for Test { - type Currency = Balances; - type BankAddress = BankAddress; - type GasMultiplier = GasMultiplier; -} +common::impl_pallet_system!(Test, DbWeight = RocksDbWeight, BlockWeights = ()); +common::impl_pallet_authorship!(Test); +common::impl_pallet_balances!(Test); +pallet_gear_bank::impl_config!(Test); pub fn new_test_ext() -> TestExternalities { let mut storage = frame_system::GenesisConfig::default() diff --git a/pallets/gear-debug/Cargo.toml b/pallets/gear-debug/Cargo.toml index 449d6f13eee..e0c9efb3478 100644 --- a/pallets/gear-debug/Cargo.toml +++ b/pallets/gear-debug/Cargo.toml @@ -36,6 +36,7 @@ pallet-authorship.workspace = true [dev-dependencies] serde.workspace = true env_logger.workspace = true +common = { workspace = true, features = ["std"] } wabt.workspace = true hex-literal.workspace = true frame-support-test = { workspace = true, features = ["std"] } diff --git a/pallets/gear-debug/src/mock.rs b/pallets/gear-debug/src/mock.rs index ae669dd7f33..0306045e380 100644 --- a/pallets/gear-debug/src/mock.rs +++ b/pallets/gear-debug/src/mock.rs @@ -29,7 +29,7 @@ use pallet_gear::GasAllowanceOf; use primitive_types::H256; use sp_core::ConstBool; use sp_runtime::{ - testing::Header, + generic, traits::{BlakeTwo256, ConstU64, IdentityLookup}, }; use sp_std::convert::{TryFrom, TryInto}; @@ -42,51 +42,11 @@ type Balance = u128; pub const BLOCK_AUTHOR: AccountId = 255; -impl pallet_balances::Config for Test { - type MaxLocks = (); - type MaxReserves = (); - type ReserveIdentifier = [u8; 8]; - type Balance = Balance; - type DustRemoval = (); - type RuntimeEvent = RuntimeEvent; - type ExistentialDeposit = ExistentialDeposit; - type AccountStore = System; - type WeightInfo = (); -} - parameter_types! { - pub const BlockHashCount: u64 = 250; - pub const SS58Prefix: u8 = 42; + pub const BlockHashCount: BlockNumber = 250; pub const ExistentialDeposit: Balance = 1; } -impl system::Config for Test { - type BaseCallFilter = frame_support::traits::Everything; - type BlockWeights = (); - type BlockLength = (); - type DbWeight = (); - type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; - type Index = u64; - type BlockNumber = BlockNumber; - type Hash = H256; - type Hashing = BlakeTwo256; - type AccountId = AccountId; - type Lookup = IdentityLookup; - type Header = Header; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = BlockHashCount; - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type SS58Prefix = SS58Prefix; - type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; -} - impl pallet_gear_debug::Config for Test { type RuntimeEvent = RuntimeEvent; type WeightInfo = (); @@ -95,42 +55,12 @@ impl pallet_gear_debug::Config for Test { type Messenger = GearMessenger; } -pub struct FixedBlockAuthor; - -impl FindAuthor for FixedBlockAuthor { - fn find_author<'a, I>(_digests: I) -> Option - where - I: 'a + IntoIterator, - { - Some(BLOCK_AUTHOR) - } -} - -impl pallet_authorship::Config for Test { - type FindAuthor = FixedBlockAuthor; - - type EventHandler = (); -} - parameter_types! { - pub const MinimumPeriod: u64 = 500; pub const OutgoingLimit: u32 = 1024; pub const BlockGasLimit: u64 = 100_000_000_000; pub const PerformanceMultiplier: u32 = 100; } -impl pallet_timestamp::Config for Test { - type Moment = u64; - type OnTimestampSet = (); - type MinimumPeriod = MinimumPeriod; - type WeightInfo = (); -} - -impl pallet_gear_program::Config for Test { - type Scheduler = GearScheduler; - type CurrentBlockNumber = (); -} - parameter_types! { pub RentFreePeriod: BlockNumber = 1_000; pub RentCostPerBlock: Balance = 11; @@ -138,56 +68,7 @@ parameter_types! { pub ResumeSessionDuration: BlockNumber = 1_000; pub const BankAddress: AccountId = 15082001; pub const GasMultiplier: common::GasMultiplier = common::GasMultiplier::ValuePerGas(25); -} - -impl pallet_gear_bank::Config for Test { - type Currency = Balances; - type BankAddress = BankAddress; - type GasMultiplier = GasMultiplier; -} - -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; -} - -impl pallet_gear_messenger::Config for Test { - type BlockLimiter = GearGas; - type CurrentBlockNumber = Gear; -} - -impl pallet_gear_scheduler::Config for Test { - type BlockLimiter = GearGas; - type ReserveThreshold = ConstU64<1>; - type WaitlistCost = ConstU64<100>; - type MailboxCost = ConstU64<100>; - type ReservationCost = ConstU64<100>; - type DispatchHoldCost = ConstU64<100>; -} - -impl pallet_gear_gas::Config for Test { - type BlockGasLimit = BlockGasLimit; + pub ReserveThreshold: BlockNumber = 1; } // Configure a mock runtime to test the pallet. @@ -211,6 +92,17 @@ construct_runtime!( } ); +common::impl_pallet_system!(Test, DbWeight = (), BlockWeights = ()); +common::impl_pallet_balances!(Test); +common::impl_pallet_authorship!(Test); +common::impl_pallet_timestamp!(Test); +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. pub fn new_test_ext() -> sp_io::TestExternalities { let mut t = system::GenesisConfig::default() diff --git a/pallets/gear-messenger/Cargo.toml b/pallets/gear-messenger/Cargo.toml index 8037b76a09f..b04b8338531 100644 --- a/pallets/gear-messenger/Cargo.toml +++ b/pallets/gear-messenger/Cargo.toml @@ -37,6 +37,7 @@ pallet-balances = { workspace = true, features = ["std"] } pallet-authorship = { workspace = true, features = ["std"] } pallet-timestamp = { workspace = true, features = ["std"] } env_logger.workspace = true +common = { workspace = true, features = ["std"] } [features] default = ['std'] diff --git a/pallets/gear-messenger/src/lib.rs b/pallets/gear-messenger/src/lib.rs index cc32d5e3a8b..0c0330ec073 100644 --- a/pallets/gear-messenger/src/lib.rs +++ b/pallets/gear-messenger/src/lib.rs @@ -142,6 +142,8 @@ mod mock; #[cfg(test)] mod tests; +pub mod pallet_tests; + // Public exports from pallet. pub use pallet::*; diff --git a/pallets/gear-messenger/src/mock.rs b/pallets/gear-messenger/src/mock.rs index 0f714caafbe..1ce9591ae1e 100644 --- a/pallets/gear-messenger/src/mock.rs +++ b/pallets/gear-messenger/src/mock.rs @@ -26,7 +26,7 @@ use frame_support::{ use frame_system as system; use primitive_types::H256; use sp_runtime::{ - testing::Header, + generic, traits::{BlakeTwo256, IdentityLookup}, }; use sp_std::convert::{TryFrom, TryInto}; @@ -51,61 +51,17 @@ construct_runtime!( } ); -impl pallet_balances::Config for Test { - type MaxLocks = (); - type MaxReserves = (); - type ReserveIdentifier = [u8; 8]; - type Balance = Balance; - type DustRemoval = (); - type RuntimeEvent = RuntimeEvent; - type ExistentialDeposit = ExistentialDeposit; - type AccountStore = System; - type WeightInfo = (); -} +common::impl_pallet_system!(Test, DbWeight = (), BlockWeights = ()); +common::impl_pallet_balances!(Test); +pallet_gear_gas::impl_config!(Test); +pallet_gear_messenger::impl_config!(Test); parameter_types! { - pub const BlockHashCount: u64 = 250; - pub const SS58Prefix: u8 = 42; + pub const BlockHashCount: BlockNumber = 250; pub const ExistentialDeposit: Balance = 1; pub const BlockGasLimit: u64 = 100_000_000; } -impl pallet_gear_gas::Config for Test { - type BlockGasLimit = BlockGasLimit; -} - -impl system::Config for Test { - type BaseCallFilter = frame_support::traits::Everything; - type BlockWeights = (); - type BlockLength = (); - type DbWeight = (); - type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; - type Index = u64; - type BlockNumber = BlockNumber; - type Hash = H256; - type Hashing = BlakeTwo256; - type AccountId = AccountId; - type Lookup = IdentityLookup; - type Header = Header; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = BlockHashCount; - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type SS58Prefix = SS58Prefix; - type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; -} - -impl pallet_gear_messenger::Config for Test { - type BlockLimiter = GearGas; - type CurrentBlockNumber = (); -} - // 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-messenger/src/pallet_tests.rs b/pallets/gear-messenger/src/pallet_tests.rs new file mode 100644 index 00000000000..3d1adbfa780 --- /dev/null +++ b/pallets/gear-messenger/src/pallet_tests.rs @@ -0,0 +1,47 @@ +// 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 GearMessengerCurrentBlockNumber = (); + + mod pallet_tests_gear_messenger_config_impl { + use super::*; + + $crate::impl_config_inner!($( $tokens )*); + } + }; +} + +#[macro_export] +macro_rules! impl_config_inner { + ($runtime:ty$(,)?) => { + impl pallet_gear_messenger::Config for $runtime { + type BlockLimiter = GearGas; + type CurrentBlockNumber = GearMessengerCurrentBlockNumber; + } + }; + + ($runtime:ty, CurrentBlockNumber = $current_block_number:ty $(, $( $rest:tt )*)?) => { + type GearMessengerCurrentBlockNumber = $current_block_number; + + $crate::impl_config_inner!($runtime, $($( $rest )*)?); + }; +} diff --git a/pallets/gear-program/Cargo.toml b/pallets/gear-program/Cargo.toml index d39b18f9446..7b1a063b145 100644 --- a/pallets/gear-program/Cargo.toml +++ b/pallets/gear-program/Cargo.toml @@ -33,6 +33,7 @@ sp-io.workspace = true sp-runtime.workspace = true [dev-dependencies] +common = { workspace = true, features = ["std"] } pallet-balances = { workspace = true, features = ["std"] } pallet-authorship = { workspace = true, features = ["std"] } pallet-timestamp = { workspace = true, features = ["std"] } diff --git a/pallets/gear-program/src/lib.rs b/pallets/gear-program/src/lib.rs index bb3fd47b935..f6ea7129d3e 100644 --- a/pallets/gear-program/src/lib.rs +++ b/pallets/gear-program/src/lib.rs @@ -138,6 +138,8 @@ pub mod migrations; #[cfg(test)] mod mock; +pub mod pallet_tests; + #[frame_support::pallet] pub mod pallet { use super::*; diff --git a/pallets/gear-program/src/mock.rs b/pallets/gear-program/src/mock.rs index 6937c6b4cdb..b9b7007f684 100644 --- a/pallets/gear-program/src/mock.rs +++ b/pallets/gear-program/src/mock.rs @@ -20,6 +20,7 @@ use crate as pallet_gear_program; use crate::*; +use common::pallet_tests::MAX_BLOCK; use frame_support::{ construct_runtime, pallet_prelude::*, @@ -30,7 +31,7 @@ use frame_support::{ use frame_system::{self as system, limits::BlockWeights}; use sp_core::H256; use sp_runtime::{ - testing::Header, + generic, traits::{BlakeTwo256, IdentityLookup}, Perbill, }; @@ -47,8 +48,6 @@ pub(crate) const USER_2: AccountId = 2; pub(crate) const USER_3: AccountId = 3; pub(crate) const LOW_BALANCE_USER: AccountId = 4; pub(crate) const BLOCK_AUTHOR: AccountId = 255; -const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75); -const MAX_BLOCK: u64 = 100_000_000_000; // Configure a mock runtime to test the pallet. construct_runtime!( @@ -67,101 +66,19 @@ construct_runtime!( } ); -impl pallet_balances::Config for Test { - type MaxLocks = (); - type MaxReserves = (); - type ReserveIdentifier = [u8; 8]; - type Balance = Balance; - type DustRemoval = (); - type RuntimeEvent = RuntimeEvent; - type ExistentialDeposit = ExistentialDeposit; - type AccountStore = System; - type WeightInfo = (); -} +common::impl_pallet_system!(Test); +pallet_gear_program::impl_config!(Test); +pallet_gear_scheduler::impl_config!(Test); +pallet_gear_gas::impl_config!(Test); +common::impl_pallet_balances!(Test); +common::impl_pallet_authorship!(Test); +common::impl_pallet_timestamp!(Test); parameter_types! { pub const BlockGasLimit: u64 = MAX_BLOCK; - pub const BlockHashCount: u64 = 250; - pub RuntimeBlockWeights: BlockWeights = BlockWeights::with_sensible_defaults( - Weight::from_parts(MAX_BLOCK, u64::MAX), - NORMAL_DISPATCH_RATIO, - ); - pub const SS58Prefix: u8 = 42; + pub const BlockHashCount: BlockNumber = 250; pub const ExistentialDeposit: Balance = 500; - pub const DbWeight: RuntimeDbWeight = RuntimeDbWeight { read: 1110, write: 2300 }; -} - -impl system::Config for Test { - type BaseCallFilter = frame_support::traits::Everything; - type BlockWeights = RuntimeBlockWeights; - type BlockLength = (); - type DbWeight = DbWeight; - type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; - type Index = u64; - type BlockNumber = BlockNumber; - type Hash = H256; - type Hashing = BlakeTwo256; - type AccountId = AccountId; - type Lookup = IdentityLookup; - type Header = Header; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = BlockHashCount; - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type SS58Prefix = SS58Prefix; - type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; -} - -impl pallet_gear_program::Config for Test { - type Scheduler = GearScheduler; - type CurrentBlockNumber = (); -} - -impl pallet_gear_scheduler::Config for Test { - type BlockLimiter = GearGas; - type ReserveThreshold = ConstU64<1>; - type WaitlistCost = ConstU64<100>; - type MailboxCost = ConstU64<100>; - type ReservationCost = ConstU64<100>; - type DispatchHoldCost = ConstU64<100>; -} - -impl pallet_gear_gas::Config for Test { - type BlockGasLimit = BlockGasLimit; -} - -pub struct FixedBlockAuthor; - -impl FindAuthor for FixedBlockAuthor { - fn find_author<'a, I>(_digests: I) -> Option - where - I: 'a + IntoIterator, - { - Some(BLOCK_AUTHOR) - } -} - -impl pallet_authorship::Config for Test { - type FindAuthor = FixedBlockAuthor; - - type EventHandler = (); -} - -parameter_types! { - pub const MinimumPeriod: u64 = 500; -} - -impl pallet_timestamp::Config for Test { - type Moment = u64; - type OnTimestampSet = (); - type MinimumPeriod = MinimumPeriod; - type WeightInfo = (); + pub ReserveThreshold: BlockNumber = 1; } // Build genesis storage according to the mock runtime. diff --git a/pallets/gear-program/src/pallet_tests.rs b/pallets/gear-program/src/pallet_tests.rs new file mode 100644 index 00000000000..7878f15f04b --- /dev/null +++ b/pallets/gear-program/src/pallet_tests.rs @@ -0,0 +1,27 @@ +// 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 { + ($runtime:ty) => { + impl pallet_gear_program::Config for $runtime { + type Scheduler = GearScheduler; + type CurrentBlockNumber = (); + } + }; +} diff --git a/pallets/gear-scheduler/Cargo.toml b/pallets/gear-scheduler/Cargo.toml index d85e5827e3b..5e310760e9f 100644 --- a/pallets/gear-scheduler/Cargo.toml +++ b/pallets/gear-scheduler/Cargo.toml @@ -44,6 +44,7 @@ pallet-balances = { workspace = true, features = ["std"] } pallet-authorship = { workspace = true, features = ["std"] } pallet-timestamp = { workspace = true, features = ["std"] } env_logger.workspace = true +common = { workspace = true, features = ["std"] } [features] default = ['std'] diff --git a/pallets/gear-scheduler/src/lib.rs b/pallets/gear-scheduler/src/lib.rs index eadecd43ca0..1049aefdd1b 100644 --- a/pallets/gear-scheduler/src/lib.rs +++ b/pallets/gear-scheduler/src/lib.rs @@ -28,6 +28,20 @@ mod mock; #[cfg(test)] mod tests; +#[macro_export] +macro_rules! impl_config { + ($runtime:ty) => { + impl pallet_gear_scheduler::Config for $runtime { + type BlockLimiter = GearGas; + type ReserveThreshold = ReserveThreshold; + type WaitlistCost = ConstU64<100>; + type MailboxCost = ConstU64<100>; + type ReservationCost = ConstU64<100>; + type DispatchHoldCost = ConstU64<100>; + } + }; +} + // Public exports from pallet. pub use pallet::*; diff --git a/pallets/gear-scheduler/src/mock.rs b/pallets/gear-scheduler/src/mock.rs index 8b662f87b0b..65e97e9802d 100644 --- a/pallets/gear-scheduler/src/mock.rs +++ b/pallets/gear-scheduler/src/mock.rs @@ -30,7 +30,7 @@ use frame_system::{self as system, limits::BlockWeights}; use pallet_gear::GasAllowanceOf; use sp_core::{ConstBool, H256}; use sp_runtime::{ - testing::Header, + generic, traits::{BlakeTwo256, IdentityLookup}, }; @@ -68,54 +68,21 @@ construct_runtime!( } ); -impl pallet_balances::Config for Test { - type MaxLocks = (); - type MaxReserves = (); - type ReserveIdentifier = [u8; 8]; - type Balance = Balance; - type DustRemoval = (); - type RuntimeEvent = RuntimeEvent; - type ExistentialDeposit = ExistentialDeposit; - type AccountStore = System; - type WeightInfo = (); -} +common::impl_pallet_system!(Test, DbWeight = RocksDbWeight, BlockWeights = ()); +common::impl_pallet_timestamp!(Test); +common::impl_pallet_authorship!(Test); +common::impl_pallet_balances!(Test); +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! { - pub const BlockHashCount: u64 = 250; - pub const SS58Prefix: u8 = 42; + pub const BlockHashCount: BlockNumber = 250; pub const ExistentialDeposit: Balance = 500; -} - -impl system::Config for Test { - type BaseCallFilter = frame_support::traits::Everything; - type BlockWeights = (); - type BlockLength = (); - type DbWeight = RocksDbWeight; - type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; - type Index = u64; - type BlockNumber = BlockNumber; - type Hash = H256; - type Hashing = BlakeTwo256; - type AccountId = AccountId; - type Lookup = IdentityLookup; - type Header = Header; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = BlockHashCount; - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type SS58Prefix = SS58Prefix; - type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; -} - -impl pallet_gear_program::Config for Test { - type Scheduler = GearScheduler; - type CurrentBlockNumber = (); + pub ReserveThreshold: BlockNumber = 1; } parameter_types! { @@ -131,84 +98,6 @@ parameter_types! { pub const GasMultiplier: common::GasMultiplier = common::GasMultiplier::ValuePerGas(25); } -impl pallet_gear_bank::Config for Test { - type Currency = Balances; - type BankAddress = BankAddress; - type GasMultiplier = GasMultiplier; -} - -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; -} - -impl pallet_gear_scheduler::Config for Test { - type BlockLimiter = GearGas; - type ReserveThreshold = ConstU64<1>; - type WaitlistCost = ConstU64<100>; - type MailboxCost = ConstU64<100>; - type ReservationCost = ConstU64<100>; - type DispatchHoldCost = ConstU64<100>; -} - -impl pallet_gear_gas::Config for Test { - type BlockGasLimit = BlockGasLimit; -} - -impl pallet_gear_messenger::Config for Test { - type BlockLimiter = GearGas; - type CurrentBlockNumber = Gear; -} - -pub struct FixedBlockAuthor; - -impl FindAuthor for FixedBlockAuthor { - fn find_author<'a, I>(_digests: I) -> Option - where - I: 'a + IntoIterator, - { - Some(BLOCK_AUTHOR) - } -} - -impl pallet_authorship::Config for Test { - type FindAuthor = FixedBlockAuthor; - - type EventHandler = (); -} - -parameter_types! { - pub const MinimumPeriod: u64 = 500; -} - -impl pallet_timestamp::Config for Test { - type Moment = u64; - type OnTimestampSet = (); - type MinimumPeriod = MinimumPeriod; - type WeightInfo = (); -} - // 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-voucher/Cargo.toml b/pallets/gear-voucher/Cargo.toml index 95a87591564..dcbf7094a70 100644 --- a/pallets/gear-voucher/Cargo.toml +++ b/pallets/gear-voucher/Cargo.toml @@ -35,6 +35,7 @@ pallet-balances.workspace = true [dev-dependencies] serde.workspace = true env_logger.workspace = true +common = { workspace = true, features = ["std"] } sp-core = {workspace = true, features = ["std"] } [features] diff --git a/pallets/gear-voucher/src/mock.rs b/pallets/gear-voucher/src/mock.rs index 180772bd8c5..418dedc28bc 100644 --- a/pallets/gear-voucher/src/mock.rs +++ b/pallets/gear-voucher/src/mock.rs @@ -23,7 +23,7 @@ use frame_support::{ use frame_system as system; use primitive_types::H256; use sp_runtime::{ - testing::Header, + generic, traits::{BlakeTwo256, IdentityLookup}, }; use sp_std::convert::{TryFrom, TryInto}; @@ -51,49 +51,12 @@ construct_runtime!( ); parameter_types! { - pub const BlockHashCount: u64 = 250; - pub const SS58Prefix: u8 = 42; + pub const BlockHashCount: BlockNumber = 250; pub const ExistentialDeposit: Balance = 1; } -impl system::Config for Test { - type BaseCallFilter = frame_support::traits::Everything; - type BlockWeights = (); - type BlockLength = (); - type DbWeight = RocksDbWeight; - type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; - type Index = u64; - type BlockNumber = BlockNumber; - type Hash = H256; - type Hashing = BlakeTwo256; - type AccountId = AccountId; - type Lookup = IdentityLookup; - type Header = Header; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = BlockHashCount; - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type SS58Prefix = SS58Prefix; - type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; -} - -impl pallet_balances::Config for Test { - type MaxLocks = (); - type MaxReserves = (); - type ReserveIdentifier = [u8; 8]; - type Balance = Balance; - type DustRemoval = (); - type RuntimeEvent = RuntimeEvent; - type ExistentialDeposit = ExistentialDeposit; - type AccountStore = System; - type WeightInfo = (); -} +common::impl_pallet_system!(Test, DbWeight = RocksDbWeight, BlockWeights = ()); +common::impl_pallet_balances!(Test); parameter_types! { pub const VoucherPalletId: PalletId = PalletId(*b"py/vouch"); diff --git a/pallets/gear/Cargo.toml b/pallets/gear/Cargo.toml index 6b412909f43..b0e76956394 100644 --- a/pallets/gear/Cargo.toml +++ b/pallets/gear/Cargo.toml @@ -116,6 +116,7 @@ demo-custom.workspace = true test-syscalls.workspace = true page_size.workspace = true frame-support-test = { workspace = true, features = ["std"] } +common = { workspace = true, features = ["std"] } pallet-gear-gas = { workspace = true, features = ["std"] } pallet-gear-messenger = { workspace = true, features = ["std"] } pallet-gear-scheduler = { workspace = true, features = ["std"] } 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 d0702ce788f..84d3a630975 100644 --- a/pallets/gear/src/mock.rs +++ b/pallets/gear/src/mock.rs @@ -18,12 +18,12 @@ use crate as pallet_gear; use crate::*; +use common::pallet_tests::MAX_BLOCK; use frame_support::{ construct_runtime, pallet_prelude::*, parameter_types, traits::{ConstU64, FindAuthor, Get}, - weights::RuntimeDbWeight, PalletId, }; use frame_support_test::TestRandomness; @@ -32,7 +32,6 @@ use sp_core::H256; use sp_runtime::{ generic, traits::{BlakeTwo256, IdentityLookup}, - Perbill, }; use sp_std::{ cell::RefCell, @@ -52,8 +51,6 @@ pub(crate) const USER_2: AccountId = 2; pub(crate) const USER_3: AccountId = 3; pub(crate) const LOW_BALANCE_USER: AccountId = 4; pub(crate) const BLOCK_AUTHOR: AccountId = 255; -const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75); -const MAX_BLOCK: u64 = 250_000_000_000; macro_rules! dry_run { ( @@ -91,59 +88,20 @@ construct_runtime!( } ); -impl pallet_balances::Config for Test { - type MaxLocks = (); - type MaxReserves = (); - type ReserveIdentifier = [u8; 8]; - type Balance = Balance; - type DustRemoval = (); - type RuntimeEvent = RuntimeEvent; - type ExistentialDeposit = ExistentialDeposit; - type AccountStore = System; - type WeightInfo = (); -} +common::impl_pallet_system!(Test); +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); +common::impl_pallet_timestamp!(Test); parameter_types! { pub const BlockHashCount: BlockNumber = 250; - pub RuntimeBlockWeights: BlockWeights = BlockWeights::with_sensible_defaults( - Weight::from_parts(MAX_BLOCK, u64::MAX), - NORMAL_DISPATCH_RATIO, - ); - pub const SS58Prefix: u8 = 42; pub const ExistentialDeposit: Balance = 500; - pub const DbWeight: RuntimeDbWeight = RuntimeDbWeight { read: 1110, write: 2300 }; -} - -impl system::Config for Test { - type BaseCallFilter = frame_support::traits::Everything; - type BlockWeights = RuntimeBlockWeights; - type BlockLength = (); - type DbWeight = DbWeight; - type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; - type Index = u64; - type BlockNumber = BlockNumber; - type Hash = H256; - type Hashing = BlakeTwo256; - type AccountId = AccountId; - type Lookup = IdentityLookup; - type Header = generic::Header; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = BlockHashCount; - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type SS58Prefix = SS58Prefix; - type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; -} - -impl pallet_gear_program::Config for Test { - type Scheduler = GearScheduler; - type CurrentBlockNumber = (); } parameter_types! { @@ -206,84 +164,6 @@ parameter_types! { pub const GasMultiplier: common::GasMultiplier = common::GasMultiplier::ValuePerGas(25); } -impl pallet_gear_bank::Config for Test { - type Currency = Balances; - type BankAddress = BankAddress; - type GasMultiplier = GasMultiplier; -} - -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; -} - -impl pallet_gear_scheduler::Config for Test { - type BlockLimiter = GearGas; - type ReserveThreshold = ReserveThreshold; - type WaitlistCost = ConstU64<100>; - type MailboxCost = ConstU64<100>; - type ReservationCost = ConstU64<100>; - type DispatchHoldCost = ConstU64<100>; -} - -impl pallet_gear_gas::Config for Test { - type BlockGasLimit = BlockGasLimit; -} - -impl pallet_gear_messenger::Config for Test { - type BlockLimiter = GearGas; - type CurrentBlockNumber = Gear; -} - -pub struct FixedBlockAuthor; - -impl FindAuthor for FixedBlockAuthor { - fn find_author<'a, I>(_digests: I) -> Option - where - I: 'a + IntoIterator, - { - Some(BLOCK_AUTHOR) - } -} - -impl pallet_authorship::Config for Test { - type FindAuthor = FixedBlockAuthor; - - type EventHandler = (); -} - -parameter_types! { - pub const MinimumPeriod: u64 = 500; -} - -impl pallet_timestamp::Config for Test { - type Moment = u64; - type OnTimestampSet = (); - type MinimumPeriod = MinimumPeriod; - type WeightInfo = (); -} - 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..7cd98cb72c7 --- /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/Cargo.toml b/pallets/payment/Cargo.toml index 84d09e5244c..48a2772ecbf 100644 --- a/pallets/payment/Cargo.toml +++ b/pallets/payment/Cargo.toml @@ -34,6 +34,7 @@ pallet-transaction-payment.workspace = true [dev-dependencies] serde.workspace = true env_logger.workspace = true +common = { workspace = true, features = ["std"] } wabt.workspace = true gear-core.workspace = true sp-io = { workspace = true, features = ["std"] } diff --git a/pallets/payment/src/mock.rs b/pallets/payment/src/mock.rs index 8b8b85077fd..b989c655a8d 100644 --- a/pallets/payment/src/mock.rs +++ b/pallets/payment/src/mock.rs @@ -31,7 +31,8 @@ use frame_system as system; use pallet_transaction_payment::CurrencyAdapter; use primitive_types::H256; use sp_runtime::{ - testing::{Header, TestXt}, + generic, + testing::TestXt, traits::{BlakeTwo256, ConstBool, ConstU64, IdentityLookup}, }; use sp_std::{ @@ -74,80 +75,24 @@ construct_runtime!( } ); -impl pallet_balances::Config for Test { - type MaxLocks = (); - type MaxReserves = (); - type ReserveIdentifier = [u8; 8]; - type Balance = Balance; - type DustRemoval = (); - type RuntimeEvent = RuntimeEvent; - type ExistentialDeposit = ExistentialDeposit; - type AccountStore = System; - type WeightInfo = (); -} - -pub struct FixedBlockAuthor; - -impl FindAuthor for FixedBlockAuthor { - fn find_author<'a, I>(_digests: I) -> Option - where - I: 'a + IntoIterator, - { - Some(BLOCK_AUTHOR) - } -} - -impl pallet_authorship::Config for Test { - type FindAuthor = FixedBlockAuthor; - - type EventHandler = (); -} +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); +common::impl_pallet_timestamp!(Test); +pallet_gear_messenger::impl_config!(Test, CurrentBlockNumber = Gear); +pallet_gear_scheduler::impl_config!(Test); +pallet_gear_program::impl_config!(Test); +pallet_gear_bank::impl_config!(Test); parameter_types! { - pub const MinimumPeriod: u64 = 500; -} - -impl pallet_timestamp::Config for Test { - type Moment = u64; - type OnTimestampSet = (); - type MinimumPeriod = MinimumPeriod; - type WeightInfo = (); -} - -parameter_types! { - pub const BlockHashCount: u64 = 2400; - pub const SS58Prefix: u8 = 42; + pub const BlockHashCount: BlockNumber = 2_400; pub const ExistentialDeposit: Balance = 1; pub RuntimeBlockWeights: frame_system::limits::BlockWeights = frame_system::limits::BlockWeights::simple_max( Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND / 2, u64::MAX) ); -} - -impl system::Config for Test { - type BaseCallFilter = frame_support::traits::Everything; - type BlockWeights = RuntimeBlockWeights; - type BlockLength = (); - type DbWeight = (); - type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; - type Index = u64; - type BlockNumber = BlockNumber; - type Hash = H256; - type Hashing = BlakeTwo256; - type AccountId = AccountId; - type Lookup = IdentityLookup; - type Header = Header; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = BlockHashCount; - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type SS58Prefix = SS58Prefix; - type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; + pub ReserveThreshold: BlockNumber = 1; } parameter_types! { @@ -177,61 +122,6 @@ parameter_types! { pub const GasMultiplier: common::GasMultiplier = common::GasMultiplier::ValuePerGas(25); } -impl pallet_gear_bank::Config for Test { - type Currency = Balances; - type BankAddress = BankAddress; - type GasMultiplier = GasMultiplier; -} - -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; -} - -impl pallet_gear_program::Config for Test { - type Scheduler = GearScheduler; - type CurrentBlockNumber = (); -} - -impl pallet_gear_gas::Config for Test { - type BlockGasLimit = BlockGasLimit; -} - -impl pallet_gear_scheduler::Config for Test { - type BlockLimiter = GearGas; - type ReserveThreshold = ConstU64<1>; - type WaitlistCost = ConstU64<100>; - type MailboxCost = ConstU64<100>; - type ReservationCost = ConstU64<100>; - type DispatchHoldCost = ConstU64<100>; -} - -impl pallet_gear_messenger::Config for Test { - type BlockLimiter = GearGas; - type CurrentBlockNumber = Gear; -} - type NegativeImbalance = >::NegativeImbalance; pub struct DealWithFees; diff --git a/pallets/staking-rewards/Cargo.toml b/pallets/staking-rewards/Cargo.toml index 3dd27074128..4a78a67f8b0 100644 --- a/pallets/staking-rewards/Cargo.toml +++ b/pallets/staking-rewards/Cargo.toml @@ -45,6 +45,7 @@ pallet-utility = { workspace = true, features = ["std"] } pallet-election-provider-multi-phase = { workspace = true, features = ["std"] } frame-executive = { workspace = true, features = ["std"] } env_logger.workspace = true +common = { workspace = true, features = ["std"] } [features] default = ["std"] diff --git a/pallets/staking-rewards/src/mock.rs b/pallets/staking-rewards/src/mock.rs index e5ca6aad641..7568b19e9ff 100644 --- a/pallets/staking-rewards/src/mock.rs +++ b/pallets/staking-rewards/src/mock.rs @@ -23,8 +23,8 @@ use frame_election_provider_support::{ use frame_support::{ construct_runtime, parameter_types, traits::{ - ConstU32, Contains, Currency, Everything, FindAuthor, GenesisBuild, NeverEnsureOrigin, - OnFinalize, OnInitialize, U128CurrencyToVote, + ConstU32, Contains, Currency, FindAuthor, GenesisBuild, NeverEnsureOrigin, OnFinalize, + OnInitialize, U128CurrencyToVote, }, weights::{constants::RocksDbWeight, Weight}, PalletId, @@ -34,7 +34,8 @@ use pallet_election_provider_multi_phase::{self as multi_phase}; use pallet_session::historical::{self as pallet_session_historical}; use sp_core::{crypto::key_types, H256}; use sp_runtime::{ - testing::{Block as TestBlock, Header, UintAuthorityId}, + generic, + testing::{Block as TestBlock, UintAuthorityId}, traits::{BlakeTwo256, IdentityLookup, OpaqueKeys}, KeyTypeId, Perbill, Permill, Perquintill, }; @@ -58,6 +59,7 @@ pub(crate) type Executive = frame_executive::Executive< pub(crate) const SIGNER: AccountId = 1; pub(crate) const VAL_1_STASH: AccountId = 10; +pub(crate) const BLOCK_AUTHOR: AccountId = VAL_1_STASH; pub(crate) const VAL_1_CONTROLLER: AccountId = 11; pub(crate) const VAL_1_AUTH_ID: UintAuthorityId = UintAuthorityId(12); pub(crate) const VAL_2_STASH: AccountId = 20; @@ -103,79 +105,16 @@ construct_runtime!( } ); -impl pallet_balances::Config for Test { - type MaxLocks = (); - type MaxReserves = (); - type ReserveIdentifier = [u8; 8]; - type Balance = Balance; - type DustRemoval = (); - type RuntimeEvent = RuntimeEvent; - type ExistentialDeposit = ExistentialDeposit; - type AccountStore = System; - type WeightInfo = (); -} +common::impl_pallet_system!(Test, DbWeight = RocksDbWeight, BlockWeights = ()); +common::impl_pallet_balances!(Test); +common::impl_pallet_authorship!(Test, EventHandler = Staking); +common::impl_pallet_timestamp!(Test); parameter_types! { - pub const BlockHashCount: u64 = 250; - pub const SS58Prefix: u8 = 42; + pub const BlockHashCount: BlockNumber = 250; pub const ExistentialDeposit: Balance = EXISTENTIAL_DEPOSIT; } -impl system::Config for Test { - type BaseCallFilter = Everything; - type BlockWeights = (); - type BlockLength = (); - type DbWeight = RocksDbWeight; - type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; - type Index = u64; - type BlockNumber = BlockNumber; - type Hash = H256; - type Hashing = BlakeTwo256; - type AccountId = AccountId; - type Lookup = IdentityLookup; - type Header = Header; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = BlockHashCount; - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type SS58Prefix = SS58Prefix; - type OnSetCode = (); - type MaxConsumers = ConstU32<16>; -} - -pub struct FixedBlockAuthor; - -impl FindAuthor for FixedBlockAuthor { - fn find_author<'a, I>(_digests: I) -> Option - where - I: 'a + IntoIterator, - { - Some(VAL_1_STASH) - } -} - -impl pallet_authorship::Config for Test { - type FindAuthor = FixedBlockAuthor; - - type EventHandler = Staking; -} - -parameter_types! { - pub const MinimumPeriod: u64 = 500; -} - -impl pallet_timestamp::Config for Test { - type Moment = u64; - type OnTimestampSet = (); - type MinimumPeriod = MinimumPeriod; - type WeightInfo = (); -} - impl pallet_sudo::Config for Test { type RuntimeEvent = RuntimeEvent; type RuntimeCall = RuntimeCall; From 35c1234daacee69133f8dcfc5b6f32beddfedfb5 Mon Sep 17 00:00:00 2001 From: Dmitry Novikov Date: Wed, 8 Nov 2023 13:13:01 +0400 Subject: [PATCH 2/6] fix(gtest): Run delayed dispatches in `externalities` context (#3481) --- gtest/src/manager.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gtest/src/manager.rs b/gtest/src/manager.rs index 018a1b5bbcf..60b09973bb5 100644 --- a/gtest/src/manager.rs +++ b/gtest/src/manager.rs @@ -313,7 +313,7 @@ impl ExtManager { .map(|dispatches| { dispatches .into_iter() - .map(|dispatch| self.run_dispatch(dispatch)) + .map(|dispatch| self.with_externalities(|this| this.run_dispatch(dispatch))) .collect() }) .unwrap_or_default() From c910fe82db63285b4e5c26b33bea8ade16c845fb Mon Sep 17 00:00:00 2001 From: Sabaun Taraki Date: Thu, 9 Nov 2023 19:21:32 +0300 Subject: [PATCH 3/6] fix(wasm-gen): Include value into argument of invocable syscalls with destination param (#3484) --- utils/wasm-gen/src/generator/syscalls.rs | 11 +++++-- .../src/generator/syscalls/invocator.rs | 30 +++++++++++++++---- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/utils/wasm-gen/src/generator/syscalls.rs b/utils/wasm-gen/src/generator/syscalls.rs index ac66b948a63..ab33839a571 100644 --- a/utils/wasm-gen/src/generator/syscalls.rs +++ b/utils/wasm-gen/src/generator/syscalls.rs @@ -193,8 +193,8 @@ impl InvocableSysCall { }) } - /// Returns the index of the destination param. - fn has_destination_param(&self) -> Option { + /// Returns the index of the destination param if a syscall has it. + fn destination_param_idx(&self) -> Option { use InvocableSysCall::*; use SysCallName::*; @@ -206,6 +206,13 @@ impl InvocableSysCall { } } + /// Returns `true` for every syscall which has a destination param idx and that is not `gr_exit` syscall, + /// as it only has destination param. + fn has_destination_param_with_value(&self) -> bool { + self.destination_param_idx().is_some() + && !matches!(self, InvocableSysCall::Loose(SysCallName::Exit)) + } + // If syscall changes from fallible into infallible or vice versa in future, // we'll see it by analyzing code coverage stats produced by fuzzer. pub(crate) fn is_fallible(&self) -> bool { diff --git a/utils/wasm-gen/src/generator/syscalls/invocator.rs b/utils/wasm-gen/src/generator/syscalls/invocator.rs index 38a5f9d6628..a27ecd08f2b 100644 --- a/utils/wasm-gen/src/generator/syscalls/invocator.rs +++ b/utils/wasm-gen/src/generator/syscalls/invocator.rs @@ -31,9 +31,10 @@ use gear_wasm_instrument::{ parity_wasm::elements::{BlockType, Instruction, Internal, ValueType}, syscalls::{ParamType, PtrInfo, PtrType, SysCallName, SysCallSignature}, }; +use gsys::Hash; use std::{ collections::{btree_map::Entry, BTreeMap, BinaryHeap, HashSet}, - iter, + iter, mem, num::NonZeroU32, }; @@ -321,7 +322,7 @@ impl<'a, 'b> SysCallsInvocator<'a, 'b> { self.unstructured.len() ); - if let Some(argument_index) = invocable.has_destination_param() { + if let Some(argument_index) = invocable.destination_param_idx() { log::trace!( " -- Building call instructions for a `{}` syscall with destination", invocable.to_str() @@ -376,13 +377,30 @@ impl<'a, 'b> SysCallsInvocator<'a, 'b> { let upper_limit = mem_size.saturating_sub(100); let offset = self.unstructured.int_in_range(0..=upper_limit)?; - vec![ - // call `gsys::gr_source` with a memory offset + // 3 instructions for invoking `gsys::gr_source` and possibly 3 more + // for defining value param so HashWithValue will be constructed. + let mut ret = Vec::with_capacity(6); + ret.extend_from_slice(&[ + // call `gsys::gr_source` storing actor id and some `offset` pointer. Instruction::I32Const(offset as i32), Instruction::Call(gr_source_call_indexes_handle), - // pass the offset as the first argument to the send-call Instruction::I32Const(offset as i32), - ] + ]); + + if invocable.has_destination_param_with_value() { + // We have to skip actor id bytes to define the following value param. + let skip_bytes = mem::size_of::(); + ret.extend_from_slice(&[ + // Define 0 value for HashWithValue + Instruction::I32Const(0), + // Store value on the offset + skip_bytes. That will form HashWithValue. + Instruction::I32Store(2, skip_bytes as u32), + // Pass the offset as the first argument to the syscall with destination. + Instruction::I32Const(offset as i32), + ]); + } + + ret } else { let address_offset = match self.offsets.as_mut() { Some(offsets) => { From b5b40281104df3d4cebed397f40c0a7590b234b7 Mon Sep 17 00:00:00 2001 From: mqxf Date: Thu, 9 Nov 2023 17:27:40 +0100 Subject: [PATCH 4/6] feat(demo-constructor): Add support for `handle_signal` entry point and `system_reserve_gas` syscall. (#3469) Co-authored-by: Dmitry Novikov --- examples/constructor/src/builder.rs | 4 +++ examples/constructor/src/call.rs | 13 +++++++ .../src/scheme/demo_exit_handle.rs | 6 +++- .../constructor/src/scheme/demo_exit_init.rs | 11 +++++- examples/constructor/src/scheme/demo_ping.rs | 6 +++- .../src/scheme/demo_proxy_with_gas.rs | 11 +++++- .../src/scheme/demo_reply_deposit.rs | 5 +++ .../src/scheme/demo_wait_init_exit_reply.rs | 6 +++- examples/constructor/src/scheme/mod.rs | 27 +++++++++++--- examples/constructor/src/wasm.rs | 5 +++ pallets/gear/src/tests.rs | 36 ++++++++++++++----- 11 files changed, 112 insertions(+), 18 deletions(-) diff --git a/examples/constructor/src/builder.rs b/examples/constructor/src/builder.rs index 344eae01c72..bf871191605 100644 --- a/examples/constructor/src/builder.rs +++ b/examples/constructor/src/builder.rs @@ -325,4 +325,8 @@ impl Calls { pub fn infinite_loop(self) -> Self { self.add_call(Call::Loop) } + + pub fn system_reserve_gas(self, gas: impl Into>) -> Self { + self.add_call(Call::SystemReserveGas(gas.into())) + } } diff --git a/examples/constructor/src/call.rs b/examples/constructor/src/call.rs index 06c0fde0edb..2f14a20030c 100644 --- a/examples/constructor/src/call.rs +++ b/examples/constructor/src/call.rs @@ -42,6 +42,7 @@ pub enum Call { Wake(Arg<[u8; 32]>), MessageId, Loop, + SystemReserveGas(Arg), } #[cfg(not(feature = "wasm-wrapper"))] @@ -317,6 +318,17 @@ mod wasm { Some(msg::id().encode()) } + fn system_reserve_gas(self) -> Option> { + let Self::SystemReserveGas(gas) = self else { + unreachable!() + }; + + let gas = gas.value(); + exec::system_reserve_gas(gas).expect("Failed to reserve gas"); + + None + } + pub(crate) fn process(self, previous: Option) -> CallResult { debug!("\t[CONSTRUCTOR] >> Processing {self:?}"); let call = self.clone(); @@ -347,6 +359,7 @@ mod wasm { Call::MessageId => self.message_id(), #[allow(clippy::empty_loop)] Call::Loop => loop {}, + Call::SystemReserveGas(..) => self.system_reserve_gas(), }; (call, value) diff --git a/examples/constructor/src/scheme/demo_exit_handle.rs b/examples/constructor/src/scheme/demo_exit_handle.rs index a7b6a508057..4a6ba5a3fb2 100644 --- a/examples/constructor/src/scheme/demo_exit_handle.rs +++ b/examples/constructor/src/scheme/demo_exit_handle.rs @@ -22,6 +22,10 @@ pub fn handle_reply() -> Calls { Calls::builder().noop() } +pub fn handle_signal() -> Calls { + Calls::builder().noop() +} + pub fn scheme() -> Scheme { - Scheme::predefined(init(), handle(), handle_reply()) + Scheme::predefined(init(), handle(), handle_reply(), handle_signal()) } diff --git a/examples/constructor/src/scheme/demo_exit_init.rs b/examples/constructor/src/scheme/demo_exit_init.rs index 74a6af4f6bf..9e191c164d4 100644 --- a/examples/constructor/src/scheme/demo_exit_init.rs +++ b/examples/constructor/src/scheme/demo_exit_init.rs @@ -29,6 +29,15 @@ pub fn handle_reply() -> Calls { Calls::builder().noop() } +pub fn handle_signal() -> Calls { + Calls::builder().noop() +} + pub fn scheme(send_before_exit: bool) -> Scheme { - Scheme::predefined(init(send_before_exit), handle(), handle_reply()) + Scheme::predefined( + init(send_before_exit), + handle(), + handle_reply(), + handle_signal(), + ) } diff --git a/examples/constructor/src/scheme/demo_ping.rs b/examples/constructor/src/scheme/demo_ping.rs index c0601efbff5..d05bee2fa01 100644 --- a/examples/constructor/src/scheme/demo_ping.rs +++ b/examples/constructor/src/scheme/demo_ping.rs @@ -29,6 +29,10 @@ pub fn handle_reply() -> Calls { Calls::builder().noop() } +pub fn handle_signal() -> Calls { + Calls::builder().noop() +} + pub fn scheme() -> Scheme { - Scheme::predefined(init(), handle(), handle_reply()) + Scheme::predefined(init(), handle(), handle_reply(), handle_signal()) } diff --git a/examples/constructor/src/scheme/demo_proxy_with_gas.rs b/examples/constructor/src/scheme/demo_proxy_with_gas.rs index 70b7e2a1ba5..7b893716d5e 100644 --- a/examples/constructor/src/scheme/demo_proxy_with_gas.rs +++ b/examples/constructor/src/scheme/demo_proxy_with_gas.rs @@ -65,6 +65,15 @@ pub fn handle_reply() -> Calls { ) } +pub fn handle_signal() -> Calls { + Calls::builder().noop() +} + pub fn scheme(destination: [u8; 32], delay: u32) -> Scheme { - Scheme::predefined(init(destination, delay), handle(), handle_reply()) + Scheme::predefined( + init(destination, delay), + handle(), + handle_reply(), + handle_signal(), + ) } diff --git a/examples/constructor/src/scheme/demo_reply_deposit.rs b/examples/constructor/src/scheme/demo_reply_deposit.rs index a7313e6b23a..5de12a39092 100644 --- a/examples/constructor/src/scheme/demo_reply_deposit.rs +++ b/examples/constructor/src/scheme/demo_reply_deposit.rs @@ -31,10 +31,15 @@ pub fn handle_reply(checker: [u8; 32]) -> Calls { .send_wgas(checker, Arg::bytes(SUCCESS_MESSAGE), 10_000) } +pub fn handle_signal() -> Calls { + Calls::builder().noop() +} + pub fn scheme(checker: [u8; 32], destination: [u8; 32], gas_to_send: u64) -> Scheme { Scheme::predefined( init(), handle(destination, gas_to_send), handle_reply(checker), + handle_signal(), ) } diff --git a/examples/constructor/src/scheme/demo_wait_init_exit_reply.rs b/examples/constructor/src/scheme/demo_wait_init_exit_reply.rs index bea2b68c1b6..e44eb574f62 100644 --- a/examples/constructor/src/scheme/demo_wait_init_exit_reply.rs +++ b/examples/constructor/src/scheme/demo_wait_init_exit_reply.rs @@ -42,6 +42,10 @@ pub fn handle_reply() -> Calls { .exit(source_var) } +pub fn handle_signal() -> Calls { + Calls::builder().noop() +} + pub fn scheme() -> Scheme { - Scheme::predefined(init(), handle(), handle_reply()) + Scheme::predefined(init(), handle(), handle_reply(), handle_signal()) } diff --git a/examples/constructor/src/scheme/mod.rs b/examples/constructor/src/scheme/mod.rs index a13a3379d1a..280c5682875 100644 --- a/examples/constructor/src/scheme/mod.rs +++ b/examples/constructor/src/scheme/mod.rs @@ -26,7 +26,7 @@ pub enum Scheme { /// /// Better to use this scheme if you need common-purpose program that /// executes the same commands across different incoming payloads. - Predefined(Vec, Vec, Vec), + Predefined(Vec, Vec, Vec, Vec), } impl Scheme { @@ -38,8 +38,18 @@ impl Scheme { Self::Direct(init.calls()) } - pub fn predefined(init: Calls, handle: Calls, handle_reply: Calls) -> Self { - Self::Predefined(init.calls(), handle.calls(), handle_reply.calls()) + pub fn predefined( + init: Calls, + handle: Calls, + handle_reply: Calls, + handle_signal: Calls, + ) -> Self { + Self::Predefined( + init.calls(), + handle.calls(), + handle_reply.calls(), + handle_signal.calls(), + ) } pub fn init(&self) -> &Vec { @@ -51,14 +61,21 @@ impl Scheme { pub fn handle(&self) -> Option<&Vec> { match self { - Self::Predefined(_, handle, _) => Some(handle), + Self::Predefined(_, handle, _, _) => Some(handle), _ => None, } } pub fn handle_reply(&self) -> Option<&Vec> { match self { - Self::Predefined(_, _, handle_reply) => Some(handle_reply), + Self::Predefined(_, _, handle_reply, _) => Some(handle_reply), + _ => None, + } + } + + pub fn handle_signal(&self) -> Option<&Vec> { + match self { + Self::Predefined(_, _, _, handle_signal) => Some(handle_signal), _ => None, } } diff --git a/examples/constructor/src/wasm.rs b/examples/constructor/src/wasm.rs index 4461952ba8e..3848d0516ef 100644 --- a/examples/constructor/src/wasm.rs +++ b/examples/constructor/src/wasm.rs @@ -34,3 +34,8 @@ extern "C" fn handle() { extern "C" fn handle_reply() { process_fn(Scheme::handle_reply); } + +#[no_mangle] +extern "C" fn handle_signal() { + process_fn(Scheme::handle_signal); +} diff --git a/pallets/gear/src/tests.rs b/pallets/gear/src/tests.rs index 5ccae9dc5f5..7ad7c12cd46 100644 --- a/pallets/gear/src/tests.rs +++ b/pallets/gear/src/tests.rs @@ -167,7 +167,12 @@ fn value_counter_set_correctly_for_interruptions() { .send_value(Arg::new([0u8; 32]), Arg::new(vec![]), "value_store") .wait_for(1); - let scheme = Scheme::predefined(Calls::builder().noop(), handle, Calls::builder().noop()); + let scheme = Scheme::predefined( + Calls::builder().noop(), + handle, + Calls::builder().noop(), + Calls::builder().noop(), + ); init_logger(); new_test_ext().execute_with(|| { @@ -5937,7 +5942,12 @@ fn pause_terminated_exited_program() { let (_, terminated_pid) = submit_constructor_with_args( USER_1, DEFAULT_SALT, - Scheme::predefined(init, Default::default(), Default::default()), + Scheme::predefined( + init, + Default::default(), + Default::default(), + Default::default(), + ), 0, ); @@ -8555,7 +8565,7 @@ fn demo_constructor_is_demo_ping() { let handle_reply = Calls::builder().panic("I don't like replies"); - let scheme = Scheme::predefined(init, handle, handle_reply); + let scheme = Scheme::predefined(init, handle, handle_reply, Default::default()); // checking init let (_init_mid, constructor_id) = utils::init_constructor(scheme); @@ -14105,7 +14115,12 @@ fn double_read_works() { .load("read2") .bytes_eq("is_eq", "read1", "read2") .if_else("is_eq", noop_branch, panic_branch); - let predefined_scheme = Scheme::predefined(Default::default(), handle, Default::default()); + let predefined_scheme = Scheme::predefined( + Default::default(), + handle, + Default::default(), + Default::default(), + ); let (_, pid) = utils::init_constructor(predefined_scheme); @@ -14334,7 +14349,7 @@ fn test_send_to_terminated_from_program() { // Using `USER_2` not to pollute `USER_1` mailbox to make test easier. USER_2, b"salt1", - Scheme::predefined(init, handle, Calls::default()), + Scheme::predefined(init, handle, Calls::default(), Calls::default()), 0, ); @@ -14351,7 +14366,7 @@ fn test_send_to_terminated_from_program() { // Using `USER_2` not to pollute `USER_1` mailbox to make test easier. USER_2, b"salt2", - Scheme::predefined(Calls::default(), handle, handle_reply), + Scheme::predefined(Calls::default(), handle, handle_reply, Calls::default()), 0, ); @@ -14650,7 +14665,7 @@ fn test_gas_info_of_terminated_program() { let (_, pid_dead) = utils::submit_constructor_with_args( USER_1, b"salt1", - Scheme::predefined(init_dead, handle_dead, Calls::default()), + Scheme::predefined(init_dead, handle_dead, Calls::default(), Calls::default()), 0, ); @@ -14659,7 +14674,12 @@ fn test_gas_info_of_terminated_program() { let (_, proxy_pid) = utils::submit_constructor_with_args( USER_1, b"salt2", - Scheme::predefined(Calls::default(), handle_proxy, Calls::default()), + Scheme::predefined( + Calls::default(), + handle_proxy, + Calls::default(), + Calls::default(), + ), 0, ); From b353d0f9d34f0c7d111cb4176b69a5f1d7978fb9 Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Fri, 10 Nov 2023 06:39:01 +0300 Subject: [PATCH 5/6] fix(readme): Update binary usage examples (#3474) --- README.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index abbdd0a2f89..b5243100d5e 100644 --- a/README.md +++ b/README.md @@ -66,19 +66,25 @@ Gear node can run in a single Dev Net mode or you can create a Multi-Node local - **Linux x64**: [gear-nightly-x86_64-unknown-linux-gnu.tar.xz](https://get.gear.rs/gear-nightly-x86_64-unknown-linux-gnu.tar.xz) - **Windows x64**: [gear-nightly-x86_64-pc-windows-msvc.zip](https://get.gear.rs/gear-nightly-x86_64-pc-windows-msvc.zip) -2. Run Gear node without special arguments to get a node connected to the testnet: +2. Run Gear node without special arguments to get a node connected to the test network: ```bash gear ``` -3. One may run a local node in development mode for testing purposes. This node will not be connected to any external network. Use `--dev` argument for running the node locally and storing the state in temporary storage: +3. Connect to the Vara network: + + ```bash + gear --chain=vara + ``` + +4. One may run a local node in development mode for testing purposes. This node will not be connected to any external network. Use `--dev` argument for running the node locally and storing the state in temporary storage: ```bash gear --dev ``` -4. Get more info about usage details, flags, available options and subcommands: +5. Get more info about usage details, flags, available options and subcommands: ```bash gear --help From d723d7cb0e56a2843686ee67bec06f683e7a04a0 Mon Sep 17 00:00:00 2001 From: clearloop <26088946+clearloop@users.noreply.github.com> Date: Fri, 10 Nov 2023 19:45:14 +0800 Subject: [PATCH 6/6] docs(workspace): add favicon url for documented packages (#3478) --- common/src/lib.rs | 2 ++ core-errors/src/lib.rs | 2 ++ core-processor/src/lib.rs | 1 + core/src/lib.rs | 1 + galloc/src/lib.rs | 1 + gclient/src/lib.rs | 1 + gcore/src/lib.rs | 1 + gmeta/src/lib.rs | 1 + gsdk/src/lib.rs | 3 +++ gstd/src/lib.rs | 1 + gtest/src/lib.rs | 2 ++ lazy-pages/src/lib.rs | 2 ++ pallets/gas/src/lib.rs | 2 ++ pallets/gear-messenger/src/lib.rs | 2 ++ pallets/gear-program/src/lib.rs | 2 ++ pallets/gear-scheduler/src/lib.rs | 2 ++ pallets/gear/rpc/runtime-api/src/lib.rs | 2 ++ pallets/gear/rpc/src/lib.rs | 2 ++ pallets/gear/src/lib.rs | 2 ++ pallets/payment/src/lib.rs | 2 ++ utils/wasm-builder/src/lib.rs | 4 ++++ 21 files changed, 38 insertions(+) diff --git a/common/src/lib.rs b/common/src/lib.rs index 0f700e56d72..14c182b5dad 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -17,6 +17,8 @@ // along with this program. If not, see . #![cfg_attr(not(feature = "std"), no_std)] +#![doc(html_logo_url = "https://docs.gear.rs/logo.svg")] +#![doc(html_favicon_url = "https://gear-tech.io/favicons/favicon.ico")] #[macro_use] extern crate gear_common_codegen; diff --git a/core-errors/src/lib.rs b/core-errors/src/lib.rs index 8af87b9054c..55be7cf0198 100644 --- a/core-errors/src/lib.rs +++ b/core-errors/src/lib.rs @@ -20,6 +20,8 @@ #![no_std] #![warn(missing_docs)] +#![doc(html_logo_url = "https://docs.gear.rs/logo.svg")] +#![doc(html_favicon_url = "https://gear-tech.io/favicons/favicon.ico")] extern crate alloc; diff --git a/core-processor/src/lib.rs b/core-processor/src/lib.rs index 3e89e3e2ae0..9b63cd17dab 100644 --- a/core-processor/src/lib.rs +++ b/core-processor/src/lib.rs @@ -22,6 +22,7 @@ #![warn(missing_docs)] #![cfg_attr(feature = "strict", deny(warnings))] #![doc(html_logo_url = "https://docs.gear.rs/logo.svg")] +#![doc(html_favicon_url = "https://gear-tech.io/favicons/favicon.ico")] extern crate alloc; diff --git a/core/src/lib.rs b/core/src/lib.rs index 2458f0a4df7..cd9b6c45654 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -24,6 +24,7 @@ #![warn(missing_docs)] #![cfg_attr(feature = "strict", deny(warnings))] #![doc(html_logo_url = "https://docs.gear.rs/logo.svg")] +#![doc(html_favicon_url = "https://gear-tech.io/favicons/favicon.ico")] extern crate alloc; diff --git a/galloc/src/lib.rs b/galloc/src/lib.rs index dd3c6638f3f..8b89cf8abf2 100644 --- a/galloc/src/lib.rs +++ b/galloc/src/lib.rs @@ -19,6 +19,7 @@ #![no_std] #![cfg_attr(feature = "strict", deny(warnings))] #![doc(html_logo_url = "https://docs.gear.rs/logo.svg")] +#![doc(html_favicon_url = "https://gear-tech.io/favicons/favicon.ico")] // until https://github.com/alexcrichton/dlmalloc-rs/pull/26 is merged #[cfg(not(windows))] diff --git a/gclient/src/lib.rs b/gclient/src/lib.rs index 8a3321300bb..1a09bd621a8 100644 --- a/gclient/src/lib.rs +++ b/gclient/src/lib.rs @@ -129,6 +129,7 @@ #![warn(missing_docs)] #![cfg_attr(feature = "strict", deny(warnings))] #![doc(html_logo_url = "https://docs.gear.rs/logo.svg")] +#![doc(html_favicon_url = "https://gear-tech.io/favicons/favicon.ico")] mod api; mod utils; diff --git a/gcore/src/lib.rs b/gcore/src/lib.rs index ad3e03baf6a..ac167721177 100644 --- a/gcore/src/lib.rs +++ b/gcore/src/lib.rs @@ -66,6 +66,7 @@ #![warn(missing_docs)] #![cfg_attr(feature = "strict", deny(warnings))] #![doc(html_logo_url = "https://docs.gear.rs/logo.svg")] +#![doc(html_favicon_url = "https://gear-tech.io/favicons/favicon.ico")] #![doc(test(attr(deny(warnings), allow(unused_variables, unused_assignments))))] extern crate alloc; diff --git a/gmeta/src/lib.rs b/gmeta/src/lib.rs index 369e8baa2fc..e8db65678ea 100644 --- a/gmeta/src/lib.rs +++ b/gmeta/src/lib.rs @@ -209,6 +209,7 @@ #![no_std] #![warn(missing_docs)] #![doc(html_logo_url = "https://docs.gear.rs/logo.svg")] +#![doc(html_favicon_url = "https://gear-tech.io/favicons/favicon.ico")] extern crate alloc; diff --git a/gsdk/src/lib.rs b/gsdk/src/lib.rs index d97f0c4cff5..3ae38251b47 100644 --- a/gsdk/src/lib.rs +++ b/gsdk/src/lib.rs @@ -16,6 +16,9 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#![doc(html_logo_url = "https://docs.gear.rs/logo.svg")] +#![doc(html_favicon_url = "https://gear-tech.io/favicons/favicon.ico")] + //! Gear api pub use crate::{ api::Api, diff --git a/gstd/src/lib.rs b/gstd/src/lib.rs index e43cb0b80df..2ed7a6809b5 100644 --- a/gstd/src/lib.rs +++ b/gstd/src/lib.rs @@ -130,6 +130,7 @@ #![cfg_attr(target_arch = "wasm32", feature(alloc_error_handler))] #![cfg_attr(feature = "strict", deny(warnings))] #![doc(html_logo_url = "https://docs.gear.rs/logo.svg")] +#![doc(html_favicon_url = "https://gear-tech.io/favicons/favicon.ico")] #![doc(test(attr(deny(warnings), allow(unused_variables, unused_assignments))))] extern crate alloc; diff --git a/gtest/src/lib.rs b/gtest/src/lib.rs index fce61fbe391..ffee08b0205 100644 --- a/gtest/src/lib.rs +++ b/gtest/src/lib.rs @@ -311,6 +311,8 @@ //! assert_eq!(prog.balance(), 1000); //! ``` #![deny(missing_docs)] +#![doc(html_logo_url = "https://docs.gear.rs/logo.svg")] +#![doc(html_favicon_url = "https://gear-tech.io/favicons/favicon.ico")] mod error; mod log; diff --git a/lazy-pages/src/lib.rs b/lazy-pages/src/lib.rs index 304b826fa9d..8bd086039a6 100644 --- a/lazy-pages/src/lib.rs +++ b/lazy-pages/src/lib.rs @@ -27,6 +27,8 @@ //! It's not necessary behavior, but more simple and safe. #![allow(clippy::items_after_test_module)] +#![doc(html_logo_url = "https://docs.gear.rs/logo.svg")] +#![doc(html_favicon_url = "https://gear-tech.io/favicons/favicon.ico")] use common::{LazyPagesExecutionContext, LazyPagesRuntimeContext}; use gear_core::pages::{PageDynSize, PageNumber, PageSizeNo, WasmPage}; diff --git a/pallets/gas/src/lib.rs b/pallets/gas/src/lib.rs index 21775b42b7d..94265b83234 100644 --- a/pallets/gas/src/lib.rs +++ b/pallets/gas/src/lib.rs @@ -123,6 +123,8 @@ //! The Gear Gas Pallet doesn't depend on the `GenesisConfig`. #![cfg_attr(not(feature = "std"), no_std)] +#![doc(html_logo_url = "https://docs.gear.rs/logo.svg")] +#![doc(html_favicon_url = "https://gear-tech.io/favicons/favicon.ico")] use common::{ storage::{MapStorage, ValueStorage}, diff --git a/pallets/gear-messenger/src/lib.rs b/pallets/gear-messenger/src/lib.rs index 0c0330ec073..e20633b9eab 100644 --- a/pallets/gear-messenger/src/lib.rs +++ b/pallets/gear-messenger/src/lib.rs @@ -133,6 +133,8 @@ //! length overflow (see Gear Payment Pallet). #![cfg_attr(not(feature = "std"), no_std)] +#![doc(html_logo_url = "https://docs.gear.rs/logo.svg")] +#![doc(html_favicon_url = "https://gear-tech.io/favicons/favicon.ico")] // Runtime mock for running tests. #[cfg(test)] diff --git a/pallets/gear-program/src/lib.rs b/pallets/gear-program/src/lib.rs index f6ea7129d3e..481d976c1dc 100644 --- a/pallets/gear-program/src/lib.rs +++ b/pallets/gear-program/src/lib.rs @@ -128,6 +128,8 @@ //! The Gear Program Pallet doesn't depend on the `GenesisConfig`. #![cfg_attr(not(feature = "std"), no_std)] +#![doc(html_logo_url = "https://docs.gear.rs/logo.svg")] +#![doc(html_favicon_url = "https://gear-tech.io/favicons/favicon.ico")] use sp_std::{convert::TryInto, prelude::*}; diff --git a/pallets/gear-scheduler/src/lib.rs b/pallets/gear-scheduler/src/lib.rs index 1049aefdd1b..d022637da47 100644 --- a/pallets/gear-scheduler/src/lib.rs +++ b/pallets/gear-scheduler/src/lib.rs @@ -19,6 +19,8 @@ //! # Gear Scheduler Pallet #![cfg_attr(not(feature = "std"), no_std)] +#![doc(html_logo_url = "https://docs.gear.rs/logo.svg")] +#![doc(html_favicon_url = "https://gear-tech.io/favicons/favicon.ico")] // Runtime mock for running tests. #[cfg(test)] diff --git a/pallets/gear/rpc/runtime-api/src/lib.rs b/pallets/gear/rpc/runtime-api/src/lib.rs index 7dddda3272b..1cd1adcbda7 100644 --- a/pallets/gear/rpc/runtime-api/src/lib.rs +++ b/pallets/gear/rpc/runtime-api/src/lib.rs @@ -17,6 +17,8 @@ // along with this program. If not, see . #![cfg_attr(not(feature = "std"), no_std)] +#![doc(html_logo_url = "https://docs.gear.rs/logo.svg")] +#![doc(html_favicon_url = "https://gear-tech.io/favicons/favicon.ico")] pub use pallet_gear::{manager::HandleKind, GasInfo}; use sp_core::H256; diff --git a/pallets/gear/rpc/src/lib.rs b/pallets/gear/rpc/src/lib.rs index e0dab285f06..3f7b72c4bdb 100644 --- a/pallets/gear/rpc/src/lib.rs +++ b/pallets/gear/rpc/src/lib.rs @@ -20,6 +20,8 @@ #![allow(clippy::too_many_arguments)] #![allow(where_clauses_object_safety)] +#![doc(html_logo_url = "https://docs.gear.rs/logo.svg")] +#![doc(html_favicon_url = "https://gear-tech.io/favicons/favicon.ico")] use gear_common::Origin; use gear_core::ids::{CodeId, MessageId, ProgramId}; diff --git a/pallets/gear/src/lib.rs b/pallets/gear/src/lib.rs index 0a173351c35..28ede177994 100644 --- a/pallets/gear/src/lib.rs +++ b/pallets/gear/src/lib.rs @@ -18,6 +18,8 @@ #![cfg_attr(not(feature = "std"), no_std)] #![cfg_attr(feature = "runtime-benchmarks", recursion_limit = "1024")] +#![doc(html_logo_url = "https://docs.gear.rs/logo.svg")] +#![doc(html_favicon_url = "https://gear-tech.io/favicons/favicon.ico")] extern crate alloc; diff --git a/pallets/payment/src/lib.rs b/pallets/payment/src/lib.rs index 68e6ecaa67d..ea678fa647c 100644 --- a/pallets/payment/src/lib.rs +++ b/pallets/payment/src/lib.rs @@ -17,6 +17,8 @@ // along with this program. If not, see . #![cfg_attr(not(feature = "std"), no_std)] +#![doc(html_logo_url = "https://docs.gear.rs/logo.svg")] +#![doc(html_favicon_url = "https://gear-tech.io/favicons/favicon.ico")] use common::{storage::*, ExtractCall}; use frame_support::{ diff --git a/utils/wasm-builder/src/lib.rs b/utils/wasm-builder/src/lib.rs index 46843995653..d4642cb12e6 100644 --- a/utils/wasm-builder/src/lib.rs +++ b/utils/wasm-builder/src/lib.rs @@ -16,6 +16,10 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#![cfg_attr(feature = "strict", deny(warnings))] +#![doc(html_logo_url = "https://docs.gear.rs/logo.svg")] +#![doc(html_favicon_url = "https://gear-tech.io/favicons/favicon.ico")] + use crate::{cargo_command::CargoCommand, cargo_toolchain::Toolchain, wasm_project::WasmProject}; use anyhow::{Context, Result}; use gmeta::{Metadata, MetadataRepr};