Skip to content

Commit

Permalink
Merge branch 'master' into fmacleal/improving-slack-notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
fmacleal authored Oct 11, 2024
2 parents 282ea8a + 2aea53c commit 0054f4a
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
run: |
PR_DESCRIPTION=pr-description.txt
ALLOWED_BRANCH_CHARACTERS='[-./0-9A-Z_a-z]'
ALLOWED_BRANCH_CHARACTERS='[-+./0-9A-Z_a-z]'
default_rskj_branch=master
default_powpeg_branch=master
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public String[] getBrothers() {
}

private String serializeBlockHeader(BlockHeader blockHeader) {
return Hex.toHexString(blockHeader.getFullEncoded());
return Hex.toHexString(blockHeader.getEncoded(true, true, true));
}

private String[] serializeBrothers(List<BlockHeader> brothers) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public UpdateAncestorBlockMessage(List<BlockHeader> blockHeaders) {
}

private String parseBlockHeader(BlockHeader blockHeader) {
return Hex.toHexString(blockHeader.getEncoded(true, false));
return Hex.toHexString(blockHeader.getEncoded(true, false, true));
}

public List<String> getData() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,14 +293,14 @@ void updateAncestorBlock_ok(HSMVersion hsmVersion, int maxChunkSize) throws HSMC

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 @@ -65,7 +65,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 @@ -77,8 +76,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 @@ -89,7 +87,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 0054f4a

Please sign in to comment.