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 {code} is part of the reserved range for implementation-defined server errors"
44 );
45 }
46 }
47
48 #[test]
49 fn test_rpc_error_codes_are_unique() {
50 let codes = vec![
51 RpcErrorCodes::PARSE,
52 RpcErrorCodes::INVALID_REQUEST,
53 RpcErrorCodes::METHOD_NOT_FOUND,
54 RpcErrorCodes::INVALID_PARAMS,
55 RpcErrorCodes::INTERNAL_ERROR,
56 ];
57
58 let mut unique_codes = codes.clone();
59 unique_codes.sort();
60 unique_codes.dedup();
61
62 assert_eq!(
63 codes.len(),
64 unique_codes.len(),
65 "All error codes should be unique"
66 );
67 }
68}