From 50481f85dadbcd4ebab3dad5c8f4e04cf0bfdfe4 Mon Sep 17 00:00:00 2001 From: Francesco Leacche Date: Tue, 23 Sep 2025 14:42:23 +0100 Subject: [PATCH 1/9] move clarity-cli to contrib --- Cargo.lock | 17 ++++ Cargo.toml | 1 + contrib/clarity-cli/Cargo.toml | 19 ++++ contrib/clarity-cli/README.md | 15 +++ .../clarity-cli/src/lib.rs | 98 +++++++++++-------- .../clarity-cli/src/main.rs | 10 +- contrib/stacks-cli/Cargo.toml | 1 + contrib/stacks-cli/src/main.rs | 2 +- stackslib/src/lib.rs | 3 - 9 files changed, 111 insertions(+), 55 deletions(-) create mode 100644 contrib/clarity-cli/Cargo.toml create mode 100644 contrib/clarity-cli/README.md rename stackslib/src/clarity_cli.rs => contrib/clarity-cli/src/lib.rs (96%) rename stackslib/src/clarity_cli_main.rs => contrib/clarity-cli/src/main.rs (82%) diff --git a/Cargo.lock b/Cargo.lock index 1ef9cc74d59..ecd0bfbf01e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -624,6 +624,22 @@ dependencies = [ "time 0.2.27", ] +[[package]] +name = "clarity-cli" +version = "0.1.0" +dependencies = [ + "clarity 0.0.1", + "lazy_static", + "rand 0.8.5", + "rusqlite", + "serde", + "serde_derive", + "serde_json", + "slog", + "stacks-common 0.0.1", + "stackslib 0.0.1", +] + [[package]] name = "clarity-types" version = "0.0.1" @@ -3111,6 +3127,7 @@ name = "stacks-cli" version = "0.1.0" dependencies = [ "clarity 0.0.1", + "clarity-cli", "serde_json", "stacks-common 0.0.1", "stackslib 0.0.1", diff --git a/Cargo.toml b/Cargo.toml index edbaa79db61..6e9c7507883 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ members = [ "stacks-signer", "stacks-node", "contrib/stacks-inspect", + "contrib/clarity-cli", "contrib/stacks-cli" ] diff --git a/contrib/clarity-cli/Cargo.toml b/contrib/clarity-cli/Cargo.toml new file mode 100644 index 00000000000..1075c774d00 --- /dev/null +++ b/contrib/clarity-cli/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "clarity-cli" +version = "0.1.0" +edition = "2024" + +[dependencies] +clarity = { path = "../../clarity", default-features = false } +stackslib = { package = "stackslib", path = "../../stackslib", default-features = false } +stacks-common = { path = "../../stacks-common", default-features = false } +slog = { version = "2.5.2", features = [ "max_level_trace" ] } +lazy_static = { version = "1.4.0", default-features = false } +serde = { version = "1" } +serde_derive = "1" +serde_json = { workspace = true } +rand = { workspace = true } +rusqlite = { workspace = true } + +[dev-dependencies] +stacks-common = { path = "../../stacks-common", default-features = false, features = ["testing"] } diff --git a/contrib/clarity-cli/README.md b/contrib/clarity-cli/README.md new file mode 100644 index 00000000000..32ed0a6690a --- /dev/null +++ b/contrib/clarity-cli/README.md @@ -0,0 +1,15 @@ +# clarity-cli + +A thin wrapper executable for the Clarity CLI exposed by `blockstack_lib::clarity_cli`. It forwards argv to the library, prints JSON output, and exits with the underlying status code. + +Build: +```bash +cargo build -p clarity-cli +``` + +Usage: +```bash +./target/debug/clarity-cli --help +``` + +For advanced usage and subcommands, see the upstream Clarity CLI documentation or run with `--help`. diff --git a/stackslib/src/clarity_cli.rs b/contrib/clarity-cli/src/lib.rs similarity index 96% rename from stackslib/src/clarity_cli.rs rename to contrib/clarity-cli/src/lib.rs index bc91d386438..7e6f9013952 100644 --- a/stackslib/src/clarity_cli.rs +++ b/contrib/clarity-cli/src/lib.rs @@ -14,6 +14,9 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#[macro_use] +extern crate serde_derive; + use std::ffi::OsStr; use std::io::{Read, Write}; use std::path::PathBuf; @@ -27,42 +30,42 @@ use serde::Serialize; use serde_json::json; use stacks_common::address::c32::c32_address; use stacks_common::consts::{CHAIN_ID_MAINNET, CHAIN_ID_TESTNET}; +use stacks_common::debug; use stacks_common::types::chainstate::{ BlockHeaderHash, BurnchainHeaderHash, ConsensusHash, StacksAddress, StacksBlockId, VRFSeed, }; use stacks_common::types::sqlite::NO_PARAMS; use stacks_common::util::get_epoch_time_ms; -use stacks_common::util::hash::{bytes_to_hex, Hash160, Sha512Trunc256Sum}; - -use crate::burnchains::{PoxConstants, Txid}; -use crate::chainstate::stacks::boot::{ - BOOT_CODE_BNS, BOOT_CODE_COSTS, BOOT_CODE_COSTS_2, BOOT_CODE_COSTS_2_TESTNET, - BOOT_CODE_COSTS_3, BOOT_CODE_COST_VOTING_MAINNET, BOOT_CODE_COST_VOTING_TESTNET, - BOOT_CODE_GENESIS, BOOT_CODE_LOCKUP, BOOT_CODE_POX_MAINNET, BOOT_CODE_POX_TESTNET, - POX_2_MAINNET_CODE, POX_2_TESTNET_CODE, +use stacks_common::util::hash::{Hash160, Sha512Trunc256Sum, bytes_to_hex}; +use stackslib::burnchains::{PoxConstants, Txid}; +use stackslib::chainstate::stacks::boot::{ + BOOT_CODE_BNS, BOOT_CODE_COST_VOTING_MAINNET, BOOT_CODE_COST_VOTING_TESTNET, BOOT_CODE_COSTS, + BOOT_CODE_COSTS_2, BOOT_CODE_COSTS_2_TESTNET, BOOT_CODE_COSTS_3, BOOT_CODE_GENESIS, + BOOT_CODE_LOCKUP, BOOT_CODE_POX_MAINNET, BOOT_CODE_POX_TESTNET, POX_2_MAINNET_CODE, + POX_2_TESTNET_CODE, }; -use crate::chainstate::stacks::index::ClarityMarfTrieId; -use crate::clarity::vm::analysis::contract_interface_builder::build_contract_interface; -use crate::clarity::vm::analysis::errors::CheckError; -use crate::clarity::vm::analysis::{AnalysisDatabase, ContractAnalysis}; -use crate::clarity::vm::ast::build_ast; -use crate::clarity::vm::contexts::{AssetMap, GlobalContext, OwnedEnvironment}; -use crate::clarity::vm::costs::{ExecutionCost, LimitedCostTracker}; -use crate::clarity::vm::database::{ - BurnStateDB, ClarityDatabase, HeadersDB, STXBalance, NULL_BURN_STATE_DB, +use stackslib::chainstate::stacks::index::ClarityMarfTrieId; +use stackslib::clarity::vm::analysis::contract_interface_builder::build_contract_interface; +use stackslib::clarity::vm::analysis::errors::CheckError; +use stackslib::clarity::vm::analysis::{AnalysisDatabase, ContractAnalysis}; +use stackslib::clarity::vm::ast::build_ast; +use stackslib::clarity::vm::contexts::{AssetMap, GlobalContext, OwnedEnvironment}; +use stackslib::clarity::vm::costs::{ExecutionCost, LimitedCostTracker}; +use stackslib::clarity::vm::database::{ + BurnStateDB, ClarityDatabase, HeadersDB, NULL_BURN_STATE_DB, STXBalance, }; -use crate::clarity::vm::errors::{Error, InterpreterResult, RuntimeErrorType}; -use crate::clarity::vm::types::{PrincipalData, QualifiedContractIdentifier}; -use crate::clarity::vm::{ - analysis, ast, eval_all, ClarityVersion, ContractContext, ContractName, SymbolicExpression, - Value, +use stackslib::clarity::vm::errors::{Error, InterpreterResult, RuntimeErrorType}; +use stackslib::clarity::vm::types::{PrincipalData, QualifiedContractIdentifier}; +use stackslib::clarity::vm::{ + ClarityVersion, ContractContext, ContractName, SymbolicExpression, Value, analysis, ast, + eval_all, }; -use crate::clarity_vm::clarity::{ClarityMarfStore, ClarityMarfStoreTransaction}; -use crate::clarity_vm::database::marf::{MarfedKV, PersistentWritableMarfStore}; -use crate::clarity_vm::database::MemoryBackingStore; -use crate::core::{StacksEpochId, BLOCK_LIMIT_MAINNET_205, HELIUM_BLOCK_LIMIT_20}; -use crate::util_lib::boot::{boot_code_addr, boot_code_id}; -use crate::util_lib::db::{sqlite_open, FromColumn}; +use stackslib::clarity_vm::clarity::{ClarityMarfStore, ClarityMarfStoreTransaction}; +use stackslib::clarity_vm::database::MemoryBackingStore; +use stackslib::clarity_vm::database::marf::{MarfedKV, PersistentWritableMarfStore}; +use stackslib::core::{BLOCK_LIMIT_MAINNET_205, HELIUM_BLOCK_LIMIT_20, StacksEpochId}; +use stackslib::util_lib::boot::{boot_code_addr, boot_code_id}; +use stackslib::util_lib::db::{FromColumn, sqlite_open}; lazy_static! { pub static ref STACKS_BOOT_CODE_MAINNET_2_1: [(&'static str, &'static str); 9] = [ @@ -603,7 +606,7 @@ impl CLIHeadersDB { let parent_block_hash = get_cli_chain_tip(&tx); - let random_bytes = rand::thread_rng().gen::<[u8; 32]>(); + let random_bytes = rand::thread_rng().r#gen::<[u8; 32]>(); let next_block_hash = friendly_expect_opt( StacksBlockId::from_bytes(&random_bytes), "Failed to generate random block header.", @@ -1038,9 +1041,13 @@ pub fn invoke_command(invoked_by: &str, args: &[String]) -> (i32, Option (i32, Option { // random 20 bytes - let random_bytes = rand::thread_rng().gen::<[u8; 20]>(); + let random_bytes = rand::thread_rng().r#gen::<[u8; 20]>(); // version = 22 let addr = friendly_expect(c32_address(22, &random_bytes), "Failed to generate address"); @@ -1174,7 +1181,10 @@ pub fn invoke_command(invoked_by: &str, args: &[String]) -> (i32, Option= 3 { // use a persisted marf if testnet_given { - eprintln!("WARN: ignoring --testnet in favor of DB state in {:?}. Re-instantiate the DB to change.", &argv[2]); + eprintln!( + "WARN: ignoring --testnet in favor of DB state in {:?}. Re-instantiate the DB to change.", + &argv[2] + ); } let vm_filename = &argv[2]; @@ -1719,7 +1729,10 @@ pub fn invoke_command(invoked_by: &str, args: &[String]) -> (i32, Option()); - let json_name = format!("/tmp/test-alloc_{}.json", rand::thread_rng().gen::()); - let clar_name = format!("/tmp/test-alloc_{}.clar", rand::thread_rng().gen::()); + let db_name = format!("/tmp/db_{}", rand::thread_rng().r#gen::()); + let json_name = format!("/tmp/test-alloc_{}.json", rand::thread_rng().r#gen::()); + let clar_name = format!("/tmp/test-alloc_{}.clar", rand::thread_rng().r#gen::()); fs::write( &json_name, @@ -1936,7 +1949,7 @@ mod test { #[test] fn test_init_mainnet() { - let db_name = format!("/tmp/db_{}", rand::thread_rng().gen::()); + let db_name = format!("/tmp/db_{}", rand::thread_rng().r#gen::()); let invoked = invoke_command("test", &["initialize".to_string(), db_name.clone()]); let exit = invoked.0; @@ -1951,7 +1964,7 @@ mod test { #[test] fn test_init_testnet() { - let db_name = format!("/tmp/db_{}", rand::thread_rng().gen::()); + let db_name = format!("/tmp/db_{}", rand::thread_rng().r#gen::()); let invoked = invoke_command( "test", &[ @@ -1980,7 +1993,7 @@ mod test { #[test] fn test_samples() { - let db_name = format!("/tmp/db_{}", rand::thread_rng().gen::()); + let db_name = format!("/tmp/db_{}", rand::thread_rng().r#gen::()); eprintln!("initialize"); invoke_command("test", &["initialize".to_string(), db_name.clone()]); @@ -2261,7 +2274,7 @@ mod test { #[test] fn test_assets() { - let db_name = format!("/tmp/db_{}", rand::thread_rng().gen::()); + let db_name = format!("/tmp/db_{}", rand::thread_rng().r#gen::()); eprintln!("initialize"); invoke_command("test", &["initialize".to_string(), db_name.clone()]); @@ -2301,8 +2314,7 @@ mod test { assert_eq!(exit, 0); assert!(!result["message"].as_str().unwrap().is_empty()); assert!( - result["assets"]["tokens"]["S1G2081040G2081040G2081040G208105NK8PE5"] - ["S1G2081040G2081040G2081040G208105NK8PE5.tokens-ft::tokens"] + result["assets"]["tokens"]["S1G2081040G2081040G2081040G208105NK8PE5"]["S1G2081040G2081040G2081040G208105NK8PE5.tokens-ft::tokens"] == "10300" ); assert!(result["events"].as_array().unwrap().len() == 3); diff --git a/stackslib/src/clarity_cli_main.rs b/contrib/clarity-cli/src/main.rs similarity index 82% rename from stackslib/src/clarity_cli_main.rs rename to contrib/clarity-cli/src/main.rs index b7690ac6650..f6d9d480c74 100644 --- a/stackslib/src/clarity_cli_main.rs +++ b/contrib/clarity-cli/src/main.rs @@ -14,23 +14,17 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#![allow(dead_code)] -#![allow(non_camel_case_types)] -#![allow(non_snake_case)] -#![allow(non_upper_case_globals)] - -extern crate blockstack_lib; extern crate serde_json; use std::{env, process}; -use blockstack_lib::clarity_cli as clarity; +use clarity_cli::invoke_command; #[allow(clippy::indexing_slicing)] fn main() { let argv: Vec = env::args().collect(); - let result = clarity::invoke_command(&argv[0], &argv[1..]); + let result = invoke_command(&argv[0], &argv[1..]); match result { (exit_code, Some(output)) => { println!("{}", &serde_json::to_string(&output).unwrap()); diff --git a/contrib/stacks-cli/Cargo.toml b/contrib/stacks-cli/Cargo.toml index a3db6d6e0ff..a942aa50c33 100644 --- a/contrib/stacks-cli/Cargo.toml +++ b/contrib/stacks-cli/Cargo.toml @@ -6,6 +6,7 @@ edition = "2024" [dependencies] stackslib = { package = "stackslib", path = "../../stackslib", default-features = false } clarity = { path = "../../clarity", default-features = false } +clarity-cli = { path = "../clarity-cli", default-features = false } stacks-common = { path = "../../stacks-common", default-features = false } serde_json = { workspace = true } diff --git a/contrib/stacks-cli/src/main.rs b/contrib/stacks-cli/src/main.rs index 34561c0659b..acc5ecbf42a 100644 --- a/contrib/stacks-cli/src/main.rs +++ b/contrib/stacks-cli/src/main.rs @@ -25,6 +25,7 @@ use std::{env, fs, io}; use clarity::vm::errors::{Error as ClarityError, RuntimeErrorType}; use clarity::vm::types::PrincipalData; use clarity::vm::{ClarityName, ClarityVersion, ContractName, Value}; +use clarity_cli::vm_execute; use stacks_common::address::{AddressHashMode, b58}; use stacks_common::codec::{Error as CodecError, StacksMessageCodec}; use stacks_common::types::chainstate::StacksAddress; @@ -41,7 +42,6 @@ use stackslib::chainstate::stacks::{ TransactionContractCall, TransactionPayload, TransactionPostConditionMode, TransactionSmartContract, TransactionSpendingCondition, TransactionVersion, }; -use stackslib::clarity_cli::vm_execute; use stackslib::core::{CHAIN_ID_MAINNET, CHAIN_ID_TESTNET}; use stackslib::net::Error as NetError; use stackslib::util_lib::strings::StacksString; diff --git a/stackslib/src/lib.rs b/stackslib/src/lib.rs index 6561af78114..dec9225783a 100644 --- a/stackslib/src/lib.rs +++ b/stackslib/src/lib.rs @@ -59,9 +59,6 @@ pub extern crate libstackerdb; pub mod chainstate; pub mod burnchains; -/// Allow panics in CLI commands -#[allow(clippy::indexing_slicing)] -pub mod clarity_cli; /// A high level library for interacting with the Clarity vm pub mod clarity_vm; /// Allow panics in CLI commands From 1a358612151e3b015945d12b2e00379284d7059d Mon Sep 17 00:00:00 2001 From: Francesco Leacche Date: Tue, 23 Sep 2025 15:15:06 +0100 Subject: [PATCH 2/9] fix clippy --- contrib/clarity-cli/src/lib.rs | 161 ++++++++++++++------------------- 1 file changed, 69 insertions(+), 92 deletions(-) diff --git a/contrib/clarity-cli/src/lib.rs b/contrib/clarity-cli/src/lib.rs index 7e6f9013952..13aa211bf70 100644 --- a/contrib/clarity-cli/src/lib.rs +++ b/contrib/clarity-cli/src/lib.rs @@ -107,7 +107,7 @@ macro_rules! panic_test { fn print_usage(invoked_by: &str) { eprintln!( - "Usage: {} [command] + "Usage: {invoked_by} [command] where command is one of: initialize to initialize a local VM state database. @@ -121,22 +121,21 @@ where command is one of: repl to typecheck and evaluate expressions in a stdin/stdout loop. execute to execute a public function of a defined contract. generate_address to generate a random Stacks public address for testing purposes. -", - invoked_by +" ); panic_test!() } fn friendly_expect(input: Result, msg: &str) -> A { input.unwrap_or_else(|e| { - eprintln!("{}\nCaused by: {}", msg, e); + eprintln!("{msg}\nCaused by: {e}"); panic_test!(); }) } fn friendly_expect_opt(input: Option, msg: &str) -> A { input.unwrap_or_else(|| { - eprintln!("{}", msg); + eprintln!("{msg}"); panic_test!(); }) } @@ -272,7 +271,7 @@ fn create_or_open_db(path: &String) -> Connection { } OpenFlags::SQLITE_OPEN_READ_WRITE | OpenFlags::SQLITE_OPEN_CREATE } else { - panic!("FATAL: could not stat {}", path); + panic!("FATAL: could not stat {path}"); } } Ok(_md) => { @@ -282,11 +281,10 @@ fn create_or_open_db(path: &String) -> Connection { } }; - let conn = friendly_expect( + friendly_expect( sqlite_open(path, open_flags, false), - &format!("FATAL: failed to open '{}'", path), - ); - conn + &format!("FATAL: failed to open '{path}'"), + ) } fn get_cli_chain_tip(conn: &Connection) -> StacksBlockId { @@ -314,16 +312,11 @@ fn get_cli_block_height(conn: &Connection, block_id: &StacksBlockId) -> Option String { @@ -333,11 +326,11 @@ fn get_cli_db_path(db_path: &str) -> String { let mut cli_db_path_buf = PathBuf::from(db_path); cli_db_path_buf.push("cli.sqlite"); - let cli_db_path = cli_db_path_buf + + cli_db_path_buf .to_str() - .unwrap_or_else(|| panic!("FATAL: failed to convert '{}' to a string", db_path)) - .to_string(); - cli_db_path + .unwrap_or_else(|| panic!("FATAL: failed to convert '{db_path}' to a string")) + .to_string() } // This function is pretty weird! But it helps cut down on @@ -400,12 +393,11 @@ where } fn default_chain_id(mainnet: bool) -> u32 { - let chain_id = if mainnet { + if mainnet { CHAIN_ID_MAINNET } else { CHAIN_ID_TESTNET - }; - chain_id + } } fn with_env_costs( @@ -481,7 +473,7 @@ fn save_coverage( match (coverage_folder, coverage) { (Some(coverage_folder), Some(coverage)) => { let mut coverage_file = PathBuf::from(coverage_folder); - coverage_file.push(&format!("{}_{}", prefix, get_epoch_time_ms())); + coverage_file.push(format!("{prefix}_{}", get_epoch_time_ms())); coverage_file.set_extension("clarcov"); coverage @@ -504,7 +496,7 @@ impl CLIHeadersDB { let cli_db_path = self.get_cli_db_path(); let tx = friendly_expect( self.conn.transaction(), - &format!("FATAL: failed to begin transaction on '{}'", cli_db_path), + &format!("FATAL: failed to begin transaction on '{cli_db_path}'"), ); friendly_expect( @@ -525,7 +517,7 @@ impl CLIHeadersDB { if !mainnet { friendly_expect( - tx.execute("INSERT INTO cli_config (testnet) VALUES (?1)", &[&true]), + tx.execute("INSERT INTO cli_config (testnet) VALUES (?1)", [&true]), "FATAL: failed to set testnet flag", ); } @@ -538,7 +530,7 @@ impl CLIHeadersDB { /// Create or open a new CLI DB at db_path. If it already exists, then this method is a no-op. pub fn new(db_path: &str, mainnet: bool) -> CLIHeadersDB { - let instantiate = db_path == ":memory:" || fs::metadata(&db_path).is_err(); + let instantiate = db_path == ":memory:" || fs::metadata(db_path).is_err(); let cli_db_path = get_cli_db_path(db_path); let conn = create_or_open_db(&cli_db_path); @@ -572,8 +564,7 @@ impl CLIHeadersDB { /// Make a new CLI DB in memory. pub fn new_memory(mainnet: bool) -> CLIHeadersDB { - let db = CLIHeadersDB::new(":memory:", mainnet); - db + CLIHeadersDB::new(":memory:", mainnet) } fn get_cli_db_path(&self) -> String { @@ -615,7 +606,7 @@ impl CLIHeadersDB { friendly_expect( tx.execute( "INSERT INTO cli_chain_tips (block_hash) VALUES (?1)", - &[&next_block_hash], + [&next_block_hash], ), &format!( "FATAL: failed to store next block hash in '{}'", @@ -704,29 +695,17 @@ impl HeadersDB for CLIHeadersDB { _epoch: Option<&StacksEpochId>, ) -> Option { let conn = self.conn(); - if let Some(height) = get_cli_block_height(conn, id_bhh) { - Some(height * 600 + 1231006505) - } else { - None - } + get_cli_block_height(conn, id_bhh).map(|height| height * 600 + 1231006505) } fn get_stacks_block_time_for_block(&self, id_bhh: &StacksBlockId) -> Option { let conn = self.conn(); - if let Some(height) = get_cli_block_height(conn, id_bhh) { - Some(height * 10 + 1713799973) - } else { - None - } + get_cli_block_height(conn, id_bhh).map(|height| height * 10 + 1713799973) } fn get_burn_block_height_for_block(&self, id_bhh: &StacksBlockId) -> Option { let conn = self.conn(); - if let Some(height) = get_cli_block_height(conn, id_bhh) { - Some(height as u32) - } else { - None - } + get_cli_block_height(conn, id_bhh).map(|height| height as u32) } fn get_miner_address( @@ -776,8 +755,8 @@ impl HeadersDB for CLIHeadersDB { fn get_eval_input(invoked_by: &str, args: &[String]) -> EvalInput { if args.len() < 3 || args.len() > 4 { eprintln!( - "Usage: {} {} [--costs] [contract-identifier] (program.clar) [vm-state.db]", - invoked_by, args[0] + "Usage: {invoked_by} {} [--costs] [contract-identifier] (program.clar) [vm-state.db]", + args[0] ); panic_test!(); } @@ -810,11 +789,11 @@ fn get_eval_input(invoked_by: &str, args: &[String]) -> EvalInput { "Failed to open VM database.", ); // return (marf_kv, contract_identifier, vm_filename, content); - return EvalInput { + EvalInput { marf_kv, contract_identifier, content, - }; + } } #[derive(Serialize, Deserialize)] @@ -830,7 +809,7 @@ fn consume_arg( ) -> Result, String> { if let Some(ref switch) = args .iter() - .find(|ref arg| argnames.iter().find(|ref argname| argname == arg).is_some()) + .find(|ref arg| argnames.iter().any(|ref argname| argname == arg)) { let idx = args .iter() @@ -900,8 +879,7 @@ fn install_boot_code(header_db: &CLIHeadersDB, marf: &mut C) let contract_content = *boot_code_contract; debug!( - "Instantiate boot code contract '{}' ({} bytes)...", - &contract_identifier, + "Instantiate boot code contract '{contract_identifier}' ({} bytes)...", boot_code_contract.len() ); @@ -1014,7 +992,7 @@ pub fn invoke_command(invoked_by: &str, args: &[String]) -> (i32, Option = @@ -1038,8 +1016,8 @@ pub fn invoke_command(invoked_by: &str, args: &[String]) -> (i32, Option (i32, Option (i32, Option { if args.len() < 2 { eprintln!( - "Usage: {} {} [program-file.clar] [--contract_id CONTRACT_ID] [--output_analysis] [--costs] [--testnet] (vm-state.db)", - invoked_by, args[0] + "Usage: {invoked_by} {} [program-file.clar] [--contract_id CONTRACT_ID] [--output_analysis] [--costs] [--testnet] (vm-state.db)", + args[0] ); panic_test!(); } @@ -1129,7 +1107,7 @@ pub fn invoke_command(invoked_by: &str, args: &[String]) -> (i32, Option (i32, Option (i32, Option (i32, Option { @@ -1360,7 +1337,7 @@ pub fn invoke_command(invoked_by: &str, args: &[String]) -> (i32, Option (i32, Option (i32, Option (i32, Option (i32, Option { let mut result_json = json!({ "error": { - "runtime": serde_json::to_value(&format!("{}", error)).unwrap() + "runtime": serde_json::to_value(format!("{error}")).unwrap() }, "success": false, }); @@ -1440,7 +1417,7 @@ pub fn invoke_command(invoked_by: &str, args: &[String]) -> (i32, Option (i32, Option (i32, Option (i32, Option (i32, Option { let mut result_json = json!({ "error": { - "runtime": serde_json::to_value(&format!("{}", error)).unwrap() + "runtime": serde_json::to_value(format!("{error}")).unwrap() }, "success": false, }); @@ -1591,8 +1568,8 @@ pub fn invoke_command(invoked_by: &str, args: &[String]) -> (i32, Option (i32, Option (i32, Option (i32, Option (i32, Option (i32, Option (i32, Option (i32, Option (i32, Option (i32, Option Date: Tue, 23 Sep 2025 15:40:39 +0100 Subject: [PATCH 3/9] stacks-inspect depends on clarity-cli --- Cargo.lock | 1 + contrib/clarity-cli/src/lib.rs | 1 + contrib/stacks-inspect/Cargo.toml | 1 + contrib/stacks-inspect/src/main.rs | 14 +++++++------- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ecd0bfbf01e..092fd68c4e9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3196,6 +3196,7 @@ name = "stacks-inspect" version = "0.1.0" dependencies = [ "clarity 0.0.1", + "clarity-cli", "libstackerdb 0.0.1", "mutants", "rusqlite", diff --git a/contrib/clarity-cli/src/lib.rs b/contrib/clarity-cli/src/lib.rs index e1bb038895f..8cbfb94c359 100644 --- a/contrib/clarity-cli/src/lib.rs +++ b/contrib/clarity-cli/src/lib.rs @@ -143,6 +143,7 @@ fn friendly_expect_opt(input: Option, msg: &str) -> A { pub const DEFAULT_CLI_EPOCH: StacksEpochId = StacksEpochId::Epoch32; struct EvalInput { + #[allow(dead_code)] marf_kv: MarfedKV, contract_identifier: QualifiedContractIdentifier, content: String, diff --git a/contrib/stacks-inspect/Cargo.toml b/contrib/stacks-inspect/Cargo.toml index 354c1fdc549..9aa60904d61 100644 --- a/contrib/stacks-inspect/Cargo.toml +++ b/contrib/stacks-inspect/Cargo.toml @@ -6,6 +6,7 @@ edition = "2024" [dependencies] stackslib = { package = "stackslib", path = "../../stackslib", default-features = false } clarity = { path = "../../clarity", default-features = false } +clarity-cli = { path = "../clarity-cli", default-features = false } libstackerdb = { path = "../../libstackerdb", default-features = false } stacks-common = { path = "../../stacks-common", default-features = false } rusqlite = { workspace = true } diff --git a/contrib/stacks-inspect/src/main.rs b/contrib/stacks-inspect/src/main.rs index 9c43923920d..1da8bc9456a 100644 --- a/contrib/stacks-inspect/src/main.rs +++ b/contrib/stacks-inspect/src/main.rs @@ -43,6 +43,7 @@ use std::net::{SocketAddr, TcpStream, ToSocketAddrs}; use std::time::{Duration, Instant}; use std::{env, fs, io, process, thread}; +use clarity_cli; use libstackerdb::StackerDBChunkData; use rusqlite::{Connection, Error as SqliteError, OpenFlags, params}; use serde_json::{Value, json}; @@ -91,7 +92,6 @@ use stackslib::net::relay::Relayer; use stackslib::net::{GetNakamotoInvData, HandshakeData, StacksMessage, StacksMessageType}; use stackslib::util_lib::db::sqlite_open; use stackslib::util_lib::strings::UrlString; -use stackslib::{clarity_cli, cli}; struct P2PSession { pub local_peer: LocalPeer, @@ -301,7 +301,7 @@ fn main() { process::exit(1); } - let common_opts = cli::drain_common_opts(&mut argv, 1); + let common_opts = stackslib::cli::drain_common_opts(&mut argv, 1); if argv[1] == "--version" { println!( @@ -789,7 +789,7 @@ check if the associated microblocks can be downloaded } if argv[1] == "try-mine" { - cli::command_try_mine(&argv[1..], common_opts.config.as_ref()); + stackslib::cli::command_try_mine(&argv[1..], common_opts.config.as_ref()); process::exit(0); } @@ -1582,17 +1582,17 @@ check if the associated microblocks can be downloaded } if argv[1] == "replay-block" { - cli::command_replay_block(&argv[1..], common_opts.config.as_ref()); + stackslib::cli::command_replay_block(&argv[1..], common_opts.config.as_ref()); process::exit(0); } if argv[1] == "replay-naka-block" { - cli::command_replay_block_nakamoto(&argv[1..], common_opts.config.as_ref()); + stackslib::cli::command_replay_block_nakamoto(&argv[1..], common_opts.config.as_ref()); process::exit(0); } if argv[1] == "replay-mock-mining" { - cli::command_replay_mock_mining(&argv[1..], common_opts.config.as_ref()); + stackslib::cli::command_replay_mock_mining(&argv[1..], common_opts.config.as_ref()); process::exit(0); } @@ -1601,7 +1601,7 @@ check if the associated microblocks can be downloaded } if argv[1] == "contract-hash" { - cli::command_contract_hash(&argv[1..], common_opts.config.as_ref()); + stackslib::cli::command_contract_hash(&argv[1..], common_opts.config.as_ref()); process::exit(0); } From 13826c021f73c0f9480dfa2e78ab52b395940142 Mon Sep 17 00:00:00 2001 From: Francesco Leacche Date: Tue, 23 Sep 2025 15:41:16 +0100 Subject: [PATCH 4/9] add contrib crates to clippy-stacks --- .cargo/config.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index d277b56a032..440c785d471 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,7 +1,7 @@ [alias] stacks-node = "run --package stacks-node --" fmt-stacks = "fmt -- --config group_imports=StdExternalCrate,imports_granularity=Module" -clippy-stacks = "clippy -p stx-genesis -p libstackerdb -p stacks-signer -p pox-locking -p clarity-types -p clarity -p libsigner -p stacks-common --no-deps --tests --all-features -- -D warnings" +clippy-stacks = "clippy -p stx-genesis -p libstackerdb -p stacks-signer -p pox-locking -p clarity-types -p clarity -p libsigner -p stacks-common -p clarity-cli -p stacks-cli -p stacks-inspect --no-deps --tests --all-features -- -D warnings" clippy-stackslib = "clippy -p stackslib --no-deps -- -Aclippy::all -Wclippy::indexing_slicing -Wclippy::nonminimal_bool -Wclippy::clone_on_copy" # Uncomment to improve performance slightly, at the cost of portability From ec4b657df92e16c8e11df1e690825455cf23b145 Mon Sep 17 00:00:00 2001 From: Francesco Leacche Date: Tue, 23 Sep 2025 15:45:00 +0100 Subject: [PATCH 5/9] fix clippy --- contrib/clarity-cli/src/lib.rs | 16 ++++++---------- contrib/stacks-inspect/src/main.rs | 4 ++-- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/contrib/clarity-cli/src/lib.rs b/contrib/clarity-cli/src/lib.rs index 8cbfb94c359..c04b4c92e31 100644 --- a/contrib/clarity-cli/src/lib.rs +++ b/contrib/clarity-cli/src/lib.rs @@ -976,15 +976,11 @@ pub fn add_serialized_output(result: &mut serde_json::Value, value: Value) { /// Parse --clarity_version flag. Defaults to version for DEFAULT_CLI_EPOCH. fn parse_clarity_version_flag(argv: &mut Vec) -> ClarityVersion { - if let Ok(optarg) = consume_arg(argv, &["--clarity_version"], true) { - if let Some(s) = optarg { - friendly_expect( - s.parse::(), - &format!("Invalid clarity version: {}", s), - ) - } else { - ClarityVersion::default_for_epoch(DEFAULT_CLI_EPOCH) - } + if let Ok(Some(s)) = consume_arg(argv, &["--clarity_version"], true) { + friendly_expect( + s.parse::(), + &format!("Invalid clarity version: {s}"), + ) } else { ClarityVersion::default_for_epoch(DEFAULT_CLI_EPOCH) } @@ -1278,7 +1274,7 @@ pub fn invoke_command(invoked_by: &str, args: &[String]) -> (i32, Option ").unwrap_or_else(|e| { + stdout.write_all(b"> ").unwrap_or_else(|e| { panic!("Failed to write stdout prompt string:\n{e}"); }); stdout.flush().unwrap_or_else(|e| { diff --git a/contrib/stacks-inspect/src/main.rs b/contrib/stacks-inspect/src/main.rs index 1da8bc9456a..f1276ae3c7d 100644 --- a/contrib/stacks-inspect/src/main.rs +++ b/contrib/stacks-inspect/src/main.rs @@ -19,6 +19,7 @@ extern crate stacks_common; use clarity::consts::CHAIN_ID_MAINNET; use clarity::types::StacksEpochId; use clarity::types::chainstate::StacksPrivateKey; +use clarity_cli::DEFAULT_CLI_EPOCH; use stackslib::chainstate::stacks::miner::BlockBuilderSettings; use stackslib::chainstate::stacks::{ CoinbasePayload, StacksBlock, StacksBlockBuilder, StacksMicroblock, StacksTransaction, @@ -43,7 +44,6 @@ use std::net::{SocketAddr, TcpStream, ToSocketAddrs}; use std::time::{Duration, Instant}; use std::{env, fs, io, process, thread}; -use clarity_cli; use libstackerdb::StackerDBChunkData; use rusqlite::{Connection, Error as SqliteError, OpenFlags, params}; use serde_json::{Value, json}; @@ -896,7 +896,7 @@ check if the associated microblocks can be downloaded } let program: String = fs::read_to_string(&argv[2]) .unwrap_or_else(|_| panic!("Error reading file: {}", argv[2])); - let clarity_version = ClarityVersion::default_for_epoch(clarity_cli::DEFAULT_CLI_EPOCH); + let clarity_version = ClarityVersion::default_for_epoch(DEFAULT_CLI_EPOCH); match clarity_cli::vm_execute(&program, clarity_version) { Ok(Some(result)) => println!("{result}"), Ok(None) => println!(), From 9e4cd45222f4f0a2f4356c59a7ce2e445f79f9ad Mon Sep 17 00:00:00 2001 From: Francesco Leacche Date: Tue, 23 Sep 2025 15:46:56 +0100 Subject: [PATCH 6/9] remove clarity-cli from stackslib --- stackslib/Cargo.toml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/stackslib/Cargo.toml b/stackslib/Cargo.toml index 7f8209b5824..79a64d8777a 100644 --- a/stackslib/Cargo.toml +++ b/stackslib/Cargo.toml @@ -18,10 +18,6 @@ rust-version = "1.80" name = "blockstack_lib" path = "src/lib.rs" -[[bin]] -name = "clarity-cli" -path = "src/clarity_cli_main.rs" - [dependencies] rand = { workspace = true } rand_core = { workspace = true } From e8b0d35ef9ab037abd0f5a35df4c0c04b8fda427 Mon Sep 17 00:00:00 2001 From: Francesco Leacche Date: Wed, 24 Sep 2025 11:04:32 +0100 Subject: [PATCH 7/9] fix clippy --- contrib/stacks-inspect/src/lib.rs | 6 ++++-- contrib/stacks-inspect/src/main.rs | 1 - 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/contrib/stacks-inspect/src/lib.rs b/contrib/stacks-inspect/src/lib.rs index 444a016dbd6..02f0b275572 100644 --- a/contrib/stacks-inspect/src/lib.rs +++ b/contrib/stacks-inspect/src/lib.rs @@ -393,7 +393,7 @@ pub fn command_try_mine(argv: &[String], conf: Option<&Config>) { let print_help_and_exit = || { let n = &argv[0]; eprintln!("Usage: {n} [min-fee [max-time]]"); - eprintln!(""); + eprintln!(); eprintln!( "Given a , try to ''mine'' an anchored block. This invokes the miner block" ); @@ -731,6 +731,7 @@ fn replay_mock_mined_block(db_path: &str, block: AssembledAnchorBlock, conf: Opt } /// Validate a block against chainstate +#[allow(clippy::too_many_arguments)] fn replay_block( mut sort_tx: IndexDBTx, mut chainstate_tx: ChainstateTx, @@ -901,6 +902,7 @@ fn replay_naka_staging_block(db_path: &str, index_block_hash_hex: &str, conf: &C replay_block_nakamoto(&mut sortdb, &mut chainstate, &block, block_size).unwrap(); } +#[allow(clippy::result_large_err)] fn replay_block_nakamoto( sort_db: &mut SortitionDB, stacks_chain_state: &mut StacksChainState, @@ -1145,7 +1147,7 @@ fn replay_block_nakamoto( &mut chainstate_tx, clarity_instance, &mut burn_view_handle, - &burnchain_view, + burnchain_view, &pox_constants, &parent_header_info, &next_ready_block_snapshot.burn_header_hash, diff --git a/contrib/stacks-inspect/src/main.rs b/contrib/stacks-inspect/src/main.rs index 839010f7a05..9755ada2341 100644 --- a/contrib/stacks-inspect/src/main.rs +++ b/contrib/stacks-inspect/src/main.rs @@ -48,7 +48,6 @@ use std::net::{SocketAddr, TcpStream, ToSocketAddrs}; use std::time::{Duration, Instant}; use std::{env, fs, io, process, thread}; -use clarity_cli; use libstackerdb::StackerDBChunkData; use rusqlite::{Connection, Error as SqliteError, OpenFlags, params}; use serde_json::{Value, json}; From c6877493250bff8f9d7483dfd3be8a3276f00e1b Mon Sep 17 00:00:00 2001 From: Francesco Leacche Date: Thu, 25 Sep 2025 15:17:40 +0100 Subject: [PATCH 8/9] remove clarity-cli from stacks-node tests --- Cargo.lock | 1 - stacks-node/Cargo.toml | 1 - stacks-node/src/tests/epoch_21.rs | 21 +++++++++++++++++++-- stacks-node/src/tests/epoch_22.rs | 15 +++++++++++++-- stacks-node/src/tests/epoch_24.rs | 16 ++++++++++++++-- stacks-node/src/tests/mod.rs | 3 +++ stacks-node/src/tests/neon_integrations.rs | 14 ++++++++++++-- 7 files changed, 61 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0f3e9d0171a..4e57b01a2ac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3218,7 +3218,6 @@ dependencies = [ "base64 0.12.3", "chrono", "clarity 0.0.1", - "clarity-cli", "hashbrown 0.15.2", "http-types", "lazy_static", diff --git a/stacks-node/Cargo.toml b/stacks-node/Cargo.toml index 1a0c8cc95b7..615fe9571de 100644 --- a/stacks-node/Cargo.toml +++ b/stacks-node/Cargo.toml @@ -45,7 +45,6 @@ warp = "0.3.5" tokio = "1.15" reqwest = { version = "0.11", default-features = false, features = ["blocking", "json", "rustls", "rustls-tls"] } clarity = { path = "../clarity", features = ["default", "testing"]} -clarity-cli = { path = "../contrib/clarity-cli", default-features = false } stacks-common = { path = "../stacks-common", features = ["default", "testing"] } stacks = { package = "stackslib", path = "../stackslib", features = ["default", "testing"] } stacks-signer = { path = "../stacks-signer", features = ["testing"] } diff --git a/stacks-node/src/tests/epoch_21.rs b/stacks-node/src/tests/epoch_21.rs index 00d608bdb16..ecf656b7f1d 100644 --- a/stacks-node/src/tests/epoch_21.rs +++ b/stacks-node/src/tests/epoch_21.rs @@ -3,8 +3,7 @@ use std::{env, thread}; use ::core::str; use clarity::vm::types::{PrincipalData, QualifiedContractIdentifier}; -use clarity::vm::{ClarityVersion, Value}; -use clarity_cli::vm_execute as execute; +use clarity::vm::{execute_with_parameters as execute, ClarityVersion, Value}; use stacks::burnchains::bitcoin::address::{ BitcoinAddress, LegacyBitcoinAddressType, SegwitBitcoinAddress, }; @@ -1089,6 +1088,8 @@ fn transition_adds_get_pox_addr_recipients() { &(*addr_variant as u8) ), ClarityVersion::Clarity2, + CURRENT_TESTING_EPOCH, + false, ) .unwrap() .unwrap(); @@ -1129,6 +1130,8 @@ fn transition_adds_get_pox_addr_recipients() { let pox_addr_tuple = execute( &format!("{{ hashbytes: 0x{bytes}, version: 0x{version:02x} }}"), ClarityVersion::Clarity2, + CURRENT_TESTING_EPOCH, + false, ) .unwrap() .unwrap(); @@ -1565,6 +1568,8 @@ fn transition_removes_pox_sunset() { execute( &format!("{{ hashbytes: 0x{pox_pubkey_hash}, version: 0x00 }}"), ClarityVersion::Clarity1, + CURRENT_TESTING_EPOCH, + false, ) .unwrap() .unwrap(), @@ -1622,6 +1627,8 @@ fn transition_removes_pox_sunset() { execute( &format!("{{ hashbytes: 0x{pox_pubkey_hash}, version: 0x00 }}"), ClarityVersion::Clarity2, + CURRENT_TESTING_EPOCH, + false, ) .unwrap() .unwrap(), @@ -2222,6 +2229,8 @@ fn test_sortition_divergence_pre_21() { execute( &format!("{{ hashbytes: 0x{pox_pubkey_hash}, version: 0x00 }}"), ClarityVersion::Clarity1, + CURRENT_TESTING_EPOCH, + false, ) .unwrap() .unwrap(), @@ -2766,6 +2775,8 @@ fn test_v1_unlock_height_with_current_stackers() { let pox_addr_tuple_1 = execute( &format!("{{ hashbytes: 0x{pox_pubkey_hash_1}, version: 0x00 }}"), ClarityVersion::Clarity2, + CURRENT_TESTING_EPOCH, + false, ) .unwrap() .unwrap(); @@ -2803,6 +2814,8 @@ fn test_v1_unlock_height_with_current_stackers() { let pox_addr_tuple_2 = execute( &format!("{{ hashbytes: 0x{pox_pubkey_hash_2}, version: 0x00 }}"), ClarityVersion::Clarity2, + CURRENT_TESTING_EPOCH, + false, ) .unwrap() .unwrap(); @@ -3022,6 +3035,8 @@ fn test_v1_unlock_height_with_delay_and_current_stackers() { let pox_addr_tuple_1 = execute( &format!("{{ hashbytes: 0x{pox_pubkey_hash_1}, version: 0x00 }}"), ClarityVersion::Clarity2, + CURRENT_TESTING_EPOCH, + false, ) .unwrap() .unwrap(); @@ -3071,6 +3086,8 @@ fn test_v1_unlock_height_with_delay_and_current_stackers() { let pox_addr_tuple_2 = execute( &format!("{{ hashbytes: 0x{pox_pubkey_hash_2}, version: 0x00 }}"), ClarityVersion::Clarity2, + CURRENT_TESTING_EPOCH, + false, ) .unwrap() .unwrap(); diff --git a/stacks-node/src/tests/epoch_22.rs b/stacks-node/src/tests/epoch_22.rs index f1fee7e6d2e..b3fb0fd05db 100644 --- a/stacks-node/src/tests/epoch_22.rs +++ b/stacks-node/src/tests/epoch_22.rs @@ -2,8 +2,7 @@ use std::collections::HashMap; use std::{env, thread}; use clarity::vm::types::PrincipalData; -use clarity::vm::{ClarityVersion, Value}; -use clarity_cli::vm_execute as execute; +use clarity::vm::{execute_with_parameters as execute, ClarityVersion, Value}; use stacks::burnchains::{Burnchain, PoxConstants}; use stacks::chainstate::stacks::address::PoxAddress; use stacks::chainstate::stacks::db::StacksChainState; @@ -196,6 +195,8 @@ fn disable_pox() { let pox_addr_tuple_1 = execute( &format!("{{ hashbytes: 0x{pox_pubkey_hash_1}, version: 0x00 }}"), ClarityVersion::Clarity2, + CURRENT_TESTING_EPOCH, + false, ) .unwrap() .unwrap(); @@ -203,6 +204,8 @@ fn disable_pox() { let pox_addr_tuple_3 = execute( &format!("{{ hashbytes: 0x{pox_pubkey_hash_3}, version: 0x00 }}"), ClarityVersion::Clarity2, + CURRENT_TESTING_EPOCH, + false, ) .unwrap() .unwrap(); @@ -253,6 +256,8 @@ fn disable_pox() { let pox_addr_tuple_2 = execute( &format!("{{ hashbytes: 0x{pox_pubkey_hash_2}, version: 0x00 }}"), ClarityVersion::Clarity2, + CURRENT_TESTING_EPOCH, + false, ) .unwrap() .unwrap(); @@ -720,6 +725,8 @@ fn pox_2_unlock_all() { let pox_addr_tuple_1 = execute( &format!("{{ hashbytes: 0x{pox_pubkey_hash_1}, version: 0x00 }}"), ClarityVersion::Clarity2, + CURRENT_TESTING_EPOCH, + false, ) .unwrap() .unwrap(); @@ -727,6 +734,8 @@ fn pox_2_unlock_all() { let pox_addr_tuple_3 = execute( &format!("{{ hashbytes: 0x{pox_pubkey_hash_3}, version: 0x00 }}"), ClarityVersion::Clarity2, + CURRENT_TESTING_EPOCH, + false, ) .unwrap() .unwrap(); @@ -778,6 +787,8 @@ fn pox_2_unlock_all() { let pox_addr_tuple_2 = execute( &format!("{{ hashbytes: 0x{pox_pubkey_hash_2}, version: 0x00 }}"), ClarityVersion::Clarity2, + CURRENT_TESTING_EPOCH, + false, ) .unwrap() .unwrap(); diff --git a/stacks-node/src/tests/epoch_24.rs b/stacks-node/src/tests/epoch_24.rs index 7071af93000..61abe8fb395 100644 --- a/stacks-node/src/tests/epoch_24.rs +++ b/stacks-node/src/tests/epoch_24.rs @@ -18,8 +18,7 @@ use std::{env, thread}; use clarity::boot_util::boot_code_id; use clarity::vm::types::PrincipalData; -use clarity::vm::{ClarityVersion, Value}; -use clarity_cli::vm_execute as execute; +use clarity::vm::{execute_with_parameters as execute, ClarityVersion, Value}; use stacks::burnchains::{Burnchain, PoxConstants}; use stacks::chainstate::burn::db::sortdb::SortitionDB; use stacks::chainstate::stacks::address::PoxAddress; @@ -43,6 +42,7 @@ use crate::tests::neon_integrations::{ get_account, get_chain_info, get_pox_info, neon_integration_test_conf, next_block_and_wait, submit_tx, test_observer, wait_for_runloop, }; +use crate::tests::CURRENT_TESTING_EPOCH; use crate::{neon, BitcoinRegtestController, BurnchainController}; #[cfg(test)] @@ -222,6 +222,8 @@ fn fix_to_pox_contract() { let pox_addr_tuple_1 = execute( &format!("{{ hashbytes: 0x{pox_pubkey_hash_1}, version: 0x00 }}"), ClarityVersion::Clarity2, + CURRENT_TESTING_EPOCH, + false, ) .unwrap() .unwrap(); @@ -229,6 +231,8 @@ fn fix_to_pox_contract() { let pox_addr_tuple_3 = execute( &format!("{{ hashbytes: 0x{pox_pubkey_hash_3}, version: 0x00 }}"), ClarityVersion::Clarity2, + CURRENT_TESTING_EPOCH, + false, ) .unwrap() .unwrap(); @@ -280,6 +284,8 @@ fn fix_to_pox_contract() { let pox_addr_tuple_2 = execute( &format!("{{ hashbytes: 0x{pox_pubkey_hash_2}, version: 0x00 }}"), ClarityVersion::Clarity2, + CURRENT_TESTING_EPOCH, + false, ) .unwrap() .unwrap(); @@ -850,6 +856,8 @@ fn verify_auto_unlock_behavior() { let pox_addr_tuple_1 = execute( &format!("{{ hashbytes: 0x{pox_pubkey_hash_1}, version: 0x00 }}"), ClarityVersion::Clarity2, + CURRENT_TESTING_EPOCH, + false, ) .unwrap() .unwrap(); @@ -857,6 +865,8 @@ fn verify_auto_unlock_behavior() { let pox_addr_tuple_3 = execute( &format!("{{ hashbytes: 0x{pox_pubkey_hash_3}, version: 0x00 }}"), ClarityVersion::Clarity2, + CURRENT_TESTING_EPOCH, + false, ) .unwrap() .unwrap(); @@ -908,6 +918,8 @@ fn verify_auto_unlock_behavior() { let pox_addr_tuple_2 = execute( &format!("{{ hashbytes: 0x{pox_pubkey_hash_2}, version: 0x00 }}"), ClarityVersion::Clarity2, + CURRENT_TESTING_EPOCH, + false, ) .unwrap() .unwrap(); diff --git a/stacks-node/src/tests/mod.rs b/stacks-node/src/tests/mod.rs index 0629612f69d..437dc86359b 100644 --- a/stacks-node/src/tests/mod.rs +++ b/stacks-node/src/tests/mod.rs @@ -78,6 +78,9 @@ pub const SK_3: &str = "cb95ddd0fe18ec57f4f3533b95ae564b3f1ae063dbf75b46334bd862 pub const ADDR_4: &str = "ST31DA6FTSJX2WGTZ69SFY11BH51NZMB0ZZ239N96"; +/// The epoch that is being used for tests that call the clarity vm. +pub const CURRENT_TESTING_EPOCH: StacksEpochId = StacksEpochId::Epoch32; + lazy_static! { pub static ref PUBLISH_CONTRACT: Vec = make_contract_publish( &StacksPrivateKey::from_hex( diff --git a/stacks-node/src/tests/neon_integrations.rs b/stacks-node/src/tests/neon_integrations.rs index d1b2066f1f5..8da25c90d5f 100644 --- a/stacks-node/src/tests/neon_integrations.rs +++ b/stacks-node/src/tests/neon_integrations.rs @@ -9,8 +9,10 @@ use clarity::vm::ast::stack_depth_checker::AST_CALL_STACK_DEPTH_BUFFER; use clarity::vm::costs::ExecutionCost; use clarity::vm::types::serialization::SerializationError; use clarity::vm::types::PrincipalData; -use clarity::vm::{ClarityName, ClarityVersion, ContractName, Value, MAX_CALL_STACK_DEPTH}; -use clarity_cli::vm_execute as execute; +use clarity::vm::{ + execute_with_parameters as execute, ClarityName, ClarityVersion, ContractName, Value, + MAX_CALL_STACK_DEPTH, +}; use rusqlite::params; use serde::Deserialize; use serde_json::json; @@ -2368,6 +2370,8 @@ fn stx_delegate_btc_integration_test() { execute( &format!("{{ hashbytes: 0x{pox_pubkey_hash}, version: 0x00 }}"), ClarityVersion::Clarity2, + StacksEpochId::Epoch32, + false, ) .unwrap() .unwrap(), @@ -5356,6 +5360,8 @@ fn pox_integration_test() { execute( &format!("{{ hashbytes: 0x{pox_pubkey_hash}, version: 0x00 }}"), ClarityVersion::Clarity1, + StacksEpochId::Epoch32, + false, ) .unwrap() .unwrap(), @@ -5468,6 +5474,8 @@ fn pox_integration_test() { execute( &format!("{{ hashbytes: 0x{pox_2_pubkey_hash}, version: 0x00 }}"), ClarityVersion::Clarity1, + StacksEpochId::Epoch32, + false, ) .unwrap() .unwrap(), @@ -5492,6 +5500,8 @@ fn pox_integration_test() { execute( &format!("{{ hashbytes: 0x{pox_2_pubkey_hash}, version: 0x00 }}"), ClarityVersion::Clarity1, + StacksEpochId::Epoch32, + false, ) .unwrap() .unwrap(), From 259fb0f6dc62d62b636c8873a372213887337902 Mon Sep 17 00:00:00 2001 From: Francesco Leacche Date: Wed, 1 Oct 2025 12:18:20 +0100 Subject: [PATCH 9/9] update neon_integrations tests to use CURRENT_TESTING_EPOCH --- stacks-node/src/tests/neon_integrations.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/stacks-node/src/tests/neon_integrations.rs b/stacks-node/src/tests/neon_integrations.rs index 8da25c90d5f..010e8be8af9 100644 --- a/stacks-node/src/tests/neon_integrations.rs +++ b/stacks-node/src/tests/neon_integrations.rs @@ -92,8 +92,8 @@ use crate::neon_node::RelayerThread; use crate::operations::BurnchainOpSigner; use crate::stacks_common::types::PrivateKey; use crate::syncctl::PoxSyncWatchdogComms; -use crate::tests::gen_random_port; use crate::tests::nakamoto_integrations::{get_key_for_cycle, wait_for}; +use crate::tests::{gen_random_port, CURRENT_TESTING_EPOCH}; use crate::{neon, BitcoinRegtestController, BurnchainController, Config, ConfigFile, Keychain}; fn inner_neon_integration_test_conf(seed: Option>) -> (Config, StacksAddress) { @@ -2370,7 +2370,7 @@ fn stx_delegate_btc_integration_test() { execute( &format!("{{ hashbytes: 0x{pox_pubkey_hash}, version: 0x00 }}"), ClarityVersion::Clarity2, - StacksEpochId::Epoch32, + CURRENT_TESTING_EPOCH, false, ) .unwrap() @@ -5360,7 +5360,7 @@ fn pox_integration_test() { execute( &format!("{{ hashbytes: 0x{pox_pubkey_hash}, version: 0x00 }}"), ClarityVersion::Clarity1, - StacksEpochId::Epoch32, + CURRENT_TESTING_EPOCH, false, ) .unwrap() @@ -5474,7 +5474,7 @@ fn pox_integration_test() { execute( &format!("{{ hashbytes: 0x{pox_2_pubkey_hash}, version: 0x00 }}"), ClarityVersion::Clarity1, - StacksEpochId::Epoch32, + CURRENT_TESTING_EPOCH, false, ) .unwrap() @@ -5500,7 +5500,7 @@ fn pox_integration_test() { execute( &format!("{{ hashbytes: 0x{pox_2_pubkey_hash}, version: 0x00 }}"), ClarityVersion::Clarity1, - StacksEpochId::Epoch32, + CURRENT_TESTING_EPOCH, false, ) .unwrap()