Fix non-deterministic test caused by variable size of generated transactions (#1399)

Fix non-deterministic test caused by variable size of generated transactions. 
Validate transactions against a size range rather than a fixed size
* Use assertj instead of own method.

Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>
pull/2/head
Abdelhamid Bakhta 6 years ago committed by GitHub
parent ec2cd8fae3
commit 3a4014ddf7
  1. 8
      ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/messages/LimitedTransactionsMessagesTest.java

@ -12,6 +12,7 @@
*/ */
package tech.pegasys.pantheon.ethereum.eth.messages; package tech.pegasys.pantheon.ethereum.eth.messages;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static tech.pegasys.pantheon.ethereum.eth.messages.LimitedTransactionsMessages.LIMIT; import static tech.pegasys.pantheon.ethereum.eth.messages.LimitedTransactionsMessages.LIMIT;
@ -40,12 +41,13 @@ public class LimitedTransactionsMessagesTest {
public void createLimited() { public void createLimited() {
final Set<Transaction> txs = generator.transactions(6000); final Set<Transaction> txs = generator.transactions(6000);
final LimitedTransactionsMessages firstMessage = LimitedTransactionsMessages.createLimited(txs); final LimitedTransactionsMessages firstMessage = LimitedTransactionsMessages.createLimited(txs);
assertEquals(5219, firstMessage.getIncludedTransactions().size()); assertThat(firstMessage.getIncludedTransactions().size()).isBetween(4990, 5250);
txs.removeAll(firstMessage.getIncludedTransactions()); txs.removeAll(firstMessage.getIncludedTransactions());
assertEquals(781, txs.size()); assertThat(txs.size()).isBetween(700, 800);
final LimitedTransactionsMessages secondMessage = final LimitedTransactionsMessages secondMessage =
LimitedTransactionsMessages.createLimited(txs); LimitedTransactionsMessages.createLimited(txs);
assertEquals(781, secondMessage.getIncludedTransactions().size()); assertThat(secondMessage.getIncludedTransactions().size()).isBetween(700, 800);
txs.removeAll(secondMessage.getIncludedTransactions()); txs.removeAll(secondMessage.getIncludedTransactions());
assertEquals(0, txs.size()); assertEquals(0, txs.size());
assertTrue( assertTrue(

Loading…
Cancel
Save