Skip to content

Commit

Permalink
Merge pull request #591 from Oscar-Pepper/clean_build_clients
Browse files Browse the repository at this point in the history
remove seed from client builder and wrap build client in build faucet
  • Loading branch information
zancas authored Oct 13, 2023
2 parents ef86d28 + adcf966 commit bd5603c
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 100 deletions.
75 changes: 25 additions & 50 deletions zingo-testutils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ pub mod scenarios {
use zingolib::{get_base_address, lightclient::LightClient, wallet::Pool};

pub mod setup {
use crate::data::REG_Z_ADDR_FROM_ABANDONART;
use crate::data::{seeds, REG_Z_ADDR_FROM_ABANDONART};
use crate::BASE_HEIGHT;

use super::super::regtest::get_regtest_dir;
Expand Down Expand Up @@ -275,11 +275,7 @@ pub mod scenarios {
} else {
regtest_manager.zingo_datadir.clone()
};
let client_builder = ClientBuilder::new(
test_env.get_lightwalletd_uri(),
data_dir,
data::seeds::ABANDON_ART_SEED,
);
let client_builder = ClientBuilder::new(test_env.get_lightwalletd_uri(), data_dir);
let child_process_handler = None;
Self {
test_env,
Expand Down Expand Up @@ -370,17 +366,14 @@ pub mod scenarios {
pub struct ClientBuilder {
pub server_id: http::Uri,
pub zingo_datadir: PathBuf,
seed: String,
client_number: u8,
}
impl ClientBuilder {
pub fn new(server_id: http::Uri, zingo_datadir: PathBuf, seed: &str) -> Self {
let seed = seed.to_string();
pub fn new(server_id: http::Uri, zingo_datadir: PathBuf) -> Self {
let client_number = 0;
ClientBuilder {
server_id,
zingo_datadir,
seed,
client_number,
}
}
Expand Down Expand Up @@ -413,24 +406,21 @@ pub mod scenarios {
.unwrap()
}

pub async fn build_new_faucet(
pub async fn build_faucet(
&mut self,
birthday: u64,
overwrite: bool,
regtest_network: zingoconfig::RegtestNetwork,
) -> LightClient {
//! A "faucet" is a lightclient that receives mining rewards
let zingo_config = self.make_unique_data_dir_and_load_config(regtest_network);
LightClient::create_from_wallet_base_async(
WalletBase::MnemonicPhrase(self.seed.clone()),
&zingo_config,
birthday,
self.build_client(
seeds::ABANDON_ART_SEED.to_string(),
0,
overwrite,
regtest_network,
)
.await
.unwrap()
}
pub async fn build_newseed_client(
pub async fn build_client(
&mut self,
mnemonic_phrase: String,
birthday: u64,
Expand Down Expand Up @@ -577,10 +567,7 @@ pub mod scenarios {
&regtest_network,
)
.await;
let faucet = sb
.client_builder
.build_new_faucet(0, false, regtest_network)
.await;
let faucet = sb.client_builder.build_faucet(false, regtest_network).await;
faucet.do_sync(false).await.unwrap();
(
sb.regtest_manager,
Expand Down Expand Up @@ -646,15 +633,12 @@ pub mod scenarios {
&regtest_network,
)
.await;
let faucet = sb
.client_builder
.build_new_faucet(0, false, regtest_network)
.await;
let faucet = sb.client_builder.build_faucet(false, regtest_network).await;
faucet.do_sync(false).await.unwrap();

let recipient = sb
.client_builder
.build_newseed_client(
.build_client(
HOSPITAL_MUSEUM_SEED.to_string(),
BASE_HEIGHT as u64,
false,
Expand Down Expand Up @@ -684,15 +668,12 @@ pub mod scenarios {
&regtest_network,
)
.await;
let faucet = sb
.client_builder
.build_new_faucet(0, false, regtest_network)
.await;
let faucet = sb.client_builder.build_faucet(false, regtest_network).await;
faucet.do_sync(false).await.unwrap();

let recipient = sb
.client_builder
.build_newseed_client(
.build_client(
HOSPITAL_MUSEUM_SEED.to_string(),
BASE_HEIGHT as u64,
false,
Expand All @@ -718,7 +699,7 @@ pub mod scenarios {
scenario_builder.child_process_handler.unwrap(),
scenario_builder
.client_builder
.build_newseed_client(HOSPITAL_MUSEUM_SEED.to_string(), 0, false, regtest_network)
.build_client(HOSPITAL_MUSEUM_SEED.to_string(), 0, false, regtest_network)
.await,
)
}
Expand Down Expand Up @@ -749,11 +730,11 @@ pub mod scenarios {
.await;
let faucet = scenario_builder
.client_builder
.build_new_faucet(0, false, regtest_network)
.build_faucet(false, regtest_network)
.await;
let recipient = scenario_builder
.client_builder
.build_newseed_client(HOSPITAL_MUSEUM_SEED.to_string(), 0, false, regtest_network)
.build_client(HOSPITAL_MUSEUM_SEED.to_string(), 0, false, regtest_network)
.await;
faucet.do_sync(false).await.unwrap();
faucet
Expand Down Expand Up @@ -787,11 +768,11 @@ pub mod scenarios {
.await;
let faucet = scenario_builder
.client_builder
.build_new_faucet(0, false, regtest_network)
.build_faucet(false, regtest_network)
.await;
let recipient = scenario_builder
.client_builder
.build_newseed_client(HOSPITAL_MUSEUM_SEED.to_string(), 0, false, regtest_network)
.build_client(HOSPITAL_MUSEUM_SEED.to_string(), 0, false, regtest_network)
.await;
increase_height_and_wait_for_client(&scenario_builder.regtest_manager, &faucet, 1)
.await
Expand Down Expand Up @@ -852,11 +833,11 @@ pub mod scenarios {
.await;
let faucet = scenario_builder
.client_builder
.build_new_faucet(0, false, regtest_network)
.build_faucet(false, regtest_network)
.await;
let recipient = scenario_builder
.client_builder
.build_newseed_client(HOSPITAL_MUSEUM_SEED.to_string(), 0, false, regtest_network)
.build_client(HOSPITAL_MUSEUM_SEED.to_string(), 0, false, regtest_network)
.await;
increase_height_and_wait_for_client(&scenario_builder.regtest_manager, &faucet, 1)
.await
Expand Down Expand Up @@ -986,14 +967,11 @@ pub mod scenarios {
let mut sb =
setup::ScenarioBuilder::new_load_1153_saplingcb_regtest_chain(&regtest_network)
.await;
let faucet = sb
.client_builder
.build_new_faucet(0, false, regtest_network)
.await;
let faucet = sb.client_builder.build_faucet(false, regtest_network).await;
faucet.do_sync(false).await.unwrap();
let recipient = sb
.client_builder
.build_newseed_client(HOSPITAL_MUSEUM_SEED.to_string(), 0, false, regtest_network)
.build_client(HOSPITAL_MUSEUM_SEED.to_string(), 0, false, regtest_network)
.await;
(
sb.regtest_manager,
Expand All @@ -1012,13 +990,10 @@ pub mod scenarios {
let mut sb =
setup::ScenarioBuilder::new_load_1153_saplingcb_regtest_chain(&regtest_network)
.await;
let faucet = sb
.client_builder
.build_new_faucet(0, false, regtest_network)
.await;
let faucet = sb.client_builder.build_faucet(false, regtest_network).await;
let recipient = sb
.client_builder
.build_newseed_client(HOSPITAL_MUSEUM_SEED.to_string(), 0, false, regtest_network)
.build_client(HOSPITAL_MUSEUM_SEED.to_string(), 0, false, regtest_network)
.await;
(
sb.regtest_manager,
Expand Down
33 changes: 11 additions & 22 deletions zingocli/tests/darkside/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,9 @@ async fn simple_sync() {
.await
.unwrap();
let regtest_network = RegtestNetwork::all_upgrades_active();
let light_client = ClientBuilder::new(
server_id,
darkside_handler.darkside_dir.clone(),
DARKSIDE_SEED,
)
.build_new_faucet(1, true, regtest_network)
.await;
let light_client = ClientBuilder::new(server_id, darkside_handler.darkside_dir.clone())
.build_client(DARKSIDE_SEED.to_string(), 0, true, regtest_network)
.await;

let result = light_client.do_sync(true).await.unwrap();

Expand Down Expand Up @@ -263,13 +259,9 @@ async fn reorg_away_receipt() {
.unwrap();

let regtest_network = RegtestNetwork::all_upgrades_active();
let light_client = ClientBuilder::new(
server_id.clone(),
darkside_handler.darkside_dir.clone(),
DARKSIDE_SEED,
)
.build_new_faucet(1, true, regtest_network)
.await;
let light_client = ClientBuilder::new(server_id.clone(), darkside_handler.darkside_dir.clone())
.build_client(DARKSIDE_SEED.to_string(), 0, true, regtest_network)
.await;

light_client.do_sync(true).await.unwrap();
assert_eq!(
Expand Down Expand Up @@ -318,21 +310,18 @@ async fn sent_transaction_reorged_into_mempool() {
.await
.unwrap();

let mut client_manager = ClientBuilder::new(
server_id.clone(),
darkside_handler.darkside_dir.clone(),
DARKSIDE_SEED,
);
let mut client_manager =
ClientBuilder::new(server_id.clone(), darkside_handler.darkside_dir.clone());
let regtest_network = RegtestNetwork::all_upgrades_active();
let light_client = client_manager
.build_new_faucet(1, true, regtest_network.clone())
.build_client(DARKSIDE_SEED.to_string(), 0, true, regtest_network)
.await;
let recipient = client_manager
.build_newseed_client(
.build_client(
crate::data::seeds::HOSPITAL_MUSEUM_SEED.to_string(),
1,
true,
regtest_network.clone(),
regtest_network,
)
.await;

Expand Down
45 changes: 17 additions & 28 deletions zingocli/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ async fn send_without_reorg_buffer_blocks_gives_correct_error() {
async fn dont_write_unconfirmed() {
let regtest_network = RegtestNetwork::all_upgrades_active();
let (regtest_manager, _cph, faucet, recipient) =
scenarios::two_wallet_one_miner_fund(regtest_network.clone()).await;
scenarios::two_wallet_one_miner_fund(regtest_network).await;
faucet
.do_send(vec![(
&get_base_address!(recipient, "unified"),
Expand Down Expand Up @@ -442,17 +442,10 @@ async fn test_scanning_in_watch_only_mode() {

let regtest_network = RegtestNetwork::all_upgrades_active();
let (regtest_manager, _cph, mut client_builder) =
scenarios::custom_clients(regtest_network.clone()).await;
let faucet = client_builder
.build_new_faucet(0, false, regtest_network.clone())
.await;
scenarios::custom_clients(regtest_network).await;
let faucet = client_builder.build_faucet(false, regtest_network).await;
let original_recipient = client_builder
.build_newseed_client(
HOSPITAL_MUSEUM_SEED.to_string(),
0,
false,
regtest_network.clone(),
)
.build_client(HOSPITAL_MUSEUM_SEED.to_string(), 0, false, regtest_network)
.await;
let zingo_config = zingolib::load_clientconfig(
client_builder.server_id,
Expand Down Expand Up @@ -657,7 +650,7 @@ async fn mine_sapling_to_self() {
async fn unspent_notes_are_not_saved() {
let regtest_network = RegtestNetwork::all_upgrades_active();
let (regtest_manager, _cph, faucet, recipient) =
scenarios::two_wallet_one_miner_fund(regtest_network.clone()).await;
scenarios::two_wallet_one_miner_fund(regtest_network).await;
zingo_testutils::increase_height_and_wait_for_client(&regtest_manager, &faucet, 1)
.await
.unwrap();
Expand Down Expand Up @@ -877,12 +870,10 @@ async fn from_t_z_o_tz_to_zo_tzo_to_orchard() {
// Test all possible promoting note source combinations
let regtest_network = RegtestNetwork::all_upgrades_active();
let (regtest_manager, _cph, mut client_builder) =
scenarios::custom_clients(regtest_network.clone()).await;
let sapling_faucet = client_builder
.build_new_faucet(0, false, regtest_network.clone())
.await;
scenarios::custom_clients(regtest_network).await;
let sapling_faucet = client_builder.build_faucet(false, regtest_network).await;
let pool_migration_client = client_builder
.build_newseed_client(HOSPITAL_MUSEUM_SEED.to_string(), 0, false, regtest_network)
.build_client(HOSPITAL_MUSEUM_SEED.to_string(), 0, false, regtest_network)
.await;
let pmc_taddr = get_base_address!(pool_migration_client, "transparent");
let pmc_sapling = get_base_address!(pool_migration_client, "sapling");
Expand Down Expand Up @@ -1214,16 +1205,14 @@ async fn rescan_still_have_outgoing_metadata_with_sends_to_self() {
async fn handling_of_nonregenerated_diversified_addresses_after_seed_restore() {
let regtest_network = RegtestNetwork::all_upgrades_active();
let (regtest_manager, _cph, mut client_builder) =
scenarios::custom_clients(regtest_network.clone()).await;
let faucet = client_builder
.build_new_faucet(0, false, regtest_network.clone())
.await;
scenarios::custom_clients(regtest_network).await;
let faucet = client_builder.build_faucet(false, regtest_network).await;
faucet.do_sync(false).await.unwrap();
let seed_phrase_of_recipient1 = zcash_primitives::zip339::Mnemonic::from_entropy([1; 32])
.unwrap()
.to_string();
let recipient1 = client_builder
.build_newseed_client(seed_phrase_of_recipient1, 0, false, regtest_network.clone())
.build_client(seed_phrase_of_recipient1, 0, false, regtest_network)
.await;
let mut expected_unspent_sapling_notes = json::object! {
"created_in_block" => 4,
Expand Down Expand Up @@ -1285,7 +1274,7 @@ async fn handling_of_nonregenerated_diversified_addresses_after_seed_restore() {
.to_string(),
);
let recipient_restored = client_builder
.build_newseed_client(
.build_client(
seed_of_recipient.seed_phrase.clone(),
0,
true,
Expand Down Expand Up @@ -1339,12 +1328,12 @@ async fn handling_of_nonregenerated_diversified_addresses_after_seed_restore() {
async fn diversification_deterministic_and_coherent() {
let regtest_network = RegtestNetwork::all_upgrades_active();
let (_regtest_manager, _cph, mut client_builder) =
scenarios::custom_clients(regtest_network.clone()).await;
scenarios::custom_clients(regtest_network).await;
let seed_phrase = zcash_primitives::zip339::Mnemonic::from_entropy([1; 32])
.unwrap()
.to_string();
let recipient1 = client_builder
.build_newseed_client(seed_phrase, 0, false, regtest_network)
.build_client(seed_phrase, 0, false, regtest_network)
.await;
let base_transparent_receiver = "tmS9nbexug7uT8x1cMTLP1ABEyKXpMjR5F1";
assert_eq!(
Expand Down Expand Up @@ -1415,12 +1404,12 @@ async fn diversification_deterministic_and_coherent() {
async fn ensure_taddrs_from_old_seeds_work() {
let regtest_network = RegtestNetwork::all_upgrades_active();
let (_regtest_manager, _cph, mut client_builder) =
scenarios::custom_clients(regtest_network.clone()).await;
scenarios::custom_clients(regtest_network).await;
// The first taddr generated on commit 9e71a14eb424631372fd08503b1bd83ea763c7fb
let transparent_address = "tmFLszfkjgim4zoUMAXpuohnFBAKy99rr2i";

let client_b = client_builder
.build_newseed_client(HOSPITAL_MUSEUM_SEED.to_string(), 0, false, regtest_network)
.build_client(HOSPITAL_MUSEUM_SEED.to_string(), 0, false, regtest_network)
.await;

assert_eq!(
Expand Down Expand Up @@ -2786,7 +2775,7 @@ async fn by_address_finsight() {
#[tokio::test]
async fn load_old_wallet_at_reorged_height() {
let regtest_network = RegtestNetwork::all_upgrades_active();
let (ref regtest_manager, cph, ref faucet) = scenarios::faucet(regtest_network.clone()).await;
let (ref regtest_manager, cph, ref faucet) = scenarios::faucet(regtest_network).await;
println!("Shutting down initial zcd/lwd unneeded processes");
drop(cph);

Expand Down

0 comments on commit bd5603c

Please sign in to comment.