From e5cbeed5bc2f063c1e542b16c829b8807cb171a2 Mon Sep 17 00:00:00 2001 From: Mirko von Leipzig Date: Thu, 8 Feb 2024 09:43:56 +0200 Subject: [PATCH] chore(rpc): test unexpected error fmt --- .../src/v04/method/add_declare_transaction.rs | 22 ++++++++++++++++ .../method/add_deploy_account_transaction.rs | 26 +++++++++++++++++++ .../src/v04/method/add_invoke_transaction.rs | 26 +++++++++++++++++++ .../src/v06/method/add_declare_transaction.rs | 22 ++++++++++++++++ .../method/add_deploy_account_transaction.rs | 26 +++++++++++++++++++ .../src/v06/method/add_invoke_transaction.rs | 22 ++++++++++++++++ 6 files changed, 144 insertions(+) diff --git a/crates/rpc/src/v04/method/add_declare_transaction.rs b/crates/rpc/src/v04/method/add_declare_transaction.rs index 4d75aa5492..2b9730f7d1 100644 --- a/crates/rpc/src/v04/method/add_declare_transaction.rs +++ b/crates/rpc/src/v04/method/add_declare_transaction.rs @@ -347,6 +347,28 @@ mod tests { }; assert_eq!(input, expected); } + + #[test] + fn unexpected_error_message() { + use starknet_gateway_types::error::{StarknetError, StarknetErrorCode, KnownStarknetErrorCode}; + 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..010a0296f8 100644 --- a/crates/rpc/src/v06/method/add_declare_transaction.rs +++ b/crates/rpc/src/v06/method/add_declare_transaction.rs @@ -349,6 +349,28 @@ mod tests { }; assert_eq!(input, expected); } + + #[test] + fn unexpected_error_message() { + use starknet_gateway_types::error::{StarknetError, StarknetErrorCode, KnownStarknetErrorCode}; + 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..9e534b7bc3 100644 --- a/crates/rpc/src/v06/method/add_invoke_transaction.rs +++ b/crates/rpc/src/v06/method/add_invoke_transaction.rs @@ -274,6 +274,28 @@ mod tests { }; assert_eq!(input, expected); } + + #[test] + fn unexpected_error_message() { + use starknet_gateway_types::error::{StarknetError, StarknetErrorCode, KnownStarknetErrorCode}; + 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]