-
Notifications
You must be signed in to change notification settings - Fork 130
IBFT message payload tests #404
Changes from all commits
fa06807
e21e683
019046e
c6c0be8
db8af05
954dfdb
891b3c2
eea0ad6
f8adc6c
5266b27
5ed7287
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,25 +19,28 @@ | |
import tech.pegasys.pantheon.ethereum.rlp.RLPInput; | ||
import tech.pegasys.pantheon.ethereum.rlp.RLPOutput; | ||
|
||
public class CommitPayload extends InRoundPayload { | ||
import java.util.Objects; | ||
import java.util.StringJoiner; | ||
|
||
public class CommitPayload implements InRoundPayload { | ||
private static final int TYPE = IbftV2.COMMIT; | ||
private final ConsensusRoundIdentifier roundIdentifier; | ||
private final Hash digest; | ||
private final Signature commitSeal; | ||
|
||
public CommitPayload( | ||
final ConsensusRoundIdentifier roundIdentifier, | ||
final Hash digest, | ||
final Signature commitSeal) { | ||
super(roundIdentifier); | ||
this.roundIdentifier = roundIdentifier; | ||
this.digest = digest; | ||
this.commitSeal = commitSeal; | ||
} | ||
|
||
public static CommitPayload readFrom(final RLPInput rlpInput) { | ||
|
||
rlpInput.enterList(); | ||
final ConsensusRoundIdentifier roundIdentifier = ConsensusRoundIdentifier.readFrom(rlpInput); | ||
final Hash digest = readDigest(rlpInput); | ||
final Hash digest = Payload.readDigest(rlpInput); | ||
final Signature commitSeal = rlpInput.readBytesValue(Signature::decode); | ||
rlpInput.leaveList(); | ||
|
||
|
@@ -46,7 +49,6 @@ public static CommitPayload readFrom(final RLPInput rlpInput) { | |
|
||
@Override | ||
public void writeTo(final RLPOutput rlpOutput) { | ||
|
||
rlpOutput.startList(); | ||
roundIdentifier.writeTo(rlpOutput); | ||
rlpOutput.writeBytesValue(digest); | ||
|
@@ -66,4 +68,37 @@ public Hash getDigest() { | |
public Signature getCommitSeal() { | ||
return commitSeal; | ||
} | ||
|
||
@Override | ||
public ConsensusRoundIdentifier getRoundIdentifier() { | ||
return roundIdentifier; | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
final CommitPayload that = (CommitPayload) o; | ||
return Objects.equals(roundIdentifier, that.roundIdentifier) | ||
&& Objects.equals(digest, that.digest) | ||
&& Objects.equals(commitSeal, that.commitSeal); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(roundIdentifier, digest, commitSeal); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what about the roundIdentifier stored in the baseclass? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's stored in the this class now as using an interface. But yes I forgot that. |
||
return new StringJoiner(", ", CommitPayload.class.getSimpleName() + "[", "]") | ||
.add("roundIdentifier=" + roundIdentifier) | ||
.add("digest=" + digest) | ||
.add("commitSeal=" + commitSeal) | ||
.toString(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,9 +16,10 @@ | |
import tech.pegasys.pantheon.ethereum.rlp.RLPOutput; | ||
|
||
import java.util.Collection; | ||
import java.util.Objects; | ||
import java.util.StringJoiner; | ||
|
||
public class PreparedCertificate { | ||
|
||
private final SignedData<ProposalPayload> proposalPayload; | ||
private final Collection<SignedData<PreparePayload>> preparePayloads; | ||
|
||
|
@@ -55,4 +56,30 @@ public SignedData<ProposalPayload> getProposalPayload() { | |
public Collection<SignedData<PreparePayload>> getPreparePayloads() { | ||
return preparePayloads; | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object o) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure we will ever do equality on these items in the real world code, could custom static functions be written in either test or testsupport. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could but I think it's cleaner from the consumers point of view to be able to rely on equals if needed. |
||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
final PreparedCertificate that = (PreparedCertificate) o; | ||
return Objects.equals(proposalPayload, that.proposalPayload) | ||
&& Objects.equals(preparePayloads, that.preparePayloads); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(proposalPayload, preparePayloads); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new StringJoiner(", ", PreparedCertificate.class.getSimpleName() + "[", "]") | ||
.add("proposalPayload=" + proposalPayload) | ||
.add("preparePayloads=" + preparePayloads) | ||
.toString(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
has missed the RoundIdentifier, needed for the hashCode and toString (and I assume the other classes?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just checked the other classes, looks like this was the unfortunate one that I forgot