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 29b607b commit c65e8d4
Show file tree
Hide file tree
Showing 3 changed files with 37 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 @@ -212,7 +212,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 @@ -222,21 +222,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 @@ -37,6 +37,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;

pub fn create_chain_info() -> ChainInfo {
let mut chain_info = ChainInfo::create_for_testing();
// Note that the chain_id affects hashes of transactions and blocks, therefore affecting the
Expand Down Expand Up @@ -156,9 +159,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
32 changes: 29 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, SequencerSetup};
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 @@ -60,6 +66,9 @@ async fn end_to_end_flow(mut tx_generator: MultiAccountTransactionGenerator) {
Felt::from_hex_unchecked(
"0x572373fe992ac8c2413d5e727036316023ed6a2e8a2256b4952e223969e0221",
),
Felt::from_hex_unchecked(
"0x36e1f3e0c71b77474494a5baa0a04a4e406626141eba2b2944e4b568f70ff48",
),
];

let sequencers = [&mock_running_system.sequencer_0, &mock_running_system.sequencer_1];
Expand All @@ -70,10 +79,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 @@ -222,3 +231,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 c65e8d4

Please sign in to comment.