tempo_precompiles/stablecoin_dex/
error.rs1#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
3pub enum OrderError {
4 #[error("invalid flip tick for bid order: flip_tick ({flip_tick}) must be >= tick ({tick})")]
8 InvalidBidFlipTick {
9 tick: i16,
11 flip_tick: i16,
13 },
14
15 #[error("invalid flip tick for ask order: flip_tick ({flip_tick}) must be <= tick ({tick})")]
19 InvalidAskFlipTick {
20 tick: i16,
22 flip_tick: i16,
24 },
25
26 #[error("cannot create flipped order from a non-flip order")]
28 NotAFlipOrder,
29
30 #[error("order must be fully filled to flip, but {remaining} amount remains")]
32 OrderNotFullyFilled {
33 remaining: u128,
35 },
36
37 #[error("cannot fill {requested} when only {available} is available")]
39 FillAmountExceedsRemaining {
40 requested: u128,
42 available: u128,
44 },
45
46 #[error("tick {tick} is out of bounds (min: {min}, max: {max})")]
48 InvalidTick {
49 tick: i16,
51 min: i16,
53 max: i16,
55 },
56}
57
58#[cfg(test)]
59mod tests {
60 use super::*;
61
62 #[test]
63 fn test_invalid_flip_tick_bid() {
64 let err = OrderError::InvalidBidFlipTick {
65 tick: 5,
66 flip_tick: 3,
67 };
68 let msg = err.to_string();
69 assert!(msg.contains("bid"));
70 assert!(msg.contains(">= tick"));
71 assert!(msg.contains("5"));
72 assert!(msg.contains("3"));
73 }
74
75 #[test]
76 fn test_invalid_flip_tick_ask() {
77 let err = OrderError::InvalidAskFlipTick {
78 tick: 5,
79 flip_tick: 7,
80 };
81 let msg = err.to_string();
82 assert!(msg.contains("ask"));
83 assert!(msg.contains("<= tick"));
84 assert!(msg.contains("5"));
85 assert!(msg.contains("7"));
86 }
87
88 #[test]
89 fn test_not_a_flip_order() {
90 let err = OrderError::NotAFlipOrder;
91 assert_eq!(
92 err.to_string(),
93 "cannot create flipped order from a non-flip order"
94 );
95 }
96
97 #[test]
98 fn test_order_not_fully_filled() {
99 let err = OrderError::OrderNotFullyFilled { remaining: 500 };
100 let msg = err.to_string();
101 assert!(msg.contains("500"));
102 assert!(msg.contains("must be fully filled"));
103 }
104
105 #[test]
106 fn test_fill_amount_exceeds_remaining() {
107 let err = OrderError::FillAmountExceedsRemaining {
108 requested: 1000,
109 available: 600,
110 };
111 let msg = err.to_string();
112 assert!(msg.contains("1000"));
113 assert!(msg.contains("600"));
114 }
115
116 #[test]
117 fn test_invalid_tick() {
118 let err = OrderError::InvalidTick {
119 tick: 3000,
120 min: -2000,
121 max: 2000,
122 };
123 let msg = err.to_string();
124 assert_eq!(msg, "tick 3000 is out of bounds (min: -2000, max: 2000)");
125 }
126}