16
16
17
17
import static java .util .Collections .singletonList ;
18
18
import static org .assertj .core .api .Assertions .assertThat ;
19
+ import static org .mockito .Mockito .lenient ;
19
20
import static org .mockito .Mockito .mock ;
20
21
import static org .mockito .Mockito .when ;
21
22
33
34
import org .hyperledger .besu .ethereum .api .jsonrpc .websocket .WebSocketConfiguration ;
34
35
import org .hyperledger .besu .ethereum .api .query .BlockchainQueries ;
35
36
import org .hyperledger .besu .ethereum .blockcreation .PoWMiningCoordinator ;
37
+ import org .hyperledger .besu .ethereum .chain .Blockchain ;
36
38
import org .hyperledger .besu .ethereum .chain .MutableBlockchain ;
37
39
import org .hyperledger .besu .ethereum .core .Block ;
38
40
import org .hyperledger .besu .ethereum .core .InMemoryKeyValueStorageProvider ;
@@ -199,6 +201,7 @@ private JsonRpcHttpService createJsonRpcHttpServiceWithRpcApis(final String... r
199
201
200
202
private JsonRpcHttpService createJsonRpcHttpServiceWithRpcApis (final JsonRpcConfiguration config )
201
203
throws Exception {
204
+ setupMocksRequiredForBlockchainGenesisHash ();
202
205
final Set <Capability > supportedCapabilities = new HashSet <>();
203
206
supportedCapabilities .add (EthProtocol .LATEST );
204
207
@@ -313,6 +316,8 @@ private JsonRpcHttpService createJsonRpcHttpService(
313
316
jsonRpcConfiguration .setPort (0 );
314
317
webSocketConfiguration .setPort (0 );
315
318
319
+ setupMocksRequiredForBlockchainGenesisHash ();
320
+
316
321
final Map <String , JsonRpcMethod > rpcMethods =
317
322
new JsonRpcMethodsFactory ()
318
323
.methods (
@@ -433,6 +438,8 @@ public RequestBody createNetServicesRequestBody() {
433
438
434
439
public JsonRpcHttpService getJsonRpcHttpService (final boolean [] enabledNetServices ) {
435
440
441
+ setupMocksRequiredForBlockchainGenesisHash ();
442
+
436
443
JsonRpcConfiguration jsonRpcConfiguration = JsonRpcConfiguration .createDefault ();
437
444
WebSocketConfiguration webSocketConfiguration = WebSocketConfiguration .createDefault ();
438
445
P2PNetwork p2pNetwork = mock (P2PNetwork .class );
@@ -457,6 +464,14 @@ public JsonRpcHttpService getJsonRpcHttpService(final boolean[] enabledNetServic
457
464
jsonRpcConfiguration , webSocketConfiguration , p2pNetwork , metricsConfiguration , natService );
458
465
}
459
466
467
+ private void setupMocksRequiredForBlockchainGenesisHash () {
468
+ Blockchain blockchain = mock (Blockchain .class );
469
+ Block block = mock (Block .class );
470
+ lenient ().when (blockchainQueries .getBlockchain ()).thenReturn (blockchain );
471
+ lenient ().when (blockchain .getGenesisBlock ()).thenReturn (block );
472
+ lenient ().when (block .getHash ()).thenReturn (Hash .EMPTY );
473
+ }
474
+
460
475
@ Test
461
476
public void netServicesTestWhenJsonrpcWebsocketP2pNetworkAndMatricesIsDisabled ()
462
477
throws Exception {
0 commit comments