2021-06-21 05:46:36 +00:00
|
|
|
use lazy_static::lazy_static;
|
2020-11-24 07:21:14 +00:00
|
|
|
use slashing_protection::interchange_test::MultiTestCase;
|
2020-10-02 01:42:27 +00:00
|
|
|
use std::fs::File;
|
|
|
|
use std::path::PathBuf;
|
|
|
|
|
2021-06-21 05:46:36 +00:00
|
|
|
lazy_static! {
|
|
|
|
pub static ref TEST_ROOT_DIR: PathBuf = test_root_dir();
|
|
|
|
}
|
|
|
|
|
2020-12-03 22:07:12 +00:00
|
|
|
fn download_tests() {
|
|
|
|
let make_output = std::process::Command::new("make")
|
|
|
|
.current_dir(std::env::var("CARGO_MANIFEST_DIR").unwrap())
|
|
|
|
.output()
|
|
|
|
.expect("need `make` to succeed to download and untar slashing protection tests");
|
|
|
|
if !make_output.status.success() {
|
|
|
|
eprintln!("{}", String::from_utf8_lossy(&make_output.stderr));
|
|
|
|
panic!("Running `make` for slashing protection tests failed, see above");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-02 01:42:27 +00:00
|
|
|
fn test_root_dir() -> PathBuf {
|
2020-12-03 22:07:12 +00:00
|
|
|
download_tests();
|
2020-10-02 01:42:27 +00:00
|
|
|
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
|
|
|
.join("interchange-tests")
|
|
|
|
.join("tests")
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn generated() {
|
2021-06-21 05:46:36 +00:00
|
|
|
for entry in TEST_ROOT_DIR
|
|
|
|
.join("generated")
|
|
|
|
.read_dir()
|
|
|
|
.unwrap()
|
|
|
|
.map(Result::unwrap)
|
|
|
|
{
|
|
|
|
let file = File::open(entry.path()).unwrap();
|
|
|
|
let test_case: MultiTestCase = serde_json::from_reader(&file).unwrap();
|
|
|
|
test_case.run(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn generated_with_minification() {
|
|
|
|
for entry in TEST_ROOT_DIR
|
2020-10-02 01:42:27 +00:00
|
|
|
.join("generated")
|
|
|
|
.read_dir()
|
|
|
|
.unwrap()
|
|
|
|
.map(Result::unwrap)
|
|
|
|
{
|
|
|
|
let file = File::open(entry.path()).unwrap();
|
2020-11-24 07:21:14 +00:00
|
|
|
let test_case: MultiTestCase = serde_json::from_reader(&file).unwrap();
|
2021-06-21 05:46:36 +00:00
|
|
|
test_case.run(true);
|
2020-10-02 01:42:27 +00:00
|
|
|
}
|
|
|
|
}
|