@@ -21,12 +21,12 @@ use crate::{
2121} ;
2222
2323const WAIT_TIME_BATCHES : u64 = 40 ;
24- const NUM_RECEIPTS : u32 = 3 ;
24+ const NUM_RECEIPTS : u32 = 30 ; // Increased to 30 receipts per batch
2525
2626// Send receipts in batches with a delay in between
2727// to ensure some receipts get outside the timestamp buffer
28- const BATCHES : u32 = 2 ;
29- const MAX_TRIGGERS : usize = 100 ;
28+ const BATCHES : u32 = 15 ; // Increased to 15 batches for total 450 receipts in Stage 1
29+ const MAX_TRIGGERS : usize = 200 ; // Increased trigger attempts to 200
3030
3131// Function to test the tap RAV generation
3232pub async fn test_tap_rav_v1 ( ) -> Result < ( ) > {
@@ -241,17 +241,23 @@ pub async fn test_tap_rav_v2() -> Result<()> {
241241 "\n === V2 Initial metrics: RAVs created: {initial_ravs_created}, Unaggregated fees: {initial_unaggregated} ==="
242242 ) ;
243243
244+ // Calculate expected thresholds
245+ let trigger_threshold = 2_000_000_000_000_000u128 ; // 0.002 GRT trigger value
246+ let receipts_needed = trigger_threshold / ( MAX_RECEIPT_VALUE / 10 ) ; // Using trigger receipt value
247+ println ! ( "📊 RAV trigger threshold: {trigger_threshold} wei (0.002 GRT)" , ) ;
248+ let receipt_value = MAX_RECEIPT_VALUE / 10 ;
249+ println ! (
250+ "📊 Receipts needed for trigger: ~{receipts_needed} receipts at {receipt_value} wei each" ,
251+ ) ;
252+
244253 println ! ( "\n === V2 STAGE 1: Sending large receipt batches with small pauses ===" ) ;
245254
246255 // Send multiple V2 receipts in two batches with a gap between them
247256 let mut total_successful = 0 ;
248257
249258 for batch in 0 ..BATCHES {
250- println ! (
251- "Sending V2 batch {} of 2 with {} receipts each..." ,
252- batch + 1 ,
253- NUM_RECEIPTS
254- ) ;
259+ let batch = batch + 1 ;
260+ println ! ( "Sending V2 batch {batch} of {BATCHES} with {NUM_RECEIPTS} receipts each..." , ) ;
255261
256262 for i in 0 ..NUM_RECEIPTS {
257263 // Create V2 receipt
@@ -267,16 +273,17 @@ pub async fn test_tap_rav_v2() -> Result<()> {
267273
268274 let receipt_encoded = encode_v2_receipt ( & receipt) ?;
269275
270- let response = create_request (
271- & http_client,
272- & format ! ( "{INDEXER_URL}/subgraphs/id/{SUBGRAPH_ID}" ) ,
273- & receipt_encoded,
274- & json ! ( {
276+ let response = http_client
277+ . post ( format ! ( "{GATEWAY_URL}/api/subgraphs/id/{SUBGRAPH_ID}" ) )
278+ . header ( "Content-Type" , "application/json" )
279+ . header ( "Authorization" , format ! ( "Bearer {GATEWAY_API_KEY}" ) )
280+ . header ( "Tap-Receipt" , receipt_encoded)
281+ . json ( & json ! ( {
275282 "query" : "{ _meta { block { number } } }"
276- } ) ,
277- )
278- . send ( )
279- . await ?;
283+ } ) )
284+ . timeout ( Duration :: from_secs ( 10 ) )
285+ . send ( )
286+ . await ?;
280287
281288 if response. status ( ) . is_success ( ) {
282289 total_successful += 1 ;
@@ -298,15 +305,22 @@ pub async fn test_tap_rav_v2() -> Result<()> {
298305
299306 // Check metrics after batch
300307 let batch_metrics = metrics_checker. get_current_metrics ( ) . await ?;
308+ let current_unaggregated =
309+ batch_metrics. unaggregated_fees_by_allocation ( & allocation_id. to_string ( ) ) ;
310+ let trigger_threshold = 2_000_000_000_000_000u128 ;
311+ let progress_pct =
312+ ( current_unaggregated as f64 / trigger_threshold as f64 * 100.0 ) . min ( 100.0 ) ;
313+
301314 println ! (
302- "After V2 batch {}: RAVs created: {}, Unaggregated fees: {}" ,
315+ "After V2 batch {}: RAVs created: {}, Unaggregated fees: {} ({:.1}% of trigger threshold) " ,
303316 batch + 1 ,
304317 batch_metrics. ravs_created_by_allocation( & allocation_id. to_string( ) ) ,
305- batch_metrics. unaggregated_fees_by_allocation( & allocation_id. to_string( ) )
318+ current_unaggregated,
319+ progress_pct
306320 ) ;
307321
308322 // Wait between batches - long enough for first batch to exit buffer
309- if batch < 1 {
323+ if batch < BATCHES - 1 {
310324 println ! ( "Waiting for buffer period + 5s..." ) ;
311325 tokio:: time:: sleep ( Duration :: from_secs ( WAIT_TIME_BATCHES ) ) . await ;
312326 }
@@ -331,16 +345,17 @@ pub async fn test_tap_rav_v2() -> Result<()> {
331345
332346 let receipt_encoded = encode_v2_receipt ( & receipt) ?;
333347
334- let response = create_request (
335- & http_client,
336- & format ! ( "{INDEXER_URL}/subgraphs/id/{SUBGRAPH_ID}" ) ,
337- & receipt_encoded,
338- & json ! ( {
348+ let response = http_client
349+ . post ( format ! ( "{GATEWAY_URL}/api/subgraphs/id/{SUBGRAPH_ID}" ) )
350+ . header ( "Content-Type" , "application/json" )
351+ . header ( "Authorization" , format ! ( "Bearer {GATEWAY_API_KEY}" ) )
352+ . header ( "Tap-Receipt" , receipt_encoded)
353+ . json ( & json ! ( {
339354 "query" : "{ _meta { block { number } } }"
340- } ) ,
341- )
342- . send ( )
343- . await ?;
355+ } ) )
356+ . timeout ( Duration :: from_secs ( 10 ) )
357+ . send ( )
358+ . await ?;
344359
345360 if response. status ( ) . is_success ( ) {
346361 total_successful += 1 ;
@@ -361,11 +376,17 @@ pub async fn test_tap_rav_v2() -> Result<()> {
361376 let current_unaggregated =
362377 current_metrics. unaggregated_fees_by_allocation ( & allocation_id. to_string ( ) ) ;
363378
379+ // Calculate progress toward trigger threshold
380+ let trigger_threshold = 2_000_000_000_000_000u128 ;
381+ let progress_pct =
382+ ( current_unaggregated as f64 / trigger_threshold as f64 * 100.0 ) . min ( 100.0 ) ;
383+
364384 println ! (
365- "After V2 trigger {}: RAVs created: {}, Unaggregated fees: {}" ,
385+ "After V2 trigger {}: RAVs created: {}, Unaggregated fees: {} ({:.1}% of trigger threshold) " ,
366386 i + 1 ,
367387 current_ravs_created,
368- current_unaggregated
388+ current_unaggregated,
389+ progress_pct
369390 ) ;
370391
371392 // If we've succeeded, exit early
0 commit comments