Skip to content

Commit

Permalink
Adds more verification tests (#475)
Browse files Browse the repository at this point in the history
* fix predicate bug

* fix fmt error

* changes from ismail's comments + remove header time check

* set clock_drift to 1 sec for testing

* remove unnecessary Time type conversion

* more verification tests

* cargo fmt

* update link to test generator

* comment out deprecated test as per Romain's suggestion
  • Loading branch information
Shivani912 committed Jul 29, 2020
1 parent 877c586 commit 667fc8d
Show file tree
Hide file tree
Showing 12 changed files with 5,365 additions and 4,612 deletions.
6 changes: 1 addition & 5 deletions light-client/src/predicates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,7 @@ pub fn verify(
now: Time,
) -> Result<(), VerificationError> {
// Ensure the latest trusted header hasn't expired
vp.is_within_trust_period(
&trusted.signed_header.header,
options.trusting_period,
now,
)?;
vp.is_within_trust_period(&trusted.signed_header.header, options.trusting_period, now)?;

// Ensure the header isn't from a future time
vp.is_header_from_past(&untrusted.signed_header.header, options.clock_drift, now)?;
Expand Down
20 changes: 10 additions & 10 deletions light-client/tests/light_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::convert::TryInto;
use std::fs;
use std::{
path::{Path, PathBuf},
time::{Duration, SystemTime},
time::Duration,
};

use tendermint_light_client::{
Expand All @@ -17,11 +17,11 @@ use tendermint_light_client::{
state::State,
store::{memory::MemoryStore, LightStore},
tests::{Trusted, *},
types::{Height, LightBlock, Status, TrustThreshold},
types::{Height, LightBlock, Status, Time, TrustThreshold},
};

// Link to the commit that generated below JSON test files:
// https://github.com/Shivani912/tendermint/commit/e02f8fd54a278f0192353e54b84a027c8fe31c1e
// Link to JSON test files repo:
// https://github.com/informalsystems/conformance-tests
const TEST_FILES_PATH: &str = "./tests/support/";

fn read_json_fixture(file: impl AsRef<Path>) -> String {
Expand All @@ -34,7 +34,7 @@ fn verify_single(
trust_threshold: TrustThreshold,
trusting_period: Duration,
clock_drift: Duration,
now: SystemTime,
now: Time,
) -> Result<LightBlock, Verdict> {
let verifier = ProdVerifier::default();

Expand All @@ -51,7 +51,7 @@ fn verify_single(
clock_drift,
};

let result = verifier.verify(&input, &trusted_state, &options, now.into());
let result = verifier.verify(&input, &trusted_state, &options, now);

match result {
Verdict::Success => Ok(input),
Expand All @@ -70,13 +70,13 @@ fn run_test_case(tc: TestCase<LightBlock>) {
None => false,
};

// In Go, default is 10 sec.
// For testing, it makes it easier to have smaller clock drift
// Same is done in Go - clock_drift is set to 1 sec for these tests
// Once we switch to the proposer based timestamps, it will probably be a consensus parameter
let clock_drift = Duration::from_secs(10);
let clock_drift = Duration::from_secs(1);

let trusting_period: Duration = tc.initial.trusting_period.into();
let tm_now = tc.initial.now;
let now = tm_now.to_system_time().unwrap();
let now = tc.initial.now;

for (i, input) in tc.input.iter().enumerate() {
println!(" - {}: {}", i, tc.description);
Expand Down
22 changes: 11 additions & 11 deletions tendermint/tests/lite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,17 +211,17 @@ fn single_step_sequential() {
}
}

#[test]
fn single_step_skipping() {
let dirs = [
"single_step/skipping/commit",
"single_step/skipping/header",
"single_step/skipping/validator_set",
];
for dir in &dirs {
run_single_step_tests(dir);
}
}
// #[test]
// fn single_step_skipping() {
// let dirs = [
// "single_step/skipping/commit",
// "single_step/skipping/header",
// "single_step/skipping/validator_set",
// ];
// for dir in &dirs {
// run_single_step_tests(dir);
// }
// }

async fn run_bisection_tests(dir: &str) {
let paths = fs::read_dir(PathBuf::from(TEST_FILES_PATH).join(dir)).unwrap();
Expand Down
Loading

0 comments on commit 667fc8d

Please sign in to comment.