morpho_rs_contracts/
error.rs1use thiserror::Error;
4
5#[derive(Debug, Error)]
7pub enum ContractError {
8 #[error("RPC connection failed: {0}")]
10 RpcConnection(String),
11
12 #[error("Transaction failed: {0}")]
14 TransactionFailed(String),
15
16 #[error("Invalid private key")]
18 InvalidPrivateKey,
19}
20
21pub type Result<T> = std::result::Result<T, ContractError>;
23
24#[cfg(test)]
25mod tests {
26 use super::*;
27
28 #[test]
29 fn test_error_display_rpc_connection() {
30 let error = ContractError::RpcConnection("connection refused".to_string());
31 assert_eq!(
32 error.to_string(),
33 "RPC connection failed: connection refused"
34 );
35 }
36
37 #[test]
38 fn test_error_display_transaction_failed() {
39 let error = ContractError::TransactionFailed("out of gas".to_string());
40 assert_eq!(error.to_string(), "Transaction failed: out of gas");
41 }
42
43 #[test]
44 fn test_error_display_invalid_private_key() {
45 let error = ContractError::InvalidPrivateKey;
46 assert_eq!(error.to_string(), "Invalid private key");
47 }
48}