From b9b5bc25924badcce25838d82e37620d22eb8661 Mon Sep 17 00:00:00 2001 From: Hazel OHearn Date: Thu, 11 Apr 2024 17:25:43 -0300 Subject: [PATCH 1/2] Upgrade darkside interface, add nonfunctional transparent darkside test --- darkside-tests/src/utils.rs | 63 ++++++++++++++----- .../tests/network_interruption_tests.rs | 13 +--- darkside-tests/tests/shield_transparent.rs | 48 ++++++++++++++ 3 files changed, 99 insertions(+), 25 deletions(-) create mode 100644 darkside-tests/tests/shield_transparent.rs diff --git a/darkside-tests/src/utils.rs b/darkside-tests/src/utils.rs index 4778fa6e1..8f2314f7c 100644 --- a/darkside-tests/src/utils.rs +++ b/darkside-tests/src/utils.rs @@ -496,7 +496,9 @@ pub mod scenarios { use zcash_primitives::consensus::{BlockHeight, BranchId}; use zingo_testutils::scenarios::setup::ClientBuilder; use zingoconfig::RegtestNetwork; - use zingolib::{lightclient::LightClient, wallet::Pool}; + use zingolib::{ + lightclient::LightClient, testvectors::seeds::HOSPITAL_MUSEUM_SEED, wallet::Pool, + }; use crate::{ constants, @@ -544,6 +546,15 @@ pub mod scenarios { pub async fn default() -> DarksideScenario { DarksideScenario::new(None).await } + pub async fn default_faucet_recipient(funded_pool: Pool) -> DarksideScenario { + let mut scenario = DarksideScenario::new(None).await; + scenario + .build_faucet(funded_pool) + .await + .build_client(HOSPITAL_MUSEUM_SEED.to_string(), 4) + .await; + scenario + } /// Builds a lightclient with spending capability to the initial source of funds to the darkside blockchain /// The staged block with the funding transaction is not applied and the faucet is not synced @@ -638,6 +649,19 @@ pub mod scenarios { value: u64, chainbuild_file: &File, ) -> &mut DarksideScenario { + let (_, raw_tx) = self.send_transaction(sender, receiver_address, value).await; + write_raw_transaction(&raw_tx, BranchId::Nu5, chainbuild_file); + self + } + + pub async fn send_transaction( + &mut self, + // We can't just take a reference to a LightClient, as that might be a reference to + // a field of the DarksideScenario which we're taking by exclusive (i.e. mut) reference + sender: DarksideSender<'_>, + receiver_address: &str, + value: u64, + ) -> (&mut DarksideScenario, RawTransaction) { self.staged_blockheight = self.staged_blockheight.add(1); self.darkside_connector .stage_blocks_create(u32::from(self.staged_blockheight) as i32, 1, 0) @@ -664,7 +688,6 @@ pub mod scenarios { let raw_tx = streamed_raw_txns.message().await.unwrap().unwrap(); // There should only be one transaction incoming assert!(streamed_raw_txns.message().await.unwrap().is_none()); - write_raw_transaction(&raw_tx, BranchId::Nu5, chainbuild_file); self.darkside_connector .stage_transactions_stream(vec![( raw_tx.data.clone(), @@ -674,25 +697,20 @@ pub mod scenarios { .unwrap(); self.tree_state = update_tree_states_for_transaction( &self.darkside_connector.0, - raw_tx, + raw_tx.clone(), u64::from(self.staged_blockheight), ) .await; - self + (self, raw_tx) } - /// Tool for chainbuilds. - /// Stage a block and a shield from funded lightclient, then write hex transaction to file. - /// Only one pool can be shielded at a time. - /// All sends in a chainbuild are appended to same file in order. - /// Does not apply block. - pub async fn shield_and_write_transaction( + + pub async fn shield_transaction( &mut self, // We can't just take a reference to a LightClient, as that might be a reference to // a field of the DarksideScenario which we're taking by exclusive (i.e. mut) reference sender: DarksideSender<'_>, pool_to_shield: Pool, - chainbuild_file: &File, - ) -> &mut DarksideScenario { + ) -> (&mut DarksideScenario, RawTransaction) { self.staged_blockheight = self.staged_blockheight.add(1); self.darkside_connector .stage_blocks_create(u32::from(self.staged_blockheight) as i32, 1, 0) @@ -719,7 +737,6 @@ pub mod scenarios { let raw_tx = streamed_raw_txns.message().await.unwrap().unwrap(); // There should only be one transaction incoming assert!(streamed_raw_txns.message().await.unwrap().is_none()); - write_raw_transaction(&raw_tx, BranchId::Nu5, chainbuild_file); self.darkside_connector .stage_transactions_stream(vec![( raw_tx.data.clone(), @@ -729,10 +746,28 @@ pub mod scenarios { .unwrap(); self.tree_state = update_tree_states_for_transaction( &self.darkside_connector.0, - raw_tx, + raw_tx.clone(), u64::from(self.staged_blockheight), ) .await; + (self, raw_tx) + } + + /// Tool for chainbuilds. + /// Stage a block and a shield from funded lightclient, then write hex transaction to file. + /// Only one pool can be shielded at a time. + /// All sends in a chainbuild are appended to same file in order. + /// Does not apply block. + pub async fn shield_and_write_transaction( + &mut self, + // We can't just take a reference to a LightClient, as that might be a reference to + // a field of the DarksideScenario which we're taking by exclusive (i.e. mut) reference + sender: DarksideSender<'_>, + pool_to_shield: Pool, + chainbuild_file: &File, + ) -> &mut DarksideScenario { + let (_, raw_tx) = self.shield_transaction(sender, pool_to_shield).await; + write_raw_transaction(&raw_tx, BranchId::Nu5, chainbuild_file); self } /// Stage a block and transaction, then update tree state. diff --git a/darkside-tests/tests/network_interruption_tests.rs b/darkside-tests/tests/network_interruption_tests.rs index ed06e800d..c1adb9eab 100644 --- a/darkside-tests/tests/network_interruption_tests.rs +++ b/darkside-tests/tests/network_interruption_tests.rs @@ -22,7 +22,6 @@ use zingoconfig::RegtestNetwork; use zingolib::{ get_base_address, lightclient::PoolBalances, - testvectors::seeds, wallet::{data::summaries::ValueTransferKind, Pool}, }; @@ -85,11 +84,7 @@ async fn interrupt_initial_tree_fetch() { async fn shielded_note_marked_as_change_chainbuild() { const BLOCKCHAIN_HEIGHT: u64 = 20_000; let chainbuild_file = create_chainbuild_file("shielded_note_marked_as_change"); - let mut scenario = DarksideScenario::default().await; - scenario.build_faucet(Pool::Sapling).await; - scenario - .build_client(seeds::HOSPITAL_MUSEUM_SEED.to_string(), 4) - .await; + let mut scenario = DarksideScenario::default_faucet_recipient(Pool::Sapling).await; // stage a sapling to orchard send-to-self every thousand blocks for thousands_blocks_count in 1..BLOCKCHAIN_HEIGHT / 1000 { @@ -136,11 +131,7 @@ async fn shielded_note_marked_as_change_chainbuild() { async fn shielded_note_marked_as_change_test() { const BLOCKCHAIN_HEIGHT: u64 = 20_000; let transaction_set = load_chainbuild_file("shielded_note_marked_as_change"); - let mut scenario = DarksideScenario::default().await; - scenario.build_faucet(Pool::Sapling).await; - scenario - .build_client(seeds::HOSPITAL_MUSEUM_SEED.to_string(), 4) - .await; + let mut scenario = DarksideScenario::default_faucet_recipient(Pool::Sapling).await; // stage a send to self every thousand blocks for thousands_blocks_count in 1..BLOCKCHAIN_HEIGHT / 1000 { diff --git a/darkside-tests/tests/shield_transparent.rs b/darkside-tests/tests/shield_transparent.rs new file mode 100644 index 000000000..e044f9984 --- /dev/null +++ b/darkside-tests/tests/shield_transparent.rs @@ -0,0 +1,48 @@ +use darkside_tests::utils::scenarios::{DarksideScenario, DarksideSender}; +use zingolib::{get_base_address, wallet::Pool}; + +#[tokio::test] +async fn shield_transparent() { + let mut targ_height = 10; //arbitrary? + let mut scenario = DarksideScenario::default_faucet_recipient(Pool::Orchard).await; + scenario.stage_and_apply_blocks(targ_height, 0).await; + targ_height += 2; + scenario.get_faucet().do_sync(false).await.unwrap(); + println!( + "scenario initial + faucet: {} + recipient: {}", + serde_json::to_string_pretty(&scenario.get_faucet().do_balance().await).unwrap(), + serde_json::to_string_pretty(&scenario.get_lightclient(0).do_balance().await).unwrap(), + ); + scenario + .send_transaction( + DarksideSender::Faucet, + &get_base_address!(scenario.get_lightclient(0), "transparent"), + 100_000, + ) + .await; + scenario.stage_and_apply_blocks(targ_height, 0).await; + targ_height += 2; + scenario.get_lightclient(0).do_sync(false).await.unwrap(); + + println!( + "sent to recipient + faucet: {} + recipient: {}", + serde_json::to_string_pretty(&scenario.get_faucet().do_balance().await).unwrap(), + serde_json::to_string_pretty(&scenario.get_lightclient(0).do_balance().await).unwrap(), + ); + + scenario + .shield_transaction(DarksideSender::IndexedClient(0), Pool::Transparent) + .await; + println!( + "post-shield recipient + faucet: {} + recipient: {}", + serde_json::to_string_pretty(&scenario.get_faucet().do_balance().await).unwrap(), + serde_json::to_string_pretty(&scenario.get_lightclient(0).do_balance().await).unwrap(), + ); + scenario.stage_and_apply_blocks(targ_height, 0).await; +} From 687dfb059ab322587d80861c710b021561fc533c Mon Sep 17 00:00:00 2001 From: Hazel OHearn Date: Thu, 11 Apr 2024 17:27:56 -0300 Subject: [PATCH 2/2] remove nonfunctional test --- darkside-tests/tests/shield_transparent.rs | 48 ---------------------- 1 file changed, 48 deletions(-) delete mode 100644 darkside-tests/tests/shield_transparent.rs diff --git a/darkside-tests/tests/shield_transparent.rs b/darkside-tests/tests/shield_transparent.rs deleted file mode 100644 index e044f9984..000000000 --- a/darkside-tests/tests/shield_transparent.rs +++ /dev/null @@ -1,48 +0,0 @@ -use darkside_tests::utils::scenarios::{DarksideScenario, DarksideSender}; -use zingolib::{get_base_address, wallet::Pool}; - -#[tokio::test] -async fn shield_transparent() { - let mut targ_height = 10; //arbitrary? - let mut scenario = DarksideScenario::default_faucet_recipient(Pool::Orchard).await; - scenario.stage_and_apply_blocks(targ_height, 0).await; - targ_height += 2; - scenario.get_faucet().do_sync(false).await.unwrap(); - println!( - "scenario initial - faucet: {} - recipient: {}", - serde_json::to_string_pretty(&scenario.get_faucet().do_balance().await).unwrap(), - serde_json::to_string_pretty(&scenario.get_lightclient(0).do_balance().await).unwrap(), - ); - scenario - .send_transaction( - DarksideSender::Faucet, - &get_base_address!(scenario.get_lightclient(0), "transparent"), - 100_000, - ) - .await; - scenario.stage_and_apply_blocks(targ_height, 0).await; - targ_height += 2; - scenario.get_lightclient(0).do_sync(false).await.unwrap(); - - println!( - "sent to recipient - faucet: {} - recipient: {}", - serde_json::to_string_pretty(&scenario.get_faucet().do_balance().await).unwrap(), - serde_json::to_string_pretty(&scenario.get_lightclient(0).do_balance().await).unwrap(), - ); - - scenario - .shield_transaction(DarksideSender::IndexedClient(0), Pool::Transparent) - .await; - println!( - "post-shield recipient - faucet: {} - recipient: {}", - serde_json::to_string_pretty(&scenario.get_faucet().do_balance().await).unwrap(), - serde_json::to_string_pretty(&scenario.get_lightclient(0).do_balance().await).unwrap(), - ); - scenario.stage_and_apply_blocks(targ_height, 0).await; -}