Skip to content

Commit

Permalink
chore: Fix sonar issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zurcusa committed Jan 27, 2025
1 parent 9cc5b22 commit 9563d4d
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 16 deletions.
1 change: 0 additions & 1 deletion src/main/java/com/limechain/grandpa/GrandpaService.java
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,6 @@ private long getObservedVotesForBlock(GrandpaRound grandpaRound, Hash256 blockHa
*/
private HashMap<Vote, Long> getDirectVotes(GrandpaRound grandpaRound, Subround subround) {
var voteCounts = new HashMap<Vote, Long>();
GrandpaSetState grandpaSetState = stateManager.getGrandpaSetState();

Map<Hash256, SignedVote> votes = switch (subround) {
case Subround.PREVOTE -> grandpaRound.getPreVotes();
Expand Down
16 changes: 1 addition & 15 deletions src/test/java/com/limechain/grandpa/GrandpaServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -716,7 +703,6 @@ void testGetPossibleSelectedAncestors() throws Exception {
Map<Hash256, SignedVote> 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);
Expand Down

0 comments on commit 9563d4d

Please sign in to comment.