-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
52 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,18 @@ | ||
use glob::glob; | ||
|
||
use malachite_itf::consensus::State; | ||
use rstest::rstest; | ||
use std::path::PathBuf; | ||
|
||
#[rstest] | ||
fn test_itf(#[files("tests/fixtures/consensus/*.json")] json_fixture: PathBuf) { | ||
println!("Parsing {json_fixture:?}"); | ||
#[test] | ||
fn test_itf() { | ||
for json_fixture in glob("tests/fixtures/consensus/*.json") | ||
.expect("Failed to read glob pattern") | ||
.flatten() | ||
{ | ||
println!("Parsing {json_fixture:?}"); | ||
|
||
let json = std::fs::read_to_string(&json_fixture).unwrap(); | ||
let state = itf::trace_from_str::<State>(&json).unwrap(); | ||
let json = std::fs::read_to_string(&json_fixture).unwrap(); | ||
let state = itf::trace_from_str::<State>(&json).unwrap(); | ||
|
||
dbg!(state); | ||
dbg!(state); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,44 @@ | ||
use std::path::PathBuf; | ||
|
||
use malachite_itf::votekeeper::State; | ||
|
||
use rstest::rstest; | ||
|
||
#[path = "votekeeper/runner.rs"] | ||
pub mod runner; | ||
#[path = "votekeeper/utils.rs"] | ||
pub mod utils; | ||
|
||
use runner::{vote_keeper_runner, VoteKeeperRunner}; | ||
use glob::glob; | ||
use rand::rngs::StdRng; | ||
use rand::SeedableRng; | ||
|
||
use malachite_itf::votekeeper::State; | ||
use malachite_test::{Address, PrivateKey}; | ||
|
||
use runner::VoteKeeperRunner; | ||
use utils::ADDRESSES; | ||
|
||
const RANDOM_SEED: u64 = 0x42; | ||
|
||
#[test] | ||
fn test_itf() { | ||
for json_fixture in glob("tests/fixtures/votekeeper/*.itf.json") | ||
.expect("Failed to read glob pattern") | ||
.flatten() | ||
{ | ||
println!("Parsing {json_fixture:?}"); | ||
|
||
let json = std::fs::read_to_string(&json_fixture).unwrap(); | ||
let trace = itf::trace_from_str::<State>(&json).unwrap(); | ||
|
||
let mut rng = StdRng::seed_from_u64(RANDOM_SEED); | ||
|
||
#[rstest] | ||
fn test_itf( | ||
#[files("tests/fixtures/votekeeper/*.itf.json")] json_fixture: PathBuf, | ||
vote_keeper_runner: VoteKeeperRunner, | ||
) { | ||
println!("Parsing {json_fixture:?}"); | ||
// build mapping from model addresses to real addresses | ||
let vote_keeper_runner = VoteKeeperRunner { | ||
address_map: ADDRESSES | ||
.iter() | ||
.map(|&name| { | ||
let pk = PrivateKey::generate(&mut rng).public_key(); | ||
(name.into(), Address::from_public_key(&pk)) | ||
}) | ||
.collect(), | ||
}; | ||
|
||
let json = std::fs::read_to_string(&json_fixture).unwrap(); | ||
let trace = itf::trace_from_str::<State>(&json).unwrap(); | ||
trace.run_on(vote_keeper_runner).unwrap(); | ||
trace.run_on(vote_keeper_runner).unwrap(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters