Skip to content

Commit

Permalink
#547 add missing file updates from #529
Browse files Browse the repository at this point in the history
  • Loading branch information
andrey-kuprianov committed Sep 4, 2020
1 parent 3dcb316 commit 29807a4
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 49 deletions.
46 changes: 46 additions & 0 deletions light-client/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ use tendermint_rpc as rpc;

use crate::components::clock::Clock;
use crate::components::io::{AtHeight, Io, IoError};
use crate::components::verifier::{ProdVerifier, Verdict, Verifier};
use crate::errors::Error;
use crate::evidence::EvidenceReporter;
use crate::light_client::{LightClient, Options};
use crate::state::State;
use contracts::contract_trait;
use std::collections::HashMap;
use std::time::Duration;
use tendermint::block::Height as HeightStr;
use tendermint::evidence::{Duration as DurationStr, Evidence};

Expand Down Expand Up @@ -148,6 +153,47 @@ impl MockEvidenceReporter {
}
}

pub fn verify_single(
trusted_state: Trusted,
input: LightBlock,
trust_threshold: TrustThreshold,
trusting_period: Duration,
clock_drift: Duration,
now: Time,
) -> Result<LightBlock, Verdict> {
let verifier = ProdVerifier::default();

let trusted_state = LightBlock::new(
trusted_state.signed_header,
trusted_state.next_validators.clone(),
trusted_state.next_validators,
default_peer_id(),
);

let options = Options {
trust_threshold,
trusting_period,
clock_drift,
};

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

match result {
Verdict::Success => Ok(input),
error => Err(error),
}
}

pub fn verify_bisection(
untrusted_height: Height,
light_client: &mut LightClient,
state: &mut State,
) -> Result<Vec<LightBlock>, Error> {
light_client
.verify_to_target(untrusted_height, state)
.map(|_| state.get_trace(untrusted_height))
}

// -----------------------------------------------------------------------------
// Everything below is a temporary workaround for the lack of `provider` field
// in the light blocks serialized in the JSON fixtures.
Expand Down
53 changes: 6 additions & 47 deletions light-client/tests/light_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ use tendermint_light_client::{
components::{
io::{AtHeight, Io},
scheduler,
verifier::{ProdVerifier, Verdict, Verifier},
verifier::ProdVerifier,
},
errors::{Error, ErrorKind},
light_client::{LightClient, Options},
state::State,
store::{memory::MemoryStore, LightStore},
tests::{Trusted, *},
types::{Height, LightBlock, Status, Time, TrustThreshold},
types::{LightBlock, Status, TrustThreshold},
};

use tendermint_testgen::Tester;
Expand All @@ -21,47 +21,6 @@ use tendermint_testgen::Tester;
// https://github.com/informalsystems/conformance-tests
const TEST_FILES_PATH: &str = "./tests/support/";

fn verify_single(
trusted_state: Trusted,
input: LightBlock,
trust_threshold: TrustThreshold,
trusting_period: Duration,
clock_drift: Duration,
now: Time,
) -> Result<LightBlock, Verdict> {
let verifier = ProdVerifier::default();

let trusted_state = LightBlock::new(
trusted_state.signed_header,
trusted_state.next_validators.clone(),
trusted_state.next_validators,
default_peer_id(),
);

let options = Options {
trust_threshold,
trusting_period,
clock_drift,
};

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

match result {
Verdict::Success => Ok(input),
error => Err(error),
}
}

fn verify_bisection(
untrusted_height: Height,
light_client: &mut LightClient,
state: &mut State,
) -> Result<Vec<LightBlock>, Error> {
light_client
.verify_to_target(untrusted_height, state)
.map(|_| state.get_trace(untrusted_height))
}

struct BisectionTestResult {
untrusted_light_block: LightBlock,
new_states: Result<Vec<LightBlock>, Error>,
Expand Down Expand Up @@ -229,17 +188,17 @@ fn bisection_lower_test(tc: TestBisection<AnonLightBlock>) {

#[test]
fn run_single_step_tests() {
let mut tester = Tester::new(TEST_FILES_PATH);
let mut tester = Tester::new("single_step", TEST_FILES_PATH);
tester.add_test("single-step test", single_step_test);
tester.run_foreach_in_dir("single_step");
tester.print_results();
tester.finalize();
}

#[test]
fn run_bisection_tests() {
let mut tester = Tester::new(TEST_FILES_PATH);
let mut tester = Tester::new("bisection", TEST_FILES_PATH);
tester.add_test("bisection test", bisection_test);
tester.add_test("bisection lower test", bisection_lower_test);
tester.run_foreach_in_dir("bisection/single_peer");
tester.print_results();
tester.finalize();
}
4 changes: 2 additions & 2 deletions light-client/tests/supervisor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ fn run_multipeer_test(tc: TestBisection<AnonLightBlock>) {

#[test]
fn run_multipeer_tests() {
let mut tester = Tester::new(TEST_FILES_PATH);
let mut tester = Tester::new("bisection_multi_peer", TEST_FILES_PATH);
tester.add_test("multipeer test", run_multipeer_test);
tester.run_foreach_in_dir("bisection/multi_peer");
tester.print_results();
tester.finalize();
}

0 comments on commit 29807a4

Please sign in to comment.