diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 18d83696f..05c71536e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -110,6 +110,7 @@ jobs: image: rust:1.81-bookworm env: DATABASE_URL: postgres://postgres@postgres:5432 + CI: true steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 - name: Cache dependencies diff --git a/Cargo.lock b/Cargo.lock index cab14340a..fdac17694 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3500,7 +3500,7 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", - "socket2 0.4.10", + "socket2 0.5.8", "tokio", "tower-service", "tracing", @@ -4018,6 +4018,7 @@ dependencies = [ "indexer-receipt", "indexer-tap-agent", "indexer-watcher", + "insta", "itertools 0.14.0", "jsonrpsee", "lazy_static", @@ -4086,13 +4087,14 @@ checksum = "c8fae54786f62fb2918dcfae3d568594e50eb9b5c25bf04371af6fe7516452fb" [[package]] name = "insta" -version = "1.41.1" +version = "1.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e9ffc4d4892617c50a928c52b2961cb5174b6fc6ebf252b2fac9d21955c48b8" +checksum = "50259abbaa67d11d2bcafc7ba1d094ed7a0c70e3ce893f0d0997f73558cb3084" dependencies = [ "console", - "lazy_static", "linked-hash-map", + "once_cell", + "pin-project 1.1.9", "similar", ] @@ -8599,7 +8601,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "windows-sys 0.48.0", + "windows-sys 0.59.0", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index c50729b8d..f6e2676a8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -95,3 +95,9 @@ rev = "9fd4beb" [patch.crates-io.tap_graph] git = "https://github.com/semiotic-ai/timeline-aggregation-protocol" rev = "9fd4beb" + +# Insta benefits from being compiled in release mode, even as dev dependency +# see https://insta.rs/docs/quickstart +[profile.dev.package] +insta.opt-level = 3 +similar.opt-level = 3 diff --git a/crates/tap-agent/Cargo.toml b/crates/tap-agent/Cargo.toml index a3140aced..4a339cbdd 100644 --- a/crates/tap-agent/Cargo.toml +++ b/crates/tap-agent/Cargo.toml @@ -67,3 +67,4 @@ test-assets = { path = "../test-assets" } test-log.workspace = true rstest = "0.24.0" stdext = "0.3.3" +insta = "1.42.2" diff --git a/crates/tap-agent/src/agent/sender_account.rs b/crates/tap-agent/src/agent/sender_account.rs index 2ac203ca0..a4305ed8b 100644 --- a/crates/tap-agent/src/agent/sender_account.rs +++ b/crates/tap-agent/src/agent/sender_account.rs @@ -1527,10 +1527,7 @@ pub mod tests { )) .unwrap(); let message = msg_receiver.recv().await.expect("Channel failed"); - assert_eq!( - message, - SenderAccountMessage::UpdateAllocationIds(allocation_ids) - ); + insta::assert_debug_snapshot!(message); // verify if create sender account let sender_allocation_id = format!("{}:{}:{}", prefix.clone(), SENDER.1, ALLOCATION_ID_0); @@ -1541,17 +1538,7 @@ pub mod tests { .cast(SenderAccountMessage::UpdateAllocationIds(HashSet::new())) .unwrap(); let message = msg_receiver.recv().await.expect("Channel failed"); - assert_eq!( - message, - SenderAccountMessage::UpdateReceiptFees( - ALLOCATION_ID_0, - ReceiptFees::UpdateValue(UnaggregatedReceipts { - value: 0, - last_id: 0, - counter: 0, - }) - ) - ); + insta::assert_debug_snapshot!(message); let actor_ref = ActorRef::::where_is(sender_allocation_id.clone()); assert!(actor_ref.is_some()); @@ -1582,10 +1569,7 @@ pub mod tests { .cast(SenderAccountMessage::UpdateAllocationIds(HashSet::new())) .unwrap(); let msg = msg_receiver.recv().await.expect("Channel failed"); - assert_eq!( - msg, - SenderAccountMessage::UpdateAllocationIds(HashSet::new()) - ); + insta::assert_debug_snapshot!(msg); let actor_ref = ActorRef::::where_is(sender_allocation_id.clone()); assert!(actor_ref.is_none()); diff --git a/crates/tap-agent/src/agent/sender_accounts_manager.rs b/crates/tap-agent/src/agent/sender_accounts_manager.rs index 1bb183241..f31ea95bf 100644 --- a/crates/tap-agent/src/agent/sender_accounts_manager.rs +++ b/crates/tap-agent/src/agent/sender_accounts_manager.rs @@ -948,9 +948,7 @@ mod tests { use crate::{ agent::{ sender_account::SenderAccountMessage, - sender_accounts_manager::{ - handle_notification, AllocationId, NewReceiptNotification, SenderType, - }, + sender_accounts_manager::{handle_notification, NewReceiptNotification, SenderType}, }, test::{ actors::{DummyActor, MockSenderAccount, MockSenderAllocation, TestableActor}, @@ -1316,10 +1314,8 @@ mod tests { .await .unwrap(); - assert_eq!( - rx.recv().await.unwrap(), - SenderAccountMessage::NewAllocationId(AllocationId::Legacy(ALLOCATION_ID_0)) - ); + let new_alloc_msg = rx.recv().await.unwrap(); + insta::assert_debug_snapshot!(new_alloc_msg); sender_account.stop_and_wait(None, None).await.unwrap(); join_handle.await.unwrap(); } diff --git a/crates/tap-agent/src/agent/sender_allocation.rs b/crates/tap-agent/src/agent/sender_allocation.rs index eba730895..fef46487f 100644 --- a/crates/tap-agent/src/agent/sender_allocation.rs +++ b/crates/tap-agent/src/agent/sender_allocation.rs @@ -1293,7 +1293,6 @@ pub mod tests { time::{Duration, SystemTime, UNIX_EPOCH}, }; - use bigdecimal::ToPrimitive; use futures::future::join_all; use indexer_monitor::{DeploymentDetails, EscrowAccounts, SubgraphClient}; use indexer_receipt::TapReceipt; @@ -1326,7 +1325,6 @@ pub mod tests { sender_account::{ReceiptFees, SenderAccountMessage}, sender_accounts_manager::NewReceiptNotification, sender_allocation::DatabaseInteractions, - unaggregated_receipts::UnaggregatedReceipts, }, tap::{context::Legacy, CheckingReceipt}, test::{ @@ -1492,17 +1490,8 @@ pub mod tests { ) .unwrap(); - // Should emit a message to the sender account with the unaggregated fees. - let expected_message = SenderAccountMessage::UpdateReceiptFees( - ALLOCATION_ID_0, - ReceiptFees::UpdateValue(UnaggregatedReceipts { - last_id: 10, - value: 55u128, - counter: 10, - }), - ); let last_message_emitted = last_message_emitted.recv().await.unwrap(); - assert_eq!(last_message_emitted, expected_message); + insta::assert_debug_snapshot!(last_message_emitted); // Check that the unaggregated fees are correct. assert_eq!(total_unaggregated_fees.value, 55u128); @@ -1537,25 +1526,11 @@ pub mod tests { ) .unwrap(); - // Should emit a message to the sender account with the unaggregated fees. - let expected_message = SenderAccountMessage::UpdateInvalidReceiptFees( - ALLOCATION_ID_0, - UnaggregatedReceipts { - last_id: 10, - value: 55u128, - counter: 10, - }, - ); let update_invalid_msg = message_receiver.recv().await.unwrap(); - assert_eq!(update_invalid_msg, expected_message); + insta::assert_debug_snapshot!(update_invalid_msg); + let last_message_emitted = message_receiver.recv().await.unwrap(); - assert_eq!( - last_message_emitted, - SenderAccountMessage::UpdateReceiptFees( - ALLOCATION_ID_0, - ReceiptFees::UpdateValue(UnaggregatedReceipts::default()) - ) - ); + insta::assert_debug_snapshot!(last_message_emitted); // Check that the unaggregated fees are correct. assert_eq!(total_unaggregated_fees.value, 0u128); @@ -1609,23 +1584,14 @@ pub mod tests { flush_messages(&mut msg_receiver).await; // should emit update aggregate fees message to sender account + let startup_load_msg = message_receiver.recv().await.unwrap(); + insta::assert_debug_snapshot!(startup_load_msg); + + let last_message_emitted = message_receiver.recv().await.unwrap(); let expected_message = SenderAccountMessage::UpdateReceiptFees( ALLOCATION_ID_0, ReceiptFees::NewReceipt(20u128, timestamp_ns), ); - let startup_load_msg = message_receiver.recv().await.unwrap(); - assert_eq!( - startup_load_msg, - SenderAccountMessage::UpdateReceiptFees( - ALLOCATION_ID_0, - ReceiptFees::UpdateValue(UnaggregatedReceipts { - value: 0, - last_id: 0, - counter: 0, - }) - ) - ); - let last_message_emitted = message_receiver.recv().await.unwrap(); assert_eq!(last_message_emitted, expected_message); } @@ -1686,40 +1652,18 @@ pub mod tests { assert_eq!(total_unaggregated_fees.value, 0u128); let startup_msg = message_receiver.recv().await.unwrap(); - assert_eq!( - startup_msg, - SenderAccountMessage::UpdateReceiptFees( - ALLOCATION_ID_0, - ReceiptFees::UpdateValue(UnaggregatedReceipts { - value: 90, - last_id: 20, - counter: 20, - }) - ) - ); + insta::assert_debug_snapshot!(startup_msg); // Check if the sender received invalid receipt fees - let expected_message = SenderAccountMessage::UpdateInvalidReceiptFees( - ALLOCATION_ID_0, - UnaggregatedReceipts { - last_id: 0, - value: 45, - counter: 0, - }, - ); - assert_eq!(message_receiver.recv().await.unwrap(), expected_message); + let msg = message_receiver.recv().await.unwrap(); + insta::assert_debug_snapshot!(msg); - assert!(matches!( - message_receiver.recv().await.unwrap(), - SenderAccountMessage::UpdateReceiptFees(_, ReceiptFees::RavRequestResponse(_, _)) - )); + let updated_receipt_fees = message_receiver.recv().await.unwrap(); + insta::assert_debug_snapshot!(updated_receipt_fees); } - async fn execute( - pgpool: PgPool, - amount_of_receipts: u64, - populate: impl FnOnce(PgPool) -> Fut, - ) where + async fn execute(pgpool: PgPool, populate: impl FnOnce(PgPool) -> Fut) + where Fut: Future, { // Start a mock graphql server using wiremock @@ -1767,27 +1711,13 @@ pub mod tests { assert_eq!(total_unaggregated_fees.value, 0u128); let startup_msg = message_receiver.recv().await.unwrap(); - let expected_value: u128 = ((amount_of_receipts.to_u128().expect("should be u128") - - 1u128) - * (amount_of_receipts.to_u128().expect("should be u128"))) - / 2; - assert_eq!( - startup_msg, - SenderAccountMessage::UpdateReceiptFees( - ALLOCATION_ID_0, - ReceiptFees::UpdateValue(UnaggregatedReceipts { - value: expected_value, - last_id: amount_of_receipts, - counter: amount_of_receipts, - }) - ) - ); + insta::assert_debug_snapshot!(startup_msg); } #[sqlx::test(migrations = "../../migrations")] async fn test_several_receipts_rav_request(pgpool: PgPool) { const AMOUNT_OF_RECEIPTS: u64 = 1000; - execute(pgpool, AMOUNT_OF_RECEIPTS, |pgpool| async move { + execute(pgpool, |pgpool| async move { // Add receipts to the database. for i in 0..AMOUNT_OF_RECEIPTS { @@ -1805,7 +1735,7 @@ pub mod tests { async fn test_several_receipts_batch_insert_rav_request(pgpool: PgPool) { // Add batch receipts to the database. const AMOUNT_OF_RECEIPTS: u64 = 1000; - execute(pgpool, AMOUNT_OF_RECEIPTS, |pgpool| async move { + execute(pgpool, |pgpool| async move { // Add receipts to the database. let mut receipts = Vec::with_capacity(1000); for i in 0..AMOUNT_OF_RECEIPTS { @@ -1841,13 +1771,7 @@ pub mod tests { assert_eq!(sender_allocation.get_status(), ActorStatus::Stopped); // check if message is sent to sender account - assert_eq!( - message_receiver.recv().await.unwrap(), - SenderAccountMessage::UpdateReceiptFees( - ALLOCATION_ID_0, - ReceiptFees::UpdateValue(UnaggregatedReceipts::default()) - ) - ); + insta::assert_debug_snapshot!(message_receiver.recv().await); } // used for test_close_allocation_with_pending_fees(pgpool: @@ -2117,27 +2041,10 @@ pub mod tests { // If it is an error then rav request failed let startup_msg = message_receiver.recv().await.unwrap(); - assert_eq!( - startup_msg, - SenderAccountMessage::UpdateReceiptFees( - ALLOCATION_ID_0, - ReceiptFees::UpdateValue(UnaggregatedReceipts { - value: 45, - last_id: 10, - counter: 10, - }) - ) - ); - let rav_response_message = message_receiver.recv().await.unwrap(); - match rav_response_message { - SenderAccountMessage::UpdateReceiptFees( - _, - ReceiptFees::RavRequestResponse(_, rav_response), - ) => { - assert!(rav_response.is_err()); - } - v => panic!("Expecting RavRequestResponse as last message, found: {v:?}"), - } + insta::assert_debug_snapshot!(startup_msg); + + let rav_error_response_message = message_receiver.recv().await.unwrap(); + insta::assert_debug_snapshot!(rav_error_response_message); // expect the actor to keep running assert_eq!(sender_allocation.get_status(), ActorStatus::Running); @@ -2173,7 +2080,6 @@ pub mod tests { .as_nanos() as u64; const RECEIPT_VALUE: u128 = 1622018441284756158; const TOTAL_RECEIPTS: u64 = 10; - const TOTAL_SUM: u128 = RECEIPT_VALUE * TOTAL_RECEIPTS as u128; for i in 0..TOTAL_RECEIPTS { let receipt = @@ -2203,42 +2109,14 @@ pub mod tests { // If it is an error then rav request failed let startup_msg = message_receiver.recv().await.unwrap(); - assert_eq!( - startup_msg, - SenderAccountMessage::UpdateReceiptFees( - ALLOCATION_ID_0, - ReceiptFees::UpdateValue(UnaggregatedReceipts { - value: 16220184412847561580, - last_id: 10, - counter: 10, - }) - ) - ); + insta::assert_debug_snapshot!(startup_msg); let invalid_receipts = message_receiver.recv().await.unwrap(); - assert_eq!( - invalid_receipts, - SenderAccountMessage::UpdateInvalidReceiptFees( - ALLOCATION_ID_0, - UnaggregatedReceipts { - value: TOTAL_SUM, - last_id: 0, - counter: 0, - } - ) - ); + insta::assert_debug_snapshot!(invalid_receipts); - let rav_response_message = message_receiver.recv().await.unwrap(); - match rav_response_message { - SenderAccountMessage::UpdateReceiptFees( - _, - ReceiptFees::RavRequestResponse(_, rav_response), - ) => { - assert!(rav_response.is_err()); - } - v => panic!("Expecting RavRequestResponse as last message, found: {v:?}"), - } + let rav_error_response_message = message_receiver.recv().await.unwrap(); + insta::assert_debug_snapshot!(rav_error_response_message); let invalid_receipts = sqlx::query!( r#" diff --git a/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_account__tests__update_allocation_ids-2.snap b/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_account__tests__update_allocation_ids-2.snap new file mode 100644 index 000000000..ef0269c0b --- /dev/null +++ b/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_account__tests__update_allocation_ids-2.snap @@ -0,0 +1,14 @@ +--- +source: crates/tap-agent/src/agent/sender_account.rs +expression: message +--- +UpdateReceiptFees( + 0xfa44c72b753a66591f241c7dc04e8178c30e13af, + UpdateValue( + UnaggregatedReceipts { + value: 0, + last_id: 0, + counter: 0, + }, + ), +) diff --git a/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_account__tests__update_allocation_ids-3.snap b/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_account__tests__update_allocation_ids-3.snap new file mode 100644 index 000000000..d8da2e81f --- /dev/null +++ b/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_account__tests__update_allocation_ids-3.snap @@ -0,0 +1,7 @@ +--- +source: crates/tap-agent/src/agent/sender_account.rs +expression: msg +--- +UpdateAllocationIds( + {}, +) diff --git a/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_account__tests__update_allocation_ids.snap b/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_account__tests__update_allocation_ids.snap new file mode 100644 index 000000000..bbf15d8e1 --- /dev/null +++ b/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_account__tests__update_allocation_ids.snap @@ -0,0 +1,11 @@ +--- +source: crates/tap-agent/src/agent/sender_account.rs +expression: message +--- +UpdateAllocationIds( + { + Legacy( + 0xfa44c72b753a66591f241c7dc04e8178c30e13af, + ), + }, +) diff --git a/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_accounts_manager__tests__create_allocation_id.snap b/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_accounts_manager__tests__create_allocation_id.snap new file mode 100644 index 000000000..0ad0a8a08 --- /dev/null +++ b/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_accounts_manager__tests__create_allocation_id.snap @@ -0,0 +1,9 @@ +--- +source: crates/tap-agent/src/agent/sender_accounts_manager.rs +expression: new_alloc_msg +--- +NewAllocationId( + Legacy( + 0xfa44c72b753a66591f241c7dc04e8178c30e13af, + ), +) diff --git a/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_allocation__tests__close_allocation_no_pending_fees.snap b/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_allocation__tests__close_allocation_no_pending_fees.snap new file mode 100644 index 000000000..9d3934e1f --- /dev/null +++ b/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_allocation__tests__close_allocation_no_pending_fees.snap @@ -0,0 +1,16 @@ +--- +source: crates/tap-agent/src/agent/sender_allocation.rs +expression: message_receiver.recv().await +--- +Some( + UpdateReceiptFees( + 0xfa44c72b753a66591f241c7dc04e8178c30e13af, + UpdateValue( + UnaggregatedReceipts { + value: 0, + last_id: 0, + counter: 0, + }, + ), + ), +) diff --git a/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_allocation__tests__execute-2.snap b/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_allocation__tests__execute-2.snap new file mode 100644 index 000000000..4fb719143 --- /dev/null +++ b/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_allocation__tests__execute-2.snap @@ -0,0 +1,14 @@ +--- +source: crates/tap-agent/src/agent/sender_allocation.rs +expression: startup_msg +--- +UpdateReceiptFees( + 0xfa44c72b753a66591f241c7dc04e8178c30e13af, + UpdateValue( + UnaggregatedReceipts { + value: 499500, + last_id: 1000, + counter: 1000, + }, + ), +) diff --git a/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_allocation__tests__execute.snap b/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_allocation__tests__execute.snap new file mode 100644 index 000000000..4fb719143 --- /dev/null +++ b/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_allocation__tests__execute.snap @@ -0,0 +1,14 @@ +--- +source: crates/tap-agent/src/agent/sender_allocation.rs +expression: startup_msg +--- +UpdateReceiptFees( + 0xfa44c72b753a66591f241c7dc04e8178c30e13af, + UpdateValue( + UnaggregatedReceipts { + value: 499500, + last_id: 1000, + counter: 1000, + }, + ), +) diff --git a/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_allocation__tests__failed_rav_request-2.snap b/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_allocation__tests__failed_rav_request-2.snap new file mode 100644 index 000000000..390b67866 --- /dev/null +++ b/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_allocation__tests__failed_rav_request-2.snap @@ -0,0 +1,19 @@ +--- +source: crates/tap-agent/src/agent/sender_allocation.rs +expression: rav_response_message +--- +UpdateReceiptFees( + 0xfa44c72b753a66591f241c7dc04e8178c30e13af, + RavRequestResponse( + UnaggregatedReceipts { + value: 45, + last_id: 10, + counter: 10, + }, + Err( + Other( + "It looks like there are no valid receipts for the RAV request.This may happen if your `rav_request_trigger_value` is too low and no receipts were found outside the `rav_request_timestamp_buffer_ms`.You can fix this by increasing the `rav_request_trigger_value`.", + ), + ), + ), +) diff --git a/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_allocation__tests__failed_rav_request.snap b/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_allocation__tests__failed_rav_request.snap new file mode 100644 index 000000000..155e493df --- /dev/null +++ b/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_allocation__tests__failed_rav_request.snap @@ -0,0 +1,14 @@ +--- +source: crates/tap-agent/src/agent/sender_allocation.rs +expression: startup_msg +--- +UpdateReceiptFees( + 0xfa44c72b753a66591f241c7dc04e8178c30e13af, + UpdateValue( + UnaggregatedReceipts { + value: 45, + last_id: 10, + counter: 10, + }, + ), +) diff --git a/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_allocation__tests__rav_request_when_all_receipts_invalid-2.snap b/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_allocation__tests__rav_request_when_all_receipts_invalid-2.snap new file mode 100644 index 000000000..f977ceac9 --- /dev/null +++ b/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_allocation__tests__rav_request_when_all_receipts_invalid-2.snap @@ -0,0 +1,12 @@ +--- +source: crates/tap-agent/src/agent/sender_allocation.rs +expression: invalid_receipts +--- +UpdateInvalidReceiptFees( + 0xfa44c72b753a66591f241c7dc04e8178c30e13af, + UnaggregatedReceipts { + value: 16220184412847561580, + last_id: 0, + counter: 0, + }, +) diff --git a/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_allocation__tests__rav_request_when_all_receipts_invalid-3.snap b/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_allocation__tests__rav_request_when_all_receipts_invalid-3.snap new file mode 100644 index 000000000..2d8170404 --- /dev/null +++ b/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_allocation__tests__rav_request_when_all_receipts_invalid-3.snap @@ -0,0 +1,17 @@ +--- +source: crates/tap-agent/src/agent/sender_allocation.rs +expression: rav_error_response_message +--- +UpdateReceiptFees( + 0xfa44c72b753a66591f241c7dc04e8178c30e13af, + RavRequestResponse( + UnaggregatedReceipts { + value: 0, + last_id: 0, + counter: 0, + }, + Err( + AllReceiptsInvalid, + ), + ), +) diff --git a/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_allocation__tests__rav_request_when_all_receipts_invalid.snap b/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_allocation__tests__rav_request_when_all_receipts_invalid.snap new file mode 100644 index 000000000..408b3bdc1 --- /dev/null +++ b/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_allocation__tests__rav_request_when_all_receipts_invalid.snap @@ -0,0 +1,14 @@ +--- +source: crates/tap-agent/src/agent/sender_allocation.rs +expression: startup_msg +--- +UpdateReceiptFees( + 0xfa44c72b753a66591f241c7dc04e8178c30e13af, + UpdateValue( + UnaggregatedReceipts { + value: 16220184412847561580, + last_id: 10, + counter: 10, + }, + ), +) diff --git a/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_allocation__tests__receive_new_receipt.snap b/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_allocation__tests__receive_new_receipt.snap new file mode 100644 index 000000000..5acfb2b0d --- /dev/null +++ b/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_allocation__tests__receive_new_receipt.snap @@ -0,0 +1,14 @@ +--- +source: crates/tap-agent/src/agent/sender_allocation.rs +expression: startup_load_msg +--- +UpdateReceiptFees( + 0xfa44c72b753a66591f241c7dc04e8178c30e13af, + UpdateValue( + UnaggregatedReceipts { + value: 0, + last_id: 0, + counter: 0, + }, + ), +) diff --git a/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_allocation__tests__should_return_invalid_receipts_on_startup-2.snap b/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_allocation__tests__should_return_invalid_receipts_on_startup-2.snap new file mode 100644 index 000000000..688a7d38c --- /dev/null +++ b/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_allocation__tests__should_return_invalid_receipts_on_startup-2.snap @@ -0,0 +1,14 @@ +--- +source: crates/tap-agent/src/agent/sender_allocation.rs +expression: last_message_emitted +--- +UpdateReceiptFees( + 0xfa44c72b753a66591f241c7dc04e8178c30e13af, + UpdateValue( + UnaggregatedReceipts { + value: 0, + last_id: 0, + counter: 0, + }, + ), +) diff --git a/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_allocation__tests__should_return_invalid_receipts_on_startup.snap b/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_allocation__tests__should_return_invalid_receipts_on_startup.snap new file mode 100644 index 000000000..226cf567e --- /dev/null +++ b/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_allocation__tests__should_return_invalid_receipts_on_startup.snap @@ -0,0 +1,12 @@ +--- +source: crates/tap-agent/src/agent/sender_allocation.rs +expression: update_invalid_msg +--- +UpdateInvalidReceiptFees( + 0xfa44c72b753a66591f241c7dc04e8178c30e13af, + UnaggregatedReceipts { + value: 55, + last_id: 10, + counter: 10, + }, +) diff --git a/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_allocation__tests__should_update_unaggregated_fees_on_start.snap b/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_allocation__tests__should_update_unaggregated_fees_on_start.snap new file mode 100644 index 000000000..bd5403702 --- /dev/null +++ b/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_allocation__tests__should_update_unaggregated_fees_on_start.snap @@ -0,0 +1,14 @@ +--- +source: crates/tap-agent/src/agent/sender_allocation.rs +expression: last_message_emitted +--- +UpdateReceiptFees( + 0xfa44c72b753a66591f241c7dc04e8178c30e13af, + UpdateValue( + UnaggregatedReceipts { + value: 55, + last_id: 10, + counter: 10, + }, + ), +) diff --git a/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_allocation__tests__trigger_rav_request-2.snap b/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_allocation__tests__trigger_rav_request-2.snap new file mode 100644 index 000000000..43602262d --- /dev/null +++ b/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_allocation__tests__trigger_rav_request-2.snap @@ -0,0 +1,12 @@ +--- +source: crates/tap-agent/src/agent/sender_allocation.rs +expression: msg +--- +UpdateInvalidReceiptFees( + 0xfa44c72b753a66591f241c7dc04e8178c30e13af, + UnaggregatedReceipts { + value: 45, + last_id: 0, + counter: 0, + }, +) diff --git a/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_allocation__tests__trigger_rav_request-3.snap b/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_allocation__tests__trigger_rav_request-3.snap new file mode 100644 index 000000000..c35d23b96 --- /dev/null +++ b/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_allocation__tests__trigger_rav_request-3.snap @@ -0,0 +1,22 @@ +--- +source: crates/tap-agent/src/agent/sender_allocation.rs +expression: x +--- +UpdateReceiptFees( + 0xfa44c72b753a66591f241c7dc04e8178c30e13af, + RavRequestResponse( + UnaggregatedReceipts { + value: 0, + last_id: 0, + counter: 0, + }, + Ok( + Some( + RavInformation { + allocation_id: 0xfa44c72b753a66591f241c7dc04e8178c30e13af, + value_aggregate: 45, + }, + ), + ), + ), +) diff --git a/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_allocation__tests__trigger_rav_request.snap b/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_allocation__tests__trigger_rav_request.snap new file mode 100644 index 000000000..208b1ba24 --- /dev/null +++ b/crates/tap-agent/src/agent/snapshots/indexer_tap_agent__agent__sender_allocation__tests__trigger_rav_request.snap @@ -0,0 +1,14 @@ +--- +source: crates/tap-agent/src/agent/sender_allocation.rs +expression: startup_msg +--- +UpdateReceiptFees( + 0xfa44c72b753a66591f241c7dc04e8178c30e13af, + UpdateValue( + UnaggregatedReceipts { + value: 90, + last_id: 20, + counter: 20, + }, + ), +) diff --git a/crates/tap-agent/src/tap/context/receipt.rs b/crates/tap-agent/src/tap/context/receipt.rs index dab3032c3..99e4eef15 100644 --- a/crates/tap-agent/src/tap/context/receipt.rs +++ b/crates/tap-agent/src/tap/context/receipt.rs @@ -41,6 +41,7 @@ impl From for AdapterError { } /// convert Bound`` to Bound`` +#[inline] fn u64_bound_to_bigdecimal_bound(bound: Bound<&u64>) -> Bound { match bound { Bound::Included(val) => Bound::Included(BigDecimal::from(*val)), @@ -473,10 +474,9 @@ mod test { .unwrap()[0] .clone(); - assert_eq!( - received_receipt.signed_receipt().unique_id(), - retrieved_receipt.signed_receipt().unique_id(), - ); + let received_id = received_receipt.signed_receipt().unique_id(); + let retrieved_id = retrieved_receipt.signed_receipt().unique_id(); + assert_eq!(received_id, retrieved_id); } /// This function compares a local receipts vector filter by timestamp range (we assume that the stdlib @@ -934,8 +934,6 @@ mod test { ); } - // zip the 2 vectors together - macro_rules! test_ranges{ ($($arg: expr), +) => { { diff --git a/justfile b/justfile index adb42400f..f9b8b58d7 100644 --- a/justfile +++ b/justfile @@ -25,6 +25,9 @@ ci: test: RUST_LOG=debug cargo nextest run +review: + RUST_LOG=debug cargo insta review + fmt: cargo +nightly fmt