Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internal: isolate test utilities in a dedicated crate #9

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[workspace]
resolver = "2"

members = ["madara-prover-rpc-client", "madara-prover-rpc-server", "stone-prover"]
members = ["madara-prover-rpc-client", "madara-prover-rpc-server", "stone-prover", "test-toolkit"]

[workspace.dependencies]
prost = "0.12.1"
Expand Down
3 changes: 3 additions & 0 deletions madara-prover-rpc-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ tokio-stream = "0.1.14"
[build-dependencies]
tonic-build = { workspace = true }

[dev-dependencies]
test-toolkit = { path = "../test-toolkit" }

2 changes: 2 additions & 0 deletions stone-prover/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ tempfile = "3.8.1"
thiserror = "1.0.50"
tokio = { workspace = true }

[dev-dependencies]
test-toolkit = { path = "../test-toolkit" }
2 changes: 1 addition & 1 deletion stone-prover/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ pub struct Proof {

#[cfg(test)]
mod tests {
use crate::toolkit::load_fixture;
use std::path::Path;
use test_toolkit::load_fixture;

use super::*;

Expand Down
4 changes: 3 additions & 1 deletion stone-prover/src/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,10 @@ pub async fn run_prover_async(
mod test {
use tempfile::NamedTempFile;

use test_toolkit::get_fixture_path;

use crate::models::{PrivateInput, Proof};
use crate::toolkit::{get_fixture_path, read_json_from_file};
use crate::toolkit::read_json_from_file;

use super::*;

Expand Down
17 changes: 0 additions & 17 deletions stone-prover/src/toolkit.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#[cfg(test)]
use std::fs;
use std::fs::File;
use std::path::Path;
#[cfg(test)]
use std::path::PathBuf;

use serde::de::DeserializeOwned;
use serde::Serialize;
Expand All @@ -26,16 +22,3 @@ pub fn write_json_to_file<T: Serialize, P: AsRef<Path>>(
serde_json::to_writer(&mut file, &obj)?;
Ok(())
}

#[cfg(test)]
pub fn get_fixture_path(filename: &str) -> PathBuf {
Path::new(env!("CARGO_MANIFEST_DIR"))
.join("tests/fixtures")
.join(filename)
}

#[cfg(test)]
pub fn load_fixture(filename: &str) -> String {
let fixture_path = get_fixture_path(filename);
fs::read_to_string(fixture_path).expect("Failed to read the fixture file")
}
8 changes: 8 additions & 0 deletions test-toolkit/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "test-toolkit"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
12 changes: 12 additions & 0 deletions test-toolkit/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use std::path::{Path, PathBuf};

pub fn get_fixture_path(filename: &str) -> PathBuf {
Path::new(env!("CARGO_MANIFEST_DIR"))
.join("../stone-prover/tests/fixtures")
.join(filename)
}

pub fn load_fixture(filename: &str) -> String {
let fixture_path = get_fixture_path(filename);
std::fs::read_to_string(fixture_path).expect("Failed to read the fixture file")
}
Loading