Skip to content

Commit 6c21ec2

Browse files
committed
test(integration-tests): update test middleware for v2
1 parent c189647 commit 6c21ec2

File tree

5 files changed

+30
-8
lines changed

5 files changed

+30
-8
lines changed

Cargo.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integration-tests/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ rand.workspace = true
2525
indexer-receipt = { path = "../crates/indexer-receipt" }
2626
num_cpus = "1.16.0"
2727
clap = { version = "4.0", features = ["derive"] }
28+
base64 = { workspace = true }
29+
prost = { workspace = true }
30+
tap_aggregator = { workspace = true }

integration-tests/src/load_test.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ use crate::{
1414
ACCOUNT0_SECRET, CHAIN_ID, GRAPH_URL, INDEXER_URL, MAX_RECEIPT_VALUE, SUBGRAPH_ID,
1515
TAP_VERIFIER_CONTRACT,
1616
},
17-
utils::{create_request, create_tap_receipt, create_tap_receipt_v2, find_allocation},
17+
utils::{
18+
create_request, create_tap_receipt, create_tap_receipt_v2, encode_v2_receipt,
19+
find_allocation,
20+
},
1821
};
1922

2023
// Function to test indexer service component
@@ -233,11 +236,11 @@ async fn create_and_send_receipts_v2(
233236
&service_provider,
234237
)?;
235238

236-
let receipt_json = serde_json::to_string(&receipt).unwrap();
239+
let receipt_encoded = encode_v2_receipt(&receipt)?;
237240
let response = create_request(
238241
&http_client,
239242
format!("{}/subgraphs/id/{}", INDEXER_URL, SUBGRAPH_ID).as_str(),
240-
&receipt_json,
243+
&receipt_encoded,
241244
&json!({
242245
"query": "{ _meta { block { number } } }"
243246
}),

integration-tests/src/rav_tests.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ use crate::{
1313
ACCOUNT0_SECRET, CHAIN_ID, GATEWAY_API_KEY, GATEWAY_URL, GRAPH_URL, INDEXER_URL,
1414
MAX_RECEIPT_VALUE, SUBGRAPH_ID, TAP_AGENT_METRICS_URL, TAP_VERIFIER_CONTRACT,
1515
},
16-
utils::{create_request, create_tap_receipt, create_tap_receipt_v2, find_allocation},
16+
utils::{
17+
create_request, create_tap_receipt, create_tap_receipt_v2, encode_v2_receipt,
18+
find_allocation,
19+
},
1720
MetricsChecker,
1821
};
1922

@@ -266,12 +269,12 @@ pub async fn test_tap_rav_v2() -> Result<()> {
266269
&service_provider,
267270
)?;
268271

269-
let receipt_json = serde_json::to_string(&receipt)?;
272+
let receipt_encoded = encode_v2_receipt(&receipt)?;
270273

271274
let response = create_request(
272275
&http_client,
273276
&format!("{}/subgraphs/id/{}", INDEXER_URL, SUBGRAPH_ID),
274-
&receipt_json,
277+
&receipt_encoded,
275278
&json!({
276279
"query": "{ _meta { block { number } } }"
277280
}),
@@ -330,12 +333,12 @@ pub async fn test_tap_rav_v2() -> Result<()> {
330333
&service_provider,
331334
)?;
332335

333-
let receipt_json = serde_json::to_string(&receipt)?;
336+
let receipt_encoded = encode_v2_receipt(&receipt)?;
334337

335338
let response = create_request(
336339
&http_client,
337340
&format!("{}/subgraphs/id/{}", INDEXER_URL, SUBGRAPH_ID),
338-
&receipt_json,
341+
&receipt_encoded,
339342
&json!({
340343
"query": "{ _meta { block { number } } }"
341344
}),

integration-tests/src/utils.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ use std::{
88
};
99

1010
use anyhow::Result;
11+
use base64::prelude::*;
12+
use prost::Message;
1113
use rand::{rng, Rng};
1214
use reqwest::Client;
1315
use serde_json::json;
16+
use tap_aggregator::grpc;
1417
use tap_core::{signed_message::Eip712SignedMessage, tap_eip712_domain};
1518
use tap_graph::Receipt;
1619
use thegraph_core::alloy::{primitives::Address, signers::local::PrivateKeySigner};
@@ -94,6 +97,13 @@ pub fn create_tap_receipt_v2(
9497
Ok(receipt)
9598
}
9699

100+
pub fn encode_v2_receipt(receipt: &Eip712SignedMessage<tap_graph::v2::Receipt>) -> Result<String> {
101+
let protobuf_receipt = grpc::v2::SignedReceipt::from(receipt.clone());
102+
let encoded = protobuf_receipt.encode_to_vec();
103+
let base64_encoded = BASE64_STANDARD.encode(encoded);
104+
Ok(base64_encoded)
105+
}
106+
97107
// Function to create a configured request
98108
pub fn create_request(
99109
client: &reqwest::Client,

0 commit comments

Comments
 (0)