Skip to content

Commit

Permalink
added more tests, get_tree_state fails on sync_full_batch
Browse files Browse the repository at this point in the history
  • Loading branch information
idky137 committed Jun 14, 2024
1 parent 9498f72 commit f2d5234
Show file tree
Hide file tree
Showing 4 changed files with 367 additions and 127 deletions.
327 changes: 301 additions & 26 deletions integration-tests/tests/integrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use zingoproxy_testutils::{drop_test_manager, TestManager};

use zingo_netutils::GrpcConnector;

mod wallet {
mod wallet_basic {
use super::*;

#[tokio::test]
Expand Down Expand Up @@ -43,13 +43,45 @@ mod wallet {
}

#[tokio::test]
async fn send_and_sync_shielded() {
async fn send_to_orchard() {
let online = Arc::new(AtomicBool::new(true));
let (test_manager, regtest_handler, _proxy_handler) =
TestManager::launch(online.clone()).await;
let zingo_client = test_manager.build_lightclient().await;

test_manager.regtest_manager.generate_n_blocks(2).unwrap();
test_manager.regtest_manager.generate_n_blocks(1).unwrap();
zingo_client.do_sync(false).await.unwrap();
zingo_client
.do_send(vec![(
&zingolib::get_base_address!(zingo_client, "unified"),
250_000,
None,
)])
.await
.unwrap();
test_manager.regtest_manager.generate_n_blocks(1).unwrap();
zingo_client.do_sync(false).await.unwrap();

let balance = zingo_client.do_balance().await;
println!("@zingoproxytest: zingo_client balance: \n{:#?}.", balance);
assert_eq!(balance.orchard_balance.unwrap(), 1_875_000_000);

drop_test_manager(
Some(test_manager.temp_conf_dir.path().to_path_buf()),
regtest_handler,
online,
)
.await;
}

#[tokio::test]
async fn send_to_sapling() {
let online = Arc::new(AtomicBool::new(true));
let (test_manager, regtest_handler, _proxy_handler) =
TestManager::launch(online.clone()).await;
let zingo_client = test_manager.build_lightclient().await;

test_manager.regtest_manager.generate_n_blocks(1).unwrap();
zingo_client.do_sync(false).await.unwrap();
zingo_client
.do_send(vec![(
Expand All @@ -59,26 +91,94 @@ mod wallet {
)])
.await
.unwrap();
// zingo_client
// .do_send(vec![(
// &zingolib::get_base_address!(zingo_client, "sapling"),
// 250_000,
// None,
// )])
// .await
// .unwrap();
test_manager.regtest_manager.generate_n_blocks(1).unwrap();
zingo_client.do_sync(false).await.unwrap();

tokio::time::sleep(tokio::time::Duration::from_secs(10)).await;
// test_manager.regtest_manager.generate_n_blocks(1).unwrap();
// zingo_client.do_sync(false).await.unwrap();
// tokio::time::sleep(tokio::time::Duration::from_secs(10)).await;
let balance = zingo_client.do_balance().await;
println!("@zingoproxytest: zingo_client balance: \n{:#?}.", balance);
assert_eq!(balance.sapling_balance.unwrap(), 250_000);

drop_test_manager(
Some(test_manager.temp_conf_dir.path().to_path_buf()),
regtest_handler,
online,
)
.await;
}

#[tokio::test]
async fn send_to_transparent() {
let online = Arc::new(AtomicBool::new(true));
let (test_manager, regtest_handler, _proxy_handler) =
TestManager::launch(online.clone()).await;
let zingo_client = test_manager.build_lightclient().await;

test_manager.regtest_manager.generate_n_blocks(1).unwrap();
zingo_client.do_sync(false).await.unwrap();
zingo_client
.do_send(vec![(
&zingolib::get_base_address!(zingo_client, "transparent"),
250_000,
None,
)])
.await
.unwrap();
test_manager.regtest_manager.generate_n_blocks(1).unwrap();
zingo_client.do_sync(false).await.unwrap();

let balance = zingo_client.do_balance().await;
println!("@zingoproxytest: zingo_client balance: \n{:#?}.", balance);
assert_eq!(balance.transparent_balance.unwrap(), 250_000);

drop_test_manager(
Some(test_manager.temp_conf_dir.path().to_path_buf()),
regtest_handler,
online,
)
.await;
}

#[tokio::test]
async fn send_to_multiple() {
let online = Arc::new(AtomicBool::new(true));
let (test_manager, regtest_handler, _proxy_handler) =
TestManager::launch(online.clone()).await;
let zingo_client = test_manager.build_lightclient().await;

test_manager.regtest_manager.generate_n_blocks(2).unwrap();
zingo_client.do_sync(false).await.unwrap();
zingo_client
.do_send(vec![(
&zingolib::get_base_address!(zingo_client, "unified"),
250_000,
None,
)])
.await
.unwrap();
zingo_client
.do_send(vec![(
&zingolib::get_base_address!(zingo_client, "sapling"),
250_000,
None,
)])
.await
.unwrap();
zingo_client
.do_send(vec![(
&zingolib::get_base_address!(zingo_client, "transparent"),
250_000,
None,
)])
.await
.unwrap();
test_manager.regtest_manager.generate_n_blocks(1).unwrap();
zingo_client.do_sync(false).await.unwrap();

let balance = zingo_client.do_balance().await;
println!("@zingoproxytest: zingo_client balance: \n{:#?}.", balance);
assert_eq!(balance.orchard_balance.unwrap(), 2_499_500_000);
assert_eq!(balance.sapling_balance.unwrap(), 250_000);
assert_eq!(balance.transparent_balance.unwrap(), 250_000);

drop_test_manager(
Some(test_manager.temp_conf_dir.path().to_path_buf()),
Expand All @@ -89,13 +189,63 @@ mod wallet {
}

#[tokio::test]
async fn send_and_sync_transparent() {
async fn shield_from_sapling() {
let online = Arc::new(AtomicBool::new(true));
let (test_manager, regtest_handler, _proxy_handler) =
TestManager::launch(online.clone()).await;
let zingo_client = test_manager.build_lightclient().await;

test_manager.regtest_manager.generate_n_blocks(2).unwrap();
test_manager.regtest_manager.generate_n_blocks(1).unwrap();
zingo_client.do_sync(false).await.unwrap();
zingo_client
.do_send(vec![(
&zingolib::get_base_address!(zingo_client, "sapling"),
250_000,
None,
)])
.await
.unwrap();
test_manager.regtest_manager.generate_n_blocks(1).unwrap();
zingo_client.do_sync(false).await.unwrap();

let balance = zingo_client.do_balance().await;
println!("@zingoproxytest: zingo_client balance: \n{:#?}.", balance);
assert_eq!(balance.sapling_balance.unwrap(), 250_000);

zingo_client
.do_shield(
&[
zingolib::wallet::Pool::Sapling,
// zingolib::wallet::Pool::Transparent,
],
None,
)
.await
.unwrap();
test_manager.regtest_manager.generate_n_blocks(1).unwrap();
zingo_client.do_sync(false).await.unwrap();

let balance = zingo_client.do_balance().await;
println!("@zingoproxytest: zingo_client balance: \n{:#?}.", balance);
assert_eq!(balance.sapling_balance.unwrap(), 0);
assert_eq!(balance.orchard_balance.unwrap(), 2_500_000_000);

drop_test_manager(
Some(test_manager.temp_conf_dir.path().to_path_buf()),
regtest_handler,
online,
)
.await;
}

#[tokio::test]
async fn shield_from_transparent() {
let online = Arc::new(AtomicBool::new(true));
let (test_manager, regtest_handler, _proxy_handler) =
TestManager::launch(online.clone()).await;
let zingo_client = test_manager.build_lightclient().await;

test_manager.regtest_manager.generate_n_blocks(1).unwrap();
zingo_client.do_sync(false).await.unwrap();
zingo_client
.do_send(vec![(
Expand All @@ -105,20 +255,145 @@ mod wallet {
)])
.await
.unwrap();
// zingo_client
// .do_send(vec![(
// &zingolib::get_base_address!(zingo_client, "transparent"),
// 250_000,
// None,
// )])
// .await
// .unwrap();
test_manager.regtest_manager.generate_n_blocks(1).unwrap();
zingo_client.do_sync(false).await.unwrap();

let balance = zingo_client.do_balance().await;
println!("@zingoproxytest: zingo_client balance: \n{:#?}.", balance);
assert_eq!(balance.transparent_balance.unwrap(), 250_000);

zingo_client
.do_shield(
&[
// zingolib::wallet::Pool::Sapling,
zingolib::wallet::Pool::Transparent,
],
None,
)
.await
.unwrap();
test_manager.regtest_manager.generate_n_blocks(1).unwrap();
zingo_client.do_sync(false).await.unwrap();

let balance = zingo_client.do_balance().await;
println!("@zingoproxytest: zingo_client balance: \n{:#?}.", balance);
assert_eq!(balance.transparent_balance.unwrap(), 0);
assert_eq!(balance.orchard_balance.unwrap(), 2_500_000_000);

drop_test_manager(
Some(test_manager.temp_conf_dir.path().to_path_buf()),
regtest_handler,
online,
)
.await;
}

#[tokio::test]
async fn shield_from_multiple() {
let online = Arc::new(AtomicBool::new(true));
let (test_manager, regtest_handler, _proxy_handler) =
TestManager::launch(online.clone()).await;
let zingo_client = test_manager.build_lightclient().await;

test_manager.regtest_manager.generate_n_blocks(1).unwrap();
zingo_client.do_sync(false).await.unwrap();
zingo_client
.do_send(vec![(
&zingolib::get_base_address!(zingo_client, "sapling"),
250_000,
None,
)])
.await
.unwrap();
zingo_client
.do_send(vec![(
&zingolib::get_base_address!(zingo_client, "transparent"),
250_000,
None,
)])
.await
.unwrap();
test_manager.regtest_manager.generate_n_blocks(1).unwrap();
zingo_client.do_sync(false).await.unwrap();

let balance = zingo_client.do_balance().await;
println!("@zingoproxytest: zingo_client balance: \n{:#?}.", balance);
assert_eq!(balance.sapling_balance.unwrap(), 250_000);
assert_eq!(balance.transparent_balance.unwrap(), 250_000);

zingo_client
.do_shield(
&[
zingolib::wallet::Pool::Sapling,
zingolib::wallet::Pool::Transparent,
],
None,
)
.await
.unwrap();
test_manager.regtest_manager.generate_n_blocks(1).unwrap();
zingo_client.do_sync(false).await.unwrap();

let balance = zingo_client.do_balance().await;
println!("@zingoproxytest: zingo_client balance: \n{:#?}.", balance);
assert_eq!(balance.sapling_balance.unwrap(), 0);
assert_eq!(balance.transparent_balance.unwrap(), 0);
assert_eq!(balance.orchard_balance.unwrap(), 2_500_000_000);

drop_test_manager(
Some(test_manager.temp_conf_dir.path().to_path_buf()),
regtest_handler,
online,
)
.await;
}

#[tokio::test]
async fn sync_full_batch() {
let online = Arc::new(AtomicBool::new(true));
let (test_manager, regtest_handler, _proxy_handler) =
TestManager::launch(online.clone()).await;
let zingo_client = test_manager.build_lightclient().await;

test_manager.regtest_manager.generate_n_blocks(2).unwrap();
zingo_client.do_sync(false).await.unwrap();

test_manager.regtest_manager.generate_n_blocks(30).unwrap();
zingo_client
.do_send(vec![(
&zingolib::get_base_address!(zingo_client, "unified"),
250_000,
None,
)])
.await
.unwrap();
test_manager.regtest_manager.generate_n_blocks(30).unwrap();
zingo_client
.do_send(vec![(
&zingolib::get_base_address!(zingo_client, "sapling"),
250_000,
None,
)])
.await
.unwrap();
test_manager.regtest_manager.generate_n_blocks(30).unwrap();
zingo_client
.do_send(vec![(
&zingolib::get_base_address!(zingo_client, "transparent"),
250_000,
None,
)])
.await
.unwrap();
test_manager.regtest_manager.generate_n_blocks(30).unwrap();
zingo_client.do_sync(false).await.unwrap();

let balance = zingo_client.do_balance().await;
println!("@zingoproxytest: zingo_client balance: \n{:#?}.", balance);
assert_eq!(balance.orchard_balance.unwrap(), 76_874_500_000);
assert_eq!(balance.sapling_balance.unwrap(), 250_000);
assert_eq!(balance.transparent_balance.unwrap(), 250_000);

drop_test_manager(
Some(test_manager.temp_conf_dir.path().to_path_buf()),
regtest_handler,
Expand All @@ -129,7 +404,7 @@ mod wallet {

// TODO: Add test for get_mempool_stream: lightclient::start_mempool_monitor.
// #[tokio::test]
// async fn mempool_monitor() {}
// async fn monitor_mempool() {}
}

mod nym {
Expand Down
Loading

0 comments on commit f2d5234

Please sign in to comment.