Skip to content
/ besu Public
forked from hyperledger/besu

Commit

Permalink
Update execution-spec-tests support (hyperledger#6942)
Browse files Browse the repository at this point in the history
Update t8n, b11r, and friends to support current execution spec
* bonsai migration introduced issues with deleted storage/accounts
* status on pre-constantinople json was invalid
* track refund across tx, not call frame
* allow tests to be executed by name
* fix withdrawal self-destruct test
* trace support in execution-spec-tests
* fix blob tests
* t8n results changes

Signed-off-by: Danno Ferrin <[email protected]>
  • Loading branch information
shemnon authored Apr 16, 2024
1 parent 941ab01 commit 9601456
Show file tree
Hide file tree
Showing 14 changed files with 261 additions and 176 deletions.
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

0 comments on commit 9601456

Please sign in to comment.