Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade darkside interface #937

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 49 additions & 14 deletions darkside-tests/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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(),
Expand All @@ -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)
Expand All @@ -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(),
Expand All @@ -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.
Expand Down
13 changes: 2 additions & 11 deletions darkside-tests/tests/network_interruption_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use zingoconfig::RegtestNetwork;
use zingolib::{
get_base_address,
lightclient::PoolBalances,
testvectors::seeds,
wallet::{data::summaries::ValueTransferKind, Pool},
};

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down