|
|
|
@ -18,9 +18,8 @@ import static java.util.Arrays.asList; |
|
|
|
|
import static java.util.Collections.singletonList; |
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
|
import static org.mockito.ArgumentMatchers.any; |
|
|
|
|
import static org.mockito.Mockito.doAnswer; |
|
|
|
|
import static org.mockito.ArgumentMatchers.eq; |
|
|
|
|
import static org.mockito.Mockito.mock; |
|
|
|
|
import static org.mockito.Mockito.spy; |
|
|
|
|
import static org.mockito.Mockito.when; |
|
|
|
|
|
|
|
|
|
import org.hyperledger.besu.datatypes.Wei; |
|
|
|
@ -35,32 +34,25 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSucces |
|
|
|
|
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; |
|
|
|
|
import org.hyperledger.besu.ethereum.api.query.BlockWithMetadata; |
|
|
|
|
import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; |
|
|
|
|
import org.hyperledger.besu.ethereum.chain.Blockchain; |
|
|
|
|
import org.hyperledger.besu.ethereum.core.Block; |
|
|
|
|
import org.hyperledger.besu.ethereum.core.BlockDataGenerator; |
|
|
|
|
import org.hyperledger.besu.ethereum.debug.TraceFrame; |
|
|
|
|
import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions; |
|
|
|
|
import org.hyperledger.besu.ethereum.processing.TransactionProcessingResult; |
|
|
|
|
import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; |
|
|
|
|
|
|
|
|
|
import java.util.Collection; |
|
|
|
|
import java.util.Collections; |
|
|
|
|
import java.util.Optional; |
|
|
|
|
import java.util.OptionalLong; |
|
|
|
|
import java.util.function.Function; |
|
|
|
|
|
|
|
|
|
import org.apache.tuweni.bytes.Bytes; |
|
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
|
import org.mockito.Answers; |
|
|
|
|
import org.mockito.Mockito; |
|
|
|
|
|
|
|
|
|
public class DebugTraceBlockTest { |
|
|
|
|
|
|
|
|
|
private final BlockTracer blockTracer = mock(BlockTracer.class); |
|
|
|
|
private final WorldStateArchive archive = |
|
|
|
|
mock(WorldStateArchive.class, Answers.RETURNS_DEEP_STUBS); |
|
|
|
|
private final Blockchain blockchain = mock(Blockchain.class); |
|
|
|
|
private final BlockchainQueries blockchainQueries = |
|
|
|
|
spy(new BlockchainQueries(blockchain, archive)); |
|
|
|
|
private final BlockchainQueries blockchainQueries = mock(BlockchainQueries.class); |
|
|
|
|
private final DebugTraceBlock debugTraceBlock = |
|
|
|
|
new DebugTraceBlock(() -> blockTracer, new MainnetBlockHeaderFunctions(), blockchainQueries); |
|
|
|
|
|
|
|
|
@ -127,22 +119,25 @@ public class DebugTraceBlockTest { |
|
|
|
|
when(transaction2Trace.getResult()).thenReturn(transaction2Result); |
|
|
|
|
when(transaction1Result.getOutput()).thenReturn(Bytes.fromHexString("1234")); |
|
|
|
|
when(transaction2Result.getOutput()).thenReturn(Bytes.fromHexString("1234")); |
|
|
|
|
when(blockTracer.trace(any(Tracer.TraceableState.class), Mockito.eq(block), any())) |
|
|
|
|
when(blockTracer.trace(any(Tracer.TraceableState.class), eq(block), any())) |
|
|
|
|
.thenReturn(Optional.of(blockTrace)); |
|
|
|
|
|
|
|
|
|
when(blockchain.getBlockHeader(parentBlock.getHash())) |
|
|
|
|
.thenReturn(Optional.of(parentBlock.getHeader())); |
|
|
|
|
doAnswer( |
|
|
|
|
invocation -> |
|
|
|
|
when(blockchainQueries.blockByHash(parentBlock.getHash())) |
|
|
|
|
.thenReturn( |
|
|
|
|
Optional.of( |
|
|
|
|
new BlockWithMetadata<>( |
|
|
|
|
parentBlock.getHeader(), |
|
|
|
|
Collections.emptyList(), |
|
|
|
|
Collections.emptyList(), |
|
|
|
|
parentBlock.getHeader().getDifficulty(), |
|
|
|
|
parentBlock.calculateSize()))) |
|
|
|
|
.when(blockchainQueries) |
|
|
|
|
.blockByHash(parentBlock.getHash()); |
|
|
|
|
parentBlock.calculateSize()))); |
|
|
|
|
when(blockchainQueries.getAndMapWorldState(eq(parentBlock.getHash()), any())) |
|
|
|
|
.thenAnswer( |
|
|
|
|
invocationOnMock -> { |
|
|
|
|
Function<Tracer.TraceableState, ? extends Optional<BlockTracer>> mapper = |
|
|
|
|
invocationOnMock.getArgument(1); |
|
|
|
|
return mapper.apply(mock(Tracer.TraceableState.class)); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
final JsonRpcSuccessResponse response = |
|
|
|
|
(JsonRpcSuccessResponse) debugTraceBlock.response(request); |
|
|
|
|