From e5dfb0fd72354c8fda6f8f45e9ac52c9b3a1c6f3 Mon Sep 17 00:00:00 2001 From: Gustavo Inacio Date: Fri, 8 Mar 2024 13:25:16 -0300 Subject: [PATCH] test: remove unused parameters from showcase Signed-off-by: Gustavo Inacio --- .../tests/indexer_mock/mod.rs | 2 - tap_integration_tests/tests/showcase.rs | 136 +++++++----------- 2 files changed, 55 insertions(+), 83 deletions(-) diff --git a/tap_integration_tests/tests/indexer_mock/mod.rs b/tap_integration_tests/tests/indexer_mock/mod.rs index 81cc28f6..221c0798 100644 --- a/tap_integration_tests/tests/indexer_mock/mod.rs +++ b/tap_integration_tests/tests/indexer_mock/mod.rs @@ -33,7 +33,6 @@ pub trait Rpc { #[method(name = "request")] async fn request( &self, - request_id: u64, // Unique identifier for the request receipt: SignedReceipt, // Signed receipt associated with the request ) -> Result<(), jsonrpsee::types::ErrorObjectOwned>; // The result of the request, a JSON-RPC error if it fails } @@ -90,7 +89,6 @@ where { async fn request( &self, - _request_id: u64, receipt: SignedReceipt, ) -> Result<(), jsonrpsee::types::ErrorObjectOwned> { let verify_result = match self.manager.verify_and_store_receipt(receipt).await { diff --git a/tap_integration_tests/tests/showcase.rs b/tap_integration_tests/tests/showcase.rs index 110b1fad..73cba0b0 100644 --- a/tap_integration_tests/tests/showcase.rs +++ b/tap_integration_tests/tests/showcase.rs @@ -219,7 +219,7 @@ fn requests_1( num_batches: u64, allocation_ids: Vec
, domain_separator: Eip712Domain, -) -> Vec<(EIP712SignedMessage, u64)> { +) -> Vec> { let (sender_key, _) = keys_sender; // Create your Receipt here generate_requests( @@ -229,7 +229,6 @@ fn requests_1( allocation_ids[0], &domain_separator, ) - .unwrap() } #[fixture] @@ -239,7 +238,7 @@ fn requests_2( num_batches: u64, allocation_ids: Vec
, domain_separator: Eip712Domain, -) -> Vec<(EIP712SignedMessage, u64)> { +) -> Vec> { let (sender_key, _) = keys_sender; // Create your Receipt here generate_requests( @@ -249,7 +248,6 @@ fn requests_2( allocation_ids[1], &domain_separator, ) - .unwrap() } #[fixture] @@ -260,7 +258,7 @@ fn repeated_timestamp_request( domain_separator: Eip712Domain, num_batches: u64, receipt_threshold_1: u64, -) -> Result, u64)>> { +) -> Vec> { let (sender_key, _) = keys_sender; // Create signed receipts @@ -270,14 +268,13 @@ fn repeated_timestamp_request( &sender_key, allocation_ids[0], &domain_separator, - )?; + ); // Create a new receipt with the timestamp equal to the latest receipt in the first RAV request batch let repeat_timestamp = requests[receipt_threshold_1 as usize - 1] - .0 .message .timestamp_ns; - let target_receipt = &requests[receipt_threshold_1 as usize].0.message; + let target_receipt = &requests[receipt_threshold_1 as usize].message; let repeat_receipt = Receipt { allocation_id: target_receipt.allocation_id, timestamp_ns: repeat_timestamp, @@ -286,9 +283,9 @@ fn repeated_timestamp_request( }; // Sign the new receipt and insert it in the second batch - requests[receipt_threshold_1 as usize].0 = - EIP712SignedMessage::new(&domain_separator, repeat_receipt, &sender_key)?; - Ok(requests) + requests[receipt_threshold_1 as usize] = + EIP712SignedMessage::new(&domain_separator, repeat_receipt, &sender_key).unwrap(); + requests } #[fixture] @@ -299,7 +296,7 @@ fn repeated_timestamp_incremented_by_one_request( domain_separator: Eip712Domain, num_batches: u64, receipt_threshold_1: u64, -) -> Result, u64)>> { +) -> Vec> { let (sender_key, _) = keys_sender; // Create your Receipt here let mut requests = generate_requests( @@ -308,15 +305,14 @@ fn repeated_timestamp_incremented_by_one_request( &sender_key, allocation_ids[0], &domain_separator, - )?; + ); // Create a new receipt with the timestamp equal to the latest receipt timestamp+1 in the first RAV request batch let repeat_timestamp = requests[receipt_threshold_1 as usize - 1] - .0 .message .timestamp_ns + 1; - let target_receipt = &requests[receipt_threshold_1 as usize].0.message; + let target_receipt = &requests[receipt_threshold_1 as usize].message; let repeat_receipt = Receipt { allocation_id: target_receipt.allocation_id, timestamp_ns: repeat_timestamp, @@ -325,9 +321,10 @@ fn repeated_timestamp_incremented_by_one_request( }; // Sign the new receipt and insert it in the second batch - requests[receipt_threshold_1 as usize].0 = - EIP712SignedMessage::new(&domain_separator, repeat_receipt, &sender_key)?; - Ok(requests) + requests[receipt_threshold_1 as usize] = + EIP712SignedMessage::new(&domain_separator, repeat_receipt, &sender_key).unwrap(); + + requests } #[fixture] @@ -337,18 +334,17 @@ fn wrong_requests( num_batches: u64, allocation_ids: Vec
, domain_separator: Eip712Domain, -) -> Result, u64)>> { +) -> Vec> { let (sender_key, _) = wrong_keys_sender; // Create your Receipt here // Create your Receipt here - let requests = generate_requests( + generate_requests( query_price, num_batches, &sender_key, allocation_ids[0], &domain_separator, - )?; - Ok(requests) + ) } // Helper fixtures to start servers for tests @@ -511,15 +507,15 @@ async fn test_manager_one_indexer( (ServerHandle, SocketAddr, ServerHandle, SocketAddr), Error, >, - requests_1: Vec<(EIP712SignedMessage, u64)>, + requests_1: Vec>, ) -> Result<(), Box> { let (_server_handle, socket_addr, _sender_handle, _sender_addr) = single_indexer_test_server.await?; let indexer_1_address = "http://".to_string() + &socket_addr.to_string(); let client_1 = HttpClientBuilder::default().build(indexer_1_address)?; - for (receipt_1, id) in requests_1 { - let result = client_1.request("request", (id, receipt_1)).await; + for receipt_1 in requests_1 { + let result = client_1.request("request", (receipt_1,)).await; match result { Ok(()) => {} @@ -544,8 +540,8 @@ async fn test_manager_two_indexers( ), Error, >, - requests_1: Vec<(EIP712SignedMessage, u64)>, - requests_2: Vec<(EIP712SignedMessage, u64)>, + requests_1: Vec>, + requests_2: Vec>, ) -> Result<()> { let ( _server_handle_1, @@ -561,9 +557,9 @@ async fn test_manager_two_indexers( let client_1 = HttpClientBuilder::default().build(indexer_1_address)?; let client_2 = HttpClientBuilder::default().build(indexer_2_address)?; - for ((receipt_1, id_1), (receipt_2, id_2)) in requests_1.iter().zip(requests_2) { - let future_1 = client_1.request("request", (id_1, receipt_1)); - let future_2 = client_2.request("request", (id_2, receipt_2)); + for (receipt_1, receipt_2) in requests_1.iter().zip(requests_2) { + let future_1 = client_1.request("request", (receipt_1,)); + let future_2 = client_2.request("request", (receipt_2,)); match tokio::try_join!(future_1, future_2) { Ok(((), ())) => {} Err(e) => panic!("Error making receipt request: {:?}", e), @@ -579,7 +575,7 @@ async fn test_manager_wrong_aggregator_keys( (ServerHandle, SocketAddr, ServerHandle, SocketAddr), Error, >, - requests_1: Vec<(EIP712SignedMessage, u64)>, + requests_1: Vec>, receipt_threshold_1: u64, ) -> Result<()> { let (_server_handle, socket_addr, _sender_handle, _sender_addr) = @@ -588,9 +584,9 @@ async fn test_manager_wrong_aggregator_keys( let client_1 = HttpClientBuilder::default().build(indexer_1_address)?; let mut counter = 1; - for (receipt_1, id) in requests_1 { + for receipt_1 in requests_1 { let result: Result<(), jsonrpsee::core::Error> = - client_1.request("request", (id, receipt_1)).await; + client_1.request("request", (receipt_1,)).await; // The rav request is being made with messages that have been signed with a key that differs from the sender aggregator's. // So the Sender Aggregator should send an error to the requesting Indexer. // 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( (ServerHandle, SocketAddr, ServerHandle, SocketAddr), Error, >, - wrong_requests: Result, u64)>>, + wrong_requests: Vec>, ) -> Result<()> { let (_server_handle, socket_addr, _sender_handle, _sender_addr) = single_indexer_test_server.await?; let indexer_1_address = "http://".to_string() + &socket_addr.to_string(); let client_1 = HttpClientBuilder::default().build(indexer_1_address)?; - let requests = wrong_requests?; - for (receipt_1, id) in requests { + for receipt_1 in wrong_requests { let result: Result<(), jsonrpsee::core::Error> = - client_1.request("request", (id, receipt_1)).await; + client_1.request("request", (receipt_1,)).await; // The receipts have been signed with a key that the Indexer is not expecting. // This is one of the initial tests, so it should fail to receive the receipt assert!(result.is_err(), "Should have failed signature verification"); @@ -654,8 +649,8 @@ async fn test_tap_manager_rav_timestamp_cuttoff( ), Error, >, - repeated_timestamp_request: Result, u64)>>, - repeated_timestamp_incremented_by_one_request: Result, u64)>>, + repeated_timestamp_request: Vec>, + repeated_timestamp_incremented_by_one_request: Vec>, receipt_threshold_1: u64, ) -> Result<(), Box> { // This test checks that tap_core is correctly filtering receipts by timestamp. @@ -672,12 +667,11 @@ async fn test_tap_manager_rav_timestamp_cuttoff( let indexer_2_address = "http://".to_string() + &socket_addr_2.to_string(); let client_1 = HttpClientBuilder::default().build(indexer_1_address)?; let client_2 = HttpClientBuilder::default().build(indexer_2_address)?; - let requests = repeated_timestamp_request?; let mut counter = 1; - for (receipt_1, id) in requests { + for receipt_1 in repeated_timestamp_request { let result: Result<(), jsonrpsee::core::Error> = - client_1.request("request", (id, receipt_1)).await; + client_1.request("request", (receipt_1,)).await; // The first receipt in the second batch has the same timestamp as the last receipt in the first batch. // TAP manager should ignore this receipt when creating the second RAV request. @@ -699,9 +693,8 @@ async fn test_tap_manager_rav_timestamp_cuttoff( // Here the timestamp first receipt in the second batch is equal to timestamp + 1 of the last receipt in the first batch. // No errors are expected. - let requests = repeated_timestamp_incremented_by_one_request?; - for (receipt_1, id) in requests { - let result = client_2.request("request", (id, receipt_1)).await; + for receipt_1 in repeated_timestamp_incremented_by_one_request { + let result = client_2.request("request", (receipt_1,)).await; match result { Ok(()) => {} Err(e) => panic!("Error making receipt request: {:?}", e), @@ -718,8 +711,8 @@ async fn test_tap_aggregator_rav_timestamp_cuttoff( http_request_size_limit: u32, http_response_size_limit: u32, http_max_concurrent_connections: u32, - repeated_timestamp_request: Result, u64)>>, - repeated_timestamp_incremented_by_one_request: Result, u64)>>, + repeated_timestamp_request: Vec>, + repeated_timestamp_incremented_by_one_request: Vec>, receipt_threshold_1: u64, ) -> Result<(), Box> { // 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( // The second batch has one receipt with the same timestamp as the latest receipt in the first batch. // The first RAV will have the same timestamp as one receipt in the second batch. // tap_aggregator should reject the second RAV request due to the repeated timestamp. - let requests = repeated_timestamp_request?; + let requests = repeated_timestamp_request; let first_batch = &requests[0..receipt_threshold_1 as usize]; let second_batch = &requests[receipt_threshold_1 as usize..2 * receipt_threshold_1 as usize]; - let receipts = first_batch - .iter() - .map(|(r, _)| r.clone()) - .collect::>(); - let params = rpc_params!(&aggregate_server_api_version(), &receipts, None::<()>); + let params = rpc_params!(&aggregate_server_api_version(), &first_batch, None::<()>); let first_rav_response: jsonrpsee_helpers::JsonRpcResponse = client.request("aggregate_receipts", params).await?; - let receipts = second_batch - .iter() - .map(|(r, _)| r.clone()) - .collect::>(); let params = rpc_params!( &aggregate_server_api_version(), - &receipts, + &second_batch, first_rav_response.data ); let second_rav_response: Result< @@ -770,25 +755,17 @@ async fn test_tap_aggregator_rav_timestamp_cuttoff( // This is the second part of the test, two batches of receipts are sent to the aggregator. // The second batch has one receipt with the timestamp = timestamp+1 of the latest receipt in the first batch. // tap_aggregator should accept the second RAV request. - let requests = repeated_timestamp_incremented_by_one_request?; + let requests = repeated_timestamp_incremented_by_one_request; let first_batch = &requests[0..receipt_threshold_1 as usize]; let second_batch = &requests[receipt_threshold_1 as usize..2 * receipt_threshold_1 as usize]; - let receipts = first_batch - .iter() - .map(|(r, _)| r.clone()) - .collect::>(); - let params = rpc_params!(&aggregate_server_api_version(), &receipts, None::<()>); + let params = rpc_params!(&aggregate_server_api_version(), &first_batch, None::<()>); let first_rav_response: jsonrpsee_helpers::JsonRpcResponse = client.request("aggregate_receipts", params).await?; - let receipts = second_batch - .iter() - .map(|(r, _)| r.clone()) - .collect::>(); let params = rpc_params!( &aggregate_server_api_version(), - &receipts, + &second_batch, first_rav_response.data ); let second_rav_response: jsonrpsee_helpers::JsonRpcResponse = @@ -796,7 +773,7 @@ async fn test_tap_aggregator_rav_timestamp_cuttoff( // Compute the expected aggregate value and check that it matches the latest RAV. let mut expected_value = 0; - for (receipt, _) in first_batch.iter().chain(second_batch.iter()) { + for receipt in first_batch.iter().chain(second_batch.iter()) { expected_value += receipt.message.value; } assert!(expected_value == second_rav_response.data.message.valueAggregate); @@ -811,26 +788,23 @@ fn generate_requests( sender_key: &LocalWallet, allocation_id: Address, domain_separator: &Eip712Domain, -) -> Result, u64)>> { - let mut requests: Vec<(EIP712SignedMessage, u64)> = Vec::new(); +) -> Vec> { + let mut requests: Vec> = Vec::new(); - let mut counter = 0; for _ in 0..num_batches { for value in query_price { - requests.push(( + requests.push( EIP712SignedMessage::new( domain_separator, - Receipt::new(allocation_id, *value)?, + Receipt::new(allocation_id, *value).unwrap(), sender_key, - )?, - counter, - )); - counter += 1; + ) + .unwrap(), + ); } - counter = 0; } - Ok(requests) + requests } // Start-up a mock Indexer. Requires a Sender Aggregator to be running.