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

Migrate all zcash_client_sqlite pool tests to zcash_client_backend and make them generic over backend implementation #1533

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
9 changes: 9 additions & 0 deletions zcash_client_backend/src/data_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,15 @@ pub trait InputSource {
) -> Result<Vec<WalletTransparentOutput>, Self::Error> {
Ok(vec![])
}

/// Return the notes with a given value
#[cfg(any(test, feature = "test-dependencies"))]
fn get_notes(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In #1539 I'm moving these to a dedicated WalletTest trait so we can freely expose whatever internals are needed for testing purposes. (I'll handle any conflicts.)

&self,
_protocol: ShieldedProtocol,
) -> Result<Vec<ReceivedNote<Self::NoteRef, Note>>, Self::Error> {
Ok(vec![])
}
}

/// Read-only operations required for light wallet functions.
Expand Down
22 changes: 21 additions & 1 deletion zcash_client_backend/src/data_api/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ pub struct TransactionSummary<AccountId> {
memo_count: usize,
expired_unmined: bool,
is_shielding: bool,
raw: Vec<u8>,
}

impl<AccountId> TransactionSummary<AccountId> {
Expand All @@ -118,6 +119,7 @@ impl<AccountId> TransactionSummary<AccountId> {
memo_count: usize,
expired_unmined: bool,
is_shielding: bool,
raw: &[u8],
) -> Self {
Self {
account_id,
Expand All @@ -133,6 +135,7 @@ impl<AccountId> TransactionSummary<AccountId> {
memo_count,
expired_unmined,
is_shielding,
raw: raw.to_vec(),
}
}

Expand Down Expand Up @@ -701,7 +704,7 @@ where
Cache: TestCache,
<Cache::BlockSource as BlockSource>::Error: fmt::Debug,
ParamsT: consensus::Parameters + Send + 'static,
DbT: InputSource + WalletWrite + WalletCommitmentTrees,
DbT: InputSource<AccountId = <DbT as WalletRead>::AccountId, Error = <DbT as WalletRead>::Error> + WalletWrite + WalletCommitmentTrees,
<DbT as WalletRead>::AccountId: ConditionallySelectable + Default + Send + 'static,
{
/// Invokes [`scan_cached_blocks`] with the given arguments, expecting success.
Expand Down Expand Up @@ -756,6 +759,23 @@ where

Ok(())
}

pub fn add_funds<Fvk: TestFvk>(&mut self, account: &TestAccount<<DbT as WalletRead>::Account>, fvk: &Fvk, value: NonNegativeAmount) {
let account_id = account.id();

let (h, _, _) = self.generate_next_block(&fvk, AddressType::DefaultExternal, value);
self.scan_cached_blocks(h, 1);

assert_eq!(
self.wallet()
.block_max_scanned()
.unwrap()
.unwrap()
.block_height(),
h
);
assert_eq!(self.get_spendable_balance(account_id, 1), value);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assertion being embedded here is a bit surprising, because a caller could reasonably expect to be able to call this in locations other than just at the start of a test.

}
}

impl<Cache, DbT, ParamsT, AccountIdT, ErrT> TestState<Cache, DbT, ParamsT>
Expand Down
Loading