Skip to content

Commit

Permalink
Merge pull request #1751 from eqlabs/1750-align-unexpected_error-mess…
Browse files Browse the repository at this point in the history
…age-with-other-nodes

fix: align `UNEXPECTED_ERROR` message with other nodes
  • Loading branch information
Mirko-von-Leipzig committed Feb 8, 2024
2 parents eaba589 + c5d1193 commit e430e47
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 1 deletion.
2 changes: 1 addition & 1 deletion crates/gateway-types/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
24 changes: 24 additions & 0 deletions crates/rpc/src/v04/method/add_declare_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
26 changes: 26 additions & 0 deletions crates/rpc/src/v04/method/add_deploy_account_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
26 changes: 26 additions & 0 deletions crates/rpc/src/v04/method/add_invoke_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
24 changes: 24 additions & 0 deletions crates/rpc/src/v06/method/add_declare_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
26 changes: 26 additions & 0 deletions crates/rpc/src/v06/method/add_deploy_account_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
24 changes: 24 additions & 0 deletions crates/rpc/src/v06/method/add_invoke_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit e430e47

Please sign in to comment.