zcash_client_sqlite: Move `TestState` to `zcash_client_backend`

This commit is contained in:
Kris Nuttycombe 2024-09-05 21:48:07 -06:00
parent 7e9f78bf46
commit e55df6c493
14 changed files with 1980 additions and 1998 deletions

2
Cargo.lock generated
View File

@ -5854,10 +5854,12 @@ dependencies = [
"nom",
"nonempty",
"orchard",
"pasta_curves",
"percent-encoding",
"proptest",
"prost",
"rand 0.8.5",
"rand_chacha 0.3.1",
"rand_core 0.6.4",
"rayon",
"rust_decimal",

View File

@ -89,9 +89,13 @@ incrementalmerkletree.workspace = true
shardtree.workspace = true
# - Test dependencies
ambassador = { workspace = true, optional = true }
assert_matches = { workspace = true, optional = true }
pasta_curves = { workspace = true, optional = true }
proptest = { workspace = true, optional = true }
jubjub = { workspace = true, optional = true }
ambassador = { workspace = true, optional = true }
rand_chacha = { workspace = true, optional = true }
zcash_proofs = { workspace = true, optional = true }
# - ZIP 321
nom = "7"
@ -138,17 +142,21 @@ tonic-build = { workspace = true, features = ["prost"] }
which = "4"
[dev-dependencies]
ambassador.workspace = true
assert_matches.workspace = true
gumdrop = "0.8"
incrementalmerkletree = { workspace = true, features = ["test-dependencies"] }
jubjub.workspace = true
proptest.workspace = true
rand_core.workspace = true
rand.workspace = true
rand_chacha.workspace = true
shardtree = { workspace = true, features = ["test-dependencies"] }
zcash_proofs.workspace = true
tokio = { version = "1.21.0", features = ["rt-multi-thread"] }
zcash_address = { workspace = true, features = ["test-dependencies"] }
zcash_keys = { workspace = true, features = ["test-dependencies"] }
tokio = { version = "1.21.0", features = ["rt-multi-thread"] }
zcash_primitives = { workspace = true, features = ["test-dependencies"] }
zcash_proofs = { workspace = true, features = ["bundled-prover"] }
zcash_protocol = { workspace = true, features = ["local-consensus"] }
[features]
## Enables the `tonic` gRPC client bindings for connecting to a `lightwalletd` server.
@ -165,7 +173,7 @@ transparent-inputs = [
]
## Enables receiving and spending Orchard funds.
orchard = ["dep:orchard", "zcash_keys/orchard"]
orchard = ["dep:orchard", "dep:pasta_curves", "zcash_keys/orchard"]
## Exposes a wallet synchronization function that implements the necessary state machine.
sync = [
@ -197,11 +205,16 @@ tor = [
## Exposes APIs that are useful for testing, such as `proptest` strategies.
test-dependencies = [
"dep:ambassador",
"dep:assert_matches",
"dep:proptest",
"dep:jubjub",
"dep:rand",
"dep:rand_chacha",
"orchard?/test-dependencies",
"zcash_keys/test-dependencies",
"zcash_primitives/test-dependencies",
"zcash_proofs/bundled-prover",
"zcash_protocol/local-consensus",
"incrementalmerkletree/test-dependencies",
]

View File

@ -1169,7 +1169,7 @@ pub trait WalletRead {
/// Currently test-only, as production use could return a very large number of results; either
/// pagination or a streaming design will be necessary to stabilize this feature for production
/// use.
#[cfg(feature = "test-dependencies")]
#[cfg(any(test, feature = "test-dependencies"))]
fn get_tx_history(
&self,
) -> Result<Vec<testing::TransactionSummary<Self::AccountId>>, Self::Error> {

File diff suppressed because it is too large Load Diff

View File

@ -1698,22 +1698,21 @@ extern crate assert_matches;
mod tests {
use secrecy::{ExposeSecret, Secret, SecretVec};
use zcash_client_backend::data_api::{
chain::ChainState, Account, AccountBirthday, AccountPurpose, AccountSource, WalletRead,
WalletWrite,
chain::ChainState,
testing::{TestBuilder, TestState},
Account, AccountBirthday, AccountPurpose, AccountSource, WalletRead, WalletWrite,
};
use zcash_keys::keys::{UnifiedFullViewingKey, UnifiedSpendingKey};
use zcash_primitives::block::BlockHash;
use zcash_protocol::consensus;
use crate::{
error::SqliteClientError,
testing::{db::TestDbFactory, TestBuilder, TestState},
AccountId, DEFAULT_UA_REQUEST,
error::SqliteClientError, testing::db::TestDbFactory, AccountId, DEFAULT_UA_REQUEST,
};
#[cfg(feature = "unstable")]
use {
crate::testing::AddressType, zcash_client_backend::keys::sapling,
zcash_client_backend::keys::sapling,
zcash_primitives::transaction::components::amount::NonNegativeAmount,
};
@ -1996,8 +1995,9 @@ mod tests {
#[cfg(feature = "unstable")]
#[test]
pub(crate) fn fsblockdb_api() {
use zcash_primitives::consensus::NetworkConstants;
use zcash_client_backend::data_api::testing::AddressType;
use zcash_primitives::zip32;
use zcash_protocol::consensus::NetworkConstants;
use crate::testing::FsBlockCache;

File diff suppressed because it is too large Load Diff

View File

@ -14,6 +14,7 @@ use zcash_client_backend::{
data_api::{
chain::{ChainState, CommitmentTreeRoot},
scanning::ScanRange,
testing::{DataStoreFactory, Reset, TestState},
*,
},
keys::UnifiedFullViewingKey,
@ -30,13 +31,12 @@ use zcash_primitives::{
};
use zcash_protocol::{consensus::BlockHeight, local_consensus::LocalNetwork, memo::Memo};
use super::{DataStoreFactory, Reset, TestState};
use crate::{wallet::init::init_wallet_db, AccountId, WalletDb};
#[cfg(feature = "transparent-inputs")]
use {
core::ops::Range,
crate::TransparentAddressMetadata,
core::ops::Range,
zcash_primitives::{legacy::TransparentAddress, transaction::components::OutPoint},
};
@ -165,7 +165,7 @@ impl Reset for TestDb {
fn reset<C>(st: &mut TestState<C, Self, LocalNetwork>) -> NamedTempFile {
let network = *st.network();
let old_db = std::mem::replace(
&mut st.wallet_data,
st.wallet_mut(),
TestDbFactory.new_data_store(network).unwrap(),
);
old_db.take_data_file()

View File

@ -33,6 +33,10 @@ use zcash_client_backend::{
self,
chain::{self, ChainState, CommitmentTreeRoot, ScanSummary},
error::Error,
testing::{
input_selector, AddressType, FakeCompactOutput, InitialChainState, TestBuilder,
TestFvk, TestState,
},
wallet::{
decrypt_and_store_transaction,
input_selection::{GreedyInputSelector, GreedyInputSelectorError},
@ -50,13 +54,11 @@ use zcash_client_backend::{
};
use zcash_protocol::consensus::{self, BlockHeight};
use super::TestFvk;
use crate::{
error::SqliteClientError,
testing::{
db::{TestDb, TestDbFactory},
input_selector, AddressType, BlockCache, FakeCompactOutput, InitialChainState, TestBuilder,
TestState,
BlockCache,
},
wallet::{commitment_tree, parse_scope, truncate_to_height},
AccountId, NoteId, ReceivedNoteId,
@ -319,11 +321,10 @@ pub(crate) fn send_multi_step_proposed_transfer<T: ShieldedPoolTester>() {
legacy::keys::{NonHardenedChildIndex, TransparentKeyScope},
transaction::builder::{BuildConfig, Builder},
};
use zcash_proofs::prover::LocalTxProver;
use zcash_protocol::value::ZatBalance;
use crate::wallet::{
sapling::tests::test_prover, transparent::get_wallet_transparent_output, GAP_LIMIT,
};
use crate::wallet::{transparent::get_wallet_transparent_output, GAP_LIMIT};
let mut st = TestBuilder::new()
.with_data_store_factory(TestDbFactory)
@ -593,7 +594,7 @@ pub(crate) fn send_multi_step_proposed_transfer<T: ShieldedPoolTester>() {
.unwrap();
assert_matches!(builder.add_transparent_input(sk, outpoint, txout), Ok(_));
let test_prover = test_prover();
let test_prover = LocalTxProver::bundled();
let build_result = builder
.build(
OsRng,
@ -1750,8 +1751,8 @@ pub(crate) fn checkpoint_gaps<T: ShieldedPoolTester>() {
AddressType::DefaultExternal,
not_our_value,
)],
st.latest_cached_block().unwrap().sapling_end_size,
st.latest_cached_block().unwrap().orchard_end_size,
st.latest_cached_block().unwrap().sapling_end_size(),
st.latest_cached_block().unwrap().orchard_end_size(),
false,
);
@ -2106,7 +2107,7 @@ pub(crate) fn multi_pool_checkpoint<P0: ShieldedPoolTester, P1: ShieldedPoolTest
// First, send funds just to P0
let transfer_amount = NonNegativeAmount::const_from_u64(200000);
let p0_transfer = zip321::TransactionRequest::new(vec![Payment::without_memo(
P0::random_address(&mut st.rng).to_zcash_address(st.network()),
P0::random_address(st.rng_mut()).to_zcash_address(st.network()),
transfer_amount,
)])
.unwrap();
@ -2132,11 +2133,11 @@ pub(crate) fn multi_pool_checkpoint<P0: ShieldedPoolTester, P1: ShieldedPoolTest
// In the next block, send funds to both P0 and P1
let both_transfer = zip321::TransactionRequest::new(vec![
Payment::without_memo(
P0::random_address(&mut st.rng).to_zcash_address(st.network()),
P0::random_address(st.rng_mut()).to_zcash_address(st.network()),
transfer_amount,
),
Payment::without_memo(
P1::random_address(&mut st.rng).to_zcash_address(st.network()),
P1::random_address(st.rng_mut()).to_zcash_address(st.network()),
transfer_amount,
),
])
@ -2250,8 +2251,8 @@ pub(crate) fn multi_pool_checkpoints_with_pruning<
let account = st.test_account().cloned().unwrap();
let p0_fvk = P0::random_fvk(&mut st.rng);
let p1_fvk = P1::random_fvk(&mut st.rng);
let p0_fvk = P0::random_fvk(st.rng_mut());
let p1_fvk = P1::random_fvk(st.rng_mut());
let note_value = NonNegativeAmount::const_from_u64(10000);
// Generate 100 P0 blocks, then 100 P1 blocks, then another 100 P0 blocks.

View File

@ -3255,14 +3255,14 @@ mod tests {
use sapling::zip32::ExtendedSpendingKey;
use secrecy::{ExposeSecret, SecretVec};
use zcash_client_backend::data_api::{Account as _, AccountSource, WalletRead, WalletWrite};
use zcash_client_backend::data_api::{
testing::{AddressType, DataStoreFactory, FakeCompactOutput, TestBuilder, TestState},
Account as _, AccountSource, WalletRead, WalletWrite,
};
use zcash_primitives::{block::BlockHash, transaction::components::amount::NonNegativeAmount};
use crate::{
testing::{
db::TestDbFactory, AddressType, BlockCache, DataStoreFactory, FakeCompactOutput,
TestBuilder, TestState,
},
testing::{db::TestDbFactory, BlockCache},
AccountId,
};

View File

@ -418,6 +418,7 @@ mod tests {
use zcash_client_backend::{
address::Address,
data_api::testing::TestBuilder,
encoding::{encode_extended_full_viewing_key, encode_payment_address},
keys::{sapling, UnifiedAddressRequest, UnifiedFullViewingKey, UnifiedSpendingKey},
};
@ -429,11 +430,7 @@ mod tests {
zip32::AccountId,
};
use crate::{
testing::{db::TestDbFactory, TestBuilder},
wallet::db,
WalletDb, UA_TRANSPARENT,
};
use crate::{testing::db::TestDbFactory, wallet::db, WalletDb, UA_TRANSPARENT};
use super::init_wallet_db;

View File

@ -397,8 +397,8 @@ pub(crate) mod tests {
use shardtree::error::ShardTreeError;
use zcash_client_backend::{
data_api::{
chain::CommitmentTreeRoot, DecryptedTransaction, InputSource, WalletCommitmentTrees,
WalletRead, WalletSummary,
chain::CommitmentTreeRoot, testing::TestState, DecryptedTransaction, InputSource,
WalletCommitmentTrees, WalletRead, WalletSummary,
},
wallet::{Note, ReceivedNote},
};
@ -419,7 +419,6 @@ pub(crate) mod tests {
testing::{
self,
pool::{OutputRecoveryError, ShieldedPoolTester},
TestState,
},
wallet::sapling::tests::SaplingPoolTester,
ORCHARD_TABLES_PREFIX,

View File

@ -403,12 +403,10 @@ pub(crate) mod tests {
use incrementalmerkletree::{Hashable, Level};
use shardtree::error::ShardTreeError;
use zcash_proofs::prover::LocalTxProver;
use sapling::{
self,
note_encryption::try_sapling_output_recovery,
prover::{OutputProver, SpendProver},
zip32::{DiversifiableFullViewingKey, ExtendedSpendingKey},
};
use zcash_primitives::{
@ -424,8 +422,8 @@ pub(crate) mod tests {
use zcash_client_backend::{
address::Address,
data_api::{
chain::CommitmentTreeRoot, DecryptedTransaction, InputSource, WalletCommitmentTrees,
WalletRead, WalletSummary,
chain::CommitmentTreeRoot, testing::TestState, DecryptedTransaction, InputSource,
WalletCommitmentTrees, WalletRead, WalletSummary,
},
keys::UnifiedSpendingKey,
wallet::{Note, ReceivedNote},
@ -437,7 +435,6 @@ pub(crate) mod tests {
testing::{
self,
pool::{OutputRecoveryError, ShieldedPoolTester},
TestState,
},
AccountId, SAPLING_TABLES_PREFIX,
};
@ -571,10 +568,6 @@ pub(crate) mod tests {
}
}
pub(crate) fn test_prover() -> impl SpendProver + OutputProver {
LocalTxProver::bundled()
}
#[test]
fn send_single_step_proposed_transfer() {
testing::pool::send_single_step_proposed_transfer::<SaplingPoolTester>()

View File

@ -587,6 +587,7 @@ pub(crate) mod tests {
use zcash_client_backend::data_api::{
chain::{ChainState, CommitmentTreeRoot},
scanning::{spanning_tree::testing::scan_range, ScanPriority},
testing::{AddressType, FakeCompactOutput, InitialChainState, TestBuilder, TestState},
AccountBirthday, Ratio, WalletRead, WalletWrite, SAPLING_SHARD_HEIGHT,
};
use zcash_primitives::{
@ -601,7 +602,7 @@ pub(crate) mod tests {
testing::{
db::{TestDb, TestDbFactory},
pool::ShieldedPoolTester,
AddressType, BlockCache, FakeCompactOutput, InitialChainState, TestBuilder, TestState,
BlockCache,
},
wallet::{
sapling::tests::SaplingPoolTester,

View File

@ -824,14 +824,15 @@ pub(crate) fn queue_transparent_spend_detection<P: consensus::Parameters>(
mod tests {
use crate::testing::{
db::{TestDb, TestDbFactory},
AddressType, BlockCache, TestBuilder, TestState,
BlockCache,
};
use sapling::zip32::ExtendedSpendingKey;
use zcash_client_backend::{
data_api::{
wallet::input_selection::GreedyInputSelector, Account as _, InputSource, WalletRead,
WalletWrite,
testing::{AddressType, TestBuilder, TestState},
wallet::input_selection::GreedyInputSelector,
Account as _, InputSource, WalletRead, WalletWrite,
},
encoding::AddressCodec,
fees::{fixed, DustOutputPolicy},
@ -847,8 +848,6 @@ mod tests {
#[test]
fn put_received_transparent_utxo() {
use crate::testing::TestBuilder;
let mut st = TestBuilder::new()
.with_data_store_factory(TestDbFactory)
.with_account_from_sapling_activation(BlockHash([0; 32]))