Skip to content

Commit

Permalink
Added single-step-skipping JSON tests (#143)
Browse files Browse the repository at this point in the history
* Added single-step-skipping JSON tests

* Add a check for the parts.hash in commit.validate impl

* All tests passing

* cargo fmt and delete comment

* clean up

Co-authored-by: Ismail Khoffi <Ismail.Khoffi@gmail.com>
  • Loading branch information
Shivani912 and liamsi committed Feb 6, 2020
1 parent 0ca3e8c commit 994b457
Show file tree
Hide file tree
Showing 13 changed files with 19,618 additions and 18,176 deletions.
4 changes: 4 additions & 0 deletions tendermint/src/lite_impl/signed_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ impl lite::Commit for block::signed_header::SignedHeader {
if self.commit.precommits.len() != vals.validators().len() {
return Err(lite::Error::InvalidCommitSignatures);
}
// TODO: compare to the go code for more implementation related checks and clarify if this:
// https://github.com/interchainio/tendermint-rs/pull/143/commits/0a30022fa47e909e6c7b20417dd178c8a3b84838#r374958528
// should go here or somewhere else

Ok(())
}
}
Expand Down
29 changes: 23 additions & 6 deletions tendermint/tests/lite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ struct Duration(u64);

#[derive(Deserialize, Clone, Debug)]
struct TestCases {
batch_name: String,
test_cases: Vec<TestCase>,
}

#[derive(Deserialize, Clone, Debug)]
struct TestCase {
test_name: String,
description: String,
initial: Initial,
input: Vec<LiteBlock>,
Expand Down Expand Up @@ -44,19 +44,36 @@ fn read_json_fixture(name: &str) -> String {

#[test]
fn val_set_tests_verify() {
let cases: TestCases = serde_json::from_str(&read_json_fixture("val_set_tests")).unwrap();
let cases: TestCases =
serde_json::from_str(&read_json_fixture("single_step_sequential/val_set_tests")).unwrap();
run_test_cases(cases);
}

#[test]
fn commit_tests_verify() {
let cases: TestCases = serde_json::from_str(&read_json_fixture("commit_tests")).unwrap();
let cases: TestCases =
serde_json::from_str(&read_json_fixture("single_step_sequential/commit_tests")).unwrap();
run_test_cases(cases);
}

#[test]
fn header_tests_verify() {
let cases: TestCases = serde_json::from_str(&read_json_fixture("header_tests")).unwrap();
let cases: TestCases =
serde_json::from_str(&read_json_fixture("single_step_sequential/header_tests")).unwrap();
run_test_cases(cases);
}

#[test]
fn single_skip_val_set_tests_verify() {
let cases: TestCases =
serde_json::from_str(&read_json_fixture("single_step_skipping/val_set_tests")).unwrap();
run_test_cases(cases);
}

#[test]
fn single_skip_commit_tests_verify() {
let cases: TestCases =
serde_json::from_str(&read_json_fixture("single_step_skipping/commit_tests")).unwrap();
run_test_cases(cases);
}

Expand All @@ -76,8 +93,8 @@ fn run_test_cases(cases: TestCases) {
let tm_now = tc.initial.now;
let now = tm_now.to_system_time().unwrap();

for (_, input) in tc.input.iter().enumerate() {
println!("{}", tc.description);
for (i, input) in tc.input.iter().enumerate() {
println!("i: {}, {}", i, tc.description);
let untrusted_signed_header = &input.signed_header;
let untrusted_vals = &input.validator_set;
let untrusted_next_vals = &input.next_validator_set;
Expand Down
Loading

0 comments on commit 994b457

Please sign in to comment.