Skip to content

Commit

Permalink
test: remove unused parameters from showcase
Browse files Browse the repository at this point in the history
Signed-off-by: Gustavo Inacio <[email protected]>
  • Loading branch information
gusinacio committed Mar 8, 2024
1 parent 78beec1 commit e5dfb0f
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 83 deletions.
2 changes: 0 additions & 2 deletions tap_integration_tests/tests/indexer_mock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down
136 changes: 55 additions & 81 deletions tap_integration_tests/tests/showcase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ fn requests_1(
num_batches: u64,
allocation_ids: Vec<Address>,
domain_separator: Eip712Domain,
) -> Vec<(EIP712SignedMessage<Receipt>, u64)> {
) -> Vec<EIP712SignedMessage<Receipt>> {
let (sender_key, _) = keys_sender;
// Create your Receipt here
generate_requests(
Expand All @@ -229,7 +229,6 @@ fn requests_1(
allocation_ids[0],
&domain_separator,
)
.unwrap()
}

#[fixture]
Expand All @@ -239,7 +238,7 @@ fn requests_2(
num_batches: u64,
allocation_ids: Vec<Address>,
domain_separator: Eip712Domain,
) -> Vec<(EIP712SignedMessage<Receipt>, u64)> {
) -> Vec<EIP712SignedMessage<Receipt>> {
let (sender_key, _) = keys_sender;
// Create your Receipt here
generate_requests(
Expand All @@ -249,7 +248,6 @@ fn requests_2(
allocation_ids[1],
&domain_separator,
)
.unwrap()
}

#[fixture]
Expand All @@ -260,7 +258,7 @@ fn repeated_timestamp_request(
domain_separator: Eip712Domain,
num_batches: u64,
receipt_threshold_1: u64,
) -> Result<Vec<(EIP712SignedMessage<Receipt>, u64)>> {
) -> Vec<EIP712SignedMessage<Receipt>> {
let (sender_key, _) = keys_sender;

// Create signed receipts
Expand All @@ -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,
Expand All @@ -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]
Expand All @@ -299,7 +296,7 @@ fn repeated_timestamp_incremented_by_one_request(
domain_separator: Eip712Domain,
num_batches: u64,
receipt_threshold_1: u64,
) -> Result<Vec<(EIP712SignedMessage<Receipt>, u64)>> {
) -> Vec<EIP712SignedMessage<Receipt>> {
let (sender_key, _) = keys_sender;
// Create your Receipt here
let mut requests = generate_requests(
Expand All @@ -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,
Expand All @@ -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]
Expand All @@ -337,18 +334,17 @@ fn wrong_requests(
num_batches: u64,
allocation_ids: Vec<Address>,
domain_separator: Eip712Domain,
) -> Result<Vec<(EIP712SignedMessage<Receipt>, u64)>> {
) -> Vec<EIP712SignedMessage<Receipt>> {
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
Expand Down Expand Up @@ -511,15 +507,15 @@ async fn test_manager_one_indexer(
(ServerHandle, SocketAddr, ServerHandle, SocketAddr),
Error,
>,
requests_1: Vec<(EIP712SignedMessage<Receipt>, u64)>,
requests_1: Vec<EIP712SignedMessage<Receipt>>,
) -> Result<(), Box<dyn std::error::Error>> {
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(()) => {}
Expand All @@ -544,8 +540,8 @@ async fn test_manager_two_indexers(
),
Error,
>,
requests_1: Vec<(EIP712SignedMessage<Receipt>, u64)>,
requests_2: Vec<(EIP712SignedMessage<Receipt>, u64)>,
requests_1: Vec<EIP712SignedMessage<Receipt>>,
requests_2: Vec<EIP712SignedMessage<Receipt>>,
) -> Result<()> {
let (
_server_handle_1,
Expand All @@ -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),
Expand All @@ -579,7 +575,7 @@ async fn test_manager_wrong_aggregator_keys(
(ServerHandle, SocketAddr, ServerHandle, SocketAddr),
Error,
>,
requests_1: Vec<(EIP712SignedMessage<Receipt>, u64)>,
requests_1: Vec<EIP712SignedMessage<Receipt>>,
receipt_threshold_1: u64,
) -> Result<()> {
let (_server_handle, socket_addr, _sender_handle, _sender_addr) =
Expand All @@ -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.
Expand Down Expand Up @@ -621,17 +617,16 @@ async fn test_manager_wrong_requestor_keys(
(ServerHandle, SocketAddr, ServerHandle, SocketAddr),
Error,
>,
wrong_requests: Result<Vec<(EIP712SignedMessage<Receipt>, u64)>>,
wrong_requests: Vec<EIP712SignedMessage<Receipt>>,
) -> 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");
Expand All @@ -654,8 +649,8 @@ async fn test_tap_manager_rav_timestamp_cuttoff(
),
Error,
>,
repeated_timestamp_request: Result<Vec<(EIP712SignedMessage<Receipt>, u64)>>,
repeated_timestamp_incremented_by_one_request: Result<Vec<(EIP712SignedMessage<Receipt>, u64)>>,
repeated_timestamp_request: Vec<EIP712SignedMessage<Receipt>>,
repeated_timestamp_incremented_by_one_request: Vec<EIP712SignedMessage<Receipt>>,
receipt_threshold_1: u64,
) -> Result<(), Box<dyn std::error::Error>> {
// This test checks that tap_core is correctly filtering receipts by timestamp.
Expand All @@ -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.
Expand All @@ -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),
Expand All @@ -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<Vec<(EIP712SignedMessage<Receipt>, u64)>>,
repeated_timestamp_incremented_by_one_request: Result<Vec<(EIP712SignedMessage<Receipt>, u64)>>,
repeated_timestamp_request: Vec<EIP712SignedMessage<Receipt>>,
repeated_timestamp_incremented_by_one_request: Vec<EIP712SignedMessage<Receipt>>,
receipt_threshold_1: u64,
) -> Result<(), Box<dyn std::error::Error>> {
// This test checks that tap_aggregator is correctly rejecting receipts with invalid timestamps
Expand All @@ -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::<Vec<_>>();
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<SignedRAV> =
client.request("aggregate_receipts", params).await?;

let receipts = second_batch
.iter()
.map(|(r, _)| r.clone())
.collect::<Vec<_>>();
let params = rpc_params!(
&aggregate_server_api_version(),
&receipts,
&second_batch,
first_rav_response.data
);
let second_rav_response: Result<
Expand All @@ -770,33 +755,25 @@ 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::<Vec<_>>();
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<SignedRAV> =
client.request("aggregate_receipts", params).await?;

let receipts = second_batch
.iter()
.map(|(r, _)| r.clone())
.collect::<Vec<_>>();
let params = rpc_params!(
&aggregate_server_api_version(),
&receipts,
&second_batch,
first_rav_response.data
);
let second_rav_response: jsonrpsee_helpers::JsonRpcResponse<SignedRAV> =
client.request("aggregate_receipts", params).await?;

// 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);
Expand All @@ -811,26 +788,23 @@ fn generate_requests(
sender_key: &LocalWallet,
allocation_id: Address,
domain_separator: &Eip712Domain,
) -> Result<Vec<(EIP712SignedMessage<Receipt>, u64)>> {
let mut requests: Vec<(EIP712SignedMessage<Receipt>, u64)> = Vec::new();
) -> Vec<EIP712SignedMessage<Receipt>> {
let mut requests: Vec<EIP712SignedMessage<Receipt>> = 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.
Expand Down

0 comments on commit e5dfb0f

Please sign in to comment.