Skip to content

Commit

Permalink
test(starknet_integration_tests): add deploy_tx to the integration te…
Browse files Browse the repository at this point in the history
…st (#3803)
  • Loading branch information
Yael-Starkware authored Feb 3, 2025
1 parent dc13926 commit fca1ca8
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 14 deletions.
26 changes: 20 additions & 6 deletions crates/starknet_integration_tests/src/end_to_end_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ use starknet_sequencer_node::test_utils::node_runner::get_node_executable_path;
use tracing::info;

use crate::sequencer_manager::{get_sequencer_setup_configs, IntegrationTestManager};
use crate::utils::InvokeTxs;
use crate::utils::{BootstrapTxs, InvokeTxs, N_TXS_IN_FIRST_BLOCK};

pub async fn end_to_end_integration(tx_generator: &mut MultiAccountTransactionGenerator) {
const EXPECTED_BLOCK_NUMBER: BlockNumber = BlockNumber(10);
const LATE_NODE_EXPECTED_BLOCK_NUMBER: BlockNumber = BlockNumber(25);
const BLOCK_TO_WAIT_FOR_BOOTSTRAP: BlockNumber = BlockNumber(2);
const BLOCK_TO_WAIT_FOR_FIRST_ROUND: BlockNumber = BlockNumber(10);
const BLOCK_TO_WAIT_FOR_LATE_NODE: BlockNumber = BlockNumber(25);
const N_TXS: usize = 50;
const SENDER_ACCOUNT: AccountId = 0;
/// The number of consolidated local sequencers that participate in the test.
Expand Down Expand Up @@ -41,9 +42,22 @@ pub async fn end_to_end_integration(tx_generator: &mut MultiAccountTransactionGe
// Run the nodes.
integration_test_manager.run(filtered_nodes).await;

// Run the first block scenario to bootstrap the accounts.
integration_test_manager
.test_and_verify(tx_generator, 0, BootstrapTxs, SENDER_ACCOUNT, BLOCK_TO_WAIT_FOR_BOOTSTRAP)
.await;

// Run the test.
integration_test_manager
.test_and_verify(tx_generator, 0, InvokeTxs(N_TXS), SENDER_ACCOUNT, EXPECTED_BLOCK_NUMBER)
.test_and_verify(
tx_generator,
// TODO(Yael): consider removing this parameter and take it from the tx_generator
// instead.
N_TXS_IN_FIRST_BLOCK,
InvokeTxs(N_TXS),
SENDER_ACCOUNT,
BLOCK_TO_WAIT_FOR_FIRST_ROUND,
)
.await;

// Run the late node.
Expand All @@ -53,10 +67,10 @@ pub async fn end_to_end_integration(tx_generator: &mut MultiAccountTransactionGe
integration_test_manager
.test_and_verify(
tx_generator,
N_TXS,
N_TXS + N_TXS_IN_FIRST_BLOCK,
InvokeTxs(N_TXS),
SENDER_ACCOUNT,
LATE_NODE_EXPECTED_BLOCK_NUMBER,
BLOCK_TO_WAIT_FOR_LATE_NODE,
)
.await;

Expand Down
4 changes: 2 additions & 2 deletions crates/starknet_integration_tests/src/sequencer_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,12 @@ impl IntegrationTestManager {
expected_initial_value: usize,
test_scenario: impl TestScenario,
sender_account: AccountId,
expected_block_number: BlockNumber,
wait_for_block: BlockNumber,
) {
// Verify the initial state
self.verify_results(expected_initial_value).await;
self.run_integration_test_simulator(tx_generator, &test_scenario, sender_account).await;
self.await_execution(expected_block_number).await;
self.await_execution(wait_for_block).await;
self.verify_results(expected_initial_value + test_scenario.n_txs()).await;
}

Expand Down
19 changes: 15 additions & 4 deletions crates/starknet_integration_tests/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub const UNDEPLOYED_ACCOUNT_ID: AccountId = 2;
// Transactions per second sent to the gateway. This rate makes each block contain ~10 transactions
// with the set [TimeoutsConfig] .
pub const TPS: u64 = 2;
const N_TXS_IN_FIRST_BLOCK: usize = 2;
pub const N_TXS_IN_FIRST_BLOCK: usize = 2;

pub trait TestScenario {
fn create_txs(
Expand Down Expand Up @@ -87,9 +87,9 @@ impl TestScenario for InvokeTxs {
}
}

pub struct FirstBlock;
pub struct BootstrapTxs;

impl TestScenario for FirstBlock {
impl TestScenario for BootstrapTxs {
fn create_txs(
&self,
tx_generator: &mut MultiAccountTransactionGenerator,
Expand Down Expand Up @@ -241,11 +241,22 @@ pub fn create_mempool_p2p_configs(chain_id: ChainId, ports: Vec<u16>) -> Vec<Mem
.collect()
}

/// Creates a multi-account transaction generator for integration tests.
/// Creates a multi-account transaction generator for the integration test.
pub fn create_integration_test_tx_generator() -> MultiAccountTransactionGenerator {
let mut tx_generator: MultiAccountTransactionGenerator =
MultiAccountTransactionGenerator::new();

let account =
FeatureContract::AccountWithoutValidations(CairoVersion::Cairo1(RunnableCairo1::Casm));
tx_generator.register_undeployed_account(account, ContractAddressSalt(Felt::ZERO));
tx_generator
}

/// Creates a multi-account transaction generator for the flow test.
pub fn create_flow_test_tx_generator() -> MultiAccountTransactionGenerator {
let mut tx_generator: MultiAccountTransactionGenerator =
MultiAccountTransactionGenerator::new();

for account in [
FeatureContract::AccountWithoutValidations(CairoVersion::Cairo1(RunnableCairo1::Casm)),
FeatureContract::AccountWithoutValidations(CairoVersion::Cairo0),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ use starknet_infra_utils::test_utils::TestIdentifier;
use starknet_integration_tests::flow_test_setup::{FlowSequencerSetup, FlowTestSetup};
use starknet_integration_tests::utils::{
create_deploy_account_tx_and_invoke_tx,
create_flow_test_tx_generator,
create_funding_txs,
create_integration_test_tx_generator,
create_many_invoke_txs,
create_multiple_account_txs,
run_test_scenario,
Expand All @@ -41,7 +41,7 @@ const LAST_HEIGHT: BlockNumber = BlockNumber(4);

#[fixture]
fn tx_generator() -> MultiAccountTransactionGenerator {
create_integration_test_tx_generator()
create_flow_test_tx_generator()
}

#[rstest]
Expand Down

0 comments on commit fca1ca8

Please sign in to comment.