@@ -10,7 +10,7 @@ use services::types::L1Tx;
10
10
11
11
use crate :: error:: { Error , Result } ;
12
12
13
- #[ derive( Debug , Clone , Copy ) ]
13
+ #[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
14
14
pub struct MaxTxFeesPerGas {
15
15
pub normal : u128 ,
16
16
pub priority : u128 ,
@@ -21,8 +21,8 @@ impl<'a> From<&'a L1Tx> for MaxTxFeesPerGas {
21
21
fn from ( value : & ' a L1Tx ) -> Self {
22
22
Self {
23
23
normal : value. max_fee ,
24
- priority : value. blob_fee ,
25
- blob : value. priority_fee ,
24
+ priority : value. priority_fee ,
25
+ blob : value. blob_fee ,
26
26
}
27
27
}
28
28
}
@@ -113,3 +113,95 @@ fn estimate_max_priority_fee_per_gas(fee_history: &FeeHistory) -> Result<u128> {
113
113
114
114
Ok ( std:: cmp:: max ( median, EIP1559_MIN_PRIORITY_FEE ) )
115
115
}
116
+
117
+ #[ cfg( test) ]
118
+ mod tests {
119
+ use super :: * ;
120
+
121
+ #[ test]
122
+ fn correctly_reads_fees_from_l1_tx ( ) {
123
+ // given
124
+ let normal = 100 ;
125
+ let blob = 50 ;
126
+ let priority = 25 ;
127
+ let l1tx = gen_l1_tx ( normal, blob, priority) ;
128
+
129
+ // when
130
+ let fees: MaxTxFeesPerGas = ( & l1tx) . into ( ) ;
131
+
132
+ // then
133
+ assert_eq ! (
134
+ fees,
135
+ MaxTxFeesPerGas {
136
+ normal,
137
+ priority,
138
+ blob,
139
+ }
140
+ ) ;
141
+ }
142
+
143
+ #[ test]
144
+ fn double_method_doubles_all_fees ( ) {
145
+ // given
146
+ let fees = MaxTxFeesPerGas {
147
+ normal : 100 ,
148
+ priority : 50 ,
149
+ blob : 25 ,
150
+ } ;
151
+
152
+ // when
153
+ let doubled = fees. double ( ) ;
154
+
155
+ // then
156
+ assert_eq ! (
157
+ doubled,
158
+ MaxTxFeesPerGas {
159
+ normal: 200 ,
160
+ priority: 100 ,
161
+ blob: 50 ,
162
+ }
163
+ ) ;
164
+ }
165
+
166
+ #[ test]
167
+ fn retain_max_method_returns_max_of_each_fee ( ) {
168
+ // given
169
+ let fees1 = MaxTxFeesPerGas {
170
+ normal : 100 ,
171
+ priority : 50 ,
172
+ blob : 25 ,
173
+ } ;
174
+ let fees2 = MaxTxFeesPerGas {
175
+ normal : 150 ,
176
+ priority : 40 ,
177
+ blob : 30 ,
178
+ } ;
179
+
180
+ // when
181
+ let retained = fees1. retain_max ( fees2) ;
182
+ // normal: max(100, 150) = 150
183
+ // priority: max(50, 40) = 50
184
+ // blob: max(25, 30) = 30
185
+ assert_eq ! (
186
+ retained,
187
+ MaxTxFeesPerGas {
188
+ normal: 150 ,
189
+ priority: 50 ,
190
+ blob: 30 ,
191
+ } ,
192
+ ) ;
193
+ }
194
+
195
+ fn gen_l1_tx ( max_fee : u128 , blob_fee : u128 , priority_fee : u128 ) -> L1Tx {
196
+ L1Tx {
197
+ max_fee,
198
+ blob_fee,
199
+ priority_fee,
200
+ id : None ,
201
+ hash : Default :: default ( ) ,
202
+ nonce : Default :: default ( ) ,
203
+ created_at : Default :: default ( ) ,
204
+ state : services:: types:: TransactionState :: Pending ,
205
+ }
206
+ }
207
+ }
0 commit comments