From 3332a88e6fdb0642a2e85a622eed273a4692421e Mon Sep 17 00:00:00 2001 From: adrian Date: Tue, 16 Sep 2025 08:58:51 +0200 Subject: [PATCH] fix: version handling in protocol-testing --- protocol-testing/build.rs | 15 +++++++++++++++ protocol-testing/entrypoint.sh | 19 ++++++++++++++++++- protocol-testing/src/main.rs | 25 ++++++++++++++++--------- protocol-testing/src/test_runner.rs | 2 +- 4 files changed, 50 insertions(+), 11 deletions(-) create mode 100644 protocol-testing/build.rs diff --git a/protocol-testing/build.rs b/protocol-testing/build.rs new file mode 100644 index 0000000..65908f7 --- /dev/null +++ b/protocol-testing/build.rs @@ -0,0 +1,15 @@ +use std::process::Command; + +fn hash() { + let output = Command::new("git") + .args(["rev-parse", "HEAD"]) + .output() + .unwrap(); + let git_hash = String::from_utf8(output.stdout).unwrap(); + println!("cargo:rustc-env=GIT_HASH={git_hash}"); + println!("cargo:rerun-if-changed=.git/HEAD"); +} + +fn main() { + hash(); +} diff --git a/protocol-testing/entrypoint.sh b/protocol-testing/entrypoint.sh index 2e97d29..b766b78 100644 --- a/protocol-testing/entrypoint.sh +++ b/protocol-testing/entrypoint.sh @@ -1,17 +1,34 @@ #!/bin/bash set -e +# Check arguments if [ "$#" -lt 1 ]; then echo "Usage: $0 protocol1[=filter] [protocol2 ...] or \"$0 'protocol1[=filter] protocol2'\"" exit 1 fi - if [ "$#" -eq 1 ] && [[ "$1" == *" "* ]]; then IFS=' ' read -r -a args <<< "$1" else args=("$@") fi +# Check required binaries +errors=() +for bin in tycho-indexer tycho-protocol-sdk substreams forge cast; do + if command -v "$bin" >/dev/null 2>&1; then + "$bin" --version || echo "$bin does not support --version" + else + errors+=("Binary '$bin' not found in PATH") + fi +done +if [ "${#errors[@]}" -ne 0 ]; then + for err in "${errors[@]}"; do + echo "$err" + done + exit 1 +fi + +# Run tests for test in "${args[@]}"; do protocol="${test%%=*}" filter="${test#*=}" diff --git a/protocol-testing/src/main.rs b/protocol-testing/src/main.rs index 530e642..3a0d371 100644 --- a/protocol-testing/src/main.rs +++ b/protocol-testing/src/main.rs @@ -7,7 +7,7 @@ mod tycho_rpc; mod tycho_runner; mod utils; -use std::{path::PathBuf, process::Command}; +use std::{fmt::Display, path::PathBuf}; use clap::Parser; use miette::{miette, IntoDiagnostic, WrapErr}; @@ -82,7 +82,11 @@ fn main() -> miette::Result<()> { .init(); let version = Version::from_env()?; - info!("version: {}, hash: {}", version.version, version.hash); + if std::env::args().any(|arg| arg == "--version") { + println!("{version}"); + return Ok(()); + } + info!("{version}"); let args = Args::parse(); @@ -108,13 +112,16 @@ impl Version { let version = option_env!("CARGO_PKG_VERSION") .unwrap_or("unknown") .to_string(); - let hash = { - let output = Command::new("git") - .args(["rev-parse", "HEAD"]) - .output() - .into_diagnostic()?; - String::from_utf8(output.stdout).into_diagnostic()? - }; + let hash = option_env!("GIT_HASH") + .unwrap_or("unknown") + .to_string(); Ok(Self { version, hash }) } } + +impl Display for Version { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let bin_name = option_env!("CARGO_PKG_NAME").unwrap_or_default(); + write!(f, "{bin_name} version: {}, hash: {}", self.version, self.hash) + } +} diff --git a/protocol-testing/src/test_runner.rs b/protocol-testing/src/test_runner.rs index f97e0e9..ecc2a29 100644 --- a/protocol-testing/src/test_runner.rs +++ b/protocol-testing/src/test_runner.rs @@ -366,7 +366,7 @@ fn validate_state( let mut decoder = TychoStreamDecoder::new(); let decoder_context = DecoderContext::new() .vm_adapter_path(adapter_contract_path_str) - .vm_trace(vm_traces); + .vm_traces(vm_traces); decoder.register_decoder_with_context::>( protocol_system, decoder_context,