Merge branch 'master' of github.com:adityapk00/lightwalletclient

This commit is contained in:
Aditya Kulkarni
2019-09-30 21:12:26 -07:00
9 changed files with 121 additions and 134 deletions

View File

@@ -335,7 +335,7 @@ impl LightWallet {
}).collect::<Vec<(String, String)>>()
}
// Clears all the downloaded blocks and resets the state back to the inital block.
// Clears all the downloaded blocks and resets the state back to the initial block.
// After this, the wallet's initial state will need to be set
// and the wallet will need to be rescanned
pub fn clear_blocks(&self) {
@@ -1072,7 +1072,7 @@ impl LightWallet {
let mut builder = Builder::new(height);
// A note on t addresses
// Funds recieved by t-addresses can't be explicitly spent in ZecWallet.
// Funds received by t-addresses can't be explicitly spent in ZecWallet.
// ZecWallet will lazily consolidate all t address funds into your shielded addresses.
// Specifically, if you send an outgoing transaction that is sent to a shielded address,
// ZecWallet will add all your t-address funds into that transaction, and send them to your shielded
@@ -1197,8 +1197,7 @@ impl LightWallet {
#[cfg(test)]
pub mod tests {
use std::convert::TryInto;
use std::fs::File;
use std::io::{Read, Error, ErrorKind};
use std::io::{Error};
use ff::{Field, PrimeField, PrimeFieldRepr};
use pairing::bls12_381::Bls12;
use rand_core::{RngCore, OsRng};
@@ -1228,24 +1227,17 @@ pub mod tests {
use super::LightWallet;
use crate::LightClientConfig;
use secp256k1::{Secp256k1, key::PublicKey, key::SecretKey};
use crate::SaplingParams;
fn get_sapling_params(config: &LightClientConfig) -> Result<(Vec<u8>, Vec<u8>), Error> {
fn get_sapling_params() -> Result<(Vec<u8>, Vec<u8>), Error> {
// Read Sapling Params
let mut sapling_output = vec![];
let mut f = match File::open(config.get_params_path("sapling-output.params")) {
Ok(file) => file,
Err(_) => return Err(Error::new(ErrorKind::NotFound,
format!("Couldn't read {}", config.get_params_path("sapling-output.params").display())))
};
f.read_to_end(&mut sapling_output)?;
sapling_output.extend_from_slice(SaplingParams::get("sapling-output.params").unwrap().as_ref());
println!("Read output {}", sapling_output.len());
let mut sapling_spend = vec![];
let mut f = match File::open(config.get_params_path("sapling-spend.params")) {
Ok(file) => file,
Err(_) => return Err(Error::new(ErrorKind::NotFound,
format!("Couldn't read {}", config.get_params_path("sapling-spend.params").display())))
};
f.read_to_end(&mut sapling_spend)?;
sapling_spend.extend_from_slice(SaplingParams::get("sapling-spend.params").unwrap().as_ref());
println!("Read output {}", sapling_spend.len());
Ok((sapling_spend, sapling_output))
}
@@ -1832,7 +1824,7 @@ pub mod tests {
}
// Get a test wallet already setup with a single note
fn get_test_wallet(amount: u64) -> (LightWallet, LightClientConfig, TxId, BlockHash) {
fn get_test_wallet(amount: u64) -> (LightWallet, TxId, BlockHash) {
let config = get_test_config();
let wallet = LightWallet::new(None, &config, 0).unwrap();
@@ -1852,18 +1844,17 @@ pub mod tests {
assert_eq!(wallet.verified_zbalance(None), amount);
// Create a new block so that the note is now verified to be spent
let cb2 = FakeCompactBlock::new(1, cb1.hash());
wallet.scan_block(&cb2.as_bytes()).unwrap();
(wallet, config, txid1, cb2.hash())
(wallet, txid1, cb2.hash())
}
#[test]
fn test_z_spend() {
const AMOUNT1: u64 = 50000;
let (wallet, config, txid1, block_hash) = get_test_wallet(AMOUNT1);
let (wallet, txid1, block_hash) = get_test_wallet(AMOUNT1);
let fvk = ExtendedFullViewingKey::from(&ExtendedSpendingKey::master(&[1u8; 32]));
let ext_address = encode_payment_address(wallet.config.hrp_sapling_address(),
@@ -1875,7 +1866,7 @@ pub mod tests {
let fee: u64 = DEFAULT_FEE.try_into().unwrap();
let branch_id = u32::from_str_radix("2bb40e60", 16).unwrap();
let (ss, so) = get_sapling_params(&config).unwrap();
let (ss, so) =get_sapling_params().unwrap();
// Create a tx and send to address
let raw_tx = wallet.send_to_address(branch_id, &ss, &so,
@@ -1933,10 +1924,10 @@ pub mod tests {
#[test]
fn test_z_spend_to_taddr() {
const AMOUNT1: u64 = 50000;
let (wallet, config, txid1, block_hash) = get_test_wallet(AMOUNT1);
let (wallet, txid1, block_hash) = get_test_wallet(AMOUNT1);
let branch_id = u32::from_str_radix("2bb40e60", 16).unwrap();
let (ss, so) = get_sapling_params(&config).unwrap();
let (ss, so) =get_sapling_params().unwrap();
let taddr = wallet.address_from_sk(&SecretKey::from_slice(&[1u8; 32]).unwrap());
const AMOUNT_SENT: u64 = 30;
@@ -1998,7 +1989,7 @@ pub mod tests {
const AMOUNT_Z: u64 = 50000;
const AMOUNT_T: u64 = 40000;
let (wallet, config, txid1, block_hash) = get_test_wallet(AMOUNT_Z);
let (wallet, txid1, block_hash) = get_test_wallet(AMOUNT_Z);
let pk = PublicKey::from_secret_key(&secp, &wallet.tkeys[0]);
let taddr = wallet.address_from_sk(&wallet.tkeys[0]);
@@ -2031,7 +2022,7 @@ pub mod tests {
let fee: u64 = DEFAULT_FEE.try_into().unwrap();
let branch_id = u32::from_str_radix("2bb40e60", 16).unwrap();
let (ss, so) = get_sapling_params(&config).unwrap();
let (ss, so) =get_sapling_params().unwrap();
// Create a tx and send to address. This should consume both the UTXO and the note
let raw_tx = wallet.send_to_address(branch_id, &ss, &so,
@@ -2096,7 +2087,7 @@ pub mod tests {
#[test]
fn test_z_incoming_memo() {
const AMOUNT1: u64 = 50000;
let (wallet, config, _txid1, block_hash) = get_test_wallet(AMOUNT1);
let (wallet, _txid1, block_hash) = get_test_wallet(AMOUNT1);
let my_address = encode_payment_address(wallet.config.hrp_sapling_address(),
&wallet.extfvks[0].default_address().unwrap().1);
@@ -2105,7 +2096,7 @@ pub mod tests {
let fee: u64 = DEFAULT_FEE.try_into().unwrap();
let branch_id = u32::from_str_radix("2bb40e60", 16).unwrap();
let (ss, so) = get_sapling_params(&config).unwrap();
let (ss, so) =get_sapling_params().unwrap();
// Create a tx and send to address
let raw_tx = wallet.send_to_address(branch_id, &ss, &so,