Skip to content

Commit

Permalink
Merge remote-tracking branch 'zingolabs/dev' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
zancas committed Jul 15, 2024
2 parents 59078cf + b2d92a3 commit 6e1a16f
Show file tree
Hide file tree
Showing 35 changed files with 707 additions and 420 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Zingo-CLI does automatic note and utxo management, which means it doesn't allow
## Compiling from source

#### Pre-requisites
* Rust v1.70 or higher.
* Rust v1.79 or higher.
* Run `rustup update` to get the latest version of Rust if you already have it installed
* Rustfmt
* Run `rustup component add rustfmt` to add rustfmt
Expand Down
4 changes: 4 additions & 0 deletions darkside-tests/src/chain_generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,9 @@ pub(crate) mod impl_conduct_chain_for_darkside_environment {
self.staged_blockheight = self.staged_blockheight + 1;
self.apply_blocks(u64::from(self.staged_blockheight)).await;
}

fn get_chain_height(&mut self) -> u32 {
self.staged_blockheight.into()
}
}
}
6 changes: 3 additions & 3 deletions darkside-tests/tests/advanced_reorg_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ async fn reorg_changes_outgoing_tx_height() {
.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 {
if addr == recipient_string && v.value() == 100_000 {
Some(v.blockheight())
} else {
None
Expand Down Expand Up @@ -839,7 +839,7 @@ async fn reorg_expires_outgoing_tx_height() {
.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 {
if addr == recipient_string && v.value() == 100_000 {
Some(v.blockheight())
} else {
None
Expand Down Expand Up @@ -1026,7 +1026,7 @@ async fn reorg_changes_outgoing_tx_index() {
.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 {
if addr == recipient_string && v.value() == 100_000 {
Some(v.blockheight())
} else {
None
Expand Down
7 changes: 7 additions & 0 deletions libtonode-tests/tests/chain_generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,13 @@ mod chain_generics {
target
);
}

fn get_chain_height(&mut self) -> u32 {
self.scenario_builder
.regtest_manager
.get_current_height()
.unwrap()
}
}
}
}
93 changes: 89 additions & 4 deletions libtonode-tests/tests/concrete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,89 @@ mod fast {
use zcash_address::unified::Encoding;
use zcash_client_backend::{PoolType, ShieldedProtocol};
use zcash_primitives::transaction::components::amount::NonNegativeAmount;
use zingo_status::confirmation_status::ConfirmationStatus;
use zingo_testutils::lightclient::from_inputs;
use zingolib::wallet::WalletBase;
use zingolib::{
utils::conversion::txid_from_hex_encoded_str,
wallet::{notes::ShieldedNoteInterface, WalletBase},
};

use super::*;

#[tokio::test]
async fn targetted_rescan() {
let (regtest_manager, _cph, _faucet, recipient, txid) =
scenarios::orchard_funded_recipient(100_000).await;

*recipient
.wallet
.transaction_context
.transaction_metadata_set
.write()
.await
.transaction_records_by_id
.get_mut(&txid_from_hex_encoded_str(&txid).unwrap())
.unwrap()
.orchard_notes[0]
.output_index_mut() = None;

let tx_summaries = recipient.transaction_summaries().await.0;
assert!(tx_summaries[0].orchard_notes()[0].output_index().is_none());

increase_height_and_wait_for_client(&regtest_manager, &recipient, 1)
.await
.unwrap();

let tx_summaries = recipient.transaction_summaries().await.0;
assert!(tx_summaries[0].orchard_notes()[0].output_index().is_some());
}

#[tokio::test]
async fn received_tx_status_pending_to_confirmed_with_mempool_monitor() {
let (regtest_manager, _cph, faucet, recipient, _txid) =
scenarios::orchard_funded_recipient(100_000).await;

let recipient = std::sync::Arc::new(recipient);

from_inputs::quick_send(
&faucet,
vec![(
&get_base_address_macro!(&recipient, "sapling"),
20_000,
None,
)],
)
.await
.unwrap();

LightClient::start_mempool_monitor(recipient.clone());
tokio::time::sleep(Duration::from_secs(5)).await;

let transactions = &recipient.transaction_summaries().await.0;
assert_eq!(
transactions
.iter()
.find(|tx| tx.value() == 20_000)
.unwrap()
.status(),
ConfirmationStatus::Pending(BlockHeight::from_u32(5)) // FIXME: mempool blockheight is at chain hieght instead of chain height + 1
);

increase_height_and_wait_for_client(&regtest_manager, &recipient, 1)
.await
.unwrap();

let transactions = &recipient.transaction_summaries().await.0;
assert_eq!(
transactions
.iter()
.find(|tx| tx.value() == 20_000)
.unwrap()
.status(),
ConfirmationStatus::Confirmed(BlockHeight::from_u32(6))
);
}

#[tokio::test]
async fn utxos_are_not_prematurely_confirmed() {
let (regtest_manager, _cph, faucet, recipient) =
Expand Down Expand Up @@ -1968,12 +2047,14 @@ mod slow {
// 5. Check the pending transaction is present
// 5.1 Check notes

let notes = recipient.do_list_notes(true).await;
let notes = dbg!(recipient.do_list_notes(true).await);

// Has a new (pending) unspent note (the change)
assert_eq!(notes["unspent_orchard_notes"].len(), 0); // Change for z-to-z is now sapling

assert_eq!(notes["spent_sapling_notes"].len(), 0);

// note is now pending_spent
assert_eq!(notes["pending_sapling_notes"].len(), 1);
assert_eq!(
notes["pending_sapling_notes"][0]["created_in_txid"],
Expand Down Expand Up @@ -2407,6 +2488,8 @@ mod slow {
// More explicit than ignoring the unused variable, we only care about this in order to drop it
*/
}

// FIXME: it seems this test makes assertions on mempool but mempool monitoring is off?
#[tokio::test]
async fn mempool_clearing_and_full_batch_syncs_correct_trees() {
async fn do_maybe_recent_txid(lc: &LightClient) -> JsonValue {
Expand Down Expand Up @@ -2693,6 +2776,7 @@ mod slow {
.unwrap()
)
}
// FIXME: it seems this test makes assertions on mempool but mempool monitoring is off?
#[tokio::test]
async fn mempool_and_balance() {
let value = 100_000;
Expand Down Expand Up @@ -2908,9 +2992,10 @@ mod slow {
let txid2 = utils::conversion::txid_from_hex_encoded_str("7a9d41caca143013ebd2f710e4dad04f0eb9f0ae98b42af0f58f25c61a9d439e").unwrap();
let expected_txids = vec![txid1, txid2];
// in case the txids are in reverse order
if output_error != expected_txids {
let missing_index_txids: Vec<zcash_primitives::transaction::TxId> = output_error.into_iter().map(|(txid, _)| txid).collect();
if missing_index_txids != expected_txids {
let expected_txids = vec![txid2, txid1];
assert!(output_error == expected_txids, "{:?}\n\n{:?}", output_error, expected_txids);
assert!(missing_index_txids == expected_txids, "{:?}\n\n{:?}", missing_index_txids, expected_txids);
}
};
}
Expand Down
2 changes: 1 addition & 1 deletion zingo-status/src/confirmation_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use zcash_primitives::consensus::BlockHeight;
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum ConfirmationStatus {
/// The transaction is pending confirmation to the zcash blockchain. It may be waiting in the mempool.
/// The BlockHeight is the height of the chain as the transaction was broadcast.
/// The BlockHeight is the 1 + the height of the chain as the transaction was broadcast, i.e. the target height.
Pending(BlockHeight),
/// The transaction has been included in at-least one block mined to the zcash blockchain.
/// The height of a confirmed block that contains the transaction.
Expand Down
1 change: 1 addition & 0 deletions zingo-testutils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ zingoconfig = { path = "../zingoconfig" }
zingolib = { path = "../zingolib" }
zingo-netutils = { path = "../zingo-netutils", features = ["test-features"] }
zingo-testvectors = { path = "../zingo-testvectors" }
zingo-status = { path = "../zingo-status" }

zcash_client_backend = { workspace = true }
zcash_primitives = { workspace = true }
Expand Down
7 changes: 6 additions & 1 deletion zingo-testutils/src/assertions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use nonempty::NonEmpty;

use zcash_client_backend::proposal::Proposal;
use zcash_primitives::transaction::TxId;

use zingo_status::confirmation_status::ConfirmationStatus;
use zingolib::{lightclient::LightClient, wallet::notes::query::OutputQuery};

/// currently checks:
Expand All @@ -12,10 +14,11 @@ use zingolib::{lightclient::LightClient, wallet::notes::query::OutputQuery};
/// 3. if the fee from the calculate_transaction_fee matches the sum of the per-step fees
/// this currently fails for any broadcast but not confirmed transaction: it seems like get_transaction_fee does not recognize pending spends
/// returns the total fee for the transfer
pub async fn assert_sender_fee<NoteId>(
pub async fn assert_record_fee_and_status<NoteId>(
client: &LightClient,
proposal: &Proposal<zcash_primitives::transaction::fees::zip317::FeeRule, NoteId>,
txids: &NonEmpty<TxId>,
expected_status: ConfirmationStatus,
) -> u64 {
let records = &client
.wallet
Expand All @@ -30,6 +33,8 @@ pub async fn assert_sender_fee<NoteId>(
for (i, step) in proposal.steps().iter().enumerate() {
let record = records.get(&txids[i]).expect("sender must recognize txid");
// does this record match this step?
// we can check that it has the expected status
assert_eq!(record.status, expected_status);
// may fail in uncertain ways if used on a transaction we dont have an OutgoingViewingKey for
let recorded_fee = records.calculate_transaction_fee(record).unwrap();
assert_eq!(recorded_fee, step.balance().fee_required().into_u64());
Expand Down
3 changes: 3 additions & 0 deletions zingo-testutils/src/chain_generics/conduct_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ pub trait ConductChain {
/// and confirming transactions that were received by the server
async fn bump_chain(&mut self);

/// gets the height. does not yet need to be async
fn get_chain_height(&mut self) -> u32;

/// builds a client and funds it in orchard and syncs it
async fn fund_client_orchard(&mut self, value: u64) -> LightClient {
let faucet = self.create_faucet().await;
Expand Down
Loading

0 comments on commit 6e1a16f

Please sign in to comment.