Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

propose name change, and add returned u64 to _total_output_value #32

Merged
merged 1 commit into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions zingo-testutils/src/assertions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<NoteId>(
pub async fn get_proposal_vs_records_matched_total_fee<NoteId>(
client: &LightClient,
proposal: &Proposal<zcash_primitives::transaction::fees::zip317::FeeRule, NoteId>,
txids: &NonEmpty<TxId>,
Expand Down Expand Up @@ -37,11 +37,11 @@ pub async fn assert_send_outputs_match_sender<NoteId>(
}

/// currently only checks if the received total matches
pub async fn assert_send_outputs_match_recipient<NoteId>(
pub async fn get_proposal_vs_records_matched_total_output_value<NoteId>(
client: &LightClient,
proposal: &Proposal<zcash_primitives::transaction::fees::zip317::FeeRule, NoteId>,
txids: &NonEmpty<TxId>,
) {
) -> u64 {
let records = &client
.wallet
.transaction_context
Expand All @@ -51,12 +51,16 @@ pub async fn assert_send_outputs_match_recipient<NoteId>(
.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
}
17 changes: 9 additions & 8 deletions zingo-testutils/src/lightclient/with_assertions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Loading