Skip to content
This repository has been archived by the owner on Dec 26, 2024. It is now read-only.

Commit

Permalink
test(load_test): partially add execution and spec V0_4 scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
DvirYo-starkware committed Sep 3, 2023
1 parent 487ea3f commit 6bf81d2
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 4 deletions.
15 changes: 15 additions & 0 deletions crates/papyrus_load_test/src/create_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,21 @@ pub fn get_transaction_receipt(transaction_hash: &str) -> jsonVal {
jsonrpc_request("starknet_getTransactionReceipt", json!([transaction_hash]))
}

pub fn trace_transaction(transaction_hash: &str) -> jsonVal {
jsonrpc_request("starknet_traceTransaction", json!([transaction_hash]))
}

pub fn trace_block_transactions_by_number(block_number: &str) -> jsonVal {
jsonrpc_request(
"starknet_traceBlockTransactions",
json!([{ "block_number": block_number.parse::<u64>().unwrap() }]),
)
}

pub fn trace_block_transactions_by_hash(block_hash: &str) -> jsonVal {
jsonrpc_request("starknet_traceBlockTransactions", json!([{ "block_hash": block_hash }]))
}

// This struct is for iterating over the args string.
struct ArgsIter<'a> {
iter: SplitWhitespace<'a>,
Expand Down
3 changes: 3 additions & 0 deletions crates/papyrus_load_test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ const GET_TRANSACTION_BY_BLOCK_ID_AND_INDEX_BY_NUMBER_WEIGHT: usize = 10;
const GET_TRANSACTION_BY_HASH_WEIGHT: usize = 10;
const GET_TRANSACTION_RECEIPT_WEIGHT: usize = 10;
const SYNCING_WEIGHT: usize = 10;
const TRACE_BLOCK_TRANSACTIONS_BY_HASH_WEIGHT: usize = 10;
const TRACE_BLOCK_TRANSACTIONS_BY_NUMBER_WEIGHT: usize = 10;
const TRACE_TRANSACTION_WEIGHT: usize = 10;

static RPC_VERSION_ID: Lazy<String> = Lazy::new(|| match std::env::var("VERSION_ID") {
Ok(version_id) => version_id,
Expand Down
6 changes: 4 additions & 2 deletions crates/papyrus_load_test/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// This code is inspired by the pathfinder load test.
// first set the env variable VERSION_ID to the version of the node you want to test.
// To run this load test, run locally a node and then run:
// cargo run -r -p papyrus_load_test -- -t 5m -H http://127.0.0.1:8080
// cargo run -r -p papyrus_load_test -- -t 5m -H http://127.0.0.1:8080 --scenarios=generalrequestv04
// To create the files of requests run:
// cargo run -r -p papyrus_load_test -- --create_files 127.0.0.1:8080
// For more options run:
Expand All @@ -26,7 +26,9 @@ async fn main() -> anyhow::Result<()> {
}

let metrics = GooseAttack::initialize()?
.register_scenario(scenarios::general_request())
// The choice between V0_3 and V0_4 must be also in the environment variable VERSION_ID.
.register_scenario(scenarios::general_request_v0_3())
.register_scenario(scenarios::general_request_v0_4())
.execute()
.await?;

Expand Down
27 changes: 25 additions & 2 deletions crates/papyrus_load_test/src/scenarios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@ use crate::{
GET_TRANSACTION_BY_HASH_WEIGHT,
GET_TRANSACTION_RECEIPT_WEIGHT,
SYNCING_WEIGHT,
TRACE_BLOCK_TRANSACTIONS_BY_HASH_WEIGHT,
TRACE_BLOCK_TRANSACTIONS_BY_NUMBER_WEIGHT,
TRACE_TRANSACTION_WEIGHT,
};

pub fn general_request() -> Scenario {
let mut scenario = scenario!("general_request");
pub fn general_request_v0_3() -> Scenario {
let mut scenario = scenario!("general_request_V0_3");
let trans_and_weights = vec![
(txs::block_hash_and_number(), BLOCK_HASH_AND_NUMBER_WEIGHT),
(txs::block_number(), BLOCK_NUMBER_WEIGHT),
Expand Down Expand Up @@ -91,3 +94,23 @@ pub fn general_request() -> Scenario {
}
scenario
}

// TODO(dvir): add also traceTransaction, simulateTransactions, estimateFee and call endpoints.
pub fn general_request_v0_4() -> Scenario {
let mut scenario = scenario!("general_request_V0_4");

// Add V0_3 transactions.
for trans in general_request_v0_3().transactions {
scenario = scenario.register_transaction(trans);
}

let new_trans_and_weights = vec![
(txs::trace_block_transactions_by_hash(), TRACE_BLOCK_TRANSACTIONS_BY_HASH_WEIGHT),
(txs::trace_block_transactions_by_number(), TRACE_BLOCK_TRANSACTIONS_BY_NUMBER_WEIGHT),
(txs::trace_transaction(), TRACE_TRANSACTION_WEIGHT),
];
for (transaction, weight) in new_trans_and_weights.into_iter() {
scenario = scenario.register_transaction(transaction.set_weight(weight).unwrap());
}
scenario
}
3 changes: 3 additions & 0 deletions crates/papyrus_load_test/src/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ create_get_transaction_function_with_requests_from_file! {
get_class_by_hash, "block_hash_and_class_hash.txt";
get_events_with_address, "block_range_and_contract_address.txt";
get_events_without_address, "block_range_and_contract_address.txt";
trace_transaction, "transaction_hash.txt";
trace_block_transactions_by_number, "block_number.txt";
trace_block_transactions_by_hash, "block_hash.txt";
}

pub fn block_number() -> Transaction {
Expand Down

0 comments on commit 6bf81d2

Please sign in to comment.