From cc08e0a614fc3848a84aa664de851ae57f56e415 Mon Sep 17 00:00:00 2001 From: Sergio Chouhy Date: Fri, 5 Dec 2025 17:54:51 -0300 Subject: [PATCH 1/4] add deploy program command --- integration_tests/{src => }/data_changer.bin | Bin integration_tests/src/lib.rs | 2 +- integration_tests/src/test_suite_map.rs | 15 ++++++++++----- wallet/src/cli/mod.rs | 17 ++++++++++++++++- 4 files changed, 27 insertions(+), 7 deletions(-) rename integration_tests/{src => }/data_changer.bin (100%) diff --git a/integration_tests/src/data_changer.bin b/integration_tests/data_changer.bin similarity index 100% rename from integration_tests/src/data_changer.bin rename to integration_tests/data_changer.bin diff --git a/integration_tests/src/lib.rs b/integration_tests/src/lib.rs index 31cd177..401238f 100644 --- a/integration_tests/src/lib.rs +++ b/integration_tests/src/lib.rs @@ -42,7 +42,7 @@ pub const ACC_RECEIVER_PRIVATE: &str = "AKTcXgJ1xoynta1Ec7y6Jso1z1JQtHqd7aPQ1h9e pub const TIME_TO_WAIT_FOR_BLOCK_SECONDS: u64 = 12; -pub const NSSA_PROGRAM_FOR_TEST_DATA_CHANGER: &[u8] = include_bytes!("data_changer.bin"); +pub const NSSA_PROGRAM_FOR_TEST_DATA_CHANGER: &str = "data_changer.bin"; fn make_public_account_input_from_str(account_id: &str) -> String { format!("Public/{account_id}") diff --git a/integration_tests/src/test_suite_map.rs b/integration_tests/src/test_suite_map.rs index 1c5f91f..6b06479 100644 --- a/integration_tests/src/test_suite_map.rs +++ b/integration_tests/src/test_suite_map.rs @@ -1441,15 +1441,18 @@ pub fn prepare_function_map() -> HashMap { #[nssa_integration_test] pub async fn test_program_deployment() { info!("########## test program deployment ##########"); - let bytecode = NSSA_PROGRAM_FOR_TEST_DATA_CHANGER.to_vec(); - let message = nssa::program_deployment_transaction::Message::new(bytecode.clone()); - let transaction = ProgramDeploymentTransaction::new(message); + + let binary_filepath = NSSA_PROGRAM_FOR_TEST_DATA_CHANGER.to_string(); + + let command = Command::DeployProgram { + binary_filepath: binary_filepath.clone(), + }; + + wallet::cli::execute_subcommand(command).await.unwrap(); let wallet_config = fetch_config().await.unwrap(); let seq_client = SequencerClient::new(wallet_config.sequencer_addr.clone()).unwrap(); - let _response = seq_client.send_tx_program(transaction).await.unwrap(); - info!("Waiting for next block creation"); tokio::time::sleep(Duration::from_secs(TIME_TO_WAIT_FOR_BLOCK_SECONDS)).await; @@ -1457,6 +1460,8 @@ pub fn prepare_function_map() -> HashMap { // We pass an uninitialized account and we expect after execution to be owned by the data // changer program (NSSA account claiming mechanism) with data equal to [0] (due to program // logic) + // + let bytecode = std::fs::read(binary_filepath).unwrap(); let data_changer = Program::new(bytecode).unwrap(); let account_id: AccountId = "11".repeat(16).parse().unwrap(); let message = nssa::public_transaction::Message::try_new( diff --git a/wallet/src/cli/mod.rs b/wallet/src/cli/mod.rs index eb4e891..69d7ccb 100644 --- a/wallet/src/cli/mod.rs +++ b/wallet/src/cli/mod.rs @@ -1,6 +1,6 @@ use anyhow::Result; use clap::{Parser, Subcommand}; -use nssa::program::Program; +use nssa::{ProgramDeploymentTransaction, program::Program}; use crate::{ WalletCore, @@ -51,6 +51,8 @@ pub enum Command { /// Command to setup config, get and set config fields #[command(subcommand)] Config(ConfigSubcommand), + /// Deploy a program + DeployProgram { binary_filepath: String }, } /// Represents overarching CLI command for a wallet with setup included @@ -154,6 +156,19 @@ pub async fn execute_subcommand(command: Command) -> Result { + let bytecode: Vec = std::fs::read(binary_filepath).expect("File not found"); + 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"); + println!("Response: {:?}", response); + + SubcommandReturnValue::Empty + } }; Ok(subcommand_ret) From 7825f69e06e319292c8db553be5f0f4b6d71bcce Mon Sep 17 00:00:00 2001 From: Sergio Chouhy Date: Fri, 5 Dec 2025 17:57:48 -0300 Subject: [PATCH 2/4] remove unused import --- integration_tests/src/test_suite_map.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration_tests/src/test_suite_map.rs b/integration_tests/src/test_suite_map.rs index 6b06479..5c9b46c 100644 --- a/integration_tests/src/test_suite_map.rs +++ b/integration_tests/src/test_suite_map.rs @@ -10,7 +10,7 @@ use anyhow::Result; use common::{PINATA_BASE58, sequencer_client::SequencerClient}; use key_protocol::key_management::key_tree::chain_index::ChainIndex; use log::info; -use nssa::{AccountId, ProgramDeploymentTransaction, program::Program}; +use nssa::{AccountId, program::Program}; use nssa_core::{NullifierPublicKey, encryption::shared_key_derivation::Secp256k1Point}; use sequencer_runner::startup_sequencer; use tempfile::TempDir; From 8cfb586bee7430424228616faf1afcc9d753646b Mon Sep 17 00:00:00 2001 From: Sergio Chouhy <41742639+schouhy@users.noreply.github.com> Date: Tue, 9 Dec 2025 14:55:12 -0300 Subject: [PATCH 3/4] Update wallet/src/cli/mod.rs Co-authored-by: Daniil Polyakov --- wallet/src/cli/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wallet/src/cli/mod.rs b/wallet/src/cli/mod.rs index 69d7ccb..1b4c779 100644 --- a/wallet/src/cli/mod.rs +++ b/wallet/src/cli/mod.rs @@ -165,7 +165,7 @@ pub async fn execute_subcommand(command: Command) -> Result Date: Tue, 9 Dec 2025 15:18:48 -0300 Subject: [PATCH 4/4] 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