diff --git a/crates/gateway-types/src/error.rs b/crates/gateway-types/src/error.rs index 33e710c352..8489a2e4ff 100644 --- a/crates/gateway-types/src/error.rs +++ b/crates/gateway-types/src/error.rs @@ -29,7 +29,7 @@ impl std::error::Error for StarknetError {} impl std::fmt::Display for StarknetError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{self:?}") + write!(f, "{}", self.message) } } diff --git a/crates/rpc/src/v04/method/add_declare_transaction.rs b/crates/rpc/src/v04/method/add_declare_transaction.rs index 4d75aa5492..b262a86a73 100644 --- a/crates/rpc/src/v04/method/add_declare_transaction.rs +++ b/crates/rpc/src/v04/method/add_declare_transaction.rs @@ -347,6 +347,30 @@ mod tests { }; assert_eq!(input, expected); } + + #[test] + fn unexpected_error_message() { + use starknet_gateway_types::error::{ + KnownStarknetErrorCode, StarknetError, StarknetErrorCode, + }; + let starknet_error = SequencerError::StarknetError(StarknetError { + code: StarknetErrorCode::Known(KnownStarknetErrorCode::TransactionLimitExceeded), + message: "StarkNet Alpha throughput limit reached, please wait a few minutes and try again.".to_string() + }); + + let error = AddDeclareTransactionError::from(starknet_error); + let error = crate::error::ApplicationError::from(error); + let error = crate::jsonrpc::RpcError::from(error); + let error = serde_json::to_value(error).unwrap(); + + let expected = json!({ + "code": 63, + "message": "An unexpected error occurred", + "data": "StarkNet Alpha throughput limit reached, please wait a few minutes and try again." + }); + + assert_eq!(error, expected); + } } mod v2 { diff --git a/crates/rpc/src/v04/method/add_deploy_account_transaction.rs b/crates/rpc/src/v04/method/add_deploy_account_transaction.rs index 2c2dc0df42..7e3fbe9073 100644 --- a/crates/rpc/src/v04/method/add_deploy_account_transaction.rs +++ b/crates/rpc/src/v04/method/add_deploy_account_transaction.rs @@ -155,6 +155,32 @@ mod tests { assert_eq!(input, get_input()); } + #[test] + fn unexpected_error_message() { + use starknet_gateway_types::error::{ + KnownStarknetErrorCode, StarknetError, StarknetErrorCode, + }; + let starknet_error = SequencerError::StarknetError(StarknetError { + code: StarknetErrorCode::Known(KnownStarknetErrorCode::TransactionLimitExceeded), + message: + "StarkNet Alpha throughput limit reached, please wait a few minutes and try again." + .to_string(), + }); + + let error = AddDeployAccountTransactionError::from(starknet_error); + let error = crate::error::ApplicationError::from(error); + let error = crate::jsonrpc::RpcError::from(error); + let error = serde_json::to_value(error).unwrap(); + + let expected = serde_json::json!({ + "code": 63, + "message": "An unexpected error occurred", + "data": "StarkNet Alpha throughput limit reached, please wait a few minutes and try again." + }); + + assert_eq!(error, expected); + } + fn get_input() -> AddDeployAccountTransactionInput { AddDeployAccountTransactionInput { deploy_account_transaction: Transaction::DeployAccount( diff --git a/crates/rpc/src/v04/method/add_invoke_transaction.rs b/crates/rpc/src/v04/method/add_invoke_transaction.rs index c590639124..aed17f782a 100644 --- a/crates/rpc/src/v04/method/add_invoke_transaction.rs +++ b/crates/rpc/src/v04/method/add_invoke_transaction.rs @@ -213,6 +213,32 @@ mod tests { }; assert_eq!(input, expected); } + + #[test] + fn unexpected_error_message() { + use starknet_gateway_types::error::{ + KnownStarknetErrorCode, StarknetError, StarknetErrorCode, + }; + let starknet_error = SequencerError::StarknetError(StarknetError { + code: StarknetErrorCode::Known(KnownStarknetErrorCode::TransactionLimitExceeded), + message: + "StarkNet Alpha throughput limit reached, please wait a few minutes and try again." + .to_string(), + }); + + let error = AddInvokeTransactionError::from(starknet_error); + let error = crate::error::ApplicationError::from(error); + let error = crate::jsonrpc::RpcError::from(error); + let error = serde_json::to_value(error).unwrap(); + + let expected = serde_json::json!({ + "code": 63, + "message": "An unexpected error occurred", + "data": "StarkNet Alpha throughput limit reached, please wait a few minutes and try again." + }); + + assert_eq!(error, expected); + } } #[tokio::test] diff --git a/crates/rpc/src/v06/method/add_declare_transaction.rs b/crates/rpc/src/v06/method/add_declare_transaction.rs index 2a4ef0c831..98bb48e09e 100644 --- a/crates/rpc/src/v06/method/add_declare_transaction.rs +++ b/crates/rpc/src/v06/method/add_declare_transaction.rs @@ -349,6 +349,30 @@ mod tests { }; assert_eq!(input, expected); } + + #[test] + fn unexpected_error_message() { + use starknet_gateway_types::error::{ + KnownStarknetErrorCode, StarknetError, StarknetErrorCode, + }; + let starknet_error = SequencerError::StarknetError(StarknetError { + code: StarknetErrorCode::Known(KnownStarknetErrorCode::TransactionLimitExceeded), + message: "StarkNet Alpha throughput limit reached, please wait a few minutes and try again.".to_string() + }); + + let error = AddDeclareTransactionError::from(starknet_error); + let error = crate::error::ApplicationError::from(error); + let error = crate::jsonrpc::RpcError::from(error); + let error = serde_json::to_value(error).unwrap(); + + let expected = json!({ + "code": 63, + "message": "An unexpected error occurred", + "data": "StarkNet Alpha throughput limit reached, please wait a few minutes and try again." + }); + + assert_eq!(error, expected); + } } mod v2 { diff --git a/crates/rpc/src/v06/method/add_deploy_account_transaction.rs b/crates/rpc/src/v06/method/add_deploy_account_transaction.rs index 43e579a6e5..92f6c6d19b 100644 --- a/crates/rpc/src/v06/method/add_deploy_account_transaction.rs +++ b/crates/rpc/src/v06/method/add_deploy_account_transaction.rs @@ -224,6 +224,32 @@ mod tests { assert_eq!(input, get_input()); } + #[test] + fn unexpected_error_message() { + use starknet_gateway_types::error::{ + KnownStarknetErrorCode, StarknetError, StarknetErrorCode, + }; + let starknet_error = SequencerError::StarknetError(StarknetError { + code: StarknetErrorCode::Known(KnownStarknetErrorCode::TransactionLimitExceeded), + message: + "StarkNet Alpha throughput limit reached, please wait a few minutes and try again." + .to_string(), + }); + + let error = AddDeployAccountTransactionError::from(starknet_error); + let error = crate::error::ApplicationError::from(error); + let error = crate::jsonrpc::RpcError::from(error); + let error = serde_json::to_value(error).unwrap(); + + let expected = serde_json::json!({ + "code": 63, + "message": "An unexpected error occurred", + "data": "StarkNet Alpha throughput limit reached, please wait a few minutes and try again." + }); + + assert_eq!(error, expected); + } + fn get_input() -> AddDeployAccountTransactionInput { AddDeployAccountTransactionInput { deploy_account_transaction: Transaction::DeployAccount( diff --git a/crates/rpc/src/v06/method/add_invoke_transaction.rs b/crates/rpc/src/v06/method/add_invoke_transaction.rs index 34a7ed0b1c..3071bfda54 100644 --- a/crates/rpc/src/v06/method/add_invoke_transaction.rs +++ b/crates/rpc/src/v06/method/add_invoke_transaction.rs @@ -274,6 +274,30 @@ mod tests { }; assert_eq!(input, expected); } + + #[test] + fn unexpected_error_message() { + use starknet_gateway_types::error::{ + KnownStarknetErrorCode, StarknetError, StarknetErrorCode, + }; + let starknet_error = SequencerError::StarknetError(StarknetError { + code: StarknetErrorCode::Known(KnownStarknetErrorCode::TransactionLimitExceeded), + message: "StarkNet Alpha throughput limit reached, please wait a few minutes and try again.".to_string() + }); + + let error = AddInvokeTransactionError::from(starknet_error); + let error = crate::error::ApplicationError::from(error); + let error = crate::jsonrpc::RpcError::from(error); + let error = serde_json::to_value(error).unwrap(); + + let expected = json!({ + "code": 63, + "message": "An unexpected error occurred", + "data": "StarkNet Alpha throughput limit reached, please wait a few minutes and try again." + }); + + assert_eq!(error, expected); + } } #[tokio::test]