Skip to content

Commit

Permalink
Start with spent-tree testing
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasvdw committed Dec 4, 2016
1 parent eb71ff5 commit 1cf7de0
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 3 deletions.
62 changes: 60 additions & 2 deletions bitcrust-lib/src/store/spent_tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
/// The scan is succesful if the transaction is found and unsuccesful if it is not found or if the
/// same spent-output is found before the transaction.
///
/// TODO
/// Refactor FilePtr & Record to be typed as what they point to
///
///
///
use std::mem;

Expand Down Expand Up @@ -114,3 +114,61 @@ impl SpentTree {

}


#[cfg(test)]
mod tests {

extern crate tempdir;
use store::fileptr::FilePtr;
use std::path::PathBuf;

use super::*;

/// Macro to create a block for the spent_tree tests
/// blockheaders and txs are unqiue numbers (fileptrs but where they point to doesn't matter
/// for the spent_tree).
///
/// Construct a block as
///
/// ```
/// (blk 1 => /* bloocknr */
/// [tx 2], /* tx with no inputs */
/// [tx 3 => (2;0),(2;1)] /* tx with two inputs referencing tx 2 ouput 0 and 1
/// )
///

macro_rules! block {

(blk $header:expr =>
$( [tx $tx:expr $(=> $( ($tx_in:expr;$tx_in_idx:expr) ),+)*] ),+
)
=>
( ( FilePtr::new(0,$header),
$( FilePtr::new(0,$tx), $( $( FilePtr::new(0,$tx_in).as_input($tx_in_idx) ),+ )* ),+
)
)

}

#[test]
fn test_spent_tree() {

//let block1 = block!(blk 1 -> [tx 2], [tx 3, spents (2;0),(2;1)] );
let block1 = block!(blk 1 =>
[tx 2 => (2;1),(2;0)],
[tx 3]
);

/*
let dir = tempdir::TempDir::new("test1").unwrap();
let cfg = config::Config { root: PathBuf::from(dir.path) };
let st = SpentTree::new(&cfg);
(*/




}
}

5 changes: 4 additions & 1 deletion bitcrust-lib/src/store/spent_tree/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub struct Record {
impl Record {

fn get_bits(&self, start: u64, length: u64) -> u64 {

(self.skips >> start) & ((2^length)-1)
}

Expand All @@ -38,7 +39,7 @@ impl Record {
1 => Some( self.before_in_memory(1) ),
2 => Some( self.before_in_memory( self.skips_bit_3_to_16())),
3 => None,
_ => panic!()
_ => unreachable!()
}
}
*/
Expand Down Expand Up @@ -102,4 +103,6 @@ mod tests {





}

0 comments on commit 1cf7de0

Please sign in to comment.