Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add flag to skip deploy prompt in 'run' command #135

Merged
merged 2 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions crates/cli/src/commands/contender_subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,13 @@ May be specified multiple times."
default_value = "100"
)]
txs_per_duration: usize,

#[arg(
long,
long_help = "Skip the deploy prompt. Contracts will only be deployed if not found in DB.",
visible_aliases = &["sdp"]
)]
skip_deploy_prompt: bool,
// TODO: DRY duplicate args
},
}
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use clap::Parser;
pub use contender_subcommand::{ContenderSubcommand, DbCommand};
pub use db::*;
pub use report::report;
pub use run::run;
pub use run::{run, RunCommandArgs};
pub use setup::setup;
pub use spam::{spam, SpamCommandArgs};

Expand Down
50 changes: 30 additions & 20 deletions crates/cli/src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,26 @@ use crate::{
util::{check_private_keys, get_signers_with_defaults, prompt_cli},
};

pub struct RunCommandArgs {
pub scenario: BuiltinScenario,
pub rpc_url: String,
pub private_key: Option<String>,
pub interval: usize,
pub duration: usize,
pub txs_per_duration: usize,
pub skip_deploy_prompt: bool,
}

pub async fn run(
db: &(impl DbOps + Clone + Send + Sync + 'static),
scenario: BuiltinScenario,
rpc_url: String,
private_key: Option<String>,
interval: usize,
duration: usize,
txs_per_duration: usize,
args: RunCommandArgs,
) -> Result<(), Box<dyn std::error::Error>> {
let user_signers = get_signers_with_defaults(private_key.map(|s| vec![s]));
let user_signers = get_signers_with_defaults(args.private_key.map(|s| vec![s]));
let admin_signer = &user_signers[0];
let rand_seed = RandSeed::default();
let provider = ProviderBuilder::new()
.network::<AnyNetwork>()
.on_http(Url::parse(&rpc_url).expect("Invalid RPC URL"));
.on_http(Url::parse(&args.rpc_url).expect("Invalid RPC URL"));
let block_gas_limit = provider
.get_block(BlockId::latest(), BlockTransactionsKind::Hashes)
.await?
Expand All @@ -50,10 +55,10 @@ pub async fn run(
.map(|s| u16::from_str(&s).expect("invalid u16: fill_percent"))
.unwrap_or(100u16);

let scenario_config = match scenario {
let scenario_config = match args.scenario {
BuiltinScenario::FillBlock => BuiltinScenarioConfig::fill_block(
block_gas_limit,
txs_per_duration as u64,
args.txs_per_duration as u64,
admin_signer.address(),
fill_percent,
),
Expand All @@ -62,7 +67,7 @@ pub async fn run(
let testconfig: TestConfig = scenario_config.into();
check_private_keys(&testconfig, &user_signers);

let rpc_url = Url::parse(&rpc_url).expect("Invalid RPC URL");
let rpc_url = Url::parse(&args.rpc_url).expect("Invalid RPC URL");
let mut scenario = TestScenario::new(
testconfig,
db.clone().into(),
Expand All @@ -76,12 +81,17 @@ pub async fn run(

let contract_name = "SpamMe";
let contract_result = db.get_named_tx(contract_name, rpc_url.as_str())?;

let do_deploy_contracts = if contract_result.is_some() {
let input = prompt_cli(format!(
"{} deployment already detected. Re-deploy? [y/N]",
contract_name
));
input.to_lowercase() == "y"
if args.skip_deploy_prompt {
false
} else {
let input = prompt_cli(format!(
"{} deployment already detected. Re-deploy? [y/N]",
contract_name
));
input.to_lowercase() == "y"
}
} else {
true
};
Expand All @@ -94,15 +104,15 @@ pub async fn run(
println!("running setup...");
scenario.run_setup().await?;

let wait_duration = std::time::Duration::from_secs(interval as u64);
let wait_duration = std::time::Duration::from_secs(args.interval as u64);
let spammer = TimedSpammer::new(wait_duration);
let timestamp = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.expect("Time went backwards")
.as_millis();
let run_id = db.insert_run(
timestamp as u64,
duration * txs_per_duration,
args.duration * args.txs_per_duration,
&format!("{} ({})", contract_name, scenario_name),
)?;
let callback = LogCallback::new(Arc::new(DynProvider::new(
Expand All @@ -115,8 +125,8 @@ pub async fn run(
spammer
.spam_rpc(
&mut scenario,
txs_per_duration,
duration,
args.txs_per_duration,
args.duration,
Some(run_id),
callback.into(),
)
Expand Down
18 changes: 11 additions & 7 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod util;
use std::sync::LazyLock;

use alloy::hex;
use commands::{ContenderCli, ContenderSubcommand, DbCommand, SpamCommandArgs};
use commands::{ContenderCli, ContenderSubcommand, DbCommand, RunCommandArgs, SpamCommandArgs};
use contender_core::{db::DbOps, generator::RandSeed};
use contender_sqlite::SqliteDb;
use rand::Rng;
Expand Down Expand Up @@ -116,15 +116,19 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
interval,
duration,
txs_per_duration,
skip_deploy_prompt,
} => {
commands::run(
&db,
scenario,
rpc_url,
private_key,
interval,
duration,
txs_per_duration,
RunCommandArgs {
scenario,
rpc_url,
private_key,
interval,
duration,
txs_per_duration,
skip_deploy_prompt,
},
)
.await?
}
Expand Down
Loading