Skip to content

Commit

Permalink
chore(rpc): test unexpected error fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Mirko-von-Leipzig committed Feb 8, 2024
1 parent dbf2276 commit e5cbeed
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 0 deletions.
22 changes: 22 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,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 {
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
22 changes: 22 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,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 {
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
22 changes: 22 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,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]
Expand Down

0 comments on commit e5cbeed

Please sign in to comment.