Skip to content

Commit

Permalink
test(starknet_integration_tests): add deploy_tx to the integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
Yael-Starkware committed Feb 2, 2025
1 parent 4c9f573 commit 2f4d4a7
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 10 deletions.
16 changes: 13 additions & 3 deletions crates/starknet_integration_tests/src/end_to_end_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use starknet_api::block::BlockNumber;
use starknet_sequencer_node::test_utils::node_runner::get_node_executable_path;
use tracing::info;

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

pub async fn end_to_end_integration(tx_generator: &mut MultiAccountTransactionGenerator) {
const EXPECTED_BLOCK_NUMBER: BlockNumber = BlockNumber(15);
Expand All @@ -30,11 +31,18 @@ pub async fn end_to_end_integration(tx_generator: &mut MultiAccountTransactionGe
// Run the nodes.
integration_test_manager.run(node_indices).await;

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

// Run the test.
integration_test_manager
.test_and_verify(
tx_generator,
0,
// TODO(Yael): consider removing this parameter and take it from the tx_generator
// instead.
N_TXS_IN_FIRST_BLOCK,
InvokeTxs(N_TXS),
SENDER_ACCOUNT,
EXPECTED_BLOCK_NUMBER,
Expand All @@ -48,7 +56,7 @@ 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,
Expand All @@ -57,4 +65,6 @@ pub async fn end_to_end_integration(tx_generator: &mut MultiAccountTransactionGe

info!("Shutting down nodes.");
integration_test_manager.shutdown_nodes();

info!("TEST PASSED");
}
7 changes: 4 additions & 3 deletions crates/starknet_integration_tests/src/sequencer_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,14 @@ impl IntegrationTestManager {
// Verify the initial state
self.verify_results(
tx_generator.account_with_id(sender_account).sender_address(),
expected_initial_value + 1,
expected_initial_value,
)
.await;
self.run_integration_test_simulator(tx_generator, &test_scenario, sender_account).await;
self.await_execution(expected_block_number).await;
self.verify_results(
tx_generator.account_with_id(sender_account).sender_address(),
expected_initial_value + test_scenario.n_txs() + 1,
expected_initial_value + test_scenario.n_txs(),
)
.await;
}
Expand Down Expand Up @@ -330,7 +330,8 @@ fn get_account_nonce(storage_reader: &StorageReader, contract_address: ContractA
let state_number = StateNumber::unchecked_right_after_block(block_number);
get_nonce_at(&txn, state_number, None, contract_address)
.expect("Should always be Ok(Some(Nonce))")
.expect("Should always be Some(Nonce)")
// If the none is None, it means that the account was not deployed yet and it's nonce is 0.
.unwrap_or_default()
}

/// Sample a storage until sufficiently many blocks have been stored. Returns an error if after
Expand Down
21 changes: 19 additions & 2 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 @@ -240,11 +240,28 @@ 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();

for (i, account) in [
FeatureContract::AccountWithoutValidations(CairoVersion::Cairo1(RunnableCairo1::Casm)),
FeatureContract::AccountWithoutValidations(CairoVersion::Cairo0),
]
.iter()
.enumerate()
{
tx_generator.register_undeployed_account(*account, ContractAddressSalt(Felt::from(i)));
}
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 @@ -20,8 +20,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 @@ -38,7 +38,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 2f4d4a7

Please sign in to comment.