Skip to content

Commit 1e90326

Browse files
committed
clean up test file and merge the memorydb and sqlite test
1 parent b5963a4 commit 1e90326

File tree

2 files changed

+19
-59
lines changed

2 files changed

+19
-59
lines changed

justfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ test-native:
1111
cargo test -r -- --nocapture
1212

1313
test-sqlite:
14-
cargo test -r --features="sqlite-db" test_get_and_scan_range_native_sqlite -- --nocapture
14+
cargo test -r --features="sqlite-db" -- --nocapture
1515

1616
check:
1717
cargo check

tests/tests.rs

Lines changed: 18 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ async fn test_get_and_scan_range() {
5050
#[cfg(feature = "native")]
5151
#[tokio::test]
5252
async fn test_get_and_scan_range_native() {
53-
use webz_core::PRUNING_DEPTH;
54-
use zcash_client_memory::MemoryWalletDb;
5553
use zcash_primitives::consensus;
54+
let db_cache = tempfile::tempdir().unwrap();
55+
let _db_data = tempfile::NamedTempFile::new_in(db_cache.path()).unwrap();
5656

5757
initialize();
5858
let url = "https://testnet.zec.rocks:443";
@@ -62,65 +62,25 @@ async fn test_get_and_scan_range_native() {
6262
.domain_name("testnet.zec.rocks")
6363
.with_webpki_roots();
6464
let channel = c.tls_config(tls).unwrap();
65-
let wallet_db = MemoryWalletDb::new(consensus::Network::TestNetwork, PRUNING_DEPTH);
66-
let mut w = Wallet::new(
67-
wallet_db,
68-
channel.connect().await.unwrap(),
69-
Network::TestNetwork,
70-
NonZeroU32::try_from(1).unwrap(),
71-
)
72-
.unwrap();
73-
74-
let id = w.create_account(SEED, HD_INDEX, BIRTHDAY).await.unwrap();
75-
tracing::info!("Created account with id: {}", id);
76-
77-
tracing::info!("Syncing wallet");
78-
w.sync(|scanned_to, tip| {
79-
println!("Scanned: {}/{}", scanned_to, tip);
80-
})
81-
.await
82-
.unwrap();
83-
84-
tracing::info!("Syncing complete :)");
85-
86-
let summary = w.get_wallet_summary().unwrap();
87-
tracing::info!("Wallet summary: {:?}", summary);
8865

89-
tracing::info!("Proposing a transaction");
90-
let addr = ZcashAddress::try_from_encoded("utest1z00xn09t4eyeqw9zmjss75sf460423dymgyfjn8rtlj26cffy0yad3eea82xekk24s00wnm38cvyrm2c6x7fxlc0ns4a5j7utgl6lchvglfvl9g9p56fqwzvzvj9d3z6r6ft88j654d7dj0ep6myq5duz9s8x78fdzmtx04d2qn8ydkxr4lfdhlkx9ktrw98gd97dateegrr68vl8xu");
91-
92-
w.transfer(SEED, 0, addr.unwrap(), 1000).await.unwrap();
93-
tracing::info!("Transaction proposed");
94-
95-
let summary = w.get_wallet_summary().unwrap();
96-
tracing::info!("Wallet summary: {:?}", summary);
97-
}
98-
99-
#[cfg(all(feature = "native", feature = "sqlite-db"))]
100-
#[tokio::test]
101-
async fn test_get_and_scan_range_native_sqlite() {
102-
use tempfile::{tempdir, NamedTempFile};
103-
use zcash_client_sqlite::{
104-
chain::init::init_blockmeta_db, wallet::init::init_wallet_db, FsBlockDb, WalletDb,
66+
#[cfg(feature = "sqlite-db")]
67+
let wallet_db = {
68+
use zcash_client_sqlite::{
69+
chain::init::init_blockmeta_db, wallet::init::init_wallet_db, FsBlockDb, WalletDb,
70+
};
71+
72+
let mut db_cache = FsBlockDb::for_path(&db_cache).unwrap();
73+
let mut wallet_db = WalletDb::for_path(&_db_data, consensus::Network::TestNetwork).unwrap();
74+
init_blockmeta_db(&mut db_cache).unwrap();
75+
init_wallet_db(&mut wallet_db, None).unwrap();
76+
wallet_db
10577
};
106-
use zcash_primitives::consensus;
107-
108-
initialize();
109-
let url = "https://testnet.zec.rocks:443";
110-
let c = tonic::transport::Channel::from_shared(url).unwrap();
111-
112-
let tls = tonic::transport::ClientTlsConfig::new()
113-
.domain_name("testnet.zec.rocks")
114-
.with_webpki_roots();
115-
let channel = c.tls_config(tls).unwrap();
116-
117-
let db_cache = tempdir().unwrap();
118-
let db_data = NamedTempFile::new_in(db_cache.path()).unwrap();
11978

120-
let mut db_cache = FsBlockDb::for_path(&db_cache).unwrap();
121-
let mut wallet_db = WalletDb::for_path(&db_data, consensus::Network::TestNetwork).unwrap();
122-
init_blockmeta_db(&mut db_cache).unwrap();
123-
init_wallet_db(&mut wallet_db, None).unwrap();
79+
#[cfg(not(feature = "sqlite-db"))]
80+
let wallet_db = zcash_client_memory::MemoryWalletDb::new(
81+
consensus::Network::TestNetwork,
82+
webz_core::PRUNING_DEPTH,
83+
);
12484

12585
let mut w = Wallet::new(
12686
wallet_db,

0 commit comments

Comments
 (0)