Skip to content

Commit e5dfb0f

Browse files
committed
test: remove unused parameters from showcase
Signed-off-by: Gustavo Inacio <[email protected]>
1 parent 78beec1 commit e5dfb0f

File tree

2 files changed

+55
-83
lines changed

2 files changed

+55
-83
lines changed

tap_integration_tests/tests/indexer_mock/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ pub trait Rpc {
3333
#[method(name = "request")]
3434
async fn request(
3535
&self,
36-
request_id: u64, // Unique identifier for the request
3736
receipt: SignedReceipt, // Signed receipt associated with the request
3837
) -> Result<(), jsonrpsee::types::ErrorObjectOwned>; // The result of the request, a JSON-RPC error if it fails
3938
}
@@ -90,7 +89,6 @@ where
9089
{
9190
async fn request(
9291
&self,
93-
_request_id: u64,
9492
receipt: SignedReceipt,
9593
) -> Result<(), jsonrpsee::types::ErrorObjectOwned> {
9694
let verify_result = match self.manager.verify_and_store_receipt(receipt).await {

tap_integration_tests/tests/showcase.rs

Lines changed: 55 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ fn requests_1(
219219
num_batches: u64,
220220
allocation_ids: Vec<Address>,
221221
domain_separator: Eip712Domain,
222-
) -> Vec<(EIP712SignedMessage<Receipt>, u64)> {
222+
) -> Vec<EIP712SignedMessage<Receipt>> {
223223
let (sender_key, _) = keys_sender;
224224
// Create your Receipt here
225225
generate_requests(
@@ -229,7 +229,6 @@ fn requests_1(
229229
allocation_ids[0],
230230
&domain_separator,
231231
)
232-
.unwrap()
233232
}
234233

235234
#[fixture]
@@ -239,7 +238,7 @@ fn requests_2(
239238
num_batches: u64,
240239
allocation_ids: Vec<Address>,
241240
domain_separator: Eip712Domain,
242-
) -> Vec<(EIP712SignedMessage<Receipt>, u64)> {
241+
) -> Vec<EIP712SignedMessage<Receipt>> {
243242
let (sender_key, _) = keys_sender;
244243
// Create your Receipt here
245244
generate_requests(
@@ -249,7 +248,6 @@ fn requests_2(
249248
allocation_ids[1],
250249
&domain_separator,
251250
)
252-
.unwrap()
253251
}
254252

255253
#[fixture]
@@ -260,7 +258,7 @@ fn repeated_timestamp_request(
260258
domain_separator: Eip712Domain,
261259
num_batches: u64,
262260
receipt_threshold_1: u64,
263-
) -> Result<Vec<(EIP712SignedMessage<Receipt>, u64)>> {
261+
) -> Vec<EIP712SignedMessage<Receipt>> {
264262
let (sender_key, _) = keys_sender;
265263

266264
// Create signed receipts
@@ -270,14 +268,13 @@ fn repeated_timestamp_request(
270268
&sender_key,
271269
allocation_ids[0],
272270
&domain_separator,
273-
)?;
271+
);
274272

275273
// Create a new receipt with the timestamp equal to the latest receipt in the first RAV request batch
276274
let repeat_timestamp = requests[receipt_threshold_1 as usize - 1]
277-
.0
278275
.message
279276
.timestamp_ns;
280-
let target_receipt = &requests[receipt_threshold_1 as usize].0.message;
277+
let target_receipt = &requests[receipt_threshold_1 as usize].message;
281278
let repeat_receipt = Receipt {
282279
allocation_id: target_receipt.allocation_id,
283280
timestamp_ns: repeat_timestamp,
@@ -286,9 +283,9 @@ fn repeated_timestamp_request(
286283
};
287284

288285
// Sign the new receipt and insert it in the second batch
289-
requests[receipt_threshold_1 as usize].0 =
290-
EIP712SignedMessage::new(&domain_separator, repeat_receipt, &sender_key)?;
291-
Ok(requests)
286+
requests[receipt_threshold_1 as usize] =
287+
EIP712SignedMessage::new(&domain_separator, repeat_receipt, &sender_key).unwrap();
288+
requests
292289
}
293290

294291
#[fixture]
@@ -299,7 +296,7 @@ fn repeated_timestamp_incremented_by_one_request(
299296
domain_separator: Eip712Domain,
300297
num_batches: u64,
301298
receipt_threshold_1: u64,
302-
) -> Result<Vec<(EIP712SignedMessage<Receipt>, u64)>> {
299+
) -> Vec<EIP712SignedMessage<Receipt>> {
303300
let (sender_key, _) = keys_sender;
304301
// Create your Receipt here
305302
let mut requests = generate_requests(
@@ -308,15 +305,14 @@ fn repeated_timestamp_incremented_by_one_request(
308305
&sender_key,
309306
allocation_ids[0],
310307
&domain_separator,
311-
)?;
308+
);
312309

313310
// Create a new receipt with the timestamp equal to the latest receipt timestamp+1 in the first RAV request batch
314311
let repeat_timestamp = requests[receipt_threshold_1 as usize - 1]
315-
.0
316312
.message
317313
.timestamp_ns
318314
+ 1;
319-
let target_receipt = &requests[receipt_threshold_1 as usize].0.message;
315+
let target_receipt = &requests[receipt_threshold_1 as usize].message;
320316
let repeat_receipt = Receipt {
321317
allocation_id: target_receipt.allocation_id,
322318
timestamp_ns: repeat_timestamp,
@@ -325,9 +321,10 @@ fn repeated_timestamp_incremented_by_one_request(
325321
};
326322

327323
// Sign the new receipt and insert it in the second batch
328-
requests[receipt_threshold_1 as usize].0 =
329-
EIP712SignedMessage::new(&domain_separator, repeat_receipt, &sender_key)?;
330-
Ok(requests)
324+
requests[receipt_threshold_1 as usize] =
325+
EIP712SignedMessage::new(&domain_separator, repeat_receipt, &sender_key).unwrap();
326+
327+
requests
331328
}
332329

333330
#[fixture]
@@ -337,18 +334,17 @@ fn wrong_requests(
337334
num_batches: u64,
338335
allocation_ids: Vec<Address>,
339336
domain_separator: Eip712Domain,
340-
) -> Result<Vec<(EIP712SignedMessage<Receipt>, u64)>> {
337+
) -> Vec<EIP712SignedMessage<Receipt>> {
341338
let (sender_key, _) = wrong_keys_sender;
342339
// Create your Receipt here
343340
// Create your Receipt here
344-
let requests = generate_requests(
341+
generate_requests(
345342
query_price,
346343
num_batches,
347344
&sender_key,
348345
allocation_ids[0],
349346
&domain_separator,
350-
)?;
351-
Ok(requests)
347+
)
352348
}
353349

354350
// Helper fixtures to start servers for tests
@@ -511,15 +507,15 @@ async fn test_manager_one_indexer(
511507
(ServerHandle, SocketAddr, ServerHandle, SocketAddr),
512508
Error,
513509
>,
514-
requests_1: Vec<(EIP712SignedMessage<Receipt>, u64)>,
510+
requests_1: Vec<EIP712SignedMessage<Receipt>>,
515511
) -> Result<(), Box<dyn std::error::Error>> {
516512
let (_server_handle, socket_addr, _sender_handle, _sender_addr) =
517513
single_indexer_test_server.await?;
518514
let indexer_1_address = "http://".to_string() + &socket_addr.to_string();
519515
let client_1 = HttpClientBuilder::default().build(indexer_1_address)?;
520516

521-
for (receipt_1, id) in requests_1 {
522-
let result = client_1.request("request", (id, receipt_1)).await;
517+
for receipt_1 in requests_1 {
518+
let result = client_1.request("request", (receipt_1,)).await;
523519

524520
match result {
525521
Ok(()) => {}
@@ -544,8 +540,8 @@ async fn test_manager_two_indexers(
544540
),
545541
Error,
546542
>,
547-
requests_1: Vec<(EIP712SignedMessage<Receipt>, u64)>,
548-
requests_2: Vec<(EIP712SignedMessage<Receipt>, u64)>,
543+
requests_1: Vec<EIP712SignedMessage<Receipt>>,
544+
requests_2: Vec<EIP712SignedMessage<Receipt>>,
549545
) -> Result<()> {
550546
let (
551547
_server_handle_1,
@@ -561,9 +557,9 @@ async fn test_manager_two_indexers(
561557
let client_1 = HttpClientBuilder::default().build(indexer_1_address)?;
562558
let client_2 = HttpClientBuilder::default().build(indexer_2_address)?;
563559

564-
for ((receipt_1, id_1), (receipt_2, id_2)) in requests_1.iter().zip(requests_2) {
565-
let future_1 = client_1.request("request", (id_1, receipt_1));
566-
let future_2 = client_2.request("request", (id_2, receipt_2));
560+
for (receipt_1, receipt_2) in requests_1.iter().zip(requests_2) {
561+
let future_1 = client_1.request("request", (receipt_1,));
562+
let future_2 = client_2.request("request", (receipt_2,));
567563
match tokio::try_join!(future_1, future_2) {
568564
Ok(((), ())) => {}
569565
Err(e) => panic!("Error making receipt request: {:?}", e),
@@ -579,7 +575,7 @@ async fn test_manager_wrong_aggregator_keys(
579575
(ServerHandle, SocketAddr, ServerHandle, SocketAddr),
580576
Error,
581577
>,
582-
requests_1: Vec<(EIP712SignedMessage<Receipt>, u64)>,
578+
requests_1: Vec<EIP712SignedMessage<Receipt>>,
583579
receipt_threshold_1: u64,
584580
) -> Result<()> {
585581
let (_server_handle, socket_addr, _sender_handle, _sender_addr) =
@@ -588,9 +584,9 @@ async fn test_manager_wrong_aggregator_keys(
588584
let client_1 = HttpClientBuilder::default().build(indexer_1_address)?;
589585

590586
let mut counter = 1;
591-
for (receipt_1, id) in requests_1 {
587+
for receipt_1 in requests_1 {
592588
let result: Result<(), jsonrpsee::core::Error> =
593-
client_1.request("request", (id, receipt_1)).await;
589+
client_1.request("request", (receipt_1,)).await;
594590
// The rav request is being made with messages that have been signed with a key that differs from the sender aggregator's.
595591
// So the Sender Aggregator should send an error to the requesting Indexer.
596592
// And so the Indexer should then return an error to the clinet when a rav request is made.
@@ -621,17 +617,16 @@ async fn test_manager_wrong_requestor_keys(
621617
(ServerHandle, SocketAddr, ServerHandle, SocketAddr),
622618
Error,
623619
>,
624-
wrong_requests: Result<Vec<(EIP712SignedMessage<Receipt>, u64)>>,
620+
wrong_requests: Vec<EIP712SignedMessage<Receipt>>,
625621
) -> Result<()> {
626622
let (_server_handle, socket_addr, _sender_handle, _sender_addr) =
627623
single_indexer_test_server.await?;
628624
let indexer_1_address = "http://".to_string() + &socket_addr.to_string();
629625
let client_1 = HttpClientBuilder::default().build(indexer_1_address)?;
630-
let requests = wrong_requests?;
631626

632-
for (receipt_1, id) in requests {
627+
for receipt_1 in wrong_requests {
633628
let result: Result<(), jsonrpsee::core::Error> =
634-
client_1.request("request", (id, receipt_1)).await;
629+
client_1.request("request", (receipt_1,)).await;
635630
// The receipts have been signed with a key that the Indexer is not expecting.
636631
// This is one of the initial tests, so it should fail to receive the receipt
637632
assert!(result.is_err(), "Should have failed signature verification");
@@ -654,8 +649,8 @@ async fn test_tap_manager_rav_timestamp_cuttoff(
654649
),
655650
Error,
656651
>,
657-
repeated_timestamp_request: Result<Vec<(EIP712SignedMessage<Receipt>, u64)>>,
658-
repeated_timestamp_incremented_by_one_request: Result<Vec<(EIP712SignedMessage<Receipt>, u64)>>,
652+
repeated_timestamp_request: Vec<EIP712SignedMessage<Receipt>>,
653+
repeated_timestamp_incremented_by_one_request: Vec<EIP712SignedMessage<Receipt>>,
659654
receipt_threshold_1: u64,
660655
) -> Result<(), Box<dyn std::error::Error>> {
661656
// This test checks that tap_core is correctly filtering receipts by timestamp.
@@ -672,12 +667,11 @@ async fn test_tap_manager_rav_timestamp_cuttoff(
672667
let indexer_2_address = "http://".to_string() + &socket_addr_2.to_string();
673668
let client_1 = HttpClientBuilder::default().build(indexer_1_address)?;
674669
let client_2 = HttpClientBuilder::default().build(indexer_2_address)?;
675-
let requests = repeated_timestamp_request?;
676670

677671
let mut counter = 1;
678-
for (receipt_1, id) in requests {
672+
for receipt_1 in repeated_timestamp_request {
679673
let result: Result<(), jsonrpsee::core::Error> =
680-
client_1.request("request", (id, receipt_1)).await;
674+
client_1.request("request", (receipt_1,)).await;
681675

682676
// The first receipt in the second batch has the same timestamp as the last receipt in the first batch.
683677
// TAP manager should ignore this receipt when creating the second RAV request.
@@ -699,9 +693,8 @@ async fn test_tap_manager_rav_timestamp_cuttoff(
699693

700694
// Here the timestamp first receipt in the second batch is equal to timestamp + 1 of the last receipt in the first batch.
701695
// No errors are expected.
702-
let requests = repeated_timestamp_incremented_by_one_request?;
703-
for (receipt_1, id) in requests {
704-
let result = client_2.request("request", (id, receipt_1)).await;
696+
for receipt_1 in repeated_timestamp_incremented_by_one_request {
697+
let result = client_2.request("request", (receipt_1,)).await;
705698
match result {
706699
Ok(()) => {}
707700
Err(e) => panic!("Error making receipt request: {:?}", e),
@@ -718,8 +711,8 @@ async fn test_tap_aggregator_rav_timestamp_cuttoff(
718711
http_request_size_limit: u32,
719712
http_response_size_limit: u32,
720713
http_max_concurrent_connections: u32,
721-
repeated_timestamp_request: Result<Vec<(EIP712SignedMessage<Receipt>, u64)>>,
722-
repeated_timestamp_incremented_by_one_request: Result<Vec<(EIP712SignedMessage<Receipt>, u64)>>,
714+
repeated_timestamp_request: Vec<EIP712SignedMessage<Receipt>>,
715+
repeated_timestamp_incremented_by_one_request: Vec<EIP712SignedMessage<Receipt>>,
723716
receipt_threshold_1: u64,
724717
) -> Result<(), Box<dyn std::error::Error>> {
725718
// This test checks that tap_aggregator is correctly rejecting receipts with invalid timestamps
@@ -737,25 +730,17 @@ async fn test_tap_aggregator_rav_timestamp_cuttoff(
737730
// The second batch has one receipt with the same timestamp as the latest receipt in the first batch.
738731
// The first RAV will have the same timestamp as one receipt in the second batch.
739732
// tap_aggregator should reject the second RAV request due to the repeated timestamp.
740-
let requests = repeated_timestamp_request?;
733+
let requests = repeated_timestamp_request;
741734
let first_batch = &requests[0..receipt_threshold_1 as usize];
742735
let second_batch = &requests[receipt_threshold_1 as usize..2 * receipt_threshold_1 as usize];
743736

744-
let receipts = first_batch
745-
.iter()
746-
.map(|(r, _)| r.clone())
747-
.collect::<Vec<_>>();
748-
let params = rpc_params!(&aggregate_server_api_version(), &receipts, None::<()>);
737+
let params = rpc_params!(&aggregate_server_api_version(), &first_batch, None::<()>);
749738
let first_rav_response: jsonrpsee_helpers::JsonRpcResponse<SignedRAV> =
750739
client.request("aggregate_receipts", params).await?;
751740

752-
let receipts = second_batch
753-
.iter()
754-
.map(|(r, _)| r.clone())
755-
.collect::<Vec<_>>();
756741
let params = rpc_params!(
757742
&aggregate_server_api_version(),
758-
&receipts,
743+
&second_batch,
759744
first_rav_response.data
760745
);
761746
let second_rav_response: Result<
@@ -770,33 +755,25 @@ async fn test_tap_aggregator_rav_timestamp_cuttoff(
770755
// This is the second part of the test, two batches of receipts are sent to the aggregator.
771756
// The second batch has one receipt with the timestamp = timestamp+1 of the latest receipt in the first batch.
772757
// tap_aggregator should accept the second RAV request.
773-
let requests = repeated_timestamp_incremented_by_one_request?;
758+
let requests = repeated_timestamp_incremented_by_one_request;
774759
let first_batch = &requests[0..receipt_threshold_1 as usize];
775760
let second_batch = &requests[receipt_threshold_1 as usize..2 * receipt_threshold_1 as usize];
776761

777-
let receipts = first_batch
778-
.iter()
779-
.map(|(r, _)| r.clone())
780-
.collect::<Vec<_>>();
781-
let params = rpc_params!(&aggregate_server_api_version(), &receipts, None::<()>);
762+
let params = rpc_params!(&aggregate_server_api_version(), &first_batch, None::<()>);
782763
let first_rav_response: jsonrpsee_helpers::JsonRpcResponse<SignedRAV> =
783764
client.request("aggregate_receipts", params).await?;
784765

785-
let receipts = second_batch
786-
.iter()
787-
.map(|(r, _)| r.clone())
788-
.collect::<Vec<_>>();
789766
let params = rpc_params!(
790767
&aggregate_server_api_version(),
791-
&receipts,
768+
&second_batch,
792769
first_rav_response.data
793770
);
794771
let second_rav_response: jsonrpsee_helpers::JsonRpcResponse<SignedRAV> =
795772
client.request("aggregate_receipts", params).await?;
796773

797774
// Compute the expected aggregate value and check that it matches the latest RAV.
798775
let mut expected_value = 0;
799-
for (receipt, _) in first_batch.iter().chain(second_batch.iter()) {
776+
for receipt in first_batch.iter().chain(second_batch.iter()) {
800777
expected_value += receipt.message.value;
801778
}
802779
assert!(expected_value == second_rav_response.data.message.valueAggregate);
@@ -811,26 +788,23 @@ fn generate_requests(
811788
sender_key: &LocalWallet,
812789
allocation_id: Address,
813790
domain_separator: &Eip712Domain,
814-
) -> Result<Vec<(EIP712SignedMessage<Receipt>, u64)>> {
815-
let mut requests: Vec<(EIP712SignedMessage<Receipt>, u64)> = Vec::new();
791+
) -> Vec<EIP712SignedMessage<Receipt>> {
792+
let mut requests: Vec<EIP712SignedMessage<Receipt>> = Vec::new();
816793

817-
let mut counter = 0;
818794
for _ in 0..num_batches {
819795
for value in query_price {
820-
requests.push((
796+
requests.push(
821797
EIP712SignedMessage::new(
822798
domain_separator,
823-
Receipt::new(allocation_id, *value)?,
799+
Receipt::new(allocation_id, *value).unwrap(),
824800
sender_key,
825-
)?,
826-
counter,
827-
));
828-
counter += 1;
801+
)
802+
.unwrap(),
803+
);
829804
}
830-
counter = 0;
831805
}
832806

833-
Ok(requests)
807+
requests
834808
}
835809

836810
// Start-up a mock Indexer. Requires a Sender Aggregator to be running.

0 commit comments

Comments
 (0)