Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Fabio Di Fabio <[email protected]>
  • Loading branch information
fab-10 committed Mar 21, 2022
1 parent 98fa5a3 commit f9e1182
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 17 deletions.
8 changes: 6 additions & 2 deletions besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static org.hyperledger.besu.cli.DefaultCommandValues.getDefaultBesuDataPath;
import static org.hyperledger.besu.cli.config.NetworkName.MAINNET;
import static org.hyperledger.besu.cli.util.CommandLineUtils.DEPENDENCY_WARNING_MSG;
import static org.hyperledger.besu.cli.util.CommandLineUtils.DEPRECATED_AND_USELESS_WARNING_MSG;
import static org.hyperledger.besu.cli.util.CommandLineUtils.DEPRECATION_WARNING_MSG;
import static org.hyperledger.besu.config.experimental.MergeConfigOptions.isMergeEnabled;
import static org.hyperledger.besu.controller.BesuController.DATABASE_PATH;
Expand Down Expand Up @@ -1824,8 +1825,11 @@ private void issueOptionWarnings() {
logger.warn(
DEPRECATION_WARNING_MSG,
"--privacy-onchain-groups-enabled",
"--privacy-flexible-groups-enabled",
"--tx-pool-hashes-max-size");
"--privacy-flexible-groups-enabled");
}

if (pooledTransactionHashesSize != null) {
logger.warn(DEPRECATED_AND_USELESS_WARNING_MSG, "--tx-pool-hashes-max-size");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class CommandLineUtils {
public static final String MULTI_DEPENDENCY_WARNING_MSG =
"{} ignored because none of {} was defined.";
public static final String DEPRECATION_WARNING_MSG = "{} has been deprecated, use {} instead.";
public static final String DEPRECATED_AND_USELESS_WARNING_MSG =
"{} has been deprecated and is now useless, remove it.";

/**
* Check if options are passed that require an option to be true to have any effect and log a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import static org.hyperledger.besu.cli.config.NetworkName.RINKEBY;
import static org.hyperledger.besu.cli.config.NetworkName.ROPSTEN;
import static org.hyperledger.besu.cli.util.CommandLineUtils.DEPENDENCY_WARNING_MSG;
import static org.hyperledger.besu.cli.util.CommandLineUtils.DEPRECATED_AND_USELESS_WARNING_MSG;
import static org.hyperledger.besu.cli.util.CommandLineUtils.DEPRECATION_WARNING_MSG;
import static org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis.ENGINE;
import static org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis.ETH;
Expand Down Expand Up @@ -3884,6 +3885,13 @@ public void onchainPrivacyGroupEnabledOptionIsDeprecated() {
"--privacy-flexible-groups-enabled");
}

@Test
public void txPoolHashesMaxSizeOptionIsDeprecated() {
parseCommand("--tx-pool-hashes-max-size", "1024");

verify(mockLogger).warn(DEPRECATED_AND_USELESS_WARNING_MSG, "--tx-pool-hashes-max-size");
}

@Test
public void flexiblePrivacyGroupEnabledFlagValueIsSet() {
parseCommand(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

Expand Down Expand Up @@ -54,12 +55,13 @@ public TransactionBroadcaster(
}

public void handlePeerConnection(final EthPeer peer) {
if (peer.hasSupportForMessage(EthPV65.NEW_POOLED_TRANSACTION_HASHES)) {
sendTransactionHashes(
toTransactionList(pendingTransactions.getTransactionInfo()), List.of(peer));
} else {
sendFullTransactions(
toTransactionList(pendingTransactions.getTransactionInfo()), List.of(peer));
Set<TransactionInfo> pendingTransactionInfo = pendingTransactions.getTransactionInfo();
if (!pendingTransactionInfo.isEmpty()) {
if (peer.hasSupportForMessage(EthPV65.NEW_POOLED_TRANSACTION_HASHES)) {
sendTransactionHashes(toTransactionList(pendingTransactionInfo), List.of(peer));
} else {
sendFullTransactions(toTransactionList(pendingTransactionInfo), List.of(peer));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public void addRemoteTransactions(final Collection<Transaction> transactions) {
if (!syncState.isInSync(SYNC_TOLERANCE)) {
return;
}
final Set<Transaction> addedTransactions = new HashSet<>();
final Set<Transaction> addedTransactions = new HashSet<>(transactions.size());
for (final Transaction transaction : transactions) {
if (pendingTransactions.containsTransaction(transaction.getHash())) {
// We already have this transaction, don't even validate it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ public void testDisconnect() {
when(ethContext.getEthMessages()).thenReturn(mock(EthMessages.class));
when(ethContext.getEthPeers()).thenReturn(ethPeers);
final EthScheduler ethScheduler = mock(EthScheduler.class);
final ArgumentCaptor<Runnable> sendTaskCapture = ArgumentCaptor.forClass(Runnable.class);
doNothing().when(ethScheduler).scheduleSyncWorkerTask(sendTaskCapture.capture());
when(ethContext.getScheduler()).thenReturn(ethScheduler);
final SyncState state = mock(SyncState.class);
final GasPricePendingTransactionsSorter pendingTransactions =
Expand Down Expand Up @@ -122,9 +120,7 @@ public void testDisconnect() {
RespondingEthPeer.builder().ethProtocolManager(ethProtocolManager).build();
assertThat(ethPeer.getEthPeer()).isNotNull();
assertThat(ethPeer.getEthPeer().isDisconnected()).isFalse();
sendTaskCapture.getValue().run();
ethPeer.disconnect(DisconnectMessage.DisconnectReason.CLIENT_QUITTING);
verify(transactionsMessageSender).sendTransactionsToPeer(ethPeer.getEthPeer());
verify(peerTransactionTracker, times(1)).onDisconnect(ethPeer.getEthPeer());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.hyperledger.besu.ethereum.eth.messages.TransactionsMessage;
import org.hyperledger.besu.plugin.services.metrics.Counter;

import com.google.common.collect.ImmutableSet;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
Expand Down Expand Up @@ -57,7 +56,7 @@ public void shouldMarkAllReceivedTransactionsAsSeen() {
ofMinutes(1));

verify(transactionTracker)
.markTransactionsAsSeen(peer1, ImmutableSet.of(transaction1, transaction2, transaction3));
.markTransactionsAsSeen(peer1, asList(transaction1, transaction2, transaction3));
}

@Test
Expand All @@ -67,8 +66,7 @@ public void shouldAddReceivedTransactionsToTransactionPool() {
TransactionsMessage.create(asList(transaction1, transaction2, transaction3)),
now(),
ofMinutes(1));
verify(transactionPool)
.addRemoteTransactions(ImmutableSet.of(transaction1, transaction2, transaction3));
verify(transactionPool).addRemoteTransactions(asList(transaction1, transaction2, transaction3));
}

@Test
Expand Down

0 comments on commit f9e1182

Please sign in to comment.