Skip to content

Commit

Permalink
test: fix manager and received receipt tests
Browse files Browse the repository at this point in the history
Signed-off-by: Gustavo Inacio <gustavo@semiotic.ai>
  • Loading branch information
gusinacio committed Mar 5, 2024
1 parent bc86d16 commit 568144f
Show file tree
Hide file tree
Showing 4 changed files with 550 additions and 487 deletions.
12 changes: 7 additions & 5 deletions tap_core/src/adapters/mock/executor_mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ use tokio::sync::RwLock;

pub type EscrowStorage = Arc<RwLock<HashMap<Address, u128>>>;
pub type QueryAppraisals = Arc<RwLock<HashMap<u64, u128>>>;
pub type ReceiptStorage = Arc<RwLock<HashMap<u64, ReceivedReceipt>>>;
pub type RAVStorage = Arc<RwLock<Option<SignedRAV>>>;

use thiserror::Error;

Expand All @@ -30,18 +32,18 @@ pub enum AdapterErrorMock {
#[derive(Clone)]
pub struct ExecutorMock {
/// local RAV store with rwlocks to allow sharing with other compenents as needed
rav_storage: Arc<RwLock<Option<SignedRAV>>>,
receipt_storage: Arc<RwLock<HashMap<u64, ReceivedReceipt>>>,
rav_storage: RAVStorage,
receipt_storage: ReceiptStorage,
unique_id: Arc<RwLock<u64>>,

sender_escrow_storage: EscrowStorage,
}

impl ExecutorMock {
pub fn new(
rav_storage: Arc<RwLock<Option<SignedRAV>>>,
receipt_storage: Arc<RwLock<HashMap<u64, ReceivedReceipt>>>,
sender_escrow_storage: Arc<RwLock<HashMap<Address, u128>>>,
rav_storage: RAVStorage,
receipt_storage: ReceiptStorage,
sender_escrow_storage: EscrowStorage,
) -> Self {
ExecutorMock {
rav_storage,
Expand Down
9 changes: 5 additions & 4 deletions tap_core/src/checks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,14 @@ pub mod tests {
async fn check(&self, receipt: &ReceiptWithState<Checking>) -> ReceiptResult<()> {
let receipt_storage = self.receipt_storage.read().await;
// let receipt_id = receipt.
receipt_storage
let unique = receipt_storage
.iter()
.all(|(_stored_receipt_id, stored_receipt)| {
stored_receipt.signed_receipt().message != receipt.signed_receipt().message
})
.then_some(())
.ok_or(ReceiptError::NonUniqueReceipt)
|| stored_receipt.query_id() == receipt.query_id
});

unique.then_some(()).ok_or(ReceiptError::NonUniqueReceipt)
}

async fn check_batch(
Expand Down
Loading

0 comments on commit 568144f

Please sign in to comment.