Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PAN-2830] improve message when extraData missing #121

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ public static IbftExtraData decode(final BlockHeader blockHeader) {
}

static IbftExtraData decodeRaw(final BytesValue input) {
if (input.isEmpty()) {
throw new IllegalArgumentException("Invalid BytesValue supplied - Ibft Extra Data required.");
}

final RLPInput rlpInput = new BytesValueRLPInput(input, false);

rlpInput.enterList(); // This accounts for the "root node" which contains IBFT data items.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,14 @@ public void incorrectVoteTypeThrowsException() {
.isInstanceOf(RLPException.class);
}

@Test
public void emptyExtraDataThrowsException() {
final BytesValue bufferToInject = BytesValue.EMPTY;

assertThatThrownBy(() -> IbftExtraData.decodeRaw(bufferToInject))
.isInstanceOf(IllegalArgumentException.class);
Copy link
Contributor

Choose a reason for hiding this comment

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

To ensure the exception returned is from the intended throw (although there is only one condition here, there could be many more IllegalArgumentException conditions in the future), it might also be worth asserting the message is that expected?

Suggested change
.isInstanceOf(IllegalArgumentException.class);
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Invalid BytesValue supplied - Ibft Extra Data required.");

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I totally agree, PR updated.

}

private static byte[] createNonEmptyVanityData() {
final byte[] vanity_bytes = new byte[32];
for (int i = 0; i < vanity_bytes.length; i++) {
Expand Down