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. 71
      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,39 +79,41 @@ 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(
ri1, when(messageValidatorFactory.createAt(ri1))
new MessageValidator( .thenAnswer(
validators, invocation ->
Util.publicKeyToAddress(proposerKey.getPublicKey()), new MessageValidator(
ri1, validators,
headerValidator, Util.publicKeyToAddress(proposerKey.getPublicKey()),
protocolContext, ri1,
parentHeader)); headerValidator,
protocolContext,
messageValidators.put( parentHeader));
ri2, when(messageValidatorFactory.createAt(ri2))
new MessageValidator( .thenAnswer(
validators, invocation ->
Util.publicKeyToAddress(validator1Key.getPublicKey()), new MessageValidator(
ri2, validators,
headerValidator, Util.publicKeyToAddress(validator1Key.getPublicKey()),
protocolContext, ri2,
parentHeader)); headerValidator,
protocolContext,
messageValidators.put( parentHeader));
ri3, when(messageValidatorFactory.createAt(ri3))
new MessageValidator( .thenAnswer(
validators, invocation ->
Util.publicKeyToAddress(validator2Key.getPublicKey()), new MessageValidator(
ri3, validators,
headerValidator, Util.publicKeyToAddress(validator2Key.getPublicKey()),
protocolContext, ri3,
parentHeader)); headerValidator,
protocolContext,
manager = new RoundChangeManager(2, validators, messageValidators::get); parentHeader));
manager = new RoundChangeManager(2, validators, messageValidatorFactory);
} }
private SignedData<RoundChangePayload> makeRoundChangeMessage( private SignedData<RoundChangePayload> makeRoundChangeMessage(

Loading…
Cancel
Save