openzeppelin_relayer/models/rpc/error/
common_codes.rs1pub struct RpcErrorCodes;
7
8impl RpcErrorCodes {
9 pub const PARSE: i32 = -32700;
11
12 pub const INVALID_REQUEST: i32 = -32600;
14
15 pub const METHOD_NOT_FOUND: i32 = -32601;
17
18 pub const INVALID_PARAMS: i32 = -32602;
20
21 pub const INTERNAL_ERROR: i32 = -32603;
23}
24
25#[cfg(test)]
26mod tests {
27 use super::*;
28
29 #[test]
30 #[allow(clippy::manual_range_contains)]
31 fn test_rpc_error_codes_are_outside_of_reserved_range() {
32 let codes = vec![
33 RpcErrorCodes::PARSE,
34 RpcErrorCodes::INVALID_REQUEST,
35 RpcErrorCodes::METHOD_NOT_FOUND,
36 RpcErrorCodes::INVALID_PARAMS,
37 RpcErrorCodes::INTERNAL_ERROR,
38 ];
39
40 for code in codes {
41 assert!(
42 !(code >= -32099 && code <= -32000),
43 "Code {} is part of the reserved range for implementation-defined server errors",
44 code
45 );
46 }
47 }
48
49 #[test]
50 fn test_rpc_error_codes_are_unique() {
51 let codes = vec![
52 RpcErrorCodes::PARSE,
53 RpcErrorCodes::INVALID_REQUEST,
54 RpcErrorCodes::METHOD_NOT_FOUND,
55 RpcErrorCodes::INVALID_PARAMS,
56 RpcErrorCodes::INTERNAL_ERROR,
57 ];
58
59 let mut unique_codes = codes.clone();
60 unique_codes.sort();
61 unique_codes.dedup();
62
63 assert_eq!(
64 codes.len(),
65 unique_codes.len(),
66 "All error codes should be unique"
67 );
68 }
69}