diff --git a/bitcrust-lib/src/store/spent_tree/mod.rs b/bitcrust-lib/src/store/spent_tree/mod.rs index 53ab4ec..80038d2 100644 --- a/bitcrust-lib/src/store/spent_tree/mod.rs +++ b/bitcrust-lib/src/store/spent_tree/mod.rs @@ -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; @@ -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); + (*/ + + + + + } +} + diff --git a/bitcrust-lib/src/store/spent_tree/record.rs b/bitcrust-lib/src/store/spent_tree/record.rs index 5b89a34..e5ec0c3 100644 --- a/bitcrust-lib/src/store/spent_tree/record.rs +++ b/bitcrust-lib/src/store/spent_tree/record.rs @@ -24,6 +24,7 @@ pub struct Record { impl Record { fn get_bits(&self, start: u64, length: u64) -> u64 { + (self.skips >> start) & ((2^length)-1) } @@ -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!() } } */ @@ -102,4 +103,6 @@ mod tests { + + } \ No newline at end of file