Skip to content

Commit b9a7b96

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

File tree

7 files changed

+202
-125
lines changed

7 files changed

+202
-125
lines changed

crates/apollo_infra_utils/src/test_utils.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ pub enum TestIdentifier {
3939
RestartServiceMultipleNodesFlowIntegrationTest,
4040
RestartServiceSingleNodeFlowIntegrationTest,
4141
RevertFlowIntegrationTest,
42-
SystemTestDumpSingleNodeConfig,
4342
HttpServerUnitTests,
4443
SyncFlowIntegrationTest,
4544
StorageReaderServerUnitTests,
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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 declare_tx_flow() {
14+
end_to_end_flow(EndToEndFlowArgs::new(
15+
// TODO(Arni): Change the TestIdentifier to DeclareTxFlow.
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_declare_tx,
26+
create_l1_to_l2_messages_args_fn: |_| vec![],
27+
test_tx_hashes_fn: test_single_tx,
28+
}]
29+
}
30+
31+
fn create_declare_tx(tx_generator: &mut MultiAccountTransactionGenerator) -> Vec<RpcTransaction> {
32+
let account_tx_generator = tx_generator.account_with_id_mut(ACCOUNT_ID_0);
33+
let declare_tx = account_tx_generator.generate_declare_of_contract_class();
34+
vec![declare_tx]
35+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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 deploy_account_and_invoke_flow() {
17+
end_to_end_flow(EndToEndFlowArgs::new(
18+
// TODO(Arni): Change the TestIdentifier to DeployAccountAndInvokeFlow.
19+
TestIdentifier::EndToEndFlowTest,
20+
create_test_scenarios(),
21+
BouncerWeights::default().proving_gas,
22+
))
23+
.await
24+
}
25+
26+
fn create_test_scenarios() -> Vec<TestScenario> {
27+
vec![TestScenario {
28+
create_rpc_txs_fn: deploy_account_and_invoke,
29+
create_l1_to_l2_messages_args_fn: |_| vec![],
30+
test_tx_hashes_fn: |tx_hashes| validate_tx_count(tx_hashes, 2),
31+
}]
32+
}
33+
34+
/// Generates a deploy account transaction followed by an invoke transaction from the same deployed
35+
/// account.
36+
fn deploy_account_and_invoke(
37+
tx_generator: &mut MultiAccountTransactionGenerator,
38+
) -> Vec<RpcTransaction> {
39+
create_deploy_account_tx_and_invoke_tx(tx_generator, UNDEPLOYED_ACCOUNT_ID)
40+
}

crates/apollo_integration_tests/tests/end_to_end_flow_test.rs

Lines changed: 0 additions & 124 deletions
This file was deleted.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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 funding_txs_flow() {
14+
end_to_end_flow(EndToEndFlowArgs::new(
15+
// TODO(Arni): Change the TestIdentifier to FundingTxsFlow.
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_funding_txs,
26+
create_l1_to_l2_messages_args_fn: |_| vec![],
27+
test_tx_hashes_fn: test_single_tx,
28+
}]
29+
}
30+
31+
fn create_funding_txs(tx_generator: &mut MultiAccountTransactionGenerator) -> Vec<RpcTransaction> {
32+
// TODO(yair): Register the undeployed account here instead of in the test setup
33+
// once funding is implemented.
34+
let undeployed_account = tx_generator.account_with_id(UNDEPLOYED_ACCOUNT_ID).account;
35+
assert!(tx_generator.undeployed_accounts().contains(&undeployed_account));
36+
37+
let funding_tx =
38+
tx_generator.account_with_id_mut(ACCOUNT_ID_0).generate_transfer(&undeployed_account);
39+
vec![funding_tx]
40+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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 l1_to_l2_message_flow() {
14+
end_to_end_flow(EndToEndFlowArgs::new(
15+
// TODO(Arni): Change the TestIdentifier to L1ToL2MessageFlow.
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: |_| vec![],
26+
create_l1_to_l2_messages_args_fn: |tx_generator| {
27+
create_l1_to_l2_messages_args(tx_generator, 1, false)
28+
},
29+
test_tx_hashes_fn: test_single_tx,
30+
}]
31+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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 multiple_account_txs_flow() {
15+
end_to_end_flow(EndToEndFlowArgs::new(
16+
// TODO(Arni): Change the TestIdentifier to MultipleAccountTxsFlow.
17+
TestIdentifier::EndToEndFlowTest,
18+
create_test_scenarios(),
19+
BouncerWeights::default().proving_gas,
20+
))
21+
.await
22+
}
23+
24+
fn create_test_scenarios() -> Vec<TestScenario> {
25+
vec![TestScenario {
26+
create_rpc_txs_fn: create_multiple_account_txs,
27+
create_l1_to_l2_messages_args_fn: |_| vec![],
28+
test_tx_hashes_fn: test_multiple_account_txs,
29+
}]
30+
}
31+
32+
fn create_multiple_account_txs(
33+
tx_generator: &mut MultiAccountTransactionGenerator,
34+
) -> Vec<RpcTransaction> {
35+
// Create RPC transactions.
36+
let account0_invoke_nonce1 =
37+
tx_generator.account_with_id_mut(ACCOUNT_ID_0).generate_trivial_rpc_invoke_tx(2);
38+
let account0_invoke_nonce2 =
39+
tx_generator.account_with_id_mut(ACCOUNT_ID_0).generate_trivial_rpc_invoke_tx(3);
40+
let account1_invoke_nonce1 =
41+
tx_generator.account_with_id_mut(ACCOUNT_ID_1).generate_trivial_rpc_invoke_tx(4);
42+
43+
vec![account0_invoke_nonce1, account0_invoke_nonce2, account1_invoke_nonce1]
44+
}
45+
46+
fn test_multiple_account_txs(tx_hashes: &[TransactionHash]) -> Vec<TransactionHash> {
47+
// Return the transaction hashes in the order they should be given by the mempool:
48+
// Transactions from the same account are ordered by nonce; otherwise, higher tips are given
49+
// priority.
50+
assert!(
51+
tx_hashes.len() == 3,
52+
"Unexpected number of transactions sent in the test scenario. Found {} transactions",
53+
tx_hashes.len()
54+
);
55+
vec![tx_hashes[2], tx_hashes[0], tx_hashes[1]]
56+
}

0 commit comments

Comments
 (0)