Skip to content

Commit 43fc827

Browse files
committed
fix(test): Sent only 3 receipts per batch otherwise they could be discarted
1 parent e74d2d3 commit 43fc827

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

rav_e2e/src/main.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
use anyhow::Result;
5+
use rav_tests::tap_rav_test;
56

67
mod metrics;
7-
mod receipt;
88
mod rav_tests;
9-
10-
use rav_tests::test_rav_generation;
9+
mod receipt;
10+
use metrics::MetricsChecker;
1111
use receipt::create_tap_receipt;
1212

13-
1413
#[tokio::main]
1514
async fn main() -> Result<()> {
16-
1715
// Run the TAP receipt test
18-
test_rav_generation().await
16+
tap_rav_test().await
1917
}

rav_e2e/src/rav_tests.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ use thegraph_core::alloy::{
1313
signers::local::{MnemonicBuilder, PrivateKeySigner},
1414
};
1515

16-
use crate::metrics::MetricsChecker;
17-
use crate::receipt::create_tap_receipt;
16+
use crate::create_tap_receipt;
17+
use crate::MetricsChecker;
1818

1919
// TODO: Would be nice to read this values from:
2020
// contrib/tap-agent/config.toml
@@ -41,15 +41,18 @@ const MAX_RECEIPT_VALUE: u128 = GRT_BASE / 1_000;
4141
// in the tap-agent setting + 10 seconds
4242
const WAIT_TIME_BATCHES: u64 = 40;
4343

44-
// Bellow constant is to define the number of receipts
45-
const NUM_RECEIPTS: u32 = 20;
44+
// Calculate required receipts to trigger RAV
45+
// With MAX_RECEIPT_VALUE = GRT_BASE / 1_000 (0.001 GRT)
46+
// And trigger_value = 0.002 GRT
47+
// We need at least 3 receipts to trigger a RAV (0.003 GRT > 0.002 GRT)
48+
const NUM_RECEIPTS: u32 = 3;
4649

4750
// Send receipts in batches with a delay in between
4851
// to ensure some receipts get outside the timestamp buffer
4952
const BATCHES: u32 = 2;
5053
const MAX_TRIGGERS: usize = 100;
5154

52-
pub async fn test_rav_generation() -> Result<()> {
55+
pub async fn tap_rav_test() -> Result<()> {
5356
// Setup wallet using your MnemonicBuilder
5457
let index: u32 = 0;
5558
let wallet: PrivateKeySigner = MnemonicBuilder::<English>::default()
@@ -152,7 +155,10 @@ pub async fn test_rav_generation() -> Result<()> {
152155
total_successful += 1;
153156
println!("Receipt {} of batch {} sent successfully", i + 1, batch + 1);
154157
} else {
155-
println!("Failed to send receipt: {}", response.status());
158+
return Err(anyhow::anyhow!(
159+
"Failed to send receipt: {}",
160+
response.status()
161+
));
156162
}
157163

158164
// Small pause between receipts within batch
@@ -171,7 +177,7 @@ pub async fn test_rav_generation() -> Result<()> {
171177
// Wait between batches - long enough for first batch to exit buffer
172178
if batch < 1 {
173179
println!("Waiting for buffer period + 5s...");
174-
tokio::time::sleep(Duration::from_secs(WAIT_TIME_BATCHES + 5)).await;
180+
tokio::time::sleep(Duration::from_secs(WAIT_TIME_BATCHES)).await;
175181
}
176182
}
177183

@@ -181,7 +187,7 @@ pub async fn test_rav_generation() -> Result<()> {
181187
for i in 0..MAX_TRIGGERS {
182188
println!("Sending trigger receipt {}/{}...", i + 1, MAX_TRIGGERS);
183189

184-
let trigger_receipt = crate::create_tap_receipt(
190+
let trigger_receipt = create_tap_receipt(
185191
MAX_RECEIPT_VALUE,
186192
&allocation_id,
187193
TAP_ESCROW_CONTRACT,
@@ -213,7 +219,7 @@ pub async fn test_rav_generation() -> Result<()> {
213219
}
214220

215221
// Check after each trigger
216-
tokio::time::sleep(Duration::from_secs(5)).await;
222+
tokio::time::sleep(Duration::from_secs(1)).await;
217223

218224
let current_metrics = metrics_checker.get_current_metrics().await?;
219225
let current_ravs_created =

0 commit comments

Comments
 (0)