From 6735e1afdf2c26878053931f739dc0e4db94eb0e Mon Sep 17 00:00:00 2001 From: Carlos V Date: Fri, 2 Aug 2024 17:28:04 +0000 Subject: [PATCH] feat: expected_rav to become result --- tap_core/src/manager/tap_manager.rs | 2 +- tap_core/src/rav/request.rs | 3 ++- tap_core/tests/manager_test.rs | 41 ++++++++++++++++++----------- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/tap_core/src/manager/tap_manager.rs b/tap_core/src/manager/tap_manager.rs index 986ce883..5f48ffcb 100644 --- a/tap_core/src/manager/tap_manager.rs +++ b/tap_core/src/manager/tap_manager.rs @@ -194,7 +194,7 @@ where .collect_receipts(timestamp_buffer_ns, min_timestamp_ns, receipts_limit) .await?; - let expected_rav = Self::generate_expected_rav(&valid_receipts, previous_rav.clone())?; + let expected_rav = Self::generate_expected_rav(&valid_receipts, previous_rav.clone()); Ok(RAVRequest { valid_receipts, diff --git a/tap_core/src/rav/request.rs b/tap_core/src/rav/request.rs index 58ad9f8f..991d8626 100644 --- a/tap_core/src/rav/request.rs +++ b/tap_core/src/rav/request.rs @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 use crate::receipt::state::Reserved; +use crate::Error; use crate::{ rav::{ReceiptAggregateVoucher, SignedRAV}, receipt::{state::Failed, ReceiptWithState}, @@ -17,5 +18,5 @@ pub struct RAVRequest { /// List of failed receipt used to log invalid receipts pub invalid_receipts: Vec>, /// Expected RAV to be created - pub expected_rav: ReceiptAggregateVoucher, + pub expected_rav: Result, } diff --git a/tap_core/tests/manager_test.rs b/tap_core/tests/manager_test.rs index 27a7dde5..20f48ce9 100644 --- a/tap_core/tests/manager_test.rs +++ b/tap_core/tests/manager_test.rs @@ -196,11 +196,13 @@ async fn manager_create_rav_request_all_valid_receipts( // no failing assert_eq!(rav_request.invalid_receipts.len(), 0); + let expected_rav = rav_request.expected_rav.unwrap(); + let signed_rav = - EIP712SignedMessage::new(&domain_separator, rav_request.expected_rav.clone(), &keys.0) + EIP712SignedMessage::new(&domain_separator, expected_rav.clone(), &keys.0) .unwrap(); assert!(manager - .verify_and_store_rav(rav_request.expected_rav, signed_rav) + .verify_and_store_rav(expected_rav, signed_rav) .await .is_ok()); } @@ -288,19 +290,21 @@ async fn manager_create_multiple_rav_requests_all_valid_receipts( ); // no receipts failing assert_eq!(rav_request.invalid_receipts.len(), 0); + + let expected_rav = rav_request.expected_rav.unwrap(); // accumulated value is correct assert_eq!( - rav_request.expected_rav.valueAggregate, + expected_rav.valueAggregate, expected_accumulated_value ); // no previous rav assert!(rav_request.previous_rav.is_none()); let signed_rav = - EIP712SignedMessage::new(&domain_separator, rav_request.expected_rav.clone(), &keys.0) + EIP712SignedMessage::new(&domain_separator, expected_rav.clone(), &keys.0) .unwrap(); assert!(manager - .verify_and_store_rav(rav_request.expected_rav, signed_rav) + .verify_and_store_rav(expected_rav, signed_rav) .await .is_ok()); @@ -334,19 +338,21 @@ async fn manager_create_multiple_rav_requests_all_valid_receipts( ); // no receipts failing assert_eq!(rav_request.invalid_receipts.len(), 0); + + let expected_rav = rav_request.expected_rav.unwrap(); // accumulated value is correct assert_eq!( - rav_request.expected_rav.valueAggregate, + expected_rav.valueAggregate, expected_accumulated_value ); // Verify there is a previous rav assert!(rav_request.previous_rav.is_some()); let signed_rav = - EIP712SignedMessage::new(&domain_separator, rav_request.expected_rav.clone(), &keys.0) + EIP712SignedMessage::new(&domain_separator, expected_rav.clone(), &keys.0) .unwrap(); assert!(manager - .verify_and_store_rav(rav_request.expected_rav, signed_rav) + .verify_and_store_rav(expected_rav, signed_rav) .await .is_ok()); } @@ -408,9 +414,11 @@ async fn manager_create_multiple_rav_requests_all_valid_receipts_consecutive_tim ); // no receipts failing assert_eq!(rav_request_1.invalid_receipts.len(), 0); + + let expected_rav_1 = rav_request_1.expected_rav.unwrap(); // accumulated value is correct assert_eq!( - rav_request_1.expected_rav.valueAggregate, + expected_rav_1.valueAggregate, expected_accumulated_value ); // no previous rav @@ -418,12 +426,12 @@ async fn manager_create_multiple_rav_requests_all_valid_receipts_consecutive_tim let signed_rav_1 = EIP712SignedMessage::new( &domain_separator, - rav_request_1.expected_rav.clone(), + expected_rav_1.clone(), &keys.0, ) .unwrap(); assert!(manager - .verify_and_store_rav(rav_request_1.expected_rav, signed_rav_1) + .verify_and_store_rav(expected_rav_1, signed_rav_1) .await .is_ok()); @@ -468,9 +476,11 @@ async fn manager_create_multiple_rav_requests_all_valid_receipts_consecutive_tim ); // no receipts failing assert_eq!(rav_request_2.invalid_receipts.len(), 0); + + let expected_rav_2 = rav_request_2.expected_rav.unwrap(); // accumulated value is correct assert_eq!( - rav_request_2.expected_rav.valueAggregate, + expected_rav_2.valueAggregate, expected_accumulated_value ); // Verify there is a previous rav @@ -478,12 +488,12 @@ async fn manager_create_multiple_rav_requests_all_valid_receipts_consecutive_tim let signed_rav_2 = EIP712SignedMessage::new( &domain_separator, - rav_request_2.expected_rav.clone(), + expected_rav_2.clone(), &keys.0, ) .unwrap(); assert!(manager - .verify_and_store_rav(rav_request_2.expected_rav, signed_rav_2) + .verify_and_store_rav(expected_rav_2, signed_rav_2) .await .is_ok()); } @@ -525,10 +535,11 @@ async fn manager_create_rav_and_ignore_invalid_receipts( } let rav_request = manager.create_rav_request(0, None).await.unwrap(); + let expected_rav = rav_request.expected_rav.unwrap(); assert_eq!(rav_request.valid_receipts.len(), 1); // All receipts but one being invalid assert_eq!(rav_request.invalid_receipts.len(), 9); //Rav Value corresponds only to value of one receipt - assert_eq!(rav_request.expected_rav.valueAggregate, 20); + assert_eq!(expected_rav.valueAggregate, 20); }