From acf1098e97b8152b5ddcf3f2c738c4fbd572dac2 Mon Sep 17 00:00:00 2001 From: idky137 Date: Mon, 8 Apr 2024 15:32:24 +0100 Subject: [PATCH 01/20] added tx_inputs ans tx_outputs to zingo-testutils --- integration-tests/tests/integrations.rs | 87 ++++++++++++- zingo-testutils/src/lib.rs | 164 ++++++++++++++++++++++++ 2 files changed, 250 insertions(+), 1 deletion(-) diff --git a/integration-tests/tests/integrations.rs b/integration-tests/tests/integrations.rs index 6a6b2e291..cd6f9d2fa 100644 --- a/integration-tests/tests/integrations.rs +++ b/integration-tests/tests/integrations.rs @@ -3598,8 +3598,9 @@ mod slow { } mod basic_transactions { + use json::JsonValue; use zingo_testutils::scenarios; - use zingolib::get_base_address; + use zingolib::{get_base_address, wallet::data::summaries::ValueTransfer}; #[tokio::test] async fn send_and_sync_with_multiple_notes_no_panic() { @@ -3642,6 +3643,90 @@ mod basic_transactions { recipient.do_sync(true).await.unwrap(); faucet.do_sync(true).await.unwrap(); } + + #[tokio::test] + async fn basic_fees() { + let (regtest_manager, _cph, faucet, recipient) = + scenarios::faucet_recipient_default().await; + + let txid1 = faucet + .do_send(vec![( + get_base_address!(recipient, "sapling").as_str(), + 40_000, + None, + )]) + .await + .unwrap(); + + zingo_testutils::generate_n_blocks_return_new_height(®test_manager, 1) + .await + .unwrap(); + + faucet.do_sync(true).await.unwrap(); + recipient.do_sync(true).await.unwrap(); + + println!("Faucet Balance:\n{:#?}\n", faucet.do_balance().await); + println!("Recipient Balance:\n{:#?}\n", recipient.do_balance().await); + + // let faucet_transactions = faucet.do_list_transactions().await; + // let filtered_faucet_transactions: Vec<&JsonValue> = match &faucet_transactions { + // JsonValue::Array(arr) => arr + // .iter() + // .filter(|transaction| transaction["txid"] == txid1) + // .collect(), + // _ => { + // panic!("Failed to filter faucet_transactions!",); + // } + // }; + // println!( + // "Faucet Transactions:\n{:#?}\n", + // filtered_faucet_transactions + // ); + + // let recipient_transactions = recipient.do_list_transactions().await; + // let filtered_recipient_transactions: Vec<&JsonValue> = match &recipient_transactions { + // JsonValue::Array(arr) => arr + // .iter() + // .filter(|transaction| transaction["txid"] == txid1) + // .collect(), + // _ => { + // panic!("Failed to filter recipient_transactions!",); + // } + // }; + // println!( + // "Recipient Transactions\n:{:#?}\n", + // filtered_recipient_transactions + // ); + + // let faucet_notes = faucet.do_list_notes(true).await; + // println!("Faucet Notes:\n{:?}\n", faucet_notes); + + let tx_ins = zingo_testutils::tx_inputs(&faucet, txid1.as_str()).await; + println!("Transaction Inputs\n{:#?}\n", tx_ins); + + // let recipient_notes = recipient.do_list_notes(true).await; + // println!("Recipient Notes\n:{:?}\n", recipient_notes); + + let tx_outs = zingo_testutils::tx_outputs(&recipient, txid1.as_str()).await; + println!("Transaction Outputs\n{:#?}\n", tx_outs); + + // let faucet_summaries = faucet.do_list_txsummaries().await; + // let filtered_faucet_summaries: Vec<&ValueTransfer> = faucet_summaries + // .iter() + // .filter(|summary| summary.txid.to_string() == txid1) + // .collect(); + // println!("Faucet Summaries:\n{:#?}\n", filtered_faucet_summaries); + + // let recipient_summaries = recipient.do_list_txsummaries().await; + // let filtered_recipient_summaries: Vec<&ValueTransfer> = recipient_summaries + // .iter() + // .filter(|summary| summary.txid.to_string() == txid1) + // .collect(); + // println!( + // "Recipient Summaries:\n{:#?}\n", + // filtered_recipient_summaries + // ); + } } #[tokio::test] diff --git a/zingo-testutils/src/lib.rs b/zingo-testutils/src/lib.rs index adfaf8f0c..70c06619d 100644 --- a/zingo-testutils/src/lib.rs +++ b/zingo-testutils/src/lib.rs @@ -243,6 +243,170 @@ pub async fn load_wallet( ) } +/// List all notes held by Lightclient that were created in txid. +pub async fn tx_output_notes(client: &LightClient, txid: String) -> Vec { + let client_notes = client.do_list_notes(true).await; + + let required_txid = txid; + + let mut filtered_notes: Vec = Vec::new(); + + if let JsonValue::Object(obj) = client_notes { + if let Some(JsonValue::Array(unspent_sapling_notes)) = obj.get("unspent_sapling_notes") { + filtered_notes.extend( + unspent_sapling_notes + .iter() + .filter(|note| note["created_in_txid"] == required_txid) + .cloned(), + ); + } + + if let Some(JsonValue::Array(pending_sapling_notes)) = obj.get("pending_sapling_notes") { + filtered_notes.extend( + pending_sapling_notes + .iter() + .filter(|note| note["created_in_txid"] == required_txid) + .cloned(), + ); + } + + if let Some(JsonValue::Array(unspent_orchard_notes)) = obj.get("unspent_orchard_notes") { + filtered_notes.extend( + unspent_orchard_notes + .iter() + .filter(|note| note["created_in_txid"] == required_txid) + .cloned(), + ); + } + + if let Some(JsonValue::Array(pending_orchard_notes)) = obj.get("pending_orchard_notes") { + filtered_notes.extend( + pending_orchard_notes + .iter() + .filter(|note| note["created_in_txid"] == required_txid) + .cloned(), + ); + } + + if let Some(JsonValue::Array(utxos)) = obj.get("utxos") { + filtered_notes.extend( + utxos + .iter() + .filter(|note| note["created_in_txid"] == required_txid) + .cloned(), + ); + } + + if let Some(JsonValue::Array(pending_utxos)) = obj.get("pending_utxos") { + filtered_notes.extend( + pending_utxos + .iter() + .filter(|note| note["created_in_txid"] == required_txid) + .cloned(), + ); + } + + if let Some(JsonValue::Array(spent_sapling_notes)) = obj.get("spent_sapling_notes") { + filtered_notes.extend( + spent_sapling_notes + .iter() + .filter(|note| note["created_in_txid"] == required_txid) + .cloned(), + ); + } + + if let Some(JsonValue::Array(spent_orchard_notes)) = obj.get("spent_orchard_notes") { + filtered_notes.extend( + spent_orchard_notes + .iter() + .filter(|note| note["created_in_txid"] == required_txid) + .cloned(), + ); + } + + if let Some(JsonValue::Array(spent_utxos)) = obj.get("spent_utxos") { + filtered_notes.extend( + spent_utxos + .iter() + .filter(|note| note["created_in_txid"] == required_txid) + .cloned(), + ); + } + } + + filtered_notes +} + +/// Returnes number of notes used as inputs for txid as (transparent_notes, sapling_notes, orchard_notes). +pub async fn tx_inputs(client: &LightClient, txid: &str) -> (usize, usize, usize) { + let notes = client.do_list_notes(true).await; + + let mut transparent_notes = 0; + let mut sapling_notes = 0; + let mut orchard_notes = 0; + + if let JsonValue::Array(spent_utxos) = ¬es["spent_utxos"] { + for utxo in spent_utxos { + if utxo["spent"] == txid || utxo["unconfirmed_spent"] == txid { + transparent_notes += 1; + } + } + } + + if let JsonValue::Array(spent_sapling_notes) = ¬es["spent_sapling_notes"] { + for note in spent_sapling_notes { + if note["spent"] == txid || note["unconfirmed_spent"] == txid { + sapling_notes += 1; + } + } + } + + if let JsonValue::Array(spent_orchard_notes) = ¬es["spent_orchard_notes"] { + for note in spent_orchard_notes { + if note["spent"] == txid || note["unconfirmed_spent"] == txid { + orchard_notes += 1; + } + } + } + + (transparent_notes, sapling_notes, orchard_notes) +} + +/// Returnes number of notes created in txid as (transparent_notes, sapling_notes, orchard_notes). +pub async fn tx_outputs(client: &LightClient, txid: &str) -> (usize, usize, usize) { + let notes = client.do_list_notes(true).await; + + let mut transparent_notes = 0; + let mut sapling_notes = 0; + let mut orchard_notes = 0; + + if let JsonValue::Array(spent_utxos) = ¬es["unspent_utxos"] { + for utxo in spent_utxos { + if utxo["created_in_txid"] == txid { + transparent_notes += 1; + } + } + } + + if let JsonValue::Array(spent_sapling_notes) = ¬es["unspent_sapling_notes"] { + for note in spent_sapling_notes { + if note["created_in_txid"] == txid { + sapling_notes += 1; + } + } + } + + if let JsonValue::Array(spent_orchard_notes) = ¬es["unspent_orchard_notes"] { + for note in spent_orchard_notes { + if note["created_in_txid"] == txid { + orchard_notes += 1; + } + } + } + + (transparent_notes, sapling_notes, orchard_notes) +} + pub mod scenarios { //! In practice there are several common scenarios for which helpers are provided. //! These scenarios vary in the configuration of clients in use. Most scenarios From 8d1c6489c0307e52e125a994bbf5e253e33e63ef Mon Sep 17 00:00:00 2001 From: idky137 Date: Mon, 8 Apr 2024 16:33:43 +0100 Subject: [PATCH 02/20] tx_inputs and tx_outputs now return TxNotes --- integration-tests/tests/integrations.rs | 48 +++++---- zingo-testutils/src/lib.rs | 138 +++++++----------------- 2 files changed, 70 insertions(+), 116 deletions(-) diff --git a/integration-tests/tests/integrations.rs b/integration-tests/tests/integrations.rs index cd6f9d2fa..70f8bf1d0 100644 --- a/integration-tests/tests/integrations.rs +++ b/integration-tests/tests/integrations.rs @@ -3649,14 +3649,16 @@ mod basic_transactions { let (regtest_manager, _cph, faucet, recipient) = scenarios::faucet_recipient_default().await; - let txid1 = faucet - .do_send(vec![( - get_base_address!(recipient, "sapling").as_str(), - 40_000, - None, - )]) - .await - .unwrap(); + for _ in 0..2 { + faucet + .do_send(vec![( + get_base_address!(recipient, "unified").as_str(), + 40_000, + None, + )]) + .await + .unwrap(); + } zingo_testutils::generate_n_blocks_return_new_height(®test_manager, 1) .await @@ -3665,8 +3667,8 @@ mod basic_transactions { faucet.do_sync(true).await.unwrap(); recipient.do_sync(true).await.unwrap(); - println!("Faucet Balance:\n{:#?}\n", faucet.do_balance().await); - println!("Recipient Balance:\n{:#?}\n", recipient.do_balance().await); + // println!("Faucet Balance:\n{:#?}\n", faucet.do_balance().await); + // println!("Recipient Balance:\n{:#?}\n", recipient.do_balance().await); // let faucet_transactions = faucet.do_list_transactions().await; // let filtered_faucet_transactions: Vec<&JsonValue> = match &faucet_transactions { @@ -3698,17 +3700,27 @@ mod basic_transactions { // filtered_recipient_transactions // ); - // let faucet_notes = faucet.do_list_notes(true).await; - // println!("Faucet Notes:\n{:?}\n", faucet_notes); + let txid1 = recipient + .do_send(vec![( + get_base_address!(faucet, "unified").as_str(), + 40_000, + None, + )]) + .await + .unwrap(); + + zingo_testutils::generate_n_blocks_return_new_height(®test_manager, 1) + .await + .unwrap(); - let tx_ins = zingo_testutils::tx_inputs(&faucet, txid1.as_str()).await; - println!("Transaction Inputs\n{:#?}\n", tx_ins); + faucet.do_sync(true).await.unwrap(); + recipient.do_sync(true).await.unwrap(); - // let recipient_notes = recipient.do_list_notes(true).await; - // println!("Recipient Notes\n:{:?}\n", recipient_notes); + let tx_ins = zingo_testutils::tx_inputs(&recipient, txid1.as_str()).await; + println!("Transaction Inputs:\n{:#?}\n", tx_ins); - let tx_outs = zingo_testutils::tx_outputs(&recipient, txid1.as_str()).await; - println!("Transaction Outputs\n{:#?}\n", tx_outs); + let tx_outs = zingo_testutils::tx_outputs(&faucet, txid1.as_str()).await; + println!("Transaction Outputs:\n{:#?}\n", tx_outs); // let faucet_summaries = faucet.do_list_txsummaries().await; // let filtered_faucet_summaries: Vec<&ValueTransfer> = faucet_summaries diff --git a/zingo-testutils/src/lib.rs b/zingo-testutils/src/lib.rs index 70c06619d..6b4b4c9f2 100644 --- a/zingo-testutils/src/lib.rs +++ b/zingo-testutils/src/lib.rs @@ -243,102 +243,15 @@ pub async fn load_wallet( ) } -/// List all notes held by Lightclient that were created in txid. -pub async fn tx_output_notes(client: &LightClient, txid: String) -> Vec { - let client_notes = client.do_list_notes(true).await; - - let required_txid = txid; - - let mut filtered_notes: Vec = Vec::new(); - - if let JsonValue::Object(obj) = client_notes { - if let Some(JsonValue::Array(unspent_sapling_notes)) = obj.get("unspent_sapling_notes") { - filtered_notes.extend( - unspent_sapling_notes - .iter() - .filter(|note| note["created_in_txid"] == required_txid) - .cloned(), - ); - } - - if let Some(JsonValue::Array(pending_sapling_notes)) = obj.get("pending_sapling_notes") { - filtered_notes.extend( - pending_sapling_notes - .iter() - .filter(|note| note["created_in_txid"] == required_txid) - .cloned(), - ); - } - - if let Some(JsonValue::Array(unspent_orchard_notes)) = obj.get("unspent_orchard_notes") { - filtered_notes.extend( - unspent_orchard_notes - .iter() - .filter(|note| note["created_in_txid"] == required_txid) - .cloned(), - ); - } - - if let Some(JsonValue::Array(pending_orchard_notes)) = obj.get("pending_orchard_notes") { - filtered_notes.extend( - pending_orchard_notes - .iter() - .filter(|note| note["created_in_txid"] == required_txid) - .cloned(), - ); - } - - if let Some(JsonValue::Array(utxos)) = obj.get("utxos") { - filtered_notes.extend( - utxos - .iter() - .filter(|note| note["created_in_txid"] == required_txid) - .cloned(), - ); - } - - if let Some(JsonValue::Array(pending_utxos)) = obj.get("pending_utxos") { - filtered_notes.extend( - pending_utxos - .iter() - .filter(|note| note["created_in_txid"] == required_txid) - .cloned(), - ); - } - - if let Some(JsonValue::Array(spent_sapling_notes)) = obj.get("spent_sapling_notes") { - filtered_notes.extend( - spent_sapling_notes - .iter() - .filter(|note| note["created_in_txid"] == required_txid) - .cloned(), - ); - } - - if let Some(JsonValue::Array(spent_orchard_notes)) = obj.get("spent_orchard_notes") { - filtered_notes.extend( - spent_orchard_notes - .iter() - .filter(|note| note["created_in_txid"] == required_txid) - .cloned(), - ); - } - - if let Some(JsonValue::Array(spent_utxos)) = obj.get("spent_utxos") { - filtered_notes.extend( - spent_utxos - .iter() - .filter(|note| note["created_in_txid"] == required_txid) - .cloned(), - ); - } - } - - filtered_notes +#[derive(Debug)] +pub struct TxNotes { + pub transparent_tx_notes: usize, + pub sapling_tx_notes: usize, + pub orchard_tx_notes: usize, } -/// Returnes number of notes used as inputs for txid as (transparent_notes, sapling_notes, orchard_notes). -pub async fn tx_inputs(client: &LightClient, txid: &str) -> (usize, usize, usize) { +/// Returnes number of notes used as inputs for txid as TxNotes (transparent_notes, sapling_notes, orchard_notes). +pub async fn tx_inputs(client: &LightClient, txid: &str) -> TxNotes { let notes = client.do_list_notes(true).await; let mut transparent_notes = 0; @@ -352,6 +265,13 @@ pub async fn tx_inputs(client: &LightClient, txid: &str) -> (usize, usize, usize } } } + if let JsonValue::Array(spent_utxos) = ¬es["pending_utxos"] { + for utxo in spent_utxos { + if utxo["spent"] == txid || utxo["unconfirmed_spent"] == txid { + transparent_notes += 1; + } + } + } if let JsonValue::Array(spent_sapling_notes) = ¬es["spent_sapling_notes"] { for note in spent_sapling_notes { @@ -360,6 +280,13 @@ pub async fn tx_inputs(client: &LightClient, txid: &str) -> (usize, usize, usize } } } + if let JsonValue::Array(spent_sapling_notes) = ¬es["pending_sapling_notes"] { + for note in spent_sapling_notes { + if note["spent"] == txid || note["unconfirmed_spent"] == txid { + sapling_notes += 1; + } + } + } if let JsonValue::Array(spent_orchard_notes) = ¬es["spent_orchard_notes"] { for note in spent_orchard_notes { @@ -368,12 +295,23 @@ pub async fn tx_inputs(client: &LightClient, txid: &str) -> (usize, usize, usize } } } + if let JsonValue::Array(spent_orchard_notes) = ¬es["pending_orchard_notes"] { + for note in spent_orchard_notes { + if note["spent"] == txid || note["unconfirmed_spent"] == txid { + orchard_notes += 1; + } + } + } - (transparent_notes, sapling_notes, orchard_notes) + TxNotes { + transparent_tx_notes: transparent_notes, + sapling_tx_notes: sapling_notes, + orchard_tx_notes: orchard_notes, + } } -/// Returnes number of notes created in txid as (transparent_notes, sapling_notes, orchard_notes). -pub async fn tx_outputs(client: &LightClient, txid: &str) -> (usize, usize, usize) { +/// Returnes number of notes created in txid as TxNotes (transparent_notes, sapling_notes, orchard_notes). +pub async fn tx_outputs(client: &LightClient, txid: &str) -> TxNotes { let notes = client.do_list_notes(true).await; let mut transparent_notes = 0; @@ -404,7 +342,11 @@ pub async fn tx_outputs(client: &LightClient, txid: &str) -> (usize, usize, usiz } } - (transparent_notes, sapling_notes, orchard_notes) + TxNotes { + transparent_tx_notes: transparent_notes, + sapling_tx_notes: sapling_notes, + orchard_tx_notes: orchard_notes, + } } pub mod scenarios { From 061ee8844dfa8486d62e5c3c8647147fc7bfeea9 Mon Sep 17 00:00:00 2001 From: idky137 Date: Mon, 8 Apr 2024 16:54:00 +0100 Subject: [PATCH 03/20] extract data from do_list_summaries --- integration-tests/tests/integrations.rs | 61 +++++++++++++++++-------- 1 file changed, 42 insertions(+), 19 deletions(-) diff --git a/integration-tests/tests/integrations.rs b/integration-tests/tests/integrations.rs index 70f8bf1d0..4785c3b6c 100644 --- a/integration-tests/tests/integrations.rs +++ b/integration-tests/tests/integrations.rs @@ -3600,7 +3600,10 @@ mod slow { mod basic_transactions { use json::JsonValue; use zingo_testutils::scenarios; - use zingolib::{get_base_address, wallet::data::summaries::ValueTransfer}; + use zingolib::{ + get_base_address, + wallet::data::summaries::{ValueTransfer, ValueTransferKind}, + }; #[tokio::test] async fn send_and_sync_with_multiple_notes_no_panic() { @@ -3645,11 +3648,11 @@ mod basic_transactions { } #[tokio::test] - async fn basic_fees() { + async fn standard_fee() { let (regtest_manager, _cph, faucet, recipient) = scenarios::faucet_recipient_default().await; - for _ in 0..2 { + for _ in 0..3 { faucet .do_send(vec![( get_base_address!(recipient, "unified").as_str(), @@ -3722,22 +3725,42 @@ mod basic_transactions { let tx_outs = zingo_testutils::tx_outputs(&faucet, txid1.as_str()).await; println!("Transaction Outputs:\n{:#?}\n", tx_outs); - // let faucet_summaries = faucet.do_list_txsummaries().await; - // let filtered_faucet_summaries: Vec<&ValueTransfer> = faucet_summaries - // .iter() - // .filter(|summary| summary.txid.to_string() == txid1) - // .collect(); - // println!("Faucet Summaries:\n{:#?}\n", filtered_faucet_summaries); - - // let recipient_summaries = recipient.do_list_txsummaries().await; - // let filtered_recipient_summaries: Vec<&ValueTransfer> = recipient_summaries - // .iter() - // .filter(|summary| summary.txid.to_string() == txid1) - // .collect(); - // println!( - // "Recipient Summaries:\n{:#?}\n", - // filtered_recipient_summaries - // ); + let faucet_summaries = faucet.do_list_txsummaries().await; + let simplified_faucet_summaries: Vec<_> = faucet_summaries + .iter() + .filter(|summary| summary.txid.to_string() == txid1) + .map(|summary| match &summary.kind { + ValueTransferKind::Sent { amount, to_address } => { + format!("Sent to: {}, Amount: {}", to_address, amount) + } + ValueTransferKind::Received { pool, amount } => { + format!("Received in pool: {:?}, Amount: {}", pool, amount) + } + ValueTransferKind::SendToSelf => "Sent to Self".to_string(), + ValueTransferKind::Fee { amount } => format!("Fee, Amount: {}", amount), + }) + .collect(); + println!("Faucet Summaries:\n{:#?}\n", simplified_faucet_summaries); + + let recipient_summaries = recipient.do_list_txsummaries().await; + let simplified_recipient_summaries: Vec<_> = recipient_summaries + .iter() + .filter(|summary| summary.txid.to_string() == txid1) + .map(|summary| match &summary.kind { + ValueTransferKind::Sent { amount, to_address } => { + format!("Sent to: {}, Amount: {}", to_address, amount) + } + ValueTransferKind::Received { pool, amount } => { + format!("Received in pool: {:?}, Amount: {}", pool, amount) + } + ValueTransferKind::SendToSelf => "Sent to Self".to_string(), + ValueTransferKind::Fee { amount } => format!("Fee, Amount: {}", amount), + }) + .collect(); + println!( + "Recipient Summaries:\n{:#?}\n", + simplified_recipient_summaries + ); } } From 257e7411ab2679416858af5833051a8e35071ece Mon Sep 17 00:00:00 2001 From: idky137 Date: Tue, 9 Apr 2024 13:55:15 +0100 Subject: [PATCH 04/20] added shield_send_fee test --- integration-tests/tests/integrations.rs | 161 ++++++++++++++++++------ zingo-testutils/src/lib.rs | 44 ++++++- 2 files changed, 164 insertions(+), 41 deletions(-) diff --git a/integration-tests/tests/integrations.rs b/integration-tests/tests/integrations.rs index 4785c3b6c..9cc5a2f01 100644 --- a/integration-tests/tests/integrations.rs +++ b/integration-tests/tests/integrations.rs @@ -3598,11 +3598,16 @@ mod slow { } mod basic_transactions { + use std::cmp; + use json::JsonValue; use zingo_testutils::scenarios; use zingolib::{ get_base_address, - wallet::data::summaries::{ValueTransfer, ValueTransferKind}, + wallet::{ + data::summaries::{ValueTransfer, ValueTransferKind}, + Pool, + }, }; #[tokio::test] @@ -3670,43 +3675,10 @@ mod basic_transactions { faucet.do_sync(true).await.unwrap(); recipient.do_sync(true).await.unwrap(); - // println!("Faucet Balance:\n{:#?}\n", faucet.do_balance().await); - // println!("Recipient Balance:\n{:#?}\n", recipient.do_balance().await); - - // let faucet_transactions = faucet.do_list_transactions().await; - // let filtered_faucet_transactions: Vec<&JsonValue> = match &faucet_transactions { - // JsonValue::Array(arr) => arr - // .iter() - // .filter(|transaction| transaction["txid"] == txid1) - // .collect(), - // _ => { - // panic!("Failed to filter faucet_transactions!",); - // } - // }; - // println!( - // "Faucet Transactions:\n{:#?}\n", - // filtered_faucet_transactions - // ); - - // let recipient_transactions = recipient.do_list_transactions().await; - // let filtered_recipient_transactions: Vec<&JsonValue> = match &recipient_transactions { - // JsonValue::Array(arr) => arr - // .iter() - // .filter(|transaction| transaction["txid"] == txid1) - // .collect(), - // _ => { - // panic!("Failed to filter recipient_transactions!",); - // } - // }; - // println!( - // "Recipient Transactions\n:{:#?}\n", - // filtered_recipient_transactions - // ); - let txid1 = recipient .do_send(vec![( - get_base_address!(faucet, "unified").as_str(), - 40_000, + get_base_address!(faucet, "transparent").as_str(), + 20_000, None, )]) .await @@ -3725,6 +3697,13 @@ mod basic_transactions { let tx_outs = zingo_testutils::tx_outputs(&faucet, txid1.as_str()).await; println!("Transaction Outputs:\n{:#?}\n", tx_outs); + let tx_change = zingo_testutils::tx_outputs(&recipient, txid1.as_str()).await; + println!("Transaction Change Outputs:\n{:#?}\n", tx_change); + + let tx_actions = + zingo_testutils::tx_actions(&recipient, Some(&faucet), txid1.as_str()).await; + println!("Transaction Outputs:\n{:#?}", tx_actions); + let faucet_summaries = faucet.do_list_txsummaries().await; let simplified_faucet_summaries: Vec<_> = faucet_summaries .iter() @@ -3762,6 +3741,116 @@ mod basic_transactions { simplified_recipient_summaries ); } + + #[tokio::test] + async fn standard_send_fee() { + let (regtest_manager, _cph, faucet, recipient) = + scenarios::faucet_recipient_default().await; + + for _ in 0..2 { + faucet + .do_send(vec![( + get_base_address!(recipient, "unified").as_str(), + 40_000, + None, + )]) + .await + .unwrap(); + } + + zingo_testutils::generate_n_blocks_return_new_height(®test_manager, 1) + .await + .unwrap(); + + faucet.do_sync(true).await.unwrap(); + recipient.do_sync(true).await.unwrap(); + + let txid = recipient + .do_send(vec![( + get_base_address!(faucet, "unified").as_str(), + 40_000, + None, + )]) + .await + .unwrap(); + + zingo_testutils::generate_n_blocks_return_new_height(®test_manager, 1) + .await + .unwrap(); + + faucet.do_sync(true).await.unwrap(); + recipient.do_sync(true).await.unwrap(); + + let tx_actions = + zingo_testutils::tx_actions(&recipient, Some(&faucet), txid.as_str()).await; + println!("Transaction Outputs:\n{:#?}", tx_actions); + } + + // #[tokio::test] + // async fn dust_send_fee() {} + + #[tokio::test] + async fn shield_send_fee() { + let (regtest_manager, _cph, faucet, recipient) = + scenarios::faucet_recipient_default().await; + + faucet + .do_send(vec![( + get_base_address!(recipient, "transparent").as_str(), + 40_000, + None, + )]) + .await + .unwrap(); + + zingo_testutils::generate_n_blocks_return_new_height(®test_manager, 1) + .await + .unwrap(); + + faucet.do_sync(true).await.unwrap(); + recipient.do_sync(true).await.unwrap(); + + let txid = recipient + .do_shield( + &[Pool::Transparent], + Some(get_base_address!(recipient, "unified")), + ) + .await + .unwrap(); + + zingo_testutils::generate_n_blocks_return_new_height(®test_manager, 1) + .await + .unwrap(); + + faucet.do_sync(true).await.unwrap(); + recipient.do_sync(true).await.unwrap(); + + let tx_actions = zingo_testutils::tx_actions(&recipient, None, txid.as_str()).await; + println!("Transaction Outputs:\n{:#?}", tx_actions); + + let fee_paid: u64 = recipient + .do_list_txsummaries() + .await + .iter() + .filter(|summary| summary.txid.to_string() == txid) + .find_map(|summary| match &summary.kind { + ValueTransferKind::Fee { amount } => Some(*amount), + _ => None, + }) + .unwrap_or(0); + println!("Fee Paid: {}", fee_paid); + + let expected_fee = 5000 + * (cmp::max( + 2, + tx_actions.transparent_tx_notes + + tx_actions.sapling_tx_notes + + tx_actions.orchard_tx_notes, + )); + println!("Expected Fee: {}", expected_fee); + + assert_eq!(fee_paid, expected_fee as u64); + } } #[tokio::test] diff --git a/zingo-testutils/src/lib.rs b/zingo-testutils/src/lib.rs index 6b4b4c9f2..c55a66dd7 100644 --- a/zingo-testutils/src/lib.rs +++ b/zingo-testutils/src/lib.rs @@ -2,6 +2,7 @@ pub mod interrupts; use grpc_proxy::ProxyServer; pub use incrementalmerkletree; +use std::cmp; use std::collections::HashMap; use std::io::Read; use std::path::{Path, PathBuf}; @@ -244,14 +245,14 @@ pub async fn load_wallet( } #[derive(Debug)] -pub struct TxNotes { +pub struct TxActions { pub transparent_tx_notes: usize, pub sapling_tx_notes: usize, pub orchard_tx_notes: usize, } /// Returnes number of notes used as inputs for txid as TxNotes (transparent_notes, sapling_notes, orchard_notes). -pub async fn tx_inputs(client: &LightClient, txid: &str) -> TxNotes { +pub async fn tx_inputs(client: &LightClient, txid: &str) -> TxActions { let notes = client.do_list_notes(true).await; let mut transparent_notes = 0; @@ -303,7 +304,7 @@ pub async fn tx_inputs(client: &LightClient, txid: &str) -> TxNotes { } } - TxNotes { + TxActions { transparent_tx_notes: transparent_notes, sapling_tx_notes: sapling_notes, orchard_tx_notes: orchard_notes, @@ -311,7 +312,7 @@ pub async fn tx_inputs(client: &LightClient, txid: &str) -> TxNotes { } /// Returnes number of notes created in txid as TxNotes (transparent_notes, sapling_notes, orchard_notes). -pub async fn tx_outputs(client: &LightClient, txid: &str) -> TxNotes { +pub async fn tx_outputs(client: &LightClient, txid: &str) -> TxActions { let notes = client.do_list_notes(true).await; let mut transparent_notes = 0; @@ -342,13 +343,46 @@ pub async fn tx_outputs(client: &LightClient, txid: &str) -> TxNotes { } } - TxNotes { + TxActions { transparent_tx_notes: transparent_notes, sapling_tx_notes: sapling_notes, orchard_tx_notes: orchard_notes, } } +/// Returns total actions for txid. +pub async fn tx_actions( + faucet: &LightClient, + recipient: Option<&LightClient>, + txid: &str, +) -> TxActions { + let tx_ins = tx_inputs(faucet, txid).await; + let tx_outs = if let Some(rec) = recipient { + tx_outputs(rec, txid).await + } else { + TxActions { + transparent_tx_notes: 0, + sapling_tx_notes: 0, + orchard_tx_notes: 0, + } + }; + let tx_change = tx_outputs(faucet, txid).await; + + TxActions { + transparent_tx_notes: cmp::max( + tx_ins.transparent_tx_notes, + tx_outs.transparent_tx_notes + tx_change.transparent_tx_notes, + ), + sapling_tx_notes: cmp::max( + tx_ins.sapling_tx_notes, + tx_outs.sapling_tx_notes + tx_change.sapling_tx_notes, + ), + orchard_tx_notes: (tx_ins.orchard_tx_notes + + tx_outs.orchard_tx_notes + + tx_change.orchard_tx_notes), + } +} + pub mod scenarios { //! In practice there are several common scenarios for which helpers are provided. //! These scenarios vary in the configuration of clients in use. Most scenarios From df76a84d5a72906a0acfdce28ecc9d16c5d04e77 Mon Sep 17 00:00:00 2001 From: idky137 Date: Tue, 9 Apr 2024 17:02:19 +0100 Subject: [PATCH 05/20] finished shield_send_fee test --- integration-tests/tests/integrations.rs | 75 ++++++++++++++++++++++--- zingo-testutils/src/lib.rs | 57 +++++++++++-------- 2 files changed, 103 insertions(+), 29 deletions(-) diff --git a/integration-tests/tests/integrations.rs b/integration-tests/tests/integrations.rs index 9cc5a2f01..292b9c147 100644 --- a/integration-tests/tests/integrations.rs +++ b/integration-tests/tests/integrations.rs @@ -3840,13 +3840,74 @@ mod basic_transactions { .unwrap_or(0); println!("Fee Paid: {}", fee_paid); - let expected_fee = 5000 - * (cmp::max( - 2, - tx_actions.transparent_tx_notes - + tx_actions.sapling_tx_notes - + tx_actions.orchard_tx_notes, - )); + let expected_fee = 10000; + // currently expected fee is always 10000 but will change to the following in zip317 + // let expected_fee = 5000 + // * (cmp::max( + // 2, + // tx_actions.transparent_tx_actions + // + tx_actions.sapling_tx_actions + // + tx_actions.orchard_tx_actions, + // )); + println!("Expected Fee: {}", expected_fee); + + assert_eq!(fee_paid, expected_fee as u64); + + faucet + .do_send(vec![( + get_base_address!(recipient, "transparent").as_str(), + 40_000, + None, + )]) + .await + .unwrap(); + + zingo_testutils::generate_n_blocks_return_new_height(®test_manager, 1) + .await + .unwrap(); + + faucet.do_sync(true).await.unwrap(); + recipient.do_sync(true).await.unwrap(); + + let txid = recipient + .do_shield( + &[Pool::Transparent], + Some(get_base_address!(recipient, "sapling")), + ) + .await + .unwrap(); + + zingo_testutils::generate_n_blocks_return_new_height(®test_manager, 1) + .await + .unwrap(); + + faucet.do_sync(true).await.unwrap(); + recipient.do_sync(true).await.unwrap(); + + let tx_actions = zingo_testutils::tx_actions(&recipient, None, txid.as_str()).await; + println!("Transaction Outputs:\n{:#?}", tx_actions); + + let fee_paid: u64 = recipient + .do_list_txsummaries() + .await + .iter() + .filter(|summary| summary.txid.to_string() == txid) + .find_map(|summary| match &summary.kind { + ValueTransferKind::Fee { amount } => Some(*amount), + _ => None, + }) + .unwrap_or(0); + println!("Fee Paid: {}", fee_paid); + + let expected_fee = 10000; + // currently expected fee is always 10000 but will change to the following in zip317 + // let expected_fee = 5000 + // * (cmp::max( + // 2, + // tx_actions.transparent_tx_actions + // + tx_actions.sapling_tx_actions + // + tx_actions.orchard_tx_actions, + // )); println!("Expected Fee: {}", expected_fee); assert_eq!(fee_paid, expected_fee as u64); diff --git a/zingo-testutils/src/lib.rs b/zingo-testutils/src/lib.rs index c55a66dd7..794050eaf 100644 --- a/zingo-testutils/src/lib.rs +++ b/zingo-testutils/src/lib.rs @@ -246,9 +246,9 @@ pub async fn load_wallet( #[derive(Debug)] pub struct TxActions { - pub transparent_tx_notes: usize, - pub sapling_tx_notes: usize, - pub orchard_tx_notes: usize, + pub transparent_tx_actions: usize, + pub sapling_tx_actions: usize, + pub orchard_tx_actions: usize, } /// Returnes number of notes used as inputs for txid as TxNotes (transparent_notes, sapling_notes, orchard_notes). @@ -305,9 +305,9 @@ pub async fn tx_inputs(client: &LightClient, txid: &str) -> TxActions { } TxActions { - transparent_tx_notes: transparent_notes, - sapling_tx_notes: sapling_notes, - orchard_tx_notes: orchard_notes, + transparent_tx_actions: transparent_notes, + sapling_tx_actions: sapling_notes, + orchard_tx_actions: orchard_notes, } } @@ -344,9 +344,9 @@ pub async fn tx_outputs(client: &LightClient, txid: &str) -> TxActions { } TxActions { - transparent_tx_notes: transparent_notes, - sapling_tx_notes: sapling_notes, - orchard_tx_notes: orchard_notes, + transparent_tx_actions: transparent_notes, + sapling_tx_actions: sapling_notes, + orchard_tx_actions: orchard_notes, } } @@ -361,25 +361,38 @@ pub async fn tx_actions( tx_outputs(rec, txid).await } else { TxActions { - transparent_tx_notes: 0, - sapling_tx_notes: 0, - orchard_tx_notes: 0, + transparent_tx_actions: 0, + sapling_tx_actions: 0, + orchard_tx_actions: 0, } }; let tx_change = tx_outputs(faucet, txid).await; + let calculated_sapling_tx_actions = cmp::max( + tx_ins.sapling_tx_actions, + tx_outs.sapling_tx_actions + tx_change.sapling_tx_actions, + ); + let final_sapling_tx_actions = if calculated_sapling_tx_actions == 1 { + 2 + } else { + calculated_sapling_tx_actions + }; + + let calculated_orchard_tx_actions = + tx_ins.orchard_tx_actions + tx_outs.orchard_tx_actions + tx_change.orchard_tx_actions; + let final_orchard_tx_actions = if calculated_orchard_tx_actions == 1 { + 2 + } else { + calculated_orchard_tx_actions + }; + TxActions { - transparent_tx_notes: cmp::max( - tx_ins.transparent_tx_notes, - tx_outs.transparent_tx_notes + tx_change.transparent_tx_notes, - ), - sapling_tx_notes: cmp::max( - tx_ins.sapling_tx_notes, - tx_outs.sapling_tx_notes + tx_change.sapling_tx_notes, + transparent_tx_actions: cmp::max( + tx_ins.transparent_tx_actions, + tx_outs.transparent_tx_actions + tx_change.transparent_tx_actions, ), - orchard_tx_notes: (tx_ins.orchard_tx_notes - + tx_outs.orchard_tx_notes - + tx_change.orchard_tx_notes), + sapling_tx_actions: final_sapling_tx_actions, + orchard_tx_actions: final_orchard_tx_actions, } } From a0951f68d7cc44a06dc3dcc9e29d158bfd86f6f8 Mon Sep 17 00:00:00 2001 From: idky137 Date: Tue, 9 Apr 2024 17:24:24 +0100 Subject: [PATCH 06/20] fixed shield_send_fee test --- integration-tests/tests/integrations.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/integration-tests/tests/integrations.rs b/integration-tests/tests/integrations.rs index 292b9c147..951a45327 100644 --- a/integration-tests/tests/integrations.rs +++ b/integration-tests/tests/integrations.rs @@ -3652,6 +3652,7 @@ mod basic_transactions { faucet.do_sync(true).await.unwrap(); } + // not a test, using to test test code! #[tokio::test] async fn standard_fee() { let (regtest_manager, _cph, faucet, recipient) = @@ -3677,7 +3678,7 @@ mod basic_transactions { let txid1 = recipient .do_send(vec![( - get_base_address!(faucet, "transparent").as_str(), + get_base_address!(faucet, "sapling").as_str(), 20_000, None, )]) @@ -3702,7 +3703,7 @@ mod basic_transactions { let tx_actions = zingo_testutils::tx_actions(&recipient, Some(&faucet), txid1.as_str()).await; - println!("Transaction Outputs:\n{:#?}", tx_actions); + println!("Transaction Actions:\n{:#?}", tx_actions); let faucet_summaries = faucet.do_list_txsummaries().await; let simplified_faucet_summaries: Vec<_> = faucet_summaries @@ -3767,7 +3768,7 @@ mod basic_transactions { let txid = recipient .do_send(vec![( - get_base_address!(faucet, "unified").as_str(), + get_base_address!(faucet, "transparent").as_str(), 40_000, None, )]) @@ -3826,7 +3827,7 @@ mod basic_transactions { recipient.do_sync(true).await.unwrap(); let tx_actions = zingo_testutils::tx_actions(&recipient, None, txid.as_str()).await; - println!("Transaction Outputs:\n{:#?}", tx_actions); + println!("Transaction Actions:\n{:#?}", tx_actions); let fee_paid: u64 = recipient .do_list_txsummaries() @@ -3885,7 +3886,7 @@ mod basic_transactions { recipient.do_sync(true).await.unwrap(); let tx_actions = zingo_testutils::tx_actions(&recipient, None, txid.as_str()).await; - println!("Transaction Outputs:\n{:#?}", tx_actions); + println!("Transaction Actions:\n{:#?}", tx_actions); let fee_paid: u64 = recipient .do_list_txsummaries() From 21bfdee2797edcb4e1c552c97974fd1fc4516f41 Mon Sep 17 00:00:00 2001 From: idky137 Date: Wed, 10 Apr 2024 09:25:59 +0100 Subject: [PATCH 07/20] fixed transparent output calculation --- integration-tests/tests/integrations.rs | 6 +++++- zingo-testutils/src/lib.rs | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/integration-tests/tests/integrations.rs b/integration-tests/tests/integrations.rs index 951a45327..14bdfa94b 100644 --- a/integration-tests/tests/integrations.rs +++ b/integration-tests/tests/integrations.rs @@ -3601,6 +3601,7 @@ mod basic_transactions { use std::cmp; use json::JsonValue; + use zcash_client_backend::wallet::Recipient; use zingo_testutils::scenarios; use zingolib::{ get_base_address, @@ -3678,7 +3679,7 @@ mod basic_transactions { let txid1 = recipient .do_send(vec![( - get_base_address!(faucet, "sapling").as_str(), + get_base_address!(faucet, "transparent").as_str(), 20_000, None, )]) @@ -3705,6 +3706,9 @@ mod basic_transactions { zingo_testutils::tx_actions(&recipient, Some(&faucet), txid1.as_str()).await; println!("Transaction Actions:\n{:#?}", tx_actions); + // let recipient_notes = recipient.do_list_notes(true).await; + // println!("Recipient Notes:\n{:#?}", recipient_notes); + let faucet_summaries = faucet.do_list_txsummaries().await; let simplified_faucet_summaries: Vec<_> = faucet_summaries .iter() diff --git a/zingo-testutils/src/lib.rs b/zingo-testutils/src/lib.rs index 794050eaf..df684b30c 100644 --- a/zingo-testutils/src/lib.rs +++ b/zingo-testutils/src/lib.rs @@ -319,7 +319,7 @@ pub async fn tx_outputs(client: &LightClient, txid: &str) -> TxActions { let mut sapling_notes = 0; let mut orchard_notes = 0; - if let JsonValue::Array(spent_utxos) = ¬es["unspent_utxos"] { + if let JsonValue::Array(spent_utxos) = ¬es["utxos"] { for utxo in spent_utxos { if utxo["created_in_txid"] == txid { transparent_notes += 1; From a1e0a03f021cbdef9c73f5aa90a1bdc527729c48 Mon Sep 17 00:00:00 2001 From: idky137 Date: Wed, 10 Apr 2024 09:57:05 +0100 Subject: [PATCH 08/20] tidied shield_send_fee test --- integration-tests/tests/integrations.rs | 282 +++++++++++++----------- zingo-testutils/src/lib.rs | 28 ++- 2 files changed, 183 insertions(+), 127 deletions(-) diff --git a/integration-tests/tests/integrations.rs b/integration-tests/tests/integrations.rs index 14bdfa94b..cf04628fd 100644 --- a/integration-tests/tests/integrations.rs +++ b/integration-tests/tests/integrations.rs @@ -3654,33 +3654,117 @@ mod basic_transactions { } // not a test, using to test test code! + // #[tokio::test] + // async fn standard_fee() { + // let (regtest_manager, _cph, faucet, recipient) = + // scenarios::faucet_recipient_default().await; + + // for _ in 0..3 { + // faucet + // .do_send(vec![( + // get_base_address!(recipient, "unified").as_str(), + // 40_000, + // None, + // )]) + // .await + // .unwrap(); + // } + + // zingo_testutils::generate_n_blocks_return_new_height(®test_manager, 1) + // .await + // .unwrap(); + + // faucet.do_sync(true).await.unwrap(); + // recipient.do_sync(true).await.unwrap(); + + // let txid1 = recipient + // .do_send(vec![( + // get_base_address!(faucet, "transparent").as_str(), + // 20_000, + // None, + // )]) + // .await + // .unwrap(); + + // zingo_testutils::generate_n_blocks_return_new_height(®test_manager, 1) + // .await + // .unwrap(); + + // faucet.do_sync(true).await.unwrap(); + // recipient.do_sync(true).await.unwrap(); + + // let tx_ins = zingo_testutils::tx_inputs(&recipient, txid1.as_str()).await; + // println!("Transaction Inputs:\n{:#?}\n", tx_ins); + + // let tx_outs = zingo_testutils::tx_outputs(&faucet, txid1.as_str()).await; + // println!("Transaction Outputs:\n{:#?}\n", tx_outs); + + // let tx_change = zingo_testutils::tx_outputs(&recipient, txid1.as_str()).await; + // println!("Transaction Change Outputs:\n{:#?}\n", tx_change); + + // let tx_actions = + // zingo_testutils::tx_actions(&recipient, Some(&faucet), txid1.as_str()).await; + // println!("Transaction Actions:\n{:#?}", tx_actions); + + // // let recipient_notes = recipient.do_list_notes(true).await; + // // println!("Recipient Notes:\n{:#?}", recipient_notes); + + // let faucet_summaries = faucet.do_list_txsummaries().await; + // let simplified_faucet_summaries: Vec<_> = faucet_summaries + // .iter() + // .filter(|summary| summary.txid.to_string() == txid1) + // .map(|summary| match &summary.kind { + // ValueTransferKind::Sent { amount, to_address } => { + // format!("Sent to: {}, Amount: {}", to_address, amount) + // } + // ValueTransferKind::Received { pool, amount } => { + // format!("Received in pool: {:?}, Amount: {}", pool, amount) + // } + // ValueTransferKind::SendToSelf => "Sent to Self".to_string(), + // ValueTransferKind::Fee { amount } => format!("Fee, Amount: {}", amount), + // }) + // .collect(); + // println!("Faucet Summaries:\n{:#?}\n", simplified_faucet_summaries); + + // let recipient_summaries = recipient.do_list_txsummaries().await; + // let simplified_recipient_summaries: Vec<_> = recipient_summaries + // .iter() + // .filter(|summary| summary.txid.to_string() == txid1) + // .map(|summary| match &summary.kind { + // ValueTransferKind::Sent { amount, to_address } => { + // format!("Sent to: {}, Amount: {}", to_address, amount) + // } + // ValueTransferKind::Received { pool, amount } => { + // format!("Received in pool: {:?}, Amount: {}", pool, amount) + // } + // ValueTransferKind::SendToSelf => "Sent to Self".to_string(), + // ValueTransferKind::Fee { amount } => format!("Fee, Amount: {}", amount), + // }) + // .collect(); + // println!( + // "Recipient Summaries:\n{:#?}\n", + // simplified_recipient_summaries + // ); + // } + #[tokio::test] - async fn standard_fee() { + async fn standard_send_fees() { let (regtest_manager, _cph, faucet, recipient) = scenarios::faucet_recipient_default().await; - for _ in 0..3 { - faucet - .do_send(vec![( - get_base_address!(recipient, "unified").as_str(), - 40_000, - None, - )]) - .await - .unwrap(); - } - - zingo_testutils::generate_n_blocks_return_new_height(®test_manager, 1) + let txid1 = faucet + .do_send(vec![( + get_base_address!(recipient, "unified").as_str(), + 40_000, + None, + )]) .await .unwrap(); - faucet.do_sync(true).await.unwrap(); - recipient.do_sync(true).await.unwrap(); - - let txid1 = recipient + let txid2 = faucet .do_send(vec![( - get_base_address!(faucet, "transparent").as_str(), - 20_000, + get_base_address!(recipient, "sapling").as_str(), + 40_000, None, )]) .await @@ -3693,86 +3777,9 @@ mod basic_transactions { faucet.do_sync(true).await.unwrap(); recipient.do_sync(true).await.unwrap(); - let tx_ins = zingo_testutils::tx_inputs(&recipient, txid1.as_str()).await; - println!("Transaction Inputs:\n{:#?}\n", tx_ins); - - let tx_outs = zingo_testutils::tx_outputs(&faucet, txid1.as_str()).await; - println!("Transaction Outputs:\n{:#?}\n", tx_outs); - - let tx_change = zingo_testutils::tx_outputs(&recipient, txid1.as_str()).await; - println!("Transaction Change Outputs:\n{:#?}\n", tx_change); - - let tx_actions = - zingo_testutils::tx_actions(&recipient, Some(&faucet), txid1.as_str()).await; - println!("Transaction Actions:\n{:#?}", tx_actions); - - // let recipient_notes = recipient.do_list_notes(true).await; - // println!("Recipient Notes:\n{:#?}", recipient_notes); - - let faucet_summaries = faucet.do_list_txsummaries().await; - let simplified_faucet_summaries: Vec<_> = faucet_summaries - .iter() - .filter(|summary| summary.txid.to_string() == txid1) - .map(|summary| match &summary.kind { - ValueTransferKind::Sent { amount, to_address } => { - format!("Sent to: {}, Amount: {}", to_address, amount) - } - ValueTransferKind::Received { pool, amount } => { - format!("Received in pool: {:?}, Amount: {}", pool, amount) - } - ValueTransferKind::SendToSelf => "Sent to Self".to_string(), - ValueTransferKind::Fee { amount } => format!("Fee, Amount: {}", amount), - }) - .collect(); - println!("Faucet Summaries:\n{:#?}\n", simplified_faucet_summaries); - - let recipient_summaries = recipient.do_list_txsummaries().await; - let simplified_recipient_summaries: Vec<_> = recipient_summaries - .iter() - .filter(|summary| summary.txid.to_string() == txid1) - .map(|summary| match &summary.kind { - ValueTransferKind::Sent { amount, to_address } => { - format!("Sent to: {}, Amount: {}", to_address, amount) - } - ValueTransferKind::Received { pool, amount } => { - format!("Received in pool: {:?}, Amount: {}", pool, amount) - } - ValueTransferKind::SendToSelf => "Sent to Self".to_string(), - ValueTransferKind::Fee { amount } => format!("Fee, Amount: {}", amount), - }) - .collect(); - println!( - "Recipient Summaries:\n{:#?}\n", - simplified_recipient_summaries - ); - } - - #[tokio::test] - async fn standard_send_fee() { - let (regtest_manager, _cph, faucet, recipient) = - scenarios::faucet_recipient_default().await; - - for _ in 0..2 { - faucet - .do_send(vec![( - get_base_address!(recipient, "unified").as_str(), - 40_000, - None, - )]) - .await - .unwrap(); - } - - zingo_testutils::generate_n_blocks_return_new_height(®test_manager, 1) - .await - .unwrap(); - - faucet.do_sync(true).await.unwrap(); - recipient.do_sync(true).await.unwrap(); - let txid = recipient .do_send(vec![( - get_base_address!(faucet, "transparent").as_str(), + get_base_address!(faucet, "unified").as_str(), 40_000, None, )]) @@ -3789,13 +3796,38 @@ mod basic_transactions { let tx_actions = zingo_testutils::tx_actions(&recipient, Some(&faucet), txid.as_str()).await; println!("Transaction Outputs:\n{:#?}", tx_actions); + + let fee_paid: u64 = recipient + .do_list_txsummaries() + .await + .iter() + .filter(|summary| summary.txid.to_string() == txid) + .find_map(|summary| match &summary.kind { + ValueTransferKind::Fee { amount } => Some(*amount), + _ => None, + }) + .unwrap_or(0); + println!("Fee Paid: {}", fee_paid); + + let expected_fee = 10000; + // currently expected fee is always 10000 but will change to the following in zip317 + // let expected_fee = 5000 + // * (cmp::max( + // 2, + // tx_actions.transparent_tx_actions + // + tx_actions.sapling_tx_actions + // + tx_actions.orchard_tx_actions, + // )); + println!("Expected Fee: {}", expected_fee); + + assert_eq!(fee_paid, expected_fee as u64); } // #[tokio::test] - // async fn dust_send_fee() {} + // async fn dust_send_fees() {} #[tokio::test] - async fn shield_send_fee() { + async fn shield_send_fees() { let (regtest_manager, _cph, faucet, recipient) = scenarios::faucet_recipient_default().await; @@ -3815,7 +3847,7 @@ mod basic_transactions { faucet.do_sync(true).await.unwrap(); recipient.do_sync(true).await.unwrap(); - let txid = recipient + let txid1 = recipient .do_shield( &[Pool::Transparent], Some(get_base_address!(recipient, "unified")), @@ -3830,33 +3862,33 @@ mod basic_transactions { faucet.do_sync(true).await.unwrap(); recipient.do_sync(true).await.unwrap(); - let tx_actions = zingo_testutils::tx_actions(&recipient, None, txid.as_str()).await; - println!("Transaction Actions:\n{:#?}", tx_actions); + let tx_actions_txid1 = zingo_testutils::tx_actions(&recipient, None, txid1.as_str()).await; + println!("Transaction Actions:\n{:#?}", tx_actions_txid1); - let fee_paid: u64 = recipient + let fee_paid_txid1: u64 = recipient .do_list_txsummaries() .await .iter() - .filter(|summary| summary.txid.to_string() == txid) + .filter(|summary| summary.txid.to_string() == txid1) .find_map(|summary| match &summary.kind { ValueTransferKind::Fee { amount } => Some(*amount), _ => None, }) .unwrap_or(0); - println!("Fee Paid: {}", fee_paid); + println!("Fee Paid: {}", fee_paid_txid1); - let expected_fee = 10000; + let expected_fee_txid1 = 10000; // currently expected fee is always 10000 but will change to the following in zip317 - // let expected_fee = 5000 + // let expected_fee_txid1 = 5000 // * (cmp::max( // 2, - // tx_actions.transparent_tx_actions - // + tx_actions.sapling_tx_actions - // + tx_actions.orchard_tx_actions, + // tx_actions_txid1.transparent_tx_actions + // + tx_actions_txid1.sapling_tx_actions + // + tx_actions_txid1.orchard_tx_actions, // )); - println!("Expected Fee: {}", expected_fee); + println!("Expected Fee: {}", expected_fee_txid1); - assert_eq!(fee_paid, expected_fee as u64); + assert_eq!(fee_paid_txid1, expected_fee_txid1 as u64); faucet .do_send(vec![( @@ -3874,7 +3906,7 @@ mod basic_transactions { faucet.do_sync(true).await.unwrap(); recipient.do_sync(true).await.unwrap(); - let txid = recipient + let txid2 = recipient .do_shield( &[Pool::Transparent], Some(get_base_address!(recipient, "sapling")), @@ -3889,33 +3921,33 @@ mod basic_transactions { faucet.do_sync(true).await.unwrap(); recipient.do_sync(true).await.unwrap(); - let tx_actions = zingo_testutils::tx_actions(&recipient, None, txid.as_str()).await; - println!("Transaction Actions:\n{:#?}", tx_actions); + let tx_actions_txid2 = zingo_testutils::tx_actions(&recipient, None, txid2.as_str()).await; + println!("Transaction Actions:\n{:#?}", tx_actions_txid2); - let fee_paid: u64 = recipient + let fee_paid_txid2: u64 = recipient .do_list_txsummaries() .await .iter() - .filter(|summary| summary.txid.to_string() == txid) + .filter(|summary| summary.txid.to_string() == txid2) .find_map(|summary| match &summary.kind { ValueTransferKind::Fee { amount } => Some(*amount), _ => None, }) .unwrap_or(0); - println!("Fee Paid: {}", fee_paid); + println!("Fee Paid: {}", fee_paid_txid2); - let expected_fee = 10000; + let expected_fee_txid2 = 10000; // currently expected fee is always 10000 but will change to the following in zip317 - // let expected_fee = 5000 + // let expected_fee_txid2 = 5000 // * (cmp::max( // 2, - // tx_actions.transparent_tx_actions - // + tx_actions.sapling_tx_actions - // + tx_actions.orchard_tx_actions, + // tx_actions_txid2.transparent_tx_actions + // + tx_actions_txid2.sapling_tx_actions + // + tx_actions_txid2.orchard_tx_actions, // )); - println!("Expected Fee: {}", expected_fee); + println!("Expected Fee: {}", expected_fee_txid2); - assert_eq!(fee_paid, expected_fee as u64); + assert_eq!(fee_paid_txid2, expected_fee_txid2 as u64); } } diff --git a/zingo-testutils/src/lib.rs b/zingo-testutils/src/lib.rs index df684b30c..2c0e1589a 100644 --- a/zingo-testutils/src/lib.rs +++ b/zingo-testutils/src/lib.rs @@ -251,7 +251,7 @@ pub struct TxActions { pub orchard_tx_actions: usize, } -/// Returnes number of notes used as inputs for txid as TxNotes (transparent_notes, sapling_notes, orchard_notes). +/// Returnes number of notes used as inputs for txid as TxActions (transparent_notes, sapling_notes, orchard_notes). pub async fn tx_inputs(client: &LightClient, txid: &str) -> TxActions { let notes = client.do_list_notes(true).await; @@ -311,7 +311,7 @@ pub async fn tx_inputs(client: &LightClient, txid: &str) -> TxActions { } } -/// Returnes number of notes created in txid as TxNotes (transparent_notes, sapling_notes, orchard_notes). +/// Returnes number of notes created in txid as TxActions (transparent_notes, sapling_notes, orchard_notes). pub async fn tx_outputs(client: &LightClient, txid: &str) -> TxActions { let notes = client.do_list_notes(true).await; @@ -327,6 +327,14 @@ pub async fn tx_outputs(client: &LightClient, txid: &str) -> TxActions { } } + if let JsonValue::Array(spent_utxos) = ¬es["pending_utxos"] { + for utxo in spent_utxos { + if utxo["created_in_txid"] == txid { + transparent_notes += 1; + } + } + } + if let JsonValue::Array(spent_sapling_notes) = ¬es["unspent_sapling_notes"] { for note in spent_sapling_notes { if note["created_in_txid"] == txid { @@ -335,6 +343,14 @@ pub async fn tx_outputs(client: &LightClient, txid: &str) -> TxActions { } } + if let JsonValue::Array(spent_sapling_notes) = ¬es["pending_sapling_notes"] { + for note in spent_sapling_notes { + if note["created_in_txid"] == txid { + sapling_notes += 1; + } + } + } + if let JsonValue::Array(spent_orchard_notes) = ¬es["unspent_orchard_notes"] { for note in spent_orchard_notes { if note["created_in_txid"] == txid { @@ -343,6 +359,14 @@ pub async fn tx_outputs(client: &LightClient, txid: &str) -> TxActions { } } + if let JsonValue::Array(spent_orchard_notes) = ¬es["pending_orchard_notes"] { + for note in spent_orchard_notes { + if note["created_in_txid"] == txid { + orchard_notes += 1; + } + } + } + TxActions { transparent_tx_actions: transparent_notes, sapling_tx_actions: sapling_notes, From a6a6dcf33aac065b7f3c5dc488eda06918bcf292 Mon Sep 17 00:00:00 2001 From: idky137 Date: Wed, 10 Apr 2024 10:30:44 +0100 Subject: [PATCH 09/20] finished standard_send_fee test --- integration-tests/tests/integrations.rs | 193 ++++++++++++++++++++---- 1 file changed, 167 insertions(+), 26 deletions(-) diff --git a/integration-tests/tests/integrations.rs b/integration-tests/tests/integrations.rs index cf04628fd..ec7166380 100644 --- a/integration-tests/tests/integrations.rs +++ b/integration-tests/tests/integrations.rs @@ -3598,17 +3598,10 @@ mod slow { } mod basic_transactions { - use std::cmp; - - use json::JsonValue; - use zcash_client_backend::wallet::Recipient; use zingo_testutils::scenarios; use zingolib::{ get_base_address, - wallet::{ - data::summaries::{ValueTransfer, ValueTransferKind}, - Pool, - }, + wallet::{data::summaries::ValueTransferKind, Pool}, }; #[tokio::test] @@ -3770,6 +3763,15 @@ mod basic_transactions { .await .unwrap(); + let txid3 = faucet + .do_send(vec![( + get_base_address!(recipient, "transparent").as_str(), + 40_000, + None, + )]) + .await + .unwrap(); + zingo_testutils::generate_n_blocks_return_new_height(®test_manager, 1) .await .unwrap(); @@ -3777,10 +3779,136 @@ mod basic_transactions { faucet.do_sync(true).await.unwrap(); recipient.do_sync(true).await.unwrap(); - let txid = recipient + println!( + "Transaction Inputs:\n{:?}", + zingo_testutils::tx_inputs(&faucet, txid1.as_str()).await + ); + println!( + "Transaction Outputs:\n{:?}", + zingo_testutils::tx_outputs(&recipient, txid1.as_str()).await + ); + println!( + "Transaction Change:\n{:?}", + zingo_testutils::tx_outputs(&faucet, txid1.as_str()).await + ); + + let tx_actions_txid1 = + zingo_testutils::tx_actions(&faucet, Some(&recipient), txid1.as_str()).await; + println!("Transaction Actions:\n{:?}", tx_actions_txid1); + + let fee_paid_txid1: u64 = faucet + .do_list_txsummaries() + .await + .iter() + .filter(|summary| summary.txid.to_string() == txid1) + .find_map(|summary| match &summary.kind { + ValueTransferKind::Fee { amount } => Some(*amount), + _ => None, + }) + .unwrap_or(0); + println!("Fee Paid: {}", fee_paid_txid1); + + let expected_fee_txid1 = 10000; + // currently expected fee is always 10000 but will change to the following in zip317 + // let expected_fee_txid1 = 5000 + // * (cmp::max( + // 2, + // tx_actions_txid1.transparent_tx_actions + // + tx_actions_txid1.sapling_tx_actions + // + tx_actions_txid1.orchard_tx_actions, + // )); + println!("Expected Fee: {}", expected_fee_txid1); + + assert_eq!(fee_paid_txid1, expected_fee_txid1 as u64); + + println!( + "Transaction Inputs:\n{:?}", + zingo_testutils::tx_inputs(&faucet, txid2.as_str()).await + ); + println!( + "Transaction Outputs:\n{:?}", + zingo_testutils::tx_outputs(&recipient, txid2.as_str()).await + ); + println!( + "Transaction Change:\n{:?}", + zingo_testutils::tx_outputs(&faucet, txid2.as_str()).await + ); + + let tx_actions_txid2 = + zingo_testutils::tx_actions(&faucet, Some(&recipient), txid2.as_str()).await; + println!("Transaction Actions:\n{:?}", tx_actions_txid2); + + let fee_paid_txid2: u64 = faucet + .do_list_txsummaries() + .await + .iter() + .filter(|summary| summary.txid.to_string() == txid2) + .find_map(|summary| match &summary.kind { + ValueTransferKind::Fee { amount } => Some(*amount), + _ => None, + }) + .unwrap_or(0); + println!("Fee Paid: {}", fee_paid_txid2); + + let expected_fee_txid2 = 10000; + // currently expected fee is always 10000 but will change to the following in zip317 + // let expected_fee_txid2 = 5000 + // * (cmp::max( + // 2, + // tx_actions_txid2.transparent_tx_actions + // + tx_actions_txid2.sapling_tx_actions + // + tx_actions_txid2.orchard_tx_actions, + // )); + println!("Expected Fee: {}", expected_fee_txid2); + + assert_eq!(fee_paid_txid2, expected_fee_txid2 as u64); + + println!( + "Transaction Inputs:\n{:?}", + zingo_testutils::tx_inputs(&faucet, txid3.as_str()).await + ); + println!( + "Transaction Outputs:\n{:?}", + zingo_testutils::tx_outputs(&recipient, txid3.as_str()).await + ); + println!( + "Transaction Change:\n{:?}", + zingo_testutils::tx_outputs(&faucet, txid3.as_str()).await + ); + + let tx_actions_txid3 = + zingo_testutils::tx_actions(&faucet, Some(&recipient), txid3.as_str()).await; + println!("Transaction Actions:\n{:?}", tx_actions_txid3); + + let fee_paid_txid3: u64 = faucet + .do_list_txsummaries() + .await + .iter() + .filter(|summary| summary.txid.to_string() == txid3) + .find_map(|summary| match &summary.kind { + ValueTransferKind::Fee { amount } => Some(*amount), + _ => None, + }) + .unwrap_or(0); + println!("Fee Paid: {}", fee_paid_txid3); + + let expected_fee_txid3 = 10000; + // currently expected fee is always 10000 but will change to the following in zip317 + // let expected_fee_txid3 = 5000 + // * (cmp::max( + // 2, + // tx_actions_txid3.transparent_tx_actions + // + tx_actions_txid3.sapling_tx_actions + // + tx_actions_txid3.orchard_tx_actions, + // )); + println!("Expected Fee: {}", expected_fee_txid3); + + assert_eq!(fee_paid_txid3, expected_fee_txid3 as u64); + + let txid4 = recipient .do_send(vec![( - get_base_address!(faucet, "unified").as_str(), - 40_000, + get_base_address!(faucet, "transparent").as_str(), + 60_000, None, )]) .await @@ -3793,34 +3921,47 @@ mod basic_transactions { faucet.do_sync(true).await.unwrap(); recipient.do_sync(true).await.unwrap(); - let tx_actions = - zingo_testutils::tx_actions(&recipient, Some(&faucet), txid.as_str()).await; - println!("Transaction Outputs:\n{:#?}", tx_actions); + println!( + "Transaction Inputs:\n{:?}", + zingo_testutils::tx_inputs(&recipient, txid4.as_str()).await + ); + println!( + "Transaction Outputs:\n{:?}", + zingo_testutils::tx_outputs(&faucet, txid4.as_str()).await + ); + println!( + "Transaction Change:\n{:?}", + zingo_testutils::tx_outputs(&recipient, txid4.as_str()).await + ); + + let tx_actions_txid4 = + zingo_testutils::tx_actions(&recipient, Some(&faucet), txid4.as_str()).await; + println!("Transaction Actions:\n{:?}", tx_actions_txid4); - let fee_paid: u64 = recipient + let fee_paid_txid4: u64 = recipient .do_list_txsummaries() .await .iter() - .filter(|summary| summary.txid.to_string() == txid) + .filter(|summary| summary.txid.to_string() == txid4) .find_map(|summary| match &summary.kind { ValueTransferKind::Fee { amount } => Some(*amount), _ => None, }) .unwrap_or(0); - println!("Fee Paid: {}", fee_paid); + println!("Fee Paid: {}", fee_paid_txid4); - let expected_fee = 10000; + let expected_fee_txid4 = 10000; // currently expected fee is always 10000 but will change to the following in zip317 - // let expected_fee = 5000 + // let expected_fee_txid4 = 5000 // * (cmp::max( // 2, - // tx_actions.transparent_tx_actions - // + tx_actions.sapling_tx_actions - // + tx_actions.orchard_tx_actions, + // tx_actions_txid4.transparent_tx_actions + // + tx_actions_txid4.sapling_tx_actions + // + tx_actions_txid4.orchard_tx_actions, // )); - println!("Expected Fee: {}", expected_fee); + println!("Expected Fee: {}", expected_fee_txid4); - assert_eq!(fee_paid, expected_fee as u64); + assert_eq!(fee_paid_txid4, expected_fee_txid4 as u64); } // #[tokio::test] @@ -3863,7 +4004,7 @@ mod basic_transactions { recipient.do_sync(true).await.unwrap(); let tx_actions_txid1 = zingo_testutils::tx_actions(&recipient, None, txid1.as_str()).await; - println!("Transaction Actions:\n{:#?}", tx_actions_txid1); + println!("Transaction Actions:\n{:?}", tx_actions_txid1); let fee_paid_txid1: u64 = recipient .do_list_txsummaries() @@ -3922,7 +4063,7 @@ mod basic_transactions { recipient.do_sync(true).await.unwrap(); let tx_actions_txid2 = zingo_testutils::tx_actions(&recipient, None, txid2.as_str()).await; - println!("Transaction Actions:\n{:#?}", tx_actions_txid2); + println!("Transaction Actions:\n{:?}", tx_actions_txid2); let fee_paid_txid2: u64 = recipient .do_list_txsummaries() From 9e477f68c0b3f486fa392300a6dd8a160e6eb048 Mon Sep 17 00:00:00 2001 From: idky137 Date: Wed, 10 Apr 2024 11:04:47 +0100 Subject: [PATCH 10/20] finished adding fee tests --- integration-tests/tests/integrations.rs | 146 ++++++++---------------- 1 file changed, 50 insertions(+), 96 deletions(-) diff --git a/integration-tests/tests/integrations.rs b/integration-tests/tests/integrations.rs index ec7166380..820c1b3de 100644 --- a/integration-tests/tests/integrations.rs +++ b/integration-tests/tests/integrations.rs @@ -3646,100 +3646,6 @@ mod basic_transactions { faucet.do_sync(true).await.unwrap(); } - // not a test, using to test test code! - // #[tokio::test] - // async fn standard_fee() { - // let (regtest_manager, _cph, faucet, recipient) = - // scenarios::faucet_recipient_default().await; - - // for _ in 0..3 { - // faucet - // .do_send(vec![( - // get_base_address!(recipient, "unified").as_str(), - // 40_000, - // None, - // )]) - // .await - // .unwrap(); - // } - - // zingo_testutils::generate_n_blocks_return_new_height(®test_manager, 1) - // .await - // .unwrap(); - - // faucet.do_sync(true).await.unwrap(); - // recipient.do_sync(true).await.unwrap(); - - // let txid1 = recipient - // .do_send(vec![( - // get_base_address!(faucet, "transparent").as_str(), - // 20_000, - // None, - // )]) - // .await - // .unwrap(); - - // zingo_testutils::generate_n_blocks_return_new_height(®test_manager, 1) - // .await - // .unwrap(); - - // faucet.do_sync(true).await.unwrap(); - // recipient.do_sync(true).await.unwrap(); - - // let tx_ins = zingo_testutils::tx_inputs(&recipient, txid1.as_str()).await; - // println!("Transaction Inputs:\n{:#?}\n", tx_ins); - - // let tx_outs = zingo_testutils::tx_outputs(&faucet, txid1.as_str()).await; - // println!("Transaction Outputs:\n{:#?}\n", tx_outs); - - // let tx_change = zingo_testutils::tx_outputs(&recipient, txid1.as_str()).await; - // println!("Transaction Change Outputs:\n{:#?}\n", tx_change); - - // let tx_actions = - // zingo_testutils::tx_actions(&recipient, Some(&faucet), txid1.as_str()).await; - // println!("Transaction Actions:\n{:#?}", tx_actions); - - // // let recipient_notes = recipient.do_list_notes(true).await; - // // println!("Recipient Notes:\n{:#?}", recipient_notes); - - // let faucet_summaries = faucet.do_list_txsummaries().await; - // let simplified_faucet_summaries: Vec<_> = faucet_summaries - // .iter() - // .filter(|summary| summary.txid.to_string() == txid1) - // .map(|summary| match &summary.kind { - // ValueTransferKind::Sent { amount, to_address } => { - // format!("Sent to: {}, Amount: {}", to_address, amount) - // } - // ValueTransferKind::Received { pool, amount } => { - // format!("Received in pool: {:?}, Amount: {}", pool, amount) - // } - // ValueTransferKind::SendToSelf => "Sent to Self".to_string(), - // ValueTransferKind::Fee { amount } => format!("Fee, Amount: {}", amount), - // }) - // .collect(); - // println!("Faucet Summaries:\n{:#?}\n", simplified_faucet_summaries); - - // let recipient_summaries = recipient.do_list_txsummaries().await; - // let simplified_recipient_summaries: Vec<_> = recipient_summaries - // .iter() - // .filter(|summary| summary.txid.to_string() == txid1) - // .map(|summary| match &summary.kind { - // ValueTransferKind::Sent { amount, to_address } => { - // format!("Sent to: {}, Amount: {}", to_address, amount) - // } - // ValueTransferKind::Received { pool, amount } => { - // format!("Received in pool: {:?}, Amount: {}", pool, amount) - // } - // ValueTransferKind::SendToSelf => "Sent to Self".to_string(), - // ValueTransferKind::Fee { amount } => format!("Fee, Amount: {}", amount), - // }) - // .collect(); - // println!( - // "Recipient Summaries:\n{:#?}\n", - // simplified_recipient_summaries - // ); - // } - #[tokio::test] async fn standard_send_fees() { let (regtest_manager, _cph, faucet, recipient) = @@ -3964,8 +3870,56 @@ mod basic_transactions { assert_eq!(fee_paid_txid4, expected_fee_txid4 as u64); } - // #[tokio::test] - // async fn dust_send_fees() {} + #[tokio::test] + async fn dust_send_fees() { + let (regtest_manager, _cph, faucet, recipient) = + scenarios::faucet_recipient_default().await; + + let txid1 = faucet + .do_send(vec![( + get_base_address!(recipient, "unified").as_str(), + 0, + None, + )]) + .await + .unwrap(); + + zingo_testutils::generate_n_blocks_return_new_height(®test_manager, 1) + .await + .unwrap(); + + faucet.do_sync(true).await.unwrap(); + recipient.do_sync(true).await.unwrap(); + + let tx_actions_txid1 = + zingo_testutils::tx_actions(&faucet, Some(&recipient), txid1.as_str()).await; + println!("Transaction Actions:\n{:?}", tx_actions_txid1); + + let fee_paid_txid1: u64 = faucet + .do_list_txsummaries() + .await + .iter() + .filter(|summary| summary.txid.to_string() == txid1) + .find_map(|summary| match &summary.kind { + ValueTransferKind::Fee { amount } => Some(*amount), + _ => None, + }) + .unwrap_or(0); + println!("Fee Paid: {}", fee_paid_txid1); + + let expected_fee_txid1 = 10000; + // currently expected fee is always 10000 but will change to the following in zip317 + // let expected_fee_txid1 = 5000 + // * (cmp::max( + // 2, + // tx_actions_txid1.transparent_tx_actions + // + tx_actions_txid1.sapling_tx_actions + // + tx_actions_txid1.orchard_tx_actions, + // )); + println!("Expected Fee: {}", expected_fee_txid1); + + assert_eq!(fee_paid_txid1, expected_fee_txid1 as u64); + } #[tokio::test] async fn shield_send_fees() { From b0386df02709724d26be6ede9d1f736c8238b258 Mon Sep 17 00:00:00 2001 From: idky137 Date: Wed, 10 Apr 2024 11:57:29 +0100 Subject: [PATCH 11/20] fixed action calculation --- integration-tests/tests/integrations.rs | 31 +++++++++++++++++++++++++ zingo-testutils/src/lib.rs | 9 +++++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/integration-tests/tests/integrations.rs b/integration-tests/tests/integrations.rs index 820c1b3de..dfadf0d51 100644 --- a/integration-tests/tests/integrations.rs +++ b/integration-tests/tests/integrations.rs @@ -3891,6 +3891,19 @@ mod basic_transactions { faucet.do_sync(true).await.unwrap(); recipient.do_sync(true).await.unwrap(); + println!( + "Transaction Inputs:\n{:?}", + zingo_testutils::tx_inputs(&faucet, txid1.as_str()).await + ); + println!( + "Transaction Outputs:\n{:?}", + zingo_testutils::tx_outputs(&recipient, txid1.as_str()).await + ); + println!( + "Transaction Change:\n{:?}", + zingo_testutils::tx_outputs(&faucet, txid1.as_str()).await + ); + let tx_actions_txid1 = zingo_testutils::tx_actions(&faucet, Some(&recipient), txid1.as_str()).await; println!("Transaction Actions:\n{:?}", tx_actions_txid1); @@ -3957,6 +3970,15 @@ mod basic_transactions { faucet.do_sync(true).await.unwrap(); recipient.do_sync(true).await.unwrap(); + println!( + "Transaction Inputs:\n{:?}", + zingo_testutils::tx_inputs(&recipient, txid1.as_str()).await + ); + println!( + "Transaction Outputs:\n{:?}", + zingo_testutils::tx_outputs(&recipient, txid1.as_str()).await + ); + let tx_actions_txid1 = zingo_testutils::tx_actions(&recipient, None, txid1.as_str()).await; println!("Transaction Actions:\n{:?}", tx_actions_txid1); @@ -4016,6 +4038,15 @@ mod basic_transactions { faucet.do_sync(true).await.unwrap(); recipient.do_sync(true).await.unwrap(); + println!( + "Transaction Inputs:\n{:?}", + zingo_testutils::tx_inputs(&recipient, txid2.as_str()).await + ); + println!( + "Transaction Outputs:\n{:?}", + zingo_testutils::tx_outputs(&recipient, txid2.as_str()).await + ); + let tx_actions_txid2 = zingo_testutils::tx_actions(&recipient, None, txid2.as_str()).await; println!("Transaction Actions:\n{:?}", tx_actions_txid2); diff --git a/zingo-testutils/src/lib.rs b/zingo-testutils/src/lib.rs index 2c0e1589a..c141281d2 100644 --- a/zingo-testutils/src/lib.rs +++ b/zingo-testutils/src/lib.rs @@ -402,8 +402,13 @@ pub async fn tx_actions( calculated_sapling_tx_actions }; - let calculated_orchard_tx_actions = - tx_ins.orchard_tx_actions + tx_outs.orchard_tx_actions + tx_change.orchard_tx_actions; + // let calculated_orchard_tx_actions = + // tx_ins.orchard_tx_actions + tx_outs.orchard_tx_actions + tx_change.orchard_tx_actions; + + let calculated_orchard_tx_actions = cmp::max( + tx_ins.orchard_tx_actions, + tx_outs.orchard_tx_actions + tx_change.orchard_tx_actions, + ); let final_orchard_tx_actions = if calculated_orchard_tx_actions == 1 { 2 } else { From 911666c84cebec97f3ebc299fa69d71b89646701 Mon Sep 17 00:00:00 2001 From: idky137 Date: Wed, 10 Apr 2024 13:46:50 +0100 Subject: [PATCH 12/20] updated tx_inputs and tx_outputs to return TxNotes --- zingo-testutils/src/lib.rs | 56 ++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/zingo-testutils/src/lib.rs b/zingo-testutils/src/lib.rs index c141281d2..e489df84e 100644 --- a/zingo-testutils/src/lib.rs +++ b/zingo-testutils/src/lib.rs @@ -244,6 +244,13 @@ pub async fn load_wallet( ) } +#[derive(Debug)] +pub struct TxNotes { + pub transparent_tx_notes: usize, + pub sapling_tx_notes: usize, + pub orchard_tx_notes: usize, +} + #[derive(Debug)] pub struct TxActions { pub transparent_tx_actions: usize, @@ -252,7 +259,7 @@ pub struct TxActions { } /// Returnes number of notes used as inputs for txid as TxActions (transparent_notes, sapling_notes, orchard_notes). -pub async fn tx_inputs(client: &LightClient, txid: &str) -> TxActions { +pub async fn tx_inputs(client: &LightClient, txid: &str) -> TxNotes { let notes = client.do_list_notes(true).await; let mut transparent_notes = 0; @@ -304,15 +311,15 @@ pub async fn tx_inputs(client: &LightClient, txid: &str) -> TxActions { } } - TxActions { - transparent_tx_actions: transparent_notes, - sapling_tx_actions: sapling_notes, - orchard_tx_actions: orchard_notes, + TxNotes { + transparent_tx_notes: transparent_notes, + sapling_tx_notes: sapling_notes, + orchard_tx_notes: orchard_notes, } } /// Returnes number of notes created in txid as TxActions (transparent_notes, sapling_notes, orchard_notes). -pub async fn tx_outputs(client: &LightClient, txid: &str) -> TxActions { +pub async fn tx_outputs(client: &LightClient, txid: &str) -> TxNotes { let notes = client.do_list_notes(true).await; let mut transparent_notes = 0; @@ -367,34 +374,34 @@ pub async fn tx_outputs(client: &LightClient, txid: &str) -> TxActions { } } - TxActions { - transparent_tx_actions: transparent_notes, - sapling_tx_actions: sapling_notes, - orchard_tx_actions: orchard_notes, + TxNotes { + transparent_tx_notes: transparent_notes, + sapling_tx_notes: sapling_notes, + orchard_tx_notes: orchard_notes, } } /// Returns total actions for txid. pub async fn tx_actions( - faucet: &LightClient, + sender: &LightClient, recipient: Option<&LightClient>, txid: &str, ) -> TxActions { - let tx_ins = tx_inputs(faucet, txid).await; + let tx_ins = tx_inputs(sender, txid).await; let tx_outs = if let Some(rec) = recipient { tx_outputs(rec, txid).await } else { - TxActions { - transparent_tx_actions: 0, - sapling_tx_actions: 0, - orchard_tx_actions: 0, + TxNotes { + transparent_tx_notes: 0, + sapling_tx_notes: 0, + orchard_tx_notes: 0, } }; - let tx_change = tx_outputs(faucet, txid).await; + let tx_change = tx_outputs(sender, txid).await; let calculated_sapling_tx_actions = cmp::max( - tx_ins.sapling_tx_actions, - tx_outs.sapling_tx_actions + tx_change.sapling_tx_actions, + tx_ins.sapling_tx_notes, + tx_outs.sapling_tx_notes + tx_change.sapling_tx_notes, ); let final_sapling_tx_actions = if calculated_sapling_tx_actions == 1 { 2 @@ -402,12 +409,9 @@ pub async fn tx_actions( calculated_sapling_tx_actions }; - // let calculated_orchard_tx_actions = - // tx_ins.orchard_tx_actions + tx_outs.orchard_tx_actions + tx_change.orchard_tx_actions; - let calculated_orchard_tx_actions = cmp::max( - tx_ins.orchard_tx_actions, - tx_outs.orchard_tx_actions + tx_change.orchard_tx_actions, + tx_ins.orchard_tx_notes, + tx_outs.orchard_tx_notes + tx_change.orchard_tx_notes, ); let final_orchard_tx_actions = if calculated_orchard_tx_actions == 1 { 2 @@ -417,8 +421,8 @@ pub async fn tx_actions( TxActions { transparent_tx_actions: cmp::max( - tx_ins.transparent_tx_actions, - tx_outs.transparent_tx_actions + tx_change.transparent_tx_actions, + tx_ins.transparent_tx_notes, + tx_outs.transparent_tx_notes + tx_change.transparent_tx_notes, ), sapling_tx_actions: final_sapling_tx_actions, orchard_tx_actions: final_orchard_tx_actions, From 589a6f1ba8e7d67b6a6a9d5ed50202ff1d028c32 Mon Sep 17 00:00:00 2001 From: idky137 Date: Wed, 10 Apr 2024 16:35:30 +0100 Subject: [PATCH 13/20] removed do_list_txsummaries --- integration-tests/tests/integrations.rs | 111 ++++++------------------ zingo-testutils/src/lib.rs | 81 +++++++++++++++++ 2 files changed, 108 insertions(+), 84 deletions(-) diff --git a/integration-tests/tests/integrations.rs b/integration-tests/tests/integrations.rs index dfadf0d51..fff35c5b2 100644 --- a/integration-tests/tests/integrations.rs +++ b/integration-tests/tests/integrations.rs @@ -3702,17 +3702,9 @@ mod basic_transactions { zingo_testutils::tx_actions(&faucet, Some(&recipient), txid1.as_str()).await; println!("Transaction Actions:\n{:?}", tx_actions_txid1); - let fee_paid_txid1: u64 = faucet - .do_list_txsummaries() - .await - .iter() - .filter(|summary| summary.txid.to_string() == txid1) - .find_map(|summary| match &summary.kind { - ValueTransferKind::Fee { amount } => Some(*amount), - _ => None, - }) - .unwrap_or(0); - println!("Fee Paid: {}", fee_paid_txid1); + let calculated_fee_txid1 = + zingo_testutils::total_tx_value(&faucet, txid1.as_str()).await - 40_000; + println!("Fee Paid: {}", calculated_fee_txid1); let expected_fee_txid1 = 10000; // currently expected fee is always 10000 but will change to the following in zip317 @@ -3725,7 +3717,7 @@ mod basic_transactions { // )); println!("Expected Fee: {}", expected_fee_txid1); - assert_eq!(fee_paid_txid1, expected_fee_txid1 as u64); + assert_eq!(calculated_fee_txid1, expected_fee_txid1 as u64); println!( "Transaction Inputs:\n{:?}", @@ -3744,17 +3736,9 @@ mod basic_transactions { zingo_testutils::tx_actions(&faucet, Some(&recipient), txid2.as_str()).await; println!("Transaction Actions:\n{:?}", tx_actions_txid2); - let fee_paid_txid2: u64 = faucet - .do_list_txsummaries() - .await - .iter() - .filter(|summary| summary.txid.to_string() == txid2) - .find_map(|summary| match &summary.kind { - ValueTransferKind::Fee { amount } => Some(*amount), - _ => None, - }) - .unwrap_or(0); - println!("Fee Paid: {}", fee_paid_txid2); + let calculated_fee_txid2 = + zingo_testutils::total_tx_value(&faucet, txid2.as_str()).await - 40_000; + println!("Fee Paid: {}", calculated_fee_txid2); let expected_fee_txid2 = 10000; // currently expected fee is always 10000 but will change to the following in zip317 @@ -3767,7 +3751,7 @@ mod basic_transactions { // )); println!("Expected Fee: {}", expected_fee_txid2); - assert_eq!(fee_paid_txid2, expected_fee_txid2 as u64); + assert_eq!(calculated_fee_txid2, expected_fee_txid2 as u64); println!( "Transaction Inputs:\n{:?}", @@ -3786,17 +3770,9 @@ mod basic_transactions { zingo_testutils::tx_actions(&faucet, Some(&recipient), txid3.as_str()).await; println!("Transaction Actions:\n{:?}", tx_actions_txid3); - let fee_paid_txid3: u64 = faucet - .do_list_txsummaries() - .await - .iter() - .filter(|summary| summary.txid.to_string() == txid3) - .find_map(|summary| match &summary.kind { - ValueTransferKind::Fee { amount } => Some(*amount), - _ => None, - }) - .unwrap_or(0); - println!("Fee Paid: {}", fee_paid_txid3); + let calculated_fee_txid3 = + zingo_testutils::total_tx_value(&faucet, txid3.as_str()).await - 40_000; + println!("Fee Paid: {}", calculated_fee_txid3); let expected_fee_txid3 = 10000; // currently expected fee is always 10000 but will change to the following in zip317 @@ -3809,7 +3785,7 @@ mod basic_transactions { // )); println!("Expected Fee: {}", expected_fee_txid3); - assert_eq!(fee_paid_txid3, expected_fee_txid3 as u64); + assert_eq!(calculated_fee_txid3, expected_fee_txid3 as u64); let txid4 = recipient .do_send(vec![( @@ -3844,17 +3820,9 @@ mod basic_transactions { zingo_testutils::tx_actions(&recipient, Some(&faucet), txid4.as_str()).await; println!("Transaction Actions:\n{:?}", tx_actions_txid4); - let fee_paid_txid4: u64 = recipient - .do_list_txsummaries() - .await - .iter() - .filter(|summary| summary.txid.to_string() == txid4) - .find_map(|summary| match &summary.kind { - ValueTransferKind::Fee { amount } => Some(*amount), - _ => None, - }) - .unwrap_or(0); - println!("Fee Paid: {}", fee_paid_txid4); + let calculated_fee_txid4 = + zingo_testutils::total_tx_value(&recipient, txid4.as_str()).await - 60_000; + println!("Fee Paid: {}", calculated_fee_txid4); let expected_fee_txid4 = 10000; // currently expected fee is always 10000 but will change to the following in zip317 @@ -3867,7 +3835,7 @@ mod basic_transactions { // )); println!("Expected Fee: {}", expected_fee_txid4); - assert_eq!(fee_paid_txid4, expected_fee_txid4 as u64); + assert_eq!(calculated_fee_txid4, expected_fee_txid4 as u64); } #[tokio::test] @@ -3908,17 +3876,8 @@ mod basic_transactions { zingo_testutils::tx_actions(&faucet, Some(&recipient), txid1.as_str()).await; println!("Transaction Actions:\n{:?}", tx_actions_txid1); - let fee_paid_txid1: u64 = faucet - .do_list_txsummaries() - .await - .iter() - .filter(|summary| summary.txid.to_string() == txid1) - .find_map(|summary| match &summary.kind { - ValueTransferKind::Fee { amount } => Some(*amount), - _ => None, - }) - .unwrap_or(0); - println!("Fee Paid: {}", fee_paid_txid1); + let calculated_fee_txid1 = zingo_testutils::total_tx_value(&faucet, txid1.as_str()).await; + println!("Fee Paid: {}", calculated_fee_txid1); let expected_fee_txid1 = 10000; // currently expected fee is always 10000 but will change to the following in zip317 @@ -3931,7 +3890,7 @@ mod basic_transactions { // )); println!("Expected Fee: {}", expected_fee_txid1); - assert_eq!(fee_paid_txid1, expected_fee_txid1 as u64); + assert_eq!(calculated_fee_txid1, expected_fee_txid1 as u64); } #[tokio::test] @@ -3982,17 +3941,9 @@ mod basic_transactions { let tx_actions_txid1 = zingo_testutils::tx_actions(&recipient, None, txid1.as_str()).await; println!("Transaction Actions:\n{:?}", tx_actions_txid1); - let fee_paid_txid1: u64 = recipient - .do_list_txsummaries() - .await - .iter() - .filter(|summary| summary.txid.to_string() == txid1) - .find_map(|summary| match &summary.kind { - ValueTransferKind::Fee { amount } => Some(*amount), - _ => None, - }) - .unwrap_or(0); - println!("Fee Paid: {}", fee_paid_txid1); + let calculated_fee_txid1 = + zingo_testutils::total_tx_value(&recipient, txid1.as_str()).await; + println!("Fee Paid: {}", calculated_fee_txid1); let expected_fee_txid1 = 10000; // currently expected fee is always 10000 but will change to the following in zip317 @@ -4005,7 +3956,7 @@ mod basic_transactions { // )); println!("Expected Fee: {}", expected_fee_txid1); - assert_eq!(fee_paid_txid1, expected_fee_txid1 as u64); + assert_eq!(calculated_fee_txid1, expected_fee_txid1 as u64); faucet .do_send(vec![( @@ -4050,17 +4001,9 @@ mod basic_transactions { let tx_actions_txid2 = zingo_testutils::tx_actions(&recipient, None, txid2.as_str()).await; println!("Transaction Actions:\n{:?}", tx_actions_txid2); - let fee_paid_txid2: u64 = recipient - .do_list_txsummaries() - .await - .iter() - .filter(|summary| summary.txid.to_string() == txid2) - .find_map(|summary| match &summary.kind { - ValueTransferKind::Fee { amount } => Some(*amount), - _ => None, - }) - .unwrap_or(0); - println!("Fee Paid: {}", fee_paid_txid2); + let calculated_fee_txid2 = + zingo_testutils::total_tx_value(&recipient, txid2.as_str()).await; + println!("Fee Paid: {}", calculated_fee_txid2); let expected_fee_txid2 = 10000; // currently expected fee is always 10000 but will change to the following in zip317 @@ -4073,7 +4016,7 @@ mod basic_transactions { // )); println!("Expected Fee: {}", expected_fee_txid2); - assert_eq!(fee_paid_txid2, expected_fee_txid2 as u64); + assert_eq!(calculated_fee_txid2, expected_fee_txid2 as u64); } } diff --git a/zingo-testutils/src/lib.rs b/zingo-testutils/src/lib.rs index e489df84e..e6576a564 100644 --- a/zingo-testutils/src/lib.rs +++ b/zingo-testutils/src/lib.rs @@ -429,6 +429,87 @@ pub async fn tx_actions( } } +/// Returns the total transfer value of txid. +pub async fn total_tx_value(client: &LightClient, txid: &str) -> u64 { + let notes = client.do_list_notes(true).await; + + let mut tx_spend: u64 = 0; + let mut tx_change: u64 = 0; + if let JsonValue::Array(spent_utxos) = ¬es["spent_utxos"] { + for utxo in spent_utxos { + if utxo["spent"] == txid || utxo["unconfirmed_spent"] == txid { + tx_spend += utxo["value"].as_u64().unwrap_or(0); + } + } + } + if let JsonValue::Array(pending_utxos) = ¬es["pending_utxos"] { + for utxo in pending_utxos { + if utxo["spent"] == txid || utxo["unconfirmed_spent"] == txid { + tx_spend += utxo["value"].as_u64().unwrap_or(0); + } else if utxo["created_in_txid"] == txid { + tx_change += utxo["value"].as_u64().unwrap_or(0); + } + } + } + if let JsonValue::Array(unspent_utxos) = ¬es["utxos"] { + for utxo in unspent_utxos { + if utxo["created_in_txid"] == txid { + tx_change += utxo["value"].as_u64().unwrap_or(0); + } + } + } + + if let JsonValue::Array(spent_sapling_notes) = ¬es["spent_sapling_notes"] { + for note in spent_sapling_notes { + if note["spent"] == txid || note["unconfirmed_spent"] == txid { + tx_spend += note["value"].as_u64().unwrap_or(0); + } + } + } + if let JsonValue::Array(pending_sapling_notes) = ¬es["pending_sapling_notes"] { + for note in pending_sapling_notes { + if note["spent"] == txid || note["unconfirmed_spent"] == txid { + tx_spend += note["value"].as_u64().unwrap_or(0); + } else if note["created_in_txid"] == txid { + tx_change += note["value"].as_u64().unwrap_or(0); + } + } + } + if let JsonValue::Array(unspent_sapling_notes) = ¬es["unspent_sapling_notes"] { + for note in unspent_sapling_notes { + if note["created_in_txid"] == txid { + tx_change += note["value"].as_u64().unwrap_or(0); + } + } + } + + if let JsonValue::Array(spent_orchard_notes) = ¬es["spent_orchard_notes"] { + for note in spent_orchard_notes { + if note["spent"] == txid || note["unconfirmed_spent"] == txid { + tx_spend += note["value"].as_u64().unwrap_or(0); + } + } + } + if let JsonValue::Array(pending_orchard_notes) = ¬es["pending_orchard_notes"] { + for note in pending_orchard_notes { + if note["spent"] == txid || note["unconfirmed_spent"] == txid { + tx_spend += note["value"].as_u64().unwrap_or(0); + } else if note["created_in_txid"] == txid { + tx_change += note["value"].as_u64().unwrap_or(0); + } + } + } + if let JsonValue::Array(unspent_orchard_notes) = ¬es["unspent_orchard_notes"] { + for note in unspent_orchard_notes { + if note["created_in_txid"] == txid { + tx_change += note["value"].as_u64().unwrap_or(0); + } + } + } + + tx_spend - tx_change +} + pub mod scenarios { //! In practice there are several common scenarios for which helpers are provided. //! These scenarios vary in the configuration of clients in use. Most scenarios From 6b2d8209d634ac1a5d921c63d210c62b5905d68d Mon Sep 17 00:00:00 2001 From: idky137 Date: Wed, 10 Apr 2024 16:44:37 +0100 Subject: [PATCH 14/20] tidied helper functions --- zingo-testutils/src/lib.rs | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/zingo-testutils/src/lib.rs b/zingo-testutils/src/lib.rs index e6576a564..2b2185f16 100644 --- a/zingo-testutils/src/lib.rs +++ b/zingo-testutils/src/lib.rs @@ -273,8 +273,8 @@ pub async fn tx_inputs(client: &LightClient, txid: &str) -> TxNotes { } } } - if let JsonValue::Array(spent_utxos) = ¬es["pending_utxos"] { - for utxo in spent_utxos { + if let JsonValue::Array(pending_utxos) = ¬es["pending_utxos"] { + for utxo in pending_utxos { if utxo["spent"] == txid || utxo["unconfirmed_spent"] == txid { transparent_notes += 1; } @@ -288,8 +288,8 @@ pub async fn tx_inputs(client: &LightClient, txid: &str) -> TxNotes { } } } - if let JsonValue::Array(spent_sapling_notes) = ¬es["pending_sapling_notes"] { - for note in spent_sapling_notes { + if let JsonValue::Array(pending_sapling_notes) = ¬es["pending_sapling_notes"] { + for note in pending_sapling_notes { if note["spent"] == txid || note["unconfirmed_spent"] == txid { sapling_notes += 1; } @@ -303,8 +303,8 @@ pub async fn tx_inputs(client: &LightClient, txid: &str) -> TxNotes { } } } - if let JsonValue::Array(spent_orchard_notes) = ¬es["pending_orchard_notes"] { - for note in spent_orchard_notes { + if let JsonValue::Array(pending_orchard_notes) = ¬es["pending_orchard_notes"] { + for note in pending_orchard_notes { if note["spent"] == txid || note["unconfirmed_spent"] == txid { orchard_notes += 1; } @@ -326,48 +326,48 @@ pub async fn tx_outputs(client: &LightClient, txid: &str) -> TxNotes { let mut sapling_notes = 0; let mut orchard_notes = 0; - if let JsonValue::Array(spent_utxos) = ¬es["utxos"] { - for utxo in spent_utxos { + if let JsonValue::Array(unspent_utxos) = ¬es["utxos"] { + for utxo in unspent_utxos { if utxo["created_in_txid"] == txid { transparent_notes += 1; } } } - if let JsonValue::Array(spent_utxos) = ¬es["pending_utxos"] { - for utxo in spent_utxos { + if let JsonValue::Array(pending_utxos) = ¬es["pending_utxos"] { + for utxo in pending_utxos { if utxo["created_in_txid"] == txid { transparent_notes += 1; } } } - if let JsonValue::Array(spent_sapling_notes) = ¬es["unspent_sapling_notes"] { - for note in spent_sapling_notes { + if let JsonValue::Array(unspent_sapling_notes) = ¬es["unspent_sapling_notes"] { + for note in unspent_sapling_notes { if note["created_in_txid"] == txid { sapling_notes += 1; } } } - if let JsonValue::Array(spent_sapling_notes) = ¬es["pending_sapling_notes"] { - for note in spent_sapling_notes { + if let JsonValue::Array(pending_sapling_notes) = ¬es["pending_sapling_notes"] { + for note in pending_sapling_notes { if note["created_in_txid"] == txid { sapling_notes += 1; } } } - if let JsonValue::Array(spent_orchard_notes) = ¬es["unspent_orchard_notes"] { - for note in spent_orchard_notes { + if let JsonValue::Array(unspent_orchard_notes) = ¬es["unspent_orchard_notes"] { + for note in unspent_orchard_notes { if note["created_in_txid"] == txid { orchard_notes += 1; } } } - if let JsonValue::Array(spent_orchard_notes) = ¬es["pending_orchard_notes"] { - for note in spent_orchard_notes { + if let JsonValue::Array(pending_orchard_notes) = ¬es["pending_orchard_notes"] { + for note in pending_orchard_notes { if note["created_in_txid"] == txid { orchard_notes += 1; } From 6c5615b77bb09ca06f6abc28093f32aa5d3358b4 Mon Sep 17 00:00:00 2001 From: idky137 Date: Wed, 10 Apr 2024 16:59:39 +0100 Subject: [PATCH 15/20] feature gate expected fee calculation under zip317 --- integration-tests/Cargo.toml | 3 + integration-tests/tests/integrations.rs | 127 +++++++++++++----------- 2 files changed, 70 insertions(+), 60 deletions(-) diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index f0bb6b14d..cbf04344c 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -3,6 +3,9 @@ name = "integration-tests" version = "0.2.0" edition = "2021" +[features] +zip317 = [] + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] zingolib = { path = "../zingolib", features = ["test"] } diff --git a/integration-tests/tests/integrations.rs b/integration-tests/tests/integrations.rs index fff35c5b2..c12932fb7 100644 --- a/integration-tests/tests/integrations.rs +++ b/integration-tests/tests/integrations.rs @@ -3598,11 +3598,11 @@ mod slow { } mod basic_transactions { + #[cfg(feature = "zip317")] + use std::cmp; + use zingo_testutils::scenarios; - use zingolib::{ - get_base_address, - wallet::{data::summaries::ValueTransferKind, Pool}, - }; + use zingolib::{get_base_address, wallet::Pool}; #[tokio::test] async fn send_and_sync_with_multiple_notes_no_panic() { @@ -3706,15 +3706,16 @@ mod basic_transactions { zingo_testutils::total_tx_value(&faucet, txid1.as_str()).await - 40_000; println!("Fee Paid: {}", calculated_fee_txid1); + #[cfg(not(feature = "zip317"))] let expected_fee_txid1 = 10000; - // currently expected fee is always 10000 but will change to the following in zip317 - // let expected_fee_txid1 = 5000 - // * (cmp::max( - // 2, - // tx_actions_txid1.transparent_tx_actions - // + tx_actions_txid1.sapling_tx_actions - // + tx_actions_txid1.orchard_tx_actions, - // )); + #[cfg(feature = "zip317")] + let expected_fee_txid1 = 5000 + * (cmp::max( + 2, + tx_actions_txid1.transparent_tx_actions + + tx_actions_txid1.sapling_tx_actions + + tx_actions_txid1.orchard_tx_actions, + )); println!("Expected Fee: {}", expected_fee_txid1); assert_eq!(calculated_fee_txid1, expected_fee_txid1 as u64); @@ -3740,15 +3741,16 @@ mod basic_transactions { zingo_testutils::total_tx_value(&faucet, txid2.as_str()).await - 40_000; println!("Fee Paid: {}", calculated_fee_txid2); + #[cfg(not(feature = "zip317"))] let expected_fee_txid2 = 10000; - // currently expected fee is always 10000 but will change to the following in zip317 - // let expected_fee_txid2 = 5000 - // * (cmp::max( - // 2, - // tx_actions_txid2.transparent_tx_actions - // + tx_actions_txid2.sapling_tx_actions - // + tx_actions_txid2.orchard_tx_actions, - // )); + #[cfg(feature = "zip317")] + let expected_fee_txid2 = 5000 + * (cmp::max( + 2, + tx_actions_txid2.transparent_tx_actions + + tx_actions_txid2.sapling_tx_actions + + tx_actions_txid2.orchard_tx_actions, + )); println!("Expected Fee: {}", expected_fee_txid2); assert_eq!(calculated_fee_txid2, expected_fee_txid2 as u64); @@ -3774,15 +3776,16 @@ mod basic_transactions { zingo_testutils::total_tx_value(&faucet, txid3.as_str()).await - 40_000; println!("Fee Paid: {}", calculated_fee_txid3); + #[cfg(not(feature = "zip317"))] let expected_fee_txid3 = 10000; - // currently expected fee is always 10000 but will change to the following in zip317 - // let expected_fee_txid3 = 5000 - // * (cmp::max( - // 2, - // tx_actions_txid3.transparent_tx_actions - // + tx_actions_txid3.sapling_tx_actions - // + tx_actions_txid3.orchard_tx_actions, - // )); + #[cfg(feature = "zip317")] + let expected_fee_txid3 = 5000 + * (cmp::max( + 2, + tx_actions_txid3.transparent_tx_actions + + tx_actions_txid3.sapling_tx_actions + + tx_actions_txid3.orchard_tx_actions, + )); println!("Expected Fee: {}", expected_fee_txid3); assert_eq!(calculated_fee_txid3, expected_fee_txid3 as u64); @@ -3824,15 +3827,16 @@ mod basic_transactions { zingo_testutils::total_tx_value(&recipient, txid4.as_str()).await - 60_000; println!("Fee Paid: {}", calculated_fee_txid4); + #[cfg(not(feature = "zip317"))] let expected_fee_txid4 = 10000; - // currently expected fee is always 10000 but will change to the following in zip317 - // let expected_fee_txid4 = 5000 - // * (cmp::max( - // 2, - // tx_actions_txid4.transparent_tx_actions - // + tx_actions_txid4.sapling_tx_actions - // + tx_actions_txid4.orchard_tx_actions, - // )); + #[cfg(feature = "zip317")] + let expected_fee_txid4 = 5000 + * (cmp::max( + 2, + tx_actions_txid4.transparent_tx_actions + + tx_actions_txid4.sapling_tx_actions + + tx_actions_txid4.orchard_tx_actions, + )); println!("Expected Fee: {}", expected_fee_txid4); assert_eq!(calculated_fee_txid4, expected_fee_txid4 as u64); @@ -3879,15 +3883,16 @@ mod basic_transactions { let calculated_fee_txid1 = zingo_testutils::total_tx_value(&faucet, txid1.as_str()).await; println!("Fee Paid: {}", calculated_fee_txid1); + #[cfg(not(feature = "zip317"))] let expected_fee_txid1 = 10000; - // currently expected fee is always 10000 but will change to the following in zip317 - // let expected_fee_txid1 = 5000 - // * (cmp::max( - // 2, - // tx_actions_txid1.transparent_tx_actions - // + tx_actions_txid1.sapling_tx_actions - // + tx_actions_txid1.orchard_tx_actions, - // )); + #[cfg(feature = "zip317")] + let expected_fee_txid1 = 5000 + * (cmp::max( + 2, + tx_actions_txid1.transparent_tx_actions + + tx_actions_txid1.sapling_tx_actions + + tx_actions_txid1.orchard_tx_actions, + )); println!("Expected Fee: {}", expected_fee_txid1); assert_eq!(calculated_fee_txid1, expected_fee_txid1 as u64); @@ -3945,15 +3950,16 @@ mod basic_transactions { zingo_testutils::total_tx_value(&recipient, txid1.as_str()).await; println!("Fee Paid: {}", calculated_fee_txid1); + #[cfg(not(feature = "zip317"))] let expected_fee_txid1 = 10000; - // currently expected fee is always 10000 but will change to the following in zip317 - // let expected_fee_txid1 = 5000 - // * (cmp::max( - // 2, - // tx_actions_txid1.transparent_tx_actions - // + tx_actions_txid1.sapling_tx_actions - // + tx_actions_txid1.orchard_tx_actions, - // )); + #[cfg(feature = "zip317")] + let expected_fee_txid1 = 5000 + * (cmp::max( + 2, + tx_actions_txid1.transparent_tx_actions + + tx_actions_txid1.sapling_tx_actions + + tx_actions_txid1.orchard_tx_actions, + )); println!("Expected Fee: {}", expected_fee_txid1); assert_eq!(calculated_fee_txid1, expected_fee_txid1 as u64); @@ -4005,15 +4011,16 @@ mod basic_transactions { zingo_testutils::total_tx_value(&recipient, txid2.as_str()).await; println!("Fee Paid: {}", calculated_fee_txid2); + #[cfg(not(feature = "zip317"))] let expected_fee_txid2 = 10000; - // currently expected fee is always 10000 but will change to the following in zip317 - // let expected_fee_txid2 = 5000 - // * (cmp::max( - // 2, - // tx_actions_txid2.transparent_tx_actions - // + tx_actions_txid2.sapling_tx_actions - // + tx_actions_txid2.orchard_tx_actions, - // )); + #[cfg(feature = "zip317")] + let expected_fee_txid2 = 5000 + * (cmp::max( + 2, + tx_actions_txid2.transparent_tx_actions + + tx_actions_txid2.sapling_tx_actions + + tx_actions_txid2.orchard_tx_actions, + )); println!("Expected Fee: {}", expected_fee_txid2); assert_eq!(calculated_fee_txid2, expected_fee_txid2 as u64); From 27144bd415d04e2d2c5ce43f350334d4480b975f Mon Sep 17 00:00:00 2001 From: idky137 Date: Thu, 11 Apr 2024 08:24:43 +0100 Subject: [PATCH 16/20] changed TxNotes to TxNotesCount --- zingo-testutils/src/lib.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/zingo-testutils/src/lib.rs b/zingo-testutils/src/lib.rs index 2b2185f16..360530c94 100644 --- a/zingo-testutils/src/lib.rs +++ b/zingo-testutils/src/lib.rs @@ -245,7 +245,7 @@ pub async fn load_wallet( } #[derive(Debug)] -pub struct TxNotes { +pub struct TxNotesCount { pub transparent_tx_notes: usize, pub sapling_tx_notes: usize, pub orchard_tx_notes: usize, @@ -259,7 +259,7 @@ pub struct TxActions { } /// Returnes number of notes used as inputs for txid as TxActions (transparent_notes, sapling_notes, orchard_notes). -pub async fn tx_inputs(client: &LightClient, txid: &str) -> TxNotes { +pub async fn tx_inputs(client: &LightClient, txid: &str) -> TxNotesCount { let notes = client.do_list_notes(true).await; let mut transparent_notes = 0; @@ -311,7 +311,7 @@ pub async fn tx_inputs(client: &LightClient, txid: &str) -> TxNotes { } } - TxNotes { + TxNotesCount { transparent_tx_notes: transparent_notes, sapling_tx_notes: sapling_notes, orchard_tx_notes: orchard_notes, @@ -319,7 +319,7 @@ pub async fn tx_inputs(client: &LightClient, txid: &str) -> TxNotes { } /// Returnes number of notes created in txid as TxActions (transparent_notes, sapling_notes, orchard_notes). -pub async fn tx_outputs(client: &LightClient, txid: &str) -> TxNotes { +pub async fn tx_outputs(client: &LightClient, txid: &str) -> TxNotesCount { let notes = client.do_list_notes(true).await; let mut transparent_notes = 0; @@ -374,7 +374,7 @@ pub async fn tx_outputs(client: &LightClient, txid: &str) -> TxNotes { } } - TxNotes { + TxNotesCount { transparent_tx_notes: transparent_notes, sapling_tx_notes: sapling_notes, orchard_tx_notes: orchard_notes, @@ -391,7 +391,7 @@ pub async fn tx_actions( let tx_outs = if let Some(rec) = recipient { tx_outputs(rec, txid).await } else { - TxNotes { + TxNotesCount { transparent_tx_notes: 0, sapling_tx_notes: 0, orchard_tx_notes: 0, From 8719fad0ce85b5dfbd55c3e919132c9c57bd5ff8 Mon Sep 17 00:00:00 2001 From: idky137 Date: Thu, 11 Apr 2024 08:33:31 +0100 Subject: [PATCH 17/20] fixed for CI --- integration-tests/tests/integrations.rs | 122 +++++++++++------------- 1 file changed, 56 insertions(+), 66 deletions(-) diff --git a/integration-tests/tests/integrations.rs b/integration-tests/tests/integrations.rs index c12932fb7..1993e9a5d 100644 --- a/integration-tests/tests/integrations.rs +++ b/integration-tests/tests/integrations.rs @@ -3598,9 +3598,6 @@ mod slow { } mod basic_transactions { - #[cfg(feature = "zip317")] - use std::cmp; - use zingo_testutils::scenarios; use zingolib::{get_base_address, wallet::Pool}; @@ -3706,16 +3703,15 @@ mod basic_transactions { zingo_testutils::total_tx_value(&faucet, txid1.as_str()).await - 40_000; println!("Fee Paid: {}", calculated_fee_txid1); - #[cfg(not(feature = "zip317"))] let expected_fee_txid1 = 10000; - #[cfg(feature = "zip317")] - let expected_fee_txid1 = 5000 - * (cmp::max( - 2, - tx_actions_txid1.transparent_tx_actions - + tx_actions_txid1.sapling_tx_actions - + tx_actions_txid1.orchard_tx_actions, - )); + // currently expected fee is always 10000 but will change to the following in zip317 + // let expected_fee_txid1 = 5000 + // * (cmp::max( + // 2, + // tx_actions_txid1.transparent_tx_actions + // + tx_actions_txid1.sapling_tx_actions + // + tx_actions_txid1.orchard_tx_actions, + // )); println!("Expected Fee: {}", expected_fee_txid1); assert_eq!(calculated_fee_txid1, expected_fee_txid1 as u64); @@ -3741,16 +3737,15 @@ mod basic_transactions { zingo_testutils::total_tx_value(&faucet, txid2.as_str()).await - 40_000; println!("Fee Paid: {}", calculated_fee_txid2); - #[cfg(not(feature = "zip317"))] let expected_fee_txid2 = 10000; - #[cfg(feature = "zip317")] - let expected_fee_txid2 = 5000 - * (cmp::max( - 2, - tx_actions_txid2.transparent_tx_actions - + tx_actions_txid2.sapling_tx_actions - + tx_actions_txid2.orchard_tx_actions, - )); + // currently expected fee is always 10000 but will change to the following in zip317 + // let expected_fee_txid2 = 5000 + // * (cmp::max( + // 2, + // tx_actions_txid2.transparent_tx_actions + // + tx_actions_txid2.sapling_tx_actions + // + tx_actions_txid2.orchard_tx_actions, + // )); println!("Expected Fee: {}", expected_fee_txid2); assert_eq!(calculated_fee_txid2, expected_fee_txid2 as u64); @@ -3776,16 +3771,15 @@ mod basic_transactions { zingo_testutils::total_tx_value(&faucet, txid3.as_str()).await - 40_000; println!("Fee Paid: {}", calculated_fee_txid3); - #[cfg(not(feature = "zip317"))] let expected_fee_txid3 = 10000; - #[cfg(feature = "zip317")] - let expected_fee_txid3 = 5000 - * (cmp::max( - 2, - tx_actions_txid3.transparent_tx_actions - + tx_actions_txid3.sapling_tx_actions - + tx_actions_txid3.orchard_tx_actions, - )); + // currently expected fee is always 10000 but will change to the following in zip317 + // let expected_fee_txid3 = 5000 + // * (cmp::max( + // 2, + // tx_actions_txid3.transparent_tx_actions + // + tx_actions_txid3.sapling_tx_actions + // + tx_actions_txid3.orchard_tx_actions, + // )); println!("Expected Fee: {}", expected_fee_txid3); assert_eq!(calculated_fee_txid3, expected_fee_txid3 as u64); @@ -3827,16 +3821,15 @@ mod basic_transactions { zingo_testutils::total_tx_value(&recipient, txid4.as_str()).await - 60_000; println!("Fee Paid: {}", calculated_fee_txid4); - #[cfg(not(feature = "zip317"))] let expected_fee_txid4 = 10000; - #[cfg(feature = "zip317")] - let expected_fee_txid4 = 5000 - * (cmp::max( - 2, - tx_actions_txid4.transparent_tx_actions - + tx_actions_txid4.sapling_tx_actions - + tx_actions_txid4.orchard_tx_actions, - )); + // currently expected fee is always 10000 but will change to the following in zip317 + // let expected_fee_txid4 = 5000 + // * (cmp::max( + // 2, + // tx_actions_txid4.transparent_tx_actions + // + tx_actions_txid4.sapling_tx_actions + // + tx_actions_txid4.orchard_tx_actions, + // )); println!("Expected Fee: {}", expected_fee_txid4); assert_eq!(calculated_fee_txid4, expected_fee_txid4 as u64); @@ -3883,16 +3876,15 @@ mod basic_transactions { let calculated_fee_txid1 = zingo_testutils::total_tx_value(&faucet, txid1.as_str()).await; println!("Fee Paid: {}", calculated_fee_txid1); - #[cfg(not(feature = "zip317"))] let expected_fee_txid1 = 10000; - #[cfg(feature = "zip317")] - let expected_fee_txid1 = 5000 - * (cmp::max( - 2, - tx_actions_txid1.transparent_tx_actions - + tx_actions_txid1.sapling_tx_actions - + tx_actions_txid1.orchard_tx_actions, - )); + // currently expected fee is always 10000 but will change to the following in zip317 + // let expected_fee_txid1 = 5000 + // * (cmp::max( + // 2, + // tx_actions_txid1.transparent_tx_actions + // + tx_actions_txid1.sapling_tx_actions + // + tx_actions_txid1.orchard_tx_actions, + // )); println!("Expected Fee: {}", expected_fee_txid1); assert_eq!(calculated_fee_txid1, expected_fee_txid1 as u64); @@ -3950,16 +3942,15 @@ mod basic_transactions { zingo_testutils::total_tx_value(&recipient, txid1.as_str()).await; println!("Fee Paid: {}", calculated_fee_txid1); - #[cfg(not(feature = "zip317"))] let expected_fee_txid1 = 10000; - #[cfg(feature = "zip317")] - let expected_fee_txid1 = 5000 - * (cmp::max( - 2, - tx_actions_txid1.transparent_tx_actions - + tx_actions_txid1.sapling_tx_actions - + tx_actions_txid1.orchard_tx_actions, - )); + // currently expected fee is always 10000 but will change to the following in zip317 + // let expected_fee_txid1 = 5000 + // * (cmp::max( + // 2, + // tx_actions_txid1.transparent_tx_actions + // + tx_actions_txid1.sapling_tx_actions + // + tx_actions_txid1.orchard_tx_actions, + // )); println!("Expected Fee: {}", expected_fee_txid1); assert_eq!(calculated_fee_txid1, expected_fee_txid1 as u64); @@ -4011,16 +4002,15 @@ mod basic_transactions { zingo_testutils::total_tx_value(&recipient, txid2.as_str()).await; println!("Fee Paid: {}", calculated_fee_txid2); - #[cfg(not(feature = "zip317"))] let expected_fee_txid2 = 10000; - #[cfg(feature = "zip317")] - let expected_fee_txid2 = 5000 - * (cmp::max( - 2, - tx_actions_txid2.transparent_tx_actions - + tx_actions_txid2.sapling_tx_actions - + tx_actions_txid2.orchard_tx_actions, - )); + // currently expected fee is always 10000 but will change to the following in zip317 + // let expected_fee_txid2 = 5000 + // * (cmp::max( + // 2, + // tx_actions_txid2.transparent_tx_actions + // + tx_actions_txid2.sapling_tx_actions + // + tx_actions_txid2.orchard_tx_actions, + // )); println!("Expected Fee: {}", expected_fee_txid2); assert_eq!(calculated_fee_txid2, expected_fee_txid2 as u64); From 6e3cb8ba9a6683a5ea58d34585ac1c1fef7f9684 Mon Sep 17 00:00:00 2001 From: idky137 Date: Thu, 11 Apr 2024 18:20:22 +0100 Subject: [PATCH 18/20] review changes --- zingo-testutils/src/lib.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/zingo-testutils/src/lib.rs b/zingo-testutils/src/lib.rs index 360530c94..c9f7aef4b 100644 --- a/zingo-testutils/src/lib.rs +++ b/zingo-testutils/src/lib.rs @@ -258,7 +258,7 @@ pub struct TxActions { pub orchard_tx_actions: usize, } -/// Returnes number of notes used as inputs for txid as TxActions (transparent_notes, sapling_notes, orchard_notes). +/// Returns number of notes used as inputs for txid as TxActions (transparent_notes, sapling_notes, orchard_notes). pub async fn tx_inputs(client: &LightClient, txid: &str) -> TxNotesCount { let notes = client.do_list_notes(true).await; @@ -318,7 +318,7 @@ pub async fn tx_inputs(client: &LightClient, txid: &str) -> TxNotesCount { } } -/// Returnes number of notes created in txid as TxActions (transparent_notes, sapling_notes, orchard_notes). +/// Returns number of notes created in txid as TxActions (transparent_notes, sapling_notes, orchard_notes). pub async fn tx_outputs(client: &LightClient, txid: &str) -> TxNotesCount { let notes = client.do_list_notes(true).await; @@ -438,23 +438,23 @@ pub async fn total_tx_value(client: &LightClient, txid: &str) -> u64 { if let JsonValue::Array(spent_utxos) = ¬es["spent_utxos"] { for utxo in spent_utxos { if utxo["spent"] == txid || utxo["unconfirmed_spent"] == txid { - tx_spend += utxo["value"].as_u64().unwrap_or(0); + tx_spend += utxo["value"].as_u64().unwrap(); } } } if let JsonValue::Array(pending_utxos) = ¬es["pending_utxos"] { for utxo in pending_utxos { if utxo["spent"] == txid || utxo["unconfirmed_spent"] == txid { - tx_spend += utxo["value"].as_u64().unwrap_or(0); + tx_spend += utxo["value"].as_u64().unwrap(); } else if utxo["created_in_txid"] == txid { - tx_change += utxo["value"].as_u64().unwrap_or(0); + tx_change += utxo["value"].as_u64().unwrap(); } } } if let JsonValue::Array(unspent_utxos) = ¬es["utxos"] { for utxo in unspent_utxos { if utxo["created_in_txid"] == txid { - tx_change += utxo["value"].as_u64().unwrap_or(0); + tx_change += utxo["value"].as_u64().unwrap(); } } } @@ -462,23 +462,23 @@ pub async fn total_tx_value(client: &LightClient, txid: &str) -> u64 { if let JsonValue::Array(spent_sapling_notes) = ¬es["spent_sapling_notes"] { for note in spent_sapling_notes { if note["spent"] == txid || note["unconfirmed_spent"] == txid { - tx_spend += note["value"].as_u64().unwrap_or(0); + tx_spend += note["value"].as_u64().unwrap(); } } } if let JsonValue::Array(pending_sapling_notes) = ¬es["pending_sapling_notes"] { for note in pending_sapling_notes { if note["spent"] == txid || note["unconfirmed_spent"] == txid { - tx_spend += note["value"].as_u64().unwrap_or(0); + tx_spend += note["value"].as_u64().unwrap(); } else if note["created_in_txid"] == txid { - tx_change += note["value"].as_u64().unwrap_or(0); + tx_change += note["value"].as_u64().unwrap(); } } } if let JsonValue::Array(unspent_sapling_notes) = ¬es["unspent_sapling_notes"] { for note in unspent_sapling_notes { if note["created_in_txid"] == txid { - tx_change += note["value"].as_u64().unwrap_or(0); + tx_change += note["value"].as_u64().unwrap(); } } } @@ -486,23 +486,23 @@ pub async fn total_tx_value(client: &LightClient, txid: &str) -> u64 { if let JsonValue::Array(spent_orchard_notes) = ¬es["spent_orchard_notes"] { for note in spent_orchard_notes { if note["spent"] == txid || note["unconfirmed_spent"] == txid { - tx_spend += note["value"].as_u64().unwrap_or(0); + tx_spend += note["value"].as_u64().unwrap(); } } } if let JsonValue::Array(pending_orchard_notes) = ¬es["pending_orchard_notes"] { for note in pending_orchard_notes { if note["spent"] == txid || note["unconfirmed_spent"] == txid { - tx_spend += note["value"].as_u64().unwrap_or(0); + tx_spend += note["value"].as_u64().unwrap(); } else if note["created_in_txid"] == txid { - tx_change += note["value"].as_u64().unwrap_or(0); + tx_change += note["value"].as_u64().unwrap(); } } } if let JsonValue::Array(unspent_orchard_notes) = ¬es["unspent_orchard_notes"] { for note in unspent_orchard_notes { if note["created_in_txid"] == txid { - tx_change += note["value"].as_u64().unwrap_or(0); + tx_change += note["value"].as_u64().unwrap(); } } } From d58d2472bddc7191a3c5b45ed7fda94c393b682c Mon Sep 17 00:00:00 2001 From: idky137 Date: Fri, 12 Apr 2024 08:46:14 +0100 Subject: [PATCH 19/20] changed TxActions to TxActionsCount --- zingo-testutils/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/zingo-testutils/src/lib.rs b/zingo-testutils/src/lib.rs index c9f7aef4b..397adad11 100644 --- a/zingo-testutils/src/lib.rs +++ b/zingo-testutils/src/lib.rs @@ -252,7 +252,7 @@ pub struct TxNotesCount { } #[derive(Debug)] -pub struct TxActions { +pub struct TxActionsCount { pub transparent_tx_actions: usize, pub sapling_tx_actions: usize, pub orchard_tx_actions: usize, @@ -386,7 +386,7 @@ pub async fn tx_actions( sender: &LightClient, recipient: Option<&LightClient>, txid: &str, -) -> TxActions { +) -> TxActionsCount { let tx_ins = tx_inputs(sender, txid).await; let tx_outs = if let Some(rec) = recipient { tx_outputs(rec, txid).await @@ -419,7 +419,7 @@ pub async fn tx_actions( calculated_orchard_tx_actions }; - TxActions { + TxActionsCount { transparent_tx_actions: cmp::max( tx_ins.transparent_tx_notes, tx_outs.transparent_tx_notes + tx_change.transparent_tx_notes, From 90e1428ced4de263c21806a84d014f39563de69d Mon Sep 17 00:00:00 2001 From: idky137 Date: Fri, 12 Apr 2024 15:34:53 +0100 Subject: [PATCH 20/20] spelling mistakes --- zingo-testutils/src/lib.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/zingo-testutils/src/lib.rs b/zingo-testutils/src/lib.rs index 397adad11..aa807e511 100644 --- a/zingo-testutils/src/lib.rs +++ b/zingo-testutils/src/lib.rs @@ -244,21 +244,29 @@ pub async fn load_wallet( ) } +/// Number of notes created and consumed in a transaction. #[derive(Debug)] pub struct TxNotesCount { + /// Transparent notes in transaction. pub transparent_tx_notes: usize, + /// Sapling notes in transaction. pub sapling_tx_notes: usize, + /// Orchard notes in transaction. pub orchard_tx_notes: usize, } +/// Number of logical actions in a transaction #[derive(Debug)] pub struct TxActionsCount { + /// Transparent actions in transaction pub transparent_tx_actions: usize, + /// Sapling actions in transaction pub sapling_tx_actions: usize, + /// Orchard notes in transaction pub orchard_tx_actions: usize, } -/// Returns number of notes used as inputs for txid as TxActions (transparent_notes, sapling_notes, orchard_notes). +/// Returns number of notes used as inputs for txid as TxNotesCount (transparent_notes, sapling_notes, orchard_notes). pub async fn tx_inputs(client: &LightClient, txid: &str) -> TxNotesCount { let notes = client.do_list_notes(true).await; @@ -318,7 +326,7 @@ pub async fn tx_inputs(client: &LightClient, txid: &str) -> TxNotesCount { } } -/// Returns number of notes created in txid as TxActions (transparent_notes, sapling_notes, orchard_notes). +/// Returns number of notes created in txid as TxNotesCount (transparent_notes, sapling_notes, orchard_notes). pub async fn tx_outputs(client: &LightClient, txid: &str) -> TxNotesCount { let notes = client.do_list_notes(true).await; @@ -381,7 +389,7 @@ pub async fn tx_outputs(client: &LightClient, txid: &str) -> TxNotesCount { } } -/// Returns total actions for txid. +/// Returns total actions for txid as TxActionsCount. pub async fn tx_actions( sender: &LightClient, recipient: Option<&LightClient>,