Skip to content

Commit

Permalink
feat(starknet_integration_tests): add snapshot tx generator fn
Browse files Browse the repository at this point in the history
  • Loading branch information
noamsp-starkware committed Feb 12, 2025
1 parent 4093bd4 commit 8f46461
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
15 changes: 15 additions & 0 deletions crates/mempool_test_utils/src/starknet_api_test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,21 @@ impl MultiAccountTransactionGenerator {
Self::default()
}

pub fn snapshot(&self) -> Self {
let nonce_manager = Rc::new(RefCell::new((*self.nonce_manager.borrow()).clone()));
let account_tx_generators = self
.account_tx_generators
.iter()
.map(|tx_gen| AccountTransactionGenerator {
account: tx_gen.account,
nonce_manager: nonce_manager.clone(),
contract_address_salt: tx_gen.contract_address_salt,
})
.collect();

Self { account_tx_generators, nonce_manager }
}

/// Registers a new account with the given contract, assuming it is already deployed.
/// Note: the state should reflect that the account is already deployed.
pub fn register_deployed_account(&mut self, account_contract: FeatureContract) -> AccountId {
Expand Down
2 changes: 1 addition & 1 deletion crates/starknet_api/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub struct TransactionTestData {
pub block_number: BlockNumber,
}

#[derive(Debug, Default)]
#[derive(Debug, Default, Clone)]
pub struct NonceManager {
next_nonce: HashMap<ContractAddress, Felt>,
}
Expand Down
8 changes: 8 additions & 0 deletions crates/starknet_integration_tests/src/sequencer_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,14 @@ impl IntegrationTestManager {
Self { node_indices, idle_nodes, running_nodes, tx_generator }
}

pub fn tx_generator(&self) -> &MultiAccountTransactionGenerator {
&self.tx_generator
}

pub fn tx_generator_mut(&mut self) -> &mut MultiAccountTransactionGenerator {
&mut self.tx_generator
}

pub async fn run_nodes(&mut self, nodes_to_run: HashSet<usize>) {
info!("Running specified nodes.");

Expand Down

0 comments on commit 8f46461

Please sign in to comment.