Skip to content

Commit

Permalink
test(starknet_integration_tests): fund contract address for deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
yair-starkware committed Dec 19, 2024
1 parent faabd11 commit bc8d70b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
7 changes: 5 additions & 2 deletions crates/mempool_test_utils/src/starknet_api_test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ impl MultiAccountTransactionGenerator {

/// Registers a new account with the given contract, assuming it is already deployed.
/// Note: the state should reflect it if the account is already deployed.
pub fn register_deployed_account(&mut self, account_contract: FeatureContract) {
pub fn register_deployed_account(&mut self, account_contract: FeatureContract) -> AccountId {
let new_account_id = self.account_tx_generators.len();
let salt = ContractAddressSalt(new_account_id.into());
let (account_tx_generator, _default_deploy_account_tx) = AccountTransactionGenerator::new(
Expand All @@ -227,21 +227,24 @@ impl MultiAccountTransactionGenerator {
true,
);
self.account_tx_generators.push(account_tx_generator);
new_account_id
}

/// Registers a new undeployed account with the given contract.
pub fn register_undeployed_account(
&mut self,
account_contract: FeatureContract,
contract_address_salt: ContractAddressSalt,
) {
) -> AccountId {
let new_account_id = self.account_tx_generators.len();
let (account_tx_generator, _default_deploy_account_tx) = AccountTransactionGenerator::new(
account_contract,
self.nonce_manager.clone(),
contract_address_salt,
false,
);
self.account_tx_generators.push(account_tx_generator);
new_account_id
}

pub fn account_with_id_mut(
Expand Down
6 changes: 3 additions & 3 deletions crates/starknet_integration_tests/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ use starknet_sequencer_node::config::test_utils::RequiredParams;
use starknet_state_sync::config::StateSyncConfig;
use starknet_types_core::felt::Felt;

pub const ACCOUNT_ID_0: AccountId = 0;
pub const ACCOUNT_ID_1: AccountId = 1;

// TODO(Tsabary): Get rid of this constant once we have a better way to set the port for testing.
const STATE_SYNC_NETWORK_CONFIG_TCP_PORT_FOR_TESTING: u16 = 12345;

Expand Down Expand Up @@ -160,9 +163,6 @@ pub fn create_integration_test_tx_generator() -> MultiAccountTransactionGenerato
pub fn create_txs_for_integration_test(
tx_generator: &mut MultiAccountTransactionGenerator,
) -> Vec<RpcTransaction> {
const ACCOUNT_ID_0: AccountId = 0;
const ACCOUNT_ID_1: AccountId = 1;

// Create RPC transactions.
let account0_invoke_nonce1 =
tx_generator.account_with_id_mut(ACCOUNT_ID_0).generate_invoke_with_tip(2);
Expand Down
29 changes: 26 additions & 3 deletions crates/starknet_integration_tests/tests/end_to_end_flow_test.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::collections::HashSet;

use blockifier::test_utils::contracts::FeatureContract;
use blockifier::test_utils::{CairoVersion, RunnableCairo1};
use futures::StreamExt;
use mempool_test_utils::starknet_api_test_utils::MultiAccountTransactionGenerator;
use papyrus_consensus::types::ValidatorId;
Expand All @@ -15,20 +17,24 @@ use papyrus_storage::test_utils::CHAIN_ID_FOR_TESTS;
use pretty_assertions::assert_eq;
use rstest::{fixture, rstest};
use starknet_api::block::{BlockHash, BlockNumber};
use starknet_api::rpc_transaction::RpcTransaction;
use starknet_api::transaction::fields::ContractAddressSalt;
use starknet_api::transaction::TransactionHash;
use starknet_integration_tests::flow_test_setup::FlowTestSetup;
use starknet_integration_tests::utils::{
create_integration_test_tx_generator,
create_txs_for_integration_test,
run_integration_test_scenario,
test_tx_hashes_for_integration_test,
ACCOUNT_ID_0,
};
use starknet_sequencer_infra::trace_util::configure_tracing;
use starknet_types_core::felt::Felt;
use tracing::debug;

const INITIAL_HEIGHT: BlockNumber = BlockNumber(0);
const LAST_HEIGHT: BlockNumber = BlockNumber(2);
const LAST_HEIGHT: BlockNumber = BlockNumber(3);
const NEW_ACCOUNT_SALT: ContractAddressSalt = ContractAddressSalt(Felt::THREE);

#[fixture]
fn tx_generator() -> MultiAccountTransactionGenerator {
Expand Down Expand Up @@ -65,10 +71,10 @@ async fn end_to_end_flow(mut tx_generator: MultiAccountTransactionGenerator) {
expected_proposer_iter.next().unwrap();

let create_rpc_txs_scenarios =
[create_txs_for_integration_test, create_txs_for_integration_test];
[create_txs_for_integration_test, create_txs_for_integration_test, fund_new_account];

let test_tx_hashes_scenarios =
[test_tx_hashes_for_integration_test, test_tx_hashes_for_integration_test];
[test_tx_hashes_for_integration_test, test_tx_hashes_for_integration_test, test_funding];

assert_eq!(
n_heights,
Expand Down Expand Up @@ -214,3 +220,20 @@ async fn listen_to_broadcasted_messages(
"Unexpected transactions"
);
}

fn fund_new_account(tx_generator: &mut MultiAccountTransactionGenerator) -> Vec<RpcTransaction> {
let new_account_id = tx_generator.register_undeployed_account(
FeatureContract::AccountWithoutValidations(CairoVersion::Cairo1(RunnableCairo1::Casm)),
NEW_ACCOUNT_SALT,
);

let to = tx_generator.account_with_id(new_account_id).account;

let funding_tx = tx_generator.account_with_id_mut(ACCOUNT_ID_0).generate_transfer(&to);
vec![funding_tx]
}

fn test_funding(tx_hashes: &[TransactionHash]) -> Vec<TransactionHash>{
assert_eq!(tx_hashes.len(), 1, "Expected a single transaction");
tx_hashes.to_vec()
}

0 comments on commit bc8d70b

Please sign in to comment.