mirror of
https://github.com/logos-blockchain/logos-execution-zone.git
synced 2026-07-25 23:23:11 +00:00
fix: cli added
This commit is contained in:
@@ -3,17 +3,6 @@
|
||||
"override_rust_log": null,
|
||||
"sequencer_addr": "http://127.0.0.1:3040",
|
||||
"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": [
|
||||
{
|
||||
"address": [
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
use std::{path::PathBuf, sync::Arc, time::Duration};
|
||||
use std::{path::PathBuf, time::Duration};
|
||||
|
||||
use actix_web::dev::ServerHandle;
|
||||
use anyhow::Result;
|
||||
use clap::Parser;
|
||||
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_runner::startup_sequencer;
|
||||
use tempfile::TempDir;
|
||||
use tokio::{sync::Mutex, task::JoinHandle};
|
||||
use tokio::task::JoinHandle;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[clap(version)]
|
||||
@@ -27,65 +27,38 @@ pub const TIME_TO_WAIT_FOR_BLOCK_SECONDS: u64 = 12;
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub async fn pre_test(
|
||||
home_dir: PathBuf,
|
||||
) -> Result<(
|
||||
ServerHandle,
|
||||
JoinHandle<Result<()>>,
|
||||
TempDir,
|
||||
TempDir,
|
||||
Arc<Mutex<NodeCore>>,
|
||||
)> {
|
||||
) -> Result<(ServerHandle, JoinHandle<Result<()>>, TempDir)> {
|
||||
let home_dir_sequencer = home_dir.join("sequencer");
|
||||
let home_dir_node = home_dir.join("node");
|
||||
|
||||
let mut sequencer_config =
|
||||
sequencer_runner::config::from_file(home_dir_sequencer.join("sequencer_config.json"))
|
||||
.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) =
|
||||
replace_home_dir_with_temp_dir_in_configs(&mut node_config, &mut sequencer_config);
|
||||
let temp_dir_sequencer = replace_home_dir_with_temp_dir_in_configs(&mut sequencer_config);
|
||||
|
||||
let (seq_http_server_handle, sequencer_loop_handle) =
|
||||
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((
|
||||
seq_http_server_handle,
|
||||
sequencer_loop_handle,
|
||||
temp_dir_node,
|
||||
temp_dir_sequencer,
|
||||
wrapped_node_core,
|
||||
))
|
||||
}
|
||||
|
||||
pub fn replace_home_dir_with_temp_dir_in_configs(
|
||||
node_config: &mut NodeConfig,
|
||||
sequencer_config: &mut SequencerConfig,
|
||||
) -> (TempDir, TempDir) {
|
||||
let temp_dir_node = tempfile::tempdir().unwrap();
|
||||
) -> TempDir {
|
||||
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();
|
||||
|
||||
(temp_dir_node, temp_dir_sequencer)
|
||||
temp_dir_sequencer
|
||||
}
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub async fn post_test(
|
||||
residual: (
|
||||
ServerHandle,
|
||||
JoinHandle<Result<()>>,
|
||||
TempDir,
|
||||
TempDir,
|
||||
Arc<Mutex<NodeCore>>,
|
||||
),
|
||||
) {
|
||||
let (seq_http_server_handle, sequencer_loop_handle, _, _, _) = residual;
|
||||
pub async fn post_test(residual: (ServerHandle, JoinHandle<Result<()>>, TempDir)) {
|
||||
let (seq_http_server_handle, sequencer_loop_handle, _) = residual;
|
||||
|
||||
info!("Cleanup");
|
||||
|
||||
@@ -96,28 +69,28 @@ pub async fn post_test(
|
||||
//So they are dropped and tempdirs will be dropped too,
|
||||
}
|
||||
|
||||
pub async fn test_success(wrapped_node_core: Arc<Mutex<NodeCore>>) {
|
||||
let acc_sender = hex::decode(ACC_SENDER).unwrap().try_into().unwrap();
|
||||
let acc_receiver = hex::decode(ACC_RECEIVER).unwrap().try_into().unwrap();
|
||||
pub async fn test_success() {
|
||||
let command = Command::SendNativeTokenTransfer {
|
||||
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
|
||||
.send_public_native_token_transfer(acc_sender, 0, acc_receiver, 100)
|
||||
.await
|
||||
.unwrap();
|
||||
let seq_client = SequencerClient::new(node_config).unwrap();
|
||||
|
||||
node_core::execute_subcommand(command).await.unwrap();
|
||||
|
||||
info!("Waiting for next block creation");
|
||||
tokio::time::sleep(Duration::from_secs(TIME_TO_WAIT_FOR_BLOCK_SECONDS)).await;
|
||||
|
||||
info!("Checking correct balance move");
|
||||
let acc_1_balance = guard
|
||||
.sequencer_client
|
||||
let acc_1_balance = seq_client
|
||||
.get_account_balance(ACC_SENDER.to_string())
|
||||
.await
|
||||
.unwrap();
|
||||
let acc_2_balance = guard
|
||||
.sequencer_client
|
||||
let acc_2_balance = seq_client
|
||||
.get_account_balance(ACC_RECEIVER.to_string())
|
||||
.await
|
||||
.unwrap();
|
||||
@@ -131,30 +104,30 @@ pub async fn test_success(wrapped_node_core: Arc<Mutex<NodeCore>>) {
|
||||
info!("Success!");
|
||||
}
|
||||
|
||||
pub async fn test_success_move_to_another_account(wrapped_node_core: Arc<Mutex<NodeCore>>) {
|
||||
let acc_sender = hex::decode(ACC_SENDER).unwrap().try_into().unwrap();
|
||||
let acc_receiver_new_acc = [42; 32];
|
||||
pub async fn test_success_move_to_another_account() {
|
||||
let hex_acc_receiver_new_acc = hex::encode([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
|
||||
.send_public_native_token_transfer(acc_sender, 0, acc_receiver_new_acc, 100)
|
||||
.await
|
||||
.unwrap();
|
||||
let seq_client = SequencerClient::new(node_config).unwrap();
|
||||
|
||||
node_core::execute_subcommand(command).await.unwrap();
|
||||
|
||||
info!("Waiting for next block creation");
|
||||
tokio::time::sleep(Duration::from_secs(TIME_TO_WAIT_FOR_BLOCK_SECONDS)).await;
|
||||
|
||||
info!("Checking correct balance move");
|
||||
let acc_1_balance = guard
|
||||
.sequencer_client
|
||||
let acc_1_balance = seq_client
|
||||
.get_account_balance(ACC_SENDER.to_string())
|
||||
.await
|
||||
.unwrap();
|
||||
let acc_2_balance = guard
|
||||
.sequencer_client
|
||||
let acc_2_balance = seq_client
|
||||
.get_account_balance(hex_acc_receiver_new_acc)
|
||||
.await
|
||||
.unwrap();
|
||||
@@ -168,28 +141,28 @@ pub async fn test_success_move_to_another_account(wrapped_node_core: Arc<Mutex<N
|
||||
info!("Success!");
|
||||
}
|
||||
|
||||
pub async fn test_failure(wrapped_node_core: Arc<Mutex<NodeCore>>) {
|
||||
let acc_sender = hex::decode(ACC_SENDER).unwrap().try_into().unwrap();
|
||||
let acc_receiver = hex::decode(ACC_RECEIVER).unwrap().try_into().unwrap();
|
||||
pub async fn test_failure() {
|
||||
let command = Command::SendNativeTokenTransfer {
|
||||
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
|
||||
.send_public_native_token_transfer(acc_sender, 0, acc_receiver, 100000)
|
||||
.await
|
||||
.unwrap();
|
||||
let seq_client = SequencerClient::new(node_config).unwrap();
|
||||
|
||||
node_core::execute_subcommand(command).await.unwrap();
|
||||
|
||||
info!("Waiting for next block creation");
|
||||
tokio::time::sleep(Duration::from_secs(TIME_TO_WAIT_FOR_BLOCK_SECONDS)).await;
|
||||
|
||||
info!("Checking correct balance move");
|
||||
let acc_1_balance = guard
|
||||
.sequencer_client
|
||||
let acc_1_balance = seq_client
|
||||
.get_account_balance(ACC_SENDER.to_string())
|
||||
.await
|
||||
.unwrap();
|
||||
let acc_2_balance = guard
|
||||
.sequencer_client
|
||||
let acc_2_balance = seq_client
|
||||
.get_account_balance(ACC_RECEIVER.to_string())
|
||||
.await
|
||||
.unwrap();
|
||||
@@ -207,12 +180,10 @@ macro_rules! test_cleanup_wrap {
|
||||
($home_dir:ident, $test_func:ident) => {{
|
||||
let res = pre_test($home_dir.clone()).await.unwrap();
|
||||
|
||||
let wrapped_node_core = res.4.clone();
|
||||
|
||||
info!("Waiting for first block creation");
|
||||
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;
|
||||
}};
|
||||
|
||||
Reference in New Issue
Block a user