diff --git a/zingo-testutils/src/assertions.rs b/zingo-testutils/src/assertions.rs index e090b31892..5d0222e174 100644 --- a/zingo-testutils/src/assertions.rs +++ b/zingo-testutils/src/assertions.rs @@ -9,7 +9,7 @@ use zingolib::{lightclient::LightClient, wallet::notes::query::OutputQuery}; /// currently only checks if the fee matches /// this currently fails for any broadcast but not confirmed transaction: it seems like get_transaction_fee does not recognize pending spends /// returns the total fee for the transfer -pub async fn assert_send_outputs_match_sender( +pub async fn get_proposal_vs_records_matched_total_fee( client: &LightClient, proposal: &Proposal, txids: &NonEmpty, @@ -37,11 +37,11 @@ pub async fn assert_send_outputs_match_sender( } /// currently only checks if the received total matches -pub async fn assert_send_outputs_match_recipient( +pub async fn get_proposal_vs_records_matched_total_output_value( client: &LightClient, proposal: &Proposal, txids: &NonEmpty, -) { +) -> u64 { let records = &client .wallet .transaction_context @@ -51,12 +51,16 @@ pub async fn assert_send_outputs_match_recipient( .transaction_records_by_id; assert_eq!(proposal.steps().len(), txids.len()); + let mut total_output = 0; for (i, step) in proposal.steps().iter().enumerate() { let record = records.get(&txids[i]).expect("sender must recognize txid"); + let recorded_output = record.query_sum_value(OutputQuery::any()); assert_eq!( - record.query_sum_value(OutputQuery::any()), + recorded_output, step.transaction_request().total().unwrap().into_u64() ); + total_output = total_output + recorded_output; } + total_output } diff --git a/zingo-testutils/src/lightclient/with_assertions.rs b/zingo-testutils/src/lightclient/with_assertions.rs index 11bdd895e2..7208d295cb 100644 --- a/zingo-testutils/src/lightclient/with_assertions.rs +++ b/zingo-testutils/src/lightclient/with_assertions.rs @@ -4,7 +4,8 @@ use zcash_client_backend::PoolType; use zingolib::lightclient::LightClient; use crate::{ - assertions::{assert_send_outputs_match_recipient, assert_send_outputs_match_sender}, + assertions::get_proposal_vs_records_matched_total_fee, + assertions::get_proposal_vs_records_matched_total_output_value, chain_generic_tests::conduct_chain::ConductChain, lightclient::{from_inputs, get_base_address}, }; @@ -29,10 +30,10 @@ where environment.bump_chain().await; - assert_send_outputs_match_sender(client, &proposal, &txids).await; + get_proposal_vs_records_matched_total_fee(client, &proposal, &txids).await; client.do_sync(false).await.unwrap(); - assert_send_outputs_match_sender(client, &proposal, &txids).await + get_proposal_vs_records_matched_total_fee(client, &proposal, &txids).await } /// this version assumes a single recipient and measures that the recipient also recieved the expected balances @@ -70,11 +71,11 @@ where environment.bump_chain().await; recipient.do_sync(false).await.unwrap(); - assert_send_outputs_match_recipient(recipient, &proposal, &txids).await; + get_proposal_vs_records_matched_total_output_value(recipient, &proposal, &txids).await; - assert_send_outputs_match_sender(sender, &proposal, &txids).await; + get_proposal_vs_records_matched_total_fee(sender, &proposal, &txids).await; sender.do_sync(false).await.unwrap(); - assert_send_outputs_match_sender(sender, &proposal, &txids).await + get_proposal_vs_records_matched_total_fee(sender, &proposal, &txids).await } /// a test-only generic version of shield that includes assertions that the proposal was fulfilled @@ -93,8 +94,8 @@ where environment.bump_chain().await; - assert_send_outputs_match_sender(client, &proposal, &txids).await; + get_proposal_vs_records_matched_total_fee(client, &proposal, &txids).await; client.do_sync(false).await.unwrap(); - assert_send_outputs_match_sender(client, &proposal, &txids).await + get_proposal_vs_records_matched_total_fee(client, &proposal, &txids).await }