From 9563d4d9e41a3d9abf489adebfa0f85c88a789c5 Mon Sep 17 00:00:00 2001 From: Yordan Atanasov Date: Mon, 27 Jan 2025 13:02:51 +0200 Subject: [PATCH] chore: Fix sonar issues. --- .../com/limechain/grandpa/GrandpaService.java | 1 - .../limechain/grandpa/GrandpaServiceTest.java | 16 +--------------- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/src/main/java/com/limechain/grandpa/GrandpaService.java b/src/main/java/com/limechain/grandpa/GrandpaService.java index dce86320..c1eeaefc 100644 --- a/src/main/java/com/limechain/grandpa/GrandpaService.java +++ b/src/main/java/com/limechain/grandpa/GrandpaService.java @@ -449,7 +449,6 @@ private long getObservedVotesForBlock(GrandpaRound grandpaRound, Hash256 blockHa */ private HashMap getDirectVotes(GrandpaRound grandpaRound, Subround subround) { var voteCounts = new HashMap(); - GrandpaSetState grandpaSetState = stateManager.getGrandpaSetState(); Map votes = switch (subround) { case Subround.PREVOTE -> grandpaRound.getPreVotes(); diff --git a/src/test/java/com/limechain/grandpa/GrandpaServiceTest.java b/src/test/java/com/limechain/grandpa/GrandpaServiceTest.java index aebfca30..8aaa7e51 100644 --- a/src/test/java/com/limechain/grandpa/GrandpaServiceTest.java +++ b/src/test/java/com/limechain/grandpa/GrandpaServiceTest.java @@ -7,9 +7,7 @@ import com.limechain.network.protocol.grandpa.messages.catchup.res.SignedVote; import com.limechain.network.protocol.grandpa.messages.commit.CommitMessage; import com.limechain.network.protocol.grandpa.messages.commit.Vote; -import com.limechain.network.protocol.grandpa.messages.vote.SignedMessage; import com.limechain.network.protocol.grandpa.messages.vote.Subround; -import com.limechain.network.protocol.grandpa.messages.vote.VoteMessage; import com.limechain.network.protocol.warp.dto.BlockHeader; import com.limechain.network.protocol.warp.dto.ConsensusEngine; import com.limechain.network.protocol.warp.dto.DigestType; @@ -39,7 +37,6 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -236,8 +233,6 @@ void testFindBestPreVoteCandidate_WithSignedMessage() throws Exception { Vote primaryVote = new Vote(new Hash256(TWOS_ARRAY), BigInteger.valueOf(4)); Hash256 primaryVoteAuthorityHash = new Hash256(TWOS_ARRAY); SignedVote primarySignedVote = new SignedVote(primaryVote, Hash512.empty(), primaryVoteAuthorityHash); - VoteMessage voteMessage = mock(VoteMessage.class); - SignedMessage signedMessage = mock(SignedMessage.class); when(grandpaRound.getPrimaryVote()).thenReturn(primarySignedVote); BlockHeader blockHeader = createBlockHeader(); @@ -272,7 +267,7 @@ void testFindBestPreVoteCandidate_WithSignedMessage() throws Exception { } @Test - void testFindBestPreVoteCandidate_WithoutSignedMessage() throws Exception { + void testFindBestPreVoteCandidate_WithoutSignedMessage() throws Exception { Vote currentVote = new Vote(new Hash256(ONES_ARRAY), BigInteger.valueOf(3)); Hash256 currentVoteAuthorityHash = new Hash256(ONES_ARRAY); SignedVote currentSignedVote = new SignedVote(currentVote, Hash512.empty(), currentVoteAuthorityHash); @@ -322,7 +317,6 @@ void testFindBestPreVoteCandidate_WithSignedMessageAndBlockNumberLessThanCurrent Vote primaryVote = new Vote(new Hash256(ONES_ARRAY), BigInteger.valueOf(3)); Hash256 primaryVoteAuthorityHash = new Hash256(TWOS_ARRAY); SignedVote primarySignedVote = new SignedVote(primaryVote, Hash512.empty(), primaryVoteAuthorityHash); - SignedMessage signedMessage = mock(SignedMessage.class); when(grandpaRound.getPrimaryVote()).thenReturn(primarySignedVote); BlockHeader blockHeader = createBlockHeader(); @@ -446,7 +440,6 @@ void testGetDirectVotesForPreVotes() throws Exception { preVotes.put(firstVoteAuthorityHash, firstSignedVote); preVotes.put(secondVoteAuthorityHash, secondSignedVote); - when(stateManager.getGrandpaSetState()).thenReturn(grandpaSetState); when(grandpaRound.getPreVotes()).thenReturn(preVotes); // Call the private method via reflection @@ -518,7 +511,6 @@ void testGetVotesWithMultipleVotes() throws Exception { preVotes.put(firstVoteAuthorityHash, firstSignedVote); preVotes.put(secondVoteAuthorityHash, secondSignedVote); - when(stateManager.getGrandpaSetState()).thenReturn(grandpaSetState); when(grandpaRound.getPreVotes()).thenReturn(preVotes); // Call the private method via reflection @@ -544,7 +536,6 @@ void testGetObservedVotesForBlockWhereVotesAreNotDescendantsOfProvidedBlockHash( preVotes.put(firstVoteAuthorityHash, firstSignedVote); preVotes.put(secondVoteAuthorityHash, secondSignedVote); - when(stateManager.getGrandpaSetState()).thenReturn(grandpaSetState); when(grandpaRound.getPreVotes()).thenReturn(preVotes); when(stateManager.getBlockState()).thenReturn(blockState); when(blockState.isDescendantOf(any(), any())).thenReturn(false); @@ -576,7 +567,6 @@ void testGetObservedVotesForBlockWhereVotesAreDescendantsOfProvidedBlockHash() t preVotes.put(firstVoteAuthorityHash, firstSignedVote); preVotes.put(secondVoteAuthorityHash, secondSignedVote); - when(stateManager.getGrandpaSetState()).thenReturn(grandpaSetState); when(grandpaRound.getPreVotes()).thenReturn(preVotes); when(stateManager.getBlockState()).thenReturn(blockState); when(blockState.isDescendantOf(any(), any())).thenReturn(true); @@ -617,7 +607,6 @@ void testGetTotalVotesForBlockWithoutObservedVotes() throws Exception { when(grandpaRound.getPreVotes()).thenReturn(preVotes); when(blockState.isDescendantOf(any(), any())).thenReturn(false); - when(stateManager.getGrandpaSetState()).thenReturn(grandpaSetState); when(stateManager.getBlockState()).thenReturn(blockState); Method method = GrandpaService.class.getDeclaredMethod( @@ -650,7 +639,6 @@ void testGetTotalVotesForBlockWithObservedVotes() throws Exception { when(grandpaRound.getPreVotes()).thenReturn(preVotes); when(blockState.isDescendantOf(any(), any())).thenReturn(true); - when(stateManager.getGrandpaSetState()).thenReturn(grandpaSetState); when(stateManager.getBlockState()).thenReturn(blockState); Method method = GrandpaService.class.getDeclaredMethod( @@ -684,7 +672,6 @@ void testGetTotalVotesForBlockWithObservedVotesAndEquivocations() throws Excepti when(grandpaRound.getPvEquivocationsCount()).thenReturn(1L); when(blockState.isDescendantOf(any(), any())).thenReturn(true); - when(stateManager.getGrandpaSetState()).thenReturn(grandpaSetState); when(stateManager.getBlockState()).thenReturn(blockState); Method method = GrandpaService.class.getDeclaredMethod( @@ -716,7 +703,6 @@ void testGetPossibleSelectedAncestors() throws Exception { Map preVotes = new HashMap<>(); preVotes.put(firstVoteAuthorityHash, firstSignedVote); - when(stateManager.getGrandpaSetState()).thenReturn(grandpaSetState); when(grandpaRound.getPreVotes()).thenReturn(preVotes); when(stateManager.getBlockState()).thenReturn(blockState); when(blockState.isDescendantOf(any(), any())).thenReturn(true);