Skip to content

Commit

Permalink
Remove unnecesary ummRoot.length!=0 check since it was already done o…
Browse files Browse the repository at this point in the history
…utside the invoked method
  • Loading branch information
mpicco committed Mar 13, 2020
1 parent 73d1d9d commit 52fca5c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rskj-core/src/main/java/org/ethereum/core/BlockHeader.java
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ public byte[] getHashForMergedMining() {
}

private byte[] getHashRootForMergedMining(byte[] leftHash) {
if ((ummRoot.length != UMM_LEAVES_LENGTH) && (ummRoot.length != 0)){
if (ummRoot.length != UMM_LEAVES_LENGTH){
throw new IllegalStateException(
String.format("UMM Root length must be either 0 or 20. Found: %d", ummRoot.length)
);
Expand Down
12 changes: 12 additions & 0 deletions rskj-core/src/test/java/co/rsk/core/BlockHeaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,18 @@ public void getHashForMergedMiningWhenUmmRoot() {
assertThat(header.getHashForMergedMining(), is(newHashForMergedMining));
}

@Test
public void getHashForMergedMiningWhenEmptyUmmRoot() {
byte[] ummRoot = new byte[0];

BlockHeader header = createBlockHeaderWithUmmRoot(ummRoot);

byte[] encodedBlock = header.getEncoded(false, false);
byte[] hashForMergedMining = HashUtil.keccak256(encodedBlock);

assertThat(header.getHashForMergedMining(), is(hashForMergedMining));
}

@Test(expected = IllegalStateException.class)
public void getHashForMergedMiningWhenUmmRootWithLengthUnder20() {
byte[] ummRoot = new byte[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18};
Expand Down

0 comments on commit 52fca5c

Please sign in to comment.