Skip to content

Commit

Permalink
Use DeterministicEthScheduler in unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Ameziane H. <[email protected]>
  • Loading branch information
ahamlat committed Jan 8, 2025
1 parent 5d399c2 commit 50a50b7
Show file tree
Hide file tree
Showing 14 changed files with 28 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,6 @@ protected Object resultByBlockNumber(
}
return Optional.of(tracesList);
}))
.orElse(null);
.orElse(Collections.emptyList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import org.hyperledger.besu.ethereum.core.Transaction;
import org.hyperledger.besu.ethereum.eth.EthProtocol;
import org.hyperledger.besu.ethereum.eth.manager.EthPeers;
import org.hyperledger.besu.ethereum.eth.manager.EthScheduler;
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool;
import org.hyperledger.besu.ethereum.mainnet.ValidationResult;
import org.hyperledger.besu.ethereum.p2p.network.P2PNetwork;
Expand All @@ -54,6 +53,7 @@
import org.hyperledger.besu.nat.NatService;
import org.hyperledger.besu.plugin.services.storage.DataStorageFormat;
import org.hyperledger.besu.testutil.BlockTestUtil.ChainResources;
import org.hyperledger.besu.testutil.DeterministicEthScheduler;

import java.math.BigInteger;
import java.net.URL;
Expand Down Expand Up @@ -216,7 +216,7 @@ protected Map<String, JsonRpcMethod> getRpcMethods(
mock(ApiConfiguration.class),
Optional.empty(),
transactionSimulator,
new EthScheduler(1, 1, 1, new NoOpMetricsSystem()));
new DeterministicEthScheduler());
}

protected void startService() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.hyperledger.besu.ethereum.core.Synchronizer;
import org.hyperledger.besu.ethereum.eth.EthProtocol;
import org.hyperledger.besu.ethereum.eth.manager.EthPeers;
import org.hyperledger.besu.ethereum.eth.manager.EthScheduler;
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool;
import org.hyperledger.besu.ethereum.mainnet.MainnetProtocolSchedule;
import org.hyperledger.besu.ethereum.p2p.network.P2PNetwork;
Expand All @@ -46,6 +45,7 @@
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration;
import org.hyperledger.besu.nat.NatService;
import org.hyperledger.besu.testutil.DeterministicEthScheduler;

import java.io.IOException;
import java.math.BigInteger;
Expand Down Expand Up @@ -142,7 +142,7 @@ public void initServerAndClient() throws Exception {
mock(ApiConfiguration.class),
Optional.empty(),
mock(TransactionSimulator.class),
new EthScheduler(1, 1, 1, new NoOpMetricsSystem()));
new DeterministicEthScheduler());
service = createJsonRpcHttpService();
service.start().join();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import org.hyperledger.besu.ethereum.core.Synchronizer;
import org.hyperledger.besu.ethereum.eth.EthProtocol;
import org.hyperledger.besu.ethereum.eth.manager.EthPeers;
import org.hyperledger.besu.ethereum.eth.manager.EthScheduler;
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool;
import org.hyperledger.besu.ethereum.mainnet.MainnetProtocolSchedule;
import org.hyperledger.besu.ethereum.p2p.network.P2PNetwork;
Expand All @@ -51,6 +50,7 @@
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration;
import org.hyperledger.besu.nat.NatService;
import org.hyperledger.besu.testutil.DeterministicEthScheduler;

import java.io.IOException;
import java.math.BigInteger;
Expand Down Expand Up @@ -173,7 +173,7 @@ public static void initServerAndClient() throws Exception {
mock(ApiConfiguration.class),
Optional.empty(),
mock(TransactionSimulator.class),
new EthScheduler(1, 1, 1, new NoOpMetricsSystem()));
new DeterministicEthScheduler());
service = createJsonRpcHttpService();
jwtAuth = service.authenticationService.get().getJwtAuthProvider();
service.start().join();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import org.hyperledger.besu.ethereum.core.Synchronizer;
import org.hyperledger.besu.ethereum.eth.EthProtocol;
import org.hyperledger.besu.ethereum.eth.manager.EthPeers;
import org.hyperledger.besu.ethereum.eth.manager.EthScheduler;
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool;
import org.hyperledger.besu.ethereum.p2p.config.DiscoveryConfiguration;
import org.hyperledger.besu.ethereum.p2p.config.NetworkingConfiguration;
Expand All @@ -56,6 +55,7 @@
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration;
import org.hyperledger.besu.nat.NatService;
import org.hyperledger.besu.testutil.DeterministicEthScheduler;

import java.math.BigInteger;
import java.nio.file.Path;
Expand Down Expand Up @@ -239,7 +239,7 @@ private JsonRpcHttpService createJsonRpcHttpServiceWithRpcApis(final JsonRpcConf
mock(ApiConfiguration.class),
Optional.empty(),
mock(TransactionSimulator.class),
new EthScheduler(1, 1, 1, new NoOpMetricsSystem()));
new DeterministicEthScheduler());
final JsonRpcHttpService jsonRpcHttpService =
new JsonRpcHttpService(
vertx,
Expand Down Expand Up @@ -352,7 +352,7 @@ private JsonRpcHttpService createJsonRpcHttpService(
mock(ApiConfiguration.class),
Optional.empty(),
mock(TransactionSimulator.class),
new EthScheduler(1, 1, 1, new NoOpMetricsSystem()));
new DeterministicEthScheduler());
final JsonRpcHttpService jsonRpcHttpService =
new JsonRpcHttpService(
vertx,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.hyperledger.besu.ethereum.core.Synchronizer;
import org.hyperledger.besu.ethereum.eth.EthProtocol;
import org.hyperledger.besu.ethereum.eth.manager.EthPeers;
import org.hyperledger.besu.ethereum.eth.manager.EthScheduler;
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool;
import org.hyperledger.besu.ethereum.mainnet.MainnetProtocolSchedule;
import org.hyperledger.besu.ethereum.p2p.network.P2PNetwork;
Expand All @@ -47,6 +46,7 @@
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration;
import org.hyperledger.besu.nat.NatService;
import org.hyperledger.besu.testutil.DeterministicEthScheduler;

import java.math.BigInteger;
import java.nio.file.Path;
Expand Down Expand Up @@ -151,7 +151,7 @@ public static void initServerAndClient() throws Exception {
mock(ApiConfiguration.class),
Optional.empty(),
mock(TransactionSimulator.class),
new EthScheduler(1, 1, 1, new NoOpMetricsSystem()));
new DeterministicEthScheduler());
disabledRpcMethods = new HashMap<>();
addedRpcMethods = new HashSet<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import org.hyperledger.besu.ethereum.core.Synchronizer;
import org.hyperledger.besu.ethereum.eth.EthProtocol;
import org.hyperledger.besu.ethereum.eth.manager.EthPeers;
import org.hyperledger.besu.ethereum.eth.manager.EthScheduler;
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool;
import org.hyperledger.besu.ethereum.mainnet.MainnetProtocolSchedule;
import org.hyperledger.besu.ethereum.p2p.network.P2PNetwork;
Expand All @@ -53,6 +52,7 @@
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration;
import org.hyperledger.besu.nat.NatService;
import org.hyperledger.besu.testutil.DeterministicEthScheduler;

import java.io.FileOutputStream;
import java.io.IOException;
Expand Down Expand Up @@ -158,7 +158,7 @@ public void initServer() throws Exception {
mock(ApiConfiguration.class),
Optional.empty(),
mock(TransactionSimulator.class),
new EthScheduler(1, 1, 1, new NoOpMetricsSystem()));
new DeterministicEthScheduler());

System.setProperty("javax.net.ssl.trustStore", CLIENT_AS_CA_CERT.getKeyStoreFile().toString());
System.setProperty(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import org.hyperledger.besu.ethereum.core.Synchronizer;
import org.hyperledger.besu.ethereum.eth.EthProtocol;
import org.hyperledger.besu.ethereum.eth.manager.EthPeers;
import org.hyperledger.besu.ethereum.eth.manager.EthScheduler;
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool;
import org.hyperledger.besu.ethereum.mainnet.MainnetProtocolSchedule;
import org.hyperledger.besu.ethereum.p2p.network.P2PNetwork;
Expand All @@ -52,6 +51,7 @@
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration;
import org.hyperledger.besu.nat.NatService;
import org.hyperledger.besu.testutil.DeterministicEthScheduler;

import java.io.IOException;
import java.math.BigInteger;
Expand Down Expand Up @@ -144,7 +144,7 @@ public void beforeEach() {
mock(ApiConfiguration.class),
Optional.empty(),
mock(TransactionSimulator.class),
new EthScheduler(1, 1, 1, new NoOpMetricsSystem()));
new DeterministicEthScheduler());
}

@AfterEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import org.hyperledger.besu.ethereum.core.Synchronizer;
import org.hyperledger.besu.ethereum.eth.EthProtocol;
import org.hyperledger.besu.ethereum.eth.manager.EthPeers;
import org.hyperledger.besu.ethereum.eth.manager.EthScheduler;
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool;
import org.hyperledger.besu.ethereum.mainnet.MainnetProtocolSchedule;
import org.hyperledger.besu.ethereum.p2p.network.P2PNetwork;
Expand All @@ -52,6 +51,7 @@
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration;
import org.hyperledger.besu.nat.NatService;
import org.hyperledger.besu.testutil.DeterministicEthScheduler;

import java.io.IOException;
import java.io.UncheckedIOException;
Expand Down Expand Up @@ -145,7 +145,7 @@ public void initServer() throws Exception {
mock(ApiConfiguration.class),
Optional.empty(),
mock(TransactionSimulator.class),
new EthScheduler(1, 1, 1, new NoOpMetricsSystem()));
new DeterministicEthScheduler());
service = createJsonRpcHttpService(createJsonRpcConfig());
service.start().join();
baseUrl = service.url();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
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.eth.manager.EthScheduler;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.metrics.ObservableMetricsSystem;
import org.hyperledger.besu.testutil.DeterministicEthScheduler;

import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -68,10 +68,7 @@ public class DebugTraceBlockByHashTest {
public void setUp() {
debugTraceBlockByHash =
new DebugTraceBlockByHash(
protocolSchedule,
blockchainQueries,
metricsSystem,
new EthScheduler(1, 1, 1, metricsSystem));
protocolSchedule, blockchainQueries, metricsSystem, new DeterministicEthScheduler());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
import org.hyperledger.besu.ethereum.chain.Blockchain;
import org.hyperledger.besu.ethereum.core.Block;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.eth.manager.EthScheduler;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.metrics.ObservableMetricsSystem;
import org.hyperledger.besu.testutil.DeterministicEthScheduler;

import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -68,10 +68,7 @@ public class DebugTraceBlockByNumberTest {
public void setUp() {
debugTraceBlockByNumber =
new DebugTraceBlockByNumber(
protocolSchedule,
blockchainQueries,
metricsSystem,
new EthScheduler(1, 1, 1, metricsSystem));
protocolSchedule, blockchainQueries, metricsSystem, new DeterministicEthScheduler());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.hyperledger.besu.ethereum.core.ExecutionContextTestFixture;
import org.hyperledger.besu.ethereum.core.MiningConfiguration;
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
import org.hyperledger.besu.ethereum.eth.manager.EthScheduler;
import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions;
import org.hyperledger.besu.ethereum.mainnet.ProtocolScheduleBuilder;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpecAdapters;
Expand All @@ -47,6 +46,7 @@
import org.hyperledger.besu.evm.internal.EvmConfiguration;
import org.hyperledger.besu.metrics.ObservableMetricsSystem;
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
import org.hyperledger.besu.testutil.DeterministicEthScheduler;

import java.math.BigInteger;
import java.util.Arrays;
Expand Down Expand Up @@ -113,7 +113,7 @@ public void setUp() {
executionContextTestFixture.getProtocolSchedule(),
blockchainQueries,
metricsSystem,
new EthScheduler(1, 1, 1, metricsSystem));
new DeterministicEthScheduler());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
import org.hyperledger.besu.ethereum.api.query.BlockchainQueries;
import org.hyperledger.besu.ethereum.eth.manager.EthScheduler;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
import org.hyperledger.besu.testutil.DeterministicEthScheduler;

import java.util.function.Supplier;

Expand Down Expand Up @@ -76,7 +76,7 @@ public void shouldFailIfParamsExceedMaxRange(
blockchainQueries,
maxFilterRange,
new NoOpMetricsSystem(),
new EthScheduler(1, 1, 1, new NoOpMetricsSystem()));
new DeterministicEthScheduler());

final JsonRpcResponse response = method.response(request);
assertThat(response).isInstanceOf(JsonRpcErrorResponse.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration;
import org.hyperledger.besu.nat.NatService;
import org.hyperledger.besu.testutil.DeterministicEthScheduler;

import java.math.BigInteger;
import java.net.URISyntaxException;
Expand Down Expand Up @@ -208,7 +209,7 @@ public void before() throws URISyntaxException {
mock(ApiConfiguration.class),
Optional.empty(),
mock(TransactionSimulator.class),
new EthScheduler(1, 1, 1, new NoOpMetricsSystem())));
new DeterministicEthScheduler()));

websocketMethods.putAll(rpcMethods);
webSocketMessageHandlerSpy =
Expand Down

0 comments on commit 50a50b7

Please sign in to comment.