Skip to content

Commit

Permalink
Fail load gen if soroban invoke without setup
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasBrady committed Dec 2, 2024
1 parent fdd833d commit 7e1955f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
10 changes: 5 additions & 5 deletions src/simulation/LoadGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,11 +352,11 @@ LoadGenerator::start(GeneratedLoadConfig& cfg)
{
// start is incomplete, so reset to avoid leaving the
// LoadGenerator in an invalid state.
reset();
throw std::runtime_error(
"Before running MODE::SOROBAN_INVOKE, please run "
"MODE::SOROBAN_INVOKE_SETUP to set up your contract "
"first.");
CLOG_ERROR(LoadGen, "Before running MODE::SOROBAN_INVOKE, "
"please run MODE::SOROBAN_INVOKE_SETUP to "
"set up your contract first.");
emitFailure(/*resetSoroban=*/true);
return;
}
releaseAssert(mContractInstances.empty());
releaseAssert(mAccountsAvailable.size() >= cfg.nAccounts);
Expand Down
23 changes: 12 additions & 11 deletions src/simulation/test/LoadGeneratorTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,17 +225,18 @@ TEST_CASE("generate soroban load", "[loadgen][soroban]")
SECTION("misconfigured soroban loadgen mode usage")
{
// Users are required to run SOROBAN_INVOKE_SETUP_LOAD before running
// SOROBAN_INVOKE_LOAD. Running a SOROBAN_INVOKE_LOAD without a prior
// SOROBAN_INVOKE_SETUP_LOAD should throw a helpful exception explaining
// the misconfiguration.
auto invokeLoadCfg =
GeneratedLoadConfig::txLoad(LoadGenMode::SOROBAN_INVOKE,
/* nAccounts*/ 1, /* numSorobanTxs */ 1,
/* txRate */ 1);
REQUIRE_THROWS_WITH(
loadGen.generateLoad(invokeLoadCfg),
"Before running MODE::SOROBAN_INVOKE, please run "
"MODE::SOROBAN_INVOKE_SETUP to set up your contract first.");
// SOROBAN_INVOKE_LOAD. If they do not, load generation will fail. An
// error message will be logged and `loadgen.run.failed` will be
// incremented.
auto invokeLoadCfg = GeneratedLoadConfig::txLoad(
LoadGenMode::SOROBAN_INVOKE,
/* nAccounts */ 1, /* numSorobanTxs */ 1,
/* txRate */ 1);
auto& loadGenFailed =
app.getMetrics().NewMeter({"loadgen", "run", "failed"}, "run");
auto failedCount = loadGenFailed.count();
loadGen.generateLoad(invokeLoadCfg);
REQUIRE(loadGenFailed.count() == failedCount + 1);
}
int64_t numTxsBefore = getSuccessfulTxCount();

Expand Down

0 comments on commit 7e1955f

Please sign in to comment.