diff --git a/crates/starknet-devnet-server/src/api/json_rpc/models.rs b/crates/starknet-devnet-server/src/api/json_rpc/models.rs index 41a8ce526..8ed72934b 100644 --- a/crates/starknet-devnet-server/src/api/json_rpc/models.rs +++ b/crates/starknet-devnet-server/src/api/json_rpc/models.rs @@ -180,10 +180,12 @@ pub struct L1TransactionHashInput { pub transaction_hash: Hash256, } +pub type SubscriptionId = u64; + #[derive(Deserialize, Clone, Debug)] #[serde(deny_unknown_fields)] pub struct SubscriptionIdInput { - pub subscription_id: i64, + pub subscription_id: SubscriptionId, } #[derive(Deserialize, Clone, Debug)] diff --git a/crates/starknet-devnet-server/src/subscribe.rs b/crates/starknet-devnet-server/src/subscribe.rs index b136ac638..59ec6163f 100644 --- a/crates/starknet-devnet-server/src/subscribe.rs +++ b/crates/starknet-devnet-server/src/subscribe.rs @@ -15,12 +15,11 @@ use starknet_types::rpc::transactions::{TransactionStatus, TransactionWithHash}; use tokio::sync::Mutex; use crate::api::json_rpc::error::ApiError; +use crate::api::json_rpc::models::SubscriptionId; use crate::rpc_core::request::Id; pub type SocketId = u64; -type SubscriptionId = i64; - #[derive(Debug)] pub struct AddressFilter { address_container: Vec, diff --git a/crates/starknet-devnet/tests/common/utils.rs b/crates/starknet-devnet/tests/common/utils.rs index b2adae5e9..8ed41736a 100644 --- a/crates/starknet-devnet/tests/common/utils.rs +++ b/crates/starknet-devnet/tests/common/utils.rs @@ -434,13 +434,15 @@ pub async fn send_binary_rpc_via_ws( Ok(resp_body) } +pub type SubscriptionId = u64; + pub async fn subscribe( ws: &mut WebSocketStream>, subscription_method: &str, params: serde_json::Value, -) -> Result { +) -> Result { let subscription_confirmation = send_text_rpc_via_ws(ws, subscription_method, params).await?; - subscription_confirmation["result"].as_i64().ok_or(anyhow::Error::msg(format!( + subscription_confirmation["result"].as_u64().ok_or(anyhow::Error::msg(format!( "No ID in subscription response: {subscription_confirmation}" ))) } @@ -459,7 +461,7 @@ pub async fn receive_rpc_via_ws( pub async fn receive_notification( ws: &mut WebSocketStream>, method: &str, - expected_subscription_id: i64, + expected_subscription_id: SubscriptionId, ) -> Result { let mut notification = receive_rpc_via_ws(ws).await?; assert_eq!(notification["jsonrpc"], "2.0"); @@ -479,13 +481,13 @@ pub async fn assert_no_notifications(ws: &mut WebSocketStream>, block_specifier: serde_json::Value, -) -> Result { +) -> Result { subscribe(ws, "starknet_subscribeNewHeads", block_specifier).await } pub async fn unsubscribe( ws: &mut WebSocketStream>, - subscription_id: i64, + subscription_id: SubscriptionId, ) -> Result { send_text_rpc_via_ws(ws, "starknet_unsubscribe", json!({ "subscription_id": subscription_id })) .await diff --git a/crates/starknet-devnet/tests/test_subscription_to_blocks.rs b/crates/starknet-devnet/tests/test_subscription_to_blocks.rs index c7dfa7a6a..d96a26fd8 100644 --- a/crates/starknet-devnet/tests/test_subscription_to_blocks.rs +++ b/crates/starknet-devnet/tests/test_subscription_to_blocks.rs @@ -15,11 +15,12 @@ mod block_subscription_support { use crate::common::background_devnet::BackgroundDevnet; use crate::common::utils::{ assert_no_notifications, receive_notification, subscribe_new_heads, unsubscribe, + SubscriptionId, }; async fn receive_block( ws: &mut WebSocketStream>, - subscription_id: i64, + subscription_id: SubscriptionId, ) -> Result { receive_notification(ws, "starknet_subscriptionNewHeads", subscription_id).await } diff --git a/crates/starknet-devnet/tests/test_subscription_to_events.rs b/crates/starknet-devnet/tests/test_subscription_to_events.rs index 819b80855..7ee720dd2 100644 --- a/crates/starknet-devnet/tests/test_subscription_to_events.rs +++ b/crates/starknet-devnet/tests/test_subscription_to_events.rs @@ -20,19 +20,19 @@ mod event_subscription_support { use crate::common::utils::{ assert_no_notifications, declare_v3_deploy_v3, get_events_contract_in_sierra_and_compiled_class_hash, receive_notification, - receive_rpc_via_ws, subscribe, unsubscribe, + receive_rpc_via_ws, subscribe, unsubscribe, SubscriptionId, }; async fn subscribe_events( ws: &mut WebSocketStream>, params: serde_json::Value, - ) -> Result { + ) -> Result { subscribe(ws, "starknet_subscribeEvents", params).await } async fn receive_event( ws: &mut WebSocketStream>, - subscription_id: i64, + subscription_id: SubscriptionId, ) -> Result { receive_notification(ws, "starknet_subscriptionEvents", subscription_id).await } diff --git a/crates/starknet-devnet/tests/test_subscription_to_pending_txs.rs b/crates/starknet-devnet/tests/test_subscription_to_pending_txs.rs index 1fc55b1d6..d5702a1e5 100644 --- a/crates/starknet-devnet/tests/test_subscription_to_pending_txs.rs +++ b/crates/starknet-devnet/tests/test_subscription_to_pending_txs.rs @@ -17,13 +17,13 @@ mod pending_transactions_subscription_support { use crate::common::utils::{ assert_no_notifications, declare_v3_deploy_v3, get_simple_contract_in_sierra_and_compiled_class_hash, receive_rpc_via_ws, subscribe, - unsubscribe, + unsubscribe, SubscriptionId, }; async fn subscribe_pending_txs( ws: &mut WebSocketStream>, params: serde_json::Value, - ) -> Result { + ) -> Result { subscribe(ws, "starknet_subscribePendingTransactions", params).await } diff --git a/crates/starknet-devnet/tests/test_subscription_to_reorg.rs b/crates/starknet-devnet/tests/test_subscription_to_reorg.rs index 0735fac6d..d065c9551 100644 --- a/crates/starknet-devnet/tests/test_subscription_to_reorg.rs +++ b/crates/starknet-devnet/tests/test_subscription_to_reorg.rs @@ -99,7 +99,7 @@ mod reorg_subscription_support { // was received per subscription_id, we extract the IDs from notifications, store them // in a set, and later assert equality with the set of expected subscription IDs. let notification_id = - notification["params"]["subscription_id"].take().as_i64().unwrap(); + notification["params"]["subscription_id"].take().as_u64().unwrap(); notification_ids.insert(notification_id); assert_eq!( diff --git a/crates/starknet-devnet/tests/test_subscription_to_tx_status.rs b/crates/starknet-devnet/tests/test_subscription_to_tx_status.rs index b247419c6..d4eef8c51 100644 --- a/crates/starknet-devnet/tests/test_subscription_to_tx_status.rs +++ b/crates/starknet-devnet/tests/test_subscription_to_tx_status.rs @@ -10,13 +10,14 @@ mod tx_status_subscription_support { use crate::common::background_devnet::BackgroundDevnet; use crate::common::utils::{ assert_no_notifications, receive_rpc_via_ws, subscribe, subscribe_new_heads, unsubscribe, + SubscriptionId, }; async fn subscribe_tx_status( ws: &mut WebSocketStream>, tx_hash: &Felt, block_id: Option, - ) -> Result { + ) -> Result { let mut params = json!({ "transaction_hash": tx_hash }); if let Some(block_id) = block_id { @@ -38,7 +39,7 @@ mod tx_status_subscription_support { fn assert_successful_mint_notification( notification: serde_json::Value, tx_hash: Felt, - subscription_id: i64, + subscription_id: SubscriptionId, ) { assert_eq!( notification,