fix wallet tests, chain test output

This commit is contained in:
yeastplume 2018-06-22 14:04:51 +01:00
parent 94322c796c
commit 836d5441e6
4 changed files with 42 additions and 45 deletions

View file

@ -636,6 +636,7 @@ impl Chain {
Ok(b) => {
count += 1;
batch.delete_block(&b.hash())?;
//TODO: Validation seems to fail as block markers are being deleted?
batch.delete_block_marker(&b.hash())?;
batch.delete_block_input_bitmap(&b.hash())?;
}

View file

@ -272,7 +272,7 @@ impl<'a> Batch<'a> {
}
/// get block
fn get_block(&self, h: &Hash) -> Result<Block, Error> {
pub fn get_block(&self, h: &Hash) -> Result<Block, Error> {
option_to_not_found(self.db.get_ser(&to_key(BLOCK_PREFIX, &mut h.to_vec())))
}

View file

@ -356,8 +356,12 @@ fn spend_in_fork_and_compact() {
}
chain.validate(false).unwrap();
chain.compact().unwrap();
chain.validate(false).unwrap();
if let Err(e) = chain.compact() {
panic!("Error compacting chain: {:?}", e);
}
if let Err(e) = chain.validate(false) {
panic!("Validation error after compacting chain: {:?}", e);
}
}
fn prepare_block<K>(kc: &K, prev: &BlockHeader, chain: &Chain, diff: u64) -> Block

View file

@ -28,7 +28,8 @@ use core::core::hash::Hashed;
use core::core::{Output, OutputFeatures, OutputIdentifier, Transaction, TxKernel};
use core::{consensus, global, pow};
use keychain::ExtKeychain;
use wallet::file_wallet::{FileWallet, WalletConfig};
use wallet::file_wallet::FileWallet;
use wallet::WalletConfig;
use wallet::libwallet::internal::updater;
use wallet::libwallet::types::{BlockFees, BlockIdentifier, MerkleProofWrapper, OutputStatus,
WalletBackend};
@ -78,15 +79,12 @@ where
T: WalletBackend<K>,
K: keychain::Keychain,
{
let ret_val = wallet.read_wallet(|wallet_data| {
let mut unspent_total = 0;
let mut unspent_but_locked_total = 0;
let mut unconfirmed_total = 0;
let mut locked_total = 0;
let keychain = wallet_data.keychain().clone();
for out in wallet_data
.outputs()
.values()
let keychain = wallet.keychain().clone();
for out in wallet.iter()
.filter(|out| out.root_key_id == keychain.root_key_id())
{
if out.status == OutputStatus::Unspent {
@ -110,8 +108,6 @@ where
unspent_total - unspent_but_locked_total, // currently spendable
locked_total, // locked total
))
});
ret_val
}
/// Get an output from the chain locally and present it back as an API output
@ -183,16 +179,12 @@ where
let output_id = OutputIdentifier::from_output(&coinbase_tx.0.clone());
let m_proof = chain.get_merkle_proof(&output_id, &chain.head_header().unwrap());
let block_id = Some(BlockIdentifier(chain.head_header().unwrap().hash()));
let _ = wallet.with_wallet(|wallet_data| {
if let Entry::Occupied(mut output) = wallet_data
.outputs()
.entry(fees.key_id.as_ref().unwrap().to_hex())
{
let output = output.get_mut();
let mut output = wallet.get(&fees.key_id.unwrap()).unwrap();
output.block = block_id;
output.merkle_proof = Some(MerkleProofWrapper(m_proof.unwrap()));
}
});
let mut batch = wallet.batch().unwrap();
batch.save(output).unwrap();
batch.commit().unwrap();
}
/// adds many block rewards to a wallet, no transactions