Skip to content
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
1,246 changes: 167 additions & 1,079 deletions simplex/Cargo.lock → Cargo.lock

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions simplex/Cargo.toml → Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ resolver = "3"
members = [
"crates/*",
]
exclude = ["examples/basic"]

[workspace.package]
license = "MIT OR Apache-2.0"
Expand All @@ -12,10 +13,11 @@ edition = "2024"
multiple_crate_versions = "allow"

[workspace.dependencies]
simplex-provider = { path = "./crates/provider" }
simplex-macros-core = { path = "./crates/macros-core", features = ["bincode", "serde"] }
simplex-macros = { path = "./crates/macros" }
simplex-template-gen-core = { path = "./crates/template-gen" }
simplex-test = { path = "./crates/test" }
simplex-regtest = { path = "./crates/regtest" }
simplex-sdk = { path = "./crates/sdk" }
simplex = { path = "./crates/simplex" }

Expand All @@ -33,7 +35,7 @@ tracing = { version = "0.1.41" }
minreq = { version = "2.14.1", features = ["https", "json-using-serde"] }
electrsd = { version = "0.29.0", features = ["legacy"] }

simplicityhl = { git = "https://github.com/ikripaka/SimplicityHL/", branch = "feature/rich-params" }
simplicityhl = { git = "https://github.com/BlockstreamResearch/SimplicityHL.git", rev = "568b462" }

[patch.crates-io]
simplicity-sys = { git = "https://github.com/BlockstreamResearch/rust-simplicity", tag = "simplicity-sys-0.6.1" }
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ This collection of useful crates provides useful utilities for working with Simp
- `simplex-core` - provides useful utilities.
- `simplex-cli` - provides common cli interface and ability to setup your contract development environment.

## Quick start

Install simplex with command:
```bash
cargo install --path ./crates/cli
```

To run tests for this crate - run
```bash
RUN_SLOW_TESTS=true cargo test
```

## License

Dual-licensed under either of:
Expand Down
Binary file added assets/electrs
Binary file not shown.
Binary file renamed simplex/assets/elementsd → assets/elementsd
Binary file not shown.
8 changes: 3 additions & 5 deletions simplex/crates/cli/Cargo.toml → crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ path = "src/bin/main.rs"
workspace = true

[dependencies]
simplex-regtest = { workspace = true }
simplex-test = { workspace = true }
simplex-sdk = { workspace = true }
simplex-macros-core = { workspace = true }
simplex-template-gen-core = { workspace = true }

simplicityhl = { workspace = true }
electrsd = { workspace = true }
Expand All @@ -33,8 +35,4 @@ tracing = { version = "0.1.44" }
tracing-subscriber = { version = "0.3.22", features = ["env-filter"] }
ctrlc = { version = "3.5.2", features = ["termination"] }
glob = { version = "0.3.3"}

[dev-dependencies]
tracing = { workspace = true }
tracing-appender = { version = "0.2.3" }
tracing-subscriber = { version = "0.3.19", features = ["env-filter"] }
globwalk = { version = "0.9.1"}
9 changes: 9 additions & 0 deletions crates/cli/Simplex.default.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# TEST CONFIG

# [test]
# esplora = "esplora_api_url"

# [test.rpc]
# url = "rpc_url"
# username = "username"
# password = "password"
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
#![warn(clippy::all, clippy::pedantic)]

use clap::Parser;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
let _ = dotenvy::dotenv();

simplex_cli::logging::init();

Box::pin(simplex_cli::cli::Cli::parse().run()).await?;

Ok(())
Expand Down
77 changes: 77 additions & 0 deletions crates/cli/src/cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
use std::path::PathBuf;

use clap::Parser;

use crate::commands::commands::Command;
use crate::commands::regtest::Regtest;
use crate::commands::test::Test;
use crate::config::{Config, INIT_CONFIG};
use crate::error::CliError;

#[derive(Debug, Parser)]
#[command(name = "Simplex")]
#[command(about = "Simplicity development framework")]
pub struct Cli {
pub config: Option<PathBuf>,

#[command(subcommand)]
pub command: Command,
}

impl Cli {
pub async fn run(&self) -> Result<(), CliError> {
match &self.command {
Command::Init => {
let config_path = Config::get_default_path()?;
std::fs::write(&config_path, INIT_CONFIG)?;

println!("Config written to: '{}'", config_path.display());

Ok(())
}
Command::Config => {
let config_path = Config::get_default_path()?;
let loaded_config = Config::load(config_path)?;

println!("{loaded_config:#?}");

Ok(())
}
Command::Test { command } => {
let config_path = Config::get_default_path()?;
let loaded_config = Config::load(config_path)?;

println!("{loaded_config:#?}");

let test_config = loaded_config.test.unwrap_or_default();

Ok(Test::run(test_config, command)?)
}
Command::Regtest => {
// TODO: pass config
Ok(Regtest::run()?)
}
Command::Build { out_dir: _out_dir } => {
// let loaded_config =
// Config::load_or_discover(self.config.clone()).map_err(|e| Error::ConfigDiscoveryFailure(e))?;

// if loaded_config.build_config.is_none() {
// return Err(Error::Config(
// "No build config to build contracts environment, please add appropriate config".to_string(),
// ));
// }

// let build_config = loaded_config.build_config.unwrap();
// if build_config.compile_simf.is_empty() {
// return Err(Error::Config("No files listed to build contracts environment, please check glob patterns or 'compile_simf' field in config.".to_string()));
// }

// CodeGenerator::generate_files(&build_config.out_dir, &build_config.compile_simf)?;

// println!("{build_config:#?}");

Ok(())
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,52 +1,41 @@
use clap::{Args, Subcommand};
use std::path::PathBuf;

use clap::{Args, Subcommand};

#[derive(Debug, Subcommand)]
pub enum Command {
/// Initialize a project with the default configuration
Init,
/// Show the current configuration
Config,
/// Launch `elementsd` in regtest mode with a default config
Regtest,
/// Launch test with
Test {
#[command(subcommand)]
command: TestCommand,
},
Build {
#[arg(env = "OUT_DIR")]
out_dir: Option<PathBuf>,
},
}

/// Test management commands
#[derive(Debug, Subcommand)]
pub enum TestCommand {
/// Run integration tests using simplex conventions
Integration {
#[command(flatten)]
additional_flags: TestFlags,
},
/// Run only specific files by path for testing
Run {
#[arg(short = 't', long)]
#[arg(long)]
tests: Vec<String>,
#[command(flatten)]
additional_flags: TestFlags,
},
}

/// Additional flags for tests management
#[derive(Debug, Args, Copy, Clone)]
pub struct TestFlags {
/// Flag for not capturing output in tests
#[arg(long)]
pub nocapture: bool,
/// Show output
#[arg(long = "show-output")]
pub show_output: bool,
/// Run ignored tests
#[arg(long = "ignored")]
#[arg(long)]
pub ignored: bool,
}
11 changes: 11 additions & 0 deletions crates/cli/src/commands/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#[derive(thiserror::Error, Debug)]
pub enum CommandError {
#[error("IO error: {0}")]
Io(#[from] std::io::Error),

#[error(transparent)]
Client(#[from] simplex_regtest::error::ClientError),

#[error(transparent)]
Test(#[from] simplex_test::error::TestError),
}
4 changes: 4 additions & 0 deletions crates/cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pub mod commands;

Check warning on line 1 in crates/cli/src/commands/mod.rs

View workflow job for this annotation

GitHub Actions / Format and Clippy

Diff in /home/runner/work/simplex/simplex/crates/cli/src/commands/mod.rs
pub mod test;
pub mod regtest;
pub mod error;
34 changes: 34 additions & 0 deletions crates/cli/src/commands/regtest.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering};

use simplex_regtest::TestClient;

use crate::commands::error::CommandError;

pub struct Regtest {}

impl Regtest {
pub fn run() -> Result<(), CommandError> {
let mut client = TestClient::new();

let running = Arc::new(AtomicBool::new(true));
let r = running.clone();

ctrlc::set_handler(move || {
r.store(false, Ordering::SeqCst);
})
.expect("Error setting Ctrl-C handler");

println!("======================================");
println!("Waiting for Ctrl-C...");
println!("rpc: {}", client.rpc_url());
println!("esplora: {}", client.esplora_url());
let auth = client.auth().get_user_pass().unwrap();
println!("user: {:?}, password: {:?}", auth.0.unwrap(), auth.1.unwrap());
println!("======================================");

while running.load(Ordering::SeqCst) {}

Ok(client.kill()?)
}
}
Loading
Loading