Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

IBFT message payload tests #404

Merged
merged 11 commits into from
Dec 12, 2018

Conversation

jframe
Copy link
Contributor

@jframe jframe commented Dec 12, 2018

PR description

IBFT message payload tests. These tests are focussed on round tripping the RLP encoding and decoding.

Fixed Issue(s)

@jframe
Copy link
Contributor Author

jframe commented Dec 12, 2018

Collapsed the hierarchy in the message payloads to instead implement a Payload interface.

}

@Override
public String toString() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about the roundIdentifier stored in the baseclass?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.
Fixed.

@@ -55,4 +57,30 @@ public void writeTo(final RLPOutput rlpOutput) {
public Collection<SignedData<PreparePayload>> getPreparePayloads() {
return preparePayloads;
}

@Override
public boolean equals(final Object o) {
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 (!super.equals(o)) {
return false;
}
final CommitPayload that = (CommitPayload) o;
Copy link
Contributor

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?)

Copy link
Contributor Author

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

if (o == null || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can the super check be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's autogenerated code. Yeah doesn't technically need it, but I'd rather just leave the intellij code as it

Lists.newArrayList(),
Optional.empty(),
0,
singletonList(Address.fromHexString(String.format("%020d", 1))))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can either:
AddressHelpers.ofValue(1), or
Address.fromhexStringLenient("1")


final RLPInput rlpInput = RLP.input(rlpOut.encoded());
final CommitPayload commitPayload = CommitPayload.readFrom(rlpInput);
assertThat(commitPayload.getRoundIdentifier()).isEqualTo(ROUND_IDENTIFIER);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Do we want to check against "initial values" or just against "expectedCommitPayload"? If the latter, look at using "isEqualToComparingFieldByField".
(probably still need to do the MessageType")
I am assuming we trust that the constructor & getters do the right thing.

@Test
public void roundTripRlp() {
final Hash digest = Hash.hash(BytesValue.of(1));
final ConsensusRoundIdentifier expectedRoundIdentifier = new ConsensusRoundIdentifier(1, 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason this is written differently to the other tests? I.e. ROUND_IDENTIFIER being a class level variable?


@Test
public void roundTripRlp() {
final Hash digest = Hash.hash(BytesValue.of(1));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: diff to other test implementations

@jframe jframe merged commit 4bfb381 into PegaSysEng:master Dec 12, 2018
@jframe jframe deleted the feature/ibft_message_payload_tests branch April 18, 2019 00:17
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants