Skip to content

Commit

Permalink
fix broken tests & faulty logic
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroXbrock committed Jan 7, 2025
1 parent 4a7dd21 commit 381b12d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 66 deletions.
105 changes: 41 additions & 64 deletions crates/core/src/generator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,79 +227,56 @@ where
PlanType::Create(on_create_step) => {
let create_steps = conf.get_create_steps()?;

let agents = self.get_agent_store();
let num_accts = agents
.all_agents()
.next()
.map(|(_, store)| store.signers.len())
.unwrap_or(1);

// txs will be grouped by account [from=1, from=1, from=1, from=2, from=2, from=2, ...]
for idx in 0..num_accts {
for step in create_steps.iter() {
// lookup placeholder values in DB & update map before templating
templater.find_placeholder_values(
&step.bytecode,
&mut placeholder_map,
db,
)?;

// create tx with template values
let step = self.make_strict_create(step, idx)?;
let tx = NamedTxRequestBuilder::new(
templater.template_contract_deploy(&step, &placeholder_map)?,
)
.with_name(&step.name)
.build();

let handle = on_create_step(tx.to_owned())?;
if let Some(handle) = handle {
handle.await.map_err(|e| {
ContenderError::with_err(e, "join error; callback crashed")
})?;
}
txs.push(tx.into());
for step in create_steps.iter() {
// lookup placeholder values in DB & update map before templating
templater.find_placeholder_values(&step.bytecode, &mut placeholder_map, db)?;

// populate step with from address
let step = self.make_strict_create(step, 0)?;

// create tx with template values
let tx = NamedTxRequestBuilder::new(
templater.template_contract_deploy(&step, &placeholder_map)?,
)
.with_name(&step.name)
.build();

let handle = on_create_step(tx.to_owned())?;
if let Some(handle) = handle {
handle.await.map_err(|e| {
ContenderError::with_err(e, "join error; callback crashed")
})?;
}
txs.push(tx.into());
}
}
PlanType::Setup(on_setup_step) => {
let setup_steps = conf.get_setup_steps()?;

let agents = self.get_agent_store();
let num_accts = agents
.all_agents()
.next()
.map(|(_, store)| store.signers.len())
.unwrap_or(1);

// txs will be grouped by account [from=1, from=1, from=1, from=2, from=2, from=2, ...]
for i in 0..(num_accts) {
for step in setup_steps.iter() {
if i > 0 && step.from_pool.is_none() {
// only loop on from_pool steps; single-account steps can't be repeated
continue;
}
// lookup placeholders in DB & update map before templating
templater.find_fncall_placeholders(step, db, &mut placeholder_map)?;

// setup tx with template values
let tx = NamedTxRequest::new(
templater.template_function_call(
&self.make_strict_call(step, i)?, // 'from' address injected here
&placeholder_map,
)?,
None,
step.kind.to_owned(),
);

let handle = on_setup_step(tx.to_owned())?;
if let Some(handle) = handle {
handle.await.map_err(|e| {
ContenderError::with_err(e, "join error; callback crashed")
})?;
}
txs.push(tx.into());

for step in setup_steps.iter() {
// lookup placeholders in DB & update map before templating
templater.find_fncall_placeholders(step, db, &mut placeholder_map)?;

// setup tx with template values
let tx = NamedTxRequest::new(
templater.template_function_call(
&self.make_strict_call(step, 0)?, // 'from' address injected here
&placeholder_map,
)?,
None,
step.kind.to_owned(),
);

let handle = on_setup_step(tx.to_owned())?;
if let Some(handle) = handle {
handle.await.map_err(|e| {
ContenderError::with_err(e, "join error; callback crashed")
})?;
}
txs.push(tx.into());
}
}
PlanType::Spam(num_txs, on_spam_setup) => {
Expand Down
4 changes: 2 additions & 2 deletions crates/core/src/test_scenario.rs
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ pub mod tests {
}))
.await
.unwrap();
assert_eq!(setup_txs.len(), 12);
assert_eq!(setup_txs.len(), 3);

let spam_txs = scenario
.load_txs(PlanType::Spam(20, |tx| {
Expand Down Expand Up @@ -850,7 +850,7 @@ pub mod tests {
used_agent_keys += 1;
}
}
assert!(used_agent_keys > 1);
assert_eq!(used_agent_keys, 1);
}

#[tokio::test]
Expand Down

0 comments on commit 381b12d

Please sign in to comment.