@@ -24,6 +24,7 @@ use tap_core::{
2424 } ,
2525 Manager ,
2626 } ,
27+ rav:: ReceiptAggregateVoucher ,
2728 receipt:: {
2829 checks:: { CheckList , StatefulTimestampCheck } ,
2930 Receipt ,
@@ -204,6 +205,39 @@ async fn manager_create_rav_request_all_valid_receipts(
204205 . is_ok( ) ) ;
205206}
206207
208+ #[ rstest]
209+ #[ tokio:: test]
210+ async fn deny_rav_due_to_wrong_value (
211+ keys : ( LocalWallet , Address ) ,
212+ domain_separator : Eip712Domain ,
213+ context : ContextFixture ,
214+ ) {
215+ let ContextFixture {
216+ context, checks, ..
217+ } = context;
218+ let manager = Manager :: new ( domain_separator. clone ( ) , context, checks) ;
219+
220+ let rav = ReceiptAggregateVoucher {
221+ allocationId : Address :: from_str ( "0xabababababababababababababababababababab" ) . unwrap ( ) ,
222+ timestampNs : 1232442 ,
223+ valueAggregate : 20u128 ,
224+ } ;
225+
226+ let rav_wrong_value = ReceiptAggregateVoucher {
227+ allocationId : Address :: from_str ( "0xabababababababababababababababababababab" ) . unwrap ( ) ,
228+ timestampNs : 1232442 ,
229+ valueAggregate : 10u128 ,
230+ } ;
231+
232+ let signed_rav_with_wrong_aggregate =
233+ EIP712SignedMessage :: new ( & domain_separator, rav_wrong_value, & keys. 0 ) . unwrap ( ) ;
234+
235+ assert ! ( manager
236+ . verify_and_store_rav( rav, signed_rav_with_wrong_aggregate)
237+ . await
238+ . is_err( ) ) ;
239+ }
240+
207241#[ rstest]
208242#[ tokio:: test]
209243async fn manager_create_multiple_rav_requests_all_valid_receipts (
@@ -453,3 +487,48 @@ async fn manager_create_multiple_rav_requests_all_valid_receipts_consecutive_tim
453487 . await
454488 . is_ok( ) ) ;
455489}
490+
491+ #[ rstest]
492+ #[ tokio:: test]
493+ async fn manager_create_rav_and_ignore_invalid_receipts (
494+ keys : ( LocalWallet , Address ) ,
495+ allocation_ids : Vec < Address > ,
496+ domain_separator : Eip712Domain ,
497+ context : ContextFixture ,
498+ ) {
499+ let ContextFixture {
500+ context,
501+ checks,
502+ escrow_storage,
503+ ..
504+ } = context;
505+
506+ let manager = Manager :: new ( domain_separator. clone ( ) , context. clone ( ) , checks) ;
507+
508+ escrow_storage. write ( ) . unwrap ( ) . insert ( keys. 1 , 999999 ) ;
509+
510+ let mut stored_signed_receipts = Vec :: new ( ) ;
511+ //Forcing all receipts but one to be invalid by making all the same
512+ for _ in 0 ..10 {
513+ let receipt = Receipt {
514+ allocation_id : allocation_ids[ 0 ] ,
515+ timestamp_ns : 1 ,
516+ nonce : 1 ,
517+ value : 20u128 ,
518+ } ;
519+ let signed_receipt = EIP712SignedMessage :: new ( & domain_separator, receipt, & keys. 0 ) . unwrap ( ) ;
520+ stored_signed_receipts. push ( signed_receipt. clone ( ) ) ;
521+ manager
522+ . verify_and_store_receipt ( signed_receipt)
523+ . await
524+ . unwrap ( ) ;
525+ }
526+
527+ let rav_request = manager. create_rav_request ( 0 , None ) . await . unwrap ( ) ;
528+
529+ assert_eq ! ( rav_request. valid_receipts. len( ) , 1 ) ;
530+ // All receipts but one being invalid
531+ assert_eq ! ( rav_request. invalid_receipts. len( ) , 9 ) ;
532+ //Rav Value corresponds only to value of one receipt
533+ assert_eq ! ( rav_request. expected_rav. valueAggregate, 20 ) ;
534+ }
0 commit comments