Skip to content

Commit 9e06705

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

File tree

1 file changed

+99
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)