tests for blockchain bloomfilters
This commit is contained in:
parent
0d80821841
commit
0699cdd5d0
@ -941,4 +941,20 @@ mod tests {
|
|||||||
assert_eq!(bc.transaction(&bc.transaction_address(&t.hash()).unwrap()).unwrap(), t);
|
assert_eq!(bc.transaction(&bc.transaction_address(&t.hash()).unwrap()).unwrap(), t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_bloom_filter_simple() {
|
||||||
|
let genesis = "f901fcf901f7a00000000000000000000000000000000000000000000000000000000000000000a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a07dba07d6b448a186e9612e5f737d1c909dce473e53199901a302c00646d523c1a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302000080832fefd8808454c98c8142a059262c330941f3fe2a34d16d6e3c7b30d2ceb37c6a0e9a994c494ee1a61d2410885aa4c8bf8e56e264c0c0".from_hex().unwrap();
|
||||||
|
|
||||||
|
// bloom filter flow block 300054
|
||||||
|
let b1 = "f90261f901f9a05716670833ec874362d65fea27a7cd35af5897d275b31a44944113111e4e96d2a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a0cb52de543653d86ccd13ba3ddf8b052525b04231c6884a4db3188a184681d878a0e78628dd45a1f8dc495594d83b76c588a3ee67463260f8b7d4a42f574aeab29aa0e9244cf7503b79c03d3a099e07a80d2dbc77bb0b502d8a89d51ac0d68dd31313b90100000000000000000000000000000000000000000000000200000010000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000080000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302000001832fefd882520884562791e580a051b3ecba4e3f2b49c11d42dd0851ec514b1be3138080f72a2b6e83868275d98f8877671f479c414b47f862f86080018304cb2f94095e7baea6a6c7c4c2dfeb977efac326af552d870a801ca09e2709d7ec9bbe6b1bbbf0b2088828d14cd5e8642a1fee22dc74bfa89761a7f9a04bd8813dee4be989accdb708b1c2e325a7e9c695a8024e30e89d6c644e424747c0".from_hex().unwrap();
|
||||||
|
|
||||||
|
let bloom = H2048::from_str("00000000000000000000000000000000000000000000020000001000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000008000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").unwrap();
|
||||||
|
|
||||||
|
let temp = RandomTempPath::new();
|
||||||
|
let bc = BlockChain::new(&genesis, temp.as_path());
|
||||||
|
bc.insert_block(&b1, &[]);
|
||||||
|
let blocks = bc.blocks_with_bloom(&bloom, 0, 2);
|
||||||
|
assert_eq!(blocks, vec![1]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,9 +90,9 @@ impl<'a, D> ChainFilter<'a, D> where D: FilterDataSource
|
|||||||
// if we are on the lowest level
|
// if we are on the lowest level
|
||||||
0 => return match offset < to_block {
|
0 => return match offset < to_block {
|
||||||
// take the value if its smaller than to_block
|
// take the value if its smaller than to_block
|
||||||
true => Some(vec![offset]),
|
true if level_bloom.contains(bloom) => Some(vec![offset]),
|
||||||
// return None if it is is equal to to_block
|
// return None if it is is equal to to_block
|
||||||
false => None
|
_ => None
|
||||||
},
|
},
|
||||||
// return None if current level doesnt contain given bloom
|
// return None if current level doesnt contain given bloom
|
||||||
_ if !level_bloom.contains(bloom) => return None,
|
_ if !level_bloom.contains(bloom) => return None,
|
||||||
|
@ -261,6 +261,7 @@ impl Encodable for BlocksBlooms {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Represents location of bloom in database.
|
/// Represents location of bloom in database.
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct BlocksBloomLocation {
|
pub struct BlocksBloomLocation {
|
||||||
/// Unique hash of BlocksBloom
|
/// Unique hash of BlocksBloom
|
||||||
pub hash: H256,
|
pub hash: H256,
|
||||||
|
Loading…
Reference in New Issue
Block a user