Skip to content

Commit

Permalink
clean up test file and merge the memorydb and sqlite test
Browse files Browse the repository at this point in the history
  • Loading branch information
ec2 committed Sep 13, 2024
1 parent b5963a4 commit 1e90326
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 59 deletions.
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ test-native:
cargo test -r -- --nocapture

test-sqlite:
cargo test -r --features="sqlite-db" test_get_and_scan_range_native_sqlite -- --nocapture
cargo test -r --features="sqlite-db" -- --nocapture

check:
cargo check
76 changes: 18 additions & 58 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ async fn test_get_and_scan_range() {
#[cfg(feature = "native")]
#[tokio::test]
async fn test_get_and_scan_range_native() {
use webz_core::PRUNING_DEPTH;
use zcash_client_memory::MemoryWalletDb;
use zcash_primitives::consensus;
let db_cache = tempfile::tempdir().unwrap();
let _db_data = tempfile::NamedTempFile::new_in(db_cache.path()).unwrap();

initialize();
let url = "https://testnet.zec.rocks:443";
Expand All @@ -62,65 +62,25 @@ async fn test_get_and_scan_range_native() {
.domain_name("testnet.zec.rocks")
.with_webpki_roots();
let channel = c.tls_config(tls).unwrap();
let wallet_db = MemoryWalletDb::new(consensus::Network::TestNetwork, PRUNING_DEPTH);
let mut w = Wallet::new(
wallet_db,
channel.connect().await.unwrap(),
Network::TestNetwork,
NonZeroU32::try_from(1).unwrap(),
)
.unwrap();

let id = w.create_account(SEED, HD_INDEX, BIRTHDAY).await.unwrap();
tracing::info!("Created account with id: {}", id);

tracing::info!("Syncing wallet");
w.sync(|scanned_to, tip| {
println!("Scanned: {}/{}", scanned_to, tip);
})
.await
.unwrap();

tracing::info!("Syncing complete :)");

let summary = w.get_wallet_summary().unwrap();
tracing::info!("Wallet summary: {:?}", summary);

tracing::info!("Proposing a transaction");
let addr = ZcashAddress::try_from_encoded("utest1z00xn09t4eyeqw9zmjss75sf460423dymgyfjn8rtlj26cffy0yad3eea82xekk24s00wnm38cvyrm2c6x7fxlc0ns4a5j7utgl6lchvglfvl9g9p56fqwzvzvj9d3z6r6ft88j654d7dj0ep6myq5duz9s8x78fdzmtx04d2qn8ydkxr4lfdhlkx9ktrw98gd97dateegrr68vl8xu");

w.transfer(SEED, 0, addr.unwrap(), 1000).await.unwrap();
tracing::info!("Transaction proposed");

let summary = w.get_wallet_summary().unwrap();
tracing::info!("Wallet summary: {:?}", summary);
}

#[cfg(all(feature = "native", feature = "sqlite-db"))]
#[tokio::test]
async fn test_get_and_scan_range_native_sqlite() {
use tempfile::{tempdir, NamedTempFile};
use zcash_client_sqlite::{
chain::init::init_blockmeta_db, wallet::init::init_wallet_db, FsBlockDb, WalletDb,
#[cfg(feature = "sqlite-db")]
let wallet_db = {
use zcash_client_sqlite::{
chain::init::init_blockmeta_db, wallet::init::init_wallet_db, FsBlockDb, WalletDb,
};

let mut db_cache = FsBlockDb::for_path(&db_cache).unwrap();
let mut wallet_db = WalletDb::for_path(&_db_data, consensus::Network::TestNetwork).unwrap();
init_blockmeta_db(&mut db_cache).unwrap();
init_wallet_db(&mut wallet_db, None).unwrap();
wallet_db
};
use zcash_primitives::consensus;

initialize();
let url = "https://testnet.zec.rocks:443";
let c = tonic::transport::Channel::from_shared(url).unwrap();

let tls = tonic::transport::ClientTlsConfig::new()
.domain_name("testnet.zec.rocks")
.with_webpki_roots();
let channel = c.tls_config(tls).unwrap();

let db_cache = tempdir().unwrap();
let db_data = NamedTempFile::new_in(db_cache.path()).unwrap();

let mut db_cache = FsBlockDb::for_path(&db_cache).unwrap();
let mut wallet_db = WalletDb::for_path(&db_data, consensus::Network::TestNetwork).unwrap();
init_blockmeta_db(&mut db_cache).unwrap();
init_wallet_db(&mut wallet_db, None).unwrap();
#[cfg(not(feature = "sqlite-db"))]
let wallet_db = zcash_client_memory::MemoryWalletDb::new(
consensus::Network::TestNetwork,
webz_core::PRUNING_DEPTH,
);

let mut w = Wallet::new(
wallet_db,
Expand Down

0 comments on commit 1e90326

Please sign in to comment.