diff --git a/application/src/integrationTest/java/de/cotto/lndmanagej/controller/LegacyControllerIT.java b/application/src/integrationTest/java/de/cotto/lndmanagej/controller/LegacyControllerIT.java index 26d403f7..f4bdc4b4 100644 --- a/application/src/integrationTest/java/de/cotto/lndmanagej/controller/LegacyControllerIT.java +++ b/application/src/integrationTest/java/de/cotto/lndmanagej/controller/LegacyControllerIT.java @@ -9,12 +9,17 @@ import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.web.servlet.MockMvc; -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_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.LocalChannelFixtures.LOCAL_CHANNEL_TO_NODE_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.mockito.Mockito.when; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; @@ -47,7 +52,7 @@ class LegacyControllerIT { @Test void getOpenChannelIds() throws Exception { - when(channelService.getOpenChannelsWith(PUBKEY)).thenReturn(List.of(CHANNEL_ID, CHANNEL_ID_3)); + when(channelService.getOpenChannelsWith(PUBKEY)).thenReturn(Set.of(LOCAL_CHANNEL, LOCAL_CHANNEL_3)); mockMvc.perform(get("/legacy/node/" + PUBKEY + "/open-channels")) .andExpect(content().string(CHANNEL_ID + "\n" + CHANNEL_ID_3)); } @@ -63,4 +68,11 @@ class LegacyControllerIT { when(ownNodeService.isSyncedToChain()).thenReturn(false); mockMvc.perform(get("/legacy/synced-to-chain")).andExpect(content().string("false")); } + + @Test + void getPeerPubkeys() throws Exception { + when(channelService.getOpenChannels()).thenReturn(Set.of(LOCAL_CHANNEL, LOCAL_CHANNEL_TO_NODE_3)); + mockMvc.perform(get("/legacy/peer-pubkeys")) + .andExpect(content().string(PUBKEY_2 + "\n" + PUBKEY_3)); + } } \ No newline at end of file diff --git a/application/src/main/java/de/cotto/lndmanagej/controller/LegacyController.java b/application/src/main/java/de/cotto/lndmanagej/controller/LegacyController.java index ec91005c..3721811a 100644 --- a/application/src/main/java/de/cotto/lndmanagej/controller/LegacyController.java +++ b/application/src/main/java/de/cotto/lndmanagej/controller/LegacyController.java @@ -1,6 +1,8 @@ package de.cotto.lndmanagej.controller; +import de.cotto.lndmanagej.model.Channel; import de.cotto.lndmanagej.model.ChannelId; +import de.cotto.lndmanagej.model.LocalChannel; import de.cotto.lndmanagej.model.Pubkey; import de.cotto.lndmanagej.service.ChannelService; import de.cotto.lndmanagej.service.NodeService; @@ -34,10 +36,21 @@ public class LegacyController { @GetMapping("/node/{pubkey}/open-channels") public String getOpenChannelIds(@PathVariable Pubkey pubkey) { return channelService.getOpenChannelsWith(pubkey).stream() + .map(Channel::getId) + .sorted() .map(ChannelId::toString) .collect(Collectors.joining(NEWLINE)); } + @GetMapping("/peer-pubkeys") + public String getPeerPubkeys() { + return channelService.getOpenChannels().stream() + .map(LocalChannel::getRemotePubkey) + .map(Pubkey::toString) + .sorted() + .collect(Collectors.joining(NEWLINE)); + } + @GetMapping("/synced-to-chain") public boolean syncedToChain() { return ownNodeService.isSyncedToChain(); diff --git a/application/src/main/java/de/cotto/lndmanagej/service/ChannelService.java b/application/src/main/java/de/cotto/lndmanagej/service/ChannelService.java index badc8446..a84ec837 100644 --- a/application/src/main/java/de/cotto/lndmanagej/service/ChannelService.java +++ b/application/src/main/java/de/cotto/lndmanagej/service/ChannelService.java @@ -4,53 +4,49 @@ import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; import de.cotto.lndmanagej.grpc.GrpcChannels; -import de.cotto.lndmanagej.model.Channel; -import de.cotto.lndmanagej.model.ChannelId; -import de.cotto.lndmanagej.model.Node; +import de.cotto.lndmanagej.model.LocalChannel; import de.cotto.lndmanagej.model.Pubkey; import org.springframework.stereotype.Component; import javax.annotation.Nonnull; -import java.util.List; +import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; @Component public class ChannelService { private static final int MAXIMUM_SIZE = 500; - private static final int CACHE_EXPIRY_MINUTES = 5; + private static final int CACHE_EXPIRY_MINUTES = 1; private final GrpcChannels grpcChannels; - private final LoadingCache> channelsWithPeerCache; + private final LoadingCache> channelsCache; public ChannelService(GrpcChannels grpcChannels) { this.grpcChannels = grpcChannels; - CacheLoader> loader = new CacheLoader<>() { + channelsCache = initializeChannelsCache(); + } + + public Set getOpenChannels() { + return channelsCache.getUnchecked(""); + } + + public Set getOpenChannelsWith(Pubkey peer) { + return getOpenChannels().stream() + .filter(c -> peer.equals(c.getRemotePubkey())) + .collect(Collectors.toSet()); + } + + private LoadingCache> initializeChannelsCache() { + CacheLoader> loader = new CacheLoader<>() { @Nonnull @Override - public List load(@Nonnull Pubkey peer) { - return getOpenChannelsWithWithoutCache(peer); + public Set load(@Nonnull String ignored) { + return grpcChannels.getChannels(); } }; - channelsWithPeerCache = CacheBuilder.newBuilder() + return CacheBuilder.newBuilder() .expireAfterWrite(CACHE_EXPIRY_MINUTES, TimeUnit.MINUTES) .maximumSize(MAXIMUM_SIZE) .build(loader); } - - public List getOpenChannelsWith(Pubkey peer) { - return channelsWithPeerCache.getUnchecked(peer); - } - - public List getOpenChannelsWith(Node peer) { - return getOpenChannelsWith(peer.pubkey()); - } - - public List getOpenChannelsWithWithoutCache(Pubkey peer) { - return grpcChannels.getChannels().stream() - .filter(c -> c.getPubkeys().contains(peer)) - .map(Channel::getId) - .sorted() - .collect(Collectors.toList()); - } } diff --git a/application/src/test/java/de/cotto/lndmanagej/controller/LegacyControllerTest.java b/application/src/test/java/de/cotto/lndmanagej/controller/LegacyControllerTest.java index cf68ce25..cc90267d 100644 --- a/application/src/test/java/de/cotto/lndmanagej/controller/LegacyControllerTest.java +++ b/application/src/test/java/de/cotto/lndmanagej/controller/LegacyControllerTest.java @@ -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); + } } \ No newline at end of file diff --git a/application/src/test/java/de/cotto/lndmanagej/service/ChannelServiceTest.java b/application/src/test/java/de/cotto/lndmanagej/service/ChannelServiceTest.java index f4d7328b..ac4d405d 100644 --- a/application/src/test/java/de/cotto/lndmanagej/service/ChannelServiceTest.java +++ b/application/src/test/java/de/cotto/lndmanagej/service/ChannelServiceTest.java @@ -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); } } \ No newline at end of file diff --git a/grpc-adapter/src/main/java/de/cotto/lndmanagej/grpc/GrpcChannels.java b/grpc-adapter/src/main/java/de/cotto/lndmanagej/grpc/GrpcChannels.java index 3a3c876e..7fd4de0d 100644 --- a/grpc-adapter/src/main/java/de/cotto/lndmanagej/grpc/GrpcChannels.java +++ b/grpc-adapter/src/main/java/de/cotto/lndmanagej/grpc/GrpcChannels.java @@ -3,6 +3,7 @@ package de.cotto.lndmanagej.grpc; import de.cotto.lndmanagej.model.Channel; import de.cotto.lndmanagej.model.ChannelId; import de.cotto.lndmanagej.model.Coins; +import de.cotto.lndmanagej.model.LocalChannel; import de.cotto.lndmanagej.model.Pubkey; import org.springframework.stereotype.Component; @@ -23,20 +24,21 @@ public class GrpcChannels { this.grpcGetInfo = grpcGetInfo; } - public Set getChannels() { + public Set getChannels() { Pubkey ownPubkey = grpcGetInfo.getPubkey().orElseThrow(); return grpcService.getChannels().stream() .map(lndChannel -> toChannel(lndChannel, ownPubkey)) .collect(toSet()); } - private Channel toChannel(lnrpc.Channel lndChannel, Pubkey ownPubkey) { - return Channel.builder() + private LocalChannel toChannel(lnrpc.Channel lndChannel, Pubkey ownPubkey) { + Channel channel = Channel.builder() .withChannelId(ChannelId.fromShortChannelId(lndChannel.getChanId())) .withCapacity(Coins.ofSatoshis(lndChannel.getCapacity())) .withNode1(ownPubkey) .withNode2(Pubkey.create(lndChannel.getRemotePubkey())) .build(); + return new LocalChannel(channel, ownPubkey); } } diff --git a/grpc-adapter/src/test/java/de/cotto/lndmanagej/grpc/GrpcChannelsTest.java b/grpc-adapter/src/test/java/de/cotto/lndmanagej/grpc/GrpcChannelsTest.java index 79fe30bc..7e980619 100644 --- a/grpc-adapter/src/test/java/de/cotto/lndmanagej/grpc/GrpcChannelsTest.java +++ b/grpc-adapter/src/test/java/de/cotto/lndmanagej/grpc/GrpcChannelsTest.java @@ -12,8 +12,8 @@ import java.util.List; import java.util.Optional; import static de.cotto.lndmanagej.model.ChannelFixtures.CAPACITY; -import static de.cotto.lndmanagej.model.ChannelFixtures.CHANNEL; import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID; +import static de.cotto.lndmanagej.model.LocalChannelFixtures.LOCAL_CHANNEL; import static de.cotto.lndmanagej.model.NodeFixtures.NODE_2; import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY; import static org.assertj.core.api.Assertions.assertThat; @@ -43,7 +43,7 @@ class GrpcChannelsTest { @Test void one_channel() { when(grpcService.getChannels()).thenReturn(List.of(channel())); - assertThat(grpcChannels.getChannels()).containsExactly(CHANNEL); + assertThat(grpcChannels.getChannels()).containsExactly(LOCAL_CHANNEL); } private Channel channel() { diff --git a/model/src/main/java/de/cotto/lndmanagej/model/Channel.java b/model/src/main/java/de/cotto/lndmanagej/model/Channel.java index e909e641..e17d579c 100644 --- a/model/src/main/java/de/cotto/lndmanagej/model/Channel.java +++ b/model/src/main/java/de/cotto/lndmanagej/model/Channel.java @@ -2,7 +2,9 @@ package de.cotto.lndmanagej.model; import org.springframework.lang.Nullable; +import java.util.Collection; import java.util.LinkedHashSet; +import java.util.List; import java.util.Objects; import java.util.Set; @@ -11,13 +13,16 @@ import static java.util.Objects.requireNonNull; public class Channel { private final ChannelId channelId; private final Coins capacity; - private final Set pubkeys = new LinkedHashSet<>(); + private final Set pubkeys; private Channel(ChannelId channelId, Coins capacity, Pubkey pubkey1, Pubkey pubkey2) { + this(channelId, capacity, List.of(pubkey1, pubkey2)); + } + + protected Channel(ChannelId channelId, Coins capacity, Collection pubkeys) { this.channelId = channelId; this.capacity = Coins.ofMilliSatoshis(capacity.milliSatoshis()); - pubkeys.add(pubkey1); - pubkeys.add(pubkey2); + this.pubkeys = new LinkedHashSet<>(pubkeys); } public static Builder builder() { @@ -70,6 +75,9 @@ public class Channel { } public Channel build() { + if (requireNonNull(pubkey1).equals(requireNonNull(pubkey2))) { + throw new IllegalArgumentException("Pubkeys must not be the same"); + } return new Channel( requireNonNull(channelId), requireNonNull(capacity), diff --git a/model/src/main/java/de/cotto/lndmanagej/model/LocalChannel.java b/model/src/main/java/de/cotto/lndmanagej/model/LocalChannel.java new file mode 100644 index 00000000..a10f2b18 --- /dev/null +++ b/model/src/main/java/de/cotto/lndmanagej/model/LocalChannel.java @@ -0,0 +1,23 @@ +package de.cotto.lndmanagej.model; + +import java.util.Set; + +public class LocalChannel extends Channel { + private final Pubkey remotePubkey; + + public LocalChannel(Channel channel, Pubkey ownPubkey) { + super(channel.getId(), channel.getCapacity(), channel.getPubkeys()); + Set pubkeys = channel.getPubkeys(); + remotePubkey = pubkeys.stream() + .filter(pubkey -> !ownPubkey.equals(pubkey)) + .findFirst() + .orElseThrow(); + if (!pubkeys.contains(ownPubkey)) { + throw new IllegalArgumentException("Channel must have given pubkey as peer"); + } + } + + public Pubkey getRemotePubkey() { + return remotePubkey; + } +} diff --git a/model/src/test/java/de/cotto/lndmanagej/model/ChannelTest.java b/model/src/test/java/de/cotto/lndmanagej/model/ChannelTest.java index 23f557bd..b2897dd3 100644 --- a/model/src/test/java/de/cotto/lndmanagej/model/ChannelTest.java +++ b/model/src/test/java/de/cotto/lndmanagej/model/ChannelTest.java @@ -9,6 +9,7 @@ import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID; import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY; import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY_2; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.assertj.core.api.Assertions.assertThatNullPointerException; class ChannelTest { @@ -63,6 +64,18 @@ class ChannelTest { ); } + @Test + void builder_identical_pubkeys() { + assertThatIllegalArgumentException().isThrownBy( + () -> Channel.builder() + .withChannelId(CHANNEL_ID) + .withCapacity(CAPACITY) + .withNode1(PUBKEY) + .withNode2(PUBKEY) + .build() + ).withMessage("Pubkeys must not be the same"); + } + @Test void builder_with_all_arguments() { Channel channel = Channel.builder() diff --git a/model/src/test/java/de/cotto/lndmanagej/model/LocalChannelTest.java b/model/src/test/java/de/cotto/lndmanagej/model/LocalChannelTest.java new file mode 100644 index 00000000..20327152 --- /dev/null +++ b/model/src/test/java/de/cotto/lndmanagej/model/LocalChannelTest.java @@ -0,0 +1,32 @@ +package de.cotto.lndmanagej.model; + +import org.junit.jupiter.api.Test; + +import static de.cotto.lndmanagej.model.ChannelFixtures.CHANNEL_2; +import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID; +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.assertj.core.api.Assertions.assertThatIllegalArgumentException; + +class LocalChannelTest { + @Test + void getRemotePubkey() { + LocalChannel localChannel = new LocalChannel(ChannelFixtures.create(PUBKEY_2, PUBKEY, CHANNEL_ID), PUBKEY); + assertThat(localChannel.getRemotePubkey()).isEqualTo(PUBKEY_2); + } + + @Test + void getRemotePubkey_swapped() { + LocalChannel localChannel = new LocalChannel(ChannelFixtures.create(PUBKEY_3, PUBKEY_2, CHANNEL_ID), PUBKEY_3); + assertThat(localChannel.getRemotePubkey()).isEqualTo(PUBKEY_2); + } + + @Test + void ownPubkey_not_in_pubkey_set() { + assertThatIllegalArgumentException() + .isThrownBy(() -> new LocalChannel(CHANNEL_2, PUBKEY_3)) + .withMessage("Channel must have given pubkey as peer"); + } +} \ No newline at end of file diff --git a/model/src/testFixtures/java/de/cotto/lndmanagej/model/ChannelFixtures.java b/model/src/testFixtures/java/de/cotto/lndmanagej/model/ChannelFixtures.java index e8043bd5..dc74b179 100644 --- a/model/src/testFixtures/java/de/cotto/lndmanagej/model/ChannelFixtures.java +++ b/model/src/testFixtures/java/de/cotto/lndmanagej/model/ChannelFixtures.java @@ -5,6 +5,7 @@ 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.PubkeyFixtures.PUBKEY; import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY_2; +import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY_3; public final class ChannelFixtures { public static final Coins CAPACITY = Coins.ofSatoshis(21_000_000L); @@ -12,6 +13,7 @@ public final class ChannelFixtures { public static final Channel CHANNEL = create(PUBKEY, PUBKEY_2, CHANNEL_ID); public static final Channel CHANNEL_2 = create(PUBKEY, PUBKEY_2, CHANNEL_ID_2); public static final Channel CHANNEL_3 = create(PUBKEY, PUBKEY_2, CHANNEL_ID_3); + public static final Channel CHANNEL_TO_NODE_3 = create(PUBKEY, PUBKEY_3, CHANNEL_ID); private ChannelFixtures() { // do not instantiate diff --git a/model/src/testFixtures/java/de/cotto/lndmanagej/model/LocalChannelFixtures.java b/model/src/testFixtures/java/de/cotto/lndmanagej/model/LocalChannelFixtures.java new file mode 100644 index 00000000..9e907d54 --- /dev/null +++ b/model/src/testFixtures/java/de/cotto/lndmanagej/model/LocalChannelFixtures.java @@ -0,0 +1,14 @@ +package de.cotto.lndmanagej.model; + +import static de.cotto.lndmanagej.model.ChannelFixtures.CHANNEL; +import static de.cotto.lndmanagej.model.ChannelFixtures.CHANNEL_2; +import static de.cotto.lndmanagej.model.ChannelFixtures.CHANNEL_3; +import static de.cotto.lndmanagej.model.ChannelFixtures.CHANNEL_TO_NODE_3; +import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY; + +public class LocalChannelFixtures { + public static final LocalChannel LOCAL_CHANNEL = new LocalChannel(CHANNEL, PUBKEY); + public static final LocalChannel LOCAL_CHANNEL_2 = new LocalChannel(CHANNEL_2, PUBKEY); + public static final LocalChannel LOCAL_CHANNEL_3 = new LocalChannel(CHANNEL_3, PUBKEY); + public static final LocalChannel LOCAL_CHANNEL_TO_NODE_3 = new LocalChannel(CHANNEL_TO_NODE_3, PUBKEY); +}