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

Commit

Permalink
tst
Browse files Browse the repository at this point in the history
  • Loading branch information
smatthewenglish committed Apr 16, 2019
1 parent 35defa4 commit 973fea8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import tech.pegasys.pantheon.ethereum.eth.EthereumWireProtocolConfiguration;
import tech.pegasys.pantheon.ethereum.eth.messages.EthPV62;
import tech.pegasys.pantheon.ethereum.eth.messages.StatusMessage;
import tech.pegasys.pantheon.ethereum.eth.messages.TransactionsMessage;
import tech.pegasys.pantheon.ethereum.eth.sync.BlockBroadcaster;
import tech.pegasys.pantheon.ethereum.eth.transactions.PeerTransactionTracker;
import tech.pegasys.pantheon.ethereum.eth.transactions.TransactionPool;
Expand Down Expand Up @@ -260,12 +261,11 @@ private void dispatchLocalTransaction(final EthPeer peer) {
System.out.println("888");

LOG.debug("Dispatching local transactions to {}.", peer);
// Iterable<Transaction> localTransactions = transactionPool.getLocalTransactions();
// peer.send(TransactionsMessage.create(localTransactions));
peerTransactionTracker.markTransactionsAsSeen(peer, transactionPool.getLocalTransactions());
for (Transaction tx : transactionPool.getLocalTransactions()) {
peerTransactionTracker.addToPeerSendQueue(peer, tx);
}
try{
Iterable<Transaction> localTransactions = transactionPool.getLocalTransactions();
peer.send(TransactionsMessage.create(localTransactions));
peerTransactionTracker.markTransactionsAsSeen(peer, transactionPool.getLocalTransactions());
} catch (PeerNotConnected ignored){}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1085,24 +1085,23 @@ public void transactionMessagesGoToTheCorrectExecutor() {

@Test
public void shouldSendLocalTransactionsToNewlyConnectedPeers() {
final SECP256K1.KeyPair KEY_PAIR1 = SECP256K1.KeyPair.generate();
SECP256K1.KeyPair KEY_PAIR1 = SECP256K1.KeyPair.generate();

final MetricsSystem metricsSystem = new NoOpMetricsSystem();
MetricsSystem metricsSystem = new NoOpMetricsSystem();

@SuppressWarnings("unchecked")
final ProtocolSchedule<Void> protocolSchedule = mock(ProtocolSchedule.class);
ProtocolSchedule<Void> protocolSchedule = mock(ProtocolSchedule.class);

@SuppressWarnings("unchecked")
final ProtocolSpec<Void> protocolSpec = mock(ProtocolSpec.class);
ProtocolSpec<Void> protocolSpec = mock(ProtocolSpec.class);

final TransactionValidator transactionValidator = mock(TransactionValidator.class);
TransactionValidator transactionValidator = mock(TransactionValidator.class);
MutableBlockchain blockchain;
final Transaction transaction1 = createTransaction(1, KEY_PAIR1);
final Transaction transaction2 = createTransaction(2, KEY_PAIR1);
Transaction transaction1 = createTransaction(1, KEY_PAIR1);

final ExecutionContextTestFixture executionContext = ExecutionContextTestFixture.create();
ExecutionContextTestFixture executionContext = ExecutionContextTestFixture.create();
blockchain = executionContext.getBlockchain();
final ProtocolContext<Void> protocolContext = executionContext.getProtocolContext();
ProtocolContext<Void> protocolContext = executionContext.getProtocolContext();
when(protocolSchedule.getByBlockNumber(anyLong())).thenReturn(protocolSpec);
when(protocolSpec.getTransactionValidator()).thenReturn(transactionValidator);

Expand All @@ -1115,11 +1114,9 @@ public void shouldSendLocalTransactionsToNewlyConnectedPeers() {
EthContext ethContext = new EthContext(protocolName, ethPeers, ethMessages, ethScheduler);

PeerTransactionTracker peerTransactionTracker = new PeerTransactionTracker();
TransactionsMessageSender transactionsMessageSender =
new TransactionsMessageSender(peerTransactionTracker);
TransactionsMessageSender transactionsMessageSender = new TransactionsMessageSender(peerTransactionTracker);

final PendingTransactions pendingTransactions =
new PendingTransactions(200, TestClock.fixed(), metricsSystem);
PendingTransactions pendingTransactions = new PendingTransactions(200, TestClock.fixed(), metricsSystem);

SyncState syncState = mock(SyncState.class);
when(syncState.isInSync(anyLong())).thenReturn(true);
Expand All @@ -1140,15 +1137,10 @@ public void shouldSendLocalTransactionsToNewlyConnectedPeers() {
when(transactionValidator.validateForSender(
eq(transaction1), nullable(Account.class), eq(true)))
.thenReturn(valid());
when(transactionValidator.validateForSender(
eq(transaction2), nullable(Account.class), eq(true)))
.thenReturn(valid());

assertThat(transactionPool.addLocalTransaction(transaction1)).isEqualTo(valid());
// assertThat(transactionPool.addLocalTransaction(transaction2)).isEqualTo(valid());

assertTransactionPending(transaction1, transactionPool.getPendingTransactions());
// assertTransactionPending(transaction2, transactionPool.getPendingTransactions());

/* * */

Expand All @@ -1158,24 +1150,26 @@ public void shouldSendLocalTransactionsToNewlyConnectedPeers() {
if (message.getCode() == EthPV62.STATUS) {
return;
}
BytesValue localTransactionData =
TransactionsMessage.create(Collections.singletonList(transaction1)).getData();
BytesValue localTransactionData = TransactionsMessage.create(Collections.singletonList(transaction1)).getData();

System.out.println(TransactionsMessage.create(Collections.singletonList(transaction1)).getData());
System.out.println(message.getData());

assertThat(message.getData()).isEqualTo(localTransactionData);
};

MockPeerConnection peer = new MockPeerConnection(caps, onSend);

final EthProtocolManager ethProtocolManager =
EthProtocolManager ethProtocolManager =
new EthProtocolManager(
blockchain,
protocolContext.getWorldStateArchive(),
1,
true,
1,
1,
1,
new NoOpMetricsSystem(),
EthereumWireProtocolConfiguration.defaultConfig());
EthereumWireProtocolConfiguration.defaultConfig(),
transactionPool,
peerTransactionTracker,
ethScheduler);

ethProtocolManager.handleNewConnection(peer);
}
Expand Down

0 comments on commit 973fea8

Please sign in to comment.