Skip to content

Commit

Permalink
add legacy option to send legacy txs
Browse files Browse the repository at this point in the history
  • Loading branch information
zzzzzzch committed Nov 26, 2024
1 parent 115b1a1 commit 1c0372c
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 4 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let cfg = TestConfig::from_file("testfile.toml")?;
let mut agents = AgentStore::new();
let rand_seed = RandSeed::new();
let legacy = false;
agents.add_random_agent(
"agentName",
4, // number of random signers to create
Expand All @@ -88,7 +89,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.iter()
.map(|s| s.parse::<_>().unwrap())
.collect::<Vec<_>>(),
agents
agents,
legacy,
);

if db.get_named_tx("MyContract").is_err() {
Expand Down
14 changes: 14 additions & 0 deletions crates/cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ May be specified multiple times."
default_value = "1.0"
)]
min_balance: String,

/// Whether to send legacy transactions.
#[arg(
long,
long_help = "If set, will send legacy Ethereum transactions instead of EIP-1559 transactions."
)]
legacy: bool,
},

#[command(
Expand Down Expand Up @@ -119,6 +126,13 @@ May be specified multiple times."
default_value = "1.0"
)]
min_balance: String,

/// Whether to send legacy transactions.
#[arg(
long,
long_help = "If set, will send legacy Ethereum transactions instead of EIP-1559 transactions."
)]
legacy: bool,
},

#[command(
Expand Down
4 changes: 4 additions & 0 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
rpc_url,
private_keys,
min_balance,
legacy,
} => {
let url = Url::parse(rpc_url.as_ref()).expect("Invalid RPC URL");
let rpc_client = ProviderBuilder::new()
Expand Down Expand Up @@ -83,6 +84,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
RandSeed::new(),
&signers,
Default::default(),
legacy,
)
.await?;

Expand All @@ -101,6 +103,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
private_keys,
disable_reports,
min_balance,
legacy,
} => {
let testconfig = TestConfig::from_file(&testfile)?;
let rand_seed = seed
Expand Down Expand Up @@ -228,6 +231,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
rand_seed,
&user_signers,
agents,
legacy,
)
.await?;

Expand Down
1 change: 1 addition & 0 deletions crates/core/src/spammer/blockwise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ mod tests {
seed,
get_test_signers().as_slice(),
AgentStore::new(),
false,
)
.await
.unwrap();
Expand Down
21 changes: 18 additions & 3 deletions crates/core/src/test_scenario.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ where
pub chain_id: u64,
pub gas_limits: HashMap<FixedBytes<4>, u128>,
pub msg_handle: Arc<TxActorHandle>,
/// Whether to send legacy transactions instead of EIP-1559 transactions
pub legacy: bool,
}

impl<D, S, P> TestScenario<D, S, P>
Expand All @@ -61,6 +63,7 @@ where
rand_seed: S,
signers: &[PrivateKeySigner],
agent_store: AgentStore,
legacy: bool,
) -> Result<Self> {
let rpc_client = Arc::new(
ProviderBuilder::new()
Expand Down Expand Up @@ -120,6 +123,7 @@ where
nonces,
gas_limits,
msg_handle,
legacy,
})
}

Expand Down Expand Up @@ -320,10 +324,20 @@ where
let full_tx = tx_req
.to_owned()
.with_nonce(nonce)
.with_max_fee_per_gas(gas_price + (gas_price / 5))
.with_max_priority_fee_per_gas(gas_price)
.with_chain_id(self.chain_id)
.with_gas_limit(gas_limit + (gas_limit / 6));
.with_gas_limit(if self.legacy {
gas_limit
} else {
gas_limit + (gas_limit / 6)
});

let full_tx = if self.legacy {
full_tx.with_gas_price(gas_price)
} else {
full_tx
.with_max_fee_per_gas(gas_price + (gas_price / 5))
.with_max_priority_fee_per_gas(gas_price)
};

Ok((full_tx, signer))
}
Expand Down Expand Up @@ -721,6 +735,7 @@ pub mod tests {
seed.to_owned(),
signers,
AgentStore::new(),
false,
)
.await
.unwrap()
Expand Down
3 changes: 3 additions & 0 deletions crates/testfile/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ pub mod tests {
seed,
&get_test_signers(),
Default::default(),
false,
)
.await
.unwrap();
Expand Down Expand Up @@ -421,6 +422,7 @@ pub mod tests {
seed.to_owned(),
&signers,
Default::default(),
false,
)
.await
.unwrap();
Expand All @@ -432,6 +434,7 @@ pub mod tests {
seed,
&signers,
Default::default(),
false,
)
.await
.unwrap();
Expand Down

0 comments on commit 1c0372c

Please sign in to comment.