Skip to content

Commit

Permalink
[PAN-2830] improve message when extraData missing (hyperledger#121)
Browse files Browse the repository at this point in the history
Signed-off-by: Kasper Ziemianek <[email protected]>
Signed-off-by: edwardmack <[email protected]>
  • Loading branch information
kziemianek authored and edwardmack committed Nov 4, 2019
1 parent 14ce164 commit dcb85e6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
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,15 @@ public void incorrectVoteTypeThrowsException() {
.isInstanceOf(RLPException.class);
}

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

assertThatThrownBy(() -> IbftExtraData.decodeRaw(bufferToInject))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Invalid BytesValue supplied - Ibft Extra Data required.");
}

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

0 comments on commit dcb85e6

Please sign in to comment.