mirror of
https://github.com/aljazceru/lnd-manageJ.git
synced 2026-01-21 23:14:27 +01:00
add get-blockheight to status controller
This commit is contained in:
@@ -24,6 +24,10 @@ public class OwnNodeService {
|
||||
return Boolean.TRUE.equals(syncedToChainCache.get(""));
|
||||
}
|
||||
|
||||
public int getBlockHeight() {
|
||||
return grpcGetInfo.getBlockHeight().orElseThrow();
|
||||
}
|
||||
|
||||
private boolean isSyncedToChainWithoutCache() {
|
||||
return grpcGetInfo.isSyncedToChain().orElse(false);
|
||||
}
|
||||
|
||||
@@ -7,9 +7,11 @@ import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@@ -37,4 +39,16 @@ class OwnNodeServiceTest {
|
||||
when(grpcGetInfo.isSyncedToChain()).thenReturn(Optional.empty());
|
||||
assertThat(ownNodeService.isSyncedToChain()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void getBlockHeight() {
|
||||
when(grpcGetInfo.getBlockHeight()).thenReturn(Optional.of(123_456));
|
||||
assertThat(ownNodeService.getBlockHeight()).isEqualTo(123_456);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getBlockHeight_empty() {
|
||||
when(grpcGetInfo.getBlockHeight()).thenReturn(Optional.empty());
|
||||
assertThatExceptionOfType(NoSuchElementException.class).isThrownBy(ownNodeService::getBlockHeight);
|
||||
}
|
||||
}
|
||||
@@ -46,6 +46,13 @@ class StatusControllerIT {
|
||||
.andExpect(content().string("true"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getBlockHeight() throws Exception {
|
||||
when(ownNodeService.getBlockHeight()).thenReturn(123_456);
|
||||
mockMvc.perform(get(PREFIX + "/block-height"))
|
||||
.andExpect(content().string("123456"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getPubkeysForOpenChannels() throws Exception {
|
||||
when(channelService.getOpenChannels()).thenReturn(Set.of(LOCAL_OPEN_CHANNEL_TO_NODE_3, LOCAL_OPEN_CHANNEL));
|
||||
|
||||
@@ -37,6 +37,12 @@ public class StatusController {
|
||||
return ownNodeService.isSyncedToChain();
|
||||
}
|
||||
|
||||
@GetMapping("/block-height")
|
||||
public int getBlockHeight() {
|
||||
mark("getBlockHeight");
|
||||
return ownNodeService.getBlockHeight();
|
||||
}
|
||||
|
||||
@GetMapping("/open-channels/pubkeys")
|
||||
public PubkeysDto getPubkeysForOpenChannels() {
|
||||
mark("getPubkeysForOpenChannels");
|
||||
|
||||
@@ -83,4 +83,11 @@ class StatusControllerTest {
|
||||
when(channelService.getAllLocalChannels()).thenReturn(Stream.of(CLOSED_CHANNEL_2, CLOSED_CHANNEL));
|
||||
assertThat(statusController.getPubkeysForAllChannels().pubkeys()).containsExactly(PUBKEY_2.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getBlockHeight() {
|
||||
when(ownNodeService.getBlockHeight()).thenReturn(123_456);
|
||||
assertThat(statusController.getBlockHeight()).isEqualTo(123_456);
|
||||
verify(metrics).mark(argThat(name -> name.endsWith(".getBlockHeight")));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user