Skip to content

Commit

Permalink
Merge pull request #1598 from zancas/publish_testvectors_as_crate
Browse files Browse the repository at this point in the history
define a public testvectors crate.
  • Loading branch information
Oscar-Pepper authored Dec 23, 2024
2 parents 8745a0b + b5961d0 commit a22e723
Show file tree
Hide file tree
Showing 24 changed files with 1,244 additions and 1,256 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion darkside-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ edition = "2021"
chain_generic_tests = []

[dependencies]
zingolib = { path = "../zingolib", features = ["darkside_tests", "testvectors"] }
zingolib = { path = "../zingolib", features = ["darkside_tests"] }
zingo-sync = { path = "../zingo-sync" }
zingo-netutils = { path = "../zingo-netutils" }
zingo-status = { path = "../zingo-status" }
testvectors = { path = "../testvectors" }

tokio = { workspace = true, features = ["full"] }
json = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions darkside-tests/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,12 +379,12 @@ pub mod scenarios {
constants,
darkside_types::{RawTransaction, TreeState},
};
use testvectors::seeds::HOSPITAL_MUSEUM_SEED;
use zcash_client_backend::{PoolType, ShieldedProtocol};
use zcash_primitives::consensus::{BlockHeight, BranchId};
use zingolib::config::RegtestNetwork;
use zingolib::lightclient::LightClient;
use zingolib::testutils::scenarios::setup::ClientBuilder;
use zingolib::testvectors::seeds::HOSPITAL_MUSEUM_SEED;

use super::{
init_darksidewalletd, update_tree_states_for_transaction, write_raw_transaction,
Expand Down Expand Up @@ -446,7 +446,7 @@ pub mod scenarios {
self.faucet = Some(
self.client_builder
.build_client(
zingolib::testvectors::seeds::DARKSIDE_SEED.to_string(),
testvectors::seeds::DARKSIDE_SEED.to_string(),
0,
true,
self.regtest_network,
Expand Down
4 changes: 2 additions & 2 deletions darkside-tests/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use darkside_tests::utils::DarksideHandler;
use std::future::Future;
use std::pin::Pin;
use std::sync::Arc;
use testvectors::seeds::DARKSIDE_SEED;
use tokio::time::sleep;
use zcash_client_backend::PoolType::Shielded;
use zcash_client_backend::ShieldedProtocol::Orchard;
Expand All @@ -18,7 +19,6 @@ use zingolib::testutils::chain_generics::conduct_chain::ConductChain as _;
use zingolib::testutils::chain_generics::with_assertions::to_clients_proposal;
use zingolib::testutils::lightclient::from_inputs;
use zingolib::testutils::scenarios::setup::ClientBuilder;
use zingolib::testvectors::seeds::DARKSIDE_SEED;

#[tokio::test]
async fn simple_sync() {
Expand Down Expand Up @@ -156,7 +156,7 @@ async fn sent_transaction_reorged_into_mempool() {
.await;
let recipient = client_manager
.build_client(
zingolib::testvectors::seeds::HOSPITAL_MUSEUM_SEED.to_string(),
testvectors::seeds::HOSPITAL_MUSEUM_SEED.to_string(),
1,
true,
regtest_network,
Expand Down
1 change: 1 addition & 0 deletions libtonode-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ zingolib = { path = "../zingolib", features = ["deprecations", "test-elevation",
zingo-status = { path = "../zingo-status" }
zingo-netutils = { path = "../zingo-netutils" }
zingo-sync = { path = "../zingo-sync" }
testvectors = { path = "../testvectors" }

bip0039.workspace = true
zcash_primitives = { workspace = true }
Expand Down
21 changes: 8 additions & 13 deletions libtonode-tests/tests/concrete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use zingolib::wallet::keys::unified::UnifiedKeyStore;
use zingolib::wallet::propose::ProposeSendError;
use zingolib::{check_client_balances, get_base_address_macro, get_otd, validate_otds};

use testvectors::{block_rewards, seeds::HOSPITAL_MUSEUM_SEED, BASE_HEIGHT};
use zingolib::config::{ChainType, RegtestNetwork, MAX_REORG};
use zingolib::testvectors::{block_rewards, seeds::HOSPITAL_MUSEUM_SEED, BASE_HEIGHT};
use zingolib::{
lightclient::{LightClient, PoolBalances},
utils,
Expand Down Expand Up @@ -1290,6 +1290,7 @@ mod fast {
mod slow {
use bip0039::Mnemonic;
use orchard::note_encryption::OrchardDomain;
use testvectors::TEST_TXID;
use zcash_client_backend::{PoolType, ShieldedProtocol};
use zcash_primitives::{
consensus::NetworkConstants, memo::Memo, transaction::fees::zip317::MARGINAL_FEE,
Expand All @@ -1299,7 +1300,6 @@ mod slow {
assert_transaction_summary_equality, assert_transaction_summary_exists,
lightclient::{from_inputs, get_fees_paid_by_client},
};
use zingolib::testvectors::TEST_TXID;
use zingolib::{
lightclient::send::send_with_proposal::QuickSendError,
wallet::{
Expand Down Expand Up @@ -1683,11 +1683,8 @@ mod slow {

watch_client.do_rescan().await.unwrap();
assert!(matches!(
from_inputs::quick_send(
&watch_client,
vec![(zingolib::testvectors::EXT_TADDR, 1000, None)]
)
.await,
from_inputs::quick_send(&watch_client, vec![(testvectors::EXT_TADDR, 1000, None)])
.await,
Err(QuickSendError::ProposeSend(ProposeSendError::Proposal(
zcash_client_backend::data_api::error::Error::DataSource(
TxMapTraitError::NoSpendCapability
Expand Down Expand Up @@ -1725,12 +1722,10 @@ mod slow {

// 4. We can't spend the funds, as they're transparent. We need to shield first
let sent_value = 20_000;
let sent_transaction_error = from_inputs::quick_send(
&recipient,
vec![(zingolib::testvectors::EXT_TADDR, sent_value, None)],
)
.await
.unwrap_err();
let sent_transaction_error =
from_inputs::quick_send(&recipient, vec![(testvectors::EXT_TADDR, sent_value, None)])
.await
.unwrap_err();
assert!(matches!(
sent_transaction_error,
QuickSendError::ProposeSend(ProposeSendError::Proposal(
Expand Down
2 changes: 1 addition & 1 deletion libtonode-tests/tests/sync.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use tempfile::TempDir;
use testvectors::seeds::HOSPITAL_MUSEUM_SEED;
use zingo_netutils::GrpcConnector;
use zingo_sync::sync::sync;
use zingolib::{
config::{construct_lightwalletd_uri, load_clientconfig, DEFAULT_LIGHTWALLETD_SERVER},
get_base_address_macro,
lightclient::LightClient,
testutils::{lightclient::from_inputs, scenarios},
testvectors::seeds::HOSPITAL_MUSEUM_SEED,
wallet::WalletBase,
};

Expand Down
8 changes: 8 additions & 0 deletions testvectors/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "testvectors"
version = "0.1.0"
edition = "2021"

[dependencies]
zcash_primitives.workspace = true
bip0039 = { workspace = true }
58 changes: 58 additions & 0 deletions testvectors/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//! A public crate that provides access to testvectors
/// The number of blocks most tests start with.
pub const BASE_HEIGHT: u32 = 3;

/// TODO: Add Mod Description Here!
pub mod seeds {

/// TODO: Add Doc Comment Here!
pub const DARKSIDE_SEED: &str =
"still champion voice habit trend flight survey between bitter process artefact blind carbon truly provide dizzy crush flush breeze blouse charge solid fish spread";
#[test]
fn validate_seeds() {
let abandon_art_seed = bip0039::Mnemonic::<bip0039::English>::from_entropy([0; 32])
.unwrap()
.to_string();
assert_eq!(ABANDON_ART_SEED, abandon_art_seed);
// TODO user get_zaddr_from_bip39seed to generate this address from that seed.
}

/// Generate test seed
/// TODO: Add Doc Comment Here!
pub const ABANDON_ART_SEED: &str =
"abandon abandon abandon abandon abandon abandon abandon abandon \
abandon abandon abandon abandon abandon abandon abandon abandon \
abandon abandon abandon abandon abandon abandon abandon art";
/// TODO: Add Doc Comment Here!
pub const HOSPITAL_MUSEUM_SEED: &str = "hospital museum valve antique skate museum \
unfold vocal weird milk scale social vessel identify \
crowd hospital control album rib bulb path oven civil tank";
/// TODO: Add Doc Comment Here!
pub const CHIMNEY_BETTER_SEED: &str = "chimney better bulb horror rebuild whisper improve intact letter giraffe brave rib appear bulk aim burst snap salt hill sad merge tennis phrase raise";
}

/// faucet addresses
/// TODO: Add Doc Comment Here!
pub const REG_O_ADDR_FROM_ABANDONART: &str = "uregtest1zkuzfv5m3yhv2j4fmvq5rjurkxenxyq8r7h4daun2zkznrjaa8ra8asgdm8wwgwjvlwwrxx7347r8w0ee6dqyw4rufw4wg9djwcr6frzkezmdw6dud3wsm99eany5r8wgsctlxquu009nzd6hsme2tcsk0v3sgjvxa70er7h27z5epr67p5q767s2z5gt88paru56mxpm6pwz0cu35m";
/// TODO: Add Doc Comment Here!
pub const REG_Z_ADDR_FROM_ABANDONART: &str =
"zregtestsapling1fmq2ufux3gm0v8qf7x585wj56le4wjfsqsj27zprjghntrerntggg507hxh2ydcdkn7sx8kya7p";
/// TODO: Add Doc Comment Here!
pub const REG_T_ADDR_FROM_ABANDONART: &str = "tmBsTi2xWTjUdEXnuTceL7fecEQKeWaPDJd";

/// Regtest block rewards
pub mod block_rewards {
/// TODO: Add Doc Comment Here!
pub const SAPLING: u64 = 500_000_000;
/// TODO: Add Doc Comment Here!
pub const BLOSSOM: u64 = 500_000_000;
/// TODO: Add Doc Comment Here!
pub const CANOPY: u64 = 625_000_000;
}

/// Burn-to regtest address generated by `zcash-cli getnewaddress`
pub const EXT_TADDR: &str = "tmJTBtMwPU96XteSiP89xDz1WARNgRddEHq";

/// A test txid
pub const TEST_TXID: &str = "d5eaac5563f8bc1a0406588e05953977ad768d02f1cf8449e9d7d9cc8de3801c";
2 changes: 1 addition & 1 deletion zingolib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ deprecations = ["lightclient-deprecated"]
lightclient-deprecated = []
tempfile = ["dep:tempfile"]
test-elevation = ["portpicker", "testvectors", "tempfile", "tempdir"]
testvectors = []
sync = ['dep:zingo-sync']
zaino-test = ['test-elevation']

Expand All @@ -23,6 +22,7 @@ zingo-memo = { path = "../zingo-memo" }
zingo-status = { path = "../zingo-status" }
zingo-netutils = { path = "../zingo-netutils" }
zingo-sync = { path = "../zingo-sync", optional = true }
testvectors = { path = "../testvectors", optional = true }

orchard = { workspace = true }
shardtree = { workspace = true, features = ["legacy-api"] }
Expand Down
2 changes: 0 additions & 2 deletions zingolib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ pub mod wallet;
pub mod mocks;
#[cfg(any(test, feature = "test-elevation"))]
pub mod testutils;
#[cfg(any(test, feature = "testvectors"))]
pub mod testvectors;

// This line includes the generated `git_description()` function directly into this scope.
include!(concat!(env!("OUT_DIR"), "/git_description.rs"));
Expand Down
2 changes: 1 addition & 1 deletion zingolib/src/lightclient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ async fn get_recent_median_price_from_gemini() -> Result<f64, PriceFetchError> {
#[cfg(test)]
mod tests {
use crate::config::{ChainType, RegtestNetwork, ZingoConfig};
use crate::testvectors::seeds::CHIMNEY_BETTER_SEED;
use testvectors::seeds::CHIMNEY_BETTER_SEED;
use tokio::runtime::Runtime;

use crate::{lightclient::LightClient, wallet::WalletBase};
Expand Down
2 changes: 1 addition & 1 deletion zingolib/src/lightclient/propose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ mod shielding {
crate::lightclient::LightClient::create_unconnected(
&crate::config::ZingoConfigBuilder::default().create(),
crate::wallet::WalletBase::MnemonicPhrase(
crate::testvectors::seeds::HOSPITAL_MUSEUM_SEED.to_string(),
testvectors::seeds::HOSPITAL_MUSEUM_SEED.to_string(),
),
0,
)
Expand Down
5 changes: 3 additions & 2 deletions zingolib/src/lightclient/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ pub mod send_with_proposal {
}
}

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

Expand All @@ -389,8 +389,9 @@ pub mod send_with_proposal {
async fn complete_and_broadcast_unconnected_error() {
use crate::{
config::ZingoConfigBuilder, lightclient::LightClient,
mocks::proposal::ProposalBuilder, testvectors::seeds::ABANDON_ART_SEED,
mocks::proposal::ProposalBuilder,
};
use testvectors::seeds::ABANDON_ART_SEED;
let lc = LightClient::create_unconnected(
&ZingoConfigBuilder::default().create(),
crate::wallet::WalletBase::MnemonicPhrase(ABANDON_ART_SEED.to_string()),
Expand Down
2 changes: 1 addition & 1 deletion zingolib/src/lightclient/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ impl LightClient {
}
}

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

Expand Down
2 changes: 1 addition & 1 deletion zingolib/src/mocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ pub mod proposal {
let mut builder = Self::new();
builder
.recipient_address(
address_from_str(crate::testvectors::REG_O_ADDR_FROM_ABANDONART).unwrap(),
address_from_str(testvectors::REG_O_ADDR_FROM_ABANDONART).unwrap(),
)
.amount(NonNegativeAmount::from_u64(100_000).unwrap());
builder
Expand Down
Loading

0 comments on commit a22e723

Please sign in to comment.