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

Loading…
Cancel
Save