Value lifetime is returned from blockchain cache (#3403)

* value range in blockchain cache

* revert me (testing for spurious failure)

* Revert "revert me (testing for spurious failure)"

This reverts commit 21a4a3cf5ee14e003541b779c41351e4f5e1122a.
This commit is contained in:
Svyatoslav Nikolsky
2019-08-19 14:44:16 +03:00
committed by Gavin Wood
parent 68fd94028f
commit 6fb721e861
6 changed files with 50 additions and 20 deletions
+13 -5
View File
@@ -562,10 +562,10 @@ pub(crate) mod tests {
header
}
pub fn insert_block<F: Fn() -> Header>(
pub fn insert_block<F: FnMut() -> Header>(
db: &LightStorage<Block>,
cache: HashMap<well_known_cache_keys::Id, Vec<u8>>,
header: F,
mut header: F,
) -> Hash {
let header = header();
let hash = header.hash();
@@ -850,7 +850,7 @@ pub(crate) mod tests {
fn get_authorities(cache: &dyn BlockchainCache<Block>, at: BlockId<Block>) -> Option<Vec<AuthorityId>> {
cache.get_at(&well_known_cache_keys::AUTHORITIES, &at)
.and_then(|val| Decode::decode(&mut &val[..]).ok())
.and_then(|(_, _, val)| Decode::decode(&mut &val[..]).ok())
}
let auth1 = || AuthorityId::from_raw([1u8; 32]);
@@ -1036,7 +1036,12 @@ pub(crate) mod tests {
assert_eq!(db.cache().get_at(b"test", &BlockId::Number(0)), None);
// insert genesis block (no value for cache is provided)
insert_block(&db, HashMap::new(), || default_header(&Default::default(), 0));
let mut genesis_hash = None;
insert_block(&db, HashMap::new(), || {
let header = default_header(&Default::default(), 0);
genesis_hash = Some(header.hash());
header
});
// after genesis is inserted => None
assert_eq!(db.cache().get_at(b"test", &BlockId::Number(0)), None);
@@ -1045,6 +1050,9 @@ pub(crate) mod tests {
db.cache().initialize(b"test", vec![42]).unwrap();
// after genesis is inserted + cache is initialized => Some
assert_eq!(db.cache().get_at(b"test", &BlockId::Number(0)), Some(vec![42]));
assert_eq!(
db.cache().get_at(b"test", &BlockId::Number(0)),
Some(((0, genesis_hash.unwrap()), None, vec![42])),
);
}
}