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

Retesteth eth_getBlockByHash requires "author" field. #845

Merged
merged 4 commits into from
May 6, 2020
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 @@ -31,16 +31,20 @@ public class EthGetBlockByHash implements JsonRpcMethod {

private final BlockResultFactory blockResult;
private final Supplier<BlockchainQueries> blockchain;
private final boolean includeCoinbase;

public EthGetBlockByHash(
final BlockchainQueries blockchain, final BlockResultFactory blockResult) {
this(Suppliers.ofInstance(blockchain), blockResult);
this(Suppliers.ofInstance(blockchain), blockResult, false);
}

public EthGetBlockByHash(
final Supplier<BlockchainQueries> blockchain, final BlockResultFactory blockResult) {
final Supplier<BlockchainQueries> blockchain,
final BlockResultFactory blockResult,
final boolean includeCoinbase) {
this.blockchain = blockchain;
this.blockResult = blockResult;
this.includeCoinbase = includeCoinbase;
}

@Override
Expand All @@ -65,7 +69,11 @@ private BlockResult blockResult(final JsonRpcRequestContext request) {
}

private BlockResult transactionComplete(final Hash hash) {
return blockchain.get().blockByHash(hash).map(blockResult::transactionComplete).orElse(null);
return blockchain
.get()
.blockByHash(hash)
.map(tx -> blockResult.transactionComplete(tx, includeCoinbase))
.orElse(null);
}

private BlockResult transactionHash(final Hash hash) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,12 @@ public static class StorageEntry {
public StorageEntry(final AccountStorageEntry entry, final boolean shortValues) {
if (shortValues) {
this.value = entry.getValue().toShortHexString();
this.key = entry.getKey().map(UInt256::toShortHexString).orElse(null);
this.key =
entry
.getKey()
.map(UInt256::toShortHexString)
.map(s -> "0x".equals(s) ? "0x00" : s)
.orElse(null);
} else {
this.value = entry.getValue().toHexString();
this.key = entry.getKey().map(UInt256::toHexString).orElse(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.tuweni.bytes.Bytes;

public class RetestethContext {

Expand All @@ -72,6 +73,7 @@ public class RetestethContext {

private final ReentrantLock contextLock = new ReentrantLock();
private Address coinbase;
private Bytes extraData;
private MutableBlockchain blockchain;
private ProtocolContext<Void> protocolContext;
private BlockchainQueries blockchainQueries;
Expand Down Expand Up @@ -128,6 +130,7 @@ private boolean buildContext(

final GenesisState genesisState = GenesisState.fromJson(genesisConfigString, protocolSchedule);
coinbase = genesisState.getBlock().getHeader().getCoinbase();
extraData = genesisState.getBlock().getHeader().getExtraData();

final WorldStateArchive worldStateArchive =
new WorldStateArchive(
Expand Down Expand Up @@ -248,6 +251,10 @@ public Address getCoinbase() {
return coinbase;
}

public Bytes getExtraData() {
return extraData;
}

public MutableBlockchain getBlockchain() {
return blockchain;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public RetestethService(
new EthGetBlockByNumber(retestethContext::getBlockchainQueries, blockResult, true),
new DebugAccountRange(retestethContext::getBlockchainQueries),
new EthGetBalance(retestethContext::getBlockchainQueries),
new EthGetBlockByHash(retestethContext::getBlockchainQueries, blockResult),
new EthGetBlockByHash(retestethContext::getBlockchainQueries, blockResult, true),
new EthGetCode(retestethContext::getBlockchainQueries),
new EthGetTransactionCount(
retestethContext::getBlockchainQueries,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.hyperledger.besu.ethereum.retesteth.RetestethContext;

import com.google.common.base.Functions;
import org.apache.tuweni.bytes.Bytes;

public class TestMineBlocks implements JsonRpcMethod {
private final RetestethContext context;
Expand Down Expand Up @@ -65,7 +64,7 @@ private boolean mineNewBlock() {
final EthHashBlockCreator blockCreator =
new EthHashBlockCreator(
context.getCoinbase(),
header -> Bytes.of(),
header -> context.getExtraData(),
context.getTransactionPool().getPendingTransactions(),
protocolContext,
protocolSchedule,
Expand Down