From cc08e0a614fc3848a84aa664de851ae57f56e415 Mon Sep 17 00:00:00 2001 From: Sergio Chouhy Date: Fri, 5 Dec 2025 17:54:51 -0300 Subject: [PATCH] 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)