Skip to content
Merged

Dev #42

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
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Changelog

## [0.0.3]

- Flattened `simplex test` command interface. Removed `run` and `integration` nesting.
- Refactored `Signer` and `Program` interfaces to get rid of unnecessary `.unwrap()` calls.
- Added support for confidential UTXOs.
- Use `output.with_blinding_key()` to create one.
- Use `signer.blinding_key()` to fetch a blinding key of a specific signer.
- Renamed `Signer` functions to not use the `wpkh` prefix.
- Renamed `Context` functions to returns a default signer and provider.
- Added `create_signer` function to `Context`.
- Added `UTXO` struct to be used in the entire SDK.
- Refactored `PartialInput` to suport locktime.
- Removed presets from the SDK.
- Handled `ElementsRegtest` in test context instead of panicking.

## [0.0.2]

- Implemented `simplex init` and `simplex clean` commands.
Expand Down
14 changes: 7 additions & 7 deletions Cargo.lock

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

12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ edition = "2024"
multiple_crate_versions = "allow"

[workspace.dependencies]
smplx-macros = { path = "./crates/macros", version = "0.0.2" }
smplx-build = { path = "./crates/build", version = "0.0.2" }
smplx-test = { path = "./crates/test", version = "0.0.2" }
smplx-regtest = { path = "./crates/regtest", version = "0.0.2" }
smplx-sdk = { path = "./crates/sdk", version = "0.0.2" }
smplx-std = { path = "./crates/simplex", version = "0.0.2" }
smplx-macros = { path = "./crates/macros", version = "0.0.3" }
smplx-build = { path = "./crates/build", version = "0.0.3" }
smplx-test = { path = "./crates/test", version = "0.0.3" }
smplx-regtest = { path = "./crates/regtest", version = "0.0.3" }
smplx-sdk = { path = "./crates/sdk", version = "0.0.3" }
smplx-std = { path = "./crates/simplex", version = "0.0.3" }

serde = { version = "1.0.228", features = ["derive"]}
hex = { version = "0.4.3" }
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Where:

- `build` (`simplex build` config)
- `src_dir` - The simplicity contracts source directory.
- `simf_files` - A glob pattern incidating which contracts are in scope.
- `simf_files` - A glob pattern indicating which contracts are in scope.
- `out_dir` - The output directory where contracts artifacts are generated.
- `regtest` (`simplex regtest` config)
- `mnemonic` - The signer's mnemonic regtest will send initial funds to.
Expand Down Expand Up @@ -122,6 +122,7 @@ We are open to any mind-blowing ideas! Please take a look at our [contributing g

- [x] Complete `simplex init` and `simplex clean` tasks.
- [ ] SDK support for confidential assets, taproot signer, and custom witness signatures.
- [ ] Simplicity storage compatibility.
- [ ] Local regtest 10x speedup.
- [ ] Regtest cheat codes.
- [ ] Browser compatibility.
Expand Down
2 changes: 1 addition & 1 deletion crates/build/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "smplx-build"
version = "0.0.2"
version = "0.0.3"
description = "Simplex build command internal implementation"
license.workspace = true
edition.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "smplx-cli"
version = "0.0.2"
version = "0.0.3"
description = "Simplex cli with various utilities to manage a simplicity project"
license.workspace = true
edition.workspace = true
Expand Down
9 changes: 6 additions & 3 deletions crates/cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl Cli {
Command::Init { additional_flags } => {
let simplex_conf_path = Config::get_default_path()?;

Ok(Init::run(*additional_flags, simplex_conf_path)?)
Ok(Init::run(simplex_conf_path, additional_flags)?)
}
Command::Config => {
let config_path = Config::get_default_path()?;
Expand All @@ -37,11 +37,14 @@ impl Cli {

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

Ok(Test::run(loaded_config.test, command)?)
Ok(Test::run(loaded_config.test, tests, additional_flags)?)
}
Command::Regtest => {
let config_path = Config::get_default_path()?;
Expand Down
34 changes: 10 additions & 24 deletions crates/cli/src/commands/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,23 @@ pub enum Command {
Regtest,
/// Runs Simplex tests
Test {
#[command(subcommand)]
command: TestCommand,
/// The list of test names to run
#[arg(long)]
tests: Vec<String>,
#[command(flatten)]
additional_flags: TestFlags,
},
/// Generates the simplicity contracts artifacts
Build,
/// Clean Simplex artifacts in the current directory
Clean,
}

#[derive(Debug, Subcommand)]
pub enum TestCommand {
/// Runs integration tests
Integration {
#[command(flatten)]
additional_flags: TestFlags,
},
/// Runs specific tests
Run {
/// The list of test names to run
#[arg(long)]
tests: Vec<String>,
#[command(flatten)]
additional_flags: TestFlags,
},
#[derive(Debug, Args, Copy, Clone)]
pub struct InitFlags {
/// Generate a draft Rust library instead of just `Simplex.toml`
#[arg(long)]
pub lib: bool,
}

#[derive(Debug, Args, Copy, Clone)]
Expand All @@ -51,10 +44,3 @@ pub struct TestFlags {
#[arg(long)]
pub ignored: bool,
}

#[derive(Debug, Args, Copy, Clone)]
pub struct InitFlags {
/// Generate a draft Rust library instead of just `Simplex.toml`
#[arg(long)]
pub lib: bool,
}
4 changes: 2 additions & 2 deletions crates/cli/src/commands/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ pub const SIMPLEX_CRATE_NAME: &str = "smplx-std";
pub struct Init;

impl Init {
pub fn run(conf: InitFlags, smplx_conf_path: impl AsRef<Path>) -> Result<(), CommandError> {
if conf.lib {
pub fn run(smplx_conf_path: impl AsRef<Path>, flags: &InitFlags) -> Result<(), CommandError> {
if flags.lib {
Self::generate_lib_inplace(&smplx_conf_path)?
}

Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/commands/regtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl Regtest {
println!("Esplora: {}", client.esplora_url());
println!("User: {:?}, Password: {:?}", auth.0.unwrap(), auth.1.unwrap());
println!();
println!("Signer: {:?}", signer.get_wpkh_address()?);
println!("Signer: {:?}", signer.get_address());
println!("======================================");

while running.load(Ordering::SeqCst) {}
Expand Down
73 changes: 30 additions & 43 deletions crates/cli/src/commands/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ use std::process::Stdio;

use smplx_test::TestConfig;

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

pub struct Test {}

impl Test {
pub fn run(config: TestConfig, command: &TestCommand) -> Result<(), CommandError> {
pub fn run(config: TestConfig, tests: &[String], flags: &TestFlags) -> Result<(), CommandError> {
let cache_path = Self::get_test_config_cache_name()?;
config.to_file(&cache_path)?;

let mut cargo_test_command = Self::build_cargo_test_command(&cache_path, command);
let mut cargo_test_command = Self::build_cargo_test_command(&cache_path, tests, flags);

let output = cargo_test_command.output()?;

Expand All @@ -33,56 +33,43 @@ impl Test {
Ok(())
}

fn build_cargo_test_command(cache_path: &PathBuf, command: &TestCommand) -> std::process::Command {
let mut command_as_arg = String::new();
fn build_cargo_test_command(cache_path: &PathBuf, tests: &[String], flags: &TestFlags) -> std::process::Command {
let mut cargo_test_command = std::process::Command::new("sh");

match command {
TestCommand::Integration { additional_flags } => {
command_as_arg.push_str("cargo test --tests");
cargo_test_command.args(["-c".to_string(), Self::build_test_command(tests, flags)]);

let flag_args = Self::build_test_flags(additional_flags);
cargo_test_command
.env(smplx_test::TEST_ENV_NAME, cache_path)
.stdin(Stdio::inherit())
.stderr(Stdio::inherit())
.stdout(Stdio::inherit());

if !flag_args.is_empty() {
command_as_arg.push_str(" --");
command_as_arg.push_str(&flag_args);
}
}
TestCommand::Run {
tests,
additional_flags,
} => {
// TODO: check this behavior
if tests.is_empty() {
command_as_arg.push_str("cargo test --tests");
} else {
let mut arg = "cargo test".to_string();

for test_name in tests {
arg.push_str(&format!(" --test {test_name}"));
}

command_as_arg.push_str(&arg);
}
cargo_test_command
}

let flag_args = Self::build_test_flags(additional_flags);
fn build_test_command(tests: &[String], flags: &TestFlags) -> String {
let mut command_as_arg = String::new();

if !flag_args.is_empty() {
command_as_arg.push_str(" --");
command_as_arg.push_str(&flag_args);
}
if tests.is_empty() {
command_as_arg.push_str("cargo test --tests");
} else {
let mut arg = "cargo test".to_string();

for test_name in tests {
arg.push_str(&format!(" --test {test_name}"));
}

command_as_arg.push_str(&arg);
}

let mut cargo_test_command = std::process::Command::new("sh");
cargo_test_command.args(["-c".to_string(), command_as_arg]);
let flag_args = Self::build_test_flags(flags);

cargo_test_command
.env(smplx_test::TEST_ENV_NAME, cache_path)
.stdin(Stdio::inherit())
.stderr(Stdio::inherit())
.stdout(Stdio::inherit());
if !flag_args.is_empty() {
command_as_arg.push_str(" --");
command_as_arg.push_str(&flag_args);
}

cargo_test_command
command_as_arg
}

fn build_test_flags(flags: &TestFlags) -> String {
Expand Down
2 changes: 1 addition & 1 deletion crates/macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "smplx-macros"
version = "0.0.2"
version = "0.0.3"
description = "Simplex macros re-export package"
license.workspace = true
edition.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/regtest/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "smplx-regtest"
version = "0.0.2"
version = "0.0.3"
description = "Simplex regtest command internal implementation"
license.workspace = true
edition.workspace = true
Expand Down
4 changes: 0 additions & 4 deletions crates/regtest/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
use std::io;

use smplx_sdk::provider::ProviderError;
use smplx_sdk::provider::RpcError;
use smplx_sdk::signer::SignerError;

#[derive(thiserror::Error, Debug)]
pub enum RegtestError {
#[error(transparent)]
Provider(#[from] ProviderError),

#[error(transparent)]
Rpc(#[from] RpcError),

Expand Down
8 changes: 4 additions & 4 deletions crates/regtest/src/regtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ impl Regtest {
client.rpc_url(),
client.auth(),
SimplicityNetwork::default_regtest(),
)?);
));

let signer = Signer::new(config.mnemonic.as_str(), provider)?;
let signer = Signer::new(config.mnemonic.as_str(), provider);

Self::prepare_signer(&client, &signer, config.bitcoins)?;

Expand All @@ -38,13 +38,13 @@ impl Regtest {
rpc_provider.sweep_initialfreecoins()?;
rpc_provider.generate_blocks(100)?;

rpc_provider.send_to_address(&signer.get_wpkh_address()?, btc2sat(bitcoins), None)?;
rpc_provider.send_to_address(&signer.get_address(), btc2sat(bitcoins), None)?;

// wait for electrs to index
let mut attempts = 0;

loop {
if !(signer.get_wpkh_utxos()?).is_empty() {
if !(signer.get_utxos()?).is_empty() {
break;
}

Expand Down
Loading
Loading