From 3e3254e4734c16d20f2a9eead58ea854f249bc12 Mon Sep 17 00:00:00 2001 From: Georgy Shepelev Date: Tue, 19 Sep 2023 16:44:19 +0400 Subject: [PATCH] chore(tests): Adjust `block_max_gas_works` test of gear-authorship (#3300) --- Cargo.lock | 1 + node/authorship/Cargo.toml | 4 +++- node/authorship/src/tests.rs | 40 +++++++++++++++++++++++++++--------- 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3041ea8580e..9fe9a6d4da1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3754,6 +3754,7 @@ dependencies = [ "pallet-balances", "pallet-gear", "pallet-gear-messenger", + "pallet-gear-program", "pallet-gear-rpc-runtime-api", "pallet-sudo", "pallet-timestamp", diff --git a/node/authorship/Cargo.toml b/node/authorship/Cargo.toml index 7b474e043a6..2e59fc84df7 100644 --- a/node/authorship/Cargo.toml +++ b/node/authorship/Cargo.toml @@ -42,6 +42,7 @@ frame-system = { workspace = true, features = ["std"] } prometheus-endpoint.workspace = true [dev-dependencies] +common = { workspace = true, features = ["std"] } sc-transaction-pool.workspace = true frame-support = { workspace = true, features = ["std"] } sp-io = { workspace = true, features = ["std"] } @@ -54,8 +55,9 @@ pallet-timestamp = { workspace = true, features = ["std"] } pallet-balances = { workspace = true, features = ["std"] } pallet-gear = { workspace = true, features = ["std"] } pallet-gear-messenger = { workspace = true, features = ["std"] } +pallet-gear-program = { workspace = true, features = ["std"] } testing = {workspace = true, features = ["vara-native"] } vara-runtime = { workspace = true, features = ["std", "dev"] } -demo-mul-by-const.workspace = true +demo-mul-by-const = { workspace = true, features = ["debug"] } env_logger.workspace = true service = { workspace = true, features = ["dev", "vara-native"] } diff --git a/node/authorship/src/tests.rs b/node/authorship/src/tests.rs index afbc17b4bbd..c845fbbf692 100644 --- a/node/authorship/src/tests.rs +++ b/node/authorship/src/tests.rs @@ -23,10 +23,12 @@ use crate::authorship::*; -use codec::Encode; +use codec::{Decode, Encode}; +use common::Program; use core::convert::TryFrom; use frame_support::{storage::storage_prefix, traits::PalletInfoAccess}; use futures::executor::block_on; +use runtime_primitives::BlockNumber; use sc_client_api::Backend; use sc_transaction_pool::BasicPool; use sc_transaction_pool_api::{ @@ -53,6 +55,7 @@ use testing::{ use vara_runtime::{AccountId, Runtime, RuntimeCall, UncheckedExtrinsic, SLOT_DURATION, VERSION}; const SOURCE: TransactionSource = TransactionSource::External; +const DEFAULT_GAS_LIMIT: u64 = 865_000_000; fn chain_event(header: B::Header) -> ChainEvent where @@ -91,7 +94,7 @@ fn checked_extrinsics(n: u32, signer: AccountId, nonce: &mut u32) -> Vec::name().as_bytes(), + "ProgramStorage".as_bytes(), + ); + let mut iter_args = IterArgs::default(); + iter_args.prefix = Some(&programs_prefix); + + // The fact that 2 init messages out of 5 have been processed means + // that there should be 2 inited programs. + let inited_count = state.pairs(iter_args).unwrap().fold(0u32, |count, pair| { + let value = match pair { + Ok((_key, value)) => value, + _ => return count, + }; + + match Program::::decode(&mut &value[..]) { + Ok(p) if p.is_initialized() => count + 1, + _ => count, + } + }); + assert_eq!(inited_count, 2); } #[test]