Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Vovchyk committed Feb 7, 2024
1 parent 0b57a03 commit f819ea4
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -293,14 +293,14 @@ void updateAncestorBlock_ok(int hsmVersion, int maxChunkSize) throws HSMClientEx

for (int j = 0; j < blocksInRequest.size() - 1; j++) {
assertEquals(
Hex.toHexString(Objects.requireNonNull(blockHeadersInOriginalOrder.poll()).getFullEncoded()),
Hex.toHexString(Objects.requireNonNull(blockHeadersInOriginalOrder.poll()).getEncoded(true, false, true)),
blocksInRequest.get(j).asText()
);
}

// The last element asserted should not be removed from the queue since it will be the first element in the next chunk
assertEquals(
Hex.toHexString(Objects.requireNonNull(blockHeadersInOriginalOrder.peek()).getFullEncoded()),
Hex.toHexString(Objects.requireNonNull(blockHeadersInOriginalOrder.peek()).getEncoded(true, false, true)),
blocksInRequest.get(blocksInRequest.size() - 1).asText()
);
}
Expand Down Expand Up @@ -411,7 +411,7 @@ void advanceBlockchain_ok(
// Headers should have been parsed in the reverse order
for (int j = 0; j < blocksInRequest.size(); j++) {
assertEquals(
Hex.toHexString(blockHeadersInverted.pop().getFullEncoded()),
Hex.toHexString(blockHeadersInverted.pop().getEncoded(true, true, true)),
blocksInRequest.get(j).asText()
);
}
Expand All @@ -437,7 +437,7 @@ private void assertBrothers(JsonNode brothersInRequest, Stack<List<BlockHeader>>

for (BlockHeader brother : blockBrothers) {
byte[] brotherFromPayload = Hex.decode(brothersPayload.next().asText());
assertArrayEquals(brother.getFullEncoded(), brotherFromPayload);
assertArrayEquals(brother.getEncoded(true, true, true), brotherFromPayload);
}
assertFalse(brothersPayload.hasNext()); // No more brothers
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void getParsedBlockHeaders_ok_sorted() {
// Headers should have been parsed in the reverse order
int blockIndex = blocks.size() - 1 - i;
assertEquals(
Hex.toHexString(blocks.get(blockIndex).getHeader().getFullEncoded()),
Hex.toHexString(blocks.get(blockIndex).getHeader().getEncoded(true, true, true)),
parsedBlockHeaders.get(i)
);
}
Expand All @@ -63,7 +63,7 @@ void getParsedBrothers_ok() throws HSMBlockchainBookkeepingRelatedException {
// Headers should have been parsed in the reverse order
int blockIndex = blocks.size() - 1 - i;
assertEquals(
Hex.toHexString(blocks.get(blockIndex).getHeader().getFullEncoded()),
Hex.toHexString(blocks.get(blockIndex).getHeader().getEncoded(true, true, true)),
parsedBlockHeaders.get(i)
);

Expand All @@ -76,7 +76,7 @@ void getParsedBrothers_ok() throws HSMBlockchainBookkeepingRelatedException {

for (int j = 0; j < parsedBrothers.length; j++) {
assertEquals(
Hex.toHexString(expectedBrothers.get(j).getFullEncoded()),
Hex.toHexString(expectedBrothers.get(j).getEncoded(true, true, true)),
parsedBrothers[j]
);
}
Expand All @@ -90,7 +90,7 @@ void getParsedBrothers_invalid_blockHeader() {

assertThrows(
HSMBlockchainBookkeepingRelatedException.class,
() -> message.getParsedBrothers(Hex.toHexString(invalidBlockHeader.getFullEncoded()))
() -> message.getParsedBrothers(Hex.toHexString(invalidBlockHeader.getEncoded(true, true, true)))
);
}

Expand All @@ -107,7 +107,7 @@ void getParsedBrothers_with_more_than_10_brothers() throws HSMBlockchainBookkeep
// Headers should have been parsed in the reverse order
int blockIndex = blocksWithMultipleBrothers.size() - 1 - i;
assertEquals(
Hex.toHexString(blocksWithMultipleBrothers.get(blockIndex).getHeader().getFullEncoded()),
Hex.toHexString(blocksWithMultipleBrothers.get(blockIndex).getHeader().getEncoded(true, true, true)),
parsedBlockHeaders.get(i)
);

Expand All @@ -119,7 +119,7 @@ void getParsedBrothers_with_more_than_10_brothers() throws HSMBlockchainBookkeep

for (int j = 0; j < parsedBrothers.length; j++) {
assertEquals(
Hex.toHexString(expectedBrothers.get(j).getFullEncoded()),
Hex.toHexString(expectedBrothers.get(j).getEncoded(true, true, true)),
parsedBrothers[j]
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void setup() {

@Test
void getBlockHeader() {
String serializedHeader = Hex.toHexString(blockHeader.getFullEncoded());
String serializedHeader = Hex.toHexString(blockHeader.getEncoded(true, true, true));
assertEquals(serializedHeader, parsedHeader.getBlockHeader());
}

Expand All @@ -50,7 +50,7 @@ void getBrothers() {

brothers.sort(Comparator.comparing(BlockHeader::getHash));
for (int i = 0; i < actualBrothers.length; i++) {
assertEquals(Hex.toHexString(brothers.get(i).getFullEncoded()), actualBrothers[i]);
assertEquals(Hex.toHexString(brothers.get(i).getEncoded(true, true, true)), actualBrothers[i]);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void ensureAncestorBlockInPosition_ancestor_ok_after_update()
Block targetBlock = mock(Block.class);
when(targetBlock.getHash()).thenReturn(targetBlockHash);
BlockHeader blockHeader = mock(BlockHeader.class);
when(blockHeader.getEncoded(true, false)).thenReturn(TestUtils.createHash(2).getBytes());
when(blockHeader.getEncoded(true, false, true)).thenReturn(TestUtils.createHash(2).getBytes());
when(targetBlock.getHeader()).thenReturn(blockHeader);

Keccak256 initialAncestorBlockHash = TestUtils.createHash(1);
Expand All @@ -69,7 +69,7 @@ void ensureAncestorBlockInPosition_ancestor_ok_after_update()
// Ancestor is just one block ahead of the target block
when(initialAncestorBlock.getParentHash()).thenReturn(targetBlockHash);
when(initialAncestorBlock.getHeader()).thenReturn(initialAncestorBlockHeader);
when(initialAncestorBlockHeader.getEncoded(true, false)).thenReturn(initialAncestorBlockHash.getBytes());
when(initialAncestorBlockHeader.getEncoded(true, false, true)).thenReturn(initialAncestorBlockHash.getBytes());

PowHSMState initialState = new PowHSMState(initialAncestorBlockHash.toHexString(), initialAncestorBlockHash.toHexString(), false);
PowHSMState secondState = new PowHSMState(targetBlockHash.toHexString(), targetBlockHash.toHexString(), false);
Expand Down
5 changes: 1 addition & 4 deletions src/test/java/co/rsk/federate/signing/utils/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public static Block mockBlock(long number, Keccak256 hash) {
when(block.getUncleList()).thenReturn(Collections.emptyList());
BlockHeader blockHeader = mock(BlockHeader.class);
when(blockHeader.getHash()).thenReturn(hash);
when(blockHeader.getFullEncoded()).thenReturn(hash.getBytes());
when(block.getHeader()).thenReturn(blockHeader);

return block;
Expand All @@ -60,8 +59,7 @@ public static Block mockBlock(long number, Keccak256 hash, Keccak256 parentHash)
when(block.getNumber()).thenReturn(number);
when(block.getParentHash()).thenReturn(parentHash);
BlockHeader blockHeader = mock(BlockHeader.class);
when(blockHeader.getEncoded(true, false)).thenReturn(hash.getBytes());
when(blockHeader.getFullEncoded()).thenReturn(hash.getBytes());
when(blockHeader.getEncoded(true, false, true)).thenReturn(hash.getBytes());
when(block.getHeader()).thenReturn(blockHeader);

return block;
Expand All @@ -72,7 +70,6 @@ public static Block mockBlock(long number, Keccak256 hash, long difficultyValue)
when(block.getHash()).thenReturn(hash);
when(block.getNumber()).thenReturn(number);
BlockHeader blockHeader = mock(BlockHeader.class);
when(blockHeader.getFullEncoded()).thenReturn(hash.getBytes());
when(blockHeader.getHash()).thenReturn(hash);
when(block.getHeader()).thenReturn(blockHeader);
when(block.getDifficulty()).thenReturn(new BlockDifficulty(BigInteger.valueOf(difficultyValue)));
Expand Down

0 comments on commit f819ea4

Please sign in to comment.