diff --git a/Cargo.lock b/Cargo.lock index ccafd924a3..cd15536188 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3940,6 +3940,7 @@ dependencies = [ "papyrus_storage", "pretty_assertions", "prometheus-parse", + "rand", "rand_chacha", "regex", "serde", diff --git a/crates/papyrus_gateway/Cargo.toml b/crates/papyrus_gateway/Cargo.toml index f9cf1845cb..fdf0947d05 100644 --- a/crates/papyrus_gateway/Cargo.toml +++ b/crates/papyrus_gateway/Cargo.toml @@ -44,3 +44,4 @@ test_utils = { path = "../test_utils" } starknet_api = { workspace = true, features = ["testing"] } starknet_client = { path = "../starknet_client", features = ["testing"] } indexmap = { workspace = true, features = ["serde"] } +rand.workspace = true diff --git a/crates/papyrus_gateway/src/api.rs b/crates/papyrus_gateway/src/api.rs index c0f27aca08..d542bb236f 100644 --- a/crates/papyrus_gateway/src/api.rs +++ b/crates/papyrus_gateway/src/api.rs @@ -7,8 +7,8 @@ use starknet_api::block::{BlockHash, BlockNumber}; use starknet_api::core::{ChainId, ContractAddress}; use starknet_api::transaction::EventKey; -use crate::v0_3_0::api::api_impl::JsonRpcServerV0_3_0Impl; -use crate::v0_3_0::api::JsonRpcV0_3_0Server; +use crate::v0_3_0::api::api_impl::JsonRpcServerV0_3Impl; +use crate::v0_3_0::api::JsonRpcV0_3Server; use crate::version_config; #[derive(Copy, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] @@ -92,11 +92,11 @@ pub fn get_methods_from_supported_apis( version_config::VERSION_CONFIG .iter() .filter_map(|version_config| { - let (version_id, version_state) = version_config; + let (version, version_state) = version_config; match version_state { version_config::VersionState::Deprecated => None, - version_config::VersionState::Supported => match *version_id { - version_config::VERSION_0_3_0 => Some(JsonRpcServerV0_3_0Impl { + version_config::VersionState::Supported => match *version { + version_config::VERSION_0_3 => Some(JsonRpcServerV0_3Impl { chain_id: chain_id.clone(), storage_reader: storage_reader.clone(), max_events_chunk_size, diff --git a/crates/papyrus_gateway/src/gateway_test.rs b/crates/papyrus_gateway/src/gateway_test.rs index 30ccedbd56..62d251627b 100644 --- a/crates/papyrus_gateway/src/gateway_test.rs +++ b/crates/papyrus_gateway/src/gateway_test.rs @@ -13,7 +13,9 @@ use papyrus_storage::base_layer::BaseLayerStorageWriter; use papyrus_storage::header::HeaderStorageWriter; use papyrus_storage::test_utils::get_test_storage; use pretty_assertions::assert_eq; +use rand::seq::SliceRandom; use starknet_api::block::{BlockHash, BlockHeader, BlockNumber, BlockStatus}; +use test_utils::get_rng; use tower::BoxError; use crate::api::JsonRpcError; @@ -121,8 +123,12 @@ async fn test_version_middleware() { let base_uri = "http://localhost:8080/rpc/"; let mut path_options = vec![]; VERSION_CONFIG.iter().for_each(|(version_id, _)| { - path_options.push(((*version_id).to_string(), (*version_id).to_string())); - path_options.push(((*version_id).to_lowercase(), (*version_id).to_string())) + // add version name with capital V + path_options.push((version_id.name.to_string(), version_id.name.to_string())); + // add version name with lower case v + path_options.push((version_id.name.to_lowercase(), version_id.name.to_string())); + // add version name with patch version + path_options.push((version_id.to_string(), version_id.name.to_string())); }); // test all versions with single and batch requests @@ -151,7 +157,14 @@ async fn test_version_middleware() { } }); let unknown_version = "not_a_valid_version"; - let bad_uri = format!("{base_uri}/{unknown_version}"); + let bad_uri = format!("{base_uri}{unknown_version}"); + if let Ok(res) = call_proxy_request_get_method_in_out(bad_uri, false).await { + panic!("expected failure got: {res:?}"); + }; + let mut rng = get_rng(); + let version_id = VERSION_CONFIG.choose(&mut rng).unwrap().0; + let newer_version_then_we_have = format!("{}_{}", version_id.name, version_id.patch + 1); + let bad_uri = format!("{base_uri}{newer_version_then_we_have}"); if let Ok(res) = call_proxy_request_get_method_in_out(bad_uri, false).await { panic!("expected failure got: {res:?}"); }; diff --git a/crates/papyrus_gateway/src/middleware.rs b/crates/papyrus_gateway/src/middleware.rs index a9f878fb00..066e8ac24d 100644 --- a/crates/papyrus_gateway/src/middleware.rs +++ b/crates/papyrus_gateway/src/middleware.rs @@ -91,24 +91,32 @@ fn strip_starknet_from_method(method: &str) -> Option<&str> { fn get_version_as_prefix(path: &str) -> Result<&str, BoxError> { // get the version name from the path (should be something like "http://host:port/rpc/version_id") let uri_components = &mut path.split('/').collect::>(); - let Some(version) = uri_components.get(2) else { + let Some(temp_version) = uri_components.get(2) else { // as long as 'deny_requests_with_unsupported_path' middleware is used, this should never happen // but for safety we return an error and not unreachable!() let msg = format!("Invalid path format: {}", path); debug!(msg); return Err(BoxError::from(msg)); }; + let version_comps = temp_version.split('_').collect::>(); + let mut patch_num = 0; + if version_comps.len() == 3 { + // if the version is of the form "V0_0_1" we store the path num to check that our latest + // supported patch version is at least the requested version. + patch_num = version_comps[2].parse::().map_err(BoxError::from)?; + } + let version = format!("{}_{}", version_comps[0], version_comps[1]); let Some((version_id, _)) = // find a matching version in the version config VERSION_CONFIG.iter().find(|(version_id, version_state)| { - (*version_id == *version || (*version_id).to_lowercase() == *version) && *version_state != VersionState::Deprecated + (version_id.name == version || version_id.name.to_lowercase() == version) && *version_state != VersionState::Deprecated && patch_num <= version_id.patch }) else { return Err(BoxError::from(format!("Invalid path, couldn't find matching version for version_id: {version}"))); }; - Ok(*version_id) + Ok(version_id.name) } fn is_supported_path(path: &str) -> bool { - let re = Regex::new(r"^\/rpc\/[Vv][0-9]+_[0-9]+_[0-9]+$").expect("should be a valid regex"); + let re = Regex::new(r"^\/rpc\/[Vv][0-9]+_[0-9]+(_[0-9]+)?$").expect("should be a valid regex"); re.is_match(path) } diff --git a/crates/papyrus_gateway/src/test_utils.rs b/crates/papyrus_gateway/src/test_utils.rs index a311806e08..cbf86925c4 100644 --- a/crates/papyrus_gateway/src/test_utils.rs +++ b/crates/papyrus_gateway/src/test_utils.rs @@ -5,6 +5,7 @@ use papyrus_storage::StorageWriter; use starknet_api::core::ChainId; use crate::api::JsonRpcServerImpl; +use crate::version_config::VersionId; use crate::GatewayConfig; pub fn get_test_gateway_config() -> GatewayConfig { @@ -35,7 +36,7 @@ pub(crate) fn get_test_rpc_server_and_storage_writer() pub async fn get_starknet_spec_api_schema( component_names: &[&str], - version_id: &str, + version_id: &VersionId, ) -> JSONSchema { let target = format!("./resources/{version_id}_starknet_api_openrpc.json"); let text = std::fs::read_to_string(target).unwrap(); diff --git a/crates/papyrus_gateway/src/v0_3_0/api/api_impl.rs b/crates/papyrus_gateway/src/v0_3_0/api/api_impl.rs index 4de9380b9a..2eda78588e 100644 --- a/crates/papyrus_gateway/src/v0_3_0/api/api_impl.rs +++ b/crates/papyrus_gateway/src/v0_3_0/api/api_impl.rs @@ -23,8 +23,7 @@ use super::super::transaction::{ TransactionWithHash, Transactions, }; use super::{ - BlockHashAndNumber, BlockId, EventFilter, EventsChunk, GatewayContractClass, - JsonRpcV0_3_0Server, + BlockHashAndNumber, BlockId, EventFilter, EventsChunk, GatewayContractClass, JsonRpcV0_3Server, }; use crate::api::{BlockHashOrNumber, ContinuationToken, JsonRpcError, JsonRpcServerImpl}; use crate::block::get_block_header_by_number; @@ -35,14 +34,14 @@ use crate::{ }; /// Rpc server. -pub struct JsonRpcServerV0_3_0Impl { +pub struct JsonRpcServerV0_3Impl { pub chain_id: ChainId, pub storage_reader: StorageReader, pub max_events_chunk_size: usize, pub max_events_keys: usize, } -impl JsonRpcV0_3_0Server for JsonRpcServerV0_3_0Impl { +impl JsonRpcV0_3Server for JsonRpcServerV0_3Impl { #[instrument(skip(self), level = "debug", err, ret)] fn block_number(&self) -> RpcResult { let txn = self.storage_reader.begin_ro_txn().map_err(internal_server_error)?; @@ -448,7 +447,7 @@ impl JsonRpcV0_3_0Server for JsonRpcServerV0_3_0Impl { } } -impl JsonRpcServerImpl for JsonRpcServerV0_3_0Impl { +impl JsonRpcServerImpl for JsonRpcServerV0_3Impl { fn new( chain_id: ChainId, storage_reader: StorageReader, diff --git a/crates/papyrus_gateway/src/v0_3_0/api/mod.rs b/crates/papyrus_gateway/src/v0_3_0/api/mod.rs index cb6a260bcd..7fdeb92986 100644 --- a/crates/papyrus_gateway/src/v0_3_0/api/mod.rs +++ b/crates/papyrus_gateway/src/v0_3_0/api/mod.rs @@ -19,7 +19,7 @@ pub mod api_impl; #[cfg(test)] mod test; -#[versioned_rpc("V0_3_0")] +#[versioned_rpc("V0_3")] pub trait JsonRpc { /// Gets the most recent accepted block number. #[method(name = "blockNumber")] diff --git a/crates/papyrus_gateway/src/v0_3_0/api/test.rs b/crates/papyrus_gateway/src/v0_3_0/api/test.rs index 66760a4f1c..04dd90c51b 100644 --- a/crates/papyrus_gateway/src/v0_3_0/api/test.rs +++ b/crates/papyrus_gateway/src/v0_3_0/api/test.rs @@ -39,7 +39,7 @@ use super::super::transaction::{ Event, TransactionOutput, TransactionReceipt, TransactionReceiptWithStatus, TransactionStatus, TransactionWithHash, Transactions, }; -use super::api_impl::JsonRpcServerV0_3_0Impl; +use super::api_impl::JsonRpcServerV0_3Impl; use crate::api::{ BlockHashAndNumber, BlockHashOrNumber, BlockId, ContinuationToken, EventFilter, JsonRpcError, Tag, @@ -47,15 +47,14 @@ use crate::api::{ use crate::test_utils::{ get_starknet_spec_api_schema, get_test_gateway_config, get_test_rpc_server_and_storage_writer, }; -use crate::version_config::VERSION_0_3_0; +use crate::version_config::VERSION_0_3; use crate::{run_server, ContinuationTokenAsStruct}; #[tokio::test] async fn chain_id() { - let (module, _) = get_test_rpc_server_and_storage_writer::(); + let (module, _) = get_test_rpc_server_and_storage_writer::(); - let res = - module.call::<_, String>("starknet_V0_3_0_chainId", ObjectParams::new()).await.unwrap(); + let res = module.call::<_, String>("starknet_V0_3_chainId", ObjectParams::new()).await.unwrap(); // The result should be equal to the result of the following python code // hex(int.from_bytes(b'SN_GOERLI', byteorder="big", signed=False)) // taken from starknet documentation: @@ -66,11 +65,11 @@ async fn chain_id() { #[tokio::test] async fn block_hash_and_number() { let (module, mut storage_writer) = - get_test_rpc_server_and_storage_writer::(); + get_test_rpc_server_and_storage_writer::(); // No blocks yet. let err = module - .call::<_, BlockHashAndNumber>("starknet_V0_3_0_blockHashAndNumber", ObjectParams::new()) + .call::<_, BlockHashAndNumber>("starknet_V0_3_blockHashAndNumber", ObjectParams::new()) .await .unwrap_err(); assert_matches!(err, Error::Call(err) if err == ErrorObjectOwned::owned( @@ -89,7 +88,7 @@ async fn block_hash_and_number() { .commit() .unwrap(); let block_hash_and_number = module - .call::<_, BlockHashAndNumber>("starknet_V0_3_0_blockHashAndNumber", ObjectParams::new()) + .call::<_, BlockHashAndNumber>("starknet_V0_3_blockHashAndNumber", ObjectParams::new()) .await .unwrap(); assert_eq!( @@ -104,11 +103,11 @@ async fn block_hash_and_number() { #[tokio::test] async fn block_number() { let (module, mut storage_writer) = - get_test_rpc_server_and_storage_writer::(); + get_test_rpc_server_and_storage_writer::(); // No blocks yet. let err = module - .call::<_, BlockNumber>("starknet_V0_3_0_blockNumber", ObjectParams::new()) + .call::<_, BlockNumber>("starknet_V0_3_blockNumber", ObjectParams::new()) .await .unwrap_err(); assert_matches!(err, Error::Call(err) if err == ErrorObjectOwned::owned( @@ -126,7 +125,7 @@ async fn block_number() { .commit() .unwrap(); let block_number = module - .call::<_, BlockNumber>("starknet_V0_3_0_blockNumber", ObjectParams::new()) + .call::<_, BlockNumber>("starknet_V0_3_blockNumber", ObjectParams::new()) .await .unwrap(); assert_eq!(block_number, BlockNumber(0)); @@ -134,15 +133,15 @@ async fn block_number() { #[tokio::test] async fn syncing() { - let (module, _) = get_test_rpc_server_and_storage_writer::(); - let res = module.call::<_, bool>("starknet_V0_3_0_syncing", ObjectParams::new()).await.unwrap(); + let (module, _) = get_test_rpc_server_and_storage_writer::(); + let res = module.call::<_, bool>("starknet_V0_3_syncing", ObjectParams::new()).await.unwrap(); assert_eq!(res, false); } #[tokio::test] async fn get_block_transaction_count() { let (module, mut storage_writer) = - get_test_rpc_server_and_storage_writer::(); + get_test_rpc_server_and_storage_writer::(); let transaction_count = 5; let block = get_test_block(transaction_count, None, None, None); storage_writer @@ -158,7 +157,7 @@ async fn get_block_transaction_count() { // Get block by hash. let res = module .call::<_, usize>( - "starknet_V0_3_0_getBlockTransactionCount", + "starknet_V0_3_getBlockTransactionCount", [BlockId::HashOrNumber(BlockHashOrNumber::Hash(block.header.block_hash))], ) .await @@ -168,7 +167,7 @@ async fn get_block_transaction_count() { // Get block by number. let res = module .call::<_, usize>( - "starknet_V0_3_0_getBlockTransactionCount", + "starknet_V0_3_getBlockTransactionCount", [BlockId::HashOrNumber(BlockHashOrNumber::Number(block.header.block_number))], ) .await @@ -177,7 +176,7 @@ async fn get_block_transaction_count() { // Ask for the latest block. let res = module - .call::<_, usize>("starknet_V0_3_0_getBlockTransactionCount", [BlockId::Tag(Tag::Latest)]) + .call::<_, usize>("starknet_V0_3_getBlockTransactionCount", [BlockId::Tag(Tag::Latest)]) .await .unwrap(); assert_eq!(res, transaction_count); @@ -185,7 +184,7 @@ async fn get_block_transaction_count() { // Ask for an invalid block hash. let err = module .call::<_, usize>( - "starknet_V0_3_0_getBlockTransactionCount", + "starknet_V0_3_getBlockTransactionCount", [BlockId::HashOrNumber(BlockHashOrNumber::Hash(BlockHash(stark_felt!( "0x642b629ad8ce233b55798c83bb629a59bf0a0092f67da28d6d66776680d5484" ))))], @@ -201,7 +200,7 @@ async fn get_block_transaction_count() { // Ask for an invalid block number. let err = module .call::<_, usize>( - "starknet_V0_3_0_getBlockTransactionCount", + "starknet_V0_3_getBlockTransactionCount", [BlockId::HashOrNumber(BlockHashOrNumber::Number(BlockNumber(1)))], ) .await @@ -216,7 +215,7 @@ async fn get_block_transaction_count() { #[tokio::test] async fn get_block_w_full_transactions() { let (module, mut storage_writer) = - get_test_rpc_server_and_storage_writer::(); + get_test_rpc_server_and_storage_writer::(); let block = get_test_block(1, None, None, None); storage_writer @@ -242,7 +241,7 @@ async fn get_block_w_full_transactions() { // Get block by hash. let block = module .call::<_, Block>( - "starknet_V0_3_0_getBlockWithTxs", + "starknet_V0_3_getBlockWithTxs", [BlockId::HashOrNumber(BlockHashOrNumber::Hash(expected_block.header.block_hash))], ) .await @@ -252,7 +251,7 @@ async fn get_block_w_full_transactions() { // Get block by number. let block = module .call::<_, Block>( - "starknet_V0_3_0_getBlockWithTxs", + "starknet_V0_3_getBlockWithTxs", [BlockId::HashOrNumber(BlockHashOrNumber::Number(expected_block.header.block_number))], ) .await @@ -261,7 +260,7 @@ async fn get_block_w_full_transactions() { // Ask for the latest block. let block = module - .call::<_, Block>("starknet_V0_3_0_getBlockWithTxs", [BlockId::Tag(Tag::Latest)]) + .call::<_, Block>("starknet_V0_3_getBlockWithTxs", [BlockId::Tag(Tag::Latest)]) .await .unwrap(); assert_eq!(block, expected_block); @@ -276,7 +275,7 @@ async fn get_block_w_full_transactions() { .unwrap(); let block = module .call::<_, Block>( - "starknet_V0_3_0_getBlockWithTxs", + "starknet_V0_3_getBlockWithTxs", [BlockId::HashOrNumber(BlockHashOrNumber::Hash(expected_block.header.block_hash))], ) .await @@ -286,7 +285,7 @@ async fn get_block_w_full_transactions() { // Ask for an invalid block hash. let err = module .call::<_, Block>( - "starknet_V0_3_0_getBlockWithTxs", + "starknet_V0_3_getBlockWithTxs", [BlockId::HashOrNumber(BlockHashOrNumber::Hash(BlockHash(stark_felt!( "0x642b629ad8ce233b55798c83bb629a59bf0a0092f67da28d6d66776680d5484" ))))], @@ -302,7 +301,7 @@ async fn get_block_w_full_transactions() { // Ask for an invalid block number. let err = module .call::<_, Block>( - "starknet_V0_3_0_getBlockWithTxs", + "starknet_V0_3_getBlockWithTxs", [BlockId::HashOrNumber(BlockHashOrNumber::Number(BlockNumber(1)))], ) .await @@ -317,7 +316,7 @@ async fn get_block_w_full_transactions() { #[tokio::test] async fn get_block_w_transaction_hashes() { let (module, mut storage_writer) = - get_test_rpc_server_and_storage_writer::(); + get_test_rpc_server_and_storage_writer::(); let block = get_test_block(1, None, None, None); storage_writer @@ -339,7 +338,7 @@ async fn get_block_w_transaction_hashes() { // Get block by hash. let block = module .call::<_, Block>( - "starknet_V0_3_0_getBlockWithTxHashes", + "starknet_V0_3_getBlockWithTxHashes", [BlockId::HashOrNumber(BlockHashOrNumber::Hash(expected_block.header.block_hash))], ) .await @@ -349,7 +348,7 @@ async fn get_block_w_transaction_hashes() { // Get block by number. let block = module .call::<_, Block>( - "starknet_V0_3_0_getBlockWithTxHashes", + "starknet_V0_3_getBlockWithTxHashes", [BlockId::HashOrNumber(BlockHashOrNumber::Number(expected_block.header.block_number))], ) .await @@ -358,7 +357,7 @@ async fn get_block_w_transaction_hashes() { // Ask for the latest block. let block = module - .call::<_, Block>("starknet_V0_3_0_getBlockWithTxHashes", [BlockId::Tag(Tag::Latest)]) + .call::<_, Block>("starknet_V0_3_getBlockWithTxHashes", [BlockId::Tag(Tag::Latest)]) .await .unwrap(); assert_eq!(block, expected_block); @@ -373,7 +372,7 @@ async fn get_block_w_transaction_hashes() { .unwrap(); let block = module .call::<_, Block>( - "starknet_V0_3_0_getBlockWithTxHashes", + "starknet_V0_3_getBlockWithTxHashes", [BlockId::HashOrNumber(BlockHashOrNumber::Hash(expected_block.header.block_hash))], ) .await @@ -383,7 +382,7 @@ async fn get_block_w_transaction_hashes() { // Ask for an invalid block hash. let err = module .call::<_, Block>( - "starknet_V0_3_0_getBlockWithTxHashes", + "starknet_V0_3_getBlockWithTxHashes", [BlockId::HashOrNumber(BlockHashOrNumber::Hash(BlockHash(stark_felt!( "0x642b629ad8ce233b55798c83bb629a59bf0a0092f67da28d6d66776680d5484" ))))], @@ -399,7 +398,7 @@ async fn get_block_w_transaction_hashes() { // Ask for an invalid block number. let err = module .call::<_, Block>( - "starknet_V0_3_0_getBlockWithTxHashes", + "starknet_V0_3_getBlockWithTxHashes", [BlockId::HashOrNumber(BlockHashOrNumber::Number(BlockNumber(1)))], ) .await @@ -414,7 +413,7 @@ async fn get_block_w_transaction_hashes() { #[tokio::test] async fn get_class() { let (module, mut storage_writer) = - get_test_rpc_server_and_storage_writer::(); + get_test_rpc_server_and_storage_writer::(); let parent_header = BlockHeader::default(); let header = BlockHeader { block_hash: BlockHash(stark_felt!("0x1")), @@ -448,7 +447,7 @@ async fn get_class() { // Get class by block hash. let res = module .call::<_, DeprecatedContractClass>( - "starknet_V0_3_0_getClass", + "starknet_V0_3_getClass", (BlockId::HashOrNumber(BlockHashOrNumber::Hash(header.block_hash)), *class_hash), ) .await @@ -458,7 +457,7 @@ async fn get_class() { // Get class by block number. let res = module .call::<_, DeprecatedContractClass>( - "starknet_V0_3_0_getClass", + "starknet_V0_3_getClass", (BlockId::HashOrNumber(BlockHashOrNumber::Number(header.block_number)), *class_hash), ) .await @@ -468,7 +467,7 @@ async fn get_class() { // Ask for an invalid class hash. let err = module .call::<_, DeprecatedContractClass>( - "starknet_V0_3_0_getClass", + "starknet_V0_3_getClass", ( BlockId::HashOrNumber(BlockHashOrNumber::Number(header.block_number)), ClassHash(stark_felt!("0x7")), @@ -490,7 +489,7 @@ async fn get_class() { // Get class by block hash. let res = module .call::<_, ContractClass>( - "starknet_V0_3_0_getClass", + "starknet_V0_3_getClass", (BlockId::HashOrNumber(BlockHashOrNumber::Hash(header.block_hash)), *class_hash), ) .await @@ -500,7 +499,7 @@ async fn get_class() { // Get class by block number. let res = module .call::<_, ContractClass>( - "starknet_V0_3_0_getClass", + "starknet_V0_3_getClass", (BlockId::HashOrNumber(BlockHashOrNumber::Number(header.block_number)), *class_hash), ) .await @@ -511,7 +510,7 @@ async fn get_class() { // Ask for an invalid class hash in the given block. let err = module .call::<_, DeprecatedContractClass>( - "starknet_V0_3_0_getClass", + "starknet_V0_3_getClass", ( BlockId::HashOrNumber(BlockHashOrNumber::Number(parent_header.block_number)), *class_hash, @@ -528,7 +527,7 @@ async fn get_class() { // Ask for an invalid block hash. let err = module .call::<_, DeprecatedContractClass>( - "starknet_V0_3_0_getClass", + "starknet_V0_3_getClass", ( BlockId::HashOrNumber(BlockHashOrNumber::Hash(BlockHash(stark_felt!( "0x642b629ad8ce233b55798c83bb629a59bf0a0092f67da28d6d66776680d5484" @@ -547,7 +546,7 @@ async fn get_class() { // Ask for an invalid block number. let err = module .call::<_, DeprecatedContractClass>( - "starknet_V0_3_0_getClass", + "starknet_V0_3_getClass", (BlockId::HashOrNumber(BlockHashOrNumber::Number(BlockNumber(2))), *class_hash), ) .await @@ -562,7 +561,7 @@ async fn get_class() { #[tokio::test] async fn get_transaction_receipt() { let (module, mut storage_writer) = - get_test_rpc_server_and_storage_writer::(); + get_test_rpc_server_and_storage_writer::(); let block = get_test_block(1, None, None, None); storage_writer .begin_rw_txn() @@ -587,7 +586,7 @@ async fn get_transaction_receipt() { }; let res = module .call::<_, TransactionReceiptWithStatus>( - "starknet_V0_3_0_getTransactionReceipt", + "starknet_V0_3_getTransactionReceipt", [transaction_hash], ) .await @@ -610,7 +609,7 @@ async fn get_transaction_receipt() { .unwrap(); let res = module .call::<_, TransactionReceiptWithStatus>( - "starknet_V0_3_0_getTransactionReceipt", + "starknet_V0_3_getTransactionReceipt", [transaction_hash], ) .await @@ -620,7 +619,7 @@ async fn get_transaction_receipt() { // Ask for an invalid transaction. let err = module .call::<_, TransactionReceiptWithStatus>( - "starknet_V0_3_0_getTransactionReceipt", + "starknet_V0_3_getTransactionReceipt", [TransactionHash(StarkHash::from(1_u8))], ) .await @@ -635,7 +634,7 @@ async fn get_transaction_receipt() { #[tokio::test] async fn get_class_at() { let (module, mut storage_writer) = - get_test_rpc_server_and_storage_writer::(); + get_test_rpc_server_and_storage_writer::(); let parent_header = BlockHeader::default(); let header = BlockHeader { block_hash: BlockHash(stark_felt!("0x1")), @@ -674,7 +673,7 @@ async fn get_class_at() { // Get class by block hash. let res = module .call::<_, DeprecatedContractClass>( - "starknet_V0_3_0_getClassAt", + "starknet_V0_3_getClassAt", (BlockId::HashOrNumber(BlockHashOrNumber::Hash(header.block_hash)), *address), ) .await @@ -684,7 +683,7 @@ async fn get_class_at() { // Get class by block number. let res = module .call::<_, DeprecatedContractClass>( - "starknet_V0_3_0_getClassAt", + "starknet_V0_3_getClassAt", (BlockId::HashOrNumber(BlockHashOrNumber::Number(header.block_number)), *address), ) .await @@ -701,7 +700,7 @@ async fn get_class_at() { // Get class by block hash. let res = module .call::<_, ContractClass>( - "starknet_V0_3_0_getClassAt", + "starknet_V0_3_getClassAt", (BlockId::HashOrNumber(BlockHashOrNumber::Hash(header.block_hash)), *address), ) .await @@ -711,7 +710,7 @@ async fn get_class_at() { // Get class by block number. let res = module .call::<_, ContractClass>( - "starknet_V0_3_0_getClassAt", + "starknet_V0_3_getClassAt", (BlockId::HashOrNumber(BlockHashOrNumber::Number(header.block_number)), *address), ) .await @@ -722,7 +721,7 @@ async fn get_class_at() { // Ask for an invalid contract. let err = module .call::<_, DeprecatedContractClass>( - "starknet_V0_3_0_getClassAt", + "starknet_V0_3_getClassAt", ( BlockId::HashOrNumber(BlockHashOrNumber::Number(header.block_number)), ContractAddress(patricia_key!("0x12")), @@ -739,7 +738,7 @@ async fn get_class_at() { // Ask for an invalid contract in the given block. let err = module .call::<_, DeprecatedContractClass>( - "starknet_V0_3_0_getClassAt", + "starknet_V0_3_getClassAt", ( BlockId::HashOrNumber(BlockHashOrNumber::Number(parent_header.block_number)), *address, @@ -756,7 +755,7 @@ async fn get_class_at() { // Ask for an invalid block hash. let err = module .call::<_, DeprecatedContractClass>( - "starknet_V0_3_0_getClassAt", + "starknet_V0_3_getClassAt", ( BlockId::HashOrNumber(BlockHashOrNumber::Hash(BlockHash(stark_felt!( "0x642b629ad8ce233b55798c83bb629a59bf0a0092f67da28d6d66776680d5484" @@ -775,7 +774,7 @@ async fn get_class_at() { // Ask for an invalid block number. let err = module .call::<_, DeprecatedContractClass>( - "starknet_V0_3_0_getClassAt", + "starknet_V0_3_getClassAt", (BlockId::HashOrNumber(BlockHashOrNumber::Number(BlockNumber(2))), *address), ) .await @@ -790,7 +789,7 @@ async fn get_class_at() { #[tokio::test] async fn get_class_hash_at() { let (module, mut storage_writer) = - get_test_rpc_server_and_storage_writer::(); + get_test_rpc_server_and_storage_writer::(); let header = BlockHeader::default(); let diff = get_test_state_diff(); storage_writer @@ -808,7 +807,7 @@ async fn get_class_hash_at() { // Get class hash by block hash. let res = module .call::<_, ClassHash>( - "starknet_V0_3_0_getClassHashAt", + "starknet_V0_3_getClassHashAt", (BlockId::HashOrNumber(BlockHashOrNumber::Hash(header.block_hash)), *address), ) .await @@ -818,7 +817,7 @@ async fn get_class_hash_at() { // Get class hash by block number. let res = module .call::<_, ClassHash>( - "starknet_V0_3_0_getClassHashAt", + "starknet_V0_3_getClassHashAt", (BlockId::HashOrNumber(BlockHashOrNumber::Number(header.block_number)), *address), ) .await @@ -828,7 +827,7 @@ async fn get_class_hash_at() { // Ask for an invalid contract. let err = module .call::<_, ClassHash>( - "starknet_V0_3_0_getClassHashAt", + "starknet_V0_3_getClassHashAt", ( BlockId::HashOrNumber(BlockHashOrNumber::Number(header.block_number)), ContractAddress(patricia_key!("0x12")), @@ -845,7 +844,7 @@ async fn get_class_hash_at() { // Ask for an invalid block hash. let err = module .call::<_, ClassHash>( - "starknet_V0_3_0_getClassHashAt", + "starknet_V0_3_getClassHashAt", ( BlockId::HashOrNumber(BlockHashOrNumber::Hash(BlockHash(stark_felt!( "0x642b629ad8ce233b55798c83bb629a59bf0a0092f67da28d6d66776680d5484" @@ -864,7 +863,7 @@ async fn get_class_hash_at() { // Ask for an invalid block number. let err = module .call::<_, ClassHash>( - "starknet_V0_3_0_getClassHashAt", + "starknet_V0_3_getClassHashAt", (BlockId::HashOrNumber(BlockHashOrNumber::Number(BlockNumber(1))), *address), ) .await @@ -879,7 +878,7 @@ async fn get_class_hash_at() { #[tokio::test] async fn get_nonce() { let (module, mut storage_writer) = - get_test_rpc_server_and_storage_writer::(); + get_test_rpc_server_and_storage_writer::(); let header = BlockHeader::default(); let diff = get_test_state_diff(); storage_writer @@ -897,7 +896,7 @@ async fn get_nonce() { // Get class hash by block hash. let res = module .call::<_, Nonce>( - "starknet_V0_3_0_getNonce", + "starknet_V0_3_getNonce", (BlockId::HashOrNumber(BlockHashOrNumber::Hash(header.block_hash)), *address), ) .await @@ -907,7 +906,7 @@ async fn get_nonce() { // Get class hash by block number. let res = module .call::<_, Nonce>( - "starknet_V0_3_0_getNonce", + "starknet_V0_3_getNonce", (BlockId::HashOrNumber(BlockHashOrNumber::Number(header.block_number)), *address), ) .await @@ -917,7 +916,7 @@ async fn get_nonce() { // Ask for an invalid contract. let err = module .call::<_, Nonce>( - "starknet_V0_3_0_getNonce", + "starknet_V0_3_getNonce", ( BlockId::HashOrNumber(BlockHashOrNumber::Number(header.block_number)), ContractAddress(patricia_key!("0x31")), @@ -934,7 +933,7 @@ async fn get_nonce() { // Ask for an invalid block hash. let err = module .call::<_, Nonce>( - "starknet_V0_3_0_getNonce", + "starknet_V0_3_getNonce", ( BlockId::HashOrNumber(BlockHashOrNumber::Hash(BlockHash(stark_felt!( "0x642b629ad8ce233b55798c83bb629a59bf0a0092f67da28d6d66776680d5484" @@ -953,7 +952,7 @@ async fn get_nonce() { // Ask for an invalid block number. let err = module .call::<_, Nonce>( - "starknet_V0_3_0_getNonce", + "starknet_V0_3_getNonce", (BlockId::HashOrNumber(BlockHashOrNumber::Number(BlockNumber(1))), *address), ) .await @@ -968,7 +967,7 @@ async fn get_nonce() { #[tokio::test] async fn get_storage_at() { let (module, mut storage_writer) = - get_test_rpc_server_and_storage_writer::(); + get_test_rpc_server_and_storage_writer::(); let header = BlockHeader::default(); let diff = get_test_state_diff(); storage_writer @@ -987,7 +986,7 @@ async fn get_storage_at() { // Get storage by block hash. let res = module .call::<_, StarkFelt>( - "starknet_V0_3_0_getStorageAt", + "starknet_V0_3_getStorageAt", (*address, *key, BlockId::HashOrNumber(BlockHashOrNumber::Hash(header.block_hash))), ) .await @@ -997,7 +996,7 @@ async fn get_storage_at() { // Get storage by block number. let res = module .call::<_, StarkFelt>( - "starknet_V0_3_0_getStorageAt", + "starknet_V0_3_getStorageAt", (*address, *key, BlockId::HashOrNumber(BlockHashOrNumber::Number(header.block_number))), ) .await @@ -1007,7 +1006,7 @@ async fn get_storage_at() { // Ask for an invalid contract. let err = module .call::<_, StarkFelt>( - "starknet_V0_3_0_getStorageAt", + "starknet_V0_3_getStorageAt", ( ContractAddress(patricia_key!("0x12")), key, @@ -1025,7 +1024,7 @@ async fn get_storage_at() { // Ask for an invalid block hash. let err = module .call::<_, StarkFelt>( - "starknet_V0_3_0_getStorageAt", + "starknet_V0_3_getStorageAt", ( *address, key, @@ -1045,7 +1044,7 @@ async fn get_storage_at() { // Ask for an invalid block number. let err = module .call::<_, StarkFelt>( - "starknet_V0_3_0_getStorageAt", + "starknet_V0_3_getStorageAt", (*address, key, BlockId::HashOrNumber(BlockHashOrNumber::Number(BlockNumber(1)))), ) .await @@ -1060,7 +1059,7 @@ async fn get_storage_at() { #[tokio::test] async fn get_transaction_by_hash() { let (module, mut storage_writer) = - get_test_rpc_server_and_storage_writer::(); + get_test_rpc_server_and_storage_writer::(); let block = get_test_block(1, None, None, None); storage_writer .begin_rw_txn() @@ -1076,7 +1075,7 @@ async fn get_transaction_by_hash() { }; let res = module .call::<_, TransactionWithHash>( - "starknet_V0_3_0_getTransactionByHash", + "starknet_V0_3_getTransactionByHash", [block.body.transaction_hashes[0]], ) .await @@ -1086,7 +1085,7 @@ async fn get_transaction_by_hash() { // Ask for an invalid transaction. let err = module .call::<_, TransactionWithHash>( - "starknet_V0_3_0_getTransactionByHash", + "starknet_V0_3_getTransactionByHash", [TransactionHash(StarkHash::from(1_u8))], ) .await @@ -1101,7 +1100,7 @@ async fn get_transaction_by_hash() { #[tokio::test] async fn get_transaction_by_block_id_and_index() { let (module, mut storage_writer) = - get_test_rpc_server_and_storage_writer::(); + get_test_rpc_server_and_storage_writer::(); let block = get_test_block(1, None, None, None); storage_writer .begin_rw_txn() @@ -1121,7 +1120,7 @@ async fn get_transaction_by_block_id_and_index() { // Get transaction by block hash. let res = module .call::<_, TransactionWithHash>( - "starknet_V0_3_0_getTransactionByBlockIdAndIndex", + "starknet_V0_3_getTransactionByBlockIdAndIndex", (BlockId::HashOrNumber(BlockHashOrNumber::Hash(block.header.block_hash)), 0), ) .await @@ -1131,7 +1130,7 @@ async fn get_transaction_by_block_id_and_index() { // Get transaction by block number. let res = module .call::<_, TransactionWithHash>( - "starknet_V0_3_0_getTransactionByBlockIdAndIndex", + "starknet_V0_3_getTransactionByBlockIdAndIndex", (BlockId::HashOrNumber(BlockHashOrNumber::Number(block.header.block_number)), 0), ) .await @@ -1141,7 +1140,7 @@ async fn get_transaction_by_block_id_and_index() { // Ask for an invalid block hash. let err = module .call::<_, TransactionWithHash>( - "starknet_V0_3_0_getTransactionByBlockIdAndIndex", + "starknet_V0_3_getTransactionByBlockIdAndIndex", ( BlockId::HashOrNumber(BlockHashOrNumber::Hash(BlockHash(stark_felt!( "0x642b629ad8ce233b55798c83bb629a59bf0a0092f67da28d6d66776680d5484" @@ -1160,7 +1159,7 @@ async fn get_transaction_by_block_id_and_index() { // Ask for an invalid block number. let err = module .call::<_, TransactionWithHash>( - "starknet_V0_3_0_getTransactionByBlockIdAndIndex", + "starknet_V0_3_getTransactionByBlockIdAndIndex", (BlockId::HashOrNumber(BlockHashOrNumber::Number(BlockNumber(1))), 0), ) .await @@ -1174,7 +1173,7 @@ async fn get_transaction_by_block_id_and_index() { // Ask for an invalid transaction index. let err = module .call::<_, TransactionWithHash>( - "starknet_V0_3_0_getTransactionByBlockIdAndIndex", + "starknet_V0_3_getTransactionByBlockIdAndIndex", (BlockId::HashOrNumber(BlockHashOrNumber::Hash(block.header.block_hash)), 1), ) .await @@ -1189,7 +1188,7 @@ async fn get_transaction_by_block_id_and_index() { #[tokio::test] async fn get_state_update() { let (module, mut storage_writer) = - get_test_rpc_server_and_storage_writer::(); + get_test_rpc_server_and_storage_writer::(); let parent_header = BlockHeader::default(); let header = BlockHeader { block_hash: BlockHash(stark_felt!("0x1")), @@ -1226,7 +1225,7 @@ async fn get_state_update() { // Get state update by block hash. let res = module .call::<_, StateUpdate>( - "starknet_V0_3_0_getStateUpdate", + "starknet_V0_3_getStateUpdate", [BlockId::HashOrNumber(BlockHashOrNumber::Hash(header.block_hash))], ) .await @@ -1236,7 +1235,7 @@ async fn get_state_update() { // Get state update by block number. let res = module .call::<_, StateUpdate>( - "starknet_V0_3_0_getStateUpdate", + "starknet_V0_3_getStateUpdate", [BlockId::HashOrNumber(BlockHashOrNumber::Number(header.block_number))], ) .await @@ -1246,7 +1245,7 @@ async fn get_state_update() { // Ask for an invalid block hash. let err = module .call::<_, StateUpdate>( - "starknet_V0_3_0_getStateUpdate", + "starknet_V0_3_getStateUpdate", [BlockId::HashOrNumber(BlockHashOrNumber::Hash(BlockHash(stark_felt!( "0x642b629ad8ce233b55798c83bb629a59bf0a0092f67da28d6d66776680d5484" ))))], @@ -1262,7 +1261,7 @@ async fn get_state_update() { // Ask for an invalid block number. let err = module .call::<_, StateUpdate>( - "starknet_V0_3_0_getStateUpdate", + "starknet_V0_3_getStateUpdate", [BlockId::HashOrNumber(BlockHashOrNumber::Number(BlockNumber(2)))], ) .await @@ -1277,7 +1276,7 @@ async fn get_state_update() { #[tokio::test] async fn get_events_chunk_size_2_with_address() { let (module, mut storage_writer) = - get_test_rpc_server_and_storage_writer::(); + get_test_rpc_server_and_storage_writer::(); let address = ContractAddress(patricia_key!("0x22")); let key0 = EventKey(stark_felt!("0x6")); let key1 = EventKey(stark_felt!("0x7")); @@ -1338,7 +1337,7 @@ async fn get_events_chunk_size_2_with_address() { for (i, chunk) in emitted_events.chunks(chunk_size).enumerate() { let res = module - .call::<_, EventsChunk>("starknet_V0_3_0_getEvents", [filter.clone()]) + .call::<_, EventsChunk>("starknet_V0_3_getEvents", [filter.clone()]) .await .unwrap(); assert_eq!(res.events, chunk); @@ -1361,7 +1360,7 @@ async fn get_events_chunk_size_2_with_address() { #[tokio::test] async fn get_events_chunk_size_2_without_address() { let (module, mut storage_writer) = - get_test_rpc_server_and_storage_writer::(); + get_test_rpc_server_and_storage_writer::(); let key0 = EventKey(stark_felt!("0x6")); let key1 = EventKey(stark_felt!("0x7")); let block = get_test_block( @@ -1419,7 +1418,7 @@ async fn get_events_chunk_size_2_without_address() { for (i, chunk) in emitted_events.chunks(chunk_size).enumerate() { let res = module - .call::<_, EventsChunk>("starknet_V0_3_0_getEvents", [filter.clone()]) + .call::<_, EventsChunk>("starknet_V0_3_getEvents", [filter.clone()]) .await .unwrap(); assert_eq!(res.events, chunk); @@ -1441,7 +1440,7 @@ async fn get_events_chunk_size_2_without_address() { #[tokio::test] async fn get_events_page_size_too_big() { - let (module, _) = get_test_rpc_server_and_storage_writer::(); + let (module, _) = get_test_rpc_server_and_storage_writer::(); // Create the filter. let filter = EventFilter { @@ -1453,8 +1452,7 @@ async fn get_events_page_size_too_big() { keys: vec![], }; - let err = - module.call::<_, EventsChunk>("starknet_V0_3_0_getEvents", [filter]).await.unwrap_err(); + let err = module.call::<_, EventsChunk>("starknet_V0_3_getEvents", [filter]).await.unwrap_err(); assert_matches!(err, Error::Call(err) if err == ErrorObjectOwned::owned( JsonRpcError::PageSizeTooBig as i32, JsonRpcError::PageSizeTooBig.to_string(), @@ -1464,7 +1462,7 @@ async fn get_events_page_size_too_big() { #[tokio::test] async fn get_events_too_many_keys() { - let (module, _) = get_test_rpc_server_and_storage_writer::(); + let (module, _) = get_test_rpc_server_and_storage_writer::(); let keys = (0..get_test_gateway_config().max_events_keys + 1) .map(|i| HashSet::from([EventKey(StarkFelt::from(i as u128))])) .collect(); @@ -1479,8 +1477,7 @@ async fn get_events_too_many_keys() { keys, }; - let err = - module.call::<_, EventsChunk>("starknet_V0_3_0_getEvents", [filter]).await.unwrap_err(); + let err = module.call::<_, EventsChunk>("starknet_V0_3_getEvents", [filter]).await.unwrap_err(); assert_matches!(err, Error::Call(err) if err == ErrorObjectOwned::owned( JsonRpcError::TooManyKeysInFilter as i32, JsonRpcError::TooManyKeysInFilter.to_string(), @@ -1490,7 +1487,7 @@ async fn get_events_too_many_keys() { #[tokio::test] async fn get_events_no_blocks() { - let (module, _) = get_test_rpc_server_and_storage_writer::(); + let (module, _) = get_test_rpc_server_and_storage_writer::(); // Create the filter. let filter = EventFilter { @@ -1502,14 +1499,14 @@ async fn get_events_no_blocks() { keys: vec![], }; - let res = module.call::<_, EventsChunk>("starknet_V0_3_0_getEvents", [filter]).await.unwrap(); + let res = module.call::<_, EventsChunk>("starknet_V0_3_getEvents", [filter]).await.unwrap(); assert_eq!(res, EventsChunk { events: vec![], continuation_token: None }); } #[tokio::test] async fn get_events_no_blocks_in_filter() { let (module, mut storage_writer) = - get_test_rpc_server_and_storage_writer::(); + get_test_rpc_server_and_storage_writer::(); let parent_block = starknet_api::block::Block::default(); let block = starknet_api::block::Block { header: BlockHeader { @@ -1544,14 +1541,14 @@ async fn get_events_no_blocks_in_filter() { keys: vec![], }; - let res = module.call::<_, EventsChunk>("starknet_V0_3_0_getEvents", [filter]).await.unwrap(); + let res = module.call::<_, EventsChunk>("starknet_V0_3_getEvents", [filter]).await.unwrap(); assert_eq!(res, EventsChunk { events: vec![], continuation_token: None }); } #[tokio::test] async fn get_events_invalid_ct() { let (module, mut storage_writer) = - get_test_rpc_server_and_storage_writer::(); + get_test_rpc_server_and_storage_writer::(); let block = starknet_api::block::Block::default(); storage_writer .begin_rw_txn() @@ -1573,8 +1570,7 @@ async fn get_events_invalid_ct() { keys: vec![], }; - let err = - module.call::<_, EventsChunk>("starknet_V0_3_0_getEvents", [filter]).await.unwrap_err(); + let err = module.call::<_, EventsChunk>("starknet_V0_3_getEvents", [filter]).await.unwrap_err(); assert_matches!(err, Error::Call(err) if err == ErrorObjectOwned::owned( JsonRpcError::InvalidContinuationToken as i32, JsonRpcError::InvalidContinuationToken.to_string(), @@ -1641,7 +1637,7 @@ async fn serialize_returns_valid_json() { "TXN_RECEIPT", "EVENTS_CHUNK", ], - VERSION_0_3_0, + &VERSION_0_3, ) .await; validate_state(&state_diff, server_address, &schema).await; @@ -1654,7 +1650,7 @@ async fn validate_state(state_diff: &StateDiff, server_address: SocketAddr, sche server_address, "starknet_getStateUpdate", r#"{"block_number": 1}"#, - VERSION_0_3_0, + VERSION_0_3.name, ) .await; assert!(schema.validate(&res["result"]).is_ok(), "State update is not valid."); @@ -1664,7 +1660,7 @@ async fn validate_state(state_diff: &StateDiff, server_address: SocketAddr, sche server_address, "starknet_getClassAt", format!(r#"{{"block_number": 1}}, "0x{}""#, hex::encode(address.0.key().bytes())).as_str(), - VERSION_0_3_0, + VERSION_0_3.name, ) .await; assert!(schema.validate(&res["result"]).is_ok(), "Class is not valid."); @@ -1676,7 +1672,7 @@ async fn validate_state(state_diff: &StateDiff, server_address: SocketAddr, sche server_address, "starknet_getClassAt", format!(r#"{{"block_number": 1}}, "0x{}""#, hex::encode(address.0.key().bytes())).as_str(), - VERSION_0_3_0, + VERSION_0_3.name, ) .await; assert!(schema.validate(&res["result"]).is_ok(), "Class is not valid."); @@ -1687,7 +1683,7 @@ async fn validate_block(header: &BlockHeader, server_address: SocketAddr, schema server_address, "starknet_getBlockWithTxs", r#"{"block_number": 1}"#, - VERSION_0_3_0, + VERSION_0_3.name, ) .await; assert!(schema.validate(&res["result"]).is_ok(), "Block with transactions is not valid."); @@ -1696,7 +1692,7 @@ async fn validate_block(header: &BlockHeader, server_address: SocketAddr, schema server_address, "starknet_getBlockWithTxHashes", format!(r#"{{"block_hash": "0x{}"}}"#, hex::encode(header.block_hash.0.bytes())).as_str(), - VERSION_0_3_0, + VERSION_0_3.name, ) .await; assert!(schema.validate(&res["result"]).is_ok(), "Block with transaction hashes is not valid."); @@ -1711,7 +1707,7 @@ async fn validate_transaction( server_address, "starknet_getTransactionByBlockIdAndIndex", r#"{"block_number": 1}, 0"#, - VERSION_0_3_0, + VERSION_0_3.name, ) .await; assert!(schema.validate(&res["result"]).is_ok(), "Transaction is not valid."); @@ -1720,7 +1716,7 @@ async fn validate_transaction( server_address, "starknet_getTransactionByHash", format!(r#""0x{}""#, hex::encode(tx_hash.0.bytes())).as_str(), - VERSION_0_3_0, + VERSION_0_3.name, ) .await; assert!(schema.validate(&res["result"]).is_ok(), "Transaction is not valid."); @@ -1729,14 +1725,18 @@ async fn validate_transaction( server_address, "starknet_getTransactionReceipt", format!(r#""0x{}""#, hex::encode(tx_hash.0.bytes())).as_str(), - VERSION_0_3_0, + VERSION_0_3.name, ) .await; assert!(schema.validate(&res["result"]).is_ok(), "Transaction receipt is not valid."); - let res = - send_request(server_address, "starknet_getEvents", r#"{"chunk_size": 2}"#, VERSION_0_3_0) - .await; + let res = send_request( + server_address, + "starknet_getEvents", + r#"{"chunk_size": 2}"#, + VERSION_0_3.name, + ) + .await; assert!(schema.validate(&res["result"]).is_ok(), "Events are not valid."); } @@ -1782,7 +1782,7 @@ async fn get_deprecated_class_state_mutability() { }; let (module, mut storage_writer) = - get_test_rpc_server_and_storage_writer::(); + get_test_rpc_server_and_storage_writer::(); let header = BlockHeader::default(); storage_writer @@ -1798,7 +1798,7 @@ async fn get_deprecated_class_state_mutability() { // Get class without state mutability. let res = module .call::<_, DeprecatedContractClass>( - "starknet_V0_3_0_getClass", + "starknet_V0_3_getClass", ( BlockId::HashOrNumber(BlockHashOrNumber::Hash(header.block_hash)), ClassHash(stark_felt!("0x0")), @@ -1813,7 +1813,7 @@ async fn get_deprecated_class_state_mutability() { // Get class with state mutability. let res = module .call::<_, DeprecatedContractClass>( - "starknet_V0_3_0_getClass", + "starknet_V0_3_getClass", ( BlockId::HashOrNumber(BlockHashOrNumber::Hash(header.block_hash)), ClassHash(stark_felt!("0x1")), diff --git a/crates/papyrus_gateway/src/v0_3_0/broadcasted_transaction_test.rs b/crates/papyrus_gateway/src/v0_3_0/broadcasted_transaction_test.rs index 54c36b8c36..d5307a12e2 100644 --- a/crates/papyrus_gateway/src/v0_3_0/broadcasted_transaction_test.rs +++ b/crates/papyrus_gateway/src/v0_3_0/broadcasted_transaction_test.rs @@ -25,7 +25,7 @@ use super::broadcasted_transaction::{ }; use super::state::ContractClass; use crate::test_utils::get_starknet_spec_api_schema; -use crate::version_config::VERSION_0_3_0; +use crate::version_config::VERSION_0_3; auto_impl_get_test_instance! { pub struct BroadcastedDeployAccountTransaction { @@ -73,7 +73,7 @@ auto_impl_get_test_instance! { fn validate_tx_fits_rpc(tx: BroadcastedTransaction) { lazy_static! { static ref SCHEMA: JSONSchema = - block_on(get_starknet_spec_api_schema(&["BROADCASTED_TXN"], VERSION_0_3_0)); + block_on(get_starknet_spec_api_schema(&["BROADCASTED_TXN"], &VERSION_0_3)); } assert!(SCHEMA.is_valid(&serde_json::to_value(tx).unwrap())); } diff --git a/crates/papyrus_gateway/src/v0_4_0/api/api_impl.rs b/crates/papyrus_gateway/src/v0_4_0/api/api_impl.rs index 403f586dbd..65a1b47f3c 100644 --- a/crates/papyrus_gateway/src/v0_4_0/api/api_impl.rs +++ b/crates/papyrus_gateway/src/v0_4_0/api/api_impl.rs @@ -22,8 +22,7 @@ use super::super::transaction::{ TransactionWithHash, Transactions, }; use super::{ - BlockHashAndNumber, BlockId, EventFilter, EventsChunk, GatewayContractClass, - JsonRpcV0_4_0Server, + BlockHashAndNumber, BlockId, EventFilter, EventsChunk, GatewayContractClass, JsonRpcV0_4Server, }; use crate::api::{BlockHashOrNumber, ContinuationToken, JsonRpcError, JsonRpcServerImpl}; use crate::block::get_block_header_by_number; @@ -34,7 +33,7 @@ use crate::{ }; /// Rpc server. -pub struct JsonRpcServerV0_4_0Impl { +pub struct JsonRpcServerV0_4Impl { pub chain_id: ChainId, pub storage_reader: StorageReader, pub max_events_chunk_size: usize, @@ -42,7 +41,7 @@ pub struct JsonRpcServerV0_4_0Impl { } #[async_trait] -impl JsonRpcV0_4_0Server for JsonRpcServerV0_4_0Impl { +impl JsonRpcV0_4Server for JsonRpcServerV0_4Impl { #[instrument(skip(self), level = "debug", err, ret)] fn block_number(&self) -> RpcResult { let txn = self.storage_reader.begin_ro_txn().map_err(internal_server_error)?; @@ -434,7 +433,7 @@ impl JsonRpcV0_4_0Server for JsonRpcServerV0_4_0Impl { } } -impl JsonRpcServerImpl for JsonRpcServerV0_4_0Impl { +impl JsonRpcServerImpl for JsonRpcServerV0_4Impl { fn new( chain_id: ChainId, storage_reader: StorageReader, diff --git a/crates/papyrus_gateway/src/v0_4_0/api/mod.rs b/crates/papyrus_gateway/src/v0_4_0/api/mod.rs index ea0c3994f7..cededc0044 100644 --- a/crates/papyrus_gateway/src/v0_4_0/api/mod.rs +++ b/crates/papyrus_gateway/src/v0_4_0/api/mod.rs @@ -19,7 +19,7 @@ pub mod api_impl; #[cfg(test)] mod test; -#[versioned_rpc("V0_4_0")] +#[versioned_rpc("V0_4")] pub trait JsonRpc { /// Gets the most recent accepted block number. #[method(name = "blockNumber")] diff --git a/crates/papyrus_gateway/src/v0_4_0/api/test.rs b/crates/papyrus_gateway/src/v0_4_0/api/test.rs index 63d0463feb..9dedc78412 100644 --- a/crates/papyrus_gateway/src/v0_4_0/api/test.rs +++ b/crates/papyrus_gateway/src/v0_4_0/api/test.rs @@ -40,7 +40,7 @@ use super::super::transaction::{ Event, TransactionFinalityStatus, TransactionOutput, TransactionReceipt, TransactionReceiptWithStatus, TransactionWithHash, Transactions, }; -use super::api_impl::JsonRpcServerV0_4_0Impl; +use super::api_impl::JsonRpcServerV0_4Impl; use crate::api::{ BlockHashAndNumber, BlockHashOrNumber, BlockId, ContinuationToken, EventFilter, JsonRpcError, Tag, @@ -48,15 +48,14 @@ use crate::api::{ use crate::test_utils::{ get_starknet_spec_api_schema, get_test_gateway_config, get_test_rpc_server_and_storage_writer, }; -use crate::version_config::VERSION_0_4_0; +use crate::version_config::VERSION_0_4; use crate::{run_server, ContinuationTokenAsStruct}; #[tokio::test] async fn chain_id() { - let (module, _) = get_test_rpc_server_and_storage_writer::(); + let (module, _) = get_test_rpc_server_and_storage_writer::(); - let res = - module.call::<_, String>("starknet_V0_4_0_chainId", ObjectParams::new()).await.unwrap(); + let res = module.call::<_, String>("starknet_V0_4_chainId", ObjectParams::new()).await.unwrap(); // The result should be equal to the result of the following python code // hex(int.from_bytes(b'SN_GOERLI', byteorder="big", signed=False)) // taken from starknet documentation: @@ -67,11 +66,11 @@ async fn chain_id() { #[tokio::test] async fn block_hash_and_number() { let (module, mut storage_writer) = - get_test_rpc_server_and_storage_writer::(); + get_test_rpc_server_and_storage_writer::(); // No blocks yet. let err = module - .call::<_, BlockHashAndNumber>("starknet_V0_4_0_blockHashAndNumber", ObjectParams::new()) + .call::<_, BlockHashAndNumber>("starknet_V0_4_blockHashAndNumber", ObjectParams::new()) .await .unwrap_err(); assert_matches!(err, Error::Call(err) if err == ErrorObjectOwned::owned( @@ -90,7 +89,7 @@ async fn block_hash_and_number() { .commit() .unwrap(); let block_hash_and_number = module - .call::<_, BlockHashAndNumber>("starknet_V0_4_0_blockHashAndNumber", ObjectParams::new()) + .call::<_, BlockHashAndNumber>("starknet_V0_4_blockHashAndNumber", ObjectParams::new()) .await .unwrap(); assert_eq!( @@ -105,11 +104,11 @@ async fn block_hash_and_number() { #[tokio::test] async fn block_number() { let (module, mut storage_writer) = - get_test_rpc_server_and_storage_writer::(); + get_test_rpc_server_and_storage_writer::(); // No blocks yet. let err = module - .call::<_, BlockNumber>("starknet_V0_4_0_blockNumber", ObjectParams::new()) + .call::<_, BlockNumber>("starknet_V0_4_blockNumber", ObjectParams::new()) .await .unwrap_err(); assert_matches!(err, Error::Call(err) if err == ErrorObjectOwned::owned( @@ -127,7 +126,7 @@ async fn block_number() { .commit() .unwrap(); let block_number = module - .call::<_, BlockNumber>("starknet_V0_4_0_blockNumber", ObjectParams::new()) + .call::<_, BlockNumber>("starknet_V0_4_blockNumber", ObjectParams::new()) .await .unwrap(); assert_eq!(block_number, BlockNumber(0)); @@ -135,15 +134,15 @@ async fn block_number() { #[tokio::test] async fn syncing() { - let (module, _) = get_test_rpc_server_and_storage_writer::(); - let res = module.call::<_, bool>("starknet_V0_4_0_syncing", ObjectParams::new()).await.unwrap(); + let (module, _) = get_test_rpc_server_and_storage_writer::(); + let res = module.call::<_, bool>("starknet_V0_4_syncing", ObjectParams::new()).await.unwrap(); assert_eq!(res, false); } #[tokio::test] async fn get_block_transaction_count() { let (module, mut storage_writer) = - get_test_rpc_server_and_storage_writer::(); + get_test_rpc_server_and_storage_writer::(); let transaction_count = 5; let block = get_test_block(transaction_count, None, None, None); storage_writer @@ -159,7 +158,7 @@ async fn get_block_transaction_count() { // Get block by hash. let res = module .call::<_, usize>( - "starknet_V0_4_0_getBlockTransactionCount", + "starknet_V0_4_getBlockTransactionCount", [BlockId::HashOrNumber(BlockHashOrNumber::Hash(block.header.block_hash))], ) .await @@ -169,7 +168,7 @@ async fn get_block_transaction_count() { // Get block by number. let res = module .call::<_, usize>( - "starknet_V0_4_0_getBlockTransactionCount", + "starknet_V0_4_getBlockTransactionCount", [BlockId::HashOrNumber(BlockHashOrNumber::Number(block.header.block_number))], ) .await @@ -178,7 +177,7 @@ async fn get_block_transaction_count() { // Ask for the latest block. let res = module - .call::<_, usize>("starknet_V0_4_0_getBlockTransactionCount", [BlockId::Tag(Tag::Latest)]) + .call::<_, usize>("starknet_V0_4_getBlockTransactionCount", [BlockId::Tag(Tag::Latest)]) .await .unwrap(); assert_eq!(res, transaction_count); @@ -186,7 +185,7 @@ async fn get_block_transaction_count() { // Ask for an invalid block hash. let err = module .call::<_, usize>( - "starknet_V0_4_0_getBlockTransactionCount", + "starknet_V0_4_getBlockTransactionCount", [BlockId::HashOrNumber(BlockHashOrNumber::Hash(BlockHash(stark_felt!( "0x642b629ad8ce233b55798c83bb629a59bf0a0092f67da28d6d66776680d5484" ))))], @@ -202,7 +201,7 @@ async fn get_block_transaction_count() { // Ask for an invalid block number. let err = module .call::<_, usize>( - "starknet_V0_4_0_getBlockTransactionCount", + "starknet_V0_4_getBlockTransactionCount", [BlockId::HashOrNumber(BlockHashOrNumber::Number(BlockNumber(1)))], ) .await @@ -217,7 +216,7 @@ async fn get_block_transaction_count() { #[tokio::test] async fn get_block_w_full_transactions() { let (module, mut storage_writer) = - get_test_rpc_server_and_storage_writer::(); + get_test_rpc_server_and_storage_writer::(); let block = get_test_block(1, None, None, None); storage_writer @@ -243,7 +242,7 @@ async fn get_block_w_full_transactions() { // Get block by hash. let block = module .call::<_, Block>( - "starknet_V0_4_0_getBlockWithTxs", + "starknet_V0_4_getBlockWithTxs", [BlockId::HashOrNumber(BlockHashOrNumber::Hash(expected_block.header.block_hash))], ) .await @@ -253,7 +252,7 @@ async fn get_block_w_full_transactions() { // Get block by number. let block = module .call::<_, Block>( - "starknet_V0_4_0_getBlockWithTxs", + "starknet_V0_4_getBlockWithTxs", [BlockId::HashOrNumber(BlockHashOrNumber::Number(expected_block.header.block_number))], ) .await @@ -262,7 +261,7 @@ async fn get_block_w_full_transactions() { // Ask for the latest block. let block = module - .call::<_, Block>("starknet_V0_4_0_getBlockWithTxs", [BlockId::Tag(Tag::Latest)]) + .call::<_, Block>("starknet_V0_4_getBlockWithTxs", [BlockId::Tag(Tag::Latest)]) .await .unwrap(); assert_eq!(block, expected_block); @@ -277,7 +276,7 @@ async fn get_block_w_full_transactions() { .unwrap(); let block = module .call::<_, Block>( - "starknet_V0_4_0_getBlockWithTxs", + "starknet_V0_4_getBlockWithTxs", [BlockId::HashOrNumber(BlockHashOrNumber::Hash(expected_block.header.block_hash))], ) .await @@ -287,7 +286,7 @@ async fn get_block_w_full_transactions() { // Ask for an invalid block hash. let err = module .call::<_, Block>( - "starknet_V0_4_0_getBlockWithTxs", + "starknet_V0_4_getBlockWithTxs", [BlockId::HashOrNumber(BlockHashOrNumber::Hash(BlockHash(stark_felt!( "0x642b629ad8ce233b55798c83bb629a59bf0a0092f67da28d6d66776680d5484" ))))], @@ -303,7 +302,7 @@ async fn get_block_w_full_transactions() { // Ask for an invalid block number. let err = module .call::<_, Block>( - "starknet_V0_4_0_getBlockWithTxs", + "starknet_V0_4_getBlockWithTxs", [BlockId::HashOrNumber(BlockHashOrNumber::Number(BlockNumber(1)))], ) .await @@ -318,7 +317,7 @@ async fn get_block_w_full_transactions() { #[tokio::test] async fn get_block_w_transaction_hashes() { let (module, mut storage_writer) = - get_test_rpc_server_and_storage_writer::(); + get_test_rpc_server_and_storage_writer::(); let block = get_test_block(1, None, None, None); storage_writer @@ -340,7 +339,7 @@ async fn get_block_w_transaction_hashes() { // Get block by hash. let block = module .call::<_, Block>( - "starknet_V0_4_0_getBlockWithTxHashes", + "starknet_V0_4_getBlockWithTxHashes", [BlockId::HashOrNumber(BlockHashOrNumber::Hash(expected_block.header.block_hash))], ) .await @@ -350,7 +349,7 @@ async fn get_block_w_transaction_hashes() { // Get block by number. let block = module .call::<_, Block>( - "starknet_V0_4_0_getBlockWithTxHashes", + "starknet_V0_4_getBlockWithTxHashes", [BlockId::HashOrNumber(BlockHashOrNumber::Number(expected_block.header.block_number))], ) .await @@ -359,7 +358,7 @@ async fn get_block_w_transaction_hashes() { // Ask for the latest block. let block = module - .call::<_, Block>("starknet_V0_4_0_getBlockWithTxHashes", [BlockId::Tag(Tag::Latest)]) + .call::<_, Block>("starknet_V0_4_getBlockWithTxHashes", [BlockId::Tag(Tag::Latest)]) .await .unwrap(); assert_eq!(block, expected_block); @@ -374,7 +373,7 @@ async fn get_block_w_transaction_hashes() { .unwrap(); let block = module .call::<_, Block>( - "starknet_V0_4_0_getBlockWithTxHashes", + "starknet_V0_4_getBlockWithTxHashes", [BlockId::HashOrNumber(BlockHashOrNumber::Hash(expected_block.header.block_hash))], ) .await @@ -384,7 +383,7 @@ async fn get_block_w_transaction_hashes() { // Ask for an invalid block hash. let err = module .call::<_, Block>( - "starknet_V0_4_0_getBlockWithTxHashes", + "starknet_V0_4_getBlockWithTxHashes", [BlockId::HashOrNumber(BlockHashOrNumber::Hash(BlockHash(stark_felt!( "0x642b629ad8ce233b55798c83bb629a59bf0a0092f67da28d6d66776680d5484" ))))], @@ -400,7 +399,7 @@ async fn get_block_w_transaction_hashes() { // Ask for an invalid block number. let err = module .call::<_, Block>( - "starknet_V0_4_0_getBlockWithTxHashes", + "starknet_V0_4_getBlockWithTxHashes", [BlockId::HashOrNumber(BlockHashOrNumber::Number(BlockNumber(1)))], ) .await @@ -415,7 +414,7 @@ async fn get_block_w_transaction_hashes() { #[tokio::test] async fn get_class() { let (module, mut storage_writer) = - get_test_rpc_server_and_storage_writer::(); + get_test_rpc_server_and_storage_writer::(); let parent_header = BlockHeader::default(); let header = BlockHeader { block_hash: BlockHash(stark_felt!("0x1")), @@ -449,7 +448,7 @@ async fn get_class() { // Get class by block hash. let res = module .call::<_, DeprecatedContractClass>( - "starknet_V0_4_0_getClass", + "starknet_V0_4_getClass", (BlockId::HashOrNumber(BlockHashOrNumber::Hash(header.block_hash)), *class_hash), ) .await @@ -459,7 +458,7 @@ async fn get_class() { // Get class by block number. let res = module .call::<_, DeprecatedContractClass>( - "starknet_V0_4_0_getClass", + "starknet_V0_4_getClass", (BlockId::HashOrNumber(BlockHashOrNumber::Number(header.block_number)), *class_hash), ) .await @@ -469,7 +468,7 @@ async fn get_class() { // Ask for an invalid class hash. let err = module .call::<_, DeprecatedContractClass>( - "starknet_V0_4_0_getClass", + "starknet_V0_4_getClass", ( BlockId::HashOrNumber(BlockHashOrNumber::Number(header.block_number)), ClassHash(stark_felt!("0x7")), @@ -491,7 +490,7 @@ async fn get_class() { // Get class by block hash. let res = module .call::<_, ContractClass>( - "starknet_V0_4_0_getClass", + "starknet_V0_4_getClass", (BlockId::HashOrNumber(BlockHashOrNumber::Hash(header.block_hash)), *class_hash), ) .await @@ -501,7 +500,7 @@ async fn get_class() { // Get class by block number. let res = module .call::<_, ContractClass>( - "starknet_V0_4_0_getClass", + "starknet_V0_4_getClass", (BlockId::HashOrNumber(BlockHashOrNumber::Number(header.block_number)), *class_hash), ) .await @@ -512,7 +511,7 @@ async fn get_class() { // Ask for an invalid class hash in the given block. let err = module .call::<_, DeprecatedContractClass>( - "starknet_V0_4_0_getClass", + "starknet_V0_4_getClass", ( BlockId::HashOrNumber(BlockHashOrNumber::Number(parent_header.block_number)), *class_hash, @@ -529,7 +528,7 @@ async fn get_class() { // Ask for an invalid block hash. let err = module .call::<_, DeprecatedContractClass>( - "starknet_V0_4_0_getClass", + "starknet_V0_4_getClass", ( BlockId::HashOrNumber(BlockHashOrNumber::Hash(BlockHash(stark_felt!( "0x642b629ad8ce233b55798c83bb629a59bf0a0092f67da28d6d66776680d5484" @@ -548,7 +547,7 @@ async fn get_class() { // Ask for an invalid block number. let err = module .call::<_, DeprecatedContractClass>( - "starknet_V0_4_0_getClass", + "starknet_V0_4_getClass", (BlockId::HashOrNumber(BlockHashOrNumber::Number(BlockNumber(2))), *class_hash), ) .await @@ -563,7 +562,7 @@ async fn get_class() { #[tokio::test] async fn get_transaction_receipt() { let (module, mut storage_writer) = - get_test_rpc_server_and_storage_writer::(); + get_test_rpc_server_and_storage_writer::(); let block = get_test_block(1, None, None, None); storage_writer .begin_rw_txn() @@ -589,7 +588,7 @@ async fn get_transaction_receipt() { }; let res = module .call::<_, TransactionReceiptWithStatus>( - "starknet_V0_4_0_getTransactionReceipt", + "starknet_V0_4_getTransactionReceipt", [transaction_hash], ) .await @@ -612,7 +611,7 @@ async fn get_transaction_receipt() { .unwrap(); let res = module .call::<_, TransactionReceiptWithStatus>( - "starknet_V0_4_0_getTransactionReceipt", + "starknet_V0_4_getTransactionReceipt", [transaction_hash], ) .await @@ -623,7 +622,7 @@ async fn get_transaction_receipt() { // Ask for an invalid transaction. let err = module .call::<_, TransactionReceiptWithStatus>( - "starknet_V0_4_0_getTransactionReceipt", + "starknet_V0_4_getTransactionReceipt", [TransactionHash(StarkHash::from(1_u8))], ) .await @@ -638,7 +637,7 @@ async fn get_transaction_receipt() { #[tokio::test] async fn get_class_at() { let (module, mut storage_writer) = - get_test_rpc_server_and_storage_writer::(); + get_test_rpc_server_and_storage_writer::(); let parent_header = BlockHeader::default(); let header = BlockHeader { block_hash: BlockHash(stark_felt!("0x1")), @@ -677,7 +676,7 @@ async fn get_class_at() { // Get class by block hash. let res = module .call::<_, DeprecatedContractClass>( - "starknet_V0_4_0_getClassAt", + "starknet_V0_4_getClassAt", (BlockId::HashOrNumber(BlockHashOrNumber::Hash(header.block_hash)), *address), ) .await @@ -687,7 +686,7 @@ async fn get_class_at() { // Get class by block number. let res = module .call::<_, DeprecatedContractClass>( - "starknet_V0_4_0_getClassAt", + "starknet_V0_4_getClassAt", (BlockId::HashOrNumber(BlockHashOrNumber::Number(header.block_number)), *address), ) .await @@ -704,7 +703,7 @@ async fn get_class_at() { // Get class by block hash. let res = module .call::<_, ContractClass>( - "starknet_V0_4_0_getClassAt", + "starknet_V0_4_getClassAt", (BlockId::HashOrNumber(BlockHashOrNumber::Hash(header.block_hash)), *address), ) .await @@ -714,7 +713,7 @@ async fn get_class_at() { // Get class by block number. let res = module .call::<_, ContractClass>( - "starknet_V0_4_0_getClassAt", + "starknet_V0_4_getClassAt", (BlockId::HashOrNumber(BlockHashOrNumber::Number(header.block_number)), *address), ) .await @@ -725,7 +724,7 @@ async fn get_class_at() { // Ask for an invalid contract. let err = module .call::<_, DeprecatedContractClass>( - "starknet_V0_4_0_getClassAt", + "starknet_V0_4_getClassAt", ( BlockId::HashOrNumber(BlockHashOrNumber::Number(header.block_number)), ContractAddress(patricia_key!("0x12")), @@ -742,7 +741,7 @@ async fn get_class_at() { // Ask for an invalid contract in the given block. let err = module .call::<_, DeprecatedContractClass>( - "starknet_V0_4_0_getClassAt", + "starknet_V0_4_getClassAt", ( BlockId::HashOrNumber(BlockHashOrNumber::Number(parent_header.block_number)), *address, @@ -759,7 +758,7 @@ async fn get_class_at() { // Ask for an invalid block hash. let err = module .call::<_, DeprecatedContractClass>( - "starknet_V0_4_0_getClassAt", + "starknet_V0_4_getClassAt", ( BlockId::HashOrNumber(BlockHashOrNumber::Hash(BlockHash(stark_felt!( "0x642b629ad8ce233b55798c83bb629a59bf0a0092f67da28d6d66776680d5484" @@ -778,7 +777,7 @@ async fn get_class_at() { // Ask for an invalid block number. let err = module .call::<_, DeprecatedContractClass>( - "starknet_V0_4_0_getClassAt", + "starknet_V0_4_getClassAt", (BlockId::HashOrNumber(BlockHashOrNumber::Number(BlockNumber(2))), *address), ) .await @@ -793,7 +792,7 @@ async fn get_class_at() { #[tokio::test] async fn get_class_hash_at() { let (module, mut storage_writer) = - get_test_rpc_server_and_storage_writer::(); + get_test_rpc_server_and_storage_writer::(); let header = BlockHeader::default(); let diff = get_test_state_diff(); storage_writer @@ -811,7 +810,7 @@ async fn get_class_hash_at() { // Get class hash by block hash. let res = module .call::<_, ClassHash>( - "starknet_V0_4_0_getClassHashAt", + "starknet_V0_4_getClassHashAt", (BlockId::HashOrNumber(BlockHashOrNumber::Hash(header.block_hash)), *address), ) .await @@ -821,7 +820,7 @@ async fn get_class_hash_at() { // Get class hash by block number. let res = module .call::<_, ClassHash>( - "starknet_V0_4_0_getClassHashAt", + "starknet_V0_4_getClassHashAt", (BlockId::HashOrNumber(BlockHashOrNumber::Number(header.block_number)), *address), ) .await @@ -831,7 +830,7 @@ async fn get_class_hash_at() { // Ask for an invalid contract. let err = module .call::<_, ClassHash>( - "starknet_V0_4_0_getClassHashAt", + "starknet_V0_4_getClassHashAt", ( BlockId::HashOrNumber(BlockHashOrNumber::Number(header.block_number)), ContractAddress(patricia_key!("0x12")), @@ -848,7 +847,7 @@ async fn get_class_hash_at() { // Ask for an invalid block hash. let err = module .call::<_, ClassHash>( - "starknet_V0_4_0_getClassHashAt", + "starknet_V0_4_getClassHashAt", ( BlockId::HashOrNumber(BlockHashOrNumber::Hash(BlockHash(stark_felt!( "0x642b629ad8ce233b55798c83bb629a59bf0a0092f67da28d6d66776680d5484" @@ -867,7 +866,7 @@ async fn get_class_hash_at() { // Ask for an invalid block number. let err = module .call::<_, ClassHash>( - "starknet_V0_4_0_getClassHashAt", + "starknet_V0_4_getClassHashAt", (BlockId::HashOrNumber(BlockHashOrNumber::Number(BlockNumber(1))), *address), ) .await @@ -882,7 +881,7 @@ async fn get_class_hash_at() { #[tokio::test] async fn get_nonce() { let (module, mut storage_writer) = - get_test_rpc_server_and_storage_writer::(); + get_test_rpc_server_and_storage_writer::(); let header = BlockHeader::default(); let diff = get_test_state_diff(); storage_writer @@ -900,7 +899,7 @@ async fn get_nonce() { // Get class hash by block hash. let res = module .call::<_, Nonce>( - "starknet_V0_4_0_getNonce", + "starknet_V0_4_getNonce", (BlockId::HashOrNumber(BlockHashOrNumber::Hash(header.block_hash)), *address), ) .await @@ -910,7 +909,7 @@ async fn get_nonce() { // Get class hash by block number. let res = module .call::<_, Nonce>( - "starknet_V0_4_0_getNonce", + "starknet_V0_4_getNonce", (BlockId::HashOrNumber(BlockHashOrNumber::Number(header.block_number)), *address), ) .await @@ -920,7 +919,7 @@ async fn get_nonce() { // Ask for an invalid contract. let err = module .call::<_, Nonce>( - "starknet_V0_4_0_getNonce", + "starknet_V0_4_getNonce", ( BlockId::HashOrNumber(BlockHashOrNumber::Number(header.block_number)), ContractAddress(patricia_key!("0x31")), @@ -937,7 +936,7 @@ async fn get_nonce() { // Ask for an invalid block hash. let err = module .call::<_, Nonce>( - "starknet_V0_4_0_getNonce", + "starknet_V0_4_getNonce", ( BlockId::HashOrNumber(BlockHashOrNumber::Hash(BlockHash(stark_felt!( "0x642b629ad8ce233b55798c83bb629a59bf0a0092f67da28d6d66776680d5484" @@ -956,7 +955,7 @@ async fn get_nonce() { // Ask for an invalid block number. let err = module .call::<_, Nonce>( - "starknet_V0_4_0_getNonce", + "starknet_V0_4_getNonce", (BlockId::HashOrNumber(BlockHashOrNumber::Number(BlockNumber(1))), *address), ) .await @@ -971,7 +970,7 @@ async fn get_nonce() { #[tokio::test] async fn get_storage_at() { let (module, mut storage_writer) = - get_test_rpc_server_and_storage_writer::(); + get_test_rpc_server_and_storage_writer::(); let header = BlockHeader::default(); let diff = get_test_state_diff(); storage_writer @@ -990,7 +989,7 @@ async fn get_storage_at() { // Get storage by block hash. let res = module .call::<_, StarkFelt>( - "starknet_V0_4_0_getStorageAt", + "starknet_V0_4_getStorageAt", (*address, *key, BlockId::HashOrNumber(BlockHashOrNumber::Hash(header.block_hash))), ) .await @@ -1000,7 +999,7 @@ async fn get_storage_at() { // Get storage by block number. let res = module .call::<_, StarkFelt>( - "starknet_V0_4_0_getStorageAt", + "starknet_V0_4_getStorageAt", (*address, *key, BlockId::HashOrNumber(BlockHashOrNumber::Number(header.block_number))), ) .await @@ -1010,7 +1009,7 @@ async fn get_storage_at() { // Ask for an invalid contract. let err = module .call::<_, StarkFelt>( - "starknet_V0_4_0_getStorageAt", + "starknet_V0_4_getStorageAt", ( ContractAddress(patricia_key!("0x12")), key, @@ -1028,7 +1027,7 @@ async fn get_storage_at() { // Ask for an invalid block hash. let err = module .call::<_, StarkFelt>( - "starknet_V0_4_0_getStorageAt", + "starknet_V0_4_getStorageAt", ( *address, key, @@ -1048,7 +1047,7 @@ async fn get_storage_at() { // Ask for an invalid block number. let err = module .call::<_, StarkFelt>( - "starknet_V0_4_0_getStorageAt", + "starknet_V0_4_getStorageAt", (*address, key, BlockId::HashOrNumber(BlockHashOrNumber::Number(BlockNumber(1)))), ) .await @@ -1063,7 +1062,7 @@ async fn get_storage_at() { #[tokio::test] async fn get_transaction_by_hash() { let (module, mut storage_writer) = - get_test_rpc_server_and_storage_writer::(); + get_test_rpc_server_and_storage_writer::(); let block = get_test_block(1, None, None, None); storage_writer .begin_rw_txn() @@ -1079,7 +1078,7 @@ async fn get_transaction_by_hash() { }; let res = module .call::<_, TransactionWithHash>( - "starknet_V0_4_0_getTransactionByHash", + "starknet_V0_4_getTransactionByHash", [block.body.transaction_hashes[0]], ) .await @@ -1089,7 +1088,7 @@ async fn get_transaction_by_hash() { // Ask for an invalid transaction. let err = module .call::<_, TransactionWithHash>( - "starknet_V0_4_0_getTransactionByHash", + "starknet_V0_4_getTransactionByHash", [TransactionHash(StarkHash::from(1_u8))], ) .await @@ -1104,7 +1103,7 @@ async fn get_transaction_by_hash() { #[tokio::test] async fn get_transaction_by_block_id_and_index() { let (module, mut storage_writer) = - get_test_rpc_server_and_storage_writer::(); + get_test_rpc_server_and_storage_writer::(); let block = get_test_block(1, None, None, None); storage_writer .begin_rw_txn() @@ -1124,7 +1123,7 @@ async fn get_transaction_by_block_id_and_index() { // Get transaction by block hash. let res = module .call::<_, TransactionWithHash>( - "starknet_V0_4_0_getTransactionByBlockIdAndIndex", + "starknet_V0_4_getTransactionByBlockIdAndIndex", (BlockId::HashOrNumber(BlockHashOrNumber::Hash(block.header.block_hash)), 0), ) .await @@ -1134,7 +1133,7 @@ async fn get_transaction_by_block_id_and_index() { // Get transaction by block number. let res = module .call::<_, TransactionWithHash>( - "starknet_V0_4_0_getTransactionByBlockIdAndIndex", + "starknet_V0_4_getTransactionByBlockIdAndIndex", (BlockId::HashOrNumber(BlockHashOrNumber::Number(block.header.block_number)), 0), ) .await @@ -1144,7 +1143,7 @@ async fn get_transaction_by_block_id_and_index() { // Ask for an invalid block hash. let err = module .call::<_, TransactionWithHash>( - "starknet_V0_4_0_getTransactionByBlockIdAndIndex", + "starknet_V0_4_getTransactionByBlockIdAndIndex", ( BlockId::HashOrNumber(BlockHashOrNumber::Hash(BlockHash(stark_felt!( "0x642b629ad8ce233b55798c83bb629a59bf0a0092f67da28d6d66776680d5484" @@ -1163,7 +1162,7 @@ async fn get_transaction_by_block_id_and_index() { // Ask for an invalid block number. let err = module .call::<_, TransactionWithHash>( - "starknet_V0_4_0_getTransactionByBlockIdAndIndex", + "starknet_V0_4_getTransactionByBlockIdAndIndex", (BlockId::HashOrNumber(BlockHashOrNumber::Number(BlockNumber(1))), 0), ) .await @@ -1177,7 +1176,7 @@ async fn get_transaction_by_block_id_and_index() { // Ask for an invalid transaction index. let err = module .call::<_, TransactionWithHash>( - "starknet_V0_4_0_getTransactionByBlockIdAndIndex", + "starknet_V0_4_getTransactionByBlockIdAndIndex", (BlockId::HashOrNumber(BlockHashOrNumber::Hash(block.header.block_hash)), 1), ) .await @@ -1192,7 +1191,7 @@ async fn get_transaction_by_block_id_and_index() { #[tokio::test] async fn get_state_update() { let (module, mut storage_writer) = - get_test_rpc_server_and_storage_writer::(); + get_test_rpc_server_and_storage_writer::(); let parent_header = BlockHeader::default(); let header = BlockHeader { block_hash: BlockHash(stark_felt!("0x1")), @@ -1229,7 +1228,7 @@ async fn get_state_update() { // Get state update by block hash. let res = module .call::<_, StateUpdate>( - "starknet_V0_4_0_getStateUpdate", + "starknet_V0_4_getStateUpdate", [BlockId::HashOrNumber(BlockHashOrNumber::Hash(header.block_hash))], ) .await @@ -1239,7 +1238,7 @@ async fn get_state_update() { // Get state update by block number. let res = module .call::<_, StateUpdate>( - "starknet_V0_4_0_getStateUpdate", + "starknet_V0_4_getStateUpdate", [BlockId::HashOrNumber(BlockHashOrNumber::Number(header.block_number))], ) .await @@ -1249,7 +1248,7 @@ async fn get_state_update() { // Ask for an invalid block hash. let err = module .call::<_, StateUpdate>( - "starknet_V0_4_0_getStateUpdate", + "starknet_V0_4_getStateUpdate", [BlockId::HashOrNumber(BlockHashOrNumber::Hash(BlockHash(stark_felt!( "0x642b629ad8ce233b55798c83bb629a59bf0a0092f67da28d6d66776680d5484" ))))], @@ -1265,7 +1264,7 @@ async fn get_state_update() { // Ask for an invalid block number. let err = module .call::<_, StateUpdate>( - "starknet_V0_4_0_getStateUpdate", + "starknet_V0_4_getStateUpdate", [BlockId::HashOrNumber(BlockHashOrNumber::Number(BlockNumber(2)))], ) .await @@ -1280,7 +1279,7 @@ async fn get_state_update() { #[tokio::test] async fn get_events_chunk_size_2_with_address() { let (module, mut storage_writer) = - get_test_rpc_server_and_storage_writer::(); + get_test_rpc_server_and_storage_writer::(); let address = ContractAddress(patricia_key!("0x22")); let key0 = EventKey(stark_felt!("0x6")); let key1 = EventKey(stark_felt!("0x7")); @@ -1341,7 +1340,7 @@ async fn get_events_chunk_size_2_with_address() { for (i, chunk) in emitted_events.chunks(chunk_size).enumerate() { let res = module - .call::<_, EventsChunk>("starknet_V0_4_0_getEvents", [filter.clone()]) + .call::<_, EventsChunk>("starknet_V0_4_getEvents", [filter.clone()]) .await .unwrap(); assert_eq!(res.events, chunk); @@ -1364,7 +1363,7 @@ async fn get_events_chunk_size_2_with_address() { #[tokio::test] async fn get_events_chunk_size_2_without_address() { let (module, mut storage_writer) = - get_test_rpc_server_and_storage_writer::(); + get_test_rpc_server_and_storage_writer::(); let key0 = EventKey(stark_felt!("0x6")); let key1 = EventKey(stark_felt!("0x7")); let block = get_test_block( @@ -1422,7 +1421,7 @@ async fn get_events_chunk_size_2_without_address() { for (i, chunk) in emitted_events.chunks(chunk_size).enumerate() { let res = module - .call::<_, EventsChunk>("starknet_V0_4_0_getEvents", [filter.clone()]) + .call::<_, EventsChunk>("starknet_V0_4_getEvents", [filter.clone()]) .await .unwrap(); assert_eq!(res.events, chunk); @@ -1444,7 +1443,7 @@ async fn get_events_chunk_size_2_without_address() { #[tokio::test] async fn get_events_page_size_too_big() { - let (module, _) = get_test_rpc_server_and_storage_writer::(); + let (module, _) = get_test_rpc_server_and_storage_writer::(); // Create the filter. let filter = EventFilter { @@ -1456,8 +1455,7 @@ async fn get_events_page_size_too_big() { keys: vec![], }; - let err = - module.call::<_, EventsChunk>("starknet_V0_4_0_getEvents", [filter]).await.unwrap_err(); + let err = module.call::<_, EventsChunk>("starknet_V0_4_getEvents", [filter]).await.unwrap_err(); assert_matches!(err, Error::Call(err) if err == ErrorObjectOwned::owned( JsonRpcError::PageSizeTooBig as i32, JsonRpcError::PageSizeTooBig.to_string(), @@ -1467,7 +1465,7 @@ async fn get_events_page_size_too_big() { #[tokio::test] async fn get_events_too_many_keys() { - let (module, _) = get_test_rpc_server_and_storage_writer::(); + let (module, _) = get_test_rpc_server_and_storage_writer::(); let keys = (0..get_test_gateway_config().max_events_keys + 1) .map(|i| HashSet::from([EventKey(StarkFelt::from(i as u128))])) .collect(); @@ -1482,8 +1480,7 @@ async fn get_events_too_many_keys() { keys, }; - let err = - module.call::<_, EventsChunk>("starknet_V0_4_0_getEvents", [filter]).await.unwrap_err(); + let err = module.call::<_, EventsChunk>("starknet_V0_4_getEvents", [filter]).await.unwrap_err(); assert_matches!(err, Error::Call(err) if err == ErrorObjectOwned::owned( JsonRpcError::TooManyKeysInFilter as i32, JsonRpcError::TooManyKeysInFilter.to_string(), @@ -1493,7 +1490,7 @@ async fn get_events_too_many_keys() { #[tokio::test] async fn get_events_no_blocks() { - let (module, _) = get_test_rpc_server_and_storage_writer::(); + let (module, _) = get_test_rpc_server_and_storage_writer::(); // Create the filter. let filter = EventFilter { @@ -1505,14 +1502,14 @@ async fn get_events_no_blocks() { keys: vec![], }; - let res = module.call::<_, EventsChunk>("starknet_V0_4_0_getEvents", [filter]).await.unwrap(); + let res = module.call::<_, EventsChunk>("starknet_V0_4_getEvents", [filter]).await.unwrap(); assert_eq!(res, EventsChunk { events: vec![], continuation_token: None }); } #[tokio::test] async fn get_events_no_blocks_in_filter() { let (module, mut storage_writer) = - get_test_rpc_server_and_storage_writer::(); + get_test_rpc_server_and_storage_writer::(); let parent_block = starknet_api::block::Block::default(); let block = starknet_api::block::Block { header: BlockHeader { @@ -1547,14 +1544,14 @@ async fn get_events_no_blocks_in_filter() { keys: vec![], }; - let res = module.call::<_, EventsChunk>("starknet_V0_4_0_getEvents", [filter]).await.unwrap(); + let res = module.call::<_, EventsChunk>("starknet_V0_4_getEvents", [filter]).await.unwrap(); assert_eq!(res, EventsChunk { events: vec![], continuation_token: None }); } #[tokio::test] async fn get_events_invalid_ct() { let (module, mut storage_writer) = - get_test_rpc_server_and_storage_writer::(); + get_test_rpc_server_and_storage_writer::(); let block = starknet_api::block::Block::default(); storage_writer .begin_rw_txn() @@ -1576,8 +1573,7 @@ async fn get_events_invalid_ct() { keys: vec![], }; - let err = - module.call::<_, EventsChunk>("starknet_V0_4_0_getEvents", [filter]).await.unwrap_err(); + let err = module.call::<_, EventsChunk>("starknet_V0_4_getEvents", [filter]).await.unwrap_err(); assert_matches!(err, Error::Call(err) if err == ErrorObjectOwned::owned( JsonRpcError::InvalidContinuationToken as i32, JsonRpcError::InvalidContinuationToken.to_string(), @@ -1644,7 +1640,7 @@ async fn serialize_returns_valid_json() { "TXN_RECEIPT", "EVENTS_CHUNK", ], - VERSION_0_4_0, + &VERSION_0_4, ) .await; validate_state(&state_diff, server_address, &schema).await; @@ -1657,7 +1653,7 @@ async fn validate_state(state_diff: &StateDiff, server_address: SocketAddr, sche server_address, "starknet_getStateUpdate", r#"{"block_number": 1}"#, - VERSION_0_4_0, + VERSION_0_4.name, ) .await; assert!(schema.validate(&res["result"]).is_ok(), "State update is not valid."); @@ -1667,7 +1663,7 @@ async fn validate_state(state_diff: &StateDiff, server_address: SocketAddr, sche server_address, "starknet_getClassAt", format!(r#"{{"block_number": 1}}, "0x{}""#, hex::encode(address.0.key().bytes())).as_str(), - VERSION_0_4_0, + VERSION_0_4.name, ) .await; assert!(schema.validate(&res["result"]).is_ok(), "Class is not valid."); @@ -1679,7 +1675,7 @@ async fn validate_state(state_diff: &StateDiff, server_address: SocketAddr, sche server_address, "starknet_getClassAt", format!(r#"{{"block_number": 1}}, "0x{}""#, hex::encode(address.0.key().bytes())).as_str(), - VERSION_0_4_0, + VERSION_0_4.name, ) .await; assert!(schema.validate(&res["result"]).is_ok(), "Class is not valid."); @@ -1690,7 +1686,7 @@ async fn validate_block(header: &BlockHeader, server_address: SocketAddr, schema server_address, "starknet_getBlockWithTxs", r#"{"block_number": 1}"#, - VERSION_0_4_0, + VERSION_0_4.name, ) .await; assert!(schema.validate(&res["result"]).is_ok(), "Block with transactions is not valid."); @@ -1699,7 +1695,7 @@ async fn validate_block(header: &BlockHeader, server_address: SocketAddr, schema server_address, "starknet_getBlockWithTxHashes", format!(r#"{{"block_hash": "0x{}"}}"#, hex::encode(header.block_hash.0.bytes())).as_str(), - VERSION_0_4_0, + VERSION_0_4.name, ) .await; assert!(schema.validate(&res["result"]).is_ok(), "Block with transaction hashes is not valid."); @@ -1714,7 +1710,7 @@ async fn validate_transaction( server_address, "starknet_getTransactionByBlockIdAndIndex", r#"{"block_number": 1}, 0"#, - VERSION_0_4_0, + VERSION_0_4.name, ) .await; assert!(schema.validate(&res["result"]).is_ok(), "Transaction is not valid."); @@ -1723,7 +1719,7 @@ async fn validate_transaction( server_address, "starknet_getTransactionByHash", format!(r#""0x{}""#, hex::encode(tx_hash.0.bytes())).as_str(), - VERSION_0_4_0, + VERSION_0_4.name, ) .await; assert!(schema.validate(&res["result"]).is_ok(), "Transaction is not valid."); @@ -1732,14 +1728,18 @@ async fn validate_transaction( server_address, "starknet_getTransactionReceipt", format!(r#""0x{}""#, hex::encode(tx_hash.0.bytes())).as_str(), - VERSION_0_4_0, + VERSION_0_4.name, ) .await; assert!(schema.validate(&res["result"]).is_ok(), "Transaction receipt is not valid."); - let res = - send_request(server_address, "starknet_getEvents", r#"{"chunk_size": 2}"#, VERSION_0_4_0) - .await; + let res = send_request( + server_address, + "starknet_getEvents", + r#"{"chunk_size": 2}"#, + VERSION_0_4.name, + ) + .await; assert!(schema.validate(&res["result"]).is_ok(), "Events are not valid."); } @@ -1785,7 +1785,7 @@ async fn get_deprecated_class_state_mutability() { }; let (module, mut storage_writer) = - get_test_rpc_server_and_storage_writer::(); + get_test_rpc_server_and_storage_writer::(); let header = BlockHeader::default(); storage_writer @@ -1801,7 +1801,7 @@ async fn get_deprecated_class_state_mutability() { // Get class without state mutability. let res = module .call::<_, DeprecatedContractClass>( - "starknet_V0_4_0_getClass", + "starknet_V0_4_getClass", ( BlockId::HashOrNumber(BlockHashOrNumber::Hash(header.block_hash)), ClassHash(stark_felt!("0x0")), @@ -1816,7 +1816,7 @@ async fn get_deprecated_class_state_mutability() { // Get class with state mutability. let res = module .call::<_, DeprecatedContractClass>( - "starknet_V0_4_0_getClass", + "starknet_V0_4_getClass", ( BlockId::HashOrNumber(BlockHashOrNumber::Hash(header.block_hash)), ClassHash(stark_felt!("0x1")), diff --git a/crates/papyrus_gateway/src/version_config.rs b/crates/papyrus_gateway/src/version_config.rs index 8e0e44c4fd..2965a08149 100644 --- a/crates/papyrus_gateway/src/version_config.rs +++ b/crates/papyrus_gateway/src/version_config.rs @@ -1,3 +1,5 @@ +use std::fmt; + #[derive(Eq, PartialEq, Hash)] /// Labels the jsonRPC versions we have such that there can be multiple versions that are supported, /// and there can be multiple versions that are deprecated. @@ -12,8 +14,20 @@ pub enum VersionState { Deprecated, } +#[derive(PartialEq, Eq, Hash, Copy, Clone, Debug)] +pub struct VersionId { + pub name: &'static str, + pub patch: u8, +} + +impl fmt::Display for VersionId { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}_{}", self.name, self.patch) + } +} + /// latest version must be set as supported -pub const VERSION_CONFIG: &[(&str, VersionState)] = - &[(VERSION_0_3_0, VersionState::Supported), (VERSION_0_4_0, VersionState::Supported)]; -pub const VERSION_0_3_0: &str = "V0_3_0"; -pub const VERSION_0_4_0: &str = "V0_4_0"; +pub const VERSION_CONFIG: &[(VersionId, VersionState)] = + &[(VERSION_0_3, VersionState::Supported), (VERSION_0_4, VersionState::Supported)]; +pub const VERSION_0_3: VersionId = VersionId { name: "V0_3", patch: 0 }; +pub const VERSION_0_4: VersionId = VersionId { name: "V0_4", patch: 0 };