Rework RoundChangeManagerTest to not reuse validators (#469)

tmohay 6 years ago committed by GitHub
parent d1b24e97a6
commit 8644706bec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 25
      consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/statemachine/RoundChangeManagerTest.java

@ -27,6 +27,7 @@ import tech.pegasys.pantheon.consensus.ibft.ibftmessagedata.ProposalPayload;
import tech.pegasys.pantheon.consensus.ibft.ibftmessagedata.RoundChangePayload;
import tech.pegasys.pantheon.consensus.ibft.ibftmessagedata.SignedData;
import tech.pegasys.pantheon.consensus.ibft.validation.MessageValidator;
import tech.pegasys.pantheon.consensus.ibft.validation.RoundChangeMessageValidator;
import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair;
import tech.pegasys.pantheon.ethereum.ProtocolContext;
import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain;
@ -39,13 +40,11 @@ import tech.pegasys.pantheon.ethereum.mainnet.BlockHeaderValidator;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.junit.Before;
import org.junit.Test;
@ -80,10 +79,12 @@ public class RoundChangeManagerTest {
when(headerValidator.validateHeader(any(), any(), any(), any())).thenReturn(true);
BlockHeader parentHeader = mock(BlockHeader.class);
Map<ConsensusRoundIdentifier, MessageValidator> messageValidators = Maps.newHashMap();
RoundChangeMessageValidator.MessageValidatorForHeightFactory messageValidatorFactory =
mock(RoundChangeMessageValidator.MessageValidatorForHeightFactory.class);
messageValidators.put(
ri1,
when(messageValidatorFactory.createAt(ri1))
.thenAnswer(
invocation ->
new MessageValidator(
validators,
Util.publicKeyToAddress(proposerKey.getPublicKey()),
@ -91,9 +92,9 @@ public class RoundChangeManagerTest {
headerValidator,
protocolContext,
parentHeader));
messageValidators.put(
ri2,
when(messageValidatorFactory.createAt(ri2))
.thenAnswer(
invocation ->
new MessageValidator(
validators,
Util.publicKeyToAddress(validator1Key.getPublicKey()),
@ -101,9 +102,9 @@ public class RoundChangeManagerTest {
headerValidator,
protocolContext,
parentHeader));
messageValidators.put(
ri3,
when(messageValidatorFactory.createAt(ri3))
.thenAnswer(
invocation ->
new MessageValidator(
validators,
Util.publicKeyToAddress(validator2Key.getPublicKey()),
@ -112,7 +113,7 @@ public class RoundChangeManagerTest {
protocolContext,
parentHeader));
manager = new RoundChangeManager(2, validators, messageValidators::get);
manager = new RoundChangeManager(2, validators, messageValidatorFactory);
}
private SignedData<RoundChangePayload> makeRoundChangeMessage(

Loading…
Cancel
Save