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 582a093..8012e17 100644 --- a/integration_tests/src/test_suite_map.rs +++ b/integration_tests/src/test_suite_map.rs @@ -11,7 +11,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; @@ -1595,15 +1595,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: PathBuf = NSSA_PROGRAM_FOR_TEST_DATA_CHANGER.parse().unwrap(); + + 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; @@ -1611,6 +1614,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 eb83f98..61b8697 100644 --- a/wallet/src/cli/mod.rs +++ b/wallet/src/cli/mod.rs @@ -1,8 +1,8 @@ -use std::io::Write; +use std::{io::Write, path::PathBuf}; -use anyhow::Result; +use anyhow::{Context, Result}; use clap::{Parser, Subcommand}; -use nssa::program::Program; +use nssa::{ProgramDeploymentTransaction, program::Program}; use crate::{ WalletCore, @@ -61,6 +61,8 @@ pub enum Command { /// Indicates, how deep in tree accounts may be. Affects command complexity. depth: u32, }, + /// Deploy a program + DeployProgram { binary_filepath: PathBuf }, } /// To execute commands, env var NSSA_WALLET_HOME_DIR must be set into directory with config @@ -172,6 +174,21 @@ pub async fn execute_subcommand_with_auth( let password = read_password_from_stdin()?; execute_keys_restoration_with_auth(password, depth, auth).await?; + SubcommandReturnValue::Empty + } + Command::DeployProgram { binary_filepath } => { + let bytecode: Vec = std::fs::read(&binary_filepath).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 + .context("Transaction submission error"); + SubcommandReturnValue::Empty } };