From a8954568b3d399a158eb804b26ff20f0d20d1326 Mon Sep 17 00:00:00 2001 From: Ankit Raj Date: Wed, 24 Oct 2018 14:44:12 +0530 Subject: [PATCH 01/18] updated readme included all the details --- README.md | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 741700576..b0d5d2996 100644 --- a/README.md +++ b/README.md @@ -121,20 +121,25 @@ experimental. As such all cryptography is assumed to be insecure.** This code-base is still very much under-development and does not provide any user-facing functionality. For developers and researchers, there are several -tests and benchmarks which may be of interest. - -To run tests, use: +tests and benchmarks which may be of interest. Few basic setup needed before starting like: + 1. Install [rustup](https://rustup.rs/). It's a toolchain manager for Rust (Linux | macos | Windows) . For installation run the below command in your termainal + ``` + $ curl https://sh.rustup.rs -sSf | sh ``` -$ cargo test --all -``` - -To run benchmarks, use: - -``` -$ cargo bench --all + 2. To configure your current shell run + + ``` + $ source $HOME/.cargo/env ``` + + 3. Use `rustup show` to get the info about the Rust setup. You will see active toolchain is in stable version. + 4. Run `rustc --version` to get the version of rustup. For doing an update use `rustup update` . + 5. Navigate to the working directory. + 6. Run the test by using command `cargo test --all` . By running, it will pass all the required testcases. If you are doing it for first time, then you can grab a coffee meantime. Usually it takes time to build, compile and pass all test cases. If there are no error then, it means everything is working properly and it's time to get hand's dirty. In case, if there is error, then please raise the [issue](https://github.com/sigp/lighthouse/issues). We will help you. + 7. Alternative of abhove step, You can also run benchmarks by using `cargo bench --all` +##### Note: Lighthouse presently runs on Rust `stable`, however, benchmarks currently require the `nightly` version. From 95e89eebfdd9760cd053a2c64ddabc89a66d8e8c Mon Sep 17 00:00:00 2001 From: Ankit Raj Date: Sat, 3 Nov 2018 18:49:27 +0530 Subject: [PATCH 02/18] update Updated Readme --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index b0d5d2996..1aa793b9d 100644 --- a/README.md +++ b/README.md @@ -121,9 +121,9 @@ experimental. As such all cryptography is assumed to be insecure.** This code-base is still very much under-development and does not provide any user-facing functionality. For developers and researchers, there are several -tests and benchmarks which may be of interest. Few basic setup needed before starting like: +tests and benchmarks which may be of interest. Few basic setups needed before starting like: - 1. Install [rustup](https://rustup.rs/). It's a toolchain manager for Rust (Linux | macos | Windows) . For installation run the below command in your termainal + 1. Install [rustup](https://rustup.rs/). It's a toolchain manager for Rust (Linux | macos | Windows). For installation run the below command in your terminal ``` $ curl https://sh.rustup.rs -sSf | sh ``` @@ -133,11 +133,11 @@ tests and benchmarks which may be of interest. Few basic setup needed before sta $ source $HOME/.cargo/env ``` - 3. Use `rustup show` to get the info about the Rust setup. You will see active toolchain is in stable version. - 4. Run `rustc --version` to get the version of rustup. For doing an update use `rustup update` . + 3. Use `rustup show` to get the info about the Rust setup. You will see active toolchain is in the stable version. + 4. Run `rustc --version` to get the version of rustup. For doing an update using` rustup update` . 5. Navigate to the working directory. - 6. Run the test by using command `cargo test --all` . By running, it will pass all the required testcases. If you are doing it for first time, then you can grab a coffee meantime. Usually it takes time to build, compile and pass all test cases. If there are no error then, it means everything is working properly and it's time to get hand's dirty. In case, if there is error, then please raise the [issue](https://github.com/sigp/lighthouse/issues). We will help you. - 7. Alternative of abhove step, You can also run benchmarks by using `cargo bench --all` + 6. Run the test by using command `cargo test --all` . By running, it will pass all the required test cases. If you are doing it for the first time, then you can grab a coffee meantime. Usually, it takes time to build, compile and pass all test cases. If there is no error then, it means everything is working properly and it's time to get hand's dirty. In case, if there is an error, then please raise the [issue](https://github.com/sigp/lighthouse/issues). We will help you. + 7. The alternative of the above step, You can also run benchmarks by using `cargo bench --all` ##### Note: Lighthouse presently runs on Rust `stable`, however, benchmarks currently require the From b48a6109449bb43565d4e06070712e52d0b28014 Mon Sep 17 00:00:00 2001 From: Luke Anderson Date: Fri, 9 Nov 2018 10:32:25 +0530 Subject: [PATCH 03/18] Update README.md Co-Authored-By: aj07 --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1aa793b9d..461977fb5 100644 --- a/README.md +++ b/README.md @@ -121,7 +121,9 @@ experimental. As such all cryptography is assumed to be insecure.** This code-base is still very much under-development and does not provide any user-facing functionality. For developers and researchers, there are several -tests and benchmarks which may be of interest. Few basic setups needed before starting like: +tests and benchmarks which may be of interest. + +A few basic steps are needed to get set up: 1. Install [rustup](https://rustup.rs/). It's a toolchain manager for Rust (Linux | macos | Windows). For installation run the below command in your terminal ``` From 20961c612aecad2e4b00b8016e84422461041a98 Mon Sep 17 00:00:00 2001 From: Grant Wuerker Date: Sun, 11 Nov 2018 13:15:39 -0600 Subject: [PATCH 04/18] pow chain store tests added --- lighthouse/db/Cargo.toml | 1 + lighthouse/db/src/stores/pow_chain_store.rs | 41 ++++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/lighthouse/db/Cargo.toml b/lighthouse/db/Cargo.toml index a2718889c..0d0bf4a2e 100644 --- a/lighthouse/db/Cargo.toml +++ b/lighthouse/db/Cargo.toml @@ -11,3 +11,4 @@ rocksdb = "0.10.1" ssz = { path = "../../beacon_chain/utils/ssz" } ssz_helpers = { path = "../../beacon_chain/utils/ssz_helpers" } types = { path = "../../beacon_chain/types" } +rand = "0.5.5" diff --git a/lighthouse/db/src/stores/pow_chain_store.rs b/lighthouse/db/src/stores/pow_chain_store.rs index f1f050a39..f2f0f5df6 100644 --- a/lighthouse/db/src/stores/pow_chain_store.rs +++ b/lighthouse/db/src/stores/pow_chain_store.rs @@ -4,6 +4,7 @@ use super::{ DBError, }; use super::POW_CHAIN_DB_COLUMN as DB_COLUMN; +extern crate rand; pub struct PoWChainStore where T: ClientDB @@ -31,4 +32,42 @@ impl PoWChainStore { } } -// TODO: add tests once a memory-db is implemented +#[cfg(test)] +mod tests { + use super::*; + use super::super::super::MemoryDB; + + #[test] + fn test_put_block_hash() { + let db = Arc::new(MemoryDB::open()); + let store = PoWChainStore::new(db.clone()); + + let hash: &[u8] = &[rand::random()]; + store.put_block_hash(hash); + + assert!(db.exists(DB_COLUMN, hash).unwrap()); + } + + #[test] + fn test_block_hash_exists() { + let db = Arc::new(MemoryDB::open()); + let store = PoWChainStore::new(db.clone()); + + let hash: &[u8] = &[rand::random()]; + db.put(DB_COLUMN, hash, &[0]); + + assert!(store.block_hash_exists(hash).unwrap()); + } + + #[test] + fn test_block_hash_does_not_exist() { + let db = Arc::new(MemoryDB::open()); + let store = PoWChainStore::new(db.clone()); + + let hash: &[u8] = &[rand::random()]; + let other_hash: &[u8] = &[rand::random()]; + db.put(DB_COLUMN, hash, &[0]); + + assert!(!store.block_hash_exists(other_hash).unwrap()); + } +} From 66ca29909282a3326bb6faeda4d5e706fd1f81b2 Mon Sep 17 00:00:00 2001 From: Grant Wuerker Date: Sun, 11 Nov 2018 13:17:42 -0600 Subject: [PATCH 05/18] rand import moved --- lighthouse/db/src/stores/pow_chain_store.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lighthouse/db/src/stores/pow_chain_store.rs b/lighthouse/db/src/stores/pow_chain_store.rs index f2f0f5df6..fab197288 100644 --- a/lighthouse/db/src/stores/pow_chain_store.rs +++ b/lighthouse/db/src/stores/pow_chain_store.rs @@ -4,7 +4,6 @@ use super::{ DBError, }; use super::POW_CHAIN_DB_COLUMN as DB_COLUMN; -extern crate rand; pub struct PoWChainStore where T: ClientDB @@ -34,6 +33,8 @@ impl PoWChainStore { #[cfg(test)] mod tests { + extern crate rand; + use super::*; use super::super::super::MemoryDB; From bde0612e1d3a551d66cd37d6c2325e814d293018 Mon Sep 17 00:00:00 2001 From: Grant Wuerker Date: Sat, 17 Nov 2018 19:06:24 -0600 Subject: [PATCH 06/18] validator store cleanup --- lighthouse/db/src/stores/validator_store.rs | 52 +++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/lighthouse/db/src/stores/validator_store.rs b/lighthouse/db/src/stores/validator_store.rs index 576fb67db..1970cf4fd 100644 --- a/lighthouse/db/src/stores/validator_store.rs +++ b/lighthouse/db/src/stores/validator_store.rs @@ -82,6 +82,58 @@ mod tests { use super::super::bls::Keypair; use super::*; + #[test] + fn test_put_public_key_by_index() { + let db = Arc::new(MemoryDB::open()); + let store = ValidatorStore::new(db.clone()); + + let index = 3; + let public_key = Keypair::random().pk; + + store.put_public_key_by_index(index, &public_key).unwrap(); + let public_key_at_index = db.get( + DB_COLUMN, + &store.get_db_key_for_index(&KeyPrefixes::PublicKey, index)[..] + ).unwrap().unwrap(); + + assert_eq!(public_key_at_index, public_key.as_bytes()); + } + + #[test] + fn test_get_public_key_by_index() { + let db = Arc::new(MemoryDB::open()); + let store = ValidatorStore::new(db.clone()); + + let index = 4; + let public_key = Keypair::random().pk; + + db.put( + DB_COLUMN, + &store.get_db_key_for_index(&KeyPrefixes::PublicKey, index)[..], + &public_key.as_bytes()[..] + ).unwrap(); + + let public_key_at_index = store.get_public_key_by_index(index).unwrap().unwrap(); + assert_eq!(public_key_at_index, public_key); + } + + #[test] + fn test_get_public_key_by_invalid_index() { + let db = Arc::new(MemoryDB::open()); + let store = ValidatorStore::new(db.clone()); + + let public_key = Keypair::random().pk; + + db.put( + DB_COLUMN, + &store.get_db_key_for_index(&KeyPrefixes::PublicKey, 3)[..], + &public_key.as_bytes()[..] + ).unwrap(); + + let public_key_at_index = store.get_public_key_by_index(4).unwrap(); + assert_eq!(public_key_at_index, None); + } + #[test] fn test_validator_store_put_get() { let db = Arc::new(MemoryDB::open()); From 005efc2e7a6411c6a60a763a18b669d16254bff4 Mon Sep 17 00:00:00 2001 From: Grant Wuerker Date: Sun, 18 Nov 2018 11:00:05 -0600 Subject: [PATCH 07/18] beacon block tests --- .../db/src/stores/beacon_block_store.rs | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/lighthouse/db/src/stores/beacon_block_store.rs b/lighthouse/db/src/stores/beacon_block_store.rs index 4ea2882be..a60dc435e 100644 --- a/lighthouse/db/src/stores/beacon_block_store.rs +++ b/lighthouse/db/src/stores/beacon_block_store.rs @@ -96,6 +96,70 @@ mod tests { use std::sync::Arc; use std::thread; + #[test] + fn test_put_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(); + + store.put_serialized_block(hash, ssz); + assert_eq!(db.get(DB_COLUMN, hash).unwrap().unwrap(), ssz); + } + + #[test] + fn test_get_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(); + + db.put(DB_COLUMN, hash, ssz); + assert_eq!(store.get_serialized_block(hash).unwrap().unwrap(), ssz); + } + + #[test] + fn test_block_exists() { + 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(); + + db.put(DB_COLUMN, hash, ssz); + assert!(store.block_exists(hash).unwrap()); + } + + #[test] + fn test_block_doesnt_exist() { + 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); + assert!(!store.block_exists(other_hash).unwrap()); + } + + #[test] + fn test_delete_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(); + + db.put(DB_COLUMN, hash, ssz); + assert!(db.exists(DB_COLUMN, hash).unwrap()); + + store.delete_block(hash); + assert!(!db.exists(DB_COLUMN, hash).unwrap()); + } + #[test] fn test_block_store_on_memory_db() { let db = Arc::new(MemoryDB::open()); From 9148c20630b136e4cc7a046cd527c815a1902e07 Mon Sep 17 00:00:00 2001 From: Grant Wuerker Date: Sun, 18 Nov 2018 16:31:22 -0600 Subject: [PATCH 08/18] fixed warnings --- lighthouse/db/src/stores/beacon_block_store.rs | 12 ++++++------ lighthouse/db/src/stores/pow_chain_store.rs | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lighthouse/db/src/stores/beacon_block_store.rs b/lighthouse/db/src/stores/beacon_block_store.rs index a60dc435e..615c8fbe7 100644 --- a/lighthouse/db/src/stores/beacon_block_store.rs +++ b/lighthouse/db/src/stores/beacon_block_store.rs @@ -104,7 +104,7 @@ mod tests { let ssz = "some bytes".as_bytes(); let hash = &Hash256::from("some hash".as_bytes()).to_vec(); - store.put_serialized_block(hash, ssz); + store.put_serialized_block(hash, ssz).unwrap(); assert_eq!(db.get(DB_COLUMN, hash).unwrap().unwrap(), ssz); } @@ -116,7 +116,7 @@ mod tests { let ssz = "some bytes".as_bytes(); let hash = &Hash256::from("some hash".as_bytes()).to_vec(); - db.put(DB_COLUMN, hash, ssz); + db.put(DB_COLUMN, hash, ssz).unwrap(); assert_eq!(store.get_serialized_block(hash).unwrap().unwrap(), ssz); } @@ -128,7 +128,7 @@ mod tests { let ssz = "some bytes".as_bytes(); let hash = &Hash256::from("some hash".as_bytes()).to_vec(); - db.put(DB_COLUMN, hash, ssz); + db.put(DB_COLUMN, hash, ssz).unwrap(); assert!(store.block_exists(hash).unwrap()); } @@ -141,7 +141,7 @@ mod tests { 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); + db.put(DB_COLUMN, hash, ssz).unwrap(); assert!(!store.block_exists(other_hash).unwrap()); } @@ -153,10 +153,10 @@ mod tests { let ssz = "some bytes".as_bytes(); let hash = &Hash256::from("some hash".as_bytes()).to_vec(); - db.put(DB_COLUMN, hash, ssz); + db.put(DB_COLUMN, hash, ssz).unwrap(); assert!(db.exists(DB_COLUMN, hash).unwrap()); - store.delete_block(hash); + store.delete_block(hash).unwrap(); assert!(!db.exists(DB_COLUMN, hash).unwrap()); } diff --git a/lighthouse/db/src/stores/pow_chain_store.rs b/lighthouse/db/src/stores/pow_chain_store.rs index 382667ea0..493df47f8 100644 --- a/lighthouse/db/src/stores/pow_chain_store.rs +++ b/lighthouse/db/src/stores/pow_chain_store.rs @@ -26,7 +26,7 @@ impl PoWChainStore { #[cfg(test)] mod tests { extern crate rand; - + use super::*; use super::super::super::MemoryDB; @@ -36,7 +36,7 @@ mod tests { let store = PoWChainStore::new(db.clone()); let hash: &[u8] = &[rand::random()]; - store.put_block_hash(hash); + store.put_block_hash(hash).unwrap(); assert!(db.exists(DB_COLUMN, hash).unwrap()); } @@ -47,7 +47,7 @@ mod tests { let store = PoWChainStore::new(db.clone()); let hash: &[u8] = &[rand::random()]; - db.put(DB_COLUMN, hash, &[0]); + db.put(DB_COLUMN, hash, &[0]).unwrap(); assert!(store.block_hash_exists(hash).unwrap()); } @@ -59,7 +59,7 @@ mod tests { let hash: &[u8] = &[rand::random()]; let other_hash: &[u8] = &[rand::random()]; - db.put(DB_COLUMN, hash, &[0]); + db.put(DB_COLUMN, hash, &[0]).unwrap(); assert!(!store.block_hash_exists(other_hash).unwrap()); } From 325e1b3f0a3e878aa3dfcc0e20f31c134fe26709 Mon Sep 17 00:00:00 2001 From: Grant Wuerker Date: Sun, 18 Nov 2018 16:38:15 -0600 Subject: [PATCH 09/18] different hashes in pow store --- lighthouse/db/src/stores/pow_chain_store.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lighthouse/db/src/stores/pow_chain_store.rs b/lighthouse/db/src/stores/pow_chain_store.rs index 493df47f8..aa2b267f7 100644 --- a/lighthouse/db/src/stores/pow_chain_store.rs +++ b/lighthouse/db/src/stores/pow_chain_store.rs @@ -25,17 +25,19 @@ impl PoWChainStore { #[cfg(test)] mod tests { - extern crate rand; - + extern crate types; + use super::*; use super::super::super::MemoryDB; + use self::types::Hash256; + #[test] fn test_put_block_hash() { let db = Arc::new(MemoryDB::open()); let store = PoWChainStore::new(db.clone()); - let hash: &[u8] = &[rand::random()]; + let hash = &Hash256::from("some hash".as_bytes()).to_vec(); store.put_block_hash(hash).unwrap(); assert!(db.exists(DB_COLUMN, hash).unwrap()); @@ -46,7 +48,7 @@ mod tests { let db = Arc::new(MemoryDB::open()); let store = PoWChainStore::new(db.clone()); - let hash: &[u8] = &[rand::random()]; + let hash = &Hash256::from("some hash".as_bytes()).to_vec(); db.put(DB_COLUMN, hash, &[0]).unwrap(); assert!(store.block_hash_exists(hash).unwrap()); @@ -57,8 +59,8 @@ mod tests { let db = Arc::new(MemoryDB::open()); let store = PoWChainStore::new(db.clone()); - let hash: &[u8] = &[rand::random()]; - let other_hash: &[u8] = &[rand::random()]; + 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, &[0]).unwrap(); assert!(!store.block_hash_exists(other_hash).unwrap()); From 74ad689c21b59da89e44a2eab199f5f8487b577e Mon Sep 17 00:00:00 2001 From: Grant Wuerker Date: Sun, 18 Nov 2018 16:39:55 -0600 Subject: [PATCH 10/18] removed cargo dep --- lighthouse/db/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/lighthouse/db/Cargo.toml b/lighthouse/db/Cargo.toml index 0d0bf4a2e..a2718889c 100644 --- a/lighthouse/db/Cargo.toml +++ b/lighthouse/db/Cargo.toml @@ -11,4 +11,3 @@ rocksdb = "0.10.1" ssz = { path = "../../beacon_chain/utils/ssz" } ssz_helpers = { path = "../../beacon_chain/utils/ssz_helpers" } types = { path = "../../beacon_chain/types" } -rand = "0.5.5" From 1c5d04d727919f7b8ea633360f8f10225dd801c6 Mon Sep 17 00:00:00 2001 From: Grant Wuerker Date: Tue, 20 Nov 2018 19:49:38 -0600 Subject: [PATCH 11/18] a few more tests --- .../db/src/stores/beacon_block_store.rs | 38 +++++++++++++++++++ lighthouse/db/src/stores/validator_store.rs | 30 +++++++-------- 2 files changed, 53 insertions(+), 15 deletions(-) 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) - ); - } } From 1bd60062d96b0bf97c48318a6c263585a1c7826e Mon Sep 17 00:00:00 2001 From: Grant Wuerker Date: Tue, 20 Nov 2018 19:51:43 -0600 Subject: [PATCH 12/18] renamed a couple tests --- lighthouse/db/src/stores/beacon_block_store.rs | 4 ++-- lighthouse/db/src/stores/validator_store.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lighthouse/db/src/stores/beacon_block_store.rs b/lighthouse/db/src/stores/beacon_block_store.rs index 21cd2abc8..54c8b7f9c 100644 --- a/lighthouse/db/src/stores/beacon_block_store.rs +++ b/lighthouse/db/src/stores/beacon_block_store.rs @@ -121,7 +121,7 @@ mod tests { } #[test] - fn test_get_none_serialized_block() { + fn test_get_unknown_serialized_block() { let db = Arc::new(MemoryDB::open()); let store = BeaconBlockStore::new(db.clone()); @@ -146,7 +146,7 @@ mod tests { } #[test] - fn test_block_doesnt_exist() { + fn test_block_does_not_exist() { let db = Arc::new(MemoryDB::open()); let store = BeaconBlockStore::new(db.clone()); diff --git a/lighthouse/db/src/stores/validator_store.rs b/lighthouse/db/src/stores/validator_store.rs index a802a0d0e..6e5c960ba 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()); @@ -118,7 +118,7 @@ mod tests { } #[test] - fn test_get_public_key_by_invalid_index() { + fn test_get_public_key_by_unknown_index() { let db = Arc::new(MemoryDB::open()); let store = ValidatorStore::new(db.clone()); From e5c793a01a21ebd05a0e27b8c9cf2f37f1a86286 Mon Sep 17 00:00:00 2001 From: Luke Anderson Date: Sun, 25 Nov 2018 16:30:48 +0530 Subject: [PATCH 13/18] Update README.md Co-Authored-By: aj07 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 461977fb5..bf584b006 100644 --- a/README.md +++ b/README.md @@ -129,7 +129,7 @@ A few basic steps are needed to get set up: ``` $ curl https://sh.rustup.rs -sSf | sh ``` - 2. To configure your current shell run + 2. To configure your current shell run: ``` $ source $HOME/.cargo/env From 3d0a56a02b69873f77e2b5ffd918f97b3b4621b9 Mon Sep 17 00:00:00 2001 From: Luke Anderson Date: Sun, 25 Nov 2018 16:31:07 +0530 Subject: [PATCH 14/18] Update README.md Done Co-Authored-By: aj07 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bf584b006..1070ad365 100644 --- a/README.md +++ b/README.md @@ -135,7 +135,7 @@ A few basic steps are needed to get set up: $ source $HOME/.cargo/env ``` - 3. Use `rustup show` to get the info about the Rust setup. You will see active toolchain is in the stable version. + 3. Use the command `rustup show` to get information about the Rust installation. You should see that the active toolchain is the stable version. 4. Run `rustc --version` to get the version of rustup. For doing an update using` rustup update` . 5. Navigate to the working directory. 6. Run the test by using command `cargo test --all` . By running, it will pass all the required test cases. If you are doing it for the first time, then you can grab a coffee meantime. Usually, it takes time to build, compile and pass all test cases. If there is no error then, it means everything is working properly and it's time to get hand's dirty. In case, if there is an error, then please raise the [issue](https://github.com/sigp/lighthouse/issues). We will help you. From 546b341cdf41e5319e4db5e21e93f4d42471e2e8 Mon Sep 17 00:00:00 2001 From: Luke Anderson Date: Sun, 25 Nov 2018 16:31:22 +0530 Subject: [PATCH 15/18] Update README.md Done Co-Authored-By: aj07 --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1070ad365..15fe3cd17 100644 --- a/README.md +++ b/README.md @@ -136,7 +136,8 @@ A few basic steps are needed to get set up: ``` 3. Use the command `rustup show` to get information about the Rust installation. You should see that the active toolchain is the stable version. - 4. Run `rustc --version` to get the version of rustup. For doing an update using` rustup update` . + 4. Run `rustc --version` to check the installation and version of rust. + - Updates can be performed using` rustup update` . 5. Navigate to the working directory. 6. Run the test by using command `cargo test --all` . By running, it will pass all the required test cases. If you are doing it for the first time, then you can grab a coffee meantime. Usually, it takes time to build, compile and pass all test cases. If there is no error then, it means everything is working properly and it's time to get hand's dirty. In case, if there is an error, then please raise the [issue](https://github.com/sigp/lighthouse/issues). We will help you. 7. The alternative of the above step, You can also run benchmarks by using `cargo bench --all` From 763badc3dc02c0a133ab880c619b5dcb5af90940 Mon Sep 17 00:00:00 2001 From: Luke Anderson Date: Sun, 25 Nov 2018 16:31:38 +0530 Subject: [PATCH 16/18] Update README.md Done Co-Authored-By: aj07 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 15fe3cd17..c02caef7c 100644 --- a/README.md +++ b/README.md @@ -140,7 +140,7 @@ A few basic steps are needed to get set up: - Updates can be performed using` rustup update` . 5. Navigate to the working directory. 6. Run the test by using command `cargo test --all` . By running, it will pass all the required test cases. If you are doing it for the first time, then you can grab a coffee meantime. Usually, it takes time to build, compile and pass all test cases. If there is no error then, it means everything is working properly and it's time to get hand's dirty. In case, if there is an error, then please raise the [issue](https://github.com/sigp/lighthouse/issues). We will help you. - 7. The alternative of the above step, You can also run benchmarks by using `cargo bench --all` + 7. As an alternative to, or instead of the above step, you may also run benchmarks by using the command `cargo bench --all` ##### Note: Lighthouse presently runs on Rust `stable`, however, benchmarks currently require the From f64aa9e19253b7f22e56fd37fc0a7a0325cb3664 Mon Sep 17 00:00:00 2001 From: Grant Wuerker Date: Sun, 2 Dec 2018 19:21:17 -0600 Subject: [PATCH 17/18] more validator tests --- .../db/src/stores/beacon_block_store.rs | 2 +- lighthouse/db/src/stores/validator_store.rs | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lighthouse/db/src/stores/beacon_block_store.rs b/lighthouse/db/src/stores/beacon_block_store.rs index 54c8b7f9c..84cea2d0d 100644 --- a/lighthouse/db/src/stores/beacon_block_store.rs +++ b/lighthouse/db/src/stores/beacon_block_store.rs @@ -273,7 +273,7 @@ mod tests { let mut s = SszStream::new(); s.append(&block); let ssz = s.drain(); - bs.put_serialized_block(&hashes[i].to_vec(), &ssz).unwrap(); + db.put(DB_COLUMN, &hashes[i].to_vec(), &ssz).unwrap(); } let tuple = bs.block_at_slot(&hashes[4], 5).unwrap().unwrap(); diff --git a/lighthouse/db/src/stores/validator_store.rs b/lighthouse/db/src/stores/validator_store.rs index 6e5c960ba..518d92608 100644 --- a/lighthouse/db/src/stores/validator_store.rs +++ b/lighthouse/db/src/stores/validator_store.rs @@ -82,6 +82,25 @@ mod tests { use super::super::bls::Keypair; use super::*; + #[test] + fn test_prefix_bytes() { + let db = Arc::new(MemoryDB::open()); + let store = ValidatorStore::new(db.clone()); + + assert_eq!(store.prefix_bytes(&KeyPrefixes::PublicKey), b"pubkey".to_vec()); + } + + #[test] + fn test_get_db_key_for_index() { + let db = Arc::new(MemoryDB::open()); + let store = ValidatorStore::new(db.clone()); + + let mut buf = BytesMut::with_capacity(6 + 8); + buf.put(b"pubkey".to_vec()); + buf.put_u64_be(42); + assert_eq!(store.get_db_key_for_index(&KeyPrefixes::PublicKey, 42), buf.take().to_vec()) + } + #[test] fn test_put_public_key_by_index() { let db = Arc::new(MemoryDB::open()); From 050364cf9ad4a1eca92f54784bd54a4ed1de8e6f Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Thu, 6 Dec 2018 10:05:03 +1100 Subject: [PATCH 18/18] Add `--all` scripts to travis.yml --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index a9869e66c..3337de420 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,7 @@ language: rust +script: + - cargo build --verbose --all + - cargo test --verbose --all rust: - stable - beta