From e468ccbfea6fa377a0c17012cb0f94e2698888d0 Mon Sep 17 00:00:00 2001 From: fluidvanadium Date: Mon, 8 Jul 2024 19:28:37 +0000 Subject: [PATCH 1/7] add with_assertions mempool parameter --- .../src/chain_generics/fixtures.rs | 66 ++++++++++++------- .../src/chain_generics/with_assertions.rs | 33 ++++++---- 2 files changed, 63 insertions(+), 36 deletions(-) diff --git a/zingo-testutils/src/chain_generics/fixtures.rs b/zingo-testutils/src/chain_generics/fixtures.rs index 65ab70b78..3ee1ce02f 100644 --- a/zingo-testutils/src/chain_generics/fixtures.rs +++ b/zingo-testutils/src/chain_generics/fixtures.rs @@ -31,7 +31,7 @@ where println!("client is ready to send"); let recipient = environment.create_client().await; - with_assertions::propose_send_bump_sync_recipient( + with_assertions::propose_send_bump_sync_all_recipients( &mut environment, &sender, vec![ @@ -49,6 +49,7 @@ where ), (&sender, PoolType::Transparent, send_value_self, None), ], + false, ) .await; assert_eq!(sender.value_transfers().await.0.len(), 3); @@ -70,10 +71,11 @@ where ValueTransferKind::Received ); - with_assertions::propose_send_bump_sync_recipient( + with_assertions::propose_send_bump_sync_all_recipients( &mut environment, &sender, vec![(&sender, PoolType::Shielded(Orchard), send_value_self, None)], + false, ) .await; assert_eq!(sender.value_transfers().await.0.len(), 4); @@ -82,7 +84,7 @@ where ValueTransferKind::SendToSelf ); - with_assertions::propose_shield_bump_sync(&mut environment, &sender).await; + with_assertions::propose_shield_bump_sync(&mut environment, &sender, false).await; assert_eq!(sender.value_transfers().await.0.len(), 5); assert_eq!( sender.value_transfers().await.0[4].kind(), @@ -129,10 +131,11 @@ where println!("recipient ready"); - let recorded_fee = with_assertions::propose_send_bump_sync_recipient( + let recorded_fee = with_assertions::propose_send_bump_sync_all_recipients( &mut environment, &sender, vec![(&recipient, pooltype, send_value, None)], + false, ) .await; @@ -149,13 +152,14 @@ where let secondary = environment.create_client().await; assert_eq!( - with_assertions::propose_send_bump_sync_recipient( + with_assertions::propose_send_bump_sync_all_recipients( &mut environment, &primary, vec![ (&secondary, Shielded(Orchard), 1, None), (&secondary, Shielded(Orchard), 29_999, None) - ] + ], + false, ) .await, 3 * MARGINAL_FEE.into_u64() @@ -175,28 +179,30 @@ where for _ in 0..n { assert_eq!( - with_assertions::propose_send_bump_sync_recipient( + with_assertions::propose_send_bump_sync_all_recipients( &mut environment, &primary, vec![ (&secondary, Transparent, 100_000, None), (&secondary, Transparent, 4_000, None) ], + false, ) .await, MARGINAL_FEE.into_u64() * 4 ); assert_eq!( - with_assertions::propose_shield_bump_sync(&mut environment, &secondary).await, + with_assertions::propose_shield_bump_sync(&mut environment, &secondary, false,).await, MARGINAL_FEE.into_u64() * 3 ); assert_eq!( - with_assertions::propose_send_bump_sync_recipient( + with_assertions::propose_send_bump_sync_all_recipients( &mut environment, &secondary, vec![(&primary, Shielded(Orchard), 50_000, None)], + false, ) .await, MARGINAL_FEE.into_u64() * 2 @@ -214,23 +220,25 @@ where let secondary = environment.create_client().await; assert_eq!( - with_assertions::propose_send_bump_sync_recipient( + with_assertions::propose_send_bump_sync_all_recipients( &mut environment, &primary, vec![ (&secondary, Shielded(Orchard), 1, None), (&secondary, Shielded(Orchard), 99_999, None) - ] + ], + false, ) .await, 3 * MARGINAL_FEE.into_u64() ); assert_eq!( - with_assertions::propose_send_bump_sync_recipient( + with_assertions::propose_send_bump_sync_all_recipients( &mut environment, &secondary, - vec![(&primary, Shielded(Orchard), 90_000, None)] + vec![(&primary, Shielded(Orchard), 90_000, None)], + false, ) .await, 2 * MARGINAL_FEE.into_u64() @@ -247,23 +255,25 @@ where let secondary = environment.create_client().await; assert_eq!( - with_assertions::propose_send_bump_sync_recipient( + with_assertions::propose_send_bump_sync_all_recipients( &mut environment, &primary, vec![ (&secondary, Shielded(Orchard), 1, None), (&secondary, Shielded(Orchard), 99_999, None) - ] + ], + false, ) .await, 3 * MARGINAL_FEE.into_u64() ); assert_eq!( - with_assertions::propose_send_bump_sync_recipient( + with_assertions::propose_send_bump_sync_all_recipients( &mut environment, &secondary, - vec![(&primary, Shielded(Orchard), 30_000, None)] + vec![(&primary, Shielded(Orchard), 30_000, None)], + false, ) .await, 2 * MARGINAL_FEE.into_u64() @@ -291,7 +301,7 @@ where // send a bunch of dust assert_eq!( - with_assertions::propose_send_bump_sync_recipient( + with_assertions::propose_send_bump_sync_all_recipients( &mut environment, &primary, vec![ @@ -306,6 +316,7 @@ where (&secondary, Shielded(Orchard), 1_000, None), (&secondary, Shielded(Orchard), 15_000, None), ], + false, ) .await, 11 * MARGINAL_FEE.into_u64() @@ -313,10 +324,11 @@ where // combine the only valid sapling note with the only valid orchard note to send assert_eq!( - with_assertions::propose_send_bump_sync_recipient( + with_assertions::propose_send_bump_sync_all_recipients( &mut environment, &secondary, vec![(&primary, Shielded(Orchard), 10_000, None),], + false, ) .await, 4 * MARGINAL_FEE.into_u64() @@ -387,12 +399,13 @@ where // Send number_of_notes transfers in increasing 10_000 zat increments assert_eq!( - with_assertions::propose_send_bump_sync_recipient( + with_assertions::propose_send_bump_sync_all_recipients( &mut environment, &primary, transaction_1_values .map(|value| (&secondary, Shielded(Sapling), value, None)) - .collect() + .collect(), + false, ) .await, expected_fee_for_transaction_1 @@ -436,10 +449,11 @@ where * MARGINAL_FEE.into_u64(); // the second client selects notes to cover the transaction. assert_eq!( - with_assertions::propose_send_bump_sync_recipient( + with_assertions::propose_send_bump_sync_all_recipients( &mut environment, &secondary, - vec![(&primary, Shielded(Orchard), value_from_transaction_2, None)] + vec![(&primary, Shielded(Orchard), value_from_transaction_2, None)], + false, ) .await, expected_fee_for_transaction_2 @@ -487,10 +501,11 @@ where let primary = environment.fund_client_orchard(1_000_000).await; let secondary = environment.create_client().await; - with_assertions::propose_send_bump_sync_recipient( + with_assertions::propose_send_bump_sync_all_recipients( &mut environment, &primary, vec![(&secondary, Shielded(shpool), 100_000 + make_change, None)], + false, ) .await; @@ -506,10 +521,11 @@ where // ); assert_eq!( expected_fee, - with_assertions::propose_send_bump_sync_recipient( + with_assertions::propose_send_bump_sync_all_recipients( &mut environment, &secondary, vec![(&tertiary, pool, 100_000 - expected_fee, None)], + false, ) .await ); diff --git a/zingo-testutils/src/chain_generics/with_assertions.rs b/zingo-testutils/src/chain_generics/with_assertions.rs index dad8609d5..71547d87f 100644 --- a/zingo-testutils/src/chain_generics/with_assertions.rs +++ b/zingo-testutils/src/chain_generics/with_assertions.rs @@ -9,15 +9,17 @@ use crate::{ lightclient::{from_inputs, get_base_address}, }; -/// this version assumes a single recipient and measures that the recipient also recieved the expected balances +/// sends to any combo of recipient clients checks that each recipient also recieved the expected balances /// test-only generic /// NOTICE this function bumps the chain and syncs the client /// only compatible with zip317 /// returns the total fee for the transfer -pub async fn propose_send_bump_sync_recipient( +/// test_mempool can be enabled when the test harness supports it: TBI +pub async fn propose_send_bump_sync_all_recipients( environment: &mut CC, sender: &LightClient, sends: Vec<(&LightClient, PoolType, u64, Option<&str>)>, + test_mempool: bool, ) -> u64 where CC: ConductChain, @@ -43,11 +45,14 @@ where // digesting the calculated transaction let recorded_fee = assert_sender_fee(sender, &proposal, &txids).await; - // mempool scan shows the same - sender.do_sync(false).await.unwrap(); - assert_sender_fee(sender, &proposal, &txids).await; - // recipient.do_sync(false).await.unwrap(); - // assert_receiver_fee(recipient, &proposal, &txids).await; + if test_mempool { + // mempool scan shows the same + sender.do_sync(false).await.unwrap(); + assert_sender_fee(sender, &proposal, &txids).await; + // TODO: distribute receivers + // recipient.do_sync(false).await.unwrap(); + // assert_receiver_fee(recipient, &proposal, &txids).await; + } environment.bump_chain().await; // chain scan shows the same @@ -67,7 +72,11 @@ where /// NOTICE this function bumps the chain and syncs the client /// only compatible with zip317 /// returns the total fee for the transfer -pub async fn propose_shield_bump_sync(environment: &mut CC, client: &LightClient) -> u64 +pub async fn propose_shield_bump_sync( + environment: &mut CC, + client: &LightClient, + test_mempool: bool, +) -> u64 where CC: ConductChain, { @@ -80,9 +89,11 @@ where // digesting the calculated transaction let recorded_fee = assert_sender_fee(client, &proposal, &txids).await; - // mempool scan shows the same - client.do_sync(false).await.unwrap(); - assert_sender_fee(client, &proposal, &txids).await; + if test_mempool { + // mempool scan shows the same + client.do_sync(false).await.unwrap(); + assert_sender_fee(client, &proposal, &txids).await; + } environment.bump_chain().await; // chain scan shows the same From de0d041f55ffa6c3dae578b128809143abe615f2 Mon Sep 17 00:00:00 2001 From: fluidvanadium Date: Mon, 8 Jul 2024 19:47:53 +0000 Subject: [PATCH 2/7] check record status unfinished --- Cargo.lock | 1 + darkside-tests/src/chain_generics.rs | 3 ++ libtonode-tests/tests/chain_generics.rs | 7 +++ zingo-testutils/Cargo.toml | 1 + zingo-testutils/src/assertions.rs | 7 ++- .../src/chain_generics/conduct_chain.rs | 2 + .../src/chain_generics/with_assertions.rs | 51 ++++++++++++++++--- 7 files changed, 64 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d4baa0983..848ba28b5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4229,6 +4229,7 @@ dependencies = [ "zcash_client_backend", "zcash_primitives", "zingo-netutils", + "zingo-status", "zingo-testvectors", "zingoconfig", "zingolib", diff --git a/darkside-tests/src/chain_generics.rs b/darkside-tests/src/chain_generics.rs index 80037766d..14659568d 100644 --- a/darkside-tests/src/chain_generics.rs +++ b/darkside-tests/src/chain_generics.rs @@ -124,5 +124,8 @@ pub(crate) mod impl_conduct_chain_for_darkside_environment { self.staged_blockheight = self.staged_blockheight + 1; self.apply_blocks(u64::from(self.staged_blockheight)).await; } + async fn get_height(&mut self) -> u32 { + 0 + } } } diff --git a/libtonode-tests/tests/chain_generics.rs b/libtonode-tests/tests/chain_generics.rs index 6c916fc06..260e645f2 100644 --- a/libtonode-tests/tests/chain_generics.rs +++ b/libtonode-tests/tests/chain_generics.rs @@ -266,6 +266,13 @@ mod chain_generics { target ); } + + async fn get_height(&mut self) -> u32 { + self.scenario_builder + .regtest_manager + .get_current_height() + .unwrap() + } } } } diff --git a/zingo-testutils/Cargo.toml b/zingo-testutils/Cargo.toml index a3ca3cbe4..64d3aa6da 100644 --- a/zingo-testutils/Cargo.toml +++ b/zingo-testutils/Cargo.toml @@ -14,6 +14,7 @@ zingoconfig = { path = "../zingoconfig" } zingolib = { path = "../zingolib" } zingo-netutils = { path = "../zingo-netutils", features = ["test-features"] } zingo-testvectors = { path = "../zingo-testvectors" } +zingo-status = { path = "../zingo-status" } zcash_client_backend = { workspace = true } zcash_primitives = { workspace = true } diff --git a/zingo-testutils/src/assertions.rs b/zingo-testutils/src/assertions.rs index 4c6979c2a..394c148fa 100644 --- a/zingo-testutils/src/assertions.rs +++ b/zingo-testutils/src/assertions.rs @@ -4,6 +4,8 @@ use nonempty::NonEmpty; use zcash_client_backend::proposal::Proposal; use zcash_primitives::transaction::TxId; + +use zingo_status::confirmation_status::ConfirmationStatus; use zingolib::{lightclient::LightClient, wallet::notes::query::OutputQuery}; /// currently checks: @@ -12,10 +14,11 @@ use zingolib::{lightclient::LightClient, wallet::notes::query::OutputQuery}; /// 3. if the fee from the calculate_transaction_fee matches the sum of the per-step fees /// this currently fails for any broadcast but not confirmed transaction: it seems like get_transaction_fee does not recognize pending spends /// returns the total fee for the transfer -pub async fn assert_sender_fee( +pub async fn assert_sender_fee_and_status( client: &LightClient, proposal: &Proposal, txids: &NonEmpty, + expected_status: ConfirmationStatus, ) -> u64 { let records = &client .wallet @@ -30,6 +33,8 @@ pub async fn assert_sender_fee( for (i, step) in proposal.steps().iter().enumerate() { let record = records.get(&txids[i]).expect("sender must recognize txid"); // does this record match this step? + // we can check that it has the expected status + assert_eq!(record.status, expected_status); // may fail in uncertain ways if used on a transaction we dont have an OutgoingViewingKey for let recorded_fee = records.calculate_transaction_fee(record).unwrap(); assert_eq!(recorded_fee, step.balance().fee_required().into_u64()); diff --git a/zingo-testutils/src/chain_generics/conduct_chain.rs b/zingo-testutils/src/chain_generics/conduct_chain.rs index 6b73d3185..6f87c7c33 100644 --- a/zingo-testutils/src/chain_generics/conduct_chain.rs +++ b/zingo-testutils/src/chain_generics/conduct_chain.rs @@ -23,6 +23,8 @@ pub trait ConductChain { /// and confirming transactions that were received by the server async fn bump_chain(&mut self); + async fn get_height(&mut self) -> u32; + /// builds a client and funds it in orchard and syncs it async fn fund_client_orchard(&mut self, value: u64) -> LightClient { let faucet = self.create_faucet().await; diff --git a/zingo-testutils/src/chain_generics/with_assertions.rs b/zingo-testutils/src/chain_generics/with_assertions.rs index 71547d87f..4bebb477e 100644 --- a/zingo-testutils/src/chain_generics/with_assertions.rs +++ b/zingo-testutils/src/chain_generics/with_assertions.rs @@ -4,10 +4,11 @@ use zcash_client_backend::PoolType; use zingolib::lightclient::LightClient; use crate::{ - assertions::{assert_recipient_total_lte_to_proposal_total, assert_sender_fee}, + assertions::{assert_recipient_total_lte_to_proposal_total, assert_sender_fee_and_status}, chain_generics::conduct_chain::ConductChain, lightclient::{from_inputs, get_base_address}, }; +use zingo_status::confirmation_status::ConfirmationStatus; /// sends to any combo of recipient clients checks that each recipient also recieved the expected balances /// test-only generic @@ -43,12 +44,24 @@ where .unwrap(); // digesting the calculated transaction - let recorded_fee = assert_sender_fee(sender, &proposal, &txids).await; + let recorded_fee = assert_sender_fee_and_status( + sender, + &proposal, + &txids, + ConfirmationStatus::Pending(0.into()), + ) + .await; if test_mempool { // mempool scan shows the same sender.do_sync(false).await.unwrap(); - assert_sender_fee(sender, &proposal, &txids).await; + assert_sender_fee_and_status( + sender, + &proposal, + &txids, + ConfirmationStatus::Pending(0.into()), + ) + .await; // TODO: distribute receivers // recipient.do_sync(false).await.unwrap(); // assert_receiver_fee(recipient, &proposal, &txids).await; @@ -57,7 +70,13 @@ where environment.bump_chain().await; // chain scan shows the same sender.do_sync(false).await.unwrap(); - assert_sender_fee(sender, &proposal, &txids).await; + assert_sender_fee_and_status( + sender, + &proposal, + &txids, + ConfirmationStatus::Pending(0.into()), + ) + .await; let send_ua_id = sender.do_addresses().await[0]["address"].clone(); for (recipient, _, _, _) in sends { if send_ua_id != recipient.do_addresses().await[0]["address"].clone() { @@ -87,18 +106,36 @@ where .unwrap(); // digesting the calculated transaction - let recorded_fee = assert_sender_fee(client, &proposal, &txids).await; + let recorded_fee = assert_sender_fee_and_status( + client, + &proposal, + &txids, + ConfirmationStatus::Pending(0.into()), + ) + .await; if test_mempool { // mempool scan shows the same client.do_sync(false).await.unwrap(); - assert_sender_fee(client, &proposal, &txids).await; + assert_sender_fee_and_status( + client, + &proposal, + &txids, + ConfirmationStatus::Pending(0.into()), + ) + .await; } environment.bump_chain().await; // chain scan shows the same client.do_sync(false).await.unwrap(); - assert_sender_fee(client, &proposal, &txids).await; + assert_sender_fee_and_status( + client, + &proposal, + &txids, + ConfirmationStatus::Pending(0.into()), + ) + .await; recorded_fee } From 31a95b7eb0851fd8f369f227baa5f9d601f36a8c Mon Sep 17 00:00:00 2001 From: fluidvanadium Date: Mon, 8 Jul 2024 19:55:17 +0000 Subject: [PATCH 3/7] check record try for psbsar --- darkside-tests/src/chain_generics.rs | 5 +++-- libtonode-tests/tests/chain_generics.rs | 2 +- zingo-testutils/src/chain_generics/conduct_chain.rs | 3 ++- zingo-testutils/src/chain_generics/with_assertions.rs | 8 +++++--- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/darkside-tests/src/chain_generics.rs b/darkside-tests/src/chain_generics.rs index 14659568d..e9b52c091 100644 --- a/darkside-tests/src/chain_generics.rs +++ b/darkside-tests/src/chain_generics.rs @@ -124,8 +124,9 @@ pub(crate) mod impl_conduct_chain_for_darkside_environment { self.staged_blockheight = self.staged_blockheight + 1; self.apply_blocks(u64::from(self.staged_blockheight)).await; } - async fn get_height(&mut self) -> u32 { - 0 + + fn get_chain_height(&mut self) -> u32 { + self.staged_blockheight.into() } } } diff --git a/libtonode-tests/tests/chain_generics.rs b/libtonode-tests/tests/chain_generics.rs index 260e645f2..e80bc0f07 100644 --- a/libtonode-tests/tests/chain_generics.rs +++ b/libtonode-tests/tests/chain_generics.rs @@ -267,7 +267,7 @@ mod chain_generics { ); } - async fn get_height(&mut self) -> u32 { + fn get_chain_height(&mut self) -> u32 { self.scenario_builder .regtest_manager .get_current_height() diff --git a/zingo-testutils/src/chain_generics/conduct_chain.rs b/zingo-testutils/src/chain_generics/conduct_chain.rs index 6f87c7c33..5084546b6 100644 --- a/zingo-testutils/src/chain_generics/conduct_chain.rs +++ b/zingo-testutils/src/chain_generics/conduct_chain.rs @@ -23,7 +23,8 @@ pub trait ConductChain { /// and confirming transactions that were received by the server async fn bump_chain(&mut self); - async fn get_height(&mut self) -> u32; + /// gets the height. does not yet need to be async + fn get_chain_height(&mut self) -> u32; /// builds a client and funds it in orchard and syncs it async fn fund_client_orchard(&mut self, value: u64) -> LightClient { diff --git a/zingo-testutils/src/chain_generics/with_assertions.rs b/zingo-testutils/src/chain_generics/with_assertions.rs index 4bebb477e..d301fa089 100644 --- a/zingo-testutils/src/chain_generics/with_assertions.rs +++ b/zingo-testutils/src/chain_generics/with_assertions.rs @@ -43,12 +43,14 @@ where .await .unwrap(); + let send_height = environment.get_chain_height(); + // digesting the calculated transaction let recorded_fee = assert_sender_fee_and_status( sender, &proposal, &txids, - ConfirmationStatus::Pending(0.into()), + ConfirmationStatus::Pending(send_height.into()), ) .await; @@ -59,7 +61,7 @@ where sender, &proposal, &txids, - ConfirmationStatus::Pending(0.into()), + ConfirmationStatus::Pending(send_height.into()), ) .await; // TODO: distribute receivers @@ -74,7 +76,7 @@ where sender, &proposal, &txids, - ConfirmationStatus::Pending(0.into()), + ConfirmationStatus::Confirmed((send_height + 1).into()), ) .await; let send_ua_id = sender.do_addresses().await[0]["address"].clone(); From dc36401f90f3755876aab965f046bccf61debb3e Mon Sep 17 00:00:00 2001 From: fluidvanadium Date: Mon, 8 Jul 2024 19:59:33 +0000 Subject: [PATCH 4/7] fix pending target number in chain_generic status tests --- zingo-status/src/confirmation_status.rs | 2 +- .../src/chain_generics/with_assertions.rs | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/zingo-status/src/confirmation_status.rs b/zingo-status/src/confirmation_status.rs index 5986e4fa8..ecb6fdd0c 100644 --- a/zingo-status/src/confirmation_status.rs +++ b/zingo-status/src/confirmation_status.rs @@ -8,7 +8,7 @@ use zcash_primitives::consensus::BlockHeight; #[derive(Clone, Copy, Debug, PartialEq)] pub enum ConfirmationStatus { /// The transaction is pending confirmation to the zcash blockchain. It may be waiting in the mempool. - /// The BlockHeight is the height of the chain as the transaction was broadcast. + /// The BlockHeight is the 1 + the height of the chain as the transaction was broadcast, i.e. the target height. Pending(BlockHeight), /// The transaction has been included in at-least one block mined to the zcash blockchain. /// The height of a confirmed block that contains the transaction. diff --git a/zingo-testutils/src/chain_generics/with_assertions.rs b/zingo-testutils/src/chain_generics/with_assertions.rs index d301fa089..42b0a49e6 100644 --- a/zingo-testutils/src/chain_generics/with_assertions.rs +++ b/zingo-testutils/src/chain_generics/with_assertions.rs @@ -43,7 +43,7 @@ where .await .unwrap(); - let send_height = environment.get_chain_height(); + let send_height = environment.get_chain_height() + 1; // digesting the calculated transaction let recorded_fee = assert_sender_fee_and_status( @@ -76,7 +76,7 @@ where sender, &proposal, &txids, - ConfirmationStatus::Confirmed((send_height + 1).into()), + ConfirmationStatus::Confirmed((send_height).into()), ) .await; let send_ua_id = sender.do_addresses().await[0]["address"].clone(); @@ -102,6 +102,8 @@ where CC: ConductChain, { let proposal = client.propose_shield().await.unwrap(); + + let send_height = environment.get_chain_height() + 1; let txids = client .complete_and_broadcast_stored_proposal() .await @@ -112,7 +114,7 @@ where client, &proposal, &txids, - ConfirmationStatus::Pending(0.into()), + ConfirmationStatus::Pending(send_height.into()), ) .await; @@ -123,7 +125,7 @@ where client, &proposal, &txids, - ConfirmationStatus::Pending(0.into()), + ConfirmationStatus::Pending(send_height.into()), ) .await; } @@ -135,7 +137,7 @@ where client, &proposal, &txids, - ConfirmationStatus::Pending(0.into()), + ConfirmationStatus::Confirmed(send_height.into()), ) .await; From 21f1931a06399b15c7dab309c892f03778f676ee Mon Sep 17 00:00:00 2001 From: fluidvanadium Date: Mon, 8 Jul 2024 20:23:04 +0000 Subject: [PATCH 5/7] setup mempool checx in psbsar --- zingo-testutils/src/assertions.rs | 2 +- .../src/chain_generics/with_assertions.rs | 32 +++++++++++++------ 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/zingo-testutils/src/assertions.rs b/zingo-testutils/src/assertions.rs index 394c148fa..7a5041812 100644 --- a/zingo-testutils/src/assertions.rs +++ b/zingo-testutils/src/assertions.rs @@ -14,7 +14,7 @@ use zingolib::{lightclient::LightClient, wallet::notes::query::OutputQuery}; /// 3. if the fee from the calculate_transaction_fee matches the sum of the per-step fees /// this currently fails for any broadcast but not confirmed transaction: it seems like get_transaction_fee does not recognize pending spends /// returns the total fee for the transfer -pub async fn assert_sender_fee_and_status( +pub async fn assert_record_fee_and_status( client: &LightClient, proposal: &Proposal, txids: &NonEmpty, diff --git a/zingo-testutils/src/chain_generics/with_assertions.rs b/zingo-testutils/src/chain_generics/with_assertions.rs index 42b0a49e6..024daaba8 100644 --- a/zingo-testutils/src/chain_generics/with_assertions.rs +++ b/zingo-testutils/src/chain_generics/with_assertions.rs @@ -4,7 +4,7 @@ use zcash_client_backend::PoolType; use zingolib::lightclient::LightClient; use crate::{ - assertions::{assert_recipient_total_lte_to_proposal_total, assert_sender_fee_and_status}, + assertions::{assert_recipient_total_lte_to_proposal_total, assert_record_fee_and_status}, chain_generics::conduct_chain::ConductChain, lightclient::{from_inputs, get_base_address}, }; @@ -46,7 +46,7 @@ where let send_height = environment.get_chain_height() + 1; // digesting the calculated transaction - let recorded_fee = assert_sender_fee_and_status( + let recorded_fee = assert_record_fee_and_status( sender, &proposal, &txids, @@ -54,32 +54,44 @@ where ) .await; + let send_ua_id = sender.do_addresses().await[0]["address"].clone(); + if test_mempool { // mempool scan shows the same sender.do_sync(false).await.unwrap(); - assert_sender_fee_and_status( + assert_record_fee_and_status( sender, &proposal, &txids, ConfirmationStatus::Pending(send_height.into()), ) .await; + // TODO: distribute receivers - // recipient.do_sync(false).await.unwrap(); - // assert_receiver_fee(recipient, &proposal, &txids).await; + for (recipient, _, _, _) in sends.clone() { + if send_ua_id != recipient.do_addresses().await[0]["address"].clone() { + recipient.do_sync(false).await.unwrap(); + assert_record_fee_and_status( + recipient, + &proposal, + &txids, + ConfirmationStatus::Pending(send_height.into()), + ) + .await; + } + } } environment.bump_chain().await; // chain scan shows the same sender.do_sync(false).await.unwrap(); - assert_sender_fee_and_status( + assert_record_fee_and_status( sender, &proposal, &txids, ConfirmationStatus::Confirmed((send_height).into()), ) .await; - let send_ua_id = sender.do_addresses().await[0]["address"].clone(); for (recipient, _, _, _) in sends { if send_ua_id != recipient.do_addresses().await[0]["address"].clone() { recipient.do_sync(false).await.unwrap(); @@ -110,7 +122,7 @@ where .unwrap(); // digesting the calculated transaction - let recorded_fee = assert_sender_fee_and_status( + let recorded_fee = assert_record_fee_and_status( client, &proposal, &txids, @@ -121,7 +133,7 @@ where if test_mempool { // mempool scan shows the same client.do_sync(false).await.unwrap(); - assert_sender_fee_and_status( + assert_record_fee_and_status( client, &proposal, &txids, @@ -133,7 +145,7 @@ where environment.bump_chain().await; // chain scan shows the same client.do_sync(false).await.unwrap(); - assert_sender_fee_and_status( + assert_record_fee_and_status( client, &proposal, &txids, From b5adcf1136dcdf49407b97d3e7053b7cb5d24e6c Mon Sep 17 00:00:00 2001 From: fluidvanadium Date: Mon, 8 Jul 2024 20:36:28 +0000 Subject: [PATCH 6/7] shpool to pool could use mempool checker --- zingo-testutils/src/chain_generics/fixtures.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/zingo-testutils/src/chain_generics/fixtures.rs b/zingo-testutils/src/chain_generics/fixtures.rs index 3ee1ce02f..2df4512dd 100644 --- a/zingo-testutils/src/chain_generics/fixtures.rs +++ b/zingo-testutils/src/chain_generics/fixtures.rs @@ -1,5 +1,7 @@ //! these functions are each meant to be 'test-in-a-box' //! simply plug in a mock server as a chain conductor and provide some values +use std::sync::Arc; + use zcash_client_backend::PoolType; use zcash_client_backend::PoolType::Shielded; use zcash_client_backend::PoolType::Transparent; @@ -8,6 +10,7 @@ use zcash_client_backend::ShieldedProtocol::Orchard; use zcash_client_backend::ShieldedProtocol::Sapling; use zcash_primitives::transaction::fees::zip317::MARGINAL_FEE; +use zingolib::lightclient::LightClient; use zingolib::wallet::notes::query::OutputSpendStatusQuery; use zingolib::wallet::notes::{query::OutputPoolQuery, OutputInterface}; use zingolib::wallet::{data::summaries::ValueTransferKind, notes::query::OutputQuery}; @@ -519,12 +522,16 @@ where // .into_u64(), // 0 // ); + + let ref_tertiary: Arc = Arc::new(tertiary); + LightClient::start_mempool_monitor(ref_tertiary.clone()); + assert_eq!( expected_fee, with_assertions::propose_send_bump_sync_all_recipients( &mut environment, &secondary, - vec![(&tertiary, pool, 100_000 - expected_fee, None)], + vec![(&ref_tertiary, pool, 100_000 - expected_fee, None)], false, ) .await From a079a4319e6ddda097edb4be29b524c1fcc1657d Mon Sep 17 00:00:00 2001 From: fluidvanadium Date: Mon, 8 Jul 2024 22:13:17 +0000 Subject: [PATCH 7/7] disabled again --- zingo-testutils/src/chain_generics/fixtures.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/zingo-testutils/src/chain_generics/fixtures.rs b/zingo-testutils/src/chain_generics/fixtures.rs index 2df4512dd..35799858d 100644 --- a/zingo-testutils/src/chain_generics/fixtures.rs +++ b/zingo-testutils/src/chain_generics/fixtures.rs @@ -524,7 +524,14 @@ where // ); let ref_tertiary: Arc = Arc::new(tertiary); - LightClient::start_mempool_monitor(ref_tertiary.clone()); + + // mempool monitor + let check_mempool = false; + if check_mempool { + LightClient::start_mempool_monitor(ref_tertiary.clone()); + dbg!("mm started"); + tokio::time::sleep(std::time::Duration::from_secs(5)).await; + } assert_eq!( expected_fee, @@ -532,7 +539,7 @@ where &mut environment, &secondary, vec![(&ref_tertiary, pool, 100_000 - expected_fee, None)], - false, + check_mempool, ) .await );