Skip to content

Commit 5ffe3f7

Browse files
committed
test: add test to verify if both are working
Signed-off-by: Gustavo Inacio <[email protected]>
1 parent b2a8b16 commit 5ffe3f7

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
// Copyright 2023-, Semiotic AI, Inc.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
use std::collections::HashSet;
5+
6+
use alloy::{
7+
primitives::{address, Address},
8+
signers::local::PrivateKeySigner,
9+
};
10+
use tap_aggregator::{
11+
grpc::v1::{tap_aggregator_client::TapAggregatorClient as ClientV1, RavRequest as ReqV1},
12+
grpc::v2::{tap_aggregator_client::TapAggregatorClient as ClientV2, RavRequest as ReqV2},
13+
server,
14+
};
15+
use tap_core::{signed_message::Eip712SignedMessage, tap_eip712_domain};
16+
use tap_graph::v2::Receipt as ReceiptV2;
17+
use tap_graph::Receipt as ReceiptV1;
18+
use tonic::codec::CompressionEncoding;
19+
20+
#[tokio::test]
21+
async fn aggregation_test() {
22+
let domain_separator = tap_eip712_domain(1, Address::ZERO);
23+
24+
let wallet = PrivateKeySigner::random();
25+
26+
let max_request_body_size = 1024 * 100;
27+
let max_response_body_size = 1024 * 100;
28+
let max_concurrent_connections = 1;
29+
30+
let accepted_addresses = HashSet::from([wallet.address()]);
31+
32+
let (_, local_addr) = server::run_server(
33+
0,
34+
wallet.clone(),
35+
accepted_addresses,
36+
domain_separator.clone(),
37+
max_request_body_size,
38+
max_response_body_size,
39+
max_concurrent_connections,
40+
)
41+
.await
42+
.unwrap();
43+
44+
let endpoint = format!("http://127.0.0.1:{}", local_addr.port());
45+
46+
let mut client = ClientV1::connect(endpoint.clone())
47+
.await
48+
.unwrap()
49+
.send_compressed(CompressionEncoding::Zstd);
50+
51+
let allocation_id = address!("abababababababababababababababababababab");
52+
53+
// Create receipts
54+
let mut receipts = Vec::new();
55+
for value in 50..60 {
56+
receipts.push(
57+
Eip712SignedMessage::new(
58+
&domain_separator,
59+
ReceiptV1::new(allocation_id, value).unwrap(),
60+
&wallet,
61+
)
62+
.unwrap(),
63+
);
64+
}
65+
66+
let rav_request = ReqV1::new(receipts.clone(), None);
67+
let res = client.aggregate_receipts(rav_request).await;
68+
69+
assert!(res.is_ok());
70+
71+
let mut client = ClientV2::connect(endpoint.clone())
72+
.await
73+
.unwrap()
74+
.send_compressed(CompressionEncoding::Zstd);
75+
76+
let payer = address!("abababababababababababababababababababab");
77+
let data_service = address!("abababababababababababababababababababab");
78+
let service_provider = address!("abababababababababababababababababababab");
79+
80+
// Create receipts
81+
let mut receipts = Vec::new();
82+
for value in 50..60 {
83+
receipts.push(
84+
Eip712SignedMessage::new(
85+
&domain_separator,
86+
ReceiptV2::new(allocation_id, payer, data_service, service_provider, value)
87+
.unwrap(),
88+
&wallet,
89+
)
90+
.unwrap(),
91+
);
92+
}
93+
94+
let rav_request = ReqV2::new(receipts.clone(), None);
95+
let res = client.aggregate_receipts(rav_request).await;
96+
97+
assert!(res.is_ok());
98+
}

0 commit comments

Comments
 (0)