Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Commit

Permalink
Clock.systemUTC only used once.
Browse files Browse the repository at this point in the history
TestClock class added with a factory method for a fixed clock.
  • Loading branch information
rojotek committed Mar 6, 2019
1 parent 553c1dd commit 8a3aedd
Show file tree
Hide file tree
Showing 29 changed files with 116 additions and 70 deletions.
1 change: 1 addition & 0 deletions consensus/clique/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ dependencies {

testImplementation project(path: ':ethereum:core', configuration: 'testSupportArtifacts')
testImplementation project(path: ':consensus:common', configuration: 'testArtifacts')
testImplementation project(':testutil')

testImplementation 'junit:junit'
testImplementation 'org.assertj:assertj-core'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
import tech.pegasys.pantheon.ethereum.core.Wei;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule;
import tech.pegasys.pantheon.ethereum.worldstate.WorldStateArchive;
import tech.pegasys.pantheon.testutil.TestClock;
import tech.pegasys.pantheon.util.bytes.BytesValue;

import java.time.Clock;
import java.util.List;

import com.google.common.collect.Lists;
Expand Down Expand Up @@ -110,7 +110,7 @@ public void proposerAddressCanBeExtractFromAConstructedBlock() {
new CliqueBlockCreator(
coinbase,
parent -> extraData.encode(),
new PendingTransactions(5, Clock.systemUTC()),
new PendingTransactions(5, TestClock.fixed()),
protocolContext,
protocolSchedule,
gasLimit -> gasLimit,
Expand All @@ -137,7 +137,7 @@ public void insertsValidVoteIntoConstructedBlock() {
new CliqueBlockCreator(
coinbase,
parent -> extraData.encode(),
new PendingTransactions(5, Clock.systemUTC()),
new PendingTransactions(5, TestClock.fixed()),
protocolContext,
protocolSchedule,
gasLimit -> gasLimit,
Expand All @@ -163,7 +163,7 @@ public void insertsNoVoteWhenAuthInValidators() {
new CliqueBlockCreator(
coinbase,
parent -> extraData.encode(),
new PendingTransactions(5, Clock.systemUTC()),
new PendingTransactions(5, TestClock.fixed()),
protocolContext,
protocolSchedule,
gasLimit -> gasLimit,
Expand Down Expand Up @@ -192,7 +192,7 @@ public void insertsNoVoteWhenAtEpoch() {
new CliqueBlockCreator(
coinbase,
parent -> extraData.encode(),
new PendingTransactions(5, Clock.systemUTC()),
new PendingTransactions(5, TestClock.fixed()),
protocolContext,
protocolSchedule,
gasLimit -> gasLimit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
import tech.pegasys.pantheon.ethereum.core.PendingTransactions;
import tech.pegasys.pantheon.ethereum.core.Util;
import tech.pegasys.pantheon.ethereum.core.Wei;
import tech.pegasys.pantheon.testutil.TestClock;
import tech.pegasys.pantheon.util.bytes.BytesValue;

import java.time.Clock;
import java.util.List;
import java.util.Random;
import java.util.concurrent.Executors;
Expand Down Expand Up @@ -87,7 +87,7 @@ public void extraDataCreatedOnEpochBlocksContainsValidators() {
cliqueProtocolContext,
Executors.newSingleThreadExecutor(),
CliqueProtocolSchedule.create(GENESIS_CONFIG_OPTIONS, proposerKeyPair),
new PendingTransactions(1, Clock.systemUTC()),
new PendingTransactions(1, TestClock.fixed()),
proposerKeyPair,
new MiningParameters(AddressHelpers.ofValue(1), Wei.ZERO, wrappedVanityData, false),
mock(CliqueBlockScheduler.class),
Expand Down Expand Up @@ -117,7 +117,7 @@ public void extraDataForNonEpochBlocksDoesNotContainValidaors() {
cliqueProtocolContext,
Executors.newSingleThreadExecutor(),
CliqueProtocolSchedule.create(GENESIS_CONFIG_OPTIONS, proposerKeyPair),
new PendingTransactions(1, Clock.systemUTC()),
new PendingTransactions(1, TestClock.fixed()),
proposerKeyPair,
new MiningParameters(AddressHelpers.ofValue(1), Wei.ZERO, wrappedVanityData, false),
mock(CliqueBlockScheduler.class),
Expand Down
1 change: 1 addition & 0 deletions consensus/ibft/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ dependencies {
testImplementation project(path: ':ethereum:core', configuration: 'testSupportArtifacts')
testImplementation project(path: ':config:', configuration: 'testSupportArtifacts')
testImplementation project(path: ':consensus:common', configuration: 'testArtifacts')
testImplementation project(':testutil')

integrationTestImplementation 'junit:junit'
integrationTestImplementation 'org.assertj:assertj-core'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import tech.pegasys.pantheon.ethereum.core.Wei;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule;
import tech.pegasys.pantheon.ethereum.worldstate.WorldStateArchive;
import tech.pegasys.pantheon.testutil.TestClock;
import tech.pegasys.pantheon.util.Subscribers;
import tech.pegasys.pantheon.util.bytes.BytesValue;
import tech.pegasys.pantheon.util.uint.UInt256;
Expand Down Expand Up @@ -303,7 +304,7 @@ private static ControllerAndState createControllerAndFinalState(
ibftEventQueue,
BLOCK_TIMER_SEC * 1000,
Executors.newScheduledThreadPool(1),
Clock.systemUTC()),
TestClock.fixed()),
blockCreatorFactory,
new MessageFactory(nodeKeys),
clock);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
import tech.pegasys.pantheon.ethereum.mainnet.BlockHeaderValidator;
import tech.pegasys.pantheon.ethereum.mainnet.HeaderValidationMode;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule;
import tech.pegasys.pantheon.testutil.TestClock;
import tech.pegasys.pantheon.util.bytes.BytesValue;

import java.time.Clock;
import java.time.Instant;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -92,7 +92,7 @@ public void createdBlockPassesValidationRulesAndHasAppropriateHashAndMixHash() {
0,
initialValidatorList)
.encode(),
new PendingTransactions(1, Clock.systemUTC()),
new PendingTransactions(1, TestClock.fixed()),
protContext,
protocolSchedule,
parentGasLimit -> parentGasLimit,
Expand Down
1 change: 1 addition & 0 deletions consensus/ibftlegacy/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ dependencies {

testImplementation project(path: ':ethereum:core', configuration: 'testSupportArtifacts')
testImplementation project(path: ':consensus:ibft', configuration: 'testSupportArtifacts')
testImplementation project(':testutil')

testImplementation 'junit:junit'
testImplementation 'org.assertj:assertj-core'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
import tech.pegasys.pantheon.ethereum.mainnet.BlockHeaderValidator;
import tech.pegasys.pantheon.ethereum.mainnet.HeaderValidationMode;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule;
import tech.pegasys.pantheon.testutil.TestClock;
import tech.pegasys.pantheon.util.bytes.BytesValue;

import java.time.Clock;
import java.time.Instant;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -97,7 +97,7 @@ public void headerProducedPassesValidationRules() {
null,
initialValidatorList)
.encode(),
new PendingTransactions(1, Clock.systemUTC()),
new PendingTransactions(1, TestClock.fixed()),
protContext,
protocolSchedule,
parentGasLimit -> parentGasLimit,
Expand Down
1 change: 1 addition & 0 deletions ethereum/blockcreation/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ dependencies {
testImplementation project(path: ':config', configuration: 'testSupportArtifacts')
testImplementation project(path: ':ethereum:core', configuration: 'testSupportArtifacts')
testImplementation project(path: ':ethereum:core', configuration: 'testArtifacts')
testImplementation project(':testutil')

testImplementation 'junit:junit'
testImplementation 'org.assertj:assertj-core'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@
import tech.pegasys.pantheon.ethereum.vm.TestBlockchain;
import tech.pegasys.pantheon.ethereum.worldstate.DefaultMutableWorldState;
import tech.pegasys.pantheon.services.kvstore.InMemoryKeyValueStorage;
import tech.pegasys.pantheon.testutil.TestClock;
import tech.pegasys.pantheon.util.bytes.BytesValue;
import tech.pegasys.pantheon.util.uint.UInt256;

import java.time.Clock;
import java.time.Instant;
import java.util.List;
import java.util.function.Supplier;
Expand All @@ -71,7 +71,7 @@ public void emptyPendingTransactionsResultsInEmptyVettingResult() {
final TransactionProcessor transactionProcessor =
protocolSchedule.getByBlockNumber(0).getTransactionProcessor();
final DefaultMutableWorldState worldState = inMemoryWorldState();
final PendingTransactions pendingTransactions = new PendingTransactions(5, Clock.systemUTC());
final PendingTransactions pendingTransactions = new PendingTransactions(5, TestClock.fixed());
final Supplier<Boolean> isCancelled = () -> false;

final ProcessableBlockHeader blockHeader =
Expand Down Expand Up @@ -108,7 +108,7 @@ public void emptyPendingTransactionsResultsInEmptyVettingResult() {

@Test
public void failedTransactionsAreIncludedInTheBlock() {
final PendingTransactions pendingTransactions = new PendingTransactions(5, Clock.systemUTC());
final PendingTransactions pendingTransactions = new PendingTransactions(5, TestClock.fixed());

final Transaction transaction = createTransaction(1);
pendingTransactions.addRemoteTransaction(transaction);
Expand Down Expand Up @@ -159,7 +159,7 @@ public void failedTransactionsAreIncludedInTheBlock() {

@Test
public void invalidTransactionsTransactionProcessingAreSkippedButBlockStillFills() {
final PendingTransactions pendingTransactions = new PendingTransactions(5, Clock.systemUTC());
final PendingTransactions pendingTransactions = new PendingTransactions(5, TestClock.fixed());

final List<Transaction> transactionsToInject = Lists.newArrayList();
for (int i = 0; i < 5; i++) {
Expand Down Expand Up @@ -221,7 +221,7 @@ public void invalidTransactionsTransactionProcessingAreSkippedButBlockStillFills

@Test
public void subsetOfPendingTransactionsIncludedWhenBlockGasLimitHit() {
final PendingTransactions pendingTransactions = new PendingTransactions(5, Clock.systemUTC());
final PendingTransactions pendingTransactions = new PendingTransactions(5, TestClock.fixed());

final List<Transaction> transactionsToInject = Lists.newArrayList();
// Transactions are reported in reverse order.
Expand Down Expand Up @@ -286,7 +286,7 @@ public void subsetOfPendingTransactionsIncludedWhenBlockGasLimitHit() {

@Test
public void transactionOfferingGasPriceLessThanMinimumIsIdentifiedAndRemovedFromPending() {
final PendingTransactions pendingTransactions = new PendingTransactions(5, Clock.systemUTC());
final PendingTransactions pendingTransactions = new PendingTransactions(5, TestClock.fixed());

final Blockchain blockchain = new TestBlockchain();

Expand Down Expand Up @@ -330,7 +330,7 @@ public void transactionOfferingGasPriceLessThanMinimumIsIdentifiedAndRemovedFrom

@Test
public void transactionTooLargeForBlockDoesNotPreventMoreBeingAddedIfBlockOccupancyNotReached() {
final PendingTransactions pendingTransactions = new PendingTransactions(5, Clock.systemUTC());
final PendingTransactions pendingTransactions = new PendingTransactions(5, TestClock.fixed());
final Blockchain blockchain = new TestBlockchain();
final DefaultMutableWorldState worldState = inMemoryWorldState();
final Supplier<Boolean> isCancelled = () -> false;
Expand Down Expand Up @@ -400,7 +400,7 @@ public void transactionTooLargeForBlockDoesNotPreventMoreBeingAddedIfBlockOccupa

@Test
public void transactionSelectionStopsWhenSufficientBlockOccupancyIsReached() {
final PendingTransactions pendingTransactions = new PendingTransactions(10, Clock.systemUTC());
final PendingTransactions pendingTransactions = new PendingTransactions(10, TestClock.fixed());
final Blockchain blockchain = new TestBlockchain();
final DefaultMutableWorldState worldState = inMemoryWorldState();
final Supplier<Boolean> isCancelled = () -> false;
Expand Down Expand Up @@ -481,7 +481,7 @@ public void transactionSelectionStopsWhenSufficientBlockOccupancyIsReached() {

@Test
public void shouldDiscardTransactionsThatFailValidation() {
final PendingTransactions pendingTransactions = new PendingTransactions(10, Clock.systemUTC());
final PendingTransactions pendingTransactions = new PendingTransactions(10, TestClock.fixed());
final TransactionProcessor transactionProcessor = mock(TransactionProcessor.class);
final Blockchain blockchain = new TestBlockchain();
final DefaultMutableWorldState worldState = inMemoryWorldState();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
import tech.pegasys.pantheon.ethereum.mainnet.EthHasher.Light;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolScheduleBuilder;
import tech.pegasys.pantheon.ethereum.mainnet.ValidationTestUtils;
import tech.pegasys.pantheon.testutil.TestClock;
import tech.pegasys.pantheon.util.bytes.BytesValue;

import java.io.IOException;
import java.time.Clock;
import java.util.function.Function;

import com.google.common.collect.Lists;
Expand Down Expand Up @@ -63,7 +63,7 @@ public void createMainnetBlock1() throws IOException {
new EthHashBlockCreator(
BLOCK_1_COINBASE,
parent -> BLOCK_1_EXTRA_DATA,
new PendingTransactions(1, Clock.systemUTC()),
new PendingTransactions(1, TestClock.fixed()),
executionContextTestFixture.getProtocolContext(),
executionContextTestFixture.getProtocolSchedule(),
gasLimit -> gasLimit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
import tech.pegasys.pantheon.ethereum.core.MiningParameters;
import tech.pegasys.pantheon.ethereum.core.MiningParametersTestBuilder;
import tech.pegasys.pantheon.ethereum.core.PendingTransactions;
import tech.pegasys.pantheon.testutil.TestClock;
import tech.pegasys.pantheon.util.Subscribers;

import java.time.Clock;
import java.util.concurrent.Executors;

import org.junit.Test;
Expand All @@ -36,9 +36,9 @@ public void startingMiningWithoutCoinbaseThrowsException() {
null,
Executors.newCachedThreadPool(),
null,
new PendingTransactions(1, Clock.systemUTC()),
new PendingTransactions(1, TestClock.fixed()),
miningParameters,
new DefaultBlockScheduler(1, 10, Clock.systemUTC()));
new DefaultBlockScheduler(1, 10, TestClock.fixed()));

assertThatExceptionOfType(CoinbaseNotSetException.class)
.isThrownBy(() -> executor.startAsyncMining(new Subscribers<>(), null))
Expand All @@ -54,9 +54,9 @@ public void settingCoinbaseToNullThrowsException() {
null,
Executors.newCachedThreadPool(),
null,
new PendingTransactions(1, Clock.systemUTC()),
new PendingTransactions(1, TestClock.fixed()),
miningParameters,
new DefaultBlockScheduler(1, 10, Clock.systemUTC()));
new DefaultBlockScheduler(1, 10, TestClock.fixed()));

assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> executor.setCoinbase(null))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair;
import tech.pegasys.pantheon.ethereum.core.PendingTransactions.TransactionSelectionResult;
import tech.pegasys.pantheon.testutil.TestClock;

import java.time.Clock;
import java.util.ArrayList;
import java.util.List;
import java.util.OptionalLong;
Expand All @@ -34,7 +34,7 @@ public class PendingTransactionsTest {
private static final KeyPair KEYS1 = KeyPair.generate();
private static final KeyPair KEYS2 = KeyPair.generate();
private final PendingTransactions transactions =
new PendingTransactions(MAX_TRANSACTIONS, Clock.systemUTC());
new PendingTransactions(MAX_TRANSACTIONS, TestClock.fixed());
private final Transaction transaction1 = createTransaction(2);
private final Transaction transaction2 = createTransaction(1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSpec;
import tech.pegasys.pantheon.ethereum.mainnet.TransactionValidator;
import tech.pegasys.pantheon.ethereum.mainnet.ValidationResult;
import tech.pegasys.pantheon.testutil.TestClock;
import tech.pegasys.pantheon.util.uint.UInt256;

import java.time.Clock;
import java.util.List;
import java.util.OptionalLong;

Expand All @@ -68,7 +68,7 @@ public class TransactionPoolTest {
private final TransactionValidator transactionValidator = mock(TransactionValidator.class);
private MutableBlockchain blockchain;
private final PendingTransactions transactions =
new PendingTransactions(MAX_TRANSACTIONS, Clock.systemUTC());
new PendingTransactions(MAX_TRANSACTIONS, TestClock.fixed());
private final Transaction transaction1 = createTransaction(1);
private final Transaction transaction2 = createTransaction(2);
private TransactionPool transactionPool;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@
import tech.pegasys.pantheon.ethereum.p2p.wire.RawMessage;
import tech.pegasys.pantheon.ethereum.worldstate.WorldStateArchive;
import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem;
import tech.pegasys.pantheon.testutil.TestClock;
import tech.pegasys.pantheon.util.bytes.BytesValue;
import tech.pegasys.pantheon.util.uint.UInt256;

import java.time.Clock;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -1015,7 +1015,7 @@ public void transactionMessagesGoToTheCorrectExecutor() {
// Create a transaction pool. This has a side effect of registring a listener for the
// transactions message.
TransactionPoolFactory.createTransactionPool(
protocolSchedule, protocolContext, ethManager.ethContext(), Clock.systemUTC());
protocolSchedule, protocolContext, ethManager.ethContext(), TestClock.fixed());

// Send just a transaction message.
final PeerConnection peer = setupPeer(ethManager, (cap, msg, connection) -> {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@
import tech.pegasys.pantheon.ethereum.p2p.wire.messages.DisconnectMessage.DisconnectReason;
import tech.pegasys.pantheon.ethereum.worldstate.WorldStateArchive;
import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem;
import tech.pegasys.pantheon.testutil.TestClock;
import tech.pegasys.pantheon.util.bytes.BytesValue;

import java.io.Closeable;
import java.io.IOException;
import java.net.InetAddress;
import java.time.Clock;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -133,7 +133,7 @@ public TestNode(
final EthContext ethContext = ethProtocolManager.ethContext();
transactionPool =
TransactionPoolFactory.createTransactionPool(
protocolSchedule, protocolContext, ethContext, Clock.systemUTC());
protocolSchedule, protocolContext, ethContext, TestClock.fixed());
networkRunner.start();

selfPeer = new DefaultPeer(id(), endpoint());
Expand Down
Loading

0 comments on commit 8a3aedd

Please sign in to comment.