From 32b286c8a5e175284178077a145263867034e051 Mon Sep 17 00:00:00 2001 From: fluidvanadium Date: Mon, 13 May 2024 16:27:37 +0000 Subject: [PATCH 1/6] removed mod that duplicated tests --- integration-tests/tests/libtonode.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/integration-tests/tests/libtonode.rs b/integration-tests/tests/libtonode.rs index 04d103301..fc25c37a7 100644 --- a/integration-tests/tests/libtonode.rs +++ b/integration-tests/tests/libtonode.rs @@ -37,8 +37,6 @@ use zingolib::{ }, }; -pub mod chain_generic_tests; - fn extract_value_as_u64(input: &JsonValue) -> u64 { let note = &input["value"].as_fixed_point_u64(0).unwrap(); *note From badc51b1e150b110f939799c3bfe251dd194477d Mon Sep 17 00:00:00 2001 From: fluidvanadium Date: Mon, 13 May 2024 16:29:43 +0000 Subject: [PATCH 2/6] align test_names --- darkside-tests/src/chain_generic_tests.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/darkside-tests/src/chain_generic_tests.rs b/darkside-tests/src/chain_generic_tests.rs index 245992bb4..ce054d1cf 100644 --- a/darkside-tests/src/chain_generic_tests.rs +++ b/darkside-tests/src/chain_generic_tests.rs @@ -25,13 +25,13 @@ async fn darkside_send_40_000_to_transparent() { proptest! { #![proptest_config(proptest::test_runner::Config::with_cases(4))] #[test] - fn send_pvalue_to_orchard(value in 0..90u32) { + fn darkside_send_pvalue_to_orchard(value in 0..90u32) { Runtime::new().unwrap().block_on(async { send_value_to_pool::(value * 1_000, Shielded(Orchard)).await; }); } #[test] - fn send_pvalue_to_sapling(value in 0..90u32) { + fn darkside_send_pvalue_to_sapling(value in 0..90u32) { Runtime::new().unwrap().block_on(async { send_value_to_pool::(value * 1_000, Shielded(Sapling)).await; }); From 84d085714ad53720f0acb234accae4c0e8314c18 Mon Sep 17 00:00:00 2001 From: fluidvanadium Date: Mon, 13 May 2024 16:31:21 +0000 Subject: [PATCH 3/6] pub mod impl_conduct_chain_for_darkside_environment --- darkside-tests/src/chain_generic_tests.rs | 157 ++++++++++++---------- 1 file changed, 88 insertions(+), 69 deletions(-) diff --git a/darkside-tests/src/chain_generic_tests.rs b/darkside-tests/src/chain_generic_tests.rs index ce054d1cf..9db5bc1e0 100644 --- a/darkside-tests/src/chain_generic_tests.rs +++ b/darkside-tests/src/chain_generic_tests.rs @@ -42,83 +42,102 @@ proptest! { /// - transparent sends do not work /// - txids are regenerated randomly. zingo can optionally accept_server_txid /// these tests cannot portray the full range of network weather. -impl ConductChain for DarksideEnvironment { - async fn setup() -> Self { - DarksideEnvironment::new(None).await - } +pub mod impl_conduct_chain_for_darkside_environment { + use proptest::proptest; + use tokio::runtime::Runtime; - async fn create_faucet(&mut self) -> LightClient { - self.stage_transaction(ABANDON_TO_DARKSIDE_SAP_10_000_000_ZAT) - .await; - let mut zingo_config = self - .client_builder - .make_unique_data_dir_and_load_config(self.regtest_network); - zingo_config.accept_server_txids = true; - LightClient::create_from_wallet_base_async( - WalletBase::MnemonicPhrase(DARKSIDE_SEED.to_string()), - &zingo_config, - 0, - true, - ) - .await - .unwrap() - } + use zcash_client_backend::PoolType::Shielded; + use zcash_client_backend::PoolType::Transparent; + use zcash_client_backend::ShieldedProtocol::Orchard; + use zcash_client_backend::ShieldedProtocol::Sapling; - async fn create_client(&mut self) -> LightClient { - let mut zingo_config = self - .client_builder - .make_unique_data_dir_and_load_config(self.regtest_network); - zingo_config.accept_server_txids = true; - LightClient::create_from_wallet_base_async( - WalletBase::FreshEntropy, - &zingo_config, - 0, - false, - ) - .await - .unwrap() - } + use zingo_testutils::chain_generic_tests::send_value_to_pool; + use zingo_testutils::chain_generic_tests::ConductChain; + use zingolib::lightclient::LightClient; + use zingolib::wallet::WalletBase; + + use crate::constants::ABANDON_TO_DARKSIDE_SAP_10_000_000_ZAT; + use crate::constants::DARKSIDE_SEED; + use crate::utils::scenarios::DarksideEnvironment; + use crate::utils::update_tree_states_for_transaction; + impl ConductChain for DarksideEnvironment { + async fn setup() -> Self { + DarksideEnvironment::new(None).await + } - async fn bump_chain(&mut self) { - let mut streamed_raw_txns = self - .darkside_connector - .get_incoming_transactions() + async fn create_faucet(&mut self) -> LightClient { + self.stage_transaction(ABANDON_TO_DARKSIDE_SAP_10_000_000_ZAT) + .await; + let mut zingo_config = self + .client_builder + .make_unique_data_dir_and_load_config(self.regtest_network); + zingo_config.accept_server_txids = true; + LightClient::create_from_wallet_base_async( + WalletBase::MnemonicPhrase(DARKSIDE_SEED.to_string()), + &zingo_config, + 0, + true, + ) .await - .unwrap(); - self.darkside_connector - .clear_incoming_transactions() + .unwrap() + } + + async fn create_client(&mut self) -> LightClient { + let mut zingo_config = self + .client_builder + .make_unique_data_dir_and_load_config(self.regtest_network); + zingo_config.accept_server_txids = true; + LightClient::create_from_wallet_base_async( + WalletBase::FreshEntropy, + &zingo_config, + 0, + false, + ) .await - .unwrap(); - loop { - let maybe_raw_tx = streamed_raw_txns.message().await.unwrap(); - match maybe_raw_tx { - None => break, - Some(raw_tx) => { - self.darkside_connector - .stage_transactions_stream(vec![( - raw_tx.data.clone(), + .unwrap() + } + + async fn bump_chain(&mut self) { + let mut streamed_raw_txns = self + .darkside_connector + .get_incoming_transactions() + .await + .unwrap(); + self.darkside_connector + .clear_incoming_transactions() + .await + .unwrap(); + loop { + let maybe_raw_tx = streamed_raw_txns.message().await.unwrap(); + match maybe_raw_tx { + None => break, + Some(raw_tx) => { + self.darkside_connector + .stage_transactions_stream(vec![( + raw_tx.data.clone(), + u64::from(self.staged_blockheight), + )]) + .await + .unwrap(); + self.tree_state = update_tree_states_for_transaction( + &self.darkside_connector.0, + raw_tx.clone(), u64::from(self.staged_blockheight), - )]) - .await - .unwrap(); - self.tree_state = update_tree_states_for_transaction( - &self.darkside_connector.0, - raw_tx.clone(), - u64::from(self.staged_blockheight), - ) - .await; - self.darkside_connector - .add_tree_state(self.tree_state.clone()) - .await - .unwrap(); + ) + .await; + self.darkside_connector + .add_tree_state(self.tree_state.clone()) + .await + .unwrap(); + } } } + self.darkside_connector + .stage_blocks_create(u64::from(self.staged_blockheight) as i32, 1, 0) + .await + .unwrap(); + self.staged_blockheight = self.staged_blockheight + 1; + self.apply_blocks(u64::from(self.staged_blockheight)).await; } - self.darkside_connector - .stage_blocks_create(u64::from(self.staged_blockheight) as i32, 1, 0) - .await - .unwrap(); - self.staged_blockheight = self.staged_blockheight + 1; - self.apply_blocks(u64::from(self.staged_blockheight)).await; } } From 18cdad554812973904d4c89053fd2b32657e4445 Mon Sep 17 00:00:00 2001 From: fluidvanadium Date: Mon, 13 May 2024 16:34:29 +0000 Subject: [PATCH 4/6] pub mods --- darkside-tests/src/chain_generic_tests.rs | 2 +- .../tests/chain_generic_tests.rs | 128 ++++++++++-------- zingo-testutils/src/chain_generic_tests.rs | 102 +++++++------- 3 files changed, 124 insertions(+), 108 deletions(-) diff --git a/darkside-tests/src/chain_generic_tests.rs b/darkside-tests/src/chain_generic_tests.rs index 9db5bc1e0..feede3d5b 100644 --- a/darkside-tests/src/chain_generic_tests.rs +++ b/darkside-tests/src/chain_generic_tests.rs @@ -42,7 +42,7 @@ proptest! { /// - transparent sends do not work /// - txids are regenerated randomly. zingo can optionally accept_server_txid /// these tests cannot portray the full range of network weather. -pub mod impl_conduct_chain_for_darkside_environment { +pub(crate) mod impl_conduct_chain_for_darkside_environment { use proptest::proptest; use tokio::runtime::Runtime; diff --git a/integration-tests/tests/chain_generic_tests.rs b/integration-tests/tests/chain_generic_tests.rs index d0a5ff05f..d03be50cb 100644 --- a/integration-tests/tests/chain_generic_tests.rs +++ b/integration-tests/tests/chain_generic_tests.rs @@ -11,6 +11,8 @@ use zingoconfig::RegtestNetwork; use zingolib::lightclient::LightClient; use zingolib::wallet::WalletBase; +use libtonode_environment::LibtonodeEnvironment; + #[tokio::test] async fn libtonode_send_40_000_to_transparent() { send_value_to_pool::(40_000, Transparent).await; @@ -24,68 +26,82 @@ async fn libtonode_send_40_000_to_orchard() { send_value_to_pool::(40_000, Shielded(Orchard)).await; } -struct LibtonodeEnvironment { - regtest_network: RegtestNetwork, - scenario_builder: ScenarioBuilder, -} - -/// known issues include --slow -/// these tests cannot portray the full range of network weather. -impl ConductChain for LibtonodeEnvironment { - async fn setup() -> Self { - let regtest_network = RegtestNetwork::all_upgrades_active(); - let scenario_builder = ScenarioBuilder::build_configure_launch( - Some(PoolType::Shielded(Sapling).into()), - None, - None, - ®test_network, - ) - .await; - LibtonodeEnvironment { - regtest_network, - scenario_builder, - } - } +pub(crate) mod libtonode_environment { + use zcash_client_backend::PoolType; + use zcash_client_backend::PoolType::Shielded; + use zcash_client_backend::PoolType::Transparent; + use zcash_client_backend::ShieldedProtocol::Orchard; + use zcash_client_backend::ShieldedProtocol::Sapling; - async fn create_faucet(&mut self) -> LightClient { - self.scenario_builder - .client_builder - .build_faucet(false, self.regtest_network) - .await + use zingo_testutils::chain_generic_tests::send_value_to_pool; + use zingo_testutils::chain_generic_tests::ConductChain; + use zingo_testutils::scenarios::setup::ScenarioBuilder; + use zingoconfig::RegtestNetwork; + use zingolib::lightclient::LightClient; + use zingolib::wallet::WalletBase; + pub(crate) struct LibtonodeEnvironment { + regtest_network: RegtestNetwork, + scenario_builder: ScenarioBuilder, } - async fn create_client(&mut self) -> LightClient { - let zingo_config = self - .scenario_builder - .client_builder - .make_unique_data_dir_and_load_config(self.regtest_network); - LightClient::create_from_wallet_base_async( - WalletBase::FreshEntropy, - &zingo_config, - 0, - false, - ) - .await - .unwrap() - } + /// known issues include --slow + /// these tests cannot portray the full range of network weather. + impl ConductChain for LibtonodeEnvironment { + async fn setup() -> Self { + let regtest_network = RegtestNetwork::all_upgrades_active(); + let scenario_builder = ScenarioBuilder::build_configure_launch( + Some(PoolType::Shielded(Sapling).into()), + None, + None, + ®test_network, + ) + .await; + LibtonodeEnvironment { + regtest_network, + scenario_builder, + } + } - async fn bump_chain(&mut self) { - let start_height = self - .scenario_builder - .regtest_manager - .get_current_height() - .unwrap(); - let target = start_height + 1; - self.scenario_builder - .regtest_manager - .generate_n_blocks(1) - .expect("Called for side effect, failed!"); - assert_eq!( + async fn create_faucet(&mut self) -> LightClient { self.scenario_builder + .client_builder + .build_faucet(false, self.regtest_network) + .await + } + + async fn create_client(&mut self) -> LightClient { + let zingo_config = self + .scenario_builder + .client_builder + .make_unique_data_dir_and_load_config(self.regtest_network); + LightClient::create_from_wallet_base_async( + WalletBase::FreshEntropy, + &zingo_config, + 0, + false, + ) + .await + .unwrap() + } + + async fn bump_chain(&mut self) { + let start_height = self + .scenario_builder .regtest_manager .get_current_height() - .unwrap(), - target - ); + .unwrap(); + let target = start_height + 1; + self.scenario_builder + .regtest_manager + .generate_n_blocks(1) + .expect("Called for side effect, failed!"); + assert_eq!( + self.scenario_builder + .regtest_manager + .get_current_height() + .unwrap(), + target + ); + } } } diff --git a/zingo-testutils/src/chain_generic_tests.rs b/zingo-testutils/src/chain_generic_tests.rs index 95e7aa3c7..98ad33671 100644 --- a/zingo-testutils/src/chain_generic_tests.rs +++ b/zingo-testutils/src/chain_generic_tests.rs @@ -8,6 +8,57 @@ use zingolib::wallet::notes::query::OutputQuery; use zingolib::wallet::notes::query::OutputSpendStatusQuery; use zingolib::{get_base_address, wallet::notes::query::OutputPoolQuery}; +#[allow(async_fn_in_trait)] +#[allow(opaque_hidden_inferred_bound)] +/// A Lightclient test may involve hosting a server to send data to the LightClient. This trait can be asked to set simple scenarios where a mock LightServer sends data showing a note to a LightClient, the LightClient updates and responds by sending the note, and the Lightserver accepts the transaction and rebroadcasts it... +/// The initial two implementors are +/// lib-to-node, which links a lightserver to a zcashd in regtest mode. see `impl ConductChain for LibtoNode +/// darkside, a mode for the lightserver which mocks zcashd. search 'impl ConductChain for DarksideScenario +pub trait ConductChain { + /// set up the test chain + async fn setup() -> Self; + /// builds a faucet (funded from mining) + async fn create_faucet(&mut self) -> LightClient; + /// builds an empty client + async fn create_client(&mut self) -> LightClient; + /// moves the chain tip forward, confirming transactions that need to be confirmed + async fn bump_chain(&mut self); + + /// builds a client and funds it in a certain pool. may need sync before noticing its funds. + async fn fund_client(&mut self, value: u32) -> LightClient { + let sender = self.create_faucet().await; + let recipient = self.create_client().await; + + self.bump_chain().await; + sender.do_sync(false).await.unwrap(); + + sender + .do_send_test_only(vec![( + (get_base_address!(recipient, "unified")).as_str(), + value as u64, + None, + )]) + .await + .unwrap(); + + self.bump_chain().await; + + recipient.do_sync(false).await.unwrap(); + + recipient + } + + // async fn start_with_funds(value: u32) -> (LightClient, Self) { + // let chain = Self::setup().await; + + // let starter = chain + // .fund_client(value + 2 * (MARGINAL_FEE.into_u64() as u32)) + // .await; + + // (starter, chain); + // } +} + /// runs a send-to-receiver and receives it in a chain-generic context pub async fn propose_and_broadcast_value_to_pool(send_value: u32, pooltype: PoolType) where @@ -60,57 +111,6 @@ where ); } -#[allow(async_fn_in_trait)] -#[allow(opaque_hidden_inferred_bound)] -/// A Lightclient test may involve hosting a server to send data to the LightClient. This trait can be asked to set simple scenarios where a mock LightServer sends data showing a note to a LightClient, the LightClient updates and responds by sending the note, and the Lightserver accepts the transaction and rebroadcasts it... -/// The initial two implementors are -/// lib-to-node, which links a lightserver to a zcashd in regtest mode. see `impl ConductChain for LibtoNode -/// darkside, a mode for the lightserver which mocks zcashd. search 'impl ConductChain for DarksideScenario -pub trait ConductChain { - /// set up the test chain - async fn setup() -> Self; - /// builds a faucet (funded from mining) - async fn create_faucet(&mut self) -> LightClient; - /// builds an empty client - async fn create_client(&mut self) -> LightClient; - /// moves the chain tip forward, confirming transactions that need to be confirmed - async fn bump_chain(&mut self); - - /// builds a client and funds it in a certain pool. may need sync before noticing its funds. - async fn fund_client(&mut self, value: u32) -> LightClient { - let sender = self.create_faucet().await; - let recipient = self.create_client().await; - - self.bump_chain().await; - sender.do_sync(false).await.unwrap(); - - sender - .do_send_test_only(vec![( - (get_base_address!(recipient, "unified")).as_str(), - value as u64, - None, - )]) - .await - .unwrap(); - - self.bump_chain().await; - - recipient.do_sync(false).await.unwrap(); - - recipient - } - - // async fn start_with_funds(value: u32) -> (LightClient, Self) { - // let chain = Self::setup().await; - - // let starter = chain - // .fund_client(value + 2 * (MARGINAL_FEE.into_u64() as u32)) - // .await; - - // (starter, chain); - // } -} - /// creates a proposal, sends it and receives it (upcoming: compares that it was executed correctly) in a chain-generic context pub async fn send_value_to_pool(send_value: u32, pooltype: PoolType) where From 490c97156a13c1ae303724d22604082fb4761ea1 Mon Sep 17 00:00:00 2001 From: fluidvanadium Date: Mon, 13 May 2024 16:35:19 +0000 Subject: [PATCH 5/6] cargo fix --- darkside-tests/src/chain_generic_tests.rs | 14 -------------- integration-tests/tests/chain_generic_tests.rs | 11 +---------- 2 files changed, 1 insertion(+), 24 deletions(-) diff --git a/darkside-tests/src/chain_generic_tests.rs b/darkside-tests/src/chain_generic_tests.rs index feede3d5b..6743376bc 100644 --- a/darkside-tests/src/chain_generic_tests.rs +++ b/darkside-tests/src/chain_generic_tests.rs @@ -7,14 +7,8 @@ use zcash_client_backend::ShieldedProtocol::Orchard; use zcash_client_backend::ShieldedProtocol::Sapling; use zingo_testutils::chain_generic_tests::send_value_to_pool; -use zingo_testutils::chain_generic_tests::ConductChain; -use zingolib::lightclient::LightClient; -use zingolib::wallet::WalletBase; -use crate::constants::ABANDON_TO_DARKSIDE_SAP_10_000_000_ZAT; -use crate::constants::DARKSIDE_SEED; use crate::utils::scenarios::DarksideEnvironment; -use crate::utils::update_tree_states_for_transaction; #[tokio::test] #[ignore] // darkside cant handle transparent? @@ -43,15 +37,7 @@ proptest! { /// - txids are regenerated randomly. zingo can optionally accept_server_txid /// these tests cannot portray the full range of network weather. pub(crate) mod impl_conduct_chain_for_darkside_environment { - use proptest::proptest; - use tokio::runtime::Runtime; - use zcash_client_backend::PoolType::Shielded; - use zcash_client_backend::PoolType::Transparent; - use zcash_client_backend::ShieldedProtocol::Orchard; - use zcash_client_backend::ShieldedProtocol::Sapling; - - use zingo_testutils::chain_generic_tests::send_value_to_pool; use zingo_testutils::chain_generic_tests::ConductChain; use zingolib::lightclient::LightClient; use zingolib::wallet::WalletBase; diff --git a/integration-tests/tests/chain_generic_tests.rs b/integration-tests/tests/chain_generic_tests.rs index d03be50cb..66254ecbe 100644 --- a/integration-tests/tests/chain_generic_tests.rs +++ b/integration-tests/tests/chain_generic_tests.rs @@ -1,15 +1,9 @@ -use zcash_client_backend::PoolType; use zcash_client_backend::PoolType::Shielded; use zcash_client_backend::PoolType::Transparent; use zcash_client_backend::ShieldedProtocol::Orchard; use zcash_client_backend::ShieldedProtocol::Sapling; use zingo_testutils::chain_generic_tests::send_value_to_pool; -use zingo_testutils::chain_generic_tests::ConductChain; -use zingo_testutils::scenarios::setup::ScenarioBuilder; -use zingoconfig::RegtestNetwork; -use zingolib::lightclient::LightClient; -use zingolib::wallet::WalletBase; use libtonode_environment::LibtonodeEnvironment; @@ -28,12 +22,9 @@ async fn libtonode_send_40_000_to_orchard() { pub(crate) mod libtonode_environment { use zcash_client_backend::PoolType; - use zcash_client_backend::PoolType::Shielded; - use zcash_client_backend::PoolType::Transparent; - use zcash_client_backend::ShieldedProtocol::Orchard; + use zcash_client_backend::ShieldedProtocol::Sapling; - use zingo_testutils::chain_generic_tests::send_value_to_pool; use zingo_testutils::chain_generic_tests::ConductChain; use zingo_testutils::scenarios::setup::ScenarioBuilder; use zingoconfig::RegtestNetwork; From 63a9fb22b3dd29a7ea05816ee3c5dd2479d3dcc5 Mon Sep 17 00:00:00 2001 From: fluidvanadium Date: Mon, 13 May 2024 17:01:11 +0000 Subject: [PATCH 6/6] fixed comment --- zingo-testutils/src/chain_generic_tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zingo-testutils/src/chain_generic_tests.rs b/zingo-testutils/src/chain_generic_tests.rs index 6880dc5f7..17c5ce301 100644 --- a/zingo-testutils/src/chain_generic_tests.rs +++ b/zingo-testutils/src/chain_generic_tests.rs @@ -24,7 +24,7 @@ pub trait ConductChain { /// moves the chain tip forward, confirming transactions that need to be confirmed async fn bump_chain(&mut self); - /// builds a client and funds it in a certain pool. may need sync before noticing its funds. + /// builds a client and funds it in orchard and syncs it async fn fund_client(&mut self, value: u32) -> LightClient { let sender = self.create_faucet().await; let recipient = self.create_client().await;