add deploy program command

This commit is contained in:
Sergio Chouhy 2025-12-05 17:54:51 -03:00
parent 09116830c9
commit cc08e0a614
4 changed files with 27 additions and 7 deletions

View File

@ -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}")

View File

@ -1441,15 +1441,18 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
#[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<String, TestFunction> {
// 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(

View File

@ -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<SubcommandReturnValu
.handle_subcommand(&mut wallet_core)
.await?
}
Command::DeployProgram { binary_filepath } => {
let bytecode: Vec<u8> = 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)