openzeppelin_relayer/models/rpc/error/
openzeppelin_codes.rs1pub struct OpenZeppelinErrorCodes;
8
9impl OpenZeppelinErrorCodes {
10 pub const TIMEOUT: i32 = -33000;
12
13 pub const RATE_LIMITED: i32 = -33001;
15
16 pub const BAD_GATEWAY: i32 = -33002;
18
19 pub const REQUEST_ERROR: i32 = -33003;
21
22 pub const NETWORK_CONFIGURATION: i32 = -33004;
24}
25
26#[cfg(test)]
27mod tests {
28 use super::*;
29
30 #[test]
31 #[allow(clippy::manual_range_contains)]
32 fn test_openzeppelin_error_codes_are_not_in_reserved_range() {
33 let codes = vec![
34 OpenZeppelinErrorCodes::TIMEOUT,
35 OpenZeppelinErrorCodes::RATE_LIMITED,
36 OpenZeppelinErrorCodes::BAD_GATEWAY,
37 OpenZeppelinErrorCodes::REQUEST_ERROR,
38 OpenZeppelinErrorCodes::NETWORK_CONFIGURATION,
39 ];
40
41 for code in codes {
42 assert!(
43 !(code >= -32099 && code <= -32000),
44 "Code {code} is part of the reserved range for implementation-defined server errors"
45 );
46 }
47 }
48
49 #[test]
50 fn test_openzeppelin_error_codes_are_unique() {
51 let codes = vec![
52 OpenZeppelinErrorCodes::TIMEOUT,
53 OpenZeppelinErrorCodes::RATE_LIMITED,
54 OpenZeppelinErrorCodes::BAD_GATEWAY,
55 OpenZeppelinErrorCodes::REQUEST_ERROR,
56 OpenZeppelinErrorCodes::NETWORK_CONFIGURATION,
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
70 #[test]
71 fn test_openzeppelin_error_codes_start_from_33000() {
72 let codes = vec![
73 OpenZeppelinErrorCodes::TIMEOUT,
74 OpenZeppelinErrorCodes::RATE_LIMITED,
75 OpenZeppelinErrorCodes::BAD_GATEWAY,
76 OpenZeppelinErrorCodes::REQUEST_ERROR,
77 OpenZeppelinErrorCodes::NETWORK_CONFIGURATION,
78 ];
79
80 for code in codes {
81 assert!(
82 code <= -33000,
83 "All OpenZeppelin codes should be <= -33000, found: {code}"
84 );
85 }
86 }
87}