Skip to content
Open
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: 1 addition & 6 deletions crates/cli/src/default_scenarios/blobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ fn blob_txs(blob_data: impl AsRef<str>, recipient: Option<String>) -> Vec<SpamRe

impl ToTestConfig for BlobsCliArgs {
fn to_testconfig(&self) -> contender_testfile::TestConfig {
TestConfig {
env: None,
create: None,
setup: None,
spam: Some(blob_txs(&self.blob_data, self.recipient.to_owned())),
}
TestConfig::new().with_spam(blob_txs(&self.blob_data, self.recipient.to_owned()))
}
}
10 changes: 5 additions & 5 deletions crates/cli/src/default_scenarios/contracts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@ use alloy::primitives::U256;
use contender_core::generator::CompiledContract;

pub const COUNTER: CompiledContract<&'static str> = CompiledContract {
bytecode: include_str!("./Counter.hex"),
bytecode: include_str!("../../../../../scenarios/contracts/Counter.hex"),
name: "Counter",
};

pub const SMART_WALLET: CompiledContract<&'static str> = CompiledContract {
bytecode: include_str!("./SmartWallet.hex"),
bytecode: include_str!("../../../../../scenarios/contracts/SmartWallet.hex"),
name: "SmartWallet",
};

pub const SPAM_ME: CompiledContract<&'static str> = CompiledContract {
bytecode: include_str!("./SpamMe.hex"),
bytecode: include_str!("../../../../../scenarios/contracts/SpamMe.hex"),
name: "SpamMe5",
};

pub const SPAM_ME_6: CompiledContract<&'static str> = CompiledContract {
bytecode: include_str!("./SpamMe6.hex"),
bytecode: include_str!("../../../../../scenarios/contracts/SpamMe6.hex"),
name: "SpamMe6",
};

/// A simple token contract for testing purposes.
/// This contract takes a constructor argument for the initial supply, which must be abi-encoded and appended to the bytecode.
pub const TEST_TOKEN: CompiledContract<&'static str> = CompiledContract {
bytecode: include_str!("./TestToken.hex"),
bytecode: include_str!("../../../../../scenarios/contracts/TestToken.hex"),
name: "testToken",
};

Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/default_scenarios/custom_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ impl NameAndArgs {
impl ToTestConfig for CustomContractArgs {
fn to_testconfig(&self) -> contender_testfile::TestConfig {
TestConfig::new()
.with_create(vec![CreateDefinition::new(&self.contract)])
.with_create(vec![CreateDefinition::new(&self.contract.clone().into())])
.with_setup(self.setup.to_owned())
.with_spam(self.spam.iter().map(SpamRequest::new_tx).collect())
}
Expand Down
75 changes: 37 additions & 38 deletions crates/cli/src/default_scenarios/erc20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,48 +69,47 @@ impl ToTestConfig for Erc20Args {
.with_args(&[recipient.to_string(), self.fund_amount.to_string()])
})
.collect();
let spam_steps = vec![SpamRequest::new_tx(&{
let mut func_def = FunctionCallDefinition::new(token.template_name())
.with_from_pool("spammers") // Senders from limited pool
.with_signature("transfer(address guy, uint256 wad)")
.with_args(&[
// Use token_recipient if provided (via --recipient flag),
// otherwise this is a placeholder for fuzzing
self.token_recipient
.as_ref()
.map(|addr| addr.to_string())
.unwrap_or_else(|| {
"0x0000000000000000000000000000000000000000".to_string()
}),
self.send_amount.to_string(),
])
.with_gas_limit(55000);

TestConfig {
env: None,
create: Some(vec![CreateDefinition {
contract: token.to_owned(),
// Only add fuzzing if token_recipient is NOT provided
if self.token_recipient.is_none() {
func_def = func_def.with_fuzz(&[FuzzParam {
param: Some("guy".to_string()),
value: None,
min: Some(U256::from(1)),
max: Some(
U256::from_str("0x0000000000ffffffffffffffffffffffffffffffff").unwrap(),
),
}]);
}

func_def
})];

TestConfig::new()
.with_create(vec![CreateDefinition {
contract: token.to_owned().into(),
signature: None,
args: None,
from: None,
from_pool: Some("admin".to_owned()),
}]),
setup: Some(setup_steps),
spam: Some(vec![SpamRequest::new_tx(&{
let mut func_def = FunctionCallDefinition::new(token.template_name())
.with_from_pool("spammers") // Senders from limited pool
.with_signature("transfer(address guy, uint256 wad)")
.with_args(&[
// Use token_recipient if provided (via --recipient flag),
// otherwise this is a placeholder for fuzzing
self.token_recipient
.as_ref()
.map(|addr| addr.to_string())
.unwrap_or_else(|| {
"0x0000000000000000000000000000000000000000".to_string()
}),
self.send_amount.to_string(),
])
.with_gas_limit(55000);

// Only add fuzzing if token_recipient is NOT provided
if self.token_recipient.is_none() {
func_def = func_def.with_fuzz(&[FuzzParam {
param: Some("guy".to_string()),
value: None,
min: Some(U256::from(1)),
max: Some(
U256::from_str("0x0000000000ffffffffffffffffffffffffffffffff").unwrap(),
),
}]);
}

func_def
})]),
}
}])
.with_setup(setup_steps)
.with_spam(spam_steps)
}
}
11 changes: 4 additions & 7 deletions crates/cli/src/default_scenarios/eth_functions/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,14 @@ impl ToTestConfig for EthFunctionsArgs {
let opcode_txs = opcode_txs(opcodes, *num_iterations);
let txs = [precompile_txs, opcode_txs].concat();

TestConfig {
env: None,
create: Some(vec![CreateDefinition {
TestConfig::new()
.with_create(vec![CreateDefinition {
contract: contracts::SPAM_ME.into(),
signature: None,
args: None,
from: None,
from_pool: Some("admin".to_owned()),
}]),
setup: None,
spam: Some(txs),
}
}])
.with_spam(txs)
}
}
11 changes: 4 additions & 7 deletions crates/cli/src/default_scenarios/fill_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,14 @@ impl ToTestConfig for FillBlockArgs {
})
.collect::<Vec<_>>();

TestConfig {
env: None,
create: Some(vec![CreateDefinition {
TestConfig::new()
.with_create(vec![CreateDefinition {
contract: contracts::SPAM_ME.into(),
signature: None,
args: None,
from: None,
from_pool: Some("admin".to_owned()),
}]),
setup: None,
spam: Some(spam_txs),
}
}])
.with_spam(spam_txs)
}
}
13 changes: 5 additions & 8 deletions crates/cli/src/default_scenarios/revert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,19 @@ impl Default for RevertCliArgs {

impl ToTestConfig for RevertCliArgs {
fn to_testconfig(&self) -> contender_testfile::TestConfig {
TestConfig {
env: None,
create: Some(vec![CreateDefinition {
TestConfig::new()
.with_create(vec![CreateDefinition {
contract: SPAM_ME_6.into(),
signature: None,
args: None,
from: None,
from_pool: Some("admin".to_owned()),
}]),
setup: None,
spam: Some(vec![SpamRequest::new_tx(
}])
.with_spam(vec![SpamRequest::new_tx(
&FunctionCallDefinition::new(SPAM_ME_6.template_name())
.with_signature("consumeGasAndRevert(uint256 gas)")
.with_args(&[self.gas_use.to_string()])
.with_gas_limit(self.gas_use + 35000),
)]),
}
)])
}
}
11 changes: 4 additions & 7 deletions crates/cli/src/default_scenarios/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,14 @@ impl ToTestConfig for StorageStressArgs {
.map(SpamRequest::Tx)
.collect::<Vec<_>>();

TestConfig {
env: None,
create: Some(vec![CreateDefinition {
TestConfig::new()
.with_create(vec![CreateDefinition {
contract: contracts::SPAM_ME.into(),
signature: None,
args: None,
from: None,
from_pool: Some("admin".to_owned()),
}]),
setup: None,
spam: Some(txs),
}
}])
.with_spam(txs)
}
}
11 changes: 4 additions & 7 deletions crates/cli/src/default_scenarios/stress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,17 +206,14 @@ impl ToTestConfig for StressCliArgs {
.flat_map(|config| config.spam.unwrap_or_default())
.collect::<Vec<_>>();

TestConfig {
env: None,
create: Some(vec![CreateDefinition {
TestConfig::new()
.with_create(vec![CreateDefinition {
contract: contracts::SPAM_ME.into(),
signature: None,
args: None,
from: None,
from_pool: Some("admin".to_owned()),
}]),
setup: None,
spam: Some(txs),
}
}])
.with_spam(txs)
}
}
7 changes: 1 addition & 6 deletions crates/cli/src/default_scenarios/transfers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,6 @@ impl ToTestConfig for TransferStressArgs {
.map(Box::new)
.map(SpamRequest::Tx)
.collect::<Vec<_>>();
contender_testfile::TestConfig {
env: None,
create: None,
setup: None,
spam: Some(txs),
}
contender_testfile::TestConfig::new().with_spam(txs)
}
}
10 changes: 7 additions & 3 deletions crates/cli/src/default_scenarios/uni_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl ToTestConfig for UniV2Args {
let mut add_create_steps = vec![];
for i in 0..self.num_tokens {
let deployment = CreateDefinition {
contract: test_token(i + 1, self.initial_token_supply),
contract: test_token(i + 1, self.initial_token_supply).into(),
signature: None,
args: None,
from: None,
Expand All @@ -147,14 +147,18 @@ impl ToTestConfig for UniV2Args {

// now that contract updates are done, we can update the config & use contracts in setup steps
config.create = Some(create_steps.to_owned());
let find_contract = |name: &str| {
let find_contract = |name: &str| -> Result<CompiledContract, UniV2Error> {
let contract = create_steps
.iter()
.find(|c| c.contract.name == name)
.ok_or(UniV2Error::ContractNameNotFound(name.to_owned()))?
.contract
.to_owned();
Ok::<_, UniV2Error>(contract)
Ok::<_, UniV2Error>(
contract
.to_compiled_contract(Default::default())
.expect("contract is static, this can't fail"),
)
};

let weth = find_contract("weth").expect("contract");
Expand Down
3 changes: 3 additions & 0 deletions crates/cli/src/util/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ pub enum UtilError {
#[error("io error")]
Io(#[from] std::io::Error),

#[error("invalid scenario path: {0}")]
InvalidScenarioPath(String),

#[error("failed to parse duration")]
ParseDuration(#[from] ParseDurationError),

Expand Down
7 changes: 6 additions & 1 deletion crates/cli/src/util/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use contender_engine_provider::DEFAULT_BLOCK_TIME;
use contender_testfile::TestConfig;
use nu_ansi_term::{AnsiGenericString, Style as ANSIStyle};
use rand::Rng;
use std::path::PathBuf;
use std::{str::FromStr, sync::Arc, time::Duration};
use tracing::{debug, info, warn};

Expand Down Expand Up @@ -53,7 +54,11 @@ pub async fn load_testconfig(testfile: &str) -> Result<TestConfig, crate::CliErr
);
TestConfig::from_remote_url(&remote_url).await
} else {
TestConfig::from_file(testfile)
let path: PathBuf = testfile.into();
let parent = path
.parent()
.ok_or(UtilError::InvalidScenarioPath(testfile.to_owned()))?;
Ok(TestConfig::from_file(testfile)?.with_scenario_directory(parent.into()))
}?)
}

Expand Down
Loading
Loading