Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(starknet_integration_tests): remove const for json rpc version #2611

Merged
merged 4 commits into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions crates/blockifier_reexecution/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use blockifier_reexecution::state_reader::utils::{
guess_chain_id_from_node_url,
reexecute_and_verify_correctness,
write_block_reexecution_data_to_file,
JSON_RPC_VERSION,
};
use clap::{Args, Parser, Subcommand};
use google_cloud_storage::client::{Client, ClientConfig};
Expand Down Expand Up @@ -181,10 +180,7 @@ async fn main() {
rpc_args.node_url
);

let config = RpcStateReaderConfig {
url: rpc_args.node_url.clone(),
json_rpc_version: JSON_RPC_VERSION.to_string(),
};
let config = RpcStateReaderConfig::from_url(rpc_args.node_url.clone());

// RPC calls are "synchronous IO" (see, e.g., https://stackoverflow.com/questions/74547541/when-should-you-use-tokios-spawn-blocking)
// for details), so should be executed in a blocking thread.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub fn get_test_block_id() -> BlockId {
}

pub fn get_test_rpc_config() -> RpcStateReaderConfig {
RpcStateReaderConfig { url: get_test_url(), json_rpc_version: "2.0".to_string() }
RpcStateReaderConfig::from_url(get_test_url())
}

#[fixture]
Expand Down
11 changes: 3 additions & 8 deletions crates/blockifier_reexecution/src/state_reader/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ pub static RPC_NODE_URL: LazyLock<String> = LazyLock::new(|| {
env::var("TEST_URL")
.unwrap_or_else(|_| "https://free-rpc.nethermind.io/mainnet-juno/".to_string())
});
pub const JSON_RPC_VERSION: &str = "2.0";

pub fn guess_chain_id_from_node_url(node_url: &str) -> ReexecutionResult<ChainId> {
match (
Expand Down Expand Up @@ -59,12 +58,9 @@ pub fn get_fee_token_addresses(chain_id: &ChainId) -> FeeTokenAddresses {
}
}

/// Returns the RPC state reader configuration with the constants RPC_NODE_URL and JSON_RPC_VERSION.
/// Returns the RPC state reader configuration with the constant RPC_NODE_URL.
pub fn get_rpc_state_reader_config() -> RpcStateReaderConfig {
RpcStateReaderConfig {
url: RPC_NODE_URL.clone(),
json_rpc_version: JSON_RPC_VERSION.to_string(),
}
RpcStateReaderConfig::from_url(RPC_NODE_URL.clone())
}

/// Returns the chain info of mainnet.
Expand Down Expand Up @@ -260,8 +256,7 @@ pub fn write_block_reexecution_data_to_file(
node_url: String,
chain_id: ChainId,
) {
let config =
RpcStateReaderConfig { url: node_url, json_rpc_version: JSON_RPC_VERSION.to_string() };
let config = RpcStateReaderConfig::from_url(node_url);

let consecutive_state_readers = ConsecutiveTestStateReaders::new(
block_number.prev().expect("Should not run with block 0"),
Expand Down
2 changes: 1 addition & 1 deletion crates/papyrus_load_test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ rand.workspace = true
reqwest.workspace = true
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true, features = ["arbitrary_precision"] }
starknet_api.workspace = true
starknet_api = { workspace = true, features = ["testing"] }
tokio.workspace = true

[dev-dependencies]
Expand Down
18 changes: 16 additions & 2 deletions crates/starknet_gateway/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ use validator::Validate;

use crate::compiler_version::VersionId;

const JSON_RPC_VERSION: &str = "2.0";

#[derive(Clone, Debug, Default, Serialize, Deserialize, Validate, PartialEq)]
pub struct GatewayConfig {
pub stateless_tx_validator_config: StatelessTransactionValidatorConfig,
Expand Down Expand Up @@ -119,16 +121,28 @@ impl SerializeConfig for StatelessTransactionValidatorConfig {
}
}

#[derive(Clone, Debug, Default, Serialize, Deserialize, Validate, PartialEq)]
#[derive(Clone, Debug, Serialize, Deserialize, Validate, PartialEq)]
pub struct RpcStateReaderConfig {
pub url: String,
pub json_rpc_version: String,
}

impl RpcStateReaderConfig {
pub fn from_url(url: String) -> Self {
Self { url, ..Default::default() }
}
}

impl Default for RpcStateReaderConfig {
fn default() -> Self {
Self { url: Default::default(), json_rpc_version: JSON_RPC_VERSION.to_string() }
}
}

#[cfg(any(feature = "testing", test))]
impl RpcStateReaderConfig {
pub fn create_for_testing() -> Self {
Self { url: "http://localhost:8080".to_string(), json_rpc_version: "2.0".to_string() }
Self::from_url("http://localhost:8080".to_string())
}
}

Expand Down
1 change: 0 additions & 1 deletion crates/starknet_integration_tests/src/config_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ pub(crate) fn dump_config_file_changes(
required_params.eth_fee_token_address,
required_params.strk_fee_token_address,
required_params.validator_id,
config.rpc_state_reader_config.json_rpc_version,
config.rpc_state_reader_config.url,
config.batcher_config.storage.db_config.path_prefix,
config.http_server_config.ip,
Expand Down
6 changes: 1 addition & 5 deletions crates/starknet_integration_tests/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,7 @@ pub fn create_consensus_manager_configs_and_channels(
pub fn test_rpc_state_reader_config(rpc_server_addr: SocketAddr) -> RpcStateReaderConfig {
// TODO(Tsabary): get the latest version from the RPC crate.
const RPC_SPEC_VERSION: &str = "V0_8";
const JSON_RPC_VERSION: &str = "2.0";
RpcStateReaderConfig {
url: format!("http://{rpc_server_addr:?}/rpc/{RPC_SPEC_VERSION}"),
json_rpc_version: JSON_RPC_VERSION.to_string(),
}
RpcStateReaderConfig::from_url(format!("http://{rpc_server_addr:?}/rpc/{RPC_SPEC_VERSION}"))
}

/// Creates a multi-account transaction generator for integration tests.
Expand Down
Loading