Skip to content

Commit

Permalink
chore(tests): Adjust block_max_gas_works test of gear-authorship (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
gshep authored Sep 19, 2023
1 parent ee5ce18 commit 3e3254e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 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.

4 changes: 3 additions & 1 deletion node/authorship/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand All @@ -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"] }
40 changes: 30 additions & 10 deletions node/authorship/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -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<B: BlockT>(header: B::Header) -> ChainEvent<B>
where
Expand Down Expand Up @@ -91,7 +94,7 @@ fn checked_extrinsics(n: u32, signer: AccountId, nonce: &mut u32) -> Vec<Checked
code: WASM_BINARY.to_vec(),
salt: salt.as_bytes().to_vec(),
init_payload: (i as u64).encode(),
gas_limit: 500_000_000,
gas_limit: DEFAULT_GAS_LIMIT,
value: 0,
}),
};
Expand Down Expand Up @@ -513,8 +516,8 @@ fn block_max_gas_works() {

init_logger();

const INIT_MSG_GAS_LIMIT: u64 = 500_000_000;
const MAX_GAS: u64 = 2 * INIT_MSG_GAS_LIMIT + 25_000_100; // Enough to fit 2 messages
// Enough to fit 2 messages
const MAX_GAS: u64 = 2 * DEFAULT_GAS_LIMIT + 25_000_100;

let client_builder = TestClientBuilder::new()
.set_execution_strategy(sc_client_api::ExecutionStrategy::NativeWhenPossible);
Expand Down Expand Up @@ -621,15 +624,32 @@ fn block_max_gas_works() {
let mut queue_entry_args = IterArgs::default();
queue_entry_args.prefix = Some(&queue_entry_prefix);

let mut queue_len = 0_u32;

state
.keys(queue_entry_args)
.unwrap()
.for_each(|_k| queue_len += 1);
let queue_len = state.keys(queue_entry_args).unwrap().count();

// 2 out of 5 messages have been processed, 3 remain in the queue
assert_eq!(queue_len, 3);

let programs_prefix = storage_prefix(
pallet_gear_program::Pallet::<Runtime>::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::<BlockNumber>::decode(&mut &value[..]) {
Ok(p) if p.is_initialized() => count + 1,
_ => count,
}
});
assert_eq!(inited_count, 2);
}

#[test]
Expand Down

0 comments on commit 3e3254e

Please sign in to comment.