Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update execution-spec-tests support #6942

Merged
merged 8 commits into from
Apr 16, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
@Command(
name = COMMAND_NAME,
aliases = {COMMAND_ALIAS},
description = "Execute an Ethereum State Test.",
description = "Block Builder subcommand.",
mixinStandardHelpOptions = true,
versionProvider = VersionProvider.class)
public class B11rSubCommand implements Runnable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,19 @@
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockHeaderBuilder;
import org.hyperledger.besu.ethereum.core.Difficulty;
import org.hyperledger.besu.ethereum.core.MutableWorldState;
import org.hyperledger.besu.ethereum.core.Transaction;
import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec;
import org.hyperledger.besu.ethereum.vm.CachingBlockHashLookup;
import org.hyperledger.besu.evm.Code;
import org.hyperledger.besu.evm.EVM;
import org.hyperledger.besu.evm.EvmSpecVersion;
import org.hyperledger.besu.evm.account.AccountStorageEntry;
import org.hyperledger.besu.evm.code.CodeInvalid;
import org.hyperledger.besu.evm.frame.MessageFrame;
import org.hyperledger.besu.evm.log.LogsBloomFilter;
import org.hyperledger.besu.evm.tracing.OperationTracer;
import org.hyperledger.besu.evm.tracing.StandardJsonTracer;
import org.hyperledger.besu.evm.worldstate.WorldState;
import org.hyperledger.besu.evm.worldstate.WorldUpdater;
import org.hyperledger.besu.metrics.MetricsSystemModule;
import org.hyperledger.besu.util.LogConfigurator;
Expand All @@ -58,7 +57,7 @@
import java.util.Deque;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.NavigableMap;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -474,8 +473,9 @@ public void run() {
lastTime = stopwatch.elapsed().toNanos();
stopwatch.reset();
if (showJsonAlloc && lastLoop) {
initialMessageFrame.getSelfDestructs().forEach(updater::deleteAccount);
updater.commit();
WorldState worldState = component.getWorldState();
MutableWorldState worldState = component.getWorldState();
dumpWorldState(worldState, out);
}
} while (remainingIters-- > 0);
Expand All @@ -486,34 +486,39 @@ public void run() {
}
}

public static void dumpWorldState(final WorldState worldState, final PrintWriter out) {
public static void dumpWorldState(final MutableWorldState worldState, final PrintWriter out) {
out.println("{");
worldState
.streamAccounts(Bytes32.ZERO, Integer.MAX_VALUE)
.sorted(Comparator.comparing(o -> o.getAddress().get().toHexString()))
.forEach(
account -> {
out.println(
" \"" + account.getAddress().map(Address::toHexString).orElse("-") + "\": {");
a -> {
var account = worldState.get(a.getAddress().get());
out.println(" \"" + account.getAddress().toHexString() + "\": {");
if (account.getCode() != null && !account.getCode().isEmpty()) {
out.println(" \"code\": \"" + account.getCode().toHexString() + "\",");
}
NavigableMap<Bytes32, AccountStorageEntry> storageEntries =
account.storageEntriesFrom(Bytes32.ZERO, Integer.MAX_VALUE);
var storageEntries =
account.storageEntriesFrom(Bytes32.ZERO, Integer.MAX_VALUE).values().stream()
.map(
e ->
Map.entry(
e.getKey().get(),
account.getStorageValue(UInt256.fromBytes(e.getKey().get()))))
.filter(e -> !e.getValue().isZero())
.sorted(Map.Entry.comparingByKey())
.toList();
if (!storageEntries.isEmpty()) {
out.println(" \"storage\": {");
out.println(
STORAGE_JOINER.join(
storageEntries.values().stream()
storageEntries.stream()
.map(
accountStorageEntry ->
e ->
" \""
+ accountStorageEntry
.getKey()
.map(UInt256::toQuantityHexString)
.orElse("-")
+ e.getKey().toQuantityHexString()
+ "\": \""
+ accountStorageEntry.getValue().toQuantityHexString()
+ e.getValue().toQuantityHexString()
+ "\"")
.toList()));
out.println(" },");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ public class StateTestSubCommand implements Runnable {
description = "Force the state tests to run on a specific fork.")
private String fork = null;

@Option(
names = {"--test-name"},
description = "Limit execution to one named test.")
private String testName = null;

@Option(
names = {"--data-index"},
description = "Limit execution to one data variable.")
Expand Down Expand Up @@ -173,10 +178,12 @@ public void run() {
private void executeStateTest(final Map<String, GeneralStateTestCaseSpec> generalStateTests) {
for (final Map.Entry<String, GeneralStateTestCaseSpec> generalStateTestEntry :
generalStateTests.entrySet()) {
generalStateTestEntry
.getValue()
.finalStateSpecs()
.forEach((__, specs) -> traceTestSpecs(generalStateTestEntry.getKey(), specs));
if (testName == null || testName.equals(generalStateTestEntry.getKey())) {
generalStateTestEntry
.getValue()
.finalStateSpecs()
.forEach((__, specs) -> traceTestSpecs(generalStateTestEntry.getKey(), specs));
}
}
}

Expand Down
Loading
Loading