Skip to content

Commit ee339df

Browse files
Dyslex7cmacfarla
andauthored
fix(evmtool): implement --repeat option in state-test subcommand (#8863)
* fix(evmtool): implement --repeat option in state-test subcommand Signed-off-by: Dyslex7c <[email protected]> * fix: spotless check failing Signed-off-by: Dyslex7c <[email protected]> * fix: prevent repeated trace, and errors during invalid tx Signed-off-by: Dyslex7c <[email protected]> --------- Signed-off-by: Dyslex7c <[email protected]> Co-authored-by: Sally MacFarlane <[email protected]>
1 parent 42c4468 commit ee339df

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/EvmToolCommand.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,10 @@ void setBytes(final String optionValue) {
265265
description = "display version info")
266266
boolean versionInfoRequested;
267267

268+
Integer getRepeatCount() {
269+
return repeat;
270+
}
271+
268272
static final Joiner STORAGE_JOINER = Joiner.on(",\n");
269273
private final EvmToolCommandOptionsModule daggerOptions = new EvmToolCommandOptionsModule();
270274
PrintWriter out;

ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/StateTestSubCommand.java

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -189,20 +189,29 @@ public void run() {
189189
}
190190

191191
private void executeStateTest(final Map<String, GeneralStateTestCaseSpec> generalStateTests) {
192-
for (final Map.Entry<String, GeneralStateTestCaseSpec> generalStateTestEntry :
193-
generalStateTests.entrySet()) {
194-
if (testName == null || testName.equals(generalStateTestEntry.getKey())) {
195-
generalStateTestEntry
196-
.getValue()
197-
.finalStateSpecs()
198-
.forEach((__, specs) -> traceTestSpecs(generalStateTestEntry.getKey(), specs));
192+
int repeatCount = Math.max(1, parentCommand.getRepeatCount());
193+
for (int i = 0; i < repeatCount; i++) {
194+
boolean isLastIteration = (i == repeatCount - 1);
195+
for (final Map.Entry<String, GeneralStateTestCaseSpec> generalStateTestEntry :
196+
generalStateTests.entrySet()) {
197+
if (testName == null || testName.equals(generalStateTestEntry.getKey())) {
198+
generalStateTestEntry
199+
.getValue()
200+
.finalStateSpecs()
201+
.forEach(
202+
(__, specs) ->
203+
traceTestSpecs(generalStateTestEntry.getKey(), specs, isLastIteration));
204+
}
199205
}
200206
}
201207
}
202208

203-
private void traceTestSpecs(final String test, final List<GeneralStateTestCaseEipSpec> specs) {
209+
private void traceTestSpecs(
210+
final String test,
211+
final List<GeneralStateTestCaseEipSpec> specs,
212+
final boolean isLastIteration) {
204213
final OperationTracer tracer = // You should have picked Mercy.
205-
parentCommand.showJsonResults
214+
parentCommand.showJsonResults && isLastIteration
206215
? new StandardJsonTracer(
207216
parentCommand.out,
208217
parentCommand.showMemory,
@@ -231,7 +240,7 @@ private void traceTestSpecs(final String test, final List<GeneralStateTestCaseEi
231240
final Transaction transaction = spec.getTransaction(0);
232241
final ObjectNode summaryLine = objectMapper.createObjectNode();
233242
if (transaction == null) {
234-
if (parentCommand.showJsonAlloc || parentCommand.showJsonResults) {
243+
if ((parentCommand.showJsonAlloc || parentCommand.showJsonResults) && isLastIteration) {
235244
parentCommand.out.println(
236245
"{\"error\":\"Transaction was invalid, trace and alloc unavailable.\"}");
237246
}
@@ -332,12 +341,14 @@ private void traceTestSpecs(final String test, final List<GeneralStateTestCaseEi
332341
if (!result.getValidationResult().isValid()) {
333342
summaryLine.put("error", result.getValidationResult().getErrorMessage());
334343
}
335-
if (parentCommand.showJsonAlloc) {
344+
if (parentCommand.showJsonAlloc && isLastIteration) {
336345
EvmToolCommand.dumpWorldState(worldState, parentCommand.out);
337346
}
338347
}
339348

340-
parentCommand.out.println(summaryLine);
349+
if (isLastIteration) {
350+
parentCommand.out.println(summaryLine);
351+
}
341352
}
342353
}
343354
}

0 commit comments

Comments
 (0)