From ab6ea1f4c03b1f4c3273009a74733b32e0108ad9 Mon Sep 17 00:00:00 2001 From: Sergio Chouhy Date: Tue, 9 Dec 2025 15:18:48 -0300 Subject: [PATCH] use pathbuf and context --- integration_tests/src/test_suite_map.rs | 2 +- wallet/src/cli/mod.rs | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/integration_tests/src/test_suite_map.rs b/integration_tests/src/test_suite_map.rs index 5c9b46c..c7116fe 100644 --- a/integration_tests/src/test_suite_map.rs +++ b/integration_tests/src/test_suite_map.rs @@ -1442,7 +1442,7 @@ pub fn prepare_function_map() -> HashMap { pub async fn test_program_deployment() { info!("########## test program deployment ##########"); - let binary_filepath = NSSA_PROGRAM_FOR_TEST_DATA_CHANGER.to_string(); + let binary_filepath: PathBuf = NSSA_PROGRAM_FOR_TEST_DATA_CHANGER.parse().unwrap(); let command = Command::DeployProgram { binary_filepath: binary_filepath.clone(), diff --git a/wallet/src/cli/mod.rs b/wallet/src/cli/mod.rs index 69d7ccb..741f280 100644 --- a/wallet/src/cli/mod.rs +++ b/wallet/src/cli/mod.rs @@ -1,4 +1,6 @@ -use anyhow::Result; +use std::path::PathBuf; + +use anyhow::{Context, Result}; use clap::{Parser, Subcommand}; use nssa::{ProgramDeploymentTransaction, program::Program}; @@ -52,7 +54,7 @@ pub enum Command { #[command(subcommand)] Config(ConfigSubcommand), /// Deploy a program - DeployProgram { binary_filepath: String }, + DeployProgram { binary_filepath: PathBuf }, } /// Represents overarching CLI command for a wallet with setup included @@ -157,14 +159,19 @@ pub async fn execute_subcommand(command: Command) -> Result { - let bytecode: Vec = std::fs::read(binary_filepath).expect("File not found"); + let bytecode: Vec = std::fs::read(&binary_filepath).with_context(|| { + format!( + "Failed to read program binary at {}", + binary_filepath.display() + ) + })?; let message = nssa::program_deployment_transaction::Message::new(bytecode); let transaction = ProgramDeploymentTransaction::new(message); let response = wallet_core .sequencer_client .send_tx_program(transaction) .await - .expect("Transaction submission error"); + .with_context(|| "Transaction submission error"); println!("Response: {:?}", response); SubcommandReturnValue::Empty