Skip to content
Open
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
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ rpc_password = "password"
[test]
mnemonic = "exist carry drive collect lend cereal occur much tiger just involve mean"
bitcoins = 10_000_000
verbosity = 0 # 0 - none, 1 - debug, 2 - trace
verbosity = 0 # 0 - none, 1 - debug, 2 - trace, 3 - trace + additional cargo verbose output

[test.esplora]
url = "<esplora url>"
Expand Down
89 changes: 52 additions & 37 deletions crates/cli/src/commands/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ use std::path::PathBuf;
use std::process::Stdio;

use smplx_sdk::global::Verbosity;
use smplx_test::{SMPLX_TEST_MARKER, TestConfig};
use smplx_test::{TestConfig, smplx_test_marker};

use super::core::{TestArguments, TestFlags};
use super::error::CommandError;

/// Nextest dsl variable to filter and use only simplex tests
const SMPLX_NEXTEST_DSL_TEST_MARKER: &str = concat!("test(/", smplx_test_marker!(), "$/)");

pub struct Test {}

impl Test {
Expand All @@ -28,9 +31,9 @@ impl Test {

config.to_file(&cache_path)?;

let mut cargo_test_command = Self::build_cargo_test_command(&cache_path, args, flags);
let mut cargo_nextest_command = Self::build_cargo_nextest_command(&cache_path, args, flags);

let output = cargo_test_command.output()?;
let output = cargo_nextest_command.output()?;

match output.status.code() {
Some(code) => {
Expand All @@ -48,72 +51,84 @@ impl Test {
Ok(())
}

fn build_cargo_test_command(
fn build_cargo_nextest_command(
cache_path: &PathBuf,
args: &TestArguments,
flags: &TestFlags,
) -> std::process::Command {
let mut cargo_test_command = std::process::Command::new("cargo");
cargo_test_command.arg("test");
let mut cargo_nextest_command = std::process::Command::new("smplx-nextest");
cargo_nextest_command.arg("nextest");
cargo_nextest_command.arg("run");

cargo_test_command.args(Self::build_cargo_test_args(args, flags));
cargo_test_command.args(Self::build_test_bin_args(args, flags));
cargo_nextest_command.args(Self::build_cargo_nextest_args(args, flags));
cargo_nextest_command.args(Self::build_test_bin_flags(flags));

cargo_test_command
cargo_nextest_command
.env(smplx_test::TEST_ENV_NAME, cache_path)
.stdin(Stdio::inherit())
.stderr(Stdio::inherit())
.stdout(Stdio::inherit());

cargo_test_command
cargo_nextest_command
}

fn build_cargo_test_args(args: &TestArguments, flags: &TestFlags) -> Vec<String> {
let mut cargo_test_args = Vec::new();
fn build_cargo_nextest_args(args: &TestArguments, flags: &TestFlags) -> Vec<String> {
Comment thread
Arvolear marked this conversation as resolved.
let mut cargo_nextest_args = Vec::new();

if let Some(target) = &args.target {
cargo_test_args.push("--test".into());
cargo_test_args.push(target.clone());
}
if args.filters.is_empty() {
cargo_nextest_args.push("--filterset".into());

if flags.no_fail_fast {
cargo_test_args.push("--no-fail-fast".into());
if let Some(target) = &args.target {
cargo_nextest_args.push(format!("binary({target}) and {SMPLX_NEXTEST_DSL_TEST_MARKER}"));
} else {
cargo_nextest_args.push(SMPLX_NEXTEST_DSL_TEST_MARKER.into());
}
} else {
cargo_nextest_args.extend(args.filters.iter().cloned());
}

cargo_test_args
cargo_nextest_args.extend(Self::build_cargo_nextest_flags(flags));

cargo_nextest_args
}

fn build_test_bin_args(args: &TestArguments, flags: &TestFlags) -> Vec<String> {
let mut test_bin_args = Vec::new();
fn build_cargo_nextest_flags(flags: &TestFlags) -> Vec<String> {
let mut cargo_nextest_flags = Vec::new();

test_bin_args.push("--".into());
if flags.no_fail_fast {
Comment thread
Arvolear marked this conversation as resolved.
cargo_nextest_flags.push("--no-fail-fast".into());
}

// TODO: custom filters may run non-simplex tests due to cargo limitations. Figure out how to fix this
if args.filters.is_empty() {
test_bin_args.push(SMPLX_TEST_MARKER.to_string());
} else {
test_bin_args.extend(args.filters.iter().cloned());
if flags.nocapture {
cargo_nextest_flags.push("--nocapture".into());
}

test_bin_args.extend(Self::build_test_bin_flags(flags));
if flags.quiet {
cargo_nextest_flags.push("--cargo-quiet".into());
}

test_bin_args
if flags.verbose != 0 {
cargo_nextest_flags.push("--verbose".into());
cargo_nextest_flags.push("--cargo-verbose".into());

// `-vvv` verbosity level
if flags.verbose == Verbosity::MAX_VERBOSITY_LEVEL {
cargo_nextest_flags.push("--cargo-verbose".into());
}
}

cargo_nextest_flags
}

fn build_test_bin_flags(flags: &TestFlags) -> Vec<String> {
let mut test_bin_args = Vec::new();

if flags.nocapture {
test_bin_args.push("--nocapture".into());
}
if flags.show_output {
test_bin_args.push("--show-output".into());
}
if flags.ignored {
test_bin_args.push("--ignored".into());
}
if flags.quiet {
test_bin_args.push("--quiet".into());

if !test_bin_args.is_empty() {
test_bin_args.insert(0, "--".into());
}

test_bin_args
Expand Down
2 changes: 1 addition & 1 deletion crates/sdk/src/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub enum Verbosity {

impl Verbosity {
/// The maximum allowed verbosity level.
pub const MAX_VERBOSITY_LEVEL: u8 = 2;
pub const MAX_VERBOSITY_LEVEL: u8 = 3;

/// Creates a `Verbosity` instance from the number of verbosity flags provided (e.g., -v, -vv).
#[must_use]
Expand Down
9 changes: 8 additions & 1 deletion crates/test/src/macros/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ use syn::parse::Parser;

use crate::TEST_ENV_NAME;

pub const SMPLX_TEST_MARKER: &str = "_smplx_test";
#[macro_export]
macro_rules! smplx_test_marker {
() => {
"_smplx_test"
};
}

pub const SMPLX_TEST_MARKER: &str = smplx_test_marker!();

type AttributeArgs = syn::punctuated::Punctuated<syn::Meta, syn::Token![,]>;

Expand Down
57 changes: 54 additions & 3 deletions simplexup/simplexup
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ set -eo pipefail
# NOTE: if you make modifications to this script, please increment the version number.
# WARNING: the SemVer pattern: major.minor.patch must be followed as we use it to determine if the script is up to date.
SIMPLEXUP_INSTALLER_VERSION="0.0.4"
NEXTEST_VERSION="0.9.133"
BINSTALL_VERSION="1.19.1"

BASE_DIR=${XDG_CONFIG_HOME:-$HOME}
SIMPLEX_DIR=${SIMPLEX_DIR:-"$BASE_DIR/.simplex"}
Expand All @@ -14,14 +16,17 @@ SIMPLEX_BIN_PATH="$SIMPLEX_BIN_DIR/simplexup"
SIMPLEXUP_IGNORE_VERIFICATION=false
DEFAULT_SIMPLEX_REPO="BlockstreamResearch/smplx"

SMPLX_NEXTEST_NAME="smplx-nextest"
SMPLX_BIN_NAME="simplex"
DEP_BINS=(elementsd electrs)
BINS=(simplex "${DEP_BINS[@]}")
BINS=("${SMPLX_BIN_NAME}" "${SMPLX_NEXTEST_NAME}" "${DEP_BINS[@]}")
HASH_NAMES=()
HASH_VALUES=()

main() {
need_cmd git
need_cmd curl
need_cmd cargo

while [[ -n $1 ]]; do
case $1 in
Expand Down Expand Up @@ -82,7 +87,12 @@ main() {
version_dir="${SIMPLEX_VERSIONS_DIR}/${SIMPLEX_VERSION}"
ensure mkdir -p "$version_dir"

local BINS_TO_DOWNLOAD=("${BINS[@]}")
# Install `cargo-binstall` for installing various binaries from the internet
install_binstall_version "$BINSTALL_VERSION"
# Install default version of `nextest` for simplex
install_nextest_binary "$NEXTEST_VERSION" "$version_dir"

local BINS_TO_DOWNLOAD=("${SMPLX_BIN_NAME}" "${DEP_BINS[@]}")

if [[ -n "$SIMPLEX_COMMIT" ]]; then
local author="$(echo "${SIMPLEX_REPO}" | cut -d'/' -f1 -)"
Expand Down Expand Up @@ -595,12 +605,53 @@ install_simplex_from_commit() {
say "Installing Simplex version $simplex_version"

ensure cargo build --release --manifest-path "${tmp_dir}/Cargo.toml"
ensure mv "${tmp_dir}/target/release/simplex" "${out_dir}/simplex"
ensure mv "${tmp_dir}/target/release/${SMPLX_BIN_NAME}" "${out_dir}/${SMPLX_BIN_NAME}"

say "Removing temporary directory..."
rm -rf "${tmp_dir}"
}

install_nextest_binary() {
local nextest_version=$1
local install_dir=$2

# Check if smplx-nextest is already installed and matches the required version
say "Checking ${SMPLX_NEXTEST_NAME} version..."
local smplx_nextest_bin_full_path="${install_dir}/${SMPLX_NEXTEST_NAME}"

if check_cmd "${smplx_nextest_bin_full_path}" nextest; then
local current_version
current_version=$(${SMPLX_NEXTEST_NAME} --version | head -n 1 | awk '{print $2}')

if [[ "$current_version" == "$nextest_version" ]]; then
say "${SMPLX_NEXTEST_NAME} $nextest_version is already installed, skipping installation."
return 0
fi
fi

say "Installing ${SMPLX_NEXTEST_NAME} version ${nextest_version} into ${install_dir}..."
ensure cargo binstall cargo-nextest@"${nextest_version}" --only-signed --install-path "${install_dir}" --no-track --force --min-tls-version 1.3 -y
mv "${install_dir}/cargo-nextest" "${smplx_nextest_bin_full_path}"

return 0
Comment thread
Arvolear marked this conversation as resolved.
}

install_binstall_version() {
local binstall_version=$1

# Check if cargo-binstall is already installed
say "Checking cargo-binstall version..."
if check_cmd cargo-binstall; then
say "cargo-binstall $binstall_version is already installed, skipping installation."
return 0
fi

say "Installing cargo-binstall version $binstall_version..."
ensure cargo install cargo-binstall --version "$binstall_version" --locked --force

return 0
Comment thread
Arvolear marked this conversation as resolved.
}

# Form a comma separated list with 'and' for user experience
form_str_list() {
local STR_LIST=("$@")
Expand Down