|
|
|
@ -55,6 +55,7 @@ import tech.pegasys.pantheon.util.uint.UInt256; |
|
|
|
|
import java.math.BigInteger; |
|
|
|
|
import java.time.Instant; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
import java.util.function.Supplier; |
|
|
|
|
|
|
|
|
|
import com.google.common.collect.Lists; |
|
|
|
@ -63,6 +64,7 @@ import org.junit.Test; |
|
|
|
|
public class BlockTransactionSelectorTest { |
|
|
|
|
|
|
|
|
|
private static final KeyPair keyPair = KeyPair.generate(); |
|
|
|
|
private static final long TRANSACTION_EVICTION_INTERVAL_MS = TimeUnit.MINUTES.toMillis(1); |
|
|
|
|
private final MetricsSystem metricsSystem = new NoOpMetricsSystem(); |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@ -75,7 +77,9 @@ public class BlockTransactionSelectorTest { |
|
|
|
|
final DefaultMutableWorldState worldState = inMemoryWorldState(); |
|
|
|
|
|
|
|
|
|
final PendingTransactions pendingTransactions = |
|
|
|
|
new PendingTransactions(5, TestClock.fixed(), metricsSystem); |
|
|
|
|
new PendingTransactions( |
|
|
|
|
TRANSACTION_EVICTION_INTERVAL_MS, 5, TestClock.fixed(), metricsSystem); |
|
|
|
|
|
|
|
|
|
final Supplier<Boolean> isCancelled = () -> false; |
|
|
|
|
|
|
|
|
|
final ProcessableBlockHeader blockHeader = |
|
|
|
@ -113,7 +117,8 @@ public class BlockTransactionSelectorTest { |
|
|
|
|
@Test |
|
|
|
|
public void failedTransactionsAreIncludedInTheBlock() { |
|
|
|
|
final PendingTransactions pendingTransactions = |
|
|
|
|
new PendingTransactions(5, TestClock.fixed(), metricsSystem); |
|
|
|
|
new PendingTransactions( |
|
|
|
|
TRANSACTION_EVICTION_INTERVAL_MS, 5, TestClock.fixed(), metricsSystem); |
|
|
|
|
|
|
|
|
|
final Transaction transaction = createTransaction(1); |
|
|
|
|
pendingTransactions.addRemoteTransaction(transaction); |
|
|
|
@ -165,7 +170,8 @@ public class BlockTransactionSelectorTest { |
|
|
|
|
@Test |
|
|
|
|
public void invalidTransactionsTransactionProcessingAreSkippedButBlockStillFills() { |
|
|
|
|
final PendingTransactions pendingTransactions = |
|
|
|
|
new PendingTransactions(5, TestClock.fixed(), metricsSystem); |
|
|
|
|
new PendingTransactions( |
|
|
|
|
TRANSACTION_EVICTION_INTERVAL_MS, 5, TestClock.fixed(), metricsSystem); |
|
|
|
|
|
|
|
|
|
final List<Transaction> transactionsToInject = Lists.newArrayList(); |
|
|
|
|
for (int i = 0; i < 5; i++) { |
|
|
|
@ -228,7 +234,8 @@ public class BlockTransactionSelectorTest { |
|
|
|
|
@Test |
|
|
|
|
public void subsetOfPendingTransactionsIncludedWhenBlockGasLimitHit() { |
|
|
|
|
final PendingTransactions pendingTransactions = |
|
|
|
|
new PendingTransactions(5, TestClock.fixed(), metricsSystem); |
|
|
|
|
new PendingTransactions( |
|
|
|
|
TRANSACTION_EVICTION_INTERVAL_MS, 5, TestClock.fixed(), metricsSystem); |
|
|
|
|
|
|
|
|
|
final List<Transaction> transactionsToInject = Lists.newArrayList(); |
|
|
|
|
// Transactions are reported in reverse order.
|
|
|
|
@ -294,7 +301,8 @@ public class BlockTransactionSelectorTest { |
|
|
|
|
@Test |
|
|
|
|
public void transactionOfferingGasPriceLessThanMinimumIsIdentifiedAndRemovedFromPending() { |
|
|
|
|
final PendingTransactions pendingTransactions = |
|
|
|
|
new PendingTransactions(5, TestClock.fixed(), metricsSystem); |
|
|
|
|
new PendingTransactions( |
|
|
|
|
TRANSACTION_EVICTION_INTERVAL_MS, 5, TestClock.fixed(), metricsSystem); |
|
|
|
|
|
|
|
|
|
final Blockchain blockchain = new TestBlockchain(); |
|
|
|
|
|
|
|
|
@ -339,7 +347,9 @@ public class BlockTransactionSelectorTest { |
|
|
|
|
@Test |
|
|
|
|
public void transactionTooLargeForBlockDoesNotPreventMoreBeingAddedIfBlockOccupancyNotReached() { |
|
|
|
|
final PendingTransactions pendingTransactions = |
|
|
|
|
new PendingTransactions(5, TestClock.fixed(), metricsSystem); |
|
|
|
|
new PendingTransactions( |
|
|
|
|
TRANSACTION_EVICTION_INTERVAL_MS, 5, TestClock.fixed(), metricsSystem); |
|
|
|
|
|
|
|
|
|
final Blockchain blockchain = new TestBlockchain(); |
|
|
|
|
final DefaultMutableWorldState worldState = inMemoryWorldState(); |
|
|
|
|
final Supplier<Boolean> isCancelled = () -> false; |
|
|
|
@ -410,7 +420,9 @@ public class BlockTransactionSelectorTest { |
|
|
|
|
@Test |
|
|
|
|
public void transactionSelectionStopsWhenSufficientBlockOccupancyIsReached() { |
|
|
|
|
final PendingTransactions pendingTransactions = |
|
|
|
|
new PendingTransactions(10, TestClock.fixed(), metricsSystem); |
|
|
|
|
new PendingTransactions( |
|
|
|
|
TRANSACTION_EVICTION_INTERVAL_MS, 5, TestClock.fixed(), metricsSystem); |
|
|
|
|
|
|
|
|
|
final Blockchain blockchain = new TestBlockchain(); |
|
|
|
|
final DefaultMutableWorldState worldState = inMemoryWorldState(); |
|
|
|
|
final Supplier<Boolean> isCancelled = () -> false; |
|
|
|
@ -492,7 +504,9 @@ public class BlockTransactionSelectorTest { |
|
|
|
|
@Test |
|
|
|
|
public void shouldDiscardTransactionsThatFailValidation() { |
|
|
|
|
final PendingTransactions pendingTransactions = |
|
|
|
|
new PendingTransactions(10, TestClock.fixed(), metricsSystem); |
|
|
|
|
new PendingTransactions( |
|
|
|
|
TRANSACTION_EVICTION_INTERVAL_MS, 5, TestClock.fixed(), metricsSystem); |
|
|
|
|
|
|
|
|
|
final TransactionProcessor transactionProcessor = mock(TransactionProcessor.class); |
|
|
|
|
final Blockchain blockchain = new TestBlockchain(); |
|
|
|
|
final DefaultMutableWorldState worldState = inMemoryWorldState(); |
|
|
|
|