|
|
@ -19,10 +19,11 @@ import static org.mockito.Mockito.verify; |
|
|
|
import static org.mockito.Mockito.when; |
|
|
|
import static org.mockito.Mockito.when; |
|
|
|
|
|
|
|
|
|
|
|
import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier; |
|
|
|
import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier; |
|
|
|
import tech.pegasys.pantheon.consensus.ibft.payload.CommitPayload; |
|
|
|
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Commit; |
|
|
|
|
|
|
|
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Prepare; |
|
|
|
|
|
|
|
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Proposal; |
|
|
|
import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory; |
|
|
|
import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory; |
|
|
|
import tech.pegasys.pantheon.consensus.ibft.payload.PreparePayload; |
|
|
|
import tech.pegasys.pantheon.consensus.ibft.payload.PreparePayload; |
|
|
|
import tech.pegasys.pantheon.consensus.ibft.payload.ProposalPayload; |
|
|
|
|
|
|
|
import tech.pegasys.pantheon.consensus.ibft.payload.SignedData; |
|
|
|
import tech.pegasys.pantheon.consensus.ibft.payload.SignedData; |
|
|
|
import tech.pegasys.pantheon.consensus.ibft.validation.MessageValidator; |
|
|
|
import tech.pegasys.pantheon.consensus.ibft.validation.MessageValidator; |
|
|
|
import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair; |
|
|
|
import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair; |
|
|
@ -80,8 +81,9 @@ public class RoundStateTest { |
|
|
|
when(messageValidator.addSignedProposalPayload(any())).thenReturn(false); |
|
|
|
when(messageValidator.addSignedProposalPayload(any())).thenReturn(false); |
|
|
|
final RoundState roundState = new RoundState(roundIdentifier, 1, messageValidator); |
|
|
|
final RoundState roundState = new RoundState(roundIdentifier, 1, messageValidator); |
|
|
|
|
|
|
|
|
|
|
|
final SignedData<ProposalPayload> proposal = |
|
|
|
final Proposal proposal = |
|
|
|
validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block); |
|
|
|
new Proposal( |
|
|
|
|
|
|
|
validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block)); |
|
|
|
|
|
|
|
|
|
|
|
assertThat(roundState.setProposedBlock(proposal)).isFalse(); |
|
|
|
assertThat(roundState.setProposedBlock(proposal)).isFalse(); |
|
|
|
assertThat(roundState.isPrepared()).isFalse(); |
|
|
|
assertThat(roundState.isPrepared()).isFalse(); |
|
|
@ -94,15 +96,16 @@ public class RoundStateTest { |
|
|
|
when(messageValidator.addSignedProposalPayload(any())).thenReturn(true); |
|
|
|
when(messageValidator.addSignedProposalPayload(any())).thenReturn(true); |
|
|
|
final RoundState roundState = new RoundState(roundIdentifier, 1, messageValidator); |
|
|
|
final RoundState roundState = new RoundState(roundIdentifier, 1, messageValidator); |
|
|
|
|
|
|
|
|
|
|
|
final SignedData<ProposalPayload> proposal = |
|
|
|
final Proposal proposal = |
|
|
|
validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block); |
|
|
|
new Proposal( |
|
|
|
|
|
|
|
validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block)); |
|
|
|
|
|
|
|
|
|
|
|
assertThat(roundState.setProposedBlock(proposal)).isTrue(); |
|
|
|
assertThat(roundState.setProposedBlock(proposal)).isTrue(); |
|
|
|
assertThat(roundState.isPrepared()).isTrue(); |
|
|
|
assertThat(roundState.isPrepared()).isTrue(); |
|
|
|
assertThat(roundState.isCommitted()).isFalse(); |
|
|
|
assertThat(roundState.isCommitted()).isFalse(); |
|
|
|
assertThat(roundState.constructPreparedCertificate()).isNotEmpty(); |
|
|
|
assertThat(roundState.constructPreparedCertificate()).isNotEmpty(); |
|
|
|
assertThat(roundState.constructPreparedCertificate().get().getProposalPayload()) |
|
|
|
assertThat(roundState.constructPreparedCertificate().get().getProposalPayload()) |
|
|
|
.isEqualTo(proposal); |
|
|
|
.isEqualTo(proposal.getSignedPayload()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
@ -112,20 +115,22 @@ public class RoundStateTest { |
|
|
|
|
|
|
|
|
|
|
|
final RoundState roundState = new RoundState(roundIdentifier, 1, messageValidator); |
|
|
|
final RoundState roundState = new RoundState(roundIdentifier, 1, messageValidator); |
|
|
|
|
|
|
|
|
|
|
|
final SignedData<ProposalPayload> proposal = |
|
|
|
final Proposal proposal = |
|
|
|
validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block); |
|
|
|
new Proposal( |
|
|
|
|
|
|
|
validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block)); |
|
|
|
|
|
|
|
|
|
|
|
assertThat(roundState.setProposedBlock(proposal)).isTrue(); |
|
|
|
assertThat(roundState.setProposedBlock(proposal)).isTrue(); |
|
|
|
assertThat(roundState.isPrepared()).isTrue(); |
|
|
|
assertThat(roundState.isPrepared()).isTrue(); |
|
|
|
assertThat(roundState.isCommitted()).isFalse(); |
|
|
|
assertThat(roundState.isCommitted()).isFalse(); |
|
|
|
|
|
|
|
|
|
|
|
final SignedData<CommitPayload> commit = |
|
|
|
final Commit commit = |
|
|
|
|
|
|
|
new Commit( |
|
|
|
validatorMessageFactories |
|
|
|
validatorMessageFactories |
|
|
|
.get(0) |
|
|
|
.get(0) |
|
|
|
.createSignedCommitPayload( |
|
|
|
.createSignedCommitPayload( |
|
|
|
roundIdentifier, |
|
|
|
roundIdentifier, |
|
|
|
block.getHash(), |
|
|
|
block.getHash(), |
|
|
|
Signature.create(BigInteger.ONE, BigInteger.ONE, (byte) 1)); |
|
|
|
Signature.create(BigInteger.ONE, BigInteger.ONE, (byte) 1))); |
|
|
|
|
|
|
|
|
|
|
|
roundState.addCommitMessage(commit); |
|
|
|
roundState.addCommitMessage(commit); |
|
|
|
assertThat(roundState.isPrepared()).isTrue(); |
|
|
|
assertThat(roundState.isPrepared()).isTrue(); |
|
|
@ -140,15 +145,17 @@ public class RoundStateTest { |
|
|
|
|
|
|
|
|
|
|
|
final RoundState roundState = new RoundState(roundIdentifier, 3, messageValidator); |
|
|
|
final RoundState roundState = new RoundState(roundIdentifier, 3, messageValidator); |
|
|
|
|
|
|
|
|
|
|
|
final SignedData<PreparePayload> firstPrepare = |
|
|
|
final Prepare firstPrepare = |
|
|
|
|
|
|
|
new Prepare( |
|
|
|
validatorMessageFactories |
|
|
|
validatorMessageFactories |
|
|
|
.get(1) |
|
|
|
.get(1) |
|
|
|
.createSignedPreparePayload(roundIdentifier, block.getHash()); |
|
|
|
.createSignedPreparePayload(roundIdentifier, block.getHash())); |
|
|
|
|
|
|
|
|
|
|
|
final SignedData<PreparePayload> secondPrepare = |
|
|
|
final Prepare secondPrepare = |
|
|
|
|
|
|
|
new Prepare( |
|
|
|
validatorMessageFactories |
|
|
|
validatorMessageFactories |
|
|
|
.get(2) |
|
|
|
.get(2) |
|
|
|
.createSignedPreparePayload(roundIdentifier, block.getHash()); |
|
|
|
.createSignedPreparePayload(roundIdentifier, block.getHash())); |
|
|
|
|
|
|
|
|
|
|
|
roundState.addPrepareMessage(firstPrepare); |
|
|
|
roundState.addPrepareMessage(firstPrepare); |
|
|
|
assertThat(roundState.isPrepared()).isFalse(); |
|
|
|
assertThat(roundState.isPrepared()).isFalse(); |
|
|
@ -160,8 +167,9 @@ public class RoundStateTest { |
|
|
|
assertThat(roundState.isCommitted()).isFalse(); |
|
|
|
assertThat(roundState.isCommitted()).isFalse(); |
|
|
|
assertThat(roundState.constructPreparedCertificate()).isEmpty(); |
|
|
|
assertThat(roundState.constructPreparedCertificate()).isEmpty(); |
|
|
|
|
|
|
|
|
|
|
|
final SignedData<ProposalPayload> proposal = |
|
|
|
final Proposal proposal = |
|
|
|
validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block); |
|
|
|
new Proposal( |
|
|
|
|
|
|
|
validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block)); |
|
|
|
assertThat(roundState.setProposedBlock(proposal)).isTrue(); |
|
|
|
assertThat(roundState.setProposedBlock(proposal)).isTrue(); |
|
|
|
assertThat(roundState.isPrepared()).isTrue(); |
|
|
|
assertThat(roundState.isPrepared()).isTrue(); |
|
|
|
assertThat(roundState.isCommitted()).isFalse(); |
|
|
|
assertThat(roundState.isCommitted()).isFalse(); |
|
|
@ -188,12 +196,13 @@ public class RoundStateTest { |
|
|
|
when(messageValidator.validatePrepareMessage(firstPrepare)).thenReturn(true); |
|
|
|
when(messageValidator.validatePrepareMessage(firstPrepare)).thenReturn(true); |
|
|
|
when(messageValidator.validatePrepareMessage(secondPrepare)).thenReturn(false); |
|
|
|
when(messageValidator.validatePrepareMessage(secondPrepare)).thenReturn(false); |
|
|
|
|
|
|
|
|
|
|
|
roundState.addPrepareMessage(firstPrepare); |
|
|
|
roundState.addPrepareMessage(new Prepare(firstPrepare)); |
|
|
|
roundState.addPrepareMessage(secondPrepare); |
|
|
|
roundState.addPrepareMessage(new Prepare(secondPrepare)); |
|
|
|
verify(messageValidator, never()).validatePrepareMessage(any()); |
|
|
|
verify(messageValidator, never()).validatePrepareMessage(any()); |
|
|
|
|
|
|
|
|
|
|
|
final SignedData<ProposalPayload> proposal = |
|
|
|
final Proposal proposal = |
|
|
|
validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block); |
|
|
|
new Proposal( |
|
|
|
|
|
|
|
validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block)); |
|
|
|
|
|
|
|
|
|
|
|
assertThat(roundState.setProposedBlock(proposal)).isTrue(); |
|
|
|
assertThat(roundState.setProposedBlock(proposal)).isTrue(); |
|
|
|
assertThat(roundState.isPrepared()).isFalse(); |
|
|
|
assertThat(roundState.isPrepared()).isFalse(); |
|
|
@ -215,8 +224,9 @@ public class RoundStateTest { |
|
|
|
.get(2) |
|
|
|
.get(2) |
|
|
|
.createSignedPreparePayload(roundIdentifier, block.getHash()); |
|
|
|
.createSignedPreparePayload(roundIdentifier, block.getHash()); |
|
|
|
|
|
|
|
|
|
|
|
final SignedData<ProposalPayload> proposal = |
|
|
|
final Proposal proposal = |
|
|
|
validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block); |
|
|
|
new Proposal( |
|
|
|
|
|
|
|
validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block)); |
|
|
|
|
|
|
|
|
|
|
|
when(messageValidator.addSignedProposalPayload(any())).thenReturn(true); |
|
|
|
when(messageValidator.addSignedProposalPayload(any())).thenReturn(true); |
|
|
|
when(messageValidator.validatePrepareMessage(firstPrepare)).thenReturn(false); |
|
|
|
when(messageValidator.validatePrepareMessage(firstPrepare)).thenReturn(false); |
|
|
@ -225,10 +235,10 @@ public class RoundStateTest { |
|
|
|
roundState.setProposedBlock(proposal); |
|
|
|
roundState.setProposedBlock(proposal); |
|
|
|
assertThat(roundState.isPrepared()).isFalse(); |
|
|
|
assertThat(roundState.isPrepared()).isFalse(); |
|
|
|
|
|
|
|
|
|
|
|
roundState.addPrepareMessage(firstPrepare); |
|
|
|
roundState.addPrepareMessage(new Prepare(firstPrepare)); |
|
|
|
assertThat(roundState.isPrepared()).isFalse(); |
|
|
|
assertThat(roundState.isPrepared()).isFalse(); |
|
|
|
|
|
|
|
|
|
|
|
roundState.addPrepareMessage(secondPrepare); |
|
|
|
roundState.addPrepareMessage(new Prepare(secondPrepare)); |
|
|
|
assertThat(roundState.isPrepared()).isTrue(); |
|
|
|
assertThat(roundState.isPrepared()).isTrue(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -239,24 +249,27 @@ public class RoundStateTest { |
|
|
|
|
|
|
|
|
|
|
|
final RoundState roundState = new RoundState(roundIdentifier, 2, messageValidator); |
|
|
|
final RoundState roundState = new RoundState(roundIdentifier, 2, messageValidator); |
|
|
|
|
|
|
|
|
|
|
|
final SignedData<CommitPayload> firstCommit = |
|
|
|
final Commit firstCommit = |
|
|
|
|
|
|
|
new Commit( |
|
|
|
validatorMessageFactories |
|
|
|
validatorMessageFactories |
|
|
|
.get(1) |
|
|
|
.get(1) |
|
|
|
.createSignedCommitPayload( |
|
|
|
.createSignedCommitPayload( |
|
|
|
roundIdentifier, |
|
|
|
roundIdentifier, |
|
|
|
block.getHash(), |
|
|
|
block.getHash(), |
|
|
|
Signature.create(BigInteger.ONE, BigInteger.TEN, (byte) 1)); |
|
|
|
Signature.create(BigInteger.ONE, BigInteger.TEN, (byte) 1))); |
|
|
|
|
|
|
|
|
|
|
|
final SignedData<CommitPayload> secondCommit = |
|
|
|
final Commit secondCommit = |
|
|
|
|
|
|
|
new Commit( |
|
|
|
validatorMessageFactories |
|
|
|
validatorMessageFactories |
|
|
|
.get(2) |
|
|
|
.get(2) |
|
|
|
.createSignedCommitPayload( |
|
|
|
.createSignedCommitPayload( |
|
|
|
roundIdentifier, |
|
|
|
roundIdentifier, |
|
|
|
block.getHash(), |
|
|
|
block.getHash(), |
|
|
|
Signature.create(BigInteger.TEN, BigInteger.TEN, (byte) 1)); |
|
|
|
Signature.create(BigInteger.TEN, BigInteger.TEN, (byte) 1))); |
|
|
|
|
|
|
|
|
|
|
|
final SignedData<ProposalPayload> proposal = |
|
|
|
final Proposal proposal = |
|
|
|
validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block); |
|
|
|
new Proposal( |
|
|
|
|
|
|
|
validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block)); |
|
|
|
|
|
|
|
|
|
|
|
roundState.setProposedBlock(proposal); |
|
|
|
roundState.setProposedBlock(proposal); |
|
|
|
roundState.addCommitMessage(firstCommit); |
|
|
|
roundState.addCommitMessage(firstCommit); |
|
|
@ -266,6 +279,7 @@ public class RoundStateTest { |
|
|
|
|
|
|
|
|
|
|
|
assertThat(roundState.getCommitSeals()) |
|
|
|
assertThat(roundState.getCommitSeals()) |
|
|
|
.containsOnly( |
|
|
|
.containsOnly( |
|
|
|
firstCommit.getPayload().getCommitSeal(), secondCommit.getPayload().getCommitSeal()); |
|
|
|
firstCommit.getSignedPayload().getPayload().getCommitSeal(), |
|
|
|
|
|
|
|
secondCommit.getSignedPayload().getPayload().getCommitSeal()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|