Skip to content

Commit

Permalink
test: update tests to fail on initial checks
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 637c24c commit 0477ca9
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 42 deletions.
7 changes: 2 additions & 5 deletions tap_core/src/adapters/escrow_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ pub trait EscrowAdapter {
sender_id: Address,
value: u128,
) -> Result<(), Self::AdapterError>;

async fn verify_signer(
&self,
signer_address: Address
) -> Result<bool, Self::AdapterError>;

async fn verify_signer(&self, signer_address: Address) -> Result<bool, Self::AdapterError>;
}
1 change: 0 additions & 1 deletion tap_core/src/checks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ pub mod mock {
.map_err(|e| ReceiptError::InvalidSignature {
source_error_message: e.to_string(),
})?;
println!("{:?}, {:?}", self.valid_signers, recovered_address);
if !self.valid_signers.contains(&recovered_address) {
Err(ReceiptError::InvalidSignature {
source_error_message: "Invalid signer".to_string(),
Expand Down
3 changes: 1 addition & 2 deletions tap_core/src/tap_manager/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,7 @@ where

// perform checks
if let ReceivedReceipt::Checking(received_receipt) = &mut received_receipt {
// received_receipt.perform_checks(&self.checks).await?;
received_receipt.perform_checks(&[]).await?;
received_receipt.perform_checks(&self.checks).await?;
}

// store the receipt
Expand Down
1 change: 0 additions & 1 deletion tap_core/src/tap_manager/test/manager_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ async fn manager_create_rav_request_all_valid_receipts(
.is_ok());
}
let rav_request_result = manager.create_rav_request(0, None).await;
println!("{:?}", rav_request_result);
assert!(rav_request_result.is_ok());

let rav_request = rav_request_result.unwrap();
Expand Down
49 changes: 16 additions & 33 deletions tap_integration_tests/tests/showcase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,17 +219,17 @@ fn requests_1(
num_batches: u64,
allocation_ids: Vec<Address>,
domain_separator: Eip712Domain,
) -> Result<Vec<(EIP712SignedMessage<Receipt>, u64)>> {
) -> Vec<(EIP712SignedMessage<Receipt>, u64)> {
let (sender_key, _) = keys_sender;
// Create your Receipt here
let requests = generate_requests(
generate_requests(
query_price,
num_batches,
&sender_key,
allocation_ids[0],
&domain_separator,
)?;
Ok(requests)
)
.unwrap()
}

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

#[fixture]
Expand Down Expand Up @@ -511,15 +511,14 @@ async fn test_manager_one_indexer(
(ServerHandle, SocketAddr, ServerHandle, SocketAddr),
Error,
>,
requests_1: Result<Vec<(EIP712SignedMessage<Receipt>, u64)>>,
requests_1: Vec<(EIP712SignedMessage<Receipt>, u64)>,
) -> 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)?;
let requests = requests_1?;

for (receipt_1, id) in requests {
for (receipt_1, id) in requests_1 {
let result = client_1.request("request", (id, receipt_1)).await;

match result {
Expand All @@ -545,8 +544,8 @@ async fn test_manager_two_indexers(
),
Error,
>,
requests_1: Result<Vec<(EIP712SignedMessage<Receipt>, u64)>>,
requests_2: Result<Vec<(EIP712SignedMessage<Receipt>, u64)>>,
requests_1: Vec<(EIP712SignedMessage<Receipt>, u64)>,
requests_2: Vec<(EIP712SignedMessage<Receipt>, u64)>,
) -> Result<()> {
let (
_server_handle_1,
Expand All @@ -561,8 +560,6 @@ async fn test_manager_two_indexers(
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_1 = requests_1?;
let requests_2 = requests_2?;

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));
Expand All @@ -582,17 +579,16 @@ async fn test_manager_wrong_aggregator_keys(
(ServerHandle, SocketAddr, ServerHandle, SocketAddr),
Error,
>,
requests_1: Result<Vec<(EIP712SignedMessage<Receipt>, u64)>>,
requests_1: Vec<(EIP712SignedMessage<Receipt>, u64)>,
receipt_threshold_1: u64,
) -> Result<()> {
let (_server_handle, socket_addr, _sender_handle, _sender_addr) =
single_indexer_wrong_sender_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 = requests_1?;

let mut counter = 1;
for (receipt_1, id) in requests {
for (receipt_1, id) in requests_1 {
let result: Result<(), jsonrpsee::core::Error> =
client_1.request("request", (id, 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.
Expand Down Expand Up @@ -626,32 +622,19 @@ async fn test_manager_wrong_requestor_keys(
Error,
>,
wrong_requests: Result<Vec<(EIP712SignedMessage<Receipt>, u64)>>,
receipt_threshold_1: u64,
) -> 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?;

let mut counter = 1;
for (receipt_1, id) in requests {
let result: Result<(), jsonrpsee::core::Error> =
client_1.request("request", (id, receipt_1)).await;
// The receipts have been signed with a key that the Indexer is not expecting.
// So the Indexer should return an error when a rav request is made, because they will not have any valid receipts for the request.
// A rav request is made when the number of receipts sent = receipt_threshold_1.
// result should be an error when counter = multiple of receipt_threshold_1 and Ok otherwise.
if (counter % receipt_threshold_1) == 0 {
assert!(result.is_err(), "Should have failed signature verification");
} else {
assert!(
result.is_ok(),
"Error making receipt request: {:?}",
result.unwrap_err()
);
}
counter += 1;
// This is one of the initial tests, so it should fail to receive the receipt
assert!(result.is_err(), "Should have failed signature verification");
}

Ok(())
Expand Down

0 comments on commit 0477ca9

Please sign in to comment.