@@ -117,10 +117,7 @@ fn check_receipt_timestamps(
117117
118118#[ cfg( test) ]
119119mod tests {
120- use std:: {
121- str:: FromStr ,
122- time:: { SystemTime , UNIX_EPOCH } ,
123- } ;
120+ use std:: str:: FromStr ;
124121
125122 use ethers_core:: types:: Address ;
126123 use ethers_signers:: { coins_bip39:: English , LocalWallet , MnemonicBuilder , Signer } ;
@@ -194,71 +191,65 @@ mod tests {
194191 #[ rstest]
195192 #[ tokio:: test]
196193 /// Test that a receipt with a timestamp greater then the rav timestamp passes
197- async fn check_receipt_timestamps_ok (
198- keys : ( LocalWallet , Address ) ,
199- allocation_ids : Vec < Address > ,
200- ) {
201- let time = SystemTime :: now ( )
202- . duration_since ( UNIX_EPOCH )
203- . unwrap ( )
204- . as_millis ( ) as u64 ;
194+ async fn check_receipt_timestamps ( keys : ( LocalWallet , Address ) , allocation_ids : Vec < Address > ) {
195+ // Create receipts with consecutive timestamps
196+ let mut receipts = Vec :: new ( ) ;
197+ for i in 10 ..20 {
198+ receipts. push (
199+ EIP712SignedMessage :: new (
200+ Receipt {
201+ allocation_id : allocation_ids[ 0 ] ,
202+ timestamp_ns : i,
203+ nonce : 0 ,
204+ value : 42 ,
205+ } ,
206+ & keys. 0 ,
207+ )
208+ . await
209+ . unwrap ( ) ,
210+ ) ;
211+ }
205212
206- // Create rav
213+ // Create rav with max_timestamp below the receipts timestamps
207214 let rav = EIP712SignedMessage :: new (
208215 tap_core:: receipt_aggregate_voucher:: ReceiptAggregateVoucher {
209216 allocation_id : allocation_ids[ 0 ] ,
210- timestamp_ns : time ,
217+ timestamp_ns : 9 ,
211218 value_aggregate : 42 ,
212219 } ,
213220 & keys. 0 ,
214221 )
215222 . await
216223 . unwrap ( ) ;
224+ assert ! ( aggregator:: check_receipt_timestamps( & receipts, Some ( & rav) ) . is_ok( ) ) ;
217225
218- let mut receipts = Vec :: new ( ) ;
219- receipts. push (
220- EIP712SignedMessage :: new ( Receipt :: new ( allocation_ids[ 0 ] , 42 ) . unwrap ( ) , & keys. 0 )
221- . await
222- . unwrap ( ) ,
223- ) ;
224-
225- aggregator:: check_receipt_timestamps ( & receipts, Some ( & rav) ) . unwrap ( ) ;
226- }
227-
228- #[ rstest]
229- #[ tokio:: test]
230- /// Test that a receipt with a timestamp less then the rav timestamp fails
231- async fn check_receipt_timestamps_fail (
232- keys : ( LocalWallet , Address ) ,
233- allocation_ids : Vec < Address > ,
234- ) {
235- let mut receipts = Vec :: new ( ) ;
236- receipts. push (
237- EIP712SignedMessage :: new ( Receipt :: new ( allocation_ids[ 0 ] , 42 ) . unwrap ( ) , & keys. 0 )
238- . await
239- . unwrap ( ) ,
240- ) ;
241-
242- let time = SystemTime :: now ( )
243- . duration_since ( UNIX_EPOCH )
244- . unwrap ( )
245- . as_nanos ( ) as u64 ;
246-
247- // Create rav
226+ // Create rav with max_timestamp equal to the lowest receipt timestamp
227+ // Aggregation should fail
248228 let rav = EIP712SignedMessage :: new (
249229 tap_core:: receipt_aggregate_voucher:: ReceiptAggregateVoucher {
250230 allocation_id : allocation_ids[ 0 ] ,
251- timestamp_ns : time ,
231+ timestamp_ns : 10 ,
252232 value_aggregate : 42 ,
253233 } ,
254234 & keys. 0 ,
255235 )
256236 . await
257237 . unwrap ( ) ;
238+ assert ! ( aggregator:: check_receipt_timestamps( & receipts, Some ( & rav) ) . is_err( ) ) ;
258239
259- let res = aggregator:: check_receipt_timestamps ( & receipts, Some ( & rav) ) ;
260-
261- assert ! ( res. is_err( ) ) ;
240+ // Create rav with max_timestamp above highest receipt timestamp
241+ // Aggregation should fail
242+ let rav = EIP712SignedMessage :: new (
243+ tap_core:: receipt_aggregate_voucher:: ReceiptAggregateVoucher {
244+ allocation_id : allocation_ids[ 0 ] ,
245+ timestamp_ns : 20 ,
246+ value_aggregate : 42 ,
247+ } ,
248+ & keys. 0 ,
249+ )
250+ . await
251+ . unwrap ( ) ;
252+ assert ! ( aggregator:: check_receipt_timestamps( & receipts, Some ( & rav) ) . is_err( ) ) ;
262253 }
263254
264255 #[ rstest]
0 commit comments