|
|
@ -72,6 +72,7 @@ import org.hyperledger.besu.services.RpcEndpointServiceImpl; |
|
|
|
|
|
|
|
|
|
|
|
import java.math.BigInteger; |
|
|
|
import java.math.BigInteger; |
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
|
|
|
|
|
import java.nio.file.Path; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.Collections; |
|
|
|
|
|
|
|
|
|
|
|
import io.vertx.core.Vertx; |
|
|
|
import io.vertx.core.Vertx; |
|
|
@ -79,18 +80,17 @@ import org.apache.tuweni.bytes.Bytes; |
|
|
|
import org.apache.tuweni.units.bigints.UInt64; |
|
|
|
import org.apache.tuweni.units.bigints.UInt64; |
|
|
|
import org.ethereum.beacon.discovery.schema.NodeRecord; |
|
|
|
import org.ethereum.beacon.discovery.schema.NodeRecord; |
|
|
|
import org.ethereum.beacon.discovery.schema.NodeRecordFactory; |
|
|
|
import org.ethereum.beacon.discovery.schema.NodeRecordFactory; |
|
|
|
import org.junit.Before; |
|
|
|
import org.junit.jupiter.api.BeforeEach; |
|
|
|
import org.junit.Rule; |
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
import org.junit.Test; |
|
|
|
import org.junit.jupiter.api.extension.ExtendWith; |
|
|
|
import org.junit.rules.TemporaryFolder; |
|
|
|
import org.junit.jupiter.api.io.TempDir; |
|
|
|
import org.junit.runner.RunWith; |
|
|
|
|
|
|
|
import org.mockito.Mock; |
|
|
|
import org.mockito.Mock; |
|
|
|
import org.mockito.junit.MockitoJUnitRunner; |
|
|
|
import org.mockito.junit.jupiter.MockitoExtension; |
|
|
|
|
|
|
|
|
|
|
|
@RunWith(MockitoJUnitRunner.class) |
|
|
|
@ExtendWith(MockitoExtension.class) |
|
|
|
public final class RunnerBuilderTest { |
|
|
|
public final class RunnerBuilderTest { |
|
|
|
|
|
|
|
|
|
|
|
@Rule public TemporaryFolder dataDir = new TemporaryFolder(); |
|
|
|
@TempDir private Path dataDir; |
|
|
|
|
|
|
|
|
|
|
|
@Mock BesuController besuController; |
|
|
|
@Mock BesuController besuController; |
|
|
|
@Mock ProtocolSchedule protocolSchedule; |
|
|
|
@Mock ProtocolSchedule protocolSchedule; |
|
|
@ -99,7 +99,7 @@ public final class RunnerBuilderTest { |
|
|
|
@Mock Vertx vertx; |
|
|
|
@Mock Vertx vertx; |
|
|
|
private NodeKey nodeKey; |
|
|
|
private NodeKey nodeKey; |
|
|
|
|
|
|
|
|
|
|
|
@Before |
|
|
|
@BeforeEach |
|
|
|
public void setup() { |
|
|
|
public void setup() { |
|
|
|
final SubProtocolConfiguration subProtocolConfiguration = mock(SubProtocolConfiguration.class); |
|
|
|
final SubProtocolConfiguration subProtocolConfiguration = mock(SubProtocolConfiguration.class); |
|
|
|
final EthProtocolManager ethProtocolManager = mock(EthProtocolManager.class); |
|
|
|
final EthProtocolManager ethProtocolManager = mock(EthProtocolManager.class); |
|
|
@ -118,11 +118,7 @@ public final class RunnerBuilderTest { |
|
|
|
when(ethProtocolManager.ethContext()).thenReturn(ethContext); |
|
|
|
when(ethProtocolManager.ethContext()).thenReturn(ethContext); |
|
|
|
when(subProtocolConfiguration.getSubProtocols()) |
|
|
|
when(subProtocolConfiguration.getSubProtocols()) |
|
|
|
.thenReturn(Collections.singletonList(new IbftSubProtocol())); |
|
|
|
.thenReturn(Collections.singletonList(new IbftSubProtocol())); |
|
|
|
final DefaultBlockchain blockchain = mock(DefaultBlockchain.class); |
|
|
|
|
|
|
|
when(protocolContext.getBlockchain()).thenReturn(blockchain); |
|
|
|
|
|
|
|
final Block block = mock(Block.class); |
|
|
|
|
|
|
|
when(blockchain.getGenesisBlock()).thenReturn(block); |
|
|
|
|
|
|
|
when(block.getHash()).thenReturn(Hash.ZERO); |
|
|
|
|
|
|
|
when(protocolContext.getWorldStateArchive()).thenReturn(worldstateArchive); |
|
|
|
when(protocolContext.getWorldStateArchive()).thenReturn(worldstateArchive); |
|
|
|
when(besuController.getProtocolManager()).thenReturn(ethProtocolManager); |
|
|
|
when(besuController.getProtocolManager()).thenReturn(ethProtocolManager); |
|
|
|
when(besuController.getSubProtocolConfiguration()).thenReturn(subProtocolConfiguration); |
|
|
|
when(besuController.getSubProtocolConfiguration()).thenReturn(subProtocolConfiguration); |
|
|
@ -144,6 +140,8 @@ public final class RunnerBuilderTest { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void enodeUrlShouldHaveAdvertisedHostWhenDiscoveryDisabled() { |
|
|
|
public void enodeUrlShouldHaveAdvertisedHostWhenDiscoveryDisabled() { |
|
|
|
|
|
|
|
setupBlockchainAndBlock(); |
|
|
|
|
|
|
|
|
|
|
|
final String p2pAdvertisedHost = "172.0.0.1"; |
|
|
|
final String p2pAdvertisedHost = "172.0.0.1"; |
|
|
|
final int p2pListenPort = 30302; |
|
|
|
final int p2pListenPort = 30302; |
|
|
|
|
|
|
|
|
|
|
@ -164,7 +162,7 @@ public final class RunnerBuilderTest { |
|
|
|
.jsonRpcIpcConfiguration(mock(JsonRpcIpcConfiguration.class)) |
|
|
|
.jsonRpcIpcConfiguration(mock(JsonRpcIpcConfiguration.class)) |
|
|
|
.metricsConfiguration(mock(MetricsConfiguration.class)) |
|
|
|
.metricsConfiguration(mock(MetricsConfiguration.class)) |
|
|
|
.vertx(vertx) |
|
|
|
.vertx(vertx) |
|
|
|
.dataDir(dataDir.getRoot().toPath()) |
|
|
|
.dataDir(dataDir.getRoot()) |
|
|
|
.storageProvider(mock(KeyValueStorageProvider.class)) |
|
|
|
.storageProvider(mock(KeyValueStorageProvider.class)) |
|
|
|
.rpcEndpointService(new RpcEndpointServiceImpl()) |
|
|
|
.rpcEndpointService(new RpcEndpointServiceImpl()) |
|
|
|
.build(); |
|
|
|
.build(); |
|
|
@ -208,7 +206,7 @@ public final class RunnerBuilderTest { |
|
|
|
.jsonRpcIpcConfiguration(mock(JsonRpcIpcConfiguration.class)) |
|
|
|
.jsonRpcIpcConfiguration(mock(JsonRpcIpcConfiguration.class)) |
|
|
|
.metricsConfiguration(mock(MetricsConfiguration.class)) |
|
|
|
.metricsConfiguration(mock(MetricsConfiguration.class)) |
|
|
|
.vertx(Vertx.vertx()) |
|
|
|
.vertx(Vertx.vertx()) |
|
|
|
.dataDir(dataDir.getRoot().toPath()) |
|
|
|
.dataDir(dataDir.getRoot()) |
|
|
|
.storageProvider(storageProvider) |
|
|
|
.storageProvider(storageProvider) |
|
|
|
.rpcEndpointService(new RpcEndpointServiceImpl()) |
|
|
|
.rpcEndpointService(new RpcEndpointServiceImpl()) |
|
|
|
.build(); |
|
|
|
.build(); |
|
|
@ -236,6 +234,8 @@ public final class RunnerBuilderTest { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void whenEngineApiAddedListensOnDefaultPort() { |
|
|
|
public void whenEngineApiAddedListensOnDefaultPort() { |
|
|
|
|
|
|
|
setupBlockchainAndBlock(); |
|
|
|
|
|
|
|
|
|
|
|
final JsonRpcConfiguration jrpc = JsonRpcConfiguration.createDefault(); |
|
|
|
final JsonRpcConfiguration jrpc = JsonRpcConfiguration.createDefault(); |
|
|
|
jrpc.setEnabled(true); |
|
|
|
jrpc.setEnabled(true); |
|
|
|
final JsonRpcConfiguration engine = JsonRpcConfiguration.createEngineDefault(); |
|
|
|
final JsonRpcConfiguration engine = JsonRpcConfiguration.createEngineDefault(); |
|
|
@ -264,7 +264,7 @@ public final class RunnerBuilderTest { |
|
|
|
.jsonRpcIpcConfiguration(mock(JsonRpcIpcConfiguration.class)) |
|
|
|
.jsonRpcIpcConfiguration(mock(JsonRpcIpcConfiguration.class)) |
|
|
|
.metricsConfiguration(mock(MetricsConfiguration.class)) |
|
|
|
.metricsConfiguration(mock(MetricsConfiguration.class)) |
|
|
|
.vertx(Vertx.vertx()) |
|
|
|
.vertx(Vertx.vertx()) |
|
|
|
.dataDir(dataDir.getRoot().toPath()) |
|
|
|
.dataDir(dataDir.getRoot()) |
|
|
|
.storageProvider(mock(KeyValueStorageProvider.class)) |
|
|
|
.storageProvider(mock(KeyValueStorageProvider.class)) |
|
|
|
.rpcEndpointService(new RpcEndpointServiceImpl()) |
|
|
|
.rpcEndpointService(new RpcEndpointServiceImpl()) |
|
|
|
.besuPluginContext(mock(BesuPluginContextImpl.class)) |
|
|
|
.besuPluginContext(mock(BesuPluginContextImpl.class)) |
|
|
@ -276,6 +276,8 @@ public final class RunnerBuilderTest { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void whenEngineApiAddedWebSocketReadyOnSamePort() { |
|
|
|
public void whenEngineApiAddedWebSocketReadyOnSamePort() { |
|
|
|
|
|
|
|
setupBlockchainAndBlock(); |
|
|
|
|
|
|
|
|
|
|
|
final WebSocketConfiguration wsRpc = WebSocketConfiguration.createDefault(); |
|
|
|
final WebSocketConfiguration wsRpc = WebSocketConfiguration.createDefault(); |
|
|
|
wsRpc.setEnabled(true); |
|
|
|
wsRpc.setEnabled(true); |
|
|
|
final EthNetworkConfig mockMainnet = mock(EthNetworkConfig.class); |
|
|
|
final EthNetworkConfig mockMainnet = mock(EthNetworkConfig.class); |
|
|
@ -304,7 +306,7 @@ public final class RunnerBuilderTest { |
|
|
|
.graphQLConfiguration(mock(GraphQLConfiguration.class)) |
|
|
|
.graphQLConfiguration(mock(GraphQLConfiguration.class)) |
|
|
|
.metricsConfiguration(mock(MetricsConfiguration.class)) |
|
|
|
.metricsConfiguration(mock(MetricsConfiguration.class)) |
|
|
|
.vertx(Vertx.vertx()) |
|
|
|
.vertx(Vertx.vertx()) |
|
|
|
.dataDir(dataDir.getRoot().toPath()) |
|
|
|
.dataDir(dataDir.getRoot()) |
|
|
|
.storageProvider(mock(KeyValueStorageProvider.class)) |
|
|
|
.storageProvider(mock(KeyValueStorageProvider.class)) |
|
|
|
.rpcEndpointService(new RpcEndpointServiceImpl()) |
|
|
|
.rpcEndpointService(new RpcEndpointServiceImpl()) |
|
|
|
.besuPluginContext(mock(BesuPluginContextImpl.class)) |
|
|
|
.besuPluginContext(mock(BesuPluginContextImpl.class)) |
|
|
@ -315,6 +317,8 @@ public final class RunnerBuilderTest { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void whenEngineApiAddedEthSubscribeAvailable() { |
|
|
|
public void whenEngineApiAddedEthSubscribeAvailable() { |
|
|
|
|
|
|
|
setupBlockchainAndBlock(); |
|
|
|
|
|
|
|
|
|
|
|
final WebSocketConfiguration wsRpc = WebSocketConfiguration.createDefault(); |
|
|
|
final WebSocketConfiguration wsRpc = WebSocketConfiguration.createDefault(); |
|
|
|
wsRpc.setEnabled(true); |
|
|
|
wsRpc.setEnabled(true); |
|
|
|
final EthNetworkConfig mockMainnet = mock(EthNetworkConfig.class); |
|
|
|
final EthNetworkConfig mockMainnet = mock(EthNetworkConfig.class); |
|
|
@ -343,7 +347,7 @@ public final class RunnerBuilderTest { |
|
|
|
.graphQLConfiguration(mock(GraphQLConfiguration.class)) |
|
|
|
.graphQLConfiguration(mock(GraphQLConfiguration.class)) |
|
|
|
.metricsConfiguration(mock(MetricsConfiguration.class)) |
|
|
|
.metricsConfiguration(mock(MetricsConfiguration.class)) |
|
|
|
.vertx(Vertx.vertx()) |
|
|
|
.vertx(Vertx.vertx()) |
|
|
|
.dataDir(dataDir.getRoot().toPath()) |
|
|
|
.dataDir(dataDir.getRoot()) |
|
|
|
.storageProvider(mock(KeyValueStorageProvider.class)) |
|
|
|
.storageProvider(mock(KeyValueStorageProvider.class)) |
|
|
|
.rpcEndpointService(new RpcEndpointServiceImpl()) |
|
|
|
.rpcEndpointService(new RpcEndpointServiceImpl()) |
|
|
|
.besuPluginContext(mock(BesuPluginContextImpl.class)) |
|
|
|
.besuPluginContext(mock(BesuPluginContextImpl.class)) |
|
|
@ -357,6 +361,8 @@ public final class RunnerBuilderTest { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void noEngineApiNoServiceForMethods() { |
|
|
|
public void noEngineApiNoServiceForMethods() { |
|
|
|
|
|
|
|
setupBlockchainAndBlock(); |
|
|
|
|
|
|
|
|
|
|
|
final JsonRpcConfiguration defaultRpcConfig = JsonRpcConfiguration.createDefault(); |
|
|
|
final JsonRpcConfiguration defaultRpcConfig = JsonRpcConfiguration.createDefault(); |
|
|
|
defaultRpcConfig.setEnabled(true); |
|
|
|
defaultRpcConfig.setEnabled(true); |
|
|
|
final WebSocketConfiguration defaultWebSockConfig = WebSocketConfiguration.createDefault(); |
|
|
|
final WebSocketConfiguration defaultWebSockConfig = WebSocketConfiguration.createDefault(); |
|
|
@ -383,7 +389,7 @@ public final class RunnerBuilderTest { |
|
|
|
.jsonRpcIpcConfiguration(mock(JsonRpcIpcConfiguration.class)) |
|
|
|
.jsonRpcIpcConfiguration(mock(JsonRpcIpcConfiguration.class)) |
|
|
|
.metricsConfiguration(mock(MetricsConfiguration.class)) |
|
|
|
.metricsConfiguration(mock(MetricsConfiguration.class)) |
|
|
|
.vertx(Vertx.vertx()) |
|
|
|
.vertx(Vertx.vertx()) |
|
|
|
.dataDir(dataDir.getRoot().toPath()) |
|
|
|
.dataDir(dataDir.getRoot()) |
|
|
|
.storageProvider(mock(KeyValueStorageProvider.class)) |
|
|
|
.storageProvider(mock(KeyValueStorageProvider.class)) |
|
|
|
.rpcEndpointService(new RpcEndpointServiceImpl()) |
|
|
|
.rpcEndpointService(new RpcEndpointServiceImpl()) |
|
|
|
.besuPluginContext(mock(BesuPluginContextImpl.class)) |
|
|
|
.besuPluginContext(mock(BesuPluginContextImpl.class)) |
|
|
@ -393,4 +399,12 @@ public final class RunnerBuilderTest { |
|
|
|
assertThat(runner.getJsonRpcPort()).isPresent(); |
|
|
|
assertThat(runner.getJsonRpcPort()).isPresent(); |
|
|
|
assertThat(runner.getEngineJsonRpcPort()).isEmpty(); |
|
|
|
assertThat(runner.getEngineJsonRpcPort()).isEmpty(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void setupBlockchainAndBlock() { |
|
|
|
|
|
|
|
final DefaultBlockchain blockchain = mock(DefaultBlockchain.class); |
|
|
|
|
|
|
|
when(protocolContext.getBlockchain()).thenReturn(blockchain); |
|
|
|
|
|
|
|
final Block block = mock(Block.class); |
|
|
|
|
|
|
|
when(blockchain.getGenesisBlock()).thenReturn(block); |
|
|
|
|
|
|
|
when(block.getHash()).thenReturn(Hash.ZERO); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|