fix: cli added

This commit is contained in:
Oleksandr Pravdyvyi 2025-08-06 14:56:58 +03:00
parent 7be870369c
commit c5097ab879
No known key found for this signature in database
GPG Key ID: 9F8955C63C443871
10 changed files with 243 additions and 211 deletions

174
Cargo.lock generated
View File

@ -365,6 +365,56 @@ version = "0.2.21"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923"
[[package]]
name = "anstream"
version = "0.6.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ae563653d1938f79b1ab1b5e668c87c76a9930414574a6583a7b7e11a8e6192"
dependencies = [
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"is_terminal_polyfill",
"utf8parse",
]
[[package]]
name = "anstyle"
version = "1.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "862ed96ca487e809f1c8e5a8447f6ee2cf102f846893800b20cebdf541fc6bbd"
[[package]]
name = "anstyle-parse"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e231f6134f61b71076a3eab506c379d4f36122f2af15a9ff04415ea4c3339e2"
dependencies = [
"windows-sys 0.60.2",
]
[[package]]
name = "anstyle-wincon"
version = "3.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3e0633414522a32ffaac8ac6cc8f748e090c5717661fddeea04219e2344f5f2a"
dependencies = [
"anstyle",
"once_cell_polyfill",
"windows-sys 0.60.2",
]
[[package]] [[package]]
name = "anyhow" name = "anyhow"
version = "1.0.98" version = "1.0.98"
@ -627,17 +677,6 @@ dependencies = [
"critical-section", "critical-section",
] ]
[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [
"hermit-abi 0.1.19",
"libc",
"winapi",
]
[[package]] [[package]]
name = "auto_ops" name = "auto_ops"
version = "0.3.0" version = "0.3.0"
@ -961,42 +1000,43 @@ dependencies = [
[[package]] [[package]]
name = "clap" name = "clap"
version = "3.2.25" version = "4.5.42"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123" checksum = "ed87a9d530bb41a67537289bafcac159cb3ee28460e0a4571123d2a778a6a882"
dependencies = [ dependencies = [
"atty", "clap_builder",
"bitflags 1.3.2",
"clap_derive", "clap_derive",
]
[[package]]
name = "clap_builder"
version = "4.5.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "64f4f3f3c77c94aff3c7e9aac9a2ca1974a5adf392a8bb751e827d6d127ab966"
dependencies = [
"anstream",
"anstyle",
"clap_lex", "clap_lex",
"indexmap 1.9.3", "strsim",
"once_cell",
"strsim 0.10.0",
"termcolor",
"textwrap",
] ]
[[package]] [[package]]
name = "clap_derive" name = "clap_derive"
version = "3.2.25" version = "4.5.41"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae6371b8bdc8b7d3959e9cf7b22d4435ef3e79e138688421ec654acf8c81b008" checksum = "ef4f52386a59ca4c860f7393bcf8abd8dfd91ecccc0f774635ff68e92eeef491"
dependencies = [ dependencies = [
"heck 0.4.1", "heck 0.5.0",
"proc-macro-error",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 1.0.109", "syn 2.0.104",
] ]
[[package]] [[package]]
name = "clap_lex" name = "clap_lex"
version = "0.2.4" version = "0.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" checksum = "b94f61472cee1439c0b966b47e3aca9ae07e45d070759512cd390ea2bebc6675"
dependencies = [
"os_str_bytes",
]
[[package]] [[package]]
name = "cobs" name = "cobs"
@ -1007,6 +1047,12 @@ dependencies = [
"thiserror 2.0.12", "thiserror 2.0.12",
] ]
[[package]]
name = "colorchoice"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75"
[[package]] [[package]]
name = "common" name = "common"
version = "0.1.0" version = "0.1.0"
@ -1237,7 +1283,7 @@ dependencies = [
"ident_case", "ident_case",
"proc-macro2", "proc-macro2",
"quote", "quote",
"strsim 0.11.1", "strsim",
"syn 2.0.104", "syn 2.0.104",
] ]
@ -1927,7 +1973,7 @@ dependencies = [
"futures-sink", "futures-sink",
"futures-util", "futures-util",
"http 0.2.12", "http 0.2.12",
"indexmap 2.10.0", "indexmap",
"slab", "slab",
"tokio", "tokio",
"tokio-util", "tokio-util",
@ -2005,15 +2051,6 @@ version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]]
name = "hermit-abi"
version = "0.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
dependencies = [
"libc",
]
[[package]] [[package]]
name = "hermit-abi" name = "hermit-abi"
version = "0.5.2" version = "0.5.2"
@ -2340,16 +2377,6 @@ version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ee796ad498c8d9a1d68e477df8f754ed784ef875de1414ebdaf169f70a6a784" checksum = "4ee796ad498c8d9a1d68e477df8f754ed784ef875de1414ebdaf169f70a6a784"
[[package]]
name = "indexmap"
version = "1.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99"
dependencies = [
"autocfg",
"hashbrown 0.12.3",
]
[[package]] [[package]]
name = "indexmap" name = "indexmap"
version = "2.10.0" version = "2.10.0"
@ -2435,11 +2462,17 @@ version = "0.4.16"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e04d7f318608d35d4b61ddd75cbdaee86b023ebe2bd5a66ee0915f0bf93095a9" checksum = "e04d7f318608d35d4b61ddd75cbdaee86b023ebe2bd5a66ee0915f0bf93095a9"
dependencies = [ dependencies = [
"hermit-abi 0.5.2", "hermit-abi",
"libc", "libc",
"windows-sys 0.59.0", "windows-sys 0.59.0",
] ]
[[package]]
name = "is_terminal_polyfill"
version = "1.70.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
[[package]] [[package]]
name = "itertools" name = "itertools"
version = "0.10.5" version = "0.10.5"
@ -2943,6 +2976,7 @@ dependencies = [
"actix-rt", "actix-rt",
"anyhow", "anyhow",
"bincode", "bincode",
"clap",
"common", "common",
"elliptic-curve", "elliptic-curve",
"env_logger", "env_logger",
@ -3085,6 +3119,12 @@ version = "1.21.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
[[package]]
name = "once_cell_polyfill"
version = "1.70.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad"
[[package]] [[package]]
name = "opaque-debug" name = "opaque-debug"
version = "0.3.1" version = "0.3.1"
@ -3141,12 +3181,6 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
[[package]]
name = "os_str_bytes"
version = "6.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2355d85b9a3786f481747ced0e0ff2ba35213a1f9bd406ed906554d7af805a1"
[[package]] [[package]]
name = "parking_lot" name = "parking_lot"
version = "0.12.4" version = "0.12.4"
@ -4610,12 +4644,6 @@ dependencies = [
"thiserror 1.0.69", "thiserror 1.0.69",
] ]
[[package]]
name = "strsim"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]] [[package]]
name = "strsim" name = "strsim"
version = "0.11.1" version = "0.11.1"
@ -4754,12 +4782,6 @@ dependencies = [
"risc0-build", "risc0-build",
] ]
[[package]]
name = "textwrap"
version = "0.16.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c13547615a44dc9c452a8a534638acdf07120d4b6847c8178705da06306a3057"
[[package]] [[package]]
name = "thiserror" name = "thiserror"
version = "1.0.69" version = "1.0.69"
@ -4956,7 +4978,7 @@ version = "0.19.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421"
dependencies = [ dependencies = [
"indexmap 2.10.0", "indexmap",
"serde", "serde",
"serde_spanned", "serde_spanned",
"toml_datetime", "toml_datetime",
@ -4969,7 +4991,7 @@ version = "0.22.27"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a" checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a"
dependencies = [ dependencies = [
"indexmap 2.10.0", "indexmap",
"serde", "serde",
"serde_spanned", "serde_spanned",
"toml_datetime", "toml_datetime",
@ -5167,6 +5189,12 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be"
[[package]]
name = "utf8parse"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]] [[package]]
name = "utxo" name = "utxo"
version = "0.1.0" version = "0.1.0"
@ -5821,7 +5849,7 @@ dependencies = [
"crossbeam-utils", "crossbeam-utils",
"displaydoc", "displaydoc",
"flate2", "flate2",
"indexmap 2.10.0", "indexmap",
"memchr", "memchr",
"thiserror 2.0.12", "thiserror 2.0.12",
"zopfli", "zopfli",

View File

@ -70,7 +70,7 @@ version = "=4.1.0"
[workspace.dependencies.clap] [workspace.dependencies.clap]
features = ["derive", "env"] features = ["derive", "env"]
version = "3.1.6" version = "4.5.42"
[workspace.dependencies.tokio-retry] [workspace.dependencies.tokio-retry]
version = "0.3.0" version = "0.3.0"

View File

@ -6,4 +6,5 @@ source env.sh
cargo test --release cargo test --release
cd integration_tests cd integration_tests
export HOME_DIR=$(pwd)/configs/debug/node/
cargo run $(pwd)/configs/debug all cargo run $(pwd)/configs/debug all

View File

@ -3,17 +3,6 @@
"override_rust_log": null, "override_rust_log": null,
"sequencer_addr": "http://127.0.0.1:3040", "sequencer_addr": "http://127.0.0.1:3040",
"seq_poll_timeout_secs": 10, "seq_poll_timeout_secs": 10,
"port": 3041,
"gas_config": {
"gas_fee_per_byte_deploy": 100,
"gas_fee_per_input_buffer_runtime": 1000,
"gas_fee_per_byte_runtime": 10,
"gas_cost_runtime": 100,
"gas_cost_deploy": 1000,
"gas_limit_deploy": 30000000,
"gas_limit_runtime": 30000000
},
"shapshot_frequency_in_blocks": 10,
"initial_accounts": [ "initial_accounts": [
{ {
"address": [ "address": [

View File

@ -1,14 +1,14 @@
use std::{path::PathBuf, sync::Arc, time::Duration}; use std::{path::PathBuf, time::Duration};
use actix_web::dev::ServerHandle; use actix_web::dev::ServerHandle;
use anyhow::Result; use anyhow::Result;
use clap::Parser; use clap::Parser;
use log::info; use log::info;
use node_core::{NodeCore, config::NodeConfig}; use node_core::{Command, fetch_config, sequencer_client::SequencerClient};
use sequencer_core::config::SequencerConfig; use sequencer_core::config::SequencerConfig;
use sequencer_runner::startup_sequencer; use sequencer_runner::startup_sequencer;
use tempfile::TempDir; use tempfile::TempDir;
use tokio::{sync::Mutex, task::JoinHandle}; use tokio::task::JoinHandle;
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
#[clap(version)] #[clap(version)]
@ -27,65 +27,38 @@ pub const TIME_TO_WAIT_FOR_BLOCK_SECONDS: u64 = 12;
#[allow(clippy::type_complexity)] #[allow(clippy::type_complexity)]
pub async fn pre_test( pub async fn pre_test(
home_dir: PathBuf, home_dir: PathBuf,
) -> Result<( ) -> Result<(ServerHandle, JoinHandle<Result<()>>, TempDir)> {
ServerHandle,
JoinHandle<Result<()>>,
TempDir,
TempDir,
Arc<Mutex<NodeCore>>,
)> {
let home_dir_sequencer = home_dir.join("sequencer"); let home_dir_sequencer = home_dir.join("sequencer");
let home_dir_node = home_dir.join("node");
let mut sequencer_config = let mut sequencer_config =
sequencer_runner::config::from_file(home_dir_sequencer.join("sequencer_config.json")) sequencer_runner::config::from_file(home_dir_sequencer.join("sequencer_config.json"))
.unwrap(); .unwrap();
let mut node_config =
node_core::config::from_file(home_dir_node.join("node_config.json")).unwrap();
let (temp_dir_node, temp_dir_sequencer) = let temp_dir_sequencer = replace_home_dir_with_temp_dir_in_configs(&mut sequencer_config);
replace_home_dir_with_temp_dir_in_configs(&mut node_config, &mut sequencer_config);
let (seq_http_server_handle, sequencer_loop_handle) = let (seq_http_server_handle, sequencer_loop_handle) =
startup_sequencer(sequencer_config).await?; startup_sequencer(sequencer_config).await?;
let node_core = NodeCore::start_from_config_update_chain(node_config.clone()).await?;
let wrapped_node_core = Arc::new(Mutex::new(node_core));
Ok(( Ok((
seq_http_server_handle, seq_http_server_handle,
sequencer_loop_handle, sequencer_loop_handle,
temp_dir_node,
temp_dir_sequencer, temp_dir_sequencer,
wrapped_node_core,
)) ))
} }
pub fn replace_home_dir_with_temp_dir_in_configs( pub fn replace_home_dir_with_temp_dir_in_configs(
node_config: &mut NodeConfig,
sequencer_config: &mut SequencerConfig, sequencer_config: &mut SequencerConfig,
) -> (TempDir, TempDir) { ) -> TempDir {
let temp_dir_node = tempfile::tempdir().unwrap();
let temp_dir_sequencer = tempfile::tempdir().unwrap(); let temp_dir_sequencer = tempfile::tempdir().unwrap();
node_config.home = temp_dir_node.path().to_path_buf();
sequencer_config.home = temp_dir_sequencer.path().to_path_buf(); sequencer_config.home = temp_dir_sequencer.path().to_path_buf();
(temp_dir_node, temp_dir_sequencer) temp_dir_sequencer
} }
#[allow(clippy::type_complexity)] #[allow(clippy::type_complexity)]
pub async fn post_test( pub async fn post_test(residual: (ServerHandle, JoinHandle<Result<()>>, TempDir)) {
residual: ( let (seq_http_server_handle, sequencer_loop_handle, _) = residual;
ServerHandle,
JoinHandle<Result<()>>,
TempDir,
TempDir,
Arc<Mutex<NodeCore>>,
),
) {
let (seq_http_server_handle, sequencer_loop_handle, _, _, _) = residual;
info!("Cleanup"); info!("Cleanup");
@ -96,28 +69,28 @@ pub async fn post_test(
//So they are dropped and tempdirs will be dropped too, //So they are dropped and tempdirs will be dropped too,
} }
pub async fn test_success(wrapped_node_core: Arc<Mutex<NodeCore>>) { pub async fn test_success() {
let acc_sender = hex::decode(ACC_SENDER).unwrap().try_into().unwrap(); let command = Command::SendNativeTokenTransfer {
let acc_receiver = hex::decode(ACC_RECEIVER).unwrap().try_into().unwrap(); from: ACC_SENDER.to_string(),
to: ACC_RECEIVER.to_string(),
amount: 100,
};
let guard = wrapped_node_core.lock().await; let node_config = fetch_config().unwrap();
let _res = guard let seq_client = SequencerClient::new(node_config).unwrap();
.send_public_native_token_transfer(acc_sender, 0, acc_receiver, 100)
.await node_core::execute_subcommand(command).await.unwrap();
.unwrap();
info!("Waiting for next block creation"); info!("Waiting for next block creation");
tokio::time::sleep(Duration::from_secs(TIME_TO_WAIT_FOR_BLOCK_SECONDS)).await; tokio::time::sleep(Duration::from_secs(TIME_TO_WAIT_FOR_BLOCK_SECONDS)).await;
info!("Checking correct balance move"); info!("Checking correct balance move");
let acc_1_balance = guard let acc_1_balance = seq_client
.sequencer_client
.get_account_balance(ACC_SENDER.to_string()) .get_account_balance(ACC_SENDER.to_string())
.await .await
.unwrap(); .unwrap();
let acc_2_balance = guard let acc_2_balance = seq_client
.sequencer_client
.get_account_balance(ACC_RECEIVER.to_string()) .get_account_balance(ACC_RECEIVER.to_string())
.await .await
.unwrap(); .unwrap();
@ -131,30 +104,30 @@ pub async fn test_success(wrapped_node_core: Arc<Mutex<NodeCore>>) {
info!("Success!"); info!("Success!");
} }
pub async fn test_success_move_to_another_account(wrapped_node_core: Arc<Mutex<NodeCore>>) { pub async fn test_success_move_to_another_account() {
let acc_sender = hex::decode(ACC_SENDER).unwrap().try_into().unwrap(); let hex_acc_receiver_new_acc = hex::encode([42; 32]);
let acc_receiver_new_acc = [42; 32];
let hex_acc_receiver_new_acc = hex::encode(acc_receiver_new_acc); let command = Command::SendNativeTokenTransfer {
from: ACC_SENDER.to_string(),
to: hex_acc_receiver_new_acc.clone(),
amount: 100,
};
let guard = wrapped_node_core.lock().await; let node_config = fetch_config().unwrap();
let _res = guard let seq_client = SequencerClient::new(node_config).unwrap();
.send_public_native_token_transfer(acc_sender, 0, acc_receiver_new_acc, 100)
.await node_core::execute_subcommand(command).await.unwrap();
.unwrap();
info!("Waiting for next block creation"); info!("Waiting for next block creation");
tokio::time::sleep(Duration::from_secs(TIME_TO_WAIT_FOR_BLOCK_SECONDS)).await; tokio::time::sleep(Duration::from_secs(TIME_TO_WAIT_FOR_BLOCK_SECONDS)).await;
info!("Checking correct balance move"); info!("Checking correct balance move");
let acc_1_balance = guard let acc_1_balance = seq_client
.sequencer_client
.get_account_balance(ACC_SENDER.to_string()) .get_account_balance(ACC_SENDER.to_string())
.await .await
.unwrap(); .unwrap();
let acc_2_balance = guard let acc_2_balance = seq_client
.sequencer_client
.get_account_balance(hex_acc_receiver_new_acc) .get_account_balance(hex_acc_receiver_new_acc)
.await .await
.unwrap(); .unwrap();
@ -168,28 +141,28 @@ pub async fn test_success_move_to_another_account(wrapped_node_core: Arc<Mutex<N
info!("Success!"); info!("Success!");
} }
pub async fn test_failure(wrapped_node_core: Arc<Mutex<NodeCore>>) { pub async fn test_failure() {
let acc_sender = hex::decode(ACC_SENDER).unwrap().try_into().unwrap(); let command = Command::SendNativeTokenTransfer {
let acc_receiver = hex::decode(ACC_RECEIVER).unwrap().try_into().unwrap(); from: ACC_SENDER.to_string(),
to: ACC_RECEIVER.to_string(),
amount: 1000000,
};
let guard = wrapped_node_core.lock().await; let node_config = fetch_config().unwrap();
let _res = guard let seq_client = SequencerClient::new(node_config).unwrap();
.send_public_native_token_transfer(acc_sender, 0, acc_receiver, 100000)
.await node_core::execute_subcommand(command).await.unwrap();
.unwrap();
info!("Waiting for next block creation"); info!("Waiting for next block creation");
tokio::time::sleep(Duration::from_secs(TIME_TO_WAIT_FOR_BLOCK_SECONDS)).await; tokio::time::sleep(Duration::from_secs(TIME_TO_WAIT_FOR_BLOCK_SECONDS)).await;
info!("Checking correct balance move"); info!("Checking correct balance move");
let acc_1_balance = guard let acc_1_balance = seq_client
.sequencer_client
.get_account_balance(ACC_SENDER.to_string()) .get_account_balance(ACC_SENDER.to_string())
.await .await
.unwrap(); .unwrap();
let acc_2_balance = guard let acc_2_balance = seq_client
.sequencer_client
.get_account_balance(ACC_RECEIVER.to_string()) .get_account_balance(ACC_RECEIVER.to_string())
.await .await
.unwrap(); .unwrap();
@ -207,12 +180,10 @@ macro_rules! test_cleanup_wrap {
($home_dir:ident, $test_func:ident) => {{ ($home_dir:ident, $test_func:ident) => {{
let res = pre_test($home_dir.clone()).await.unwrap(); let res = pre_test($home_dir.clone()).await.unwrap();
let wrapped_node_core = res.4.clone();
info!("Waiting for first block creation"); info!("Waiting for first block creation");
tokio::time::sleep(Duration::from_secs(TIME_TO_WAIT_FOR_BLOCK_SECONDS)).await; tokio::time::sleep(Duration::from_secs(TIME_TO_WAIT_FOR_BLOCK_SECONDS)).await;
$test_func(wrapped_node_core.clone()).await; $test_func().await;
post_test(res).await; post_test(res).await;
}}; }};

View File

@ -21,6 +21,7 @@ tempfile.workspace = true
risc0-zkvm = { git = "https://github.com/risc0/risc0.git", branch = "release-2.3" } risc0-zkvm = { git = "https://github.com/risc0/risc0.git", branch = "release-2.3" }
hex.workspace = true hex.workspace = true
actix-rt.workspace = true actix-rt.workspace = true
clap.workspace = true
[dependencies.sc_core] [dependencies.sc_core]
path = "../sc_core" path = "../sc_core"

View File

@ -89,7 +89,6 @@ impl NodeChainStore {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::config::GasConfig;
use accounts::account_core::Account; use accounts::account_core::Account;
use std::path::PathBuf; use std::path::PathBuf;
use tempfile::tempdir; use tempfile::tempdir;
@ -268,42 +267,16 @@ mod tests {
initial_accounts initial_accounts
} }
// fn create_genesis_block() -> Block {
// Block {
// block_id: 0,
// prev_block_id: 0,
// prev_block_hash: [0; 32],
// hash: [1; 32],
// transactions: vec![],
// data: Data::default(),
// }
// }
fn create_sample_node_config(home: PathBuf) -> NodeConfig { fn create_sample_node_config(home: PathBuf) -> NodeConfig {
NodeConfig { NodeConfig {
home, home,
override_rust_log: None, override_rust_log: None,
sequencer_addr: "http://127.0.0.1".to_string(), sequencer_addr: "http://127.0.0.1".to_string(),
seq_poll_timeout_secs: 1, seq_poll_timeout_secs: 1,
port: 8000,
gas_config: create_sample_gas_config(),
shapshot_frequency_in_blocks: 1,
initial_accounts: create_initial_accounts(), initial_accounts: create_initial_accounts(),
} }
} }
fn create_sample_gas_config() -> GasConfig {
GasConfig {
gas_fee_per_byte_deploy: 0,
gas_fee_per_input_buffer_runtime: 0,
gas_fee_per_byte_runtime: 0,
gas_cost_runtime: 0,
gas_cost_deploy: 0,
gas_limit_deploy: 0,
gas_limit_runtime: 0,
}
}
#[test] #[test]
fn test_new_initializes_correctly() { fn test_new_initializes_correctly() {
let temp_dir = tempdir().unwrap(); let temp_dir = tempdir().unwrap();

View File

@ -4,11 +4,6 @@ use accounts::account_core::Account;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use zkvm::gas_calculator::GasCalculator; use zkvm::gas_calculator::GasCalculator;
use anyhow::Result;
use std::fs::File;
use std::io::BufReader;
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GasConfig { pub struct GasConfig {
/// Gas spent per deploying one byte of data /// Gas spent per deploying one byte of data
@ -51,19 +46,6 @@ pub struct NodeConfig {
pub sequencer_addr: String, pub sequencer_addr: String,
///Sequencer polling duration for new blocks in seconds ///Sequencer polling duration for new blocks in seconds
pub seq_poll_timeout_secs: u64, pub seq_poll_timeout_secs: u64,
///Port to listen
pub port: u16,
///Gas config
pub gas_config: GasConfig,
///Frequency of snapshots
pub shapshot_frequency_in_blocks: u64,
///Initial accounts for wallet ///Initial accounts for wallet
pub initial_accounts: Vec<Account>, pub initial_accounts: Vec<Account>,
} }
pub fn from_file(config_home: PathBuf) -> Result<NodeConfig> {
let file = File::open(config_home)?;
let reader = BufReader::new(file);
Ok(serde_json::from_reader(reader)?)
}

View File

@ -1,22 +1,25 @@
use std::sync::Arc; use std::{fs::File, io::BufReader, path::PathBuf, str::FromStr, sync::Arc};
use common::{ use common::{
execution_input::PublicNativeTokenSend, transaction::Transaction, ExecutionFailureKind, execution_input::PublicNativeTokenSend, transaction::Transaction, ExecutionFailureKind,
}; };
use accounts::account_core::{address::AccountAddress, Account}; use accounts::account_core::{address::AccountAddress, Account};
use anyhow::Result; use anyhow::{anyhow, Result};
use chain_storage::NodeChainStore; use chain_storage::NodeChainStore;
use common::transaction::TransactionBody; use common::transaction::TransactionBody;
use config::NodeConfig; use config::NodeConfig;
use log::info;
use sc_core::proofs_circuits::{generate_commitments, pedersen_commitment_vec}; use sc_core::proofs_circuits::{generate_commitments, pedersen_commitment_vec};
use sequencer_client::{json::SendTxResponse, SequencerClient}; use sequencer_client::{json::SendTxResponse, SequencerClient};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use storage::sc_db_utils::DataBlobChangeVariant; use storage::sc_db_utils::DataBlobChangeVariant;
use tokio::sync::RwLock; use tokio::sync::RwLock;
use utxo::utxo_core::UTXO; use utxo::utxo_core::UTXO;
use zkvm::gas_calculator::GasCalculator;
use clap::{Parser, Subcommand};
pub const HOME_DIR_ENV_VAR: &str = "HOME_DIR";
pub const BLOCK_GEN_DELAY_SECS: u64 = 20; pub const BLOCK_GEN_DELAY_SECS: u64 = 20;
pub mod chain_storage; pub mod chain_storage;
@ -74,7 +77,6 @@ pub struct NodeCore {
pub storage: Arc<RwLock<NodeChainStore>>, pub storage: Arc<RwLock<NodeChainStore>>,
pub node_config: NodeConfig, pub node_config: NodeConfig,
pub sequencer_client: Arc<SequencerClient>, pub sequencer_client: Arc<SequencerClient>,
pub gas_calculator: GasCalculator,
} }
impl NodeCore { impl NodeCore {
@ -92,7 +94,6 @@ impl NodeCore {
storage: wrapped_storage, storage: wrapped_storage,
node_config: config.clone(), node_config: config.clone(),
sequencer_client: client.clone(), sequencer_client: client.clone(),
gas_calculator: GasCalculator::from(config.gas_config),
}) })
} }
@ -190,3 +191,67 @@ pub fn generate_commitments_helper(input_utxos: &[UTXO]) -> Vec<[u8; 32]> {
.map(|comm_raw| comm_raw.try_into().unwrap()) .map(|comm_raw| comm_raw.try_into().unwrap())
.collect() .collect()
} }
///Represents CLI command for a wallet
#[derive(Subcommand, Debug, Clone)]
pub enum Command {
SendNativeTokenTransfer {
#[arg(long)]
from: String,
#[arg(long)]
to: String,
#[arg(long)]
amount: u64,
},
}
#[derive(Parser, Debug)]
#[clap(version)]
pub struct Args {
/// Wallet command
#[command(subcommand)]
pub command: Command,
}
pub fn get_home() -> Result<PathBuf> {
Ok(PathBuf::from_str(&std::env::var(HOME_DIR_ENV_VAR)?)?)
}
pub fn fetch_config() -> Result<NodeConfig> {
let config_home = get_home()?;
let file = File::open(config_home.join("node_config.json"))?;
let reader = BufReader::new(file);
Ok(serde_json::from_reader(reader)?)
}
//ToDo: Replace with structures in future
pub fn produce_account_addr_from_hex(hex_str: String) -> Result<[u8; 32]> {
hex::decode(hex_str)?
.try_into()
.map_err(|_| anyhow!("Failed conversion to 32 bytes"))
}
pub async fn execute_subcommand(command: Command) -> Result<()> {
//env_logger::init();
match command {
Command::SendNativeTokenTransfer { from, to, amount } => {
let node_config = fetch_config()?;
let from = produce_account_addr_from_hex(from)?;
let to = produce_account_addr_from_hex(to)?;
let wallet_core = NodeCore::start_from_config_update_chain(node_config).await?;
//ToDo: Nonce management
let res = wallet_core
.send_public_native_token_transfer(from, 0, to, amount)
.await?;
info!("Results of tx send is {res:#?}");
}
}
Ok(())
}

22
node_core/src/main.rs Normal file
View File

@ -0,0 +1,22 @@
use anyhow::Result;
use clap::Parser;
use node_core::{execute_subcommand, Args};
use tokio::runtime::Builder;
pub const NUM_THREADS: usize = 2;
fn main() -> Result<()> {
let runtime = Builder::new_multi_thread()
.worker_threads(NUM_THREADS)
.enable_all()
.build()
.unwrap();
let args = Args::parse();
runtime.block_on(async move {
execute_subcommand(args.command).await.unwrap();
});
Ok(())
}