Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Vovchyk committed Oct 4, 2023
1 parent a0a8e18 commit 1769105
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ void informConfirmedBlockHeaders_onIrrecoverableError() throws HSMClientExceptio
@Test
void informConfirmedBlockHeaders_already_informing() throws HSMClientException, InterruptedException {
BlockHeader mockBlockHeaderToInform = TestUtils.createBlockHeaderMock(1);
when(mockBlockHeaderToInform.getFullEncoded()).thenReturn(Keccak256.ZERO_HASH.getBytes());
when(mockBlockHeaderToInform.getEncoded(true, true, true)).thenReturn(Keccak256.ZERO_HASH.getBytes());
List<BlockHeader> blockHeadersToInform = Collections.singletonList(mockBlockHeaderToInform);

HSMBookkeepingClient mockHsmBookkeepingClient = mock(HSMBookkeepingClient.class);
Expand Down Expand Up @@ -416,7 +416,7 @@ void informConfirmedBlockHeaders_already_informing() throws HSMClientException,
@Test
void informConfirmedBlockHeaders_Ok() throws InterruptedException, HSMClientException {
BlockHeader mockBlockHeaderToInform = TestUtils.createBlockHeaderMock(1);
when(mockBlockHeaderToInform.getFullEncoded()).thenReturn(Keccak256.ZERO_HASH.getBytes());
when(mockBlockHeaderToInform.getEncoded(true, true, true)).thenReturn(Keccak256.ZERO_HASH.getBytes());
List<BlockHeader> blockHeadersToInform = Collections.singletonList(mockBlockHeaderToInform);

HSMBookkeepingClient mockHsmBookkeepingClient = mock(HSMBookkeepingClient.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ void updateAncestorBlock_ok() throws HSMClientException, JsonRpcException {
.thenReturn(buildResponse(false));

BlockHeader blockHeader = mock(BlockHeader.class);
when(blockHeader.getEncoded(true, false)).thenReturn(new byte[]{});
when(blockHeader.getEncoded(true, false, true)).thenReturn(new byte[]{});
List<BlockHeader> blockHeaders = Arrays.asList(blockHeader, blockHeader, blockHeader);

hsmBookkeepingClient.setMaxChunkSizeToHsm(2);
Expand All @@ -340,7 +340,7 @@ void updateAncestorBlock_hsm_version_3() throws HSMClientException, JsonRpcExcep
.thenReturn(buildResponse(false));

BlockHeader blockHeader = mock(BlockHeader.class);
when(blockHeader.getEncoded(true, false)).thenReturn(new byte[]{});
when(blockHeader.getEncoded(true, false, true)).thenReturn(new byte[]{});

hsmBookkeepingClient.setMaxChunkSizeToHsm(2);
hsmBookkeepingClient.updateAncestorBlock(new UpdateAncestorBlockMessage(Arrays.asList(blockHeader, blockHeader, blockHeader)));
Expand All @@ -364,7 +364,7 @@ void advanceBlockchain_ok() throws HSMClientException, JsonRpcException {
.thenReturn(buildResponse(false));

BlockHeader blockHeader = mock(BlockHeader.class);
when(blockHeader.getFullEncoded()).thenReturn(new byte[]{});
when(blockHeader.getEncoded(true, true, true)).thenReturn(new byte[]{});

hsmBookkeepingClient.advanceBlockchain(new AdvanceBlockchainMessage(Arrays.asList(blockHeader, blockHeader, blockHeader)));

Expand All @@ -385,7 +385,7 @@ void advanceBlockchain_with_brothers_ok() throws HSMClientException, JsonRpcExce
.thenReturn(buildResponse(false));

BlockHeader blockHeader = mock(BlockHeader.class);
when(blockHeader.getFullEncoded()).thenReturn(new byte[]{});
when(blockHeader.getEncoded(true, true, true)).thenReturn(new byte[]{});

hsmBookkeepingClient.setMaxChunkSizeToHsm(3);
hsmBookkeepingClient.advanceBlockchain(new AdvanceBlockchainMessage(Arrays.asList(blockHeader, blockHeader, blockHeader)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class AdvanceBlockchainMessageTest {
void getBlockHeaders_ok() {
byte[] encodedBlockHeader1 = new byte[]{ 1 };
BlockHeader blockHeader1 = mock(BlockHeader.class);
when(blockHeader1.getFullEncoded()).thenReturn(encodedBlockHeader1);
when(blockHeader1.getEncoded(true, true, true)).thenReturn(encodedBlockHeader1);

List<BlockHeader> blockHeaders = Collections.singletonList(blockHeader1);
AdvanceBlockchainMessage message = new AdvanceBlockchainMessage(blockHeaders);
Expand All @@ -30,10 +30,10 @@ void getBlockHeaders_ok() {
void getBlockHeaders_ok_sort_inverted() {
byte[] encodedBlockHeader1 = new byte[]{ 1 };
BlockHeader blockHeader1 = mock(BlockHeader.class);
when(blockHeader1.getFullEncoded()).thenReturn(encodedBlockHeader1);
when(blockHeader1.getEncoded(true, true, true)).thenReturn(encodedBlockHeader1);
byte[] encodedBlockHeader2 = new byte[]{ 2 };
BlockHeader blockHeader2 = mock(BlockHeader.class);
when(blockHeader2.getFullEncoded()).thenReturn(encodedBlockHeader2);
when(blockHeader2.getEncoded(true, true, true)).thenReturn(encodedBlockHeader2);

List<BlockHeader> blockHeaders = Arrays.asList(blockHeader1, blockHeader2);
AdvanceBlockchainMessage message = new AdvanceBlockchainMessage(blockHeaders);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,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 @@ -66,7 +66,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
2 changes: 2 additions & 0 deletions src/test/java/co/rsk/federate/signing/utils/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ public static Block mockBlock(long number, Keccak256 hash, Keccak256 parentHash)
BlockHeader blockHeader = mock(BlockHeader.class);
when(blockHeader.getEncoded(true, false)).thenReturn(hash.getBytes());
when(blockHeader.getFullEncoded()).thenReturn(hash.getBytes());
when(blockHeader.getEncoded(true, true, true)).thenReturn(hash.getBytes());
when(blockHeader.getEncoded(true, false, true)).thenReturn(hash.getBytes());
when(block.getHeader()).thenReturn(blockHeader);

return block;
Expand Down

0 comments on commit 1769105

Please sign in to comment.