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

Sync integration pt1 revisited #1610

Merged
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: tarpaulin
args: --all-features --verbose --workspace --avoid-cfg-tarpaulin --skip-clean --release --timeout 3000 --out xml
args: --verbose --workspace --avoid-cfg-tarpaulin --skip-clean --release --timeout 3000 --out xml

- name: Upload to codecov.io
uses: codecov/codecov-action@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
uses: Swatinem/rust-cache@v2

- name: Build and archive tests
run: cargo nextest archive --verbose --workspace --all-features --archive-file nextest-archive.tar.zst
run: cargo nextest archive --verbose --workspace --archive-file nextest-archive.tar.zst

- name: Upload archive
uses: actions/upload-artifact@v4
Expand Down
220 changes: 105 additions & 115 deletions darkside-tests/tests/network_interruption_tests.rs
Original file line number Diff line number Diff line change
@@ -1,32 +1,21 @@
use std::{
collections::HashMap,
sync::{
atomic::{AtomicBool, Ordering},
Arc, Mutex,
},
time::Duration,
sync::{atomic::AtomicBool, Arc, Mutex},
};

use darkside_tests::{
constants::DARKSIDE_SEED,
utils::{
create_chainbuild_file, load_chainbuild_file, prepare_darksidewalletd,
create_chainbuild_file, prepare_darksidewalletd,
scenarios::{DarksideEnvironment, DarksideSender},
DarksideHandler,
},
};
use tokio::time::sleep;

use zcash_client_backend::{PoolType, ShieldedProtocol};
use zingolib::config::RegtestNetwork;
use zingolib::get_base_address_macro;
use zingolib::testutils::{scenarios::setup::ClientBuilder, start_proxy_and_connect_lightclient};
use zingolib::{
lightclient::PoolBalances,
wallet::{
data::summaries::TransactionSummaryInterface as _,
transaction_record::{SendType, TransactionKind},
},
};

#[ignore]
#[tokio::test]
Expand Down Expand Up @@ -128,110 +117,111 @@ async fn shielded_note_marked_as_change_chainbuild() {
// json::stringify_pretty(scenario.get_lightclient(0).do_list_notes(true).await, 4)
// );
}
#[ignore]
#[tokio::test]
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 = DarksideEnvironment::default_faucet_recipient(PoolType::Shielded(
ShieldedProtocol::Sapling,
))
.await;
// // FIXME:
// #[ignore]
// #[tokio::test]
// 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 = DarksideEnvironment::default_faucet_recipient(PoolType::Shielded(
// ShieldedProtocol::Sapling,
// ))
// .await;

// stage a send to self every thousand blocks
for thousands_blocks_count in 1..BLOCKCHAIN_HEIGHT / 1000 {
scenario
.stage_and_apply_blocks(thousands_blocks_count * 1000 - 2, 0)
.await;
scenario.stage_next_transaction(&transaction_set).await;
scenario
.apply_blocks(thousands_blocks_count * 1000 - 1)
.await;
scenario.stage_next_transaction(&transaction_set).await;
}
// stage and apply final blocks
scenario.stage_and_apply_blocks(BLOCKCHAIN_HEIGHT, 0).await;
// // stage a send to self every thousand blocks
// for thousands_blocks_count in 1..BLOCKCHAIN_HEIGHT / 1000 {
// scenario
// .stage_and_apply_blocks(thousands_blocks_count * 1000 - 2, 0)
// .await;
// scenario.stage_next_transaction(&transaction_set).await;
// scenario
// .apply_blocks(thousands_blocks_count * 1000 - 1)
// .await;
// scenario.stage_next_transaction(&transaction_set).await;
// }
// // stage and apply final blocks
// scenario.stage_and_apply_blocks(BLOCKCHAIN_HEIGHT, 0).await;

// setup gRPC network interrupt conditions
let mut conditional_logic =
HashMap::<&'static str, Box<dyn Fn(Arc<AtomicBool>) + Send + Sync>>::new();
// conditional_logic.insert(
// "get_block_range",
// Box::new(|online: &Arc<AtomicBool>| {
// println!("Turning off, as we received get_block_range call");
// online.store(false, Ordering::Relaxed);
// }),
// );
conditional_logic.insert(
"get_tree_state",
Box::new(|online: Arc<AtomicBool>| {
println!("Turning off, as we received get_tree_state call");
online.store(false, Ordering::Relaxed);
}),
);
conditional_logic.insert(
"get_transaction",
Box::new(|online: Arc<AtomicBool>| {
println!("Turning off, as we received get_transaction call");
online.store(false, Ordering::Relaxed);
}),
);
// // setup gRPC network interrupt conditions
// let mut conditional_logic =
// HashMap::<&'static str, Box<dyn Fn(Arc<AtomicBool>) + Send + Sync>>::new();
// // conditional_logic.insert(
// // "get_block_range",
// // Box::new(|online: &Arc<AtomicBool>| {
// // println!("Turning off, as we received get_block_range call");
// // online.store(false, Ordering::Relaxed);
// // }),
// // );
// conditional_logic.insert(
// "get_tree_state",
// Box::new(|online: Arc<AtomicBool>| {
// println!("Turning off, as we received get_tree_state call");
// online.store(false, Ordering::Relaxed);
// }),
// );
// conditional_logic.insert(
// "get_transaction",
// Box::new(|online: Arc<AtomicBool>| {
// println!("Turning off, as we received get_transaction call");
// online.store(false, Ordering::Relaxed);
// }),
// );

let (_proxy_handle, proxy_status) =
start_proxy_and_connect_lightclient(scenario.get_lightclient(0), conditional_logic);
tokio::task::spawn(async move {
loop {
sleep(Duration::from_secs(5)).await;
proxy_status.store(true, std::sync::atomic::Ordering::Relaxed);
println!("Set proxy status to true");
}
});
// let (_proxy_handle, proxy_status) =
// start_proxy_and_connect_lightclient(scenario.get_lightclient(0), conditional_logic);
// tokio::task::spawn(async move {
// loop {
// sleep(Duration::from_secs(5)).await;
// proxy_status.store(true, std::sync::atomic::Ordering::Relaxed);
// println!("Set proxy status to true");
// }
// });

// start test
scenario.get_lightclient(0).do_sync(false).await.unwrap();
// // start test
// scenario.get_lightclient(0).do_sync(false).await.unwrap();

// debug info
println!("do list_notes:");
println!(
"{}",
json::stringify_pretty(scenario.get_lightclient(0).do_list_notes(true).await, 4)
);
println!("do list tx summaries:");
dbg!(
scenario
.get_lightclient(0)
.sorted_value_transfers(true)
.await
);
// // debug info
// println!("do list_notes:");
// println!(
// "{}",
// json::stringify_pretty(scenario.get_lightclient(0).do_list_notes(true).await, 4)
// );
// println!("do list tx summaries:");
// dbg!(
// scenario
// .get_lightclient(0)
// .sorted_value_transfers(true)
// .await
// );

// assert the balance is correct
assert_eq!(
scenario.get_lightclient(0).do_balance().await,
PoolBalances {
sapling_balance: Some(0),
verified_sapling_balance: Some(0),
spendable_sapling_balance: Some(0),
unverified_sapling_balance: Some(0),
orchard_balance: Some(760_000),
verified_orchard_balance: Some(760_000),
unverified_orchard_balance: Some(0),
spendable_orchard_balance: Some(760_000),
transparent_balance: Some(0),
}
);
// assert all fees are 10000 zats
let transaction_summaries = scenario.get_lightclient(0).transaction_summaries().await;
for summary in transaction_summaries.iter() {
if let Some(fee) = summary.fee() {
assert_eq!(fee, 10_000);
}
}
// assert the number of shields are correct
assert_eq!(
transaction_summaries
.iter()
.filter(|summary| summary.kind() == TransactionKind::Sent(SendType::Shield))
.count(),
(BLOCKCHAIN_HEIGHT / 1000 - 1) as usize
);
}
// // assert the balance is correct
// assert_eq!(
// scenario.get_lightclient(0).do_balance().await,
// PoolBalances {
// sapling_balance: Some(0),
// verified_sapling_balance: Some(0),
// spendable_sapling_balance: Some(0),
// unverified_sapling_balance: Some(0),
// orchard_balance: Some(760_000),
// verified_orchard_balance: Some(760_000),
// unverified_orchard_balance: Some(0),
// spendable_orchard_balance: Some(760_000),
// transparent_balance: Some(0),
// }
// );
// // assert all fees are 10000 zats
// let transaction_summaries = scenario.get_lightclient(0).transaction_summaries().await;
// for summary in transaction_summaries.iter() {
// if let Some(fee) = summary.fee() {
// assert_eq!(fee, 10_000);
// }
// }
// // assert the number of shields are correct
// assert_eq!(
// transaction_summaries
// .iter()
// .filter(|summary| summary.kind() == TransactionKind::Sent(SendType::Shield))
// .count(),
// (BLOCKCHAIN_HEIGHT / 1000 - 1) as usize
// );
// }
13 changes: 4 additions & 9 deletions darkside-tests/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use darkside_tests::utils::update_tree_states_for_transaction;
use darkside_tests::utils::DarksideHandler;
use std::future::Future;
use std::pin::Pin;
use std::sync::Arc;
use testvectors::seeds::DARKSIDE_SEED;
use tokio::time::sleep;
use zcash_client_backend::PoolType::Shielded;
Expand Down Expand Up @@ -59,11 +58,6 @@ async fn simple_sync() {
);
}

#[tokio::test]
async fn reorg_away_receipt_blaze() {
reorg_receipt_sync_generic(|lc| Box::pin(async { lc.do_sync(true).await.map(|_| ()) })).await;
}

#[ignore = "attempts to unwrap failed checked_sub on sapling output count"]
#[tokio::test]
async fn reorg_away_receipt_pepper() {
Expand All @@ -74,7 +68,7 @@ async fn reorg_away_receipt_pepper() {
.get_client()
.await
.unwrap();
zingo_sync::sync::sync(client, &lc.config().chain.clone(), &mut lc.wallet)
zingo_sync::sync::sync(client, &lc.config().chain.clone(), lc.wallet.clone())
.await
.map_err(|e| e.to_string())
})
Expand Down Expand Up @@ -331,6 +325,7 @@ async fn evicted_transaction_is_rebroadcast() {
);
});

let ref_primary: Arc<LightClient> = Arc::new(primary);
LightClient::start_mempool_monitor(ref_primary).unwrap();
// FIXME:
// let ref_primary: Arc<LightClient> = Arc::new(primary);
// LightClient::start_mempool_monitor(ref_primary).unwrap();
}
5 changes: 3 additions & 2 deletions libtonode-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ edition = "2021"
[features]
chain_generic_tests = []
ci = ["zingolib/ci"]
sync = ["dep:zingo-sync"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
zingolib = { path = "../zingolib", features = ["deprecations", "test-elevation", "sync"] }
zingolib = { path = "../zingolib", features = [ "deprecations", "test-elevation" ] }
zingo-status = { path = "../zingo-status" }
zingo-netutils = { path = "../zingo-netutils" }
zingo-sync = { path = "../zingo-sync" }
zingo-sync = { path = "../zingo-sync", optional = true }
testvectors = { path = "../testvectors" }

bip0039.workspace = true
Expand Down
Loading
Loading