mirror of
https://github.com/aljazceru/lnd-manageJ.git
synced 2026-01-27 09:54:51 +01:00
add peer-pubkeys endpoint
add LocalChannel class
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package de.cotto.lndmanagej.controller;
|
||||
|
||||
import de.cotto.lndmanagej.model.ChannelFixtures;
|
||||
import de.cotto.lndmanagej.model.LocalChannel;
|
||||
import de.cotto.lndmanagej.service.ChannelService;
|
||||
import de.cotto.lndmanagej.service.NodeService;
|
||||
import de.cotto.lndmanagej.service.OwnNodeService;
|
||||
@@ -9,12 +11,17 @@ import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID;
|
||||
import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID_2;
|
||||
import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID_3;
|
||||
import static de.cotto.lndmanagej.model.LocalChannelFixtures.LOCAL_CHANNEL;
|
||||
import static de.cotto.lndmanagej.model.LocalChannelFixtures.LOCAL_CHANNEL_3;
|
||||
import static de.cotto.lndmanagej.model.NodeFixtures.ALIAS;
|
||||
import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY;
|
||||
import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY_2;
|
||||
import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY_3;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -40,7 +47,15 @@ class LegacyControllerTest {
|
||||
|
||||
@Test
|
||||
void getOpenChannelIds() {
|
||||
when(channelService.getOpenChannelsWith(PUBKEY)).thenReturn(List.of(CHANNEL_ID, CHANNEL_ID_3));
|
||||
when(channelService.getOpenChannelsWith(PUBKEY)).thenReturn(Set.of(LOCAL_CHANNEL, LOCAL_CHANNEL_3));
|
||||
assertThat(legacyController.getOpenChannelIds(PUBKEY)).isEqualTo(
|
||||
CHANNEL_ID + "\n" + CHANNEL_ID_3
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getOpenChannelIds_ordered() {
|
||||
when(channelService.getOpenChannelsWith(PUBKEY)).thenReturn(Set.of(LOCAL_CHANNEL_3, LOCAL_CHANNEL));
|
||||
assertThat(legacyController.getOpenChannelIds(PUBKEY)).isEqualTo(
|
||||
CHANNEL_ID + "\n" + CHANNEL_ID_3
|
||||
);
|
||||
@@ -57,4 +72,11 @@ class LegacyControllerTest {
|
||||
when(ownNodeService.isSyncedToChain()).thenReturn(false);
|
||||
assertThat(legacyController.syncedToChain()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void getPeerPubkeys() {
|
||||
LocalChannel channel2 = new LocalChannel(ChannelFixtures.create(PUBKEY, PUBKEY_3, CHANNEL_ID_2), PUBKEY);
|
||||
when(channelService.getOpenChannels()).thenReturn(Set.of(LOCAL_CHANNEL, channel2));
|
||||
assertThat(legacyController.getPeerPubkeys()).isEqualTo(PUBKEY_2 + "\n" + PUBKEY_3);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
package de.cotto.lndmanagej.service;
|
||||
|
||||
import de.cotto.lndmanagej.grpc.GrpcChannels;
|
||||
import de.cotto.lndmanagej.model.Channel;
|
||||
import de.cotto.lndmanagej.model.ChannelFixtures;
|
||||
import de.cotto.lndmanagej.model.LocalChannel;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
@@ -11,12 +11,9 @@ import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import static de.cotto.lndmanagej.model.ChannelFixtures.CHANNEL;
|
||||
import static de.cotto.lndmanagej.model.ChannelFixtures.CHANNEL_3;
|
||||
import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID;
|
||||
import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID_2;
|
||||
import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID_3;
|
||||
import static de.cotto.lndmanagej.model.NodeFixtures.NODE_2;
|
||||
import static de.cotto.lndmanagej.model.LocalChannelFixtures.LOCAL_CHANNEL;
|
||||
import static de.cotto.lndmanagej.model.LocalChannelFixtures.LOCAL_CHANNEL_3;
|
||||
import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY;
|
||||
import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY_2;
|
||||
import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY_3;
|
||||
@@ -33,26 +30,16 @@ class ChannelServiceTest {
|
||||
|
||||
@Test
|
||||
void getOpenChannelsWith_by_pubkey() {
|
||||
when(grpcChannels.getChannels()).thenReturn(Set.of(CHANNEL, CHANNEL_3));
|
||||
assertThat(channelService.getOpenChannelsWith(PUBKEY_2)).containsExactly(CHANNEL_ID, CHANNEL_ID_3);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getOpenChannelsWith_by_node() {
|
||||
when(grpcChannels.getChannels()).thenReturn(Set.of(CHANNEL, CHANNEL_3));
|
||||
assertThat(channelService.getOpenChannelsWith(NODE_2)).containsExactly(CHANNEL_ID, CHANNEL_ID_3);
|
||||
when(grpcChannels.getChannels()).thenReturn(Set.of(LOCAL_CHANNEL, LOCAL_CHANNEL_3));
|
||||
assertThat(channelService.getOpenChannelsWith(PUBKEY_2))
|
||||
.containsExactlyInAnyOrder(LOCAL_CHANNEL, LOCAL_CHANNEL_3);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getOpenChannelsWith_ignores_channel_to_other_node() {
|
||||
Channel channel2 = ChannelFixtures.create(PUBKEY, PUBKEY_3, CHANNEL_ID_2);
|
||||
when(grpcChannels.getChannels()).thenReturn(Set.of(CHANNEL, channel2, CHANNEL_3));
|
||||
assertThat(channelService.getOpenChannelsWith(NODE_2)).containsExactly(CHANNEL_ID, CHANNEL_ID_3);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getOpenChannelsWith_ordered() {
|
||||
when(grpcChannels.getChannels()).thenReturn(Set.of(CHANNEL_3, CHANNEL));
|
||||
assertThat(channelService.getOpenChannelsWith(NODE_2)).containsExactly(CHANNEL_ID, CHANNEL_ID_3);
|
||||
LocalChannel localChannel2 = new LocalChannel(ChannelFixtures.create(PUBKEY, PUBKEY_3, CHANNEL_ID_2), PUBKEY);
|
||||
when(grpcChannels.getChannels()).thenReturn(Set.of(LOCAL_CHANNEL, localChannel2, LOCAL_CHANNEL_3));
|
||||
assertThat(channelService.getOpenChannelsWith(PUBKEY_2))
|
||||
.containsExactlyInAnyOrder(LOCAL_CHANNEL, LOCAL_CHANNEL_3);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user