From 61e51371a815b28135a758df74354e010b91f749 Mon Sep 17 00:00:00 2001 From: Gustavo Inacio Date: Mon, 4 Mar 2024 19:35:18 -0300 Subject: [PATCH] tests: add mock checks Signed-off-by: Gustavo Inacio --- .../test/receipt_checks_adapter_test.rs | 24 ++- .../test/receipt_storage_adapter_test.rs | 31 ++- tap_core/src/checks/mod.rs | 195 ++++++++++++++---- tap_core/src/tap_manager/test/manager_test.rs | 29 ++- tap_core/src/tap_receipt/mod.rs | 31 +-- .../received_receipt_unit_test.rs | 95 ++++++--- 6 files changed, 282 insertions(+), 123 deletions(-) diff --git a/tap_core/src/adapters/test/receipt_checks_adapter_test.rs b/tap_core/src/adapters/test/receipt_checks_adapter_test.rs index c59545ac..9bc205ea 100644 --- a/tap_core/src/adapters/test/receipt_checks_adapter_test.rs +++ b/tap_core/src/adapters/test/receipt_checks_adapter_test.rs @@ -17,9 +17,10 @@ mod receipt_checks_adapter_unit_test { use tokio::sync::RwLock; use crate::{ + checks::{tests::get_full_list_of_checks, ReceiptCheck}, eip_712_signed_message::EIP712SignedMessage, tap_eip712_domain, - tap_receipt::{get_full_list_of_checks, Receipt, ReceivedReceipt}, + tap_receipt::{Receipt, ReceivedReceipt}, }; #[fixture] @@ -27,9 +28,23 @@ mod receipt_checks_adapter_unit_test { tap_eip712_domain(1, Address::from([0x11u8; 20])) } + #[fixture] + fn checks(domain_separator: Eip712Domain) -> Vec { + get_full_list_of_checks( + domain_separator, + HashSet::new(), + Arc::new(RwLock::new(HashSet::new())), + Arc::new(RwLock::new(HashMap::new())), + Arc::new(RwLock::new(HashMap::new())), + ) + } + #[rstest] #[tokio::test] - async fn receipt_checks_adapter_test(domain_separator: Eip712Domain) { + async fn receipt_checks_adapter_test( + domain_separator: Eip712Domain, + checks: Vec, + ) { let sender_ids = [ Address::from_str("0xfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfb").unwrap(), Address::from_str("0xfafafafafafafafafafafafafafafafafafafafa").unwrap(), @@ -54,6 +69,7 @@ mod receipt_checks_adapter_unit_test { .then(|id| { let wallet = wallet.clone(); let domain_separator = &domain_separator; + let checks = checks.clone(); async move { ( id, @@ -65,7 +81,7 @@ mod receipt_checks_adapter_unit_test { ) .unwrap(), id, - &get_full_list_of_checks(), + &checks, ), ) } @@ -95,7 +111,7 @@ mod receipt_checks_adapter_unit_test { ) .unwrap(), 10u64, - &get_full_list_of_checks(), + &checks, ), ); diff --git a/tap_core/src/adapters/test/receipt_storage_adapter_test.rs b/tap_core/src/adapters/test/receipt_storage_adapter_test.rs index 9f8cd71f..14bc048e 100644 --- a/tap_core/src/adapters/test/receipt_storage_adapter_test.rs +++ b/tap_core/src/adapters/test/receipt_storage_adapter_test.rs @@ -5,7 +5,7 @@ mod receipt_storage_adapter_unit_test { use rand::seq::SliceRandom; use rand::thread_rng; - use std::collections::HashMap; + use std::collections::{HashMap, HashSet}; use std::str::FromStr; use std::sync::Arc; @@ -20,21 +20,31 @@ mod receipt_storage_adapter_unit_test { receipt_storage_adapter::ReceiptStore, receipt_storage_adapter_mock::ReceiptStorageAdapterMock, }; + use crate::checks::tests::get_full_list_of_checks; + use crate::checks::ReceiptCheck; use crate::tap_eip712_domain; use crate::tap_receipt::ReceivedReceipt; - use crate::{ - eip_712_signed_message::EIP712SignedMessage, tap_receipt::get_full_list_of_checks, - tap_receipt::Receipt, - }; + use crate::{eip_712_signed_message::EIP712SignedMessage, tap_receipt::Receipt}; #[fixture] fn domain_separator() -> Eip712Domain { tap_eip712_domain(1, Address::from([0x11u8; 20])) } + #[fixture] + fn checks(domain_separator: Eip712Domain) -> Vec { + get_full_list_of_checks( + domain_separator, + HashSet::new(), + Arc::new(RwLock::new(HashSet::new())), + Arc::new(RwLock::new(HashMap::new())), + Arc::new(RwLock::new(HashMap::new())), + ) + } + #[rstest] #[tokio::test] - async fn receipt_adapter_test(domain_separator: Eip712Domain) { + async fn receipt_adapter_test(domain_separator: Eip712Domain, checks: Vec) { let receipt_storage = Arc::new(RwLock::new(HashMap::new())); let mut receipt_adapter = ReceiptStorageAdapterMock::new(receipt_storage); @@ -57,7 +67,7 @@ mod receipt_storage_adapter_unit_test { ) .unwrap(), query_id, - &get_full_list_of_checks(), + &checks, ); let receipt_store_result = receipt_adapter.store_receipt(received_receipt).await; @@ -95,7 +105,7 @@ mod receipt_storage_adapter_unit_test { #[rstest] #[tokio::test] - async fn multi_receipt_adapter_test(domain_separator: Eip712Domain) { + async fn multi_receipt_adapter_test(domain_separator: Eip712Domain, checks: Vec) { let receipt_storage = Arc::new(RwLock::new(HashMap::new())); let mut receipt_adapter = ReceiptStorageAdapterMock::new(receipt_storage); @@ -118,7 +128,7 @@ mod receipt_storage_adapter_unit_test { ) .unwrap(), query_id as u64, - &get_full_list_of_checks(), + &checks, )); } let mut receipt_ids = Vec::new(); @@ -186,6 +196,7 @@ mod receipt_storage_adapter_unit_test { #[test] fn safe_truncate_receipts_test( domain_separator: Eip712Domain, + checks: Vec, #[case] input: Vec, #[case] limit: u64, #[case] expected: Vec, @@ -215,7 +226,7 @@ mod receipt_storage_adapter_unit_test { ) .unwrap(), i as u64, // Will use that to check the IDs - &get_full_list_of_checks(), + &checks, ), )); } diff --git a/tap_core/src/checks/mod.rs b/tap_core/src/checks/mod.rs index 1e277903..786dcc2b 100644 --- a/tap_core/src/checks/mod.rs +++ b/tap_core/src/checks/mod.rs @@ -1,7 +1,6 @@ use crate::tap_receipt::{Checking, ReceiptError, ReceiptResult, ReceiptWithState}; -use ethers::types::Signature; use serde::{Deserialize, Serialize}; -use std::{collections::HashSet, sync::Arc}; +use std::sync::Arc; use tokio::sync::RwLock; pub type ReceiptCheck = Arc; @@ -21,8 +20,6 @@ impl CheckingChecks { match self { Self::Pending(check) => { let result = check.check(&receipt).await; - // *self = Self::Executed(result); - // self Self::Executed(result) } Self::Executed(_) => self, @@ -57,33 +54,6 @@ pub trait Check: std::fmt::Debug + Send + Sync { } } -#[derive(Debug, Serialize, Deserialize)] -struct UniqueCheck; - -#[async_trait::async_trait] -#[typetag::serde] -impl Check for UniqueCheck { - async fn check(&self, _receipt: &ReceiptWithState) -> ReceiptResult<()> { - println!("UniqueCheck"); - Ok(()) - } - - async fn check_batch(&self, receipts: &[ReceiptWithState]) -> Vec> { - let mut signatures: HashSet = HashSet::new(); - let mut results = Vec::new(); - - for received_receipt in receipts { - let signature = received_receipt.signed_receipt.signature; - if signatures.insert(signature) { - results.push(Ok(())); - } else { - results.push(Err(ReceiptError::NonUniqueReceipt)); - } - } - results - } -} - #[derive(Debug, Serialize, Deserialize)] pub struct TimestampCheck { #[serde(skip)] @@ -118,14 +88,161 @@ impl Check for TimestampCheck { } } -#[derive(Debug, Serialize, Deserialize)] -struct AllocationId; +#[cfg(test)] +pub mod tests { + + use super::*; + use crate::tap_receipt::ReceivedReceipt; + use alloy_primitives::Address; + use alloy_sol_types::Eip712Domain; + use std::{ + collections::{HashMap, HashSet}, + fmt::Debug, + }; + + pub fn get_full_list_of_checks( + domain_separator: Eip712Domain, + valid_signers: HashSet
, + allocation_ids: Arc>>, + receipt_storage: Arc>>, + query_appraisals: Arc>>, + ) -> Vec { + vec![ + Arc::new(UniqueCheck { receipt_storage }), + Arc::new(ValueCheck { query_appraisals }), + Arc::new(AllocationIdCheck { allocation_ids }), + Arc::new(SignatureCheck { + domain_separator, + valid_signers, + }), + Arc::new(TimestampCheck::new(0)), + ] + } -#[async_trait::async_trait] -#[typetag::serde] -impl Check for AllocationId { - async fn check(&self, _receipt: &ReceiptWithState) -> ReceiptResult<()> { - println!("AllocationId"); - Ok(()) + #[derive(Serialize, Deserialize)] + struct UniqueCheck { + #[serde(skip)] + receipt_storage: Arc>>, + } + impl Debug for UniqueCheck { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "UniqueCheck") + } + } + + #[async_trait::async_trait] + #[typetag::serde] + impl Check for UniqueCheck { + async fn check(&self, receipt: &ReceiptWithState) -> ReceiptResult<()> { + let receipt_storage = self.receipt_storage.read().await; + // let receipt_id = receipt. + receipt_storage + .iter() + .all(|(_stored_receipt_id, stored_receipt)| { + stored_receipt.signed_receipt().message != receipt.signed_receipt().message + }) + .then_some(()) + .ok_or(ReceiptError::NonUniqueReceipt) + } + + async fn check_batch( + &self, + receipts: &[ReceiptWithState], + ) -> Vec> { + let mut signatures: HashSet = HashSet::new(); + let mut results = Vec::new(); + + for received_receipt in receipts { + let signature = received_receipt.signed_receipt.signature; + if signatures.insert(signature) { + results.push(Ok(())); + } else { + results.push(Err(ReceiptError::NonUniqueReceipt)); + } + } + results + } + } + + #[derive(Debug, Serialize, Deserialize)] + struct ValueCheck { + #[serde(skip)] + query_appraisals: Arc>>, + } + + #[async_trait::async_trait] + #[typetag::serde] + impl Check for ValueCheck { + async fn check(&self, receipt: &ReceiptWithState) -> ReceiptResult<()> { + let query_id = receipt.query_id; + let value = receipt.signed_receipt().message.value; + let query_appraisals = self.query_appraisals.read().await; + let appraised_value = + query_appraisals + .get(&query_id) + .ok_or(ReceiptError::CheckFailedToComplete { + source_error_message: "Could not find query_appraisals".into(), + })?; + + if value != *appraised_value { + Err(ReceiptError::InvalidValue { + received_value: value, + }) + } else { + Ok(()) + } + } + } + + #[derive(Debug, Serialize, Deserialize)] + struct AllocationIdCheck { + #[serde(skip)] + allocation_ids: Arc>>, + } + + #[async_trait::async_trait] + #[typetag::serde] + impl Check for AllocationIdCheck { + async fn check(&self, receipt: &ReceiptWithState) -> ReceiptResult<()> { + let received_allocation_id = receipt.signed_receipt().message.allocation_id; + if self + .allocation_ids + .read() + .await + .contains(&received_allocation_id) + { + Ok(()) + } else { + Err(ReceiptError::InvalidAllocationID { + received_allocation_id, + }) + } + } + } + + #[derive(Debug, Serialize, Deserialize)] + struct SignatureCheck { + domain_separator: Eip712Domain, + valid_signers: HashSet
, + } + + #[async_trait::async_trait] + #[typetag::serde] + impl Check for SignatureCheck { + async fn check(&self, receipt: &ReceiptWithState) -> ReceiptResult<()> { + let recovered_address = receipt + .signed_receipt() + .recover_signer(&self.domain_separator) + .map_err(|e| ReceiptError::InvalidSignature { + source_error_message: e.to_string(), + })?; + if !self.valid_signers.contains(&recovered_address) { + Err(ReceiptError::InvalidSignature { + source_error_message: "Invalid signer".to_string(), + }) + } else { + Ok(()) + } + } } } diff --git a/tap_core/src/tap_manager/test/manager_test.rs b/tap_core/src/tap_manager/test/manager_test.rs index c806257a..ac2f83c6 100644 --- a/tap_core/src/tap_manager/test/manager_test.rs +++ b/tap_core/src/tap_manager/test/manager_test.rs @@ -22,10 +22,10 @@ mod manager_unit_test { executor_mock::{EscrowStorage, ExecutorMock, QueryAppraisals}, receipt_storage_adapter::ReceiptRead, }, - checks::ReceiptCheck, + checks::{tests::get_full_list_of_checks, ReceiptCheck}, eip_712_signed_message::EIP712SignedMessage, get_current_timestamp_u64_ns, tap_eip712_domain, - tap_receipt::{get_full_list_of_checks, Receipt}, + tap_receipt::Receipt, }; #[fixture] @@ -61,6 +61,11 @@ mod manager_unit_test { ] } + #[fixture] + fn full_list_of_checks() -> Vec { + vec![] + } + #[fixture] fn domain_separator() -> Eip712Domain { tap_eip712_domain(1, Address::from([0x11u8; 20])) @@ -99,7 +104,7 @@ mod manager_unit_test { } #[rstest] - #[case::full_checks(get_full_list_of_checks())] + // #[case::full_checks(get_full_list_of_checks())] // #[case::partial_checks(todo!())] #[case::no_checks(Vec::::new())] #[tokio::test] @@ -109,6 +114,7 @@ mod manager_unit_test { allocation_ids: Vec
, domain_separator: Eip712Domain, #[case] initial_checks: Vec, + full_list_of_checks: Vec, ) { let (executor, escrow_storage, query_appraisal_storage) = executor_mock; // give receipt 5 second variance for min start time @@ -117,7 +123,7 @@ mod manager_unit_test { let manager = Manager::new( domain_separator.clone(), executor, - get_full_list_of_checks(), + full_list_of_checks, starting_min_timestamp, ); @@ -142,7 +148,7 @@ mod manager_unit_test { } #[rstest] - #[case::full_checks(get_full_list_of_checks())] + // #[case::full_checks(get_full_list_of_checks())] // #[case::partial_checks(vec![ReceiptCheck::CheckSignature])] #[case::no_checks(Vec::::new())] #[tokio::test] @@ -152,6 +158,7 @@ mod manager_unit_test { allocation_ids: Vec
, domain_separator: Eip712Domain, #[case] initial_checks: Vec, + full_list_of_checks: Vec, ) { let (executor, escrow_storage, query_appraisal_storage) = executor_mock; // give receipt 5 second variance for min start time @@ -160,7 +167,7 @@ mod manager_unit_test { let manager = Manager::new( domain_separator.clone(), executor, - get_full_list_of_checks(), + full_list_of_checks, starting_min_timestamp, ); escrow_storage.write().await.insert(keys.1, 999999); @@ -210,7 +217,7 @@ mod manager_unit_test { } #[rstest] - #[case::full_checks(get_full_list_of_checks())] + // #[case::full_checks(get_full_list_of_checks())] // #[case::partial_checks(vec![ReceiptCheck::CheckSignature])] #[case::no_checks(Vec::::new())] #[tokio::test] @@ -220,6 +227,7 @@ mod manager_unit_test { allocation_ids: Vec
, domain_separator: Eip712Domain, #[case] initial_checks: Vec, + full_list_of_checks: Vec, ) { let (executor, escrow_storage, query_appraisal_storage) = executor_mock; // give receipt 5 second variance for min start time @@ -228,7 +236,7 @@ mod manager_unit_test { let manager = Manager::new( domain_separator.clone(), executor, - get_full_list_of_checks(), + full_list_of_checks, starting_min_timestamp, ); @@ -345,9 +353,10 @@ mod manager_unit_test { keys: (LocalWallet, Address), allocation_ids: Vec
, domain_separator: Eip712Domain, - #[values(get_full_list_of_checks(), /* vec![ReceiptCheck::CheckSignature], */Vec::::new())] + #[values(/*get_full_list_of_checks(), vec![ReceiptCheck::CheckSignature], */Vec::::new())] initial_checks: Vec, #[values(true, false)] remove_old_receipts: bool, + full_list_of_checks: Vec, ) { let (executor, escrow_storage, query_appraisal_storage) = executor_mock; // give receipt 5 second variance for min start time @@ -356,7 +365,7 @@ mod manager_unit_test { let manager = Manager::new( domain_separator.clone(), executor, - get_full_list_of_checks(), + full_list_of_checks, starting_min_timestamp, ); diff --git a/tap_core/src/tap_receipt/mod.rs b/tap_core/src/tap_receipt/mod.rs index 31910031..4261a21b 100644 --- a/tap_core/src/tap_receipt/mod.rs +++ b/tap_core/src/tap_receipt/mod.rs @@ -17,7 +17,7 @@ pub use received_receipt::{ use serde::{Deserialize, Serialize}; use thiserror::Error; -use crate::checks::{CheckingChecks, ReceiptCheck}; +use crate::checks::CheckingChecks; #[derive(Error, Debug, Clone, Serialize, Deserialize)] pub enum ReceiptError { @@ -42,32 +42,3 @@ pub enum ReceiptError { pub type ReceiptResult = Result; pub type ReceiptCheckResults = HashMap<&'static str, CheckingChecks>; -// #[derive(Hash, Eq, PartialEq, Debug, Clone, EnumString, Display, Serialize, Deserialize)] -// pub enum ReceiptCheck { -// CheckUnique, -// CheckAllocationId, -// CheckTimestamp, -// CheckValue, -// CheckSignature, -// } - -pub fn get_full_list_of_receipt_check_results() -> ReceiptCheckResults { - let all_checks_list = ReceiptCheckResults::new(); - // all_checks_list.insert(ReceiptCheck::CheckUnique, None); - // all_checks_list.insert(ReceiptCheck::CheckAllocationId, None); - // all_checks_list.insert(ReceiptCheck::CheckTimestamp, None); - // all_checks_list.insert(ReceiptCheck::CheckValue, None); - // all_checks_list.insert(ReceiptCheck::CheckSignature, None); - - all_checks_list -} - -pub fn get_full_list_of_checks() -> Vec { - vec![ - // ReceiptCheck::CheckUnique, - // ReceiptCheck::CheckAllocationId, - // ReceiptCheck::CheckTimestamp, - // ReceiptCheck::CheckValue, - // ReceiptCheck::CheckSignature, - ] -} diff --git a/tap_core/src/tap_receipt/received_receipt/received_receipt_unit_test.rs b/tap_core/src/tap_receipt/received_receipt/received_receipt_unit_test.rs index 1ee37320..b4601702 100644 --- a/tap_core/src/tap_receipt/received_receipt/received_receipt_unit_test.rs +++ b/tap_core/src/tap_receipt/received_receipt/received_receipt_unit_test.rs @@ -17,16 +17,19 @@ use crate::{ executor_mock::{EscrowStorage, QueryAppraisals}, receipt_storage_adapter_mock::ReceiptStorageAdapterMock, }, + checks::{tests::get_full_list_of_checks, ReceiptCheck}, eip_712_signed_message::EIP712SignedMessage, get_current_timestamp_u64_ns, tap_eip712_domain, - tap_receipt::{ - get_full_list_of_checks, Receipt, ReceiptAuditor, ReceiptCheckResults, ReceivedReceipt, - }, + tap_receipt::{Receipt, ReceiptAuditor, ReceiptCheckResults, ReceivedReceipt}, }; use super::{Checking, ReceiptWithState}; impl ReceiptWithState { + fn check_is_complete(&self, check: &str) -> bool { + self.state.checks.get(check).unwrap().is_complete() + } + fn checking_is_complete(&self) -> bool { self.state .checks @@ -82,13 +85,14 @@ fn sender_ids() -> Vec
{ } #[fixture] -fn receipt_adapters() -> (ReceiptStorageAdapterMock, Arc>>) { +fn receipt_adapters() -> ( + ReceiptStorageAdapterMock, + Arc>>, +) { let receipt_storage = Arc::new(RwLock::new(HashMap::new())); let receipt_storage_adapter = ReceiptStorageAdapterMock::new(Arc::clone(&receipt_storage)); - let query_appraisal_storage = Arc::new(RwLock::new(HashMap::new())); - - (receipt_storage_adapter, query_appraisal_storage) + (receipt_storage_adapter, receipt_storage) } #[fixture] @@ -125,12 +129,35 @@ fn domain_separator() -> Eip712Domain { tap_eip712_domain(1, Address::from([0x11u8; 20])) } +#[fixture] +fn checks( + domain_separator: Eip712Domain, + auditor_executor: (AuditorExecutorMock, EscrowStorage, QueryAppraisals), + receipt_adapters: ( + ReceiptStorageAdapterMock, + Arc>>, + ), + allocation_ids: Vec
, + sender_ids: Vec
, +) -> Vec { + let (_, receipt_storage) = receipt_adapters; + let (_, _escrow_storage, query_appraisal_storage) = auditor_executor; + get_full_list_of_checks( + domain_separator, + sender_ids.iter().cloned().collect(), + Arc::new(RwLock::new(allocation_ids.iter().cloned().collect())), + receipt_storage, + query_appraisal_storage, + ) +} + #[rstest] #[tokio::test] async fn initialization_valid_receipt( keys: (LocalWallet, Address), allocation_ids: Vec
, domain_separator: Eip712Domain, + checks: Vec, ) { let signed_receipt = EIP712SignedMessage::new( &domain_separator, @@ -139,7 +166,6 @@ async fn initialization_valid_receipt( ) .unwrap(); let query_id = 1; - let checks = get_full_list_of_checks(); let received_receipt = ReceivedReceipt::new(signed_receipt, query_id, &checks); @@ -159,6 +185,7 @@ async fn partial_then_full_check_valid_receipt( domain_separator: Eip712Domain, allocation_ids: Vec
, auditor_executor: (AuditorExecutorMock, EscrowStorage, QueryAppraisals), + checks: Vec, ) { let (executor, escrow_storage, query_appraisal_storage) = auditor_executor; // give receipt 5 second variance for min start time @@ -188,25 +215,25 @@ async fn partial_then_full_check_valid_receipt( .await .insert(query_id, query_value); - let checks = get_full_list_of_checks(); let received_receipt = ReceivedReceipt::new(signed_receipt, query_id, &checks); let _receipt_id = 0u64; - let received_receipt = match received_receipt { + let mut received_receipt = match received_receipt { ReceivedReceipt::Checking(checking) => checking, _ => panic!("ReceivedReceipt should be in Checking state"), }; // perform single arbitrary check - // let arbitrary_check_to_perform = ReceiptCheck::CheckUnique; - // received_receipt - // .perform_check(&arbitrary_check_to_perform, receipt_id, &receipt_auditor) - // .await; - // assert!(received_receipt.check_is_complete(&arbitrary_check_to_perform)); - // - // received_receipt - // .perform_checks(&checks, receipt_id, &receipt_auditor) - // .await; + let arbitrary_check_to_perform = checks[0].typetag_name(); + + received_receipt + .perform_check(arbitrary_check_to_perform) + .await; + assert!(received_receipt.check_is_complete(&arbitrary_check_to_perform)); + + received_receipt + .perform_checks(&checks.iter().map(|c| c.typetag_name()).collect::>()) + .await; assert!(received_receipt.checking_is_complete()); } @@ -217,6 +244,7 @@ async fn partial_then_finalize_valid_receipt( allocation_ids: Vec
, domain_separator: Eip712Domain, auditor_executor: (AuditorExecutorMock, EscrowStorage, QueryAppraisals), + checks: Vec, ) { let (executor, escrow_storage, query_appraisal_storage) = auditor_executor; // give receipt 5 second variance for min start time @@ -246,24 +274,31 @@ async fn partial_then_finalize_valid_receipt( .await .insert(query_id, query_value); - let checks = get_full_list_of_checks(); let received_receipt = ReceivedReceipt::new(signed_receipt, query_id, &checks); let _receipt_id = 0u64; - let received_receipt = match received_receipt { + let mut received_receipt = match received_receipt { ReceivedReceipt::Checking(checking) => checking, _ => panic!("ReceivedReceipt should be in Checking state"), }; // perform single arbitrary check - // let arbitrary_check_to_perform = ReceiptCheck::CheckUnique; - - // received_receipt - // .perform_check(/** Check Unique */) - // .await; - // assert!(received_receipt.check_is_complete(&arbitrary_check_to_perform)); - - assert!(received_receipt.finalize_receipt_checks().await.is_ok()); + let arbitrary_check_to_perform = checks[0].typetag_name(); + + received_receipt + .perform_check(arbitrary_check_to_perform) + .await; + assert!(received_receipt.check_is_complete(arbitrary_check_to_perform)); + + let awaiting_escrow_receipt = received_receipt.finalize_receipt_checks().await; + println!("{:?}", awaiting_escrow_receipt); + assert!(awaiting_escrow_receipt.is_ok()); + + let awaiting_escrow_receipt = awaiting_escrow_receipt.unwrap(); + let receipt = awaiting_escrow_receipt + .check_and_reserve_escrow(&_receipt_auditor) + .await; + assert!(receipt.is_ok()); } #[rstest] @@ -273,6 +308,7 @@ async fn standard_lifetime_valid_receipt( allocation_ids: Vec
, domain_separator: Eip712Domain, auditor_executor: (AuditorExecutorMock, EscrowStorage, QueryAppraisals), + checks: Vec, ) { let (executor, escrow_storage, query_appraisal_storage) = auditor_executor; // give receipt 5 second variance for min start time @@ -302,7 +338,6 @@ async fn standard_lifetime_valid_receipt( .await .insert(query_id, query_value); - let checks = get_full_list_of_checks(); let received_receipt = ReceivedReceipt::new(signed_receipt, query_id, &checks); let _receipt_id = 0u64;