Skip to content

Commit

Permalink
Merge branch 'dev' into remove_old_send
Browse files Browse the repository at this point in the history
  • Loading branch information
zancas authored Jun 29, 2024
2 parents 82664d8 + ba1d202 commit 139174c
Show file tree
Hide file tree
Showing 17 changed files with 1,101 additions and 976 deletions.
401 changes: 76 additions & 325 deletions Cargo.lock

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ members = [
resolver = "2"

[workspace.dependencies]
zcash_address = { git = "https://github.com/zingolabs/librustzcash.git", tag = "override_sapling_change_address" }
zcash_client_backend = { git = "https://github.com/zingolabs/librustzcash.git", tag = "override_sapling_change_address", features = ["lightwalletd-tonic", "orchard", "transparent-inputs"] }
zcash_encoding = { git = "https://github.com/zingolabs/librustzcash.git", tag = "override_sapling_change_address" }
zcash_keys = { git = "https://github.com/zingolabs/librustzcash.git", tag = "override_sapling_change_address", features = ["orchard"] }
zcash_address = { git = "https://github.com/zingolabs/librustzcash.git", tag = "always_require_change" }
zcash_client_backend = { git = "https://github.com/zingolabs/librustzcash.git", tag = "always_require_change", features = ["lightwalletd-tonic", "orchard", "transparent-inputs"] }
zcash_encoding = { git = "https://github.com/zingolabs/librustzcash.git", tag = "always_require_change" }
zcash_keys = { git = "https://github.com/zingolabs/librustzcash.git", tag = "always_require_change", features = ["orchard"] }
zcash_note_encryption = "0.4"
zcash_primitives = { git = "https://github.com/zingolabs/librustzcash.git", tag = "override_sapling_change_address" }
zcash_proofs = { git = "https://github.com/zingolabs/librustzcash.git", tag = "override_sapling_change_address" }
zcash_protocol = { git = "https://github.com/zingolabs/librustzcash.git", tag = "override_sapling_change_address" }
zcash_primitives = { git = "https://github.com/zingolabs/librustzcash.git", tag = "always_require_change" }
zcash_proofs = { git = "https://github.com/zingolabs/librustzcash.git", tag = "always_require_change" }
zcash_protocol = { git = "https://github.com/zingolabs/librustzcash.git", tag = "always_require_change" }
sapling-crypto = "0.1.2"
orchard = "0.8"
zip32 = "0.1"
Expand Down
120 changes: 65 additions & 55 deletions darkside-tests/tests/advanced_reorg_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ async fn reorg_changes_incoming_tx_height() {
}
);

let before_reorg_transactions = light_client.list_value_transfers().await;
let before_reorg_transactions = light_client.value_transfers().await.0;

assert_eq!(before_reorg_transactions.len(), 1);
assert_eq!(
before_reorg_transactions[0].block_height,
before_reorg_transactions[0].blockheight(),
BlockHeight::from_u32(203)
);

Expand Down Expand Up @@ -93,11 +93,11 @@ async fn reorg_changes_incoming_tx_height() {
}
);

let after_reorg_transactions = light_client.list_value_transfers().await;
let after_reorg_transactions = light_client.value_transfers().await.0;

assert_eq!(after_reorg_transactions.len(), 1);
assert_eq!(
after_reorg_transactions[0].block_height,
after_reorg_transactions[0].blockheight(),
BlockHeight::from_u32(206)
);
}
Expand Down Expand Up @@ -214,11 +214,11 @@ async fn reorg_changes_incoming_tx_index() {
}
);

let before_reorg_transactions = light_client.list_value_transfers().await;
let before_reorg_transactions = light_client.value_transfers().await.0;

assert_eq!(before_reorg_transactions.len(), 1);
assert_eq!(
before_reorg_transactions[0].block_height,
before_reorg_transactions[0].blockheight(),
BlockHeight::from_u32(203)
);

Expand Down Expand Up @@ -249,11 +249,11 @@ async fn reorg_changes_incoming_tx_index() {
}
);

let after_reorg_transactions = light_client.list_value_transfers().await;
let after_reorg_transactions = light_client.value_transfers().await.0;

assert_eq!(after_reorg_transactions.len(), 1);
assert_eq!(
after_reorg_transactions[0].block_height,
after_reorg_transactions[0].blockheight(),
BlockHeight::from_u32(203)
);
}
Expand Down Expand Up @@ -369,11 +369,11 @@ async fn reorg_expires_incoming_tx() {
}
);

let before_reorg_transactions = light_client.list_value_transfers().await;
let before_reorg_transactions = light_client.value_transfers().await.0;

assert_eq!(before_reorg_transactions.len(), 1);
assert_eq!(
before_reorg_transactions[0].block_height,
before_reorg_transactions[0].blockheight(),
BlockHeight::from_u32(203)
);

Expand Down Expand Up @@ -404,7 +404,7 @@ async fn reorg_expires_incoming_tx() {
}
);

let after_reorg_transactions = light_client.list_value_transfers().await;
let after_reorg_transactions = light_client.value_transfers().await.0;

assert_eq!(after_reorg_transactions.len(), 0);
}
Expand Down Expand Up @@ -547,11 +547,11 @@ async fn reorg_changes_outgoing_tx_height() {
}
);

let before_reorg_transactions = light_client.list_value_transfers().await;
let before_reorg_transactions = light_client.value_transfers().await.0;

assert_eq!(before_reorg_transactions.len(), 1);
assert_eq!(
before_reorg_transactions[0].block_height,
before_reorg_transactions[0].blockheight(),
BlockHeight::from_u32(203)
);

Expand Down Expand Up @@ -597,20 +597,21 @@ async fn reorg_changes_outgoing_tx_height() {
// check that the outgoing transaction has the correct height before
// the reorg is triggered

println!("{:?}", light_client.list_value_transfers().await);
println!("{:?}", light_client.value_transfers().await);

assert_eq!(
light_client
.list_value_transfers()
.value_transfers()
.await
.into_iter()
.find_map(|v| match v.kind {
ValueTransferKind::Sent {
recipient_address,
amount,
} => {
if recipient_address.to_string() == recipient_string && amount == 100000 {
Some(v.block_height)
.iter()
.find_map(|v| match v.kind() {
ValueTransferKind::Sent => {
if let Some(addr) = v.recipient_address() {
if addr.to_string() == recipient_string && v.value() == 100_000 {
Some(v.blockheight())
} else {
None
}
} else {
None
}
Expand Down Expand Up @@ -660,11 +661,11 @@ async fn reorg_changes_outgoing_tx_height() {
expected_after_reorg_balance
);

let after_reorg_transactions = light_client.list_value_transfers().await;
let after_reorg_transactions = light_client.value_transfers().await.0;

assert_eq!(after_reorg_transactions.len(), 3);

println!("{:?}", light_client.list_value_transfers().await);
println!("{:?}", light_client.value_transfers().await);

// FIXME: This test is broken because if this issue
// https://github.com/zingolabs/zingolib/issues/622
Expand Down Expand Up @@ -785,11 +786,11 @@ async fn reorg_expires_outgoing_tx_height() {
light_client.do_sync(true).await.unwrap();
assert_eq!(light_client.do_balance().await, expected_initial_balance);

let before_reorg_transactions = light_client.list_value_transfers().await;
let before_reorg_transactions = light_client.value_transfers().await.0;

assert_eq!(before_reorg_transactions.len(), 1);
assert_eq!(
before_reorg_transactions[0].block_height,
before_reorg_transactions[0].blockheight(),
BlockHeight::from_u32(203)
);

Expand Down Expand Up @@ -828,20 +829,21 @@ async fn reorg_expires_outgoing_tx_height() {
// check that the outgoing transaction has the correct height before
// the reorg is triggered

println!("{:?}", light_client.list_value_transfers().await);
println!("{:?}", light_client.value_transfers().await);

assert_eq!(
light_client
.list_value_transfers()
.value_transfers()
.await
.into_iter()
.find_map(|v| match v.kind {
ValueTransferKind::Sent {
recipient_address,
amount,
} => {
if recipient_address.to_string() == recipient_string && amount == 100000 {
Some(v.block_height)
.iter()
.find_map(|v| match v.kind() {
ValueTransferKind::Sent => {
if let Some(addr) = v.recipient_address() {
if addr.to_string() == recipient_string && v.value() == 100_000 {
Some(v.blockheight())
} else {
None
}
} else {
None
}
Expand Down Expand Up @@ -874,11 +876,11 @@ async fn reorg_expires_outgoing_tx_height() {
// sent transaction was never mined and has expired.
assert_eq!(light_client.do_balance().await, expected_initial_balance);

let after_reorg_transactions = light_client.list_value_transfers().await;
let after_reorg_transactions = light_client.value_transfers().await.0;

assert_eq!(after_reorg_transactions.len(), 1);

println!("{:?}", light_client.list_value_transfers().await);
println!("{:?}", light_client.value_transfers().await);

// FIXME: This test is broken because if this issue
// https://github.com/zingolabs/zingolib/issues/622
Expand Down Expand Up @@ -966,11 +968,11 @@ async fn reorg_changes_outgoing_tx_index() {
}
);

let before_reorg_transactions = light_client.list_value_transfers().await;
let before_reorg_transactions = light_client.value_transfers().await.0;

assert_eq!(before_reorg_transactions.len(), 1);
assert_eq!(
before_reorg_transactions[0].block_height,
before_reorg_transactions[0].blockheight(),
BlockHeight::from_u32(203)
);

Expand Down Expand Up @@ -1016,20 +1018,19 @@ async fn reorg_changes_outgoing_tx_index() {
// check that the outgoing transaction has the correct height before
// the reorg is triggered

println!("{:?}", light_client.list_value_transfers().await);

assert_eq!(
light_client
.list_value_transfers()
.value_transfers()
.await
.into_iter()
.find_map(|v| match v.kind {
ValueTransferKind::Sent {
recipient_address,
amount,
} => {
if recipient_address.to_string() == recipient_string && amount == 100000 {
Some(v.block_height)
.iter()
.find_map(|v| match v.kind() {
ValueTransferKind::Sent => {
if let Some(addr) = v.recipient_address() {
if addr.to_string() == recipient_string && v.value() == 100_000 {
Some(v.blockheight())
} else {
None
}
} else {
None
}
Expand All @@ -1041,6 +1042,11 @@ async fn reorg_changes_outgoing_tx_index() {
Some(BlockHeight::from(sent_tx_height as u32))
);

println!("pre re-org value transfers:");
println!("{}", light_client.value_transfers().await);
println!("pre re-org tx summaries:");
println!("{}", light_client.transaction_summaries().await);

//
// Create reorg
//
Expand Down Expand Up @@ -1085,11 +1091,15 @@ async fn reorg_changes_outgoing_tx_index() {
expected_after_reorg_balance
);

let after_reorg_transactions = light_client.list_value_transfers().await;
let after_reorg_transactions = light_client.value_transfers().await;

assert_eq!(after_reorg_transactions.len(), 3);
println!("post re-org value transfers:");
println!("{}", after_reorg_transactions);
println!("post re-org tx summaries:");
println!("{}", light_client.transaction_summaries().await);

println!("{:?}", after_reorg_transactions);
// FIXME: assertion is wrong as re-org transaction has lost its outgoing tx data. darkside bug?
// assert_eq!(after_reorg_transactions.0.len(), 3);

// FIXME: This test is broken because if this issue
// https://github.com/zingolabs/zingolib/issues/622
Expand Down
29 changes: 12 additions & 17 deletions darkside-tests/tests/network_interruption_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ use darkside_tests::{
DarksideHandler,
},
};
use json::JsonValue;
use tokio::time::sleep;
use zcash_client_backend::{PoolType, ShieldedProtocol};
use zingo_testutils::{
get_base_address_macro, scenarios::setup::ClientBuilder, start_proxy_and_connect_lightclient,
};
use zingoconfig::RegtestNetwork;
use zingolib::{lightclient::PoolBalances, wallet::data::summaries::ValueTransferKind};
use zingolib::{
lightclient::PoolBalances,
wallet::transaction_record::{SendType, TransactionKind},
};

#[ignore]
#[tokio::test]
Expand Down Expand Up @@ -193,7 +195,7 @@ async fn shielded_note_marked_as_change_test() {
json::stringify_pretty(scenario.get_lightclient(0).do_list_notes(true).await, 4)
);
println!("do list tx summaries:");
dbg!(scenario.get_lightclient(0).list_value_transfers().await);
dbg!(scenario.get_lightclient(0).value_transfers().await);

// assert the balance is correct
assert_eq!(
Expand All @@ -210,25 +212,18 @@ async fn shielded_note_marked_as_change_test() {
transparent_balance: Some(0),
}
);
// assert all unspent orchard notes (shielded notes) are marked as change
let notes = scenario.get_lightclient(0).do_list_notes(true).await;
if let JsonValue::Array(unspent_orchard_notes) = &notes["unspent_orchard_notes"] {
for notes in unspent_orchard_notes {
assert!(notes["is_change"].as_bool().unwrap());
}
}
// assert all fees are 10000 zats
let value_transfers = scenario.get_lightclient(0).list_value_transfers().await;
for value_transfer in &value_transfers {
if let ValueTransferKind::Fee { amount } = value_transfer.kind {
assert_eq!(amount, 10_000)
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 that every shield has a send-to-self value transfer
// assert the number of shields are correct
assert_eq!(
value_transfers
transaction_summaries
.iter()
.filter(|vt| vt.kind == ValueTransferKind::SendToSelf)
.filter(|summary| summary.kind() == TransactionKind::Sent(SendType::Shield))
.count(),
(BLOCKCHAIN_HEIGHT / 1000 - 1) as usize
);
Expand Down
Loading

0 comments on commit 139174c

Please sign in to comment.