zcash_client_sqlite: Remove `testing::network` global accessor function.
This commit is contained in:
parent
3be55ae964
commit
a238007e14
|
@ -1,6 +1,6 @@
|
||||||
use std::convert::Infallible;
|
use std::convert::Infallible;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::{collections::HashMap, num::NonZeroU32};
|
use std::num::NonZeroU32;
|
||||||
|
|
||||||
#[cfg(feature = "unstable")]
|
#[cfg(feature = "unstable")]
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
|
@ -15,14 +15,13 @@ use tempfile::NamedTempFile;
|
||||||
use tempfile::TempDir;
|
use tempfile::TempDir;
|
||||||
|
|
||||||
#[allow(deprecated)]
|
#[allow(deprecated)]
|
||||||
use zcash_client_backend::data_api::wallet::create_spend_to_address;
|
|
||||||
use zcash_client_backend::{
|
use zcash_client_backend::{
|
||||||
address::RecipientAddress,
|
address::RecipientAddress,
|
||||||
data_api::{
|
data_api::{
|
||||||
self,
|
self,
|
||||||
chain::{scan_cached_blocks, BlockSource},
|
chain::{scan_cached_blocks, BlockSource},
|
||||||
wallet::{
|
wallet::{
|
||||||
create_proposed_transaction,
|
create_proposed_transaction, create_spend_to_address,
|
||||||
input_selection::{GreedyInputSelectorError, InputSelector, Proposal},
|
input_selection::{GreedyInputSelectorError, InputSelector, Proposal},
|
||||||
propose_transfer, spend,
|
propose_transfer, spend,
|
||||||
},
|
},
|
||||||
|
@ -37,7 +36,7 @@ use zcash_client_backend::{
|
||||||
use zcash_note_encryption::Domain;
|
use zcash_note_encryption::Domain;
|
||||||
use zcash_primitives::{
|
use zcash_primitives::{
|
||||||
block::BlockHash,
|
block::BlockHash,
|
||||||
consensus::{BlockHeight, Network, NetworkUpgrade, Parameters},
|
consensus::{self, BlockHeight, Network, NetworkUpgrade, Parameters},
|
||||||
legacy::TransparentAddress,
|
legacy::TransparentAddress,
|
||||||
memo::MemoBytes,
|
memo::MemoBytes,
|
||||||
sapling::{
|
sapling::{
|
||||||
|
@ -54,13 +53,6 @@ use zcash_primitives::{
|
||||||
zip32::{sapling::DiversifiableFullViewingKey, DiversifierIndex},
|
zip32::{sapling::DiversifiableFullViewingKey, DiversifierIndex},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(feature = "transparent-inputs")]
|
|
||||||
use zcash_client_backend::data_api::wallet::{propose_shielding, shield_transparent_funds};
|
|
||||||
#[cfg(feature = "transparent-inputs")]
|
|
||||||
use zcash_primitives::{
|
|
||||||
legacy, legacy::keys::IncomingViewingKey, transaction::components::amount::NonNegativeAmount,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
chain::init::init_cache_database,
|
chain::init::init_cache_database,
|
||||||
error::SqliteClientError,
|
error::SqliteClientError,
|
||||||
|
@ -74,13 +66,24 @@ use crate::{
|
||||||
|
|
||||||
use super::BlockDb;
|
use super::BlockDb;
|
||||||
|
|
||||||
|
#[cfg(feature = "transparent-inputs")]
|
||||||
|
use {
|
||||||
|
zcash_client_backend::data_api::wallet::{propose_shielding, shield_transparent_funds},
|
||||||
|
zcash_primitives::{
|
||||||
|
legacy::{self, keys::IncomingViewingKey},
|
||||||
|
transaction::components::amount::NonNegativeAmount,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
#[cfg(feature = "unstable")]
|
#[cfg(feature = "unstable")]
|
||||||
use crate::{
|
use crate::{
|
||||||
chain::{init::init_blockmeta_db, BlockMeta},
|
chain::{init::init_blockmeta_db, BlockMeta},
|
||||||
FsBlockDb,
|
FsBlockDb,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A builder for a `zcash_client_sqlite` test.
|
/// A builder for a `zcash_client_sqlite` test.
|
||||||
pub(crate) struct TestBuilder<Cache> {
|
pub(crate) struct TestBuilder<Cache> {
|
||||||
|
network: Network,
|
||||||
cache: Cache,
|
cache: Cache,
|
||||||
seed: Option<SecretVec<u8>>,
|
seed: Option<SecretVec<u8>>,
|
||||||
with_test_account: bool,
|
with_test_account: bool,
|
||||||
|
@ -90,6 +93,7 @@ impl TestBuilder<()> {
|
||||||
/// Constructs a new test.
|
/// Constructs a new test.
|
||||||
pub(crate) fn new() -> Self {
|
pub(crate) fn new() -> Self {
|
||||||
TestBuilder {
|
TestBuilder {
|
||||||
|
network: Network::TestNetwork,
|
||||||
cache: (),
|
cache: (),
|
||||||
seed: None,
|
seed: None,
|
||||||
with_test_account: false,
|
with_test_account: false,
|
||||||
|
@ -99,6 +103,7 @@ impl TestBuilder<()> {
|
||||||
/// Adds a [`BlockDb`] cache to the test.
|
/// Adds a [`BlockDb`] cache to the test.
|
||||||
pub(crate) fn with_block_cache(self) -> TestBuilder<BlockCache> {
|
pub(crate) fn with_block_cache(self) -> TestBuilder<BlockCache> {
|
||||||
TestBuilder {
|
TestBuilder {
|
||||||
|
network: self.network,
|
||||||
cache: BlockCache::new(),
|
cache: BlockCache::new(),
|
||||||
seed: self.seed,
|
seed: self.seed,
|
||||||
with_test_account: self.with_test_account,
|
with_test_account: self.with_test_account,
|
||||||
|
@ -109,6 +114,7 @@ impl TestBuilder<()> {
|
||||||
#[cfg(feature = "unstable")]
|
#[cfg(feature = "unstable")]
|
||||||
pub(crate) fn with_fs_block_cache(self) -> TestBuilder<FsBlockCache> {
|
pub(crate) fn with_fs_block_cache(self) -> TestBuilder<FsBlockCache> {
|
||||||
TestBuilder {
|
TestBuilder {
|
||||||
|
network: self.network,
|
||||||
cache: FsBlockCache::new(),
|
cache: FsBlockCache::new(),
|
||||||
seed: self.seed,
|
seed: self.seed,
|
||||||
with_test_account: self.with_test_account,
|
with_test_account: self.with_test_account,
|
||||||
|
@ -131,10 +137,8 @@ impl<Cache> TestBuilder<Cache> {
|
||||||
|
|
||||||
/// Builds the state for this test.
|
/// Builds the state for this test.
|
||||||
pub(crate) fn build(self) -> TestState<Cache> {
|
pub(crate) fn build(self) -> TestState<Cache> {
|
||||||
let params = network();
|
|
||||||
|
|
||||||
let data_file = NamedTempFile::new().unwrap();
|
let data_file = NamedTempFile::new().unwrap();
|
||||||
let mut db_data = WalletDb::for_path(data_file.path(), params).unwrap();
|
let mut db_data = WalletDb::for_path(data_file.path(), self.network).unwrap();
|
||||||
init_wallet_db(&mut db_data, self.seed).unwrap();
|
init_wallet_db(&mut db_data, self.seed).unwrap();
|
||||||
|
|
||||||
let test_account = if self.with_test_account {
|
let test_account = if self.with_test_account {
|
||||||
|
@ -145,7 +149,7 @@ impl<Cache> TestBuilder<Cache> {
|
||||||
};
|
};
|
||||||
|
|
||||||
TestState {
|
TestState {
|
||||||
params,
|
params: self.network,
|
||||||
cache: self.cache,
|
cache: self.cache,
|
||||||
latest_cached_block: None,
|
latest_cached_block: None,
|
||||||
_data_file: data_file,
|
_data_file: data_file,
|
||||||
|
@ -186,7 +190,15 @@ where
|
||||||
let (height, prev_hash, initial_sapling_tree_size) = self
|
let (height, prev_hash, initial_sapling_tree_size) = self
|
||||||
.latest_cached_block
|
.latest_cached_block
|
||||||
.map(|(prev_height, prev_hash, end_size)| (prev_height + 1, prev_hash, end_size))
|
.map(|(prev_height, prev_hash, end_size)| (prev_height + 1, prev_hash, end_size))
|
||||||
.unwrap_or_else(|| (sapling_activation_height(), BlockHash([0; 32]), 0));
|
.unwrap_or_else(|| {
|
||||||
|
(
|
||||||
|
self.params
|
||||||
|
.activation_height(NetworkUpgrade::Sapling)
|
||||||
|
.unwrap(),
|
||||||
|
BlockHash([0; 32]),
|
||||||
|
0,
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
let (res, nf) = self.generate_block_at(
|
let (res, nf) = self.generate_block_at(
|
||||||
height,
|
height,
|
||||||
|
@ -215,6 +227,7 @@ where
|
||||||
initial_sapling_tree_size: u32,
|
initial_sapling_tree_size: u32,
|
||||||
) -> (Cache::InsertResult, Nullifier) {
|
) -> (Cache::InsertResult, Nullifier) {
|
||||||
let (cb, nf) = fake_compact_block(
|
let (cb, nf) = fake_compact_block(
|
||||||
|
&self.params,
|
||||||
height,
|
height,
|
||||||
prev_hash,
|
prev_hash,
|
||||||
dfvk,
|
dfvk,
|
||||||
|
@ -246,9 +259,18 @@ where
|
||||||
let (height, prev_hash, initial_sapling_tree_size) = self
|
let (height, prev_hash, initial_sapling_tree_size) = self
|
||||||
.latest_cached_block
|
.latest_cached_block
|
||||||
.map(|(prev_height, prev_hash, end_size)| (prev_height + 1, prev_hash, end_size))
|
.map(|(prev_height, prev_hash, end_size)| (prev_height + 1, prev_hash, end_size))
|
||||||
.unwrap_or_else(|| (sapling_activation_height(), BlockHash([0; 32]), 0));
|
.unwrap_or_else(|| {
|
||||||
|
(
|
||||||
|
self.params
|
||||||
|
.activation_height(NetworkUpgrade::Sapling)
|
||||||
|
.unwrap(),
|
||||||
|
BlockHash([0; 32]),
|
||||||
|
0,
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
let cb = fake_compact_block_spending(
|
let cb = fake_compact_block_spending(
|
||||||
|
&self.params,
|
||||||
height,
|
height,
|
||||||
prev_hash,
|
prev_hash,
|
||||||
note,
|
note,
|
||||||
|
@ -308,6 +330,19 @@ impl<Cache> TestState<Cache> {
|
||||||
&mut self.db_data
|
&mut self.db_data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Exposes an immutable reference to the network in use.
|
||||||
|
pub(crate) fn network(&self) -> &Network {
|
||||||
|
&self.db_data.params
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Convenience method for obtaining the Sapling activation height for the network under test.
|
||||||
|
pub(crate) fn sapling_activation_height(&self) -> BlockHeight {
|
||||||
|
self.db_data
|
||||||
|
.params
|
||||||
|
.activation_height(NetworkUpgrade::Sapling)
|
||||||
|
.expect("Sapling activation height must be known.")
|
||||||
|
}
|
||||||
|
|
||||||
/// Exposes the test account, if enabled via [`TestBuilder::with_test_account`].
|
/// Exposes the test account, if enabled via [`TestBuilder::with_test_account`].
|
||||||
#[cfg(feature = "unstable")]
|
#[cfg(feature = "unstable")]
|
||||||
pub(crate) fn test_account(
|
pub(crate) fn test_account(
|
||||||
|
@ -525,42 +560,20 @@ impl<Cache> TestState<Cache> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "mainnet")]
|
|
||||||
pub(crate) fn network() -> Network {
|
|
||||||
Network::MainNetwork
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(feature = "mainnet"))]
|
|
||||||
pub(crate) fn network() -> Network {
|
|
||||||
Network::TestNetwork
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "mainnet")]
|
|
||||||
pub(crate) fn sapling_activation_height() -> BlockHeight {
|
|
||||||
Network::MainNetwork
|
|
||||||
.activation_height(NetworkUpgrade::Sapling)
|
|
||||||
.unwrap()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(feature = "mainnet"))]
|
|
||||||
pub(crate) fn sapling_activation_height() -> BlockHeight {
|
|
||||||
Network::TestNetwork
|
|
||||||
.activation_height(NetworkUpgrade::Sapling)
|
|
||||||
.unwrap()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub(crate) fn init_test_accounts_table_ufvk(
|
pub(crate) fn init_test_accounts_table_ufvk(
|
||||||
db_data: &mut WalletDb<rusqlite::Connection, Network>,
|
db_data: &mut WalletDb<rusqlite::Connection, Network>,
|
||||||
) -> (UnifiedFullViewingKey, Option<TransparentAddress>) {
|
) -> (UnifiedFullViewingKey, Option<TransparentAddress>) {
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
let seed = [0u8; 32];
|
let seed = [0u8; 32];
|
||||||
let account = AccountId::from(0);
|
let account = AccountId::from(0);
|
||||||
let extsk = sapling::spending_key(&seed, network().coin_type(), account);
|
let extsk = sapling::spending_key(&seed, db_data.params.coin_type(), account);
|
||||||
let dfvk = extsk.to_diversifiable_full_viewing_key();
|
let dfvk = extsk.to_diversifiable_full_viewing_key();
|
||||||
|
|
||||||
#[cfg(feature = "transparent-inputs")]
|
#[cfg(feature = "transparent-inputs")]
|
||||||
let (tkey, taddr) = {
|
let (tkey, taddr) = {
|
||||||
let tkey = legacy::keys::AccountPrivKey::from_seed(&network(), &seed, account)
|
let tkey = legacy::keys::AccountPrivKey::from_seed(&db_data.params, &seed, account)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_account_pubkey();
|
.to_account_pubkey();
|
||||||
let taddr = tkey.derive_external_ivk().unwrap().default_address().0;
|
let taddr = tkey.derive_external_ivk().unwrap().default_address().0;
|
||||||
|
@ -593,7 +606,8 @@ pub(crate) enum AddressType {
|
||||||
|
|
||||||
/// Create a fake CompactBlock at the given height, containing a single output paying
|
/// Create a fake CompactBlock at the given height, containing a single output paying
|
||||||
/// an address. Returns the CompactBlock and the nullifier for the new note.
|
/// an address. Returns the CompactBlock and the nullifier for the new note.
|
||||||
pub(crate) fn fake_compact_block(
|
pub(crate) fn fake_compact_block<P: consensus::Parameters>(
|
||||||
|
params: &P,
|
||||||
height: BlockHeight,
|
height: BlockHeight,
|
||||||
prev_hash: BlockHash,
|
prev_hash: BlockHash,
|
||||||
dfvk: &DiversifiableFullViewingKey,
|
dfvk: &DiversifiableFullViewingKey,
|
||||||
|
@ -609,7 +623,7 @@ pub(crate) fn fake_compact_block(
|
||||||
|
|
||||||
// Create a fake Note for the account
|
// Create a fake Note for the account
|
||||||
let mut rng = OsRng;
|
let mut rng = OsRng;
|
||||||
let rseed = generate_random_rseed(&network(), height, &mut rng);
|
let rseed = generate_random_rseed(params, height, &mut rng);
|
||||||
let note = Note::from_parts(to, NoteValue::from_raw(value.into()), rseed);
|
let note = Note::from_parts(to, NoteValue::from_raw(value.into()), rseed);
|
||||||
let encryptor = sapling_note_encryption::<_, Network>(
|
let encryptor = sapling_note_encryption::<_, Network>(
|
||||||
Some(dfvk.fvk().ovk),
|
Some(dfvk.fvk().ovk),
|
||||||
|
@ -655,7 +669,9 @@ pub(crate) fn fake_compact_block(
|
||||||
|
|
||||||
/// Create a fake CompactBlock at the given height, spending a single note from the
|
/// Create a fake CompactBlock at the given height, spending a single note from the
|
||||||
/// given address.
|
/// given address.
|
||||||
pub(crate) fn fake_compact_block_spending(
|
#[allow(clippy::too_many_arguments)]
|
||||||
|
pub(crate) fn fake_compact_block_spending<P: consensus::Parameters>(
|
||||||
|
params: &P,
|
||||||
height: BlockHeight,
|
height: BlockHeight,
|
||||||
prev_hash: BlockHash,
|
prev_hash: BlockHash,
|
||||||
(nf, in_value): (Nullifier, Amount),
|
(nf, in_value): (Nullifier, Amount),
|
||||||
|
@ -665,7 +681,7 @@ pub(crate) fn fake_compact_block_spending(
|
||||||
initial_sapling_tree_size: u32,
|
initial_sapling_tree_size: u32,
|
||||||
) -> CompactBlock {
|
) -> CompactBlock {
|
||||||
let mut rng = OsRng;
|
let mut rng = OsRng;
|
||||||
let rseed = generate_random_rseed(&network(), height, &mut rng);
|
let rseed = generate_random_rseed(params, height, &mut rng);
|
||||||
|
|
||||||
// Create a fake CompactBlock containing the note
|
// Create a fake CompactBlock containing the note
|
||||||
let cspend = CompactSaplingSpend { nf: nf.to_vec() };
|
let cspend = CompactSaplingSpend { nf: nf.to_vec() };
|
||||||
|
@ -700,7 +716,7 @@ pub(crate) fn fake_compact_block_spending(
|
||||||
// Create a fake Note for the change
|
// Create a fake Note for the change
|
||||||
ctx.outputs.push({
|
ctx.outputs.push({
|
||||||
let change_addr = dfvk.default_address().1;
|
let change_addr = dfvk.default_address().1;
|
||||||
let rseed = generate_random_rseed(&network(), height, &mut rng);
|
let rseed = generate_random_rseed(params, height, &mut rng);
|
||||||
let note = Note::from_parts(
|
let note = Note::from_parts(
|
||||||
change_addr,
|
change_addr,
|
||||||
NoteValue::from_raw((in_value - value).unwrap().into()),
|
NoteValue::from_raw((in_value - value).unwrap().into()),
|
||||||
|
|
|
@ -985,14 +985,14 @@ mod tests {
|
||||||
};
|
};
|
||||||
use shardtree::ShardTree;
|
use shardtree::ShardTree;
|
||||||
use zcash_client_backend::data_api::chain::CommitmentTreeRoot;
|
use zcash_client_backend::data_api::chain::CommitmentTreeRoot;
|
||||||
use zcash_primitives::consensus::BlockHeight;
|
use zcash_primitives::consensus::{BlockHeight, Network};
|
||||||
|
|
||||||
use super::SqliteShardStore;
|
use super::SqliteShardStore;
|
||||||
use crate::{testing, wallet::init::init_wallet_db, WalletDb, SAPLING_TABLES_PREFIX};
|
use crate::{wallet::init::init_wallet_db, WalletDb, SAPLING_TABLES_PREFIX};
|
||||||
|
|
||||||
fn new_tree(m: usize) -> ShardTree<SqliteShardStore<rusqlite::Connection, String, 3>, 4, 3> {
|
fn new_tree(m: usize) -> ShardTree<SqliteShardStore<rusqlite::Connection, String, 3>, 4, 3> {
|
||||||
let data_file = NamedTempFile::new().unwrap();
|
let data_file = NamedTempFile::new().unwrap();
|
||||||
let mut db_data = WalletDb::for_path(data_file.path(), testing::network()).unwrap();
|
let mut db_data = WalletDb::for_path(data_file.path(), Network::TestNetwork).unwrap();
|
||||||
data_file.keep().unwrap();
|
data_file.keep().unwrap();
|
||||||
|
|
||||||
init_wallet_db(&mut db_data, None).unwrap();
|
init_wallet_db(&mut db_data, None).unwrap();
|
||||||
|
@ -1040,7 +1040,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn put_shard_roots() {
|
fn put_shard_roots() {
|
||||||
let data_file = NamedTempFile::new().unwrap();
|
let data_file = NamedTempFile::new().unwrap();
|
||||||
let mut db_data = WalletDb::for_path(data_file.path(), testing::network()).unwrap();
|
let mut db_data = WalletDb::for_path(data_file.path(), Network::TestNetwork).unwrap();
|
||||||
data_file.keep().unwrap();
|
data_file.keep().unwrap();
|
||||||
|
|
||||||
init_wallet_db(&mut db_data, None).unwrap();
|
init_wallet_db(&mut db_data, None).unwrap();
|
||||||
|
|
|
@ -386,36 +386,27 @@ mod tests {
|
||||||
|
|
||||||
use zcash_primitives::{
|
use zcash_primitives::{
|
||||||
block::BlockHash,
|
block::BlockHash,
|
||||||
consensus::{BlockHeight, BranchId, NetworkUpgrade, Parameters},
|
consensus::{self, BlockHeight, BranchId, Network, NetworkUpgrade, Parameters},
|
||||||
transaction::{TransactionData, TxVersion},
|
transaction::{TransactionData, TxVersion},
|
||||||
zip32::sapling::ExtendedFullViewingKey,
|
zip32::sapling::ExtendedFullViewingKey,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{error::SqliteClientError, wallet::scanning::priority_code, AccountId, WalletDb};
|
||||||
error::SqliteClientError,
|
|
||||||
testing::{self, network},
|
|
||||||
wallet::scanning::priority_code,
|
|
||||||
AccountId, WalletDb,
|
|
||||||
};
|
|
||||||
|
|
||||||
use super::{init_accounts_table, init_blocks_table, init_wallet_db};
|
use super::{init_accounts_table, init_blocks_table, init_wallet_db};
|
||||||
|
|
||||||
#[cfg(feature = "transparent-inputs")]
|
#[cfg(feature = "transparent-inputs")]
|
||||||
use {
|
use {
|
||||||
crate::{
|
crate::wallet::{self, pool_code, PoolType},
|
||||||
wallet::{self, pool_code, PoolType},
|
|
||||||
WalletWrite,
|
|
||||||
},
|
|
||||||
zcash_address::test_vectors,
|
zcash_address::test_vectors,
|
||||||
zcash_primitives::{
|
zcash_client_backend::data_api::WalletWrite,
|
||||||
consensus::Network, legacy::keys as transparent, zip32::DiversifierIndex,
|
zcash_primitives::{legacy::keys as transparent, zip32::DiversifierIndex},
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn verify_schema() {
|
fn verify_schema() {
|
||||||
let data_file = NamedTempFile::new().unwrap();
|
let data_file = NamedTempFile::new().unwrap();
|
||||||
let mut db_data = WalletDb::for_path(data_file.path(), testing::network()).unwrap();
|
let mut db_data = WalletDb::for_path(data_file.path(), Network::TestNetwork).unwrap();
|
||||||
init_wallet_db(&mut db_data, None).unwrap();
|
init_wallet_db(&mut db_data, None).unwrap();
|
||||||
|
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
@ -609,7 +600,7 @@ mod tests {
|
||||||
AND (scan_queue.block_range_end - 1) >= shard.subtree_end_height
|
AND (scan_queue.block_range_end - 1) >= shard.subtree_end_height
|
||||||
)
|
)
|
||||||
WHERE scan_queue.priority > {}",
|
WHERE scan_queue.priority > {}",
|
||||||
u32::from(testing::network().activation_height(NetworkUpgrade::Sapling).unwrap()),
|
u32::from(db_data.params.activation_height(NetworkUpgrade::Sapling).unwrap()),
|
||||||
priority_code(&ScanPriority::Scanned),
|
priority_code(&ScanPriority::Scanned),
|
||||||
),
|
),
|
||||||
// v_transactions
|
// v_transactions
|
||||||
|
@ -768,7 +759,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn init_migrate_from_0_3_0() {
|
fn init_migrate_from_0_3_0() {
|
||||||
fn init_0_3_0<P>(
|
fn init_0_3_0<P: consensus::Parameters>(
|
||||||
wdb: &mut WalletDb<rusqlite::Connection, P>,
|
wdb: &mut WalletDb<rusqlite::Connection, P>,
|
||||||
extfvk: &ExtendedFullViewingKey,
|
extfvk: &ExtendedFullViewingKey,
|
||||||
account: AccountId,
|
account: AccountId,
|
||||||
|
@ -852,11 +843,11 @@ mod tests {
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let address = encode_payment_address(
|
let address = encode_payment_address(
|
||||||
testing::network().hrp_sapling_payment_address(),
|
wdb.params.hrp_sapling_payment_address(),
|
||||||
&extfvk.default_address().1,
|
&extfvk.default_address().1,
|
||||||
);
|
);
|
||||||
let extfvk = encode_extended_full_viewing_key(
|
let extfvk = encode_extended_full_viewing_key(
|
||||||
testing::network().hrp_sapling_extended_full_viewing_key(),
|
wdb.params.hrp_sapling_extended_full_viewing_key(),
|
||||||
extfvk,
|
extfvk,
|
||||||
);
|
);
|
||||||
wdb.conn.execute(
|
wdb.conn.execute(
|
||||||
|
@ -872,19 +863,21 @@ mod tests {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let data_file = NamedTempFile::new().unwrap();
|
||||||
|
let mut db_data = WalletDb::for_path(data_file.path(), Network::TestNetwork).unwrap();
|
||||||
|
|
||||||
let seed = [0xab; 32];
|
let seed = [0xab; 32];
|
||||||
let account = AccountId::from(0);
|
let account = AccountId::from(0);
|
||||||
let secret_key = sapling::spending_key(&seed, testing::network().coin_type(), account);
|
let secret_key = sapling::spending_key(&seed, db_data.params.coin_type(), account);
|
||||||
let extfvk = secret_key.to_extended_full_viewing_key();
|
let extfvk = secret_key.to_extended_full_viewing_key();
|
||||||
let data_file = NamedTempFile::new().unwrap();
|
|
||||||
let mut db_data = WalletDb::for_path(data_file.path(), testing::network()).unwrap();
|
|
||||||
init_0_3_0(&mut db_data, &extfvk, account).unwrap();
|
init_0_3_0(&mut db_data, &extfvk, account).unwrap();
|
||||||
init_wallet_db(&mut db_data, Some(Secret::new(seed.to_vec()))).unwrap();
|
init_wallet_db(&mut db_data, Some(Secret::new(seed.to_vec()))).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn init_migrate_from_autoshielding_poc() {
|
fn init_migrate_from_autoshielding_poc() {
|
||||||
fn init_autoshielding<P>(
|
fn init_autoshielding<P: consensus::Parameters>(
|
||||||
wdb: &mut WalletDb<rusqlite::Connection, P>,
|
wdb: &mut WalletDb<rusqlite::Connection, P>,
|
||||||
extfvk: &ExtendedFullViewingKey,
|
extfvk: &ExtendedFullViewingKey,
|
||||||
account: AccountId,
|
account: AccountId,
|
||||||
|
@ -984,11 +977,11 @@ mod tests {
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let address = encode_payment_address(
|
let address = encode_payment_address(
|
||||||
testing::network().hrp_sapling_payment_address(),
|
wdb.params.hrp_sapling_payment_address(),
|
||||||
&extfvk.default_address().1,
|
&extfvk.default_address().1,
|
||||||
);
|
);
|
||||||
let extfvk = encode_extended_full_viewing_key(
|
let extfvk = encode_extended_full_viewing_key(
|
||||||
testing::network().hrp_sapling_extended_full_viewing_key(),
|
wdb.params.hrp_sapling_extended_full_viewing_key(),
|
||||||
extfvk,
|
extfvk,
|
||||||
);
|
);
|
||||||
wdb.conn.execute(
|
wdb.conn.execute(
|
||||||
|
@ -1038,19 +1031,21 @@ mod tests {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let data_file = NamedTempFile::new().unwrap();
|
||||||
|
let mut db_data = WalletDb::for_path(data_file.path(), Network::TestNetwork).unwrap();
|
||||||
|
|
||||||
let seed = [0xab; 32];
|
let seed = [0xab; 32];
|
||||||
let account = AccountId::from(0);
|
let account = AccountId::from(0);
|
||||||
let secret_key = sapling::spending_key(&seed, testing::network().coin_type(), account);
|
let secret_key = sapling::spending_key(&seed, db_data.params.coin_type(), account);
|
||||||
let extfvk = secret_key.to_extended_full_viewing_key();
|
let extfvk = secret_key.to_extended_full_viewing_key();
|
||||||
let data_file = NamedTempFile::new().unwrap();
|
|
||||||
let mut db_data = WalletDb::for_path(data_file.path(), testing::network()).unwrap();
|
|
||||||
init_autoshielding(&mut db_data, &extfvk, account).unwrap();
|
init_autoshielding(&mut db_data, &extfvk, account).unwrap();
|
||||||
init_wallet_db(&mut db_data, Some(Secret::new(seed.to_vec()))).unwrap();
|
init_wallet_db(&mut db_data, Some(Secret::new(seed.to_vec()))).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn init_migrate_from_main_pre_migrations() {
|
fn init_migrate_from_main_pre_migrations() {
|
||||||
fn init_main<P>(
|
fn init_main<P: consensus::Parameters>(
|
||||||
wdb: &mut WalletDb<rusqlite::Connection, P>,
|
wdb: &mut WalletDb<rusqlite::Connection, P>,
|
||||||
ufvk: &UnifiedFullViewingKey,
|
ufvk: &UnifiedFullViewingKey,
|
||||||
account: AccountId,
|
account: AccountId,
|
||||||
|
@ -1150,9 +1145,9 @@ mod tests {
|
||||||
[],
|
[],
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let ufvk_str = ufvk.encode(&testing::network());
|
let ufvk_str = ufvk.encode(&wdb.params);
|
||||||
let address_str =
|
let address_str =
|
||||||
RecipientAddress::Unified(ufvk.default_address().0).encode(&testing::network());
|
RecipientAddress::Unified(ufvk.default_address().0).encode(&wdb.params);
|
||||||
wdb.conn.execute(
|
wdb.conn.execute(
|
||||||
"INSERT INTO accounts (account, ufvk, address, transparent_address)
|
"INSERT INTO accounts (account, ufvk, address, transparent_address)
|
||||||
VALUES (?, ?, ?, '')",
|
VALUES (?, ?, ?, '')",
|
||||||
|
@ -1168,7 +1163,7 @@ mod tests {
|
||||||
{
|
{
|
||||||
let taddr =
|
let taddr =
|
||||||
RecipientAddress::Transparent(*ufvk.default_address().0.transparent().unwrap())
|
RecipientAddress::Transparent(*ufvk.default_address().0.transparent().unwrap())
|
||||||
.encode(&testing::network());
|
.encode(&wdb.params);
|
||||||
wdb.conn.execute(
|
wdb.conn.execute(
|
||||||
"INSERT INTO blocks (height, hash, time, sapling_tree) VALUES (0, 0, 0, x'000000')",
|
"INSERT INTO blocks (height, hash, time, sapling_tree) VALUES (0, 0, 0, x'000000')",
|
||||||
[],
|
[],
|
||||||
|
@ -1186,12 +1181,13 @@ mod tests {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let data_file = NamedTempFile::new().unwrap();
|
||||||
|
let mut db_data = WalletDb::for_path(data_file.path(), Network::TestNetwork).unwrap();
|
||||||
|
|
||||||
let seed = [0xab; 32];
|
let seed = [0xab; 32];
|
||||||
let account = AccountId::from(0);
|
let account = AccountId::from(0);
|
||||||
let secret_key =
|
let secret_key = UnifiedSpendingKey::from_seed(&db_data.params, &seed, account).unwrap();
|
||||||
UnifiedSpendingKey::from_seed(&testing::network(), &seed, account).unwrap();
|
|
||||||
let data_file = NamedTempFile::new().unwrap();
|
|
||||||
let mut db_data = WalletDb::for_path(data_file.path(), testing::network()).unwrap();
|
|
||||||
init_main(
|
init_main(
|
||||||
&mut db_data,
|
&mut db_data,
|
||||||
&secret_key.to_unified_full_viewing_key(),
|
&secret_key.to_unified_full_viewing_key(),
|
||||||
|
@ -1204,7 +1200,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn init_accounts_table_only_works_once() {
|
fn init_accounts_table_only_works_once() {
|
||||||
let data_file = NamedTempFile::new().unwrap();
|
let data_file = NamedTempFile::new().unwrap();
|
||||||
let mut db_data = WalletDb::for_path(data_file.path(), testing::network()).unwrap();
|
let mut db_data = WalletDb::for_path(data_file.path(), Network::TestNetwork).unwrap();
|
||||||
init_wallet_db(&mut db_data, Some(Secret::new(vec![]))).unwrap();
|
init_wallet_db(&mut db_data, Some(Secret::new(vec![]))).unwrap();
|
||||||
|
|
||||||
// We can call the function as many times as we want with no data
|
// We can call the function as many times as we want with no data
|
||||||
|
@ -1215,13 +1211,13 @@ mod tests {
|
||||||
let account = AccountId::from(0);
|
let account = AccountId::from(0);
|
||||||
|
|
||||||
// First call with data should initialise the accounts table
|
// First call with data should initialise the accounts table
|
||||||
let extsk = sapling::spending_key(&seed, network().coin_type(), account);
|
let extsk = sapling::spending_key(&seed, db_data.params.coin_type(), account);
|
||||||
let dfvk = extsk.to_diversifiable_full_viewing_key();
|
let dfvk = extsk.to_diversifiable_full_viewing_key();
|
||||||
|
|
||||||
#[cfg(feature = "transparent-inputs")]
|
#[cfg(feature = "transparent-inputs")]
|
||||||
let ufvk = UnifiedFullViewingKey::new(
|
let ufvk = UnifiedFullViewingKey::new(
|
||||||
Some(
|
Some(
|
||||||
transparent::AccountPrivKey::from_seed(&network(), &seed, account)
|
transparent::AccountPrivKey::from_seed(&db_data.params, &seed, account)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_account_pubkey(),
|
.to_account_pubkey(),
|
||||||
),
|
),
|
||||||
|
@ -1243,8 +1239,9 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn init_accounts_table_allows_no_gaps() {
|
fn init_accounts_table_allows_no_gaps() {
|
||||||
|
let params = Network::TestNetwork;
|
||||||
let data_file = NamedTempFile::new().unwrap();
|
let data_file = NamedTempFile::new().unwrap();
|
||||||
let mut db_data = WalletDb::for_path(data_file.path(), network()).unwrap();
|
let mut db_data = WalletDb::for_path(data_file.path(), params).unwrap();
|
||||||
init_wallet_db(&mut db_data, Some(Secret::new(vec![]))).unwrap();
|
init_wallet_db(&mut db_data, Some(Secret::new(vec![]))).unwrap();
|
||||||
|
|
||||||
// allow sequential initialization
|
// allow sequential initialization
|
||||||
|
@ -1253,7 +1250,7 @@ mod tests {
|
||||||
ids.iter()
|
ids.iter()
|
||||||
.map(|a| {
|
.map(|a| {
|
||||||
let account = AccountId::from(*a);
|
let account = AccountId::from(*a);
|
||||||
UnifiedSpendingKey::from_seed(&network(), &seed, account)
|
UnifiedSpendingKey::from_seed(¶ms, &seed, account)
|
||||||
.map(|k| (account, k.to_unified_full_viewing_key()))
|
.map(|k| (account, k.to_unified_full_viewing_key()))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
})
|
})
|
||||||
|
@ -1273,7 +1270,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn init_blocks_table_only_works_once() {
|
fn init_blocks_table_only_works_once() {
|
||||||
let data_file = NamedTempFile::new().unwrap();
|
let data_file = NamedTempFile::new().unwrap();
|
||||||
let mut db_data = WalletDb::for_path(data_file.path(), testing::network()).unwrap();
|
let mut db_data = WalletDb::for_path(data_file.path(), Network::TestNetwork).unwrap();
|
||||||
init_wallet_db(&mut db_data, Some(Secret::new(vec![]))).unwrap();
|
init_wallet_db(&mut db_data, Some(Secret::new(vec![]))).unwrap();
|
||||||
|
|
||||||
// First call with data should initialise the blocks table
|
// First call with data should initialise the blocks table
|
||||||
|
@ -1300,14 +1297,14 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn init_accounts_table_stores_correct_address() {
|
fn init_accounts_table_stores_correct_address() {
|
||||||
let data_file = NamedTempFile::new().unwrap();
|
let data_file = NamedTempFile::new().unwrap();
|
||||||
let mut db_data = WalletDb::for_path(data_file.path(), testing::network()).unwrap();
|
let mut db_data = WalletDb::for_path(data_file.path(), Network::TestNetwork).unwrap();
|
||||||
init_wallet_db(&mut db_data, None).unwrap();
|
init_wallet_db(&mut db_data, None).unwrap();
|
||||||
|
|
||||||
let seed = [0u8; 32];
|
let seed = [0u8; 32];
|
||||||
|
|
||||||
// Add an account to the wallet
|
// Add an account to the wallet
|
||||||
let account_id = AccountId::from(0);
|
let account_id = AccountId::from(0);
|
||||||
let usk = UnifiedSpendingKey::from_seed(&testing::network(), &seed, account_id).unwrap();
|
let usk = UnifiedSpendingKey::from_seed(&db_data.params, &seed, account_id).unwrap();
|
||||||
let ufvk = usk.to_unified_full_viewing_key();
|
let ufvk = usk.to_unified_full_viewing_key();
|
||||||
let expected_address = ufvk.sapling().unwrap().default_address().1;
|
let expected_address = ufvk.sapling().unwrap().default_address().1;
|
||||||
let ufvks = HashMap::from([(account_id, ufvk)]);
|
let ufvks = HashMap::from([(account_id, ufvk)]);
|
||||||
|
|
|
@ -283,10 +283,9 @@ mod tests {
|
||||||
use tempfile::NamedTempFile;
|
use tempfile::NamedTempFile;
|
||||||
|
|
||||||
use zcash_client_backend::keys::UnifiedSpendingKey;
|
use zcash_client_backend::keys::UnifiedSpendingKey;
|
||||||
use zcash_primitives::zip32::AccountId;
|
use zcash_primitives::{consensus::Network, zip32::AccountId};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
testing,
|
|
||||||
wallet::init::{init_wallet_db_internal, migrations::addresses_table},
|
wallet::init::{init_wallet_db_internal, migrations::addresses_table},
|
||||||
WalletDb,
|
WalletDb,
|
||||||
};
|
};
|
||||||
|
@ -310,19 +309,19 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn transaction_views() {
|
fn transaction_views() {
|
||||||
|
let network = Network::TestNetwork;
|
||||||
let data_file = NamedTempFile::new().unwrap();
|
let data_file = NamedTempFile::new().unwrap();
|
||||||
let mut db_data = WalletDb::for_path(data_file.path(), testing::network()).unwrap();
|
let mut db_data = WalletDb::for_path(data_file.path(), network).unwrap();
|
||||||
init_wallet_db_internal(&mut db_data, None, &[addresses_table::MIGRATION_ID]).unwrap();
|
init_wallet_db_internal(&mut db_data, None, &[addresses_table::MIGRATION_ID]).unwrap();
|
||||||
let usk =
|
let usk =
|
||||||
UnifiedSpendingKey::from_seed(&testing::network(), &[0u8; 32][..], AccountId::from(0))
|
UnifiedSpendingKey::from_seed(&network, &[0u8; 32][..], AccountId::from(0)).unwrap();
|
||||||
.unwrap();
|
|
||||||
let ufvk = usk.to_unified_full_viewing_key();
|
let ufvk = usk.to_unified_full_viewing_key();
|
||||||
|
|
||||||
db_data
|
db_data
|
||||||
.conn
|
.conn
|
||||||
.execute(
|
.execute(
|
||||||
"INSERT INTO accounts (account, ufvk) VALUES (0, ?)",
|
"INSERT INTO accounts (account, ufvk) VALUES (0, ?)",
|
||||||
params![ufvk.encode(&testing::network())],
|
params![ufvk.encode(&network)],
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -402,8 +401,9 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(feature = "transparent-inputs")]
|
#[cfg(feature = "transparent-inputs")]
|
||||||
fn migrate_from_wm2() {
|
fn migrate_from_wm2() {
|
||||||
|
let network = Network::TestNetwork;
|
||||||
let data_file = NamedTempFile::new().unwrap();
|
let data_file = NamedTempFile::new().unwrap();
|
||||||
let mut db_data = WalletDb::for_path(data_file.path(), testing::network()).unwrap();
|
let mut db_data = WalletDb::for_path(data_file.path(), network).unwrap();
|
||||||
init_wallet_db_internal(
|
init_wallet_db_internal(
|
||||||
&mut db_data,
|
&mut db_data,
|
||||||
None,
|
None,
|
||||||
|
@ -440,8 +440,7 @@ mod tests {
|
||||||
tx.write(&mut tx_bytes).unwrap();
|
tx.write(&mut tx_bytes).unwrap();
|
||||||
|
|
||||||
let usk =
|
let usk =
|
||||||
UnifiedSpendingKey::from_seed(&testing::network(), &[0u8; 32][..], AccountId::from(0))
|
UnifiedSpendingKey::from_seed(&network, &[0u8; 32][..], AccountId::from(0)).unwrap();
|
||||||
.unwrap();
|
|
||||||
let ufvk = usk.to_unified_full_viewing_key();
|
let ufvk = usk.to_unified_full_viewing_key();
|
||||||
let (ua, _) = ufvk.default_address();
|
let (ua, _) = ufvk.default_address();
|
||||||
let taddr = ufvk
|
let taddr = ufvk
|
||||||
|
@ -451,11 +450,11 @@ mod tests {
|
||||||
.ok()
|
.ok()
|
||||||
.map(|k| k.derive_address(0).unwrap())
|
.map(|k| k.derive_address(0).unwrap())
|
||||||
})
|
})
|
||||||
.map(|a| a.encode(&testing::network()));
|
.map(|a| a.encode(&network));
|
||||||
|
|
||||||
db_data.conn.execute(
|
db_data.conn.execute(
|
||||||
"INSERT INTO accounts (account, ufvk, address, transparent_address) VALUES (0, ?, ?, ?)",
|
"INSERT INTO accounts (account, ufvk, address, transparent_address) VALUES (0, ?, ?, ?)",
|
||||||
params![ufvk.encode(&testing::network()), ua.encode(&testing::network()), &taddr]
|
params![ufvk.encode(&network), ua.encode(&network), &taddr]
|
||||||
).unwrap();
|
).unwrap();
|
||||||
db_data
|
db_data
|
||||||
.conn
|
.conn
|
||||||
|
|
|
@ -233,10 +233,9 @@ mod tests {
|
||||||
use tempfile::NamedTempFile;
|
use tempfile::NamedTempFile;
|
||||||
|
|
||||||
use zcash_client_backend::keys::UnifiedSpendingKey;
|
use zcash_client_backend::keys::UnifiedSpendingKey;
|
||||||
use zcash_primitives::zip32::AccountId;
|
use zcash_primitives::{consensus::Network, zip32::AccountId};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
testing,
|
|
||||||
wallet::init::{init_wallet_db_internal, migrations::v_transactions_net},
|
wallet::init::{init_wallet_db_internal, migrations::v_transactions_net},
|
||||||
WalletDb,
|
WalletDb,
|
||||||
};
|
};
|
||||||
|
@ -244,19 +243,19 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn received_notes_nullable_migration() {
|
fn received_notes_nullable_migration() {
|
||||||
let data_file = NamedTempFile::new().unwrap();
|
let data_file = NamedTempFile::new().unwrap();
|
||||||
let mut db_data = WalletDb::for_path(data_file.path(), testing::network()).unwrap();
|
let mut db_data = WalletDb::for_path(data_file.path(), Network::TestNetwork).unwrap();
|
||||||
init_wallet_db_internal(&mut db_data, None, &[v_transactions_net::MIGRATION_ID]).unwrap();
|
init_wallet_db_internal(&mut db_data, None, &[v_transactions_net::MIGRATION_ID]).unwrap();
|
||||||
|
|
||||||
// Create an account in the wallet
|
// Create an account in the wallet
|
||||||
let usk0 =
|
let usk0 =
|
||||||
UnifiedSpendingKey::from_seed(&testing::network(), &[0u8; 32][..], AccountId::from(0))
|
UnifiedSpendingKey::from_seed(&db_data.params, &[0u8; 32][..], AccountId::from(0))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let ufvk0 = usk0.to_unified_full_viewing_key();
|
let ufvk0 = usk0.to_unified_full_viewing_key();
|
||||||
db_data
|
db_data
|
||||||
.conn
|
.conn
|
||||||
.execute(
|
.execute(
|
||||||
"INSERT INTO accounts (account, ufvk) VALUES (0, ?)",
|
"INSERT INTO accounts (account, ufvk) VALUES (0, ?)",
|
||||||
params![ufvk0.encode(&testing::network())],
|
params![ufvk0.encode(&db_data.params)],
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
@ -212,10 +212,9 @@ mod tests {
|
||||||
use tempfile::NamedTempFile;
|
use tempfile::NamedTempFile;
|
||||||
|
|
||||||
use zcash_client_backend::keys::UnifiedSpendingKey;
|
use zcash_client_backend::keys::UnifiedSpendingKey;
|
||||||
use zcash_primitives::zip32::AccountId;
|
use zcash_primitives::{consensus::Network, zip32::AccountId};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
testing,
|
|
||||||
wallet::init::{init_wallet_db_internal, migrations::add_transaction_views},
|
wallet::init::{init_wallet_db_internal, migrations::add_transaction_views},
|
||||||
WalletDb,
|
WalletDb,
|
||||||
};
|
};
|
||||||
|
@ -223,32 +222,32 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn v_transactions_net() {
|
fn v_transactions_net() {
|
||||||
let data_file = NamedTempFile::new().unwrap();
|
let data_file = NamedTempFile::new().unwrap();
|
||||||
let mut db_data = WalletDb::for_path(data_file.path(), testing::network()).unwrap();
|
let mut db_data = WalletDb::for_path(data_file.path(), Network::TestNetwork).unwrap();
|
||||||
init_wallet_db_internal(&mut db_data, None, &[add_transaction_views::MIGRATION_ID])
|
init_wallet_db_internal(&mut db_data, None, &[add_transaction_views::MIGRATION_ID])
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// Create two accounts in the wallet.
|
// Create two accounts in the wallet.
|
||||||
let usk0 =
|
let usk0 =
|
||||||
UnifiedSpendingKey::from_seed(&testing::network(), &[0u8; 32][..], AccountId::from(0))
|
UnifiedSpendingKey::from_seed(&db_data.params, &[0u8; 32][..], AccountId::from(0))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let ufvk0 = usk0.to_unified_full_viewing_key();
|
let ufvk0 = usk0.to_unified_full_viewing_key();
|
||||||
db_data
|
db_data
|
||||||
.conn
|
.conn
|
||||||
.execute(
|
.execute(
|
||||||
"INSERT INTO accounts (account, ufvk) VALUES (0, ?)",
|
"INSERT INTO accounts (account, ufvk) VALUES (0, ?)",
|
||||||
params![ufvk0.encode(&testing::network())],
|
params![ufvk0.encode(&db_data.params)],
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let usk1 =
|
let usk1 =
|
||||||
UnifiedSpendingKey::from_seed(&testing::network(), &[1u8; 32][..], AccountId::from(1))
|
UnifiedSpendingKey::from_seed(&db_data.params, &[1u8; 32][..], AccountId::from(1))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let ufvk1 = usk1.to_unified_full_viewing_key();
|
let ufvk1 = usk1.to_unified_full_viewing_key();
|
||||||
db_data
|
db_data
|
||||||
.conn
|
.conn
|
||||||
.execute(
|
.execute(
|
||||||
"INSERT INTO accounts (account, ufvk) VALUES (1, ?)",
|
"INSERT INTO accounts (account, ufvk) VALUES (1, ?)",
|
||||||
params![ufvk1.encode(&testing::network())],
|
params![ufvk1.encode(&db_data.params)],
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
@ -439,7 +439,7 @@ pub(crate) mod tests {
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
error::SqliteClientError,
|
error::SqliteClientError,
|
||||||
testing::{self, network, AddressType, BlockCache, TestBuilder, TestState},
|
testing::{AddressType, BlockCache, TestBuilder, TestState},
|
||||||
wallet::{commitment_tree, get_balance, get_balance_at},
|
wallet::{commitment_tree, get_balance, get_balance_at},
|
||||||
AccountId, NoteId, ReceivedNoteId,
|
AccountId, NoteId, ReceivedNoteId,
|
||||||
};
|
};
|
||||||
|
@ -532,7 +532,7 @@ pub(crate) mod tests {
|
||||||
let ufvks = [(account, usk.to_unified_full_viewing_key())]
|
let ufvks = [(account, usk.to_unified_full_viewing_key())]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.collect();
|
.collect();
|
||||||
let decrypted_outputs = decrypt_transaction(&testing::network(), h + 1, &tx, &ufvks);
|
let decrypted_outputs = decrypt_transaction(st.network(), h + 1, &tx, &ufvks);
|
||||||
assert_eq!(decrypted_outputs.len(), 2);
|
assert_eq!(decrypted_outputs.len(), 2);
|
||||||
|
|
||||||
let mut found_tx_change_memo = false;
|
let mut found_tx_change_memo = false;
|
||||||
|
@ -619,7 +619,7 @@ pub(crate) mod tests {
|
||||||
|
|
||||||
// Create a USK that doesn't exist in the wallet
|
// Create a USK that doesn't exist in the wallet
|
||||||
let acct1 = AccountId::from(1);
|
let acct1 = AccountId::from(1);
|
||||||
let usk1 = UnifiedSpendingKey::from_seed(&network(), &[1u8; 32], acct1).unwrap();
|
let usk1 = UnifiedSpendingKey::from_seed(st.network(), &[1u8; 32], acct1).unwrap();
|
||||||
|
|
||||||
// Attempting to spend with a USK that is not in the wallet results in an error
|
// Attempting to spend with a USK that is not in the wallet results in an error
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
|
@ -900,7 +900,7 @@ pub(crate) mod tests {
|
||||||
let to = addr2.into();
|
let to = addr2.into();
|
||||||
|
|
||||||
#[allow(clippy::type_complexity)]
|
#[allow(clippy::type_complexity)]
|
||||||
let send_and_recover_with_policy = |test: &mut TestState<BlockCache>,
|
let send_and_recover_with_policy = |st: &mut TestState<BlockCache>,
|
||||||
ovk_policy|
|
ovk_policy|
|
||||||
-> Result<
|
-> Result<
|
||||||
Option<(Note, PaymentAddress, MemoBytes)>,
|
Option<(Note, PaymentAddress, MemoBytes)>,
|
||||||
|
@ -912,7 +912,7 @@ pub(crate) mod tests {
|
||||||
ReceivedNoteId,
|
ReceivedNoteId,
|
||||||
>,
|
>,
|
||||||
> {
|
> {
|
||||||
let txid = test.create_spend_to_address(
|
let txid = st.create_spend_to_address(
|
||||||
&usk,
|
&usk,
|
||||||
&to,
|
&to,
|
||||||
Amount::from_u64(15000).unwrap(),
|
Amount::from_u64(15000).unwrap(),
|
||||||
|
@ -922,7 +922,7 @@ pub(crate) mod tests {
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Fetch the transaction from the database
|
// Fetch the transaction from the database
|
||||||
let raw_tx: Vec<_> = test
|
let raw_tx: Vec<_> = st
|
||||||
.wallet()
|
.wallet()
|
||||||
.conn
|
.conn
|
||||||
.query_row(
|
.query_row(
|
||||||
|
@ -937,7 +937,7 @@ pub(crate) mod tests {
|
||||||
for output in tx.sapling_bundle().unwrap().shielded_outputs() {
|
for output in tx.sapling_bundle().unwrap().shielded_outputs() {
|
||||||
// Find the output that decrypts with the external OVK
|
// Find the output that decrypts with the external OVK
|
||||||
let result = try_sapling_output_recovery(
|
let result = try_sapling_output_recovery(
|
||||||
&network(),
|
st.network(),
|
||||||
h1,
|
h1,
|
||||||
&dfvk.to_ovk(Scope::External),
|
&dfvk.to_ovk(Scope::External),
|
||||||
output,
|
output,
|
||||||
|
|
|
@ -752,7 +752,7 @@ mod tests {
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
testing::{sapling_activation_height, AddressType, TestBuilder},
|
testing::{AddressType, TestBuilder},
|
||||||
wallet::{init::init_blocks_table, scanning::suggest_scan_ranges},
|
wallet::{init::init_blocks_table, scanning::suggest_scan_ranges},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1090,6 +1090,7 @@ mod tests {
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let dfvk = st.test_account_sapling().unwrap();
|
let dfvk = st.test_account_sapling().unwrap();
|
||||||
|
let sapling_activation_height = st.sapling_activation_height();
|
||||||
|
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
// In the following, we don't care what the root hashes are, they just need to be
|
// In the following, we don't care what the root hashes are, they just need to be
|
||||||
|
@ -1098,15 +1099,15 @@ mod tests {
|
||||||
0,
|
0,
|
||||||
&[
|
&[
|
||||||
CommitmentTreeRoot::from_parts(
|
CommitmentTreeRoot::from_parts(
|
||||||
sapling_activation_height() + 100,
|
sapling_activation_height + 100,
|
||||||
Node::empty_root(Level::from(0))
|
Node::empty_root(Level::from(0))
|
||||||
),
|
),
|
||||||
CommitmentTreeRoot::from_parts(
|
CommitmentTreeRoot::from_parts(
|
||||||
sapling_activation_height() + 200,
|
sapling_activation_height + 200,
|
||||||
Node::empty_root(Level::from(1))
|
Node::empty_root(Level::from(1))
|
||||||
),
|
),
|
||||||
CommitmentTreeRoot::from_parts(
|
CommitmentTreeRoot::from_parts(
|
||||||
sapling_activation_height() + 300,
|
sapling_activation_height + 300,
|
||||||
Node::empty_root(Level::from(2))
|
Node::empty_root(Level::from(2))
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
@ -1118,7 +1119,7 @@ mod tests {
|
||||||
// of 10 blocks. After `scan_cached_blocks`, the scan queue should have a requested scan
|
// of 10 blocks. After `scan_cached_blocks`, the scan queue should have a requested scan
|
||||||
// range of 300..310 with `FoundNote` priority, 310..320 with `Scanned` priority.
|
// range of 300..310 with `FoundNote` priority, 310..320 with `Scanned` priority.
|
||||||
let initial_sapling_tree_size = (0x1 << 16) * 3 + 5;
|
let initial_sapling_tree_size = (0x1 << 16) * 3 + 5;
|
||||||
let initial_height = sapling_activation_height() + 310;
|
let initial_height = sapling_activation_height + 310;
|
||||||
|
|
||||||
let value = Amount::from_u64(50000).unwrap();
|
let value = Amount::from_u64(50000).unwrap();
|
||||||
st.generate_block_at(
|
st.generate_block_at(
|
||||||
|
@ -1141,7 +1142,7 @@ mod tests {
|
||||||
st.scan_cached_blocks(initial_height, 10);
|
st.scan_cached_blocks(initial_height, 10);
|
||||||
|
|
||||||
// Verify the that adjacent range needed to make the note spendable has been prioritized.
|
// Verify the that adjacent range needed to make the note spendable has been prioritized.
|
||||||
let sap_active = u32::from(sapling_activation_height());
|
let sap_active = u32::from(sapling_activation_height);
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
st.wallet().suggest_scan_ranges(),
|
st.wallet().suggest_scan_ranges(),
|
||||||
Ok(scan_ranges) if scan_ranges == vec![
|
Ok(scan_ranges) if scan_ranges == vec![
|
||||||
|
@ -1162,7 +1163,7 @@ mod tests {
|
||||||
// future.
|
// future.
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
st.wallet_mut()
|
st.wallet_mut()
|
||||||
.update_chain_tip(sapling_activation_height() + 340),
|
.update_chain_tip(sapling_activation_height + 340),
|
||||||
Ok(())
|
Ok(())
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1179,7 +1180,7 @@ mod tests {
|
||||||
// Now simulate a jump ahead more than 100 blocks.
|
// Now simulate a jump ahead more than 100 blocks.
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
st.wallet_mut()
|
st.wallet_mut()
|
||||||
.update_chain_tip(sapling_activation_height() + 450),
|
.update_chain_tip(sapling_activation_height + 450),
|
||||||
Ok(())
|
Ok(())
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue