Skip to content

Commit 7ed8d4a

Browse files
apollo_integration_tests: use validate_tx_count accross integration tests (#11503)
1 parent 26571b0 commit 7ed8d4a

File tree

3 files changed

+15
-23
lines changed

3 files changed

+15
-23
lines changed

crates/apollo_integration_tests/tests/common/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ pub async fn end_to_end_flow(args: EndToEndFlowArgs) {
177177
pub struct TestScenario {
178178
pub create_rpc_txs_fn: CreateRpcTxsFn,
179179
pub create_l1_to_l2_messages_args_fn: CreateL1ToL2MessagesArgsFn,
180+
// TODO(Arni): replace with an optional apply shuffle to the tx hashes + a length assertion
181+
// parameter.
180182
pub test_tx_hashes_fn: TestTxHashesFn,
181183
}
182184

@@ -235,11 +237,9 @@ async fn wait_for_sequencer_node(sequencer: &FlowSequencerSetup) {
235237
}
236238

237239
pub fn test_single_tx(tx_hashes: &[TransactionHash]) -> Vec<TransactionHash> {
238-
assert_eq!(tx_hashes.len(), 1, "Expected a single transaction");
239-
tx_hashes.to_vec()
240+
validate_tx_count(tx_hashes, 1)
240241
}
241242

242-
/// TODO(Itamar): Use this function in all tests built with TestScenario struct.
243243
#[track_caller]
244244
pub fn validate_tx_count(
245245
tx_hashes: &[TransactionHash],

crates/apollo_integration_tests/tests/end_to_end_flow_test.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ use mempool_test_utils::starknet_api_test_utils::MultiAccountTransactionGenerato
1111
use starknet_api::rpc_transaction::RpcTransaction;
1212
use starknet_api::transaction::{L1HandlerTransaction, TransactionHash};
1313

14-
use crate::common::{end_to_end_flow, test_single_tx, EndToEndFlowArgs, TestScenario};
14+
use crate::common::{
15+
end_to_end_flow,
16+
test_single_tx,
17+
validate_tx_count,
18+
EndToEndFlowArgs,
19+
TestScenario,
20+
};
1521

1622
mod common;
1723

@@ -49,7 +55,7 @@ fn create_test_scenarios() -> Vec<TestScenario> {
4955
TestScenario {
5056
create_rpc_txs_fn: deploy_account_and_invoke,
5157
create_l1_to_l2_messages_args_fn: |_| vec![],
52-
test_tx_hashes_fn: test_two_txs,
58+
test_tx_hashes_fn: |tx_hashes| validate_tx_count(tx_hashes, 2),
5359
},
5460
TestScenario {
5561
create_rpc_txs_fn: create_declare_tx,
@@ -112,11 +118,6 @@ fn deploy_account_and_invoke(
112118
create_deploy_account_tx_and_invoke_tx(tx_generator, UNDEPLOYED_ACCOUNT_ID)
113119
}
114120

115-
fn test_two_txs(tx_hashes: &[TransactionHash]) -> Vec<TransactionHash> {
116-
assert_eq!(tx_hashes.len(), 2, "Expected two transactions");
117-
tx_hashes.to_vec()
118-
}
119-
120121
fn create_declare_tx(tx_generator: &mut MultiAccountTransactionGenerator) -> Vec<RpcTransaction> {
121122
let account_tx_generator = tx_generator.account_with_id_mut(ACCOUNT_ID_0);
122123
let declare_tx = account_tx_generator.generate_declare_of_contract_class();

crates/apollo_integration_tests/tests/test_many.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ use apollo_integration_tests::utils::{create_invoke_txs, ACCOUNT_ID_1};
33
use mempool_test_utils::starknet_api_test_utils::MultiAccountTransactionGenerator;
44
use starknet_api::execution_resources::GasAmount;
55
use starknet_api::rpc_transaction::RpcTransaction;
6-
use starknet_api::transaction::TransactionHash;
76

8-
use crate::common::{end_to_end_flow, EndToEndFlowArgs, TestScenario};
7+
use crate::common::{end_to_end_flow, validate_tx_count, EndToEndFlowArgs, TestScenario};
98

109
mod common;
1110

11+
const N_TXS: usize = 15;
12+
1213
/// This test checks that at least one block is full.
1314
/// The test uses 3 threads: 1 for the test's main thread and 2 for the sequencers.
1415
#[tokio::test(flavor = "multi_thread", worker_threads = 3)]
@@ -29,23 +30,13 @@ fn create_many_txs_scenario() -> Vec<TestScenario> {
2930
vec![TestScenario {
3031
create_rpc_txs_fn: create_many_invoke_txs,
3132
create_l1_to_l2_messages_args_fn: |_| vec![],
32-
test_tx_hashes_fn: test_many_invoke_txs,
33+
test_tx_hashes_fn: |tx_hashes| validate_tx_count(tx_hashes, N_TXS),
3334
}]
3435
}
3536

36-
pub fn test_many_invoke_txs(tx_hashes: &[TransactionHash]) -> Vec<TransactionHash> {
37-
assert!(
38-
tx_hashes.len() == 15,
39-
"Unexpected number of transactions sent in the test scenario. Found {} transactions",
40-
tx_hashes.len()
41-
);
42-
tx_hashes.to_vec()
43-
}
44-
4537
/// Creates and sends more transactions than can fit in a block.
4638
pub fn create_many_invoke_txs(
4739
tx_generator: &mut MultiAccountTransactionGenerator,
4840
) -> Vec<RpcTransaction> {
49-
const N_TXS: usize = 15;
5041
create_invoke_txs(tx_generator, ACCOUNT_ID_1, N_TXS)
5142
}

0 commit comments

Comments
 (0)