diff --git a/src/main/java/com/limechain/grandpa/GrandpaService.java b/src/main/java/com/limechain/grandpa/GrandpaService.java index 4cf6911a..72bde1ae 100644 --- a/src/main/java/com/limechain/grandpa/GrandpaService.java +++ b/src/main/java/com/limechain/grandpa/GrandpaService.java @@ -1,5 +1,6 @@ package com.limechain.grandpa; +import com.limechain.exception.global.ExecutionFailedException; import com.limechain.exception.storage.BlockStorageGenericException; import com.limechain.grandpa.state.GrandpaState; import com.limechain.grandpa.state.Subround; @@ -41,8 +42,7 @@ public Vote getGrandpaGHOST() { Map blocks = getPossibleSelectedBlocks(threshold, Subround.PRE_VOTE); if (blocks.isEmpty() || threshold.equals(BigInteger.ZERO)) { - log.warning("GHOST not found"); - return null; + throw new ExecutionFailedException("GHOST not found"); } return selectBlockWithMostVotes(blocks); diff --git a/src/test/java/com/limechain/grandpa/GrandpaServiceTest.java b/src/test/java/com/limechain/grandpa/GrandpaServiceTest.java index 3ed79212..755acbdf 100644 --- a/src/test/java/com/limechain/grandpa/GrandpaServiceTest.java +++ b/src/test/java/com/limechain/grandpa/GrandpaServiceTest.java @@ -1,5 +1,6 @@ package com.limechain.grandpa; +import com.limechain.exception.global.ExecutionFailedException; import com.limechain.grandpa.state.GrandpaState; import com.limechain.grandpa.state.Subround; import com.limechain.network.protocol.grandpa.messages.catchup.res.SignedVote; @@ -24,6 +25,7 @@ import static com.limechain.utils.TestUtils.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; @@ -54,9 +56,7 @@ void setUp() { void testGetGrandpaGHOSTWhereNoBlocksPassThreshold() { when(grandpaState.getThreshold()).thenReturn(BigInteger.valueOf(10)); when(grandpaState.getPrevotes()).thenReturn(Map.of()); - - var result = grandpaService.getGrandpaGHOST(); - assertNull(result); + assertThrows(ExecutionFailedException.class, () -> grandpaService.getGrandpaGHOST()); } @Test