|
|
|
@ -48,6 +48,11 @@ import tech.pegasys.pantheon.ethereum.core.Transaction; |
|
|
|
|
import tech.pegasys.pantheon.ethereum.core.TransactionReceipt; |
|
|
|
|
import tech.pegasys.pantheon.ethereum.core.TransactionTestFixture; |
|
|
|
|
import tech.pegasys.pantheon.ethereum.core.Wei; |
|
|
|
|
import tech.pegasys.pantheon.ethereum.eth.manager.EthContext; |
|
|
|
|
import tech.pegasys.pantheon.ethereum.eth.manager.EthPeers; |
|
|
|
|
import tech.pegasys.pantheon.ethereum.eth.manager.EthProtocolManager; |
|
|
|
|
import tech.pegasys.pantheon.ethereum.eth.manager.EthProtocolManagerTestUtil; |
|
|
|
|
import tech.pegasys.pantheon.ethereum.eth.manager.RespondingEthPeer; |
|
|
|
|
import tech.pegasys.pantheon.ethereum.eth.sync.state.SyncState; |
|
|
|
|
import tech.pegasys.pantheon.ethereum.eth.transactions.TransactionPool.TransactionBatchAddedListener; |
|
|
|
|
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule; |
|
|
|
@ -59,7 +64,9 @@ import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem; |
|
|
|
|
import tech.pegasys.pantheon.testutil.TestClock; |
|
|
|
|
import tech.pegasys.pantheon.util.uint.UInt256; |
|
|
|
|
|
|
|
|
|
import java.util.Collections; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Set; |
|
|
|
|
|
|
|
|
|
import org.junit.Before; |
|
|
|
|
import org.junit.Test; |
|
|
|
@ -91,6 +98,9 @@ public class TransactionPoolTest { |
|
|
|
|
private TransactionPool transactionPool; |
|
|
|
|
private long genesisBlockGasLimit; |
|
|
|
|
private final AccountFilter accountFilter = mock(AccountFilter.class); |
|
|
|
|
private SyncState syncState; |
|
|
|
|
private EthContext ethContext; |
|
|
|
|
private PeerTransactionTracker peerTransactionTracker; |
|
|
|
|
|
|
|
|
|
@Before |
|
|
|
|
public void setUp() { |
|
|
|
@ -98,12 +108,21 @@ public class TransactionPoolTest { |
|
|
|
|
when(protocolSchedule.getByBlockNumber(anyLong())).thenReturn(protocolSpec); |
|
|
|
|
when(protocolSpec.getTransactionValidator()).thenReturn(transactionValidator); |
|
|
|
|
genesisBlockGasLimit = executionContext.getGenesis().getHeader().getGasLimit(); |
|
|
|
|
SyncState syncState = mock(SyncState.class); |
|
|
|
|
syncState = mock(SyncState.class); |
|
|
|
|
when(syncState.isInSync(anyLong())).thenReturn(true); |
|
|
|
|
|
|
|
|
|
ethContext = mock(EthContext.class); |
|
|
|
|
EthPeers ethPeers = mock(EthPeers.class); |
|
|
|
|
when(ethContext.getEthPeers()).thenReturn(ethPeers); |
|
|
|
|
peerTransactionTracker = mock(PeerTransactionTracker.class); |
|
|
|
|
transactionPool = |
|
|
|
|
new TransactionPool( |
|
|
|
|
transactions, protocolSchedule, protocolContext, batchAddedListener, syncState); |
|
|
|
|
transactions, |
|
|
|
|
protocolSchedule, |
|
|
|
|
protocolContext, |
|
|
|
|
batchAddedListener, |
|
|
|
|
syncState, |
|
|
|
|
ethContext, |
|
|
|
|
peerTransactionTracker); |
|
|
|
|
blockchain.observeBlockAdded(transactionPool); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -434,7 +453,13 @@ public class TransactionPoolTest { |
|
|
|
|
when(syncState.isInSync(anyLong())).thenReturn(false); |
|
|
|
|
TransactionPool transactionPool = |
|
|
|
|
new TransactionPool( |
|
|
|
|
transactions, protocolSchedule, protocolContext, batchAddedListener, syncState); |
|
|
|
|
transactions, |
|
|
|
|
protocolSchedule, |
|
|
|
|
protocolContext, |
|
|
|
|
batchAddedListener, |
|
|
|
|
syncState, |
|
|
|
|
ethContext, |
|
|
|
|
peerTransactionTracker); |
|
|
|
|
|
|
|
|
|
final TransactionTestFixture builder = new TransactionTestFixture(); |
|
|
|
|
final Transaction transaction1 = builder.nonce(1).createTransaction(KEY_PAIR1); |
|
|
|
@ -462,12 +487,6 @@ public class TransactionPoolTest { |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void shouldAllowRemoteTransactionsWhenInSync() { |
|
|
|
|
SyncState syncState = mock(SyncState.class); |
|
|
|
|
when(syncState.isInSync(anyLong())).thenReturn(true); |
|
|
|
|
TransactionPool transactionPool = |
|
|
|
|
new TransactionPool( |
|
|
|
|
transactions, protocolSchedule, protocolContext, batchAddedListener, syncState); |
|
|
|
|
|
|
|
|
|
final TransactionTestFixture builder = new TransactionTestFixture(); |
|
|
|
|
final Transaction transaction1 = builder.nonce(1).createTransaction(KEY_PAIR1); |
|
|
|
|
final Transaction transaction2 = builder.nonce(2).createTransaction(KEY_PAIR1); |
|
|
|
@ -491,6 +510,40 @@ public class TransactionPoolTest { |
|
|
|
|
assertTransactionPending(transaction3); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void shouldSendOnlyLocalTransactionToNewlyConnectedPeer() { |
|
|
|
|
EthProtocolManager ethProtocolManager = EthProtocolManagerTestUtil.create(); |
|
|
|
|
EthContext ethContext = ethProtocolManager.ethContext(); |
|
|
|
|
PeerTransactionTracker peerTransactionTracker = new PeerTransactionTracker(); |
|
|
|
|
TransactionPool transactionPool = |
|
|
|
|
new TransactionPool( |
|
|
|
|
transactions, |
|
|
|
|
protocolSchedule, |
|
|
|
|
protocolContext, |
|
|
|
|
batchAddedListener, |
|
|
|
|
syncState, |
|
|
|
|
ethContext, |
|
|
|
|
peerTransactionTracker); |
|
|
|
|
|
|
|
|
|
final TransactionTestFixture builder = new TransactionTestFixture(); |
|
|
|
|
final Transaction transactionLocal = builder.nonce(1).createTransaction(KEY_PAIR1); |
|
|
|
|
final Transaction transactionRemote = builder.nonce(2).createTransaction(KEY_PAIR1); |
|
|
|
|
when(transactionValidator.validate(any(Transaction.class))).thenReturn(valid()); |
|
|
|
|
when(transactionValidator.validateForSender( |
|
|
|
|
any(Transaction.class), nullable(Account.class), eq(true))) |
|
|
|
|
.thenReturn(valid()); |
|
|
|
|
|
|
|
|
|
transactionPool.addLocalTransaction(transactionLocal); |
|
|
|
|
transactionPool.addRemoteTransactions(Collections.singletonList(transactionRemote)); |
|
|
|
|
|
|
|
|
|
RespondingEthPeer peer = EthProtocolManagerTestUtil.createPeer(ethProtocolManager); |
|
|
|
|
|
|
|
|
|
Set<Transaction> transactionsToSendToPeer = |
|
|
|
|
peerTransactionTracker.claimTransactionsToSendToPeer(peer.getEthPeer()); |
|
|
|
|
|
|
|
|
|
assertThat(transactionsToSendToPeer).containsExactly(transactionLocal); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void assertTransactionPending(final Transaction t) { |
|
|
|
|
assertThat(transactions.getTransactionByHash(t.hash())).contains(t); |
|
|
|
|
} |
|
|
|
|