Skip to content

Commit 300a72a

Browse files
committed
Fix run return value, print test cost bounds
1 parent e271c99 commit 300a72a

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

src/commands/run.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ pub enum Logging {
5252
}
5353

5454
pub fn run(args: RunArgs) -> Result<()> {
55+
let res = run_inner(args)?;
56+
println!("{}", res);
57+
Ok(())
58+
}
59+
60+
pub(crate) fn run_inner(args: RunArgs) -> Result<String> {
5561
let witness = if let Some(witness_path) = args.build.witness {
5662
load_witness(Some(&witness_path))?
5763
} else {
@@ -78,26 +84,31 @@ pub fn run(args: RunArgs) -> Result<()> {
7884
false,
7985
);
8086

81-
if let Some(logging) = args.logging {
87+
let res = if let Some(logging) = args.logging {
8288
let mut machine = BitMachine::for_program(node)?;
8389
let mut tracker = tracker::Tracker {
8490
debug_symbols: satisfied.debug_symbols(),
8591
debug_logs: logging >= Logging::Debug,
8692
jet_traces: logging == Logging::Trace,
8793
};
8894
let res = machine.exec_with_tracker(node, &env, &mut tracker)?;
89-
println!("Result: {}", res);
95+
format!("Result: {}", res)
9096
} else {
9197
let (program_bytes, witness_bytes) = node.encode_to_vec();
92-
run_program(
98+
let output = run_program(
9399
&program_bytes,
94100
&witness_bytes,
95101
TestUpTo::Everything,
96102
None,
97103
Some(env.c_tx_env()),
98104
)
99105
.map_err(|e| anyhow::anyhow!("Failed to run program: {}", e))?;
100-
}
106+
output
107+
.eval_result
108+
.into_result()
109+
.map_err(|e| anyhow::anyhow!("Program exited with error: {}", e))?;
110+
format!("Cost bound: {}", output.cost_bound)
111+
};
101112

102-
Ok(())
113+
Ok(res)
103114
}

src/commands/sign.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
use anyhow::{Context, Result};
22
use clap::Args;
3-
use elements::hashes::sha256;
4-
use elements::hashes::Hash as _;
53
use elements::secp256k1_zkp::{
64
rand::rngs::OsRng, Keypair, Message, Secp256k1, SecretKey, XOnlyPublicKey,
75
};
@@ -23,8 +21,7 @@ pub fn sign(args: SignArgs) -> Result<()> {
2321
let msg_bytes = Vec::from_hex(&args.message).with_context(|| "Failed to decode message hex")?;
2422
anyhow::ensure!(!msg_bytes.is_empty(), "Message must not be empty");
2523

26-
let digest = sha256::Hash::hash(&msg_bytes);
27-
let msg = Message::from_digest_slice(digest.as_ref())
24+
let msg = Message::from_digest_slice(msg_bytes.as_ref())
2825
.with_context(|| "Failed to construct message for signing")?;
2926

3027
// Obtain or generate secret key

src/commands/test.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ use std::path::PathBuf;
55
use std::{fs, path::Path};
66
use walkdir::WalkDir;
77

8-
use crate::commands::{run, BuildArgs, Logging, RunArgs};
8+
use crate::commands::run::run_inner;
9+
use crate::commands::{BuildArgs, Logging, RunArgs};
910

1011
// Colors for output
1112
const GREEN: &str = "\x1b[0;32m";
@@ -25,6 +26,7 @@ pub struct TestArgs {
2526
#[derive(Debug)]
2627
struct TestResult {
2728
name: String,
29+
message: String,
2830
success: bool,
2931
error_message: Option<String>,
3032
}
@@ -54,7 +56,7 @@ pub fn test(args: TestArgs) -> Result<()> {
5456
let result = run_single_test(&file_path, &test_func, &test_name, &args)?;
5557

5658
if result.success {
57-
println!("{}ok{}", GREEN, NC);
59+
println!("{}ok{} ({})", GREEN, NC, result.message);
5860
passed_tests += 1;
5961
} else {
6062
println!("{}err{}", RED, NC);
@@ -210,14 +212,16 @@ fn run_single_test(
210212
run_args.build.entrypoint = temp_file;
211213

212214
// Call run function directly
213-
match run(run_args) {
214-
Ok(_) => Ok(TestResult {
215+
match run_inner(run_args) {
216+
Ok(res) => Ok(TestResult {
215217
name: test_name.to_string(),
218+
message: res.to_lowercase(),
216219
success: true,
217220
error_message: None,
218221
}),
219222
Err(e) => Ok(TestResult {
220223
name: test_name.to_string(),
224+
message: e.to_string(),
221225
success: false,
222226
// Use pretty Display with full context chain
223227
error_message: Some(format!("{:#}", e)),

0 commit comments

Comments
 (0)