Skip to content

Commit

Permalink
Merge pull request zingolabs#1417 from fluidvanadium/main_bc_owl
Browse files Browse the repository at this point in the history
Improve Old Wallet Verification and Add TestNet tests
  • Loading branch information
Oscar-Pepper authored Sep 24, 2024
2 parents f25f2c1 + f229157 commit 308edba
Show file tree
Hide file tree
Showing 20 changed files with 402 additions and 164 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ rand = "0.8.5"
reqwest = "0.12"
ring = "0.17.0"
rust-embed = "6.3.0"
rustls = { version = "0.23.13", features = ["ring"] }
rustls-pemfile = "1.0.0"
rustyline = "11.0.0"
secp256k1 = "=0.27.0"
Expand Down
8 changes: 4 additions & 4 deletions libtonode-tests/tests/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ mod load_wallet {
use zingolib::utils;
use zingolib::wallet::disk::testing::examples;
use zingolib::wallet::propose::ProposeSendError::Proposal;
use zingolib::wallet::LightWallet;

#[tokio::test]
async fn load_old_wallet_at_reorged_height() {
Expand Down Expand Up @@ -74,11 +73,12 @@ mod load_wallet {
let _cph = regtest_manager.launch(false).unwrap();
println!("loading wallet");

let wallet = LightWallet::load_example_wallet(examples::ExampleWalletNetwork::Regtest(
let wallet = examples::ExampleWalletNetwork::Regtest(
examples::ExampleRegtestWalletSeed::HMVASMUVWMSSVICHCARBPOCT(
examples::ExampleHMVASMUVWMSSVICHCARBPOCTWalletVersion::V27,
examples::ExampleHMVASMUVWMSSVICHCARBPOCTVersion::V27,
),
))
)
.load_example_wallet()
.await;

// let wallet = zingolib::testutils::load_wallet(
Expand Down
1 change: 1 addition & 0 deletions zingo-netutils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ hyper-rustls.workspace = true
hyper-util.workspace = true
hyper.workspace = true
prost.workspace = true
rustls.workspace = true
rustls-pemfile = { workspace = true }
thiserror.workspace = true
tokio-rustls.workspace = true
Expand Down
5 changes: 5 additions & 0 deletions zingo-netutils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ impl GrpcConnector {
> {
let uri = Arc::new(self.uri.clone());
async move {
// install default crypto provider (ring)
if let Err(e) = rustls::crypto::ring::default_provider().install_default() {
eprintln!("Error installing crypto provider: {:?}", e)
};

let mut http_connector = HttpConnector::new();
http_connector.enforce_http(false);
let scheme = uri.scheme().ok_or(GetClientError::InvalidScheme)?.clone();
Expand Down
6 changes: 1 addition & 5 deletions zingolib/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,7 @@ impl ZingoConfig {
/// create a ZingoConfig that helps a LightClient connect to a server.
pub fn create_mainnet() -> ZingoConfig {
ZingoConfig::build(ChainType::Mainnet)
.set_lightwalletd_uri(
("https://zcash.mysideoftheweb.com:19067")
.parse::<http::Uri>()
.unwrap(),
)
.set_lightwalletd_uri(("https://zec.rocks:443").parse::<http::Uri>().unwrap())
.create()
}

Expand Down
78 changes: 64 additions & 14 deletions zingolib/src/lightclient/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,14 +318,16 @@ pub mod send_with_proposal {

#[cfg(all(test, feature = "testvectors"))]
mod tests {
use zcash_client_backend::PoolType;

use crate::{
lightclient::LightClient,
wallet::{
disk::testing::examples::{
ExampleMSKMGDBHOTBPETCJWCSPGOPPWalletVersion, ExampleTestnetWalletSeed,
ExampleWalletNetwork,
},
LightWallet,
lightclient::sync::test::sync_example_wallet,
testutils::chain_generics::{
conduct_chain::ConductChain as _, live_chain::LiveChain, with_assertions,
},
wallet::disk::testing::examples::{
ExampleCBBHRWIILGBRABABSSHSMTPRVersion, ExampleMSKMGDBHOTBPETCJWCSPGOPPVersion,
ExampleTestnetWalletSeed, ExampleWalletNetwork,
},
};

Expand All @@ -347,17 +349,65 @@ pub mod send_with_proposal {
// TODO: match on specific error
}

#[ignore]
#[ignore = "live testnet"]
#[tokio::test]
/// this is a live sync test. its execution time scales linearly since last updated
/// this is a live send test. whether it can work depends on the state of live wallet on the blockchain
/// this wallet contains archaic diversified addresses, which may clog the new send engine.
async fn testnet_mskmgdbhotbpetcjwcspgopp_shield_multi_account() {
std::env::set_var("RUST_BACKTRACE", "1");
let client = crate::lightclient::sync::test::sync_example_wallet(
ExampleWalletNetwork::Testnet(ExampleTestnetWalletSeed::MSKMGDBHOTBPETCJWCSPGOPP(
ExampleMSKMGDBHOTBPETCJWCSPGOPPVersion::Ga74fed621,
)),
)
.await;

with_assertions::propose_shield_bump_sync(&mut LiveChain::setup().await, &client, true)
.await;
}

#[ignore = "live testnet"]
#[tokio::test]
/// this is a live sync test. its execution time scales linearly since last updated
/// this is a live send test. whether it can work depends on the state of live wallet on the blockchain
async fn testnet_cbbhrwiilgbrababsshsmtpr_send_to_self_orchard_hot() {
std::env::set_var("RUST_BACKTRACE", "1");
let client = sync_example_wallet(ExampleWalletNetwork::Testnet(
ExampleTestnetWalletSeed::CBBHRWIILGBRABABSSHSMTPR(
ExampleCBBHRWIILGBRABABSSHSMTPRVersion::G2f3830058,
),
))
.await;

with_assertions::propose_send_bump_sync_all_recipients(
&mut LiveChain::setup().await,
&client,
vec![(
&client,
PoolType::Shielded(zcash_client_backend::ShieldedProtocol::Orchard),
10_000,
None,
)],
false,
)
.await;
}

#[ignore = "live testnet"]
#[tokio::test]
async fn sync_testnet() {
let wallet = LightWallet::load_example_wallet(ExampleWalletNetwork::Testnet(
ExampleTestnetWalletSeed::MSKMGDBHOTBPETCJWCSPGOPP(
ExampleMSKMGDBHOTBPETCJWCSPGOPPWalletVersion::Gab72a38b,
/// this is a live sync test. its execution time scales linearly since last updated
async fn testnet_cbbhrwiilgbrababsshsmtpr_shield_hot() {
std::env::set_var("RUST_BACKTRACE", "1");
let client = sync_example_wallet(ExampleWalletNetwork::Testnet(
ExampleTestnetWalletSeed::CBBHRWIILGBRABABSSHSMTPR(
ExampleCBBHRWIILGBRABABSSHSMTPRVersion::G2f3830058,
),
))
.await;
let lc = LightClient::create_from_wallet_async(wallet).await.unwrap();
let _ = lc.do_sync(true).await;

with_assertions::propose_shield_bump_sync(&mut LiveChain::setup().await, &client, true)
.await;
}
}
}
51 changes: 51 additions & 0 deletions zingolib/src/lightclient/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -665,3 +665,54 @@ impl LightClient {
response
}
}

#[cfg(all(test, feature = "testvectors"))]
pub mod test {
use crate::{
lightclient::LightClient,
wallet::disk::testing::examples::{
ExampleCBBHRWIILGBRABABSSHSMTPRVersion, ExampleHHCCLALTPCCKCSSLPCNETBLRVersion,
ExampleMSKMGDBHOTBPETCJWCSPGOPPVersion, ExampleMainnetWalletSeed,
ExampleTestnetWalletSeed, ExampleWalletNetwork,
},
};

pub(crate) async fn sync_example_wallet(wallet_case: ExampleWalletNetwork) -> LightClient {
std::env::set_var("RUST_BACKTRACE", "1");
let wallet = wallet_case.load_example_wallet().await;
let lc = LightClient::create_from_wallet_async(wallet).await.unwrap();
let _ = lc.do_sync(true).await;
lc
}

/// this is a live sync test. its execution time scales linearly since last updated
#[tokio::test]
async fn testnet_sync_mskmgdbhotbpetcjwcspgopp_latest() {
sync_example_wallet(ExampleWalletNetwork::Testnet(
ExampleTestnetWalletSeed::MSKMGDBHOTBPETCJWCSPGOPP(
ExampleMSKMGDBHOTBPETCJWCSPGOPPVersion::Ga74fed621,
),
))
.await;
}
/// this is a live sync test. its execution time scales linearly since last updated
#[tokio::test]
async fn testnet_sync_cbbhrwiilgbrababsshsmtpr_latest() {
sync_example_wallet(ExampleWalletNetwork::Testnet(
ExampleTestnetWalletSeed::CBBHRWIILGBRABABSSHSMTPR(
ExampleCBBHRWIILGBRABABSSHSMTPRVersion::G2f3830058,
),
))
.await;
}
/// this is a live sync test. its execution time scales linearly since last updated
#[tokio::test]
async fn mainnet_sync_hhcclaltpcckcsslpcnetblr_latest() {
sync_example_wallet(ExampleWalletNetwork::Mainnet(
ExampleMainnetWalletSeed::HHCCLALTPCCKCSSLPCNETBLR(
ExampleHHCCLALTPCCKCSSLPCNETBLRVersion::Gf0aaf9347,
),
))
.await;
}
}
21 changes: 0 additions & 21 deletions zingolib/src/testutils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ pub use incrementalmerkletree;
use std::cmp;
use std::collections::HashMap;
use std::io::Read;
use std::path::{Path, PathBuf};
use std::string::String;
use std::sync::atomic::AtomicBool;
use std::sync::Arc;
Expand Down Expand Up @@ -324,26 +323,6 @@ async fn check_wallet_chainheight_value(client: &LightClient, target: u32) -> Re
Ok(get_synced_wallet_height(client).await? != target)
}

/// TODO: Add Doc Comment Here!
pub fn get_wallet_nym(nym: &str) -> Result<(String, PathBuf, PathBuf), String> {
match nym {
"sap_only" | "orch_only" | "orch_and_sapl" | "tadd_only" => {
let one_sapling_wallet = format!(
"{}/tests/data/wallets/v26/202302_release/regtest/{nym}/zingo-wallet.dat",
paths::get_cargo_manifest_dir().to_string_lossy()
);
let wallet_path = Path::new(&one_sapling_wallet);
let wallet_dir = wallet_path.parent().unwrap();
Ok((
one_sapling_wallet.clone(),
wallet_path.to_path_buf(),
wallet_dir.to_path_buf(),
))
}
_ => Err(format!("nym {nym} not a valid wallet directory")),
}
}

/// TODO: Add Doc Comment Here!
pub struct RecordingReader<Reader> {
from: Reader,
Expand Down
2 changes: 1 addition & 1 deletion zingolib/src/testutils/chain_generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//! - mempool

pub mod conduct_chain;
pub mod live_chain;

pub mod fixtures;

pub mod with_assertions;
32 changes: 32 additions & 0 deletions zingolib/src/testutils/chain_generics/live_chain.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//! implementation of conduct chain for live chains

use crate::lightclient::LightClient;

use super::conduct_chain::ConductChain;

/// this is essentially a placeholder.
/// allows using existing ChainGeneric functions with TestNet wallets
pub struct LiveChain;

impl ConductChain for LiveChain {
async fn setup() -> Self {
Self {}
}

async fn create_faucet(&mut self) -> LightClient {
unimplemented!()
}

fn zingo_config(&mut self) -> crate::config::ZingoConfig {
todo!()
}

async fn bump_chain(&mut self) {
// average block time is 75 seconds. we do this twice here to insist on a new block
tokio::time::sleep(std::time::Duration::from_secs(150)).await;
}

fn get_chain_height(&mut self) -> u32 {
unimplemented!()
}
}
15 changes: 13 additions & 2 deletions zingolib/src/testutils/chain_generics/with_assertions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ where
.await
.unwrap();

let send_height = environment.get_chain_height() + 1;
let send_height = sender
.wallet
.get_target_height_and_anchor_offset()
.await
.expect("sender has a target height")
.0;

// digesting the calculated transaction
// this step happens after transaction is recorded locally, but before learning anything about whether the server accepted it
Expand Down Expand Up @@ -128,7 +133,13 @@ where
{
let proposal = client.propose_shield().await.unwrap();

let send_height = environment.get_chain_height() + 1;
let send_height = client
.wallet
.get_target_height_and_anchor_offset()
.await
.expect("sender has a target height")
.0;

let txids = client
.complete_and_broadcast_stored_proposal()
.await
Expand Down
Loading

0 comments on commit 308edba

Please sign in to comment.