From 9d32b41f22f2c57aa3706039a829b797ad00bf0b Mon Sep 17 00:00:00 2001 From: ekovalev Date: Sat, 19 Aug 2023 22:57:34 +0400 Subject: [PATCH] fix(authorship): Forward-fix a test that will require the gear-bank account to exist (#3118) --- Cargo.lock | 1 + node/authorship/Cargo.toml | 1 + node/authorship/src/tests.rs | 50 ++++++++++++++++++++++++++---------- 3 files changed, 38 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 91e904a5fa0..7da3b19afde 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3677,6 +3677,7 @@ dependencies = [ "gear-node-testing", "gear-runtime-primitives", "log", + "pallet-balances", "pallet-gear", "pallet-gear-messenger", "pallet-gear-rpc-runtime-api", diff --git a/node/authorship/Cargo.toml b/node/authorship/Cargo.toml index 3dabd4fc783..d8a95695478 100644 --- a/node/authorship/Cargo.toml +++ b/node/authorship/Cargo.toml @@ -52,6 +52,7 @@ sp-consensus-babe = { workspace = true, features = ["std"] } sp-state-machine = { workspace = true, features = ["std"] } pallet-sudo = { workspace = true, features = ["std"] } 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"] } testing.workspace = true diff --git a/node/authorship/src/tests.rs b/node/authorship/src/tests.rs index 775062f6018..cd9cf21fa08 100644 --- a/node/authorship/src/tests.rs +++ b/node/authorship/src/tests.rs @@ -101,6 +101,19 @@ fn checked_extrinsics(n: u32, signer: AccountId, nonce: &mut u32) -> Vec RuntimeCall { + RuntimeCall::Sudo(pallet_sudo::Call::sudo { + call: Box::new(RuntimeCall::Balances(pallet_balances::Call::set_balance { + who: sp_runtime::MultiAddress::Id(AccountId::from(BANK_ADDRESS)), + new_free: 1_000_000_000_000_000, + new_reserved: 0, + })), + }) +} + pub(crate) fn init_logger() { let _ = env_logger::Builder::from_default_env() .format_module_path(false) @@ -519,19 +532,28 @@ fn block_max_gas_works() { let genesis_hash = <[u8; 32]>::try_from(&client.info().best_hash[..]).expect("H256 is a 32 byte type"); let mut nonce = 0_u32; + // Create an extrinsic that prefunds the bank account + let pre_fund_bank_xt = sign( + CheckedExtrinsic { + signed: Some((alice(), signed_extra(0))), + function: pre_fund_bank_account_call(), + }, + VERSION.spec_version, + VERSION.transaction_version, + genesis_hash, + ); + + let mut extrinsics = vec![pre_fund_bank_xt.into()]; // Creating 5 extrinsics - let extrinsics = checked_extrinsics(5, bob(), &mut nonce) - .iter() - .map(|x| { - sign( - x.clone(), - VERSION.spec_version, - VERSION.transaction_version, - genesis_hash, - ) - .into() - }) - .collect::>(); + extrinsics.extend(checked_extrinsics(5, bob(), &mut nonce).iter().map(|x| { + sign( + x.clone(), + VERSION.spec_version, + VERSION.transaction_version, + genesis_hash, + ) + .into() + })); block_on(txpool.submit_at(&BlockId::number(0), SOURCE, extrinsics)).unwrap(); @@ -581,8 +603,8 @@ fn block_max_gas_works() { )) .unwrap(); - // All extrinsics have been included in the block: 1 inherent + 5 normal + 1 terminal - assert_eq!(proposal.block.extrinsics().len(), 7); + // All extrinsics have been included in the block: 1 inherent + sudo + 5 normal + 1 terminal + assert_eq!(proposal.block.extrinsics().len(), 8); // Importing block #1 block_on(client.import(BlockOrigin::Own, proposal.block.clone())).unwrap();