Skip to content

Commit

Permalink
Merge branch 'dev' into deconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
fluidvanadium authored Aug 27, 2024
2 parents eae4452 + e60b02e commit aa4df1f
Show file tree
Hide file tree
Showing 12 changed files with 195 additions and 207 deletions.
9 changes: 6 additions & 3 deletions libtonode-tests/tests/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ mod load_wallet {
use zingolib::testutils::paths::get_cargo_manifest_dir;
use zingolib::testutils::scenarios;
use zingolib::utils;
use zingolib::wallet::disk::testing::examples;
use zingolib::wallet::LightWallet;

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

let wallet = LightWallet::load_example_wallet_legacy(
zingolib::wallet::disk::testing::examples::LegacyWalletCase::OldWalletReorgTestWallet,
)
let wallet = LightWallet::load_example_wallet(examples::ExampleWalletNetwork::Regtest(
examples::ExampleRegtestWalletSeed::HMVASMUVWMSSVICHCARBPOCT(
examples::ExampleHMVASMUVWMSSVICHCARBPOCTWalletVersion::V27,
),
))
.await;

// let wallet = zingolib::testutils::load_wallet(
Expand Down
8 changes: 7 additions & 1 deletion zingolib/src/wallet/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ use super::{
};

impl LightWallet {
/// TODO: Add Doc Comment Here!
/// Changes in version 27:
/// - The wallet does not have to have a mnemonic.
/// Absence of mnemonic is represented by an empty byte vector in v27.
/// v26 serialized wallet is always loaded with `Some(mnemonic)`.
/// - The wallet capabilities can be restricted from spending to view-only or none.
/// We introduce `Capability` type represent different capability types in v27.
/// v26 serialized wallet is always loaded with `Capability::Spend(sk)`.
pub const fn serialized_version() -> u64 {
28
}
Expand Down
203 changes: 107 additions & 96 deletions zingolib/src/wallet/disk/testing/examples.rs
Original file line number Diff line number Diff line change
@@ -1,161 +1,172 @@
use super::super::LightWallet;

/// as opposed to [LegacyWalletCase], which enumerates test cases compiled from the history of zingo wallt tests, this ExampleWalletNetworkCase is meant to fully organize the set of test cases.
/// ExampleWalletNetworkCase sorts first by Network, then seed, then last saved version.
/// It is public so that any consumer can select and load any example wallet.
#[non_exhaustive]
#[derive(Clone)]
pub enum ExampleWalletNetworkCase {
pub enum ExampleWalletNetwork {
/// /
Mainnet(ExampleMainnetWalletSeedCase),
Regtest(ExampleRegtestWalletSeed),
/// /
Testnet(ExampleTestnetWalletSeedCase),
Testnet(ExampleTestnetWalletSeed),
/// /
Regtest(ExampleRegtestWalletSeedCase),
Mainnet(ExampleMainnetWalletSeed),
}

/// /
#[non_exhaustive]
#[derive(Clone)]
pub enum ExampleMainnetWalletSeedCase {
/// this is a mainnet seed
VTFCORFBCBPCTCFUPMEGMWBP(ExampleVTFCORFBCBPCTCFUPMEGMWBPWalletVersionCase),
pub enum ExampleMainnetWalletSeed {
/// this is a mainnet wallet originally called missing_data_test
VTFCORFBCBPCTCFUPMEGMWBP(ExampleVTFCORFBCBPCTCFUPMEGMWBPWalletVersion),
}
/// /
#[non_exhaustive]
#[derive(Clone)]
pub enum ExampleVTFCORFBCBPCTCFUPMEGMWBPWalletVersionCase {
pub enum ExampleVTFCORFBCBPCTCFUPMEGMWBPWalletVersion {
/// wallet was last saved in this serialization version
V28,
}
/// /
#[non_exhaustive]
#[derive(Clone)]
pub enum ExampleTestnetWalletSeedCase {
/// This is a testnet seed.
MSKMGDBHOTBPETCJWCSPGOPP(ExampleMSKMGDBHOTBPETCJWCSPGOPPWalletVersionCase),
pub enum ExampleTestnetWalletSeed {
/// This is a testnet seed, generated by fluidvanadium at the beginning of owls (this example wallet enumeration)
MSKMGDBHOTBPETCJWCSPGOPP(ExampleMSKMGDBHOTBPETCJWCSPGOPPWalletVersion),
/// this testnet wallet was generated at the beginning of serialization v28 by fluidvanadium
CBBHRWIILGBRABABSSHSMTPR(ExampleCBBHRWIILGBRABABSSHSMTPRWalletVersion),
}
/// /
#[non_exhaustive]
#[derive(Clone)]
pub enum ExampleMSKMGDBHOTBPETCJWCSPGOPPWalletVersionCase {
pub enum ExampleMSKMGDBHOTBPETCJWCSPGOPPWalletVersion {
/// wallet was last saved by the code in this commit
Gab72a38b,
}
/// A testnet wallet initiated with
/// --seed "chimney better bulb horror rebuild whisper improve intact letter giraffe brave rib appear bulk aim burst snap salt hill sad merge tennis phrase raise"
/// with 3 addresses containing all receivers.
/// including orchard and sapling transactions
#[non_exhaustive]
#[derive(Clone)]
pub enum ExampleCBBHRWIILGBRABABSSHSMTPRWalletVersion {
/// wallet was last saved in this serialization version
V26,
/// wallet was last saved in this serialization version
V27,
/// wallet was last saved in this serialization version
V28,
}
/// /
#[non_exhaustive]
#[derive(Clone)]
pub enum ExampleRegtestWalletSeedCase {}

/// loads test wallets
impl LightWallet {
/// loads any one of the test wallets included in the examples
pub async fn load_example_wallet(case: ExampleWalletNetworkCase) -> Self {
match case {
ExampleWalletNetworkCase::Mainnet(
ExampleMainnetWalletSeedCase::VTFCORFBCBPCTCFUPMEGMWBP(
ExampleVTFCORFBCBPCTCFUPMEGMWBPWalletVersionCase::V28,
),
) => {
LightWallet::unsafe_from_buffer_mainnet(include_bytes!(
"examples/mainnet/vtfcorfbcbpctcfupmegmwbp/v28/zingo-wallet.dat"
))
.await
}
ExampleWalletNetworkCase::Testnet(
ExampleTestnetWalletSeedCase::MSKMGDBHOTBPETCJWCSPGOPP(
ExampleMSKMGDBHOTBPETCJWCSPGOPPWalletVersionCase::Gab72a38b,
),
) => {
LightWallet::unsafe_from_buffer_testnet(include_bytes!(
"examples/testnet/mskmgdbhotbpetcjwcspgopp/Gab72a38b/zingo-wallet.dat"
))
.await
}
_ => unimplemented!(),
}
}
pub enum ExampleRegtestWalletSeed {
/// this is a regtest wallet originally called old_wallet_reorg_test_wallet
HMVASMUVWMSSVICHCARBPOCT(ExampleHMVASMUVWMSSVICHCARBPOCTWalletVersion),
/// this is a regtest wallet originally called v26/sap_only
AAAAAAAAAAAAAAAAAAAAAAAA(ExampleAAAAAAAAAAAAAAAAAAAAAAAAWalletVersion),
}

/// i do not know the difference between these wallets but i will find out soon
/// what can these files do?
/// /
#[non_exhaustive]
#[derive(Clone)]
pub enum LegacyWalletCaseZingoV26 {
/// /
One,
/// /
Two,
/// regtest sap only wallet
RegtestSapOnly,
pub enum ExampleHMVASMUVWMSSVICHCARBPOCTWalletVersion {
/// wallet was last saved in this serialization version
V27,
}
/// an enumeration of cases to test
/// /
#[non_exhaustive]
#[derive(Clone)]
pub enum LegacyWalletCase {
/// at this version, legacy testing began
ZingoV26(LegacyWalletCaseZingoV26),
/// ?
ZingoV28,
/// ...
OldWalletReorgTestWallet,
pub enum ExampleAAAAAAAAAAAAAAAAAAAAAAAAWalletVersion {
/// wallet was last saved in this serialization version
V26,
}

/// loads test wallets
impl LightWallet {
/// loads test wallets
/// this function can be improved by a macro. even better would be to derive directly from the enum.
// this file is fuc
/// loads any one of the test wallets included in the examples
pub async fn load_example_wallet_legacy(case: LegacyWalletCase) -> Self {
pub async fn load_example_wallet(case: ExampleWalletNetwork) -> Self {
match case {
LegacyWalletCase::ZingoV26(LegacyWalletCaseZingoV26::One) => {
ExampleWalletNetwork::Regtest(ExampleRegtestWalletSeed::HMVASMUVWMSSVICHCARBPOCT(
ExampleHMVASMUVWMSSVICHCARBPOCTWalletVersion::V27,
)) => {
LightWallet::unsafe_from_buffer_regtest(include_bytes!(
"examples/regtest/hmvasmuvwmssvichcarbpoct/v27/zingo-wallet.dat"
))
.await
}
ExampleWalletNetwork::Regtest(ExampleRegtestWalletSeed::AAAAAAAAAAAAAAAAAAAAAAAA(
ExampleAAAAAAAAAAAAAAAAAAAAAAAAWalletVersion::V26,
)) => {
LightWallet::unsafe_from_buffer_regtest(include_bytes!(
"examples/regtest/aaaaaaaaaaaaaaaaaaaaaaaa/v26/zingo-wallet.dat"
))
.await
}
ExampleWalletNetwork::Testnet(ExampleTestnetWalletSeed::MSKMGDBHOTBPETCJWCSPGOPP(
ExampleMSKMGDBHOTBPETCJWCSPGOPPWalletVersion::Gab72a38b,
)) => {
LightWallet::unsafe_from_buffer_testnet(include_bytes!(
"examples/v26-1/zingo-wallet.dat"
"examples/testnet/mskmgdbhotbpetcjwcspgopp/Gab72a38b/zingo-wallet.dat"
))
.await
}
LegacyWalletCase::ZingoV26(LegacyWalletCaseZingoV26::Two) => {
ExampleWalletNetwork::Testnet(ExampleTestnetWalletSeed::CBBHRWIILGBRABABSSHSMTPR(
ExampleCBBHRWIILGBRABABSSHSMTPRWalletVersion::V26,
)) => {
LightWallet::unsafe_from_buffer_testnet(include_bytes!(
"examples/v26-2/zingo-wallet.dat"
"examples/testnet/cbbhrwiilgbrababsshsmtpr/v26/zingo-wallet.dat"
))
.await
}
LegacyWalletCase::ZingoV26(LegacyWalletCaseZingoV26::RegtestSapOnly) => {
LightWallet::unsafe_from_buffer_regtest(include_bytes!(
"examples/v26/202302_release/regtest/sap_only/zingo-wallet.dat"
ExampleWalletNetwork::Testnet(ExampleTestnetWalletSeed::CBBHRWIILGBRABABSSHSMTPR(
ExampleCBBHRWIILGBRABABSSHSMTPRWalletVersion::V27,
)) => {
LightWallet::unsafe_from_buffer_testnet(include_bytes!(
"examples/testnet/cbbhrwiilgbrababsshsmtpr/v27/zingo-wallet.dat"
))
.await
}
LegacyWalletCase::ZingoV28 => {
ExampleWalletNetwork::Testnet(ExampleTestnetWalletSeed::CBBHRWIILGBRABABSSHSMTPR(
ExampleCBBHRWIILGBRABABSSHSMTPRWalletVersion::V28,
)) => {
LightWallet::unsafe_from_buffer_testnet(include_bytes!(
"examples/zingo-wallet-v28.dat"
"examples/testnet/cbbhrwiilgbrababsshsmtpr/v28/zingo-wallet.dat"
))
.await
}
LegacyWalletCase::OldWalletReorgTestWallet => {
LightWallet::unsafe_from_buffer_regtest(include_bytes!(
"examples/old_wallet_reorg_test_wallet/zingo-wallet.dat"
ExampleWalletNetwork::Mainnet(ExampleMainnetWalletSeed::VTFCORFBCBPCTCFUPMEGMWBP(
ExampleVTFCORFBCBPCTCFUPMEGMWBPWalletVersion::V28,
)) => {
LightWallet::unsafe_from_buffer_mainnet(include_bytes!(
"examples/mainnet/vtfcorfbcbpctcfupmegmwbp/v28/zingo-wallet.dat"
))
.await
}
}
}
}

/// each wallet file has a saved balance
pub fn example_expected_balance(case: LegacyWalletCase) -> u64 {
match case {
LegacyWalletCase::ZingoV26(LegacyWalletCaseZingoV26::One) => 0,
LegacyWalletCase::ZingoV26(LegacyWalletCaseZingoV26::Two) => 10177826,
LegacyWalletCase::ZingoV26(LegacyWalletCaseZingoV26::RegtestSapOnly) => todo!(),
LegacyWalletCase::ZingoV28 => 10342837,
LegacyWalletCase::OldWalletReorgTestWallet => todo!(),
}
}
// /// loads test wallets
// impl LightWallet {
// /// each wallet file has a saved balance
// pub fn example_expected_balance(case: LegacyWalletCase) -> u64 {
// match case {
// // LegacyWalletCase::ZingoV26(LegacyWalletCaseZingoV26::One) => 0,
// // LegacyWalletCase::ZingoV26(LegacyWalletCaseZingoV26::Two) => 10177826,
// LegacyWalletCase::ZingoV26(LegacyWalletCaseZingoV26::RegtestSapOnly) => todo!(),
// LegacyWalletCase::ZingoV28 => 10342837,
// }
// }

/// each wallet file has a saved balance
pub fn example_expected_num_addresses(case: LegacyWalletCase) -> usize {
match case {
LegacyWalletCase::ZingoV26(LegacyWalletCaseZingoV26::One) => 3,
LegacyWalletCase::ZingoV26(LegacyWalletCaseZingoV26::Two) => 1,
LegacyWalletCase::ZingoV26(LegacyWalletCaseZingoV26::RegtestSapOnly) => todo!(),
LegacyWalletCase::ZingoV28 => 3,
LegacyWalletCase::OldWalletReorgTestWallet => todo!(),
}
}
}
// /// each wallet file has a saved balance
// pub fn example_expected_num_addresses(case: LegacyWalletCase) -> usize {
// match case {
// // LegacyWalletCase::ZingoV26(LegacyWalletCaseZingoV26::One) => 3,
// // LegacyWalletCase::ZingoV26(LegacyWalletCaseZingoV26::Two) => 1,
// LegacyWalletCase::ZingoV26(LegacyWalletCaseZingoV26::RegtestSapOnly) => todo!(),
// LegacyWalletCase::ZingoV28 => 3,
// }
// }
// }
Loading

0 comments on commit aa4df1f

Please sign in to comment.