@@ -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,15 +241,29 @@ 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 ! (
248+ "📊 RAV trigger threshold: {} wei (0.002 GRT)" ,
249+ trigger_threshold
250+ ) ;
251+ println ! (
252+ "📊 Receipts needed for trigger: ~{} receipts at {} wei each" ,
253+ receipts_needed,
254+ MAX_RECEIPT_VALUE / 10
255+ ) ;
256+
244257 println ! ( "\n === V2 STAGE 1: Sending large receipt batches with small pauses ===" ) ;
245258
246259 // Send multiple V2 receipts in two batches with a gap between them
247260 let mut total_successful = 0 ;
248261
249262 for batch in 0 ..BATCHES {
250263 println ! (
251- "Sending V2 batch {} of 2 with {} receipts each..." ,
264+ "Sending V2 batch {} of {} with {} receipts each..." ,
252265 batch + 1 ,
266+ BATCHES ,
253267 NUM_RECEIPTS
254268 ) ;
255269
@@ -267,16 +281,17 @@ pub async fn test_tap_rav_v2() -> Result<()> {
267281
268282 let receipt_encoded = encode_v2_receipt ( & receipt) ?;
269283
270- let response = create_request (
271- & http_client,
272- & format ! ( "{INDEXER_URL}/subgraphs/id/{SUBGRAPH_ID}" ) ,
273- & receipt_encoded,
274- & json ! ( {
284+ let response = http_client
285+ . post ( format ! ( "{GATEWAY_URL}/api/subgraphs/id/{SUBGRAPH_ID}" ) )
286+ . header ( "Content-Type" , "application/json" )
287+ . header ( "Authorization" , format ! ( "Bearer {GATEWAY_API_KEY}" ) )
288+ . header ( "Tap-Receipt" , receipt_encoded)
289+ . json ( & json ! ( {
275290 "query" : "{ _meta { block { number } } }"
276- } ) ,
277- )
278- . send ( )
279- . await ?;
291+ } ) )
292+ . timeout ( Duration :: from_secs ( 10 ) )
293+ . send ( )
294+ . await ?;
280295
281296 if response. status ( ) . is_success ( ) {
282297 total_successful += 1 ;
@@ -298,15 +313,22 @@ pub async fn test_tap_rav_v2() -> Result<()> {
298313
299314 // Check metrics after batch
300315 let batch_metrics = metrics_checker. get_current_metrics ( ) . await ?;
316+ let current_unaggregated =
317+ batch_metrics. unaggregated_fees_by_allocation ( & allocation_id. to_string ( ) ) ;
318+ let trigger_threshold = 2_000_000_000_000_000u128 ;
319+ let progress_pct =
320+ ( current_unaggregated as f64 / trigger_threshold as f64 * 100.0 ) . min ( 100.0 ) ;
321+
301322 println ! (
302- "After V2 batch {}: RAVs created: {}, Unaggregated fees: {}" ,
323+ "After V2 batch {}: RAVs created: {}, Unaggregated fees: {} ({:.1}% of trigger threshold) " ,
303324 batch + 1 ,
304325 batch_metrics. ravs_created_by_allocation( & allocation_id. to_string( ) ) ,
305- batch_metrics. unaggregated_fees_by_allocation( & allocation_id. to_string( ) )
326+ current_unaggregated,
327+ progress_pct
306328 ) ;
307329
308330 // Wait between batches - long enough for first batch to exit buffer
309- if batch < 1 {
331+ if batch < BATCHES - 1 {
310332 println ! ( "Waiting for buffer period + 5s..." ) ;
311333 tokio:: time:: sleep ( Duration :: from_secs ( WAIT_TIME_BATCHES ) ) . await ;
312334 }
@@ -331,16 +353,17 @@ pub async fn test_tap_rav_v2() -> Result<()> {
331353
332354 let receipt_encoded = encode_v2_receipt ( & receipt) ?;
333355
334- let response = create_request (
335- & http_client,
336- & format ! ( "{INDEXER_URL}/subgraphs/id/{SUBGRAPH_ID}" ) ,
337- & receipt_encoded,
338- & json ! ( {
356+ let response = http_client
357+ . post ( format ! ( "{GATEWAY_URL}/api/subgraphs/id/{SUBGRAPH_ID}" ) )
358+ . header ( "Content-Type" , "application/json" )
359+ . header ( "Authorization" , format ! ( "Bearer {GATEWAY_API_KEY}" ) )
360+ . header ( "Tap-Receipt" , receipt_encoded)
361+ . json ( & json ! ( {
339362 "query" : "{ _meta { block { number } } }"
340- } ) ,
341- )
342- . send ( )
343- . await ?;
363+ } ) )
364+ . timeout ( Duration :: from_secs ( 10 ) )
365+ . send ( )
366+ . await ?;
344367
345368 if response. status ( ) . is_success ( ) {
346369 total_successful += 1 ;
@@ -361,11 +384,17 @@ pub async fn test_tap_rav_v2() -> Result<()> {
361384 let current_unaggregated =
362385 current_metrics. unaggregated_fees_by_allocation ( & allocation_id. to_string ( ) ) ;
363386
387+ // Calculate progress toward trigger threshold
388+ let trigger_threshold = 2_000_000_000_000_000u128 ;
389+ let progress_pct =
390+ ( current_unaggregated as f64 / trigger_threshold as f64 * 100.0 ) . min ( 100.0 ) ;
391+
364392 println ! (
365- "After V2 trigger {}: RAVs created: {}, Unaggregated fees: {}" ,
393+ "After V2 trigger {}: RAVs created: {}, Unaggregated fees: {} ({:.1}% of trigger threshold) " ,
366394 i + 1 ,
367395 current_ravs_created,
368- current_unaggregated
396+ current_unaggregated,
397+ progress_pct
369398 ) ;
370399
371400 // If we've succeeded, exit early
0 commit comments