Skip to content

Commit 67514fe

Browse files
committed
Added integration tests to ensure the CLI commands work
1 parent 6baf1b8 commit 67514fe

6 files changed

Lines changed: 133 additions & 4 deletions

File tree

Cargo.lock

Lines changed: 85 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ alloy = { version = "^1.0.35", features = [
1919
"ssz",
2020
] }
2121
alloy-primitives = "^1.3.1"
22+
assert_cmd = "2.1.2"
2223
async-trait = "0.1.80"
2324
axum = { version = "0.8.1", features = ["macros"] }
2425
axum-extra = { version = "0.10.0", features = ["typed-header"] }
@@ -54,6 +55,7 @@ lh_types = { package = "types", git = "https://github.com/sigp/lighthouse", tag
5455
notify = "8.2.0"
5556
parking_lot = "0.12.3"
5657
pbkdf2 = "0.12.2"
58+
predicates = "3.0.3"
5759
prometheus = "0.14.0"
5860
prost = "0.13.4"
5961
rand = { version = "0.9", features = ["os_rng"] }

bin/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ tracing.workspace = true
1818
tree_hash.workspace = true
1919
tree_hash_derive.workspace = true
2020

21+
[dev-dependencies]
22+
assert_cmd.workspace = true
23+
predicates.workspace = true
24+
2125
[[bin]]
2226
name = "commit-boost"
2327
path = "commit-boost.rs"

bin/commit-boost.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,12 @@ use clap::{Parser, Subcommand};
1313
use eyre::Result;
1414
use tracing::{error, info};
1515

16-
/// Version string with a leading 'v'
17-
const VERSION: &str = concat!("v", env!("CARGO_PKG_VERSION"));
18-
1916
/// Long about string for the CLI
2017
const LONG_ABOUT: &str = "Commit-Boost allows Ethereum validators to safely run MEV-Boost and community-built commitment protocols";
2118

2219
/// Subcommands and global arguments for the module
2320
#[derive(Parser, Debug)]
24-
#[command(name = "Commit-Boost", version = VERSION, about, long_about = LONG_ABOUT)]
21+
#[command(name = "Commit-Boost", version = commit_boost::VERSION, about, long_about = LONG_ABOUT)]
2522
struct Cli {
2623
#[command(subcommand)]
2724
command: Commands,
@@ -115,6 +112,8 @@ async fn run_init(config_path: PathBuf, output_path: PathBuf) -> Result<()> {
115112

116113
#[cfg(test)]
117114
mod tests {
115+
use commit_boost::VERSION;
116+
118117
use super::*;
119118

120119
#[test]

bin/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,6 @@ pub mod prelude {
2424
}
2525
pub use tree_hash_derive::TreeHash;
2626
}
27+
28+
/// Version string with a leading 'v'
29+
pub const VERSION: &str = concat!("v", env!("CARGO_PKG_VERSION"));

bin/tests/binary.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
use assert_cmd::{Command, cargo};
2+
3+
/// Tests that the binary can be run and returns a version string
4+
#[test]
5+
fn test_load_example_config() {
6+
let mut cmd = Command::new(cargo::cargo_bin!());
7+
let expected_version = format!("Commit-Boost {}\n", commit_boost::VERSION);
8+
cmd.arg("--version").assert().success().stdout(expected_version);
9+
}
10+
11+
/// Tests that the init command can be run and complains about not having
12+
/// --config set
13+
#[test]
14+
fn test_run_init() {
15+
let mut cmd = Command::new(cargo::cargo_bin!());
16+
cmd.args(["init"]).assert().failure().stderr(predicates::str::contains(
17+
"error: the following required arguments were not provided:\n --config <CONFIG_PATH>",
18+
));
19+
}
20+
21+
/// Tests that PBS runs without CB_CONFIG being set and complains normally
22+
#[test]
23+
fn test_run_pbs_no_config() {
24+
let mut cmd = Command::new(cargo::cargo_bin!());
25+
cmd.args(["pbs"]).assert().failure().stderr(predicates::str::contains("CB_CONFIG is not set"));
26+
}
27+
28+
/// Tests that Signer runs without CB_CONFIG being set and complains normally
29+
#[test]
30+
fn test_run_signer_no_config() {
31+
let mut cmd = Command::new(cargo::cargo_bin!());
32+
cmd.args(["signer"])
33+
.assert()
34+
.failure()
35+
.stderr(predicates::str::contains("CB_CONFIG is not set"));
36+
}

0 commit comments

Comments
 (0)