diff --git a/lighthouse/db/src/stores/beacon_block_store.rs b/lighthouse/db/src/stores/beacon_block_store.rs index 615c8fbe7..21cd2abc8 100644 --- a/lighthouse/db/src/stores/beacon_block_store.rs +++ b/lighthouse/db/src/stores/beacon_block_store.rs @@ -120,6 +120,19 @@ mod tests { assert_eq!(store.get_serialized_block(hash).unwrap().unwrap(), ssz); } + #[test] + fn test_get_none_serialized_block() { + let db = Arc::new(MemoryDB::open()); + let store = BeaconBlockStore::new(db.clone()); + + let ssz = "some bytes".as_bytes(); + let hash = &Hash256::from("some hash".as_bytes()).to_vec(); + let other_hash = &Hash256::from("another hash".as_bytes()).to_vec(); + + db.put(DB_COLUMN, other_hash, ssz).unwrap(); + assert_eq!(store.get_serialized_block(hash).unwrap(), None); + } + #[test] fn test_block_exists() { let db = Arc::new(MemoryDB::open()); @@ -160,6 +173,31 @@ mod tests { assert!(!db.exists(DB_COLUMN, hash).unwrap()); } + #[test] + fn test_invalid_block_at_slot() { + let db = Arc::new(MemoryDB::open()); + let store = BeaconBlockStore::new(db.clone()); + + let ssz = "definitly not a valid block".as_bytes(); + let hash = &Hash256::from("some hash".as_bytes()).to_vec(); + + db.put(DB_COLUMN, hash, ssz).unwrap(); + assert_eq!(store.block_at_slot(hash, 42), Err(BeaconBlockAtSlotError::InvalidBeaconBlock)); + } + + #[test] + fn test_unknown_block_at_slot() { + let db = Arc::new(MemoryDB::open()); + let store = BeaconBlockStore::new(db.clone()); + + let ssz = "some bytes".as_bytes(); + let hash = &Hash256::from("some hash".as_bytes()).to_vec(); + let other_hash = &Hash256::from("another hash".as_bytes()).to_vec(); + + db.put(DB_COLUMN, hash, ssz).unwrap(); + assert_eq!(store.block_at_slot(other_hash, 42), Err(BeaconBlockAtSlotError::UnknownBeaconBlock)); + } + #[test] fn test_block_store_on_memory_db() { let db = Arc::new(MemoryDB::open()); diff --git a/lighthouse/db/src/stores/validator_store.rs b/lighthouse/db/src/stores/validator_store.rs index 1970cf4fd..a802a0d0e 100644 --- a/lighthouse/db/src/stores/validator_store.rs +++ b/lighthouse/db/src/stores/validator_store.rs @@ -98,7 +98,7 @@ mod tests { assert_eq!(public_key_at_index, public_key.as_bytes()); } - + #[test] fn test_get_public_key_by_index() { let db = Arc::new(MemoryDB::open()); @@ -134,6 +134,20 @@ mod tests { assert_eq!(public_key_at_index, None); } + #[test] + fn test_get_invalid_public_key() { + let db = Arc::new(MemoryDB::open()); + let store = ValidatorStore::new(db.clone()); + + let key = store.get_db_key_for_index(&KeyPrefixes::PublicKey, 42); + db.put(DB_COLUMN, &key[..], "cats".as_bytes()).unwrap(); + + assert_eq!( + store.get_public_key_by_index(42), + Err(ValidatorStoreError::DecodeError) + ); + } + #[test] fn test_validator_store_put_get() { let db = Arc::new(MemoryDB::open()); @@ -169,18 +183,4 @@ mod tests { .is_none() ); } - - #[test] - fn test_validator_store_bad_key() { - let db = Arc::new(MemoryDB::open()); - let store = ValidatorStore::new(db.clone()); - - let key = store.get_db_key_for_index(&KeyPrefixes::PublicKey, 42); - db.put(DB_COLUMN, &key[..], "cats".as_bytes()).unwrap(); - - assert_eq!( - store.get_public_key_by_index(42), - Err(ValidatorStoreError::DecodeError) - ); - } }