Skip to content

Commit ce7d79e

Browse files
committed
apollo_integration_tests: split end to end flow test into 5 scenarios
1 parent c493f3d commit ce7d79e

File tree

6 files changed

+203
-124
lines changed

6 files changed

+203
-124
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
use apollo_infra_utils::test_utils::TestIdentifier;
2+
use apollo_integration_tests::utils::ACCOUNT_ID_0;
3+
use blockifier::bouncer::BouncerWeights;
4+
use mempool_test_utils::starknet_api_test_utils::MultiAccountTransactionGenerator;
5+
use starknet_api::rpc_transaction::RpcTransaction;
6+
7+
use crate::common::{end_to_end_flow, test_single_tx, EndToEndFlowArgs, TestScenario};
8+
9+
mod common;
10+
11+
/// Number of threads is 3 = Num of sequencer + 1 for the test thread.
12+
#[tokio::test(flavor = "multi_thread", worker_threads = 3)]
13+
async fn test_declare_tx_flow() {
14+
end_to_end_flow(EndToEndFlowArgs::new(
15+
TestIdentifier::EndToEndFlowTest,
16+
create_test_scenarios(),
17+
BouncerWeights::default().proving_gas,
18+
))
19+
.await
20+
}
21+
22+
fn create_test_scenarios() -> Vec<TestScenario> {
23+
vec![TestScenario {
24+
create_rpc_txs_fn: create_declare_tx,
25+
create_l1_to_l2_messages_args_fn: |_| vec![],
26+
test_tx_hashes_fn: test_single_tx,
27+
}]
28+
}
29+
30+
fn create_declare_tx(tx_generator: &mut MultiAccountTransactionGenerator) -> Vec<RpcTransaction> {
31+
let account_tx_generator = tx_generator.account_with_id_mut(ACCOUNT_ID_0);
32+
let declare_tx = account_tx_generator.generate_declare_of_contract_class();
33+
vec![declare_tx]
34+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
use apollo_infra_utils::test_utils::TestIdentifier;
2+
use apollo_integration_tests::utils::{
3+
create_deploy_account_tx_and_invoke_tx,
4+
UNDEPLOYED_ACCOUNT_ID,
5+
};
6+
use blockifier::bouncer::BouncerWeights;
7+
use mempool_test_utils::starknet_api_test_utils::MultiAccountTransactionGenerator;
8+
use starknet_api::rpc_transaction::RpcTransaction;
9+
10+
use crate::common::{end_to_end_flow, validate_tx_count, EndToEndFlowArgs, TestScenario};
11+
12+
mod common;
13+
14+
/// Number of threads is 3 = Num of sequencer + 1 for the test thread.
15+
#[tokio::test(flavor = "multi_thread", worker_threads = 3)]
16+
async fn test_deploy_account_and_invoke_flow() {
17+
end_to_end_flow(EndToEndFlowArgs::new(
18+
TestIdentifier::EndToEndFlowTest,
19+
create_test_scenarios(),
20+
BouncerWeights::default().proving_gas,
21+
))
22+
.await
23+
}
24+
25+
fn create_test_scenarios() -> Vec<TestScenario> {
26+
vec![TestScenario {
27+
create_rpc_txs_fn: deploy_account_and_invoke,
28+
create_l1_to_l2_messages_args_fn: |_| vec![],
29+
test_tx_hashes_fn: |tx_hashes| validate_tx_count(tx_hashes, 2),
30+
}]
31+
}
32+
33+
/// Generates a deploy account transaction followed by an invoke transaction from the same deployed
34+
/// account.
35+
fn deploy_account_and_invoke(
36+
tx_generator: &mut MultiAccountTransactionGenerator,
37+
) -> Vec<RpcTransaction> {
38+
create_deploy_account_tx_and_invoke_tx(tx_generator, UNDEPLOYED_ACCOUNT_ID)
39+
}

crates/apollo_integration_tests/tests/end_to_end_flow_test.rs

Lines changed: 0 additions & 124 deletions
This file was deleted.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
use apollo_infra_utils::test_utils::TestIdentifier;
2+
use apollo_integration_tests::utils::{ACCOUNT_ID_0, UNDEPLOYED_ACCOUNT_ID};
3+
use blockifier::bouncer::BouncerWeights;
4+
use mempool_test_utils::starknet_api_test_utils::MultiAccountTransactionGenerator;
5+
use starknet_api::rpc_transaction::RpcTransaction;
6+
7+
use crate::common::{end_to_end_flow, test_single_tx, EndToEndFlowArgs, TestScenario};
8+
9+
mod common;
10+
11+
/// Number of threads is 3 = Num of sequencer + 1 for the test thread.
12+
#[tokio::test(flavor = "multi_thread", worker_threads = 3)]
13+
async fn test_funding_txs_flow() {
14+
end_to_end_flow(EndToEndFlowArgs::new(
15+
TestIdentifier::EndToEndFlowTest,
16+
create_test_scenarios(),
17+
BouncerWeights::default().proving_gas,
18+
))
19+
.await
20+
}
21+
22+
fn create_test_scenarios() -> Vec<TestScenario> {
23+
vec![TestScenario {
24+
create_rpc_txs_fn: create_funding_txs,
25+
create_l1_to_l2_messages_args_fn: |_| vec![],
26+
test_tx_hashes_fn: test_single_tx,
27+
}]
28+
}
29+
30+
fn create_funding_txs(tx_generator: &mut MultiAccountTransactionGenerator) -> Vec<RpcTransaction> {
31+
// TODO(yair): Register the undeployed account here instead of in the test setup
32+
// once funding is implemented.
33+
let undeployed_account = tx_generator.account_with_id(UNDEPLOYED_ACCOUNT_ID).account;
34+
assert!(tx_generator.undeployed_accounts().contains(&undeployed_account));
35+
36+
let funding_tx =
37+
tx_generator.account_with_id_mut(ACCOUNT_ID_0).generate_transfer(&undeployed_account);
38+
vec![funding_tx]
39+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
use apollo_infra_utils::test_utils::TestIdentifier;
2+
use apollo_integration_tests::utils::create_l1_to_l2_messages_args;
3+
use blockifier::bouncer::BouncerWeights;
4+
use mempool_test_utils::starknet_api_test_utils::MultiAccountTransactionGenerator;
5+
use starknet_api::transaction::L1HandlerTransaction;
6+
7+
use crate::common::{end_to_end_flow, test_single_tx, EndToEndFlowArgs, TestScenario};
8+
9+
mod common;
10+
11+
/// Number of threads is 3 = Num of sequencer + 1 for the test thread.
12+
#[tokio::test(flavor = "multi_thread", worker_threads = 3)]
13+
async fn test_l1_to_l2_message_flow() {
14+
end_to_end_flow(EndToEndFlowArgs::new(
15+
TestIdentifier::EndToEndFlowTest,
16+
create_test_scenarios(),
17+
BouncerWeights::default().proving_gas,
18+
))
19+
.await
20+
}
21+
22+
fn create_test_scenarios() -> Vec<TestScenario> {
23+
vec![TestScenario {
24+
create_rpc_txs_fn: |_| vec![],
25+
create_l1_to_l2_messages_args_fn: create_l1_to_l2_message_args,
26+
test_tx_hashes_fn: test_single_tx,
27+
}]
28+
}
29+
30+
fn create_l1_to_l2_message_args(
31+
tx_generator: &mut MultiAccountTransactionGenerator,
32+
) -> Vec<L1HandlerTransaction> {
33+
const N_TXS: usize = 1;
34+
const SHOULD_REVERT: bool = false;
35+
create_l1_to_l2_messages_args(tx_generator, N_TXS, SHOULD_REVERT)
36+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
use apollo_infra_utils::test_utils::TestIdentifier;
2+
use apollo_integration_tests::utils::{ACCOUNT_ID_0, ACCOUNT_ID_1};
3+
use blockifier::bouncer::BouncerWeights;
4+
use mempool_test_utils::starknet_api_test_utils::MultiAccountTransactionGenerator;
5+
use starknet_api::rpc_transaction::RpcTransaction;
6+
use starknet_api::transaction::TransactionHash;
7+
8+
use crate::common::{end_to_end_flow, EndToEndFlowArgs, TestScenario};
9+
10+
mod common;
11+
12+
/// Number of threads is 3 = Num of sequencer + 1 for the test thread.
13+
#[tokio::test(flavor = "multi_thread", worker_threads = 3)]
14+
async fn test_multiple_account_txs_flow() {
15+
end_to_end_flow(EndToEndFlowArgs::new(
16+
TestIdentifier::EndToEndFlowTest,
17+
create_test_scenarios(),
18+
BouncerWeights::default().proving_gas,
19+
))
20+
.await
21+
}
22+
23+
fn create_test_scenarios() -> Vec<TestScenario> {
24+
vec![TestScenario {
25+
create_rpc_txs_fn: create_multiple_account_txs,
26+
create_l1_to_l2_messages_args_fn: |_| vec![],
27+
test_tx_hashes_fn: test_multiple_account_txs,
28+
}]
29+
}
30+
31+
fn create_multiple_account_txs(
32+
tx_generator: &mut MultiAccountTransactionGenerator,
33+
) -> Vec<RpcTransaction> {
34+
// Create RPC transactions.
35+
let account0_invoke_nonce1 =
36+
tx_generator.account_with_id_mut(ACCOUNT_ID_0).generate_trivial_rpc_invoke_tx(2);
37+
let account0_invoke_nonce2 =
38+
tx_generator.account_with_id_mut(ACCOUNT_ID_0).generate_trivial_rpc_invoke_tx(3);
39+
let account1_invoke_nonce1 =
40+
tx_generator.account_with_id_mut(ACCOUNT_ID_1).generate_trivial_rpc_invoke_tx(4);
41+
42+
vec![account0_invoke_nonce1, account0_invoke_nonce2, account1_invoke_nonce1]
43+
}
44+
45+
fn test_multiple_account_txs(tx_hashes: &[TransactionHash]) -> Vec<TransactionHash> {
46+
// Return the transaction hashes in the order they should be given by the mempool:
47+
// Transactions from the same account are ordered by nonce; otherwise, higher tips are given
48+
// priority.
49+
assert!(
50+
tx_hashes.len() == 3,
51+
"Unexpected number of transactions sent in the test scenario. Found {} transactions",
52+
tx_hashes.len()
53+
);
54+
vec![tx_hashes[2], tx_hashes[0], tx_hashes[1]]
55+
}

0 commit comments

Comments
 (0)