Skip to content

Commit

Permalink
Merge pull request #792 from fluidvanadium/undeprecate_lightclient_un…
Browse files Browse the repository at this point in the history
…it_test

Undeprecate lightclient unit test
  • Loading branch information
AloeareV authored Jan 25, 2024
2 parents 2e37ffc + 79bd989 commit c008e3f
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 63 deletions.
64 changes: 64 additions & 0 deletions zingolib/src/lightclient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2216,6 +2216,70 @@ async fn get_recent_median_price_from_gemini() -> Result<f64, PriceFetchError> {
Ok(trades[5])
}

#[cfg(test)]
mod tests {
use tokio::runtime::Runtime;
use zingo_testvectors::seeds::CHIMNEY_BETTER_SEED;
use zingoconfig::{ChainType, ZingoConfig};

use crate::{lightclient::LightClient, wallet::WalletBase};

#[test]
fn new_wallet_from_phrase() {
let temp_dir = tempfile::Builder::new().prefix("test").tempdir().unwrap();
let data_dir = temp_dir
.into_path()
.canonicalize()
.expect("This path is available.");

let wallet_name = data_dir.join("zingo-wallet.dat");
let config = ZingoConfig::build(ChainType::FakeMainnet)
.set_wallet_dir(data_dir)
.create();
let lc = LightClient::create_from_wallet_base(
WalletBase::MnemonicPhrase(CHIMNEY_BETTER_SEED.to_string()),
&config,
0,
false,
)
.unwrap();
assert_eq!(
format!(
"{:?}",
LightClient::create_from_wallet_base(
WalletBase::MnemonicPhrase(CHIMNEY_BETTER_SEED.to_string()),
&config,
0,
false
)
.err()
.unwrap()
),
format!(
"{:?}",
std::io::Error::new(
std::io::ErrorKind::AlreadyExists,
format!("Cannot create a new wallet from seed, because a wallet already exists at:\n{:?}", wallet_name),
)
)
);

// The first t address and z address should be derived
Runtime::new().unwrap().block_on(async move {
let addresses = lc.do_addresses().await;
assert_eq!(
"zs1q6xk3q783t5k92kjqt2rkuuww8pdw2euzy5rk6jytw97enx8fhpazdv3th4xe7vsk6e9sfpawfg"
.to_string(),
addresses[0]["receivers"]["sapling"]
);
assert_eq!(
"t1eQ63fwkQ4n4Eo5uCrPGaAV8FWB2tmx7ui",
addresses[0]["receivers"]["transparent"]
);
});
}
}

#[cfg(feature = "lightclient-deprecated")]
mod deprecated;
#[cfg(feature = "test-features")]
Expand Down
63 changes: 0 additions & 63 deletions zingolib/src/lightclient/deprecated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,66 +204,3 @@ impl LightClient {
JsonValue::Array(consumer_ui_notes)
}
}
#[cfg(test)]
mod tests {
use tokio::runtime::Runtime;
use zingo_testvectors::seeds::CHIMNEY_BETTER_SEED;
use zingoconfig::{ChainType, ZingoConfig};

use crate::{lightclient::LightClient, wallet::WalletBase};

#[test]
fn new_wallet_from_phrase() {
let temp_dir = tempfile::Builder::new().prefix("test").tempdir().unwrap();
let data_dir = temp_dir
.into_path()
.canonicalize()
.expect("This path is available.");

let wallet_name = data_dir.join("zingo-wallet.dat");
let config = ZingoConfig::build(ChainType::FakeMainnet)
.set_wallet_dir(data_dir)
.create();
let lc = LightClient::create_from_wallet_base(
WalletBase::MnemonicPhrase(CHIMNEY_BETTER_SEED.to_string()),
&config,
0,
false,
)
.unwrap();
assert_eq!(
format!(
"{:?}",
LightClient::create_from_wallet_base(
WalletBase::MnemonicPhrase(CHIMNEY_BETTER_SEED.to_string()),
&config,
0,
false
)
.err()
.unwrap()
),
format!(
"{:?}",
std::io::Error::new(
std::io::ErrorKind::AlreadyExists,
format!("Cannot create a new wallet from seed, because a wallet already exists at:\n{:?}", wallet_name),
)
)
);

// The first t address and z address should be derived
Runtime::new().unwrap().block_on(async move {
let addresses = lc.do_addresses().await;
assert_eq!(
"zs1q6xk3q783t5k92kjqt2rkuuww8pdw2euzy5rk6jytw97enx8fhpazdv3th4xe7vsk6e9sfpawfg"
.to_string(),
addresses[0]["receivers"]["sapling"]
);
assert_eq!(
"t1eQ63fwkQ4n4Eo5uCrPGaAV8FWB2tmx7ui",
addresses[0]["receivers"]["transparent"]
);
});
}
}

0 comments on commit c008e3f

Please sign in to comment.