Skip to content

Commit

Permalink
Merge branch 'master' into cl/issue-2832
Browse files Browse the repository at this point in the history
  • Loading branch information
clearloop committed Nov 11, 2023
2 parents a2e76e6 + d723d7c commit 7a07875
Show file tree
Hide file tree
Showing 62 changed files with 663 additions and 906 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ std = [
"sp-io/std",
"sp-arithmetic/std",
"frame-support/std",
"frame-system/std",
"primitive-types/std",
"gear-wasm-instrument?/std",
]
Expand Down
5 changes: 5 additions & 0 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

#![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;
Expand All @@ -39,6 +41,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},
Expand Down
149 changes: 149 additions & 0 deletions common/src/pallet_tests.rs
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.

//! 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<Self::AccountId>;
type Header = generic::Header<BlockNumber, BlakeTwo256>;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = BlockHashCount;
type Version = ();
type PalletInfo = PalletInfo;
type AccountData = pallet_balances::AccountData<Balance>;
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<AccountId> for FixedBlockAuthor {
fn find_author<'a, I: 'a>(_: I) -> Option<AccountId> {
Some(BLOCK_AUTHOR)
}
}

impl pallet_authorship::Config for $runtime {
type FindAuthor = FixedBlockAuthor;
type EventHandler = $event_handler;
}
};

($runtime:ty) => {
$crate::impl_pallet_authorship!($runtime, EventHandler = ());
};
}
2 changes: 2 additions & 0 deletions core-errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions core-processor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 4 additions & 0 deletions examples/constructor/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Arg<u64>>) -> Self {
self.add_call(Call::SystemReserveGas(gas.into()))
}
}
13 changes: 13 additions & 0 deletions examples/constructor/src/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ pub enum Call {
Wake(Arg<[u8; 32]>),
MessageId,
Loop,
SystemReserveGas(Arg<u64>),
}

#[cfg(not(feature = "wasm-wrapper"))]
Expand Down Expand Up @@ -317,6 +318,17 @@ mod wasm {
Some(msg::id().encode())
}

fn system_reserve_gas(self) -> Option<Vec<u8>> {
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>) -> CallResult {
debug!("\t[CONSTRUCTOR] >> Processing {self:?}");
let call = self.clone();
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion examples/constructor/src/scheme/demo_exit_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
11 changes: 10 additions & 1 deletion examples/constructor/src/scheme/demo_exit_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
)
}
6 changes: 5 additions & 1 deletion examples/constructor/src/scheme/demo_ping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
11 changes: 10 additions & 1 deletion examples/constructor/src/scheme/demo_proxy_with_gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
)
}
5 changes: 5 additions & 0 deletions examples/constructor/src/scheme/demo_reply_deposit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
)
}
6 changes: 5 additions & 1 deletion examples/constructor/src/scheme/demo_wait_init_exit_reply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Loading

0 comments on commit 7a07875

Please sign in to comment.