diff --git a/backend/src/main/java/de/cotto/lndmanagej/service/ChannelNumUpdatesWarningsProvider.java b/backend/src/main/java/de/cotto/lndmanagej/service/ChannelNumUpdatesWarningsProvider.java deleted file mode 100644 index df844f33..00000000 --- a/backend/src/main/java/de/cotto/lndmanagej/service/ChannelNumUpdatesWarningsProvider.java +++ /dev/null @@ -1,58 +0,0 @@ -package de.cotto.lndmanagej.service; - -import de.cotto.lndmanagej.configuration.ConfigurationService; -import de.cotto.lndmanagej.model.ChannelId; -import de.cotto.lndmanagej.model.ChannelIdParser; -import de.cotto.lndmanagej.model.LocalOpenChannel; -import de.cotto.lndmanagej.model.warnings.ChannelNumUpdatesWarning; -import de.cotto.lndmanagej.model.warnings.ChannelWarning; -import de.cotto.lndmanagej.service.warnings.ChannelWarningsProvider; -import org.springframework.stereotype.Component; - -import java.util.Optional; -import java.util.stream.Stream; - -import static de.cotto.lndmanagej.configuration.WarningsConfigurationSettings.MAX_NUM_UPDATES; -import static de.cotto.lndmanagej.configuration.WarningsConfigurationSettings.MAX_NUM_UPDATES_IGNORE_CHANNEL; - -@Component -public class ChannelNumUpdatesWarningsProvider implements ChannelWarningsProvider { - private static final int DEFAULT_MAX_NUM_UPDATES = 100_000; - - private final ChannelService channelService; - private final ConfigurationService configurationService; - private final ChannelIdParser channelIdParser; - - public ChannelNumUpdatesWarningsProvider( - ChannelService channelService, - ConfigurationService configurationService, - ChannelIdParser channelIdParser - ) { - this.channelService = channelService; - this.configurationService = configurationService; - this.channelIdParser = channelIdParser; - } - - @Override - public Stream getChannelWarnings(ChannelId channelId) { - if (ignoreWarning(channelId)) { - return Stream.empty(); - } - return Stream.of(getNumUpdatesWarning(channelId)).flatMap(Optional::stream); - } - - private Optional getNumUpdatesWarning(ChannelId channelId) { - Integer maxNumUpdates = configurationService.getIntegerValue(MAX_NUM_UPDATES) - .orElse(DEFAULT_MAX_NUM_UPDATES); - long numUpdates = channelService.getOpenChannel(channelId).map(LocalOpenChannel::getNumUpdates).orElse(0L); - if (numUpdates <= maxNumUpdates) { - return Optional.empty(); - } - return Optional.of(new ChannelNumUpdatesWarning(numUpdates)); - } - - private boolean ignoreWarning(ChannelId channelId) { - return configurationService.getChannelIds(MAX_NUM_UPDATES_IGNORE_CHANNEL, channelIdParser::parseFromString) - .contains(channelId); - } -} diff --git a/backend/src/test/java/de/cotto/lndmanagej/service/ChannelNumUpdatesWarningsProviderTest.java b/backend/src/test/java/de/cotto/lndmanagej/service/ChannelNumUpdatesWarningsProviderTest.java deleted file mode 100644 index 5b1081ab..00000000 --- a/backend/src/test/java/de/cotto/lndmanagej/service/ChannelNumUpdatesWarningsProviderTest.java +++ /dev/null @@ -1,122 +0,0 @@ -package de.cotto.lndmanagej.service; - -import de.cotto.lndmanagej.configuration.ConfigurationService; -import de.cotto.lndmanagej.model.ChannelCoreInformation; -import de.cotto.lndmanagej.model.ChannelIdParser; -import de.cotto.lndmanagej.model.LocalOpenChannel; -import de.cotto.lndmanagej.model.warnings.ChannelNumUpdatesWarning; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Nested; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -import java.util.Optional; -import java.util.Set; - -import static de.cotto.lndmanagej.configuration.WarningsConfigurationSettings.MAX_NUM_UPDATES; -import static de.cotto.lndmanagej.configuration.WarningsConfigurationSettings.MAX_NUM_UPDATES_IGNORE_CHANNEL; -import static de.cotto.lndmanagej.model.BalanceInformationFixtures.BALANCE_INFORMATION; -import static de.cotto.lndmanagej.model.ChannelFixtures.CAPACITY; -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.ChannelPointFixtures.CHANNEL_POINT; -import static de.cotto.lndmanagej.model.LocalOpenChannelFixtures.MIN_HTLC_CONSTRAINT; -import static de.cotto.lndmanagej.model.LocalOpenChannelFixtures.TOTAL_RECEIVED; -import static de.cotto.lndmanagej.model.LocalOpenChannelFixtures.TOTAL_SENT; -import static de.cotto.lndmanagej.model.OpenInitiator.LOCAL; -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.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.lenient; -import static org.mockito.Mockito.when; - -@ExtendWith(MockitoExtension.class) -class ChannelNumUpdatesWarningsProviderTest { - private static final long DEFAULT_MAX_NUM_UPDATES = 100_000L; - - @InjectMocks - private ChannelNumUpdatesWarningsProvider warningsProvider; - - @Mock - private ChannelService channelService; - - @Mock - private ConfigurationService configurationService; - - @Mock - @SuppressWarnings("unused") - private ChannelIdParser channelIdParser; - - @Test - void getChannelWarnings_open_channel_not_found() { - when(channelService.getOpenChannel(CHANNEL_ID)).thenReturn(Optional.empty()); - assertThat(warningsProvider.getChannelWarnings(CHANNEL_ID)).isEmpty(); - } - - @Test - void getChannelWarnings_low_number_of_num_updates() { - when(channelService.getOpenChannel(CHANNEL_ID)) - .thenReturn(Optional.of(createChannel(DEFAULT_MAX_NUM_UPDATES))); - assertThat(warningsProvider.getChannelWarnings(CHANNEL_ID)).isEmpty(); - } - - @Test - void getChannelWarnings_high_number_of_num_updates() { - when(channelService.getOpenChannel(CHANNEL_ID)) - .thenReturn(Optional.of(createChannel(DEFAULT_MAX_NUM_UPDATES + 1))); - ChannelNumUpdatesWarning channelNumUpdatesWarning = new ChannelNumUpdatesWarning(DEFAULT_MAX_NUM_UPDATES + 1); - assertThat(warningsProvider.getChannelWarnings(CHANNEL_ID)).containsExactly(channelNumUpdatesWarning); - } - - @Test - void getChannelWarnings_uses_configured_value() { - when(configurationService.getIntegerValue(MAX_NUM_UPDATES)).thenReturn(Optional.of(10)); - when(channelService.getOpenChannel(CHANNEL_ID)).thenReturn(Optional.of(createChannel(11))); - assertThat(warningsProvider.getChannelWarnings(CHANNEL_ID)).hasSize(1); - } - - @Nested - class IgnoredWarnings { - @BeforeEach - void setUp() { - lenient().when(channelService.getOpenChannel(CHANNEL_ID)) - .thenReturn(Optional.of(createChannel(DEFAULT_MAX_NUM_UPDATES + 1))); - } - - @Test - void no_warning_for_ignored_channel() { - when(configurationService.getChannelIds(eq(MAX_NUM_UPDATES_IGNORE_CHANNEL), any())) - .thenReturn(Set.of(CHANNEL_ID_2, CHANNEL_ID)); - assertThat(warningsProvider.getChannelWarnings(CHANNEL_ID)).isEmpty(); - } - - @Test - void warning_if_other_channel_is_ignored() { - when(configurationService.getChannelIds(eq(MAX_NUM_UPDATES_IGNORE_CHANNEL), any())) - .thenReturn(Set.of(CHANNEL_ID_2, CHANNEL_ID_3)); - assertThat(warningsProvider.getChannelWarnings(CHANNEL_ID)).isNotEmpty(); - } - } - - private LocalOpenChannel createChannel(long numUpdates) { - return new LocalOpenChannel( - new ChannelCoreInformation(CHANNEL_ID, CHANNEL_POINT, CAPACITY), - PUBKEY, - PUBKEY_2, - BALANCE_INFORMATION, - LOCAL, - TOTAL_SENT, - TOTAL_RECEIVED, - false, - true, - numUpdates, - MIN_HTLC_CONSTRAINT - ); - } -} diff --git a/backend/src/test/java/de/cotto/lndmanagej/service/ChannelWarningsServiceTest.java b/backend/src/test/java/de/cotto/lndmanagej/service/ChannelWarningsServiceTest.java index 6a2592ac..6e8612dd 100644 --- a/backend/src/test/java/de/cotto/lndmanagej/service/ChannelWarningsServiceTest.java +++ b/backend/src/test/java/de/cotto/lndmanagej/service/ChannelWarningsServiceTest.java @@ -17,7 +17,6 @@ import static de.cotto.lndmanagej.model.LocalOpenChannelFixtures.LOCAL_OPEN_CHANNEL; import static de.cotto.lndmanagej.model.LocalOpenChannelFixtures.LOCAL_OPEN_CHANNEL_TO_NODE_3; import static de.cotto.lndmanagej.model.warnings.ChannelWarningFixtures.CHANNEL_BALANCE_FLUCTUATION_WARNING; -import static de.cotto.lndmanagej.model.warnings.ChannelWarningFixtures.CHANNEL_NUM_UPDATES_WARNING; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.when; @@ -47,9 +46,9 @@ void getChannelWarnings_for_one_channel_no_warning() { @Test void getChannelWarnings_for_one_channel() { when(provider1.getChannelWarnings(CHANNEL_ID)) - .thenReturn(Stream.of(CHANNEL_NUM_UPDATES_WARNING)); + .thenReturn(Stream.of(CHANNEL_BALANCE_FLUCTUATION_WARNING)); ChannelWarnings expected = new ChannelWarnings( - CHANNEL_NUM_UPDATES_WARNING + CHANNEL_BALANCE_FLUCTUATION_WARNING ); assertThat(channelWarningsService.getChannelWarnings(CHANNEL_ID)).isEqualTo(expected); } @@ -69,22 +68,10 @@ void getNodeWarnings_no_warnings() { @Test void getChannelWarnings() { when(channelService.getOpenChannels()).thenReturn(Set.of(LOCAL_OPEN_CHANNEL, LOCAL_OPEN_CHANNEL_TO_NODE_3)); - when(provider1.getChannelWarnings(CHANNEL_ID)).thenReturn(Stream.of(CHANNEL_NUM_UPDATES_WARNING)); + when(provider1.getChannelWarnings(CHANNEL_ID)).thenReturn(Stream.of(CHANNEL_BALANCE_FLUCTUATION_WARNING)); when(provider1.getChannelWarnings(CHANNEL_ID_4)).thenReturn(Stream.of()); assertThat(channelWarningsService.getChannelWarnings()).containsExactlyInAnyOrderEntriesOf(Map.of( - LOCAL_OPEN_CHANNEL, new ChannelWarnings(CHANNEL_NUM_UPDATES_WARNING) + LOCAL_OPEN_CHANNEL, new ChannelWarnings(CHANNEL_BALANCE_FLUCTUATION_WARNING) )); } - - @Test - void getChannelWarnings_two_different_warnings_for_same_channel() { - when(channelService.getOpenChannels()).thenReturn(Set.of(LOCAL_OPEN_CHANNEL)); - when(provider1.getChannelWarnings(CHANNEL_ID)).thenReturn(Stream.of(CHANNEL_NUM_UPDATES_WARNING)); - when(provider2.getChannelWarnings(CHANNEL_ID)).thenReturn(Stream.of(CHANNEL_BALANCE_FLUCTUATION_WARNING)); - ChannelWarnings expectedWarnings = - new ChannelWarnings(CHANNEL_NUM_UPDATES_WARNING, CHANNEL_BALANCE_FLUCTUATION_WARNING); - assertThat(channelWarningsService.getChannelWarnings()).containsEntry( - LOCAL_OPEN_CHANNEL, expectedWarnings - ); - } } diff --git a/configuration/src/main/java/de/cotto/lndmanagej/configuration/WarningsConfigurationSettings.java b/configuration/src/main/java/de/cotto/lndmanagej/configuration/WarningsConfigurationSettings.java index 91765b15..49273a6b 100644 --- a/configuration/src/main/java/de/cotto/lndmanagej/configuration/WarningsConfigurationSettings.java +++ b/configuration/src/main/java/de/cotto/lndmanagej/configuration/WarningsConfigurationSettings.java @@ -14,10 +14,7 @@ public enum WarningsConfigurationSettings implements ConfigurationSetting { NODE_FLOW_WARNING_IGNORE_NODE("node_flow_warning_ignore_node"), NODE_RATING_THRESHOLD("node_rating_threshold"), - NODE_RATING_WARNING_IGNORE_NODE("node_rating_warning_ignore_node"), - - MAX_NUM_UPDATES("max_num_updates"), - MAX_NUM_UPDATES_IGNORE_CHANNEL("max_num_updates_warning_ignore_channel"); + NODE_RATING_WARNING_IGNORE_NODE("node_rating_warning_ignore_node"); private final String name; diff --git a/configuration/src/test/java/de/cotto/lndmanagej/configuration/ConfigurationServiceTest.java b/configuration/src/test/java/de/cotto/lndmanagej/configuration/ConfigurationServiceTest.java index 6dcad1a9..3fa78b89 100644 --- a/configuration/src/test/java/de/cotto/lndmanagej/configuration/ConfigurationServiceTest.java +++ b/configuration/src/test/java/de/cotto/lndmanagej/configuration/ConfigurationServiceTest.java @@ -13,7 +13,7 @@ import java.util.Set; import static de.cotto.lndmanagej.configuration.PickhardtPaymentsConfigurationSettings.USE_MISSION_CONTROL; -import static de.cotto.lndmanagej.configuration.WarningsConfigurationSettings.MAX_NUM_UPDATES_IGNORE_CHANNEL; +import static de.cotto.lndmanagej.configuration.WarningsConfigurationSettings.CHANNEL_FLUCTUATION_WARNING_IGNORE_CHANNEL; import static de.cotto.lndmanagej.configuration.WarningsConfigurationSettings.ONLINE_CHANGES_THRESHOLD; import static de.cotto.lndmanagej.configuration.WarningsConfigurationSettings.ONLINE_WARNING_IGNORE_NODE; import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID; @@ -131,8 +131,9 @@ void getPubkeys_forWarningConfig_twoInConfig() { @Test void getChannelIds_not_known_empty() { - Set channelIds = - configurationService.getChannelIds(MAX_NUM_UPDATES_IGNORE_CHANNEL, channelIdParser::parseFromString); + Set channelIds = configurationService.getChannelIds( + CHANNEL_FLUCTUATION_WARNING_IGNORE_CHANNEL, channelIdParser::parseFromString + ); assertThat(channelIds).isEmpty(); } @@ -143,7 +144,7 @@ void getChannelIds_forWarningConfig_fourInConfig() { when(channelIdParser.parseFromString(String.valueOf(CHANNEL_ID_3.getShortChannelId()))) .thenReturn(CHANNEL_ID_3); when(channelIdParser.parseFromString(CHANNEL_POINT.toString())).thenReturn(CHANNEL_ID_4); - WarningsConfigurationSettings config = MAX_NUM_UPDATES_IGNORE_CHANNEL; + WarningsConfigurationSettings config = CHANNEL_FLUCTUATION_WARNING_IGNORE_CHANNEL; when(iniFileReader.getValues(config.getSection())) .thenReturn(Map.of(config.getName(), Set.of( @@ -159,7 +160,7 @@ void getChannelIds_forWarningConfig_fourInConfig() { @Test() void getChannelIds_forInvalidWarningConfig_error() { when(channelIdParser.parseFromString("invalid_chan")).thenThrow(new IllegalArgumentException()); - WarningsConfigurationSettings config = MAX_NUM_UPDATES_IGNORE_CHANNEL; + WarningsConfigurationSettings config = CHANNEL_FLUCTUATION_WARNING_IGNORE_CHANNEL; when(iniFileReader.getValues(config.getSection())).thenReturn(Map.of(config.getName(), Set.of("invalid_chan"))); assertThatIllegalArgumentException().isThrownBy( () -> configurationService.getChannelIds(config, channelIdParser::parseFromString) diff --git a/configuration/src/test/java/de/cotto/lndmanagej/configuration/WarningsConfigurationSettingsTest.java b/configuration/src/test/java/de/cotto/lndmanagej/configuration/WarningsConfigurationSettingsTest.java index f0c3ba44..ade4ec2f 100644 --- a/configuration/src/test/java/de/cotto/lndmanagej/configuration/WarningsConfigurationSettingsTest.java +++ b/configuration/src/test/java/de/cotto/lndmanagej/configuration/WarningsConfigurationSettingsTest.java @@ -5,8 +5,6 @@ import static de.cotto.lndmanagej.configuration.WarningsConfigurationSettings.CHANNEL_FLUCTUATION_LOWER_THRESHOLD; import static de.cotto.lndmanagej.configuration.WarningsConfigurationSettings.CHANNEL_FLUCTUATION_UPPER_THRESHOLD; import static de.cotto.lndmanagej.configuration.WarningsConfigurationSettings.CHANNEL_FLUCTUATION_WARNING_IGNORE_CHANNEL; -import static de.cotto.lndmanagej.configuration.WarningsConfigurationSettings.MAX_NUM_UPDATES; -import static de.cotto.lndmanagej.configuration.WarningsConfigurationSettings.MAX_NUM_UPDATES_IGNORE_CHANNEL; import static de.cotto.lndmanagej.configuration.WarningsConfigurationSettings.NODE_FLOW_MAXIMUM_DAYS_TO_CONSIDER; import static de.cotto.lndmanagej.configuration.WarningsConfigurationSettings.NODE_FLOW_MINIMUM_DAYS_FOR_WARNING; import static de.cotto.lndmanagej.configuration.WarningsConfigurationSettings.NODE_FLOW_WARNING_IGNORE_NODE; @@ -39,18 +37,6 @@ void channelFluctuationIgnoreWarning() { .isEqualTo("channel_fluctuation_warning_ignore_channel"); } - @Test - void maxNumUpdates() { - assertThat(MAX_NUM_UPDATES.getSection()).isEqualTo(SECTION_NAME); - assertThat(MAX_NUM_UPDATES.getName()).isEqualTo("max_num_updates"); - } - - @Test - void maxNumUpdatesIgnoreChannel() { - assertThat(MAX_NUM_UPDATES_IGNORE_CHANNEL.getSection()).isEqualTo(SECTION_NAME); - assertThat(MAX_NUM_UPDATES_IGNORE_CHANNEL.getName()).isEqualTo("max_num_updates_warning_ignore_channel"); - } - @Test void nodeFlowMinimumDaysForWarning() { assertThat(NODE_FLOW_MINIMUM_DAYS_FOR_WARNING.getSection()).isEqualTo(SECTION_NAME); diff --git a/example-lnd-manageJ.conf b/example-lnd-manageJ.conf index 76abf363..41476476 100644 --- a/example-lnd-manageJ.conf +++ b/example-lnd-manageJ.conf @@ -26,8 +26,6 @@ channel_fluctuation_upper_threshold=90 # use this to ignore warnings for one (or more) channel channel_fluctuation_warning_ignore_channel=732759x1405x0 channel_fluctuation_warning_ignore_channel=123x456:1 -max_num_updates=100000 -max_num_updates_warning_ignore_channel=732759:1405:0 node_flow_minimum_days_for_warning=30 node_flow_maximum_days_to_consider=90 # use this to ignore warnings for one (or more) peer diff --git a/model/src/main/java/de/cotto/lndmanagej/model/warnings/ChannelNumUpdatesWarning.java b/model/src/main/java/de/cotto/lndmanagej/model/warnings/ChannelNumUpdatesWarning.java deleted file mode 100644 index e6a26640..00000000 --- a/model/src/main/java/de/cotto/lndmanagej/model/warnings/ChannelNumUpdatesWarning.java +++ /dev/null @@ -1,8 +0,0 @@ -package de.cotto.lndmanagej.model.warnings; - -public record ChannelNumUpdatesWarning(long numUpdates) implements ChannelWarning { - @Override - public String description() { - return "Channel has accumulated %,d updates".formatted(numUpdates); - } -} diff --git a/model/src/test/java/de/cotto/lndmanagej/model/warnings/ChannelNumUpdatesWarningTest.java b/model/src/test/java/de/cotto/lndmanagej/model/warnings/ChannelNumUpdatesWarningTest.java deleted file mode 100644 index bf37af9c..00000000 --- a/model/src/test/java/de/cotto/lndmanagej/model/warnings/ChannelNumUpdatesWarningTest.java +++ /dev/null @@ -1,19 +0,0 @@ -package de.cotto.lndmanagej.model.warnings; - -import org.junit.jupiter.api.Test; - -import static de.cotto.lndmanagej.model.warnings.ChannelWarningFixtures.CHANNEL_NUM_UPDATES_WARNING; -import static org.assertj.core.api.Assertions.assertThat; - -class ChannelNumUpdatesWarningTest { - @Test - void numUpdates() { - assertThat(CHANNEL_NUM_UPDATES_WARNING.numUpdates()).isEqualTo(101_000L); - } - - @Test - void description() { - assertThat(CHANNEL_NUM_UPDATES_WARNING.description()) - .isEqualTo("Channel has accumulated 101,000 updates"); - } -} \ No newline at end of file diff --git a/model/src/test/java/de/cotto/lndmanagej/model/warnings/ChannelWarningsTest.java b/model/src/test/java/de/cotto/lndmanagej/model/warnings/ChannelWarningsTest.java index e4730b9a..e3530bae 100644 --- a/model/src/test/java/de/cotto/lndmanagej/model/warnings/ChannelWarningsTest.java +++ b/model/src/test/java/de/cotto/lndmanagej/model/warnings/ChannelWarningsTest.java @@ -4,7 +4,7 @@ import java.util.Set; -import static de.cotto.lndmanagej.model.warnings.ChannelWarningFixtures.CHANNEL_NUM_UPDATES_WARNING; +import static de.cotto.lndmanagej.model.warnings.ChannelWarningFixtures.CHANNEL_BALANCE_FLUCTUATION_WARNING; import static de.cotto.lndmanagej.model.warnings.ChannelWarningsFixtures.CHANNEL_WARNINGS; import static org.assertj.core.api.Assertions.assertThat; @@ -12,14 +12,14 @@ class ChannelWarningsTest { @Test void warnings() { assertThat(CHANNEL_WARNINGS.warnings()).containsExactlyInAnyOrder( - CHANNEL_NUM_UPDATES_WARNING + CHANNEL_BALANCE_FLUCTUATION_WARNING ); } @Test void descriptions() { assertThat(CHANNEL_WARNINGS.descriptions()).containsExactlyInAnyOrder( - CHANNEL_NUM_UPDATES_WARNING.description() + CHANNEL_BALANCE_FLUCTUATION_WARNING.description() ); } @@ -27,4 +27,4 @@ void descriptions() { void none() { assertThat(ChannelWarnings.NONE).isEqualTo(new ChannelWarnings(Set.of())); } -} \ No newline at end of file +} diff --git a/model/src/testFixtures/java/de/cotto/lndmanagej/model/warnings/ChannelWarningFixtures.java b/model/src/testFixtures/java/de/cotto/lndmanagej/model/warnings/ChannelWarningFixtures.java index 167f85a2..b8bf0240 100644 --- a/model/src/testFixtures/java/de/cotto/lndmanagej/model/warnings/ChannelWarningFixtures.java +++ b/model/src/testFixtures/java/de/cotto/lndmanagej/model/warnings/ChannelWarningFixtures.java @@ -1,7 +1,6 @@ package de.cotto.lndmanagej.model.warnings; public class ChannelWarningFixtures { - public static final ChannelNumUpdatesWarning CHANNEL_NUM_UPDATES_WARNING = new ChannelNumUpdatesWarning(101_000L); public static final ChannelBalanceFluctuationWarning CHANNEL_BALANCE_FLUCTUATION_WARNING = new ChannelBalanceFluctuationWarning(2, 97, 7); } diff --git a/model/src/testFixtures/java/de/cotto/lndmanagej/model/warnings/ChannelWarningsFixtures.java b/model/src/testFixtures/java/de/cotto/lndmanagej/model/warnings/ChannelWarningsFixtures.java index f34a0b85..bf683aee 100644 --- a/model/src/testFixtures/java/de/cotto/lndmanagej/model/warnings/ChannelWarningsFixtures.java +++ b/model/src/testFixtures/java/de/cotto/lndmanagej/model/warnings/ChannelWarningsFixtures.java @@ -1,9 +1,9 @@ package de.cotto.lndmanagej.model.warnings; -import static de.cotto.lndmanagej.model.warnings.ChannelWarningFixtures.CHANNEL_NUM_UPDATES_WARNING; +import static de.cotto.lndmanagej.model.warnings.ChannelWarningFixtures.CHANNEL_BALANCE_FLUCTUATION_WARNING; public class ChannelWarningsFixtures { public static final ChannelWarnings CHANNEL_WARNINGS = new ChannelWarnings( - CHANNEL_NUM_UPDATES_WARNING + CHANNEL_BALANCE_FLUCTUATION_WARNING ); } diff --git a/ui/src/test/java/de/cotto/lndmanagej/ui/UiDataServiceImplTest.java b/ui/src/test/java/de/cotto/lndmanagej/ui/UiDataServiceImplTest.java index 46f515cc..c867791c 100644 --- a/ui/src/test/java/de/cotto/lndmanagej/ui/UiDataServiceImplTest.java +++ b/ui/src/test/java/de/cotto/lndmanagej/ui/UiDataServiceImplTest.java @@ -52,7 +52,7 @@ import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY_2; import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY_3; import static de.cotto.lndmanagej.model.RebalanceReportFixtures.REBALANCE_REPORT; -import static de.cotto.lndmanagej.model.warnings.ChannelWarningFixtures.CHANNEL_NUM_UPDATES_WARNING; +import static de.cotto.lndmanagej.model.warnings.ChannelWarningFixtures.CHANNEL_BALANCE_FLUCTUATION_WARNING; import static de.cotto.lndmanagej.ui.dto.BalanceInformationModelFixture.BALANCE_INFORMATION_MODEL; import static de.cotto.lndmanagej.ui.dto.NodeDetailsDtoFixture.NODE_DETAILS_MODEL; import static de.cotto.lndmanagej.ui.dto.OpenChannelDtoFixture.CAPACITY_SAT; @@ -139,7 +139,7 @@ void getChannelDetails() throws Exception { FeeReportDto.createFromModel(FEE_REPORT), FlowReportDto.createFromModel(FLOW_REPORT), RebalanceReportDto.createFromModel(REBALANCE_REPORT), - Set.of(CHANNEL_NUM_UPDATES_WARNING.description()), + Set.of(CHANNEL_BALANCE_FLUCTUATION_WARNING.description()), RatingDto.fromModel(RATING) ) ); diff --git a/ui/src/test/java/de/cotto/lndmanagej/ui/WarningServiceImplTest.java b/ui/src/test/java/de/cotto/lndmanagej/ui/WarningServiceImplTest.java index 9ac2028a..5925a0e8 100644 --- a/ui/src/test/java/de/cotto/lndmanagej/ui/WarningServiceImplTest.java +++ b/ui/src/test/java/de/cotto/lndmanagej/ui/WarningServiceImplTest.java @@ -16,16 +16,13 @@ import java.util.Set; import static de.cotto.lndmanagej.model.LocalOpenChannelFixtures.LOCAL_OPEN_CHANNEL; -import static de.cotto.lndmanagej.model.LocalOpenChannelFixtures.LOCAL_OPEN_CHANNEL_2; import static de.cotto.lndmanagej.model.NodeFixtures.NODE; import static de.cotto.lndmanagej.model.NodeFixtures.NODE_2; import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY; import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY_2; import static de.cotto.lndmanagej.model.warnings.ChannelWarningFixtures.CHANNEL_BALANCE_FLUCTUATION_WARNING; -import static de.cotto.lndmanagej.model.warnings.ChannelWarningFixtures.CHANNEL_NUM_UPDATES_WARNING; import static de.cotto.lndmanagej.model.warnings.ChannelWarningsFixtures.CHANNEL_WARNINGS; import static de.cotto.lndmanagej.model.warnings.NodeWarningsFixtures.NODE_WARNINGS; -import static de.cotto.lndmanagej.ui.dto.warning.ChannelWarningDtoFixture.CHANNEL_WARNING_DTO; import static de.cotto.lndmanagej.ui.dto.warning.ChannelWarningDtoFixture.CHANNEL_WARNING_DTO_2; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.lenient; @@ -78,15 +75,14 @@ void getWarnings_only_node_warnings() { @Test void getWarnings_only_channel_warnings() { when(channelWarningsService.getChannelWarnings()).thenReturn(Map.of( - LOCAL_OPEN_CHANNEL, new ChannelWarnings(CHANNEL_NUM_UPDATES_WARNING), - LOCAL_OPEN_CHANNEL_2, new ChannelWarnings(CHANNEL_BALANCE_FLUCTUATION_WARNING)) + LOCAL_OPEN_CHANNEL, new ChannelWarnings(CHANNEL_BALANCE_FLUCTUATION_WARNING)) ); assertThat(warningService.getWarnings()).containsExactly(new DashboardWarningDto( ALIAS_FOR_PUBKEY_2, PUBKEY_2, Set.of(), - Set.of(CHANNEL_WARNING_DTO, CHANNEL_WARNING_DTO_2) + Set.of(CHANNEL_WARNING_DTO_2) )); } @@ -105,7 +101,7 @@ void getWarnings_node_and_channel_warnings_combined() { ALIAS_FOR_PUBKEY_2, PUBKEY_2, THREE_NODE_WARNINGS, - Set.of(CHANNEL_WARNING_DTO) + Set.of(CHANNEL_WARNING_DTO_2) ); assertThat(warningService.getWarnings()).containsExactlyInAnyOrder(nodeWarning, anotherNodeWarning); } diff --git a/ui/src/test/java/de/cotto/lndmanagej/ui/dto/warning/ChannelWarningDtoTest.java b/ui/src/test/java/de/cotto/lndmanagej/ui/dto/warning/ChannelWarningDtoTest.java index 272ab890..37b964ab 100644 --- a/ui/src/test/java/de/cotto/lndmanagej/ui/dto/warning/ChannelWarningDtoTest.java +++ b/ui/src/test/java/de/cotto/lndmanagej/ui/dto/warning/ChannelWarningDtoTest.java @@ -2,7 +2,7 @@ import org.junit.jupiter.api.Test; -import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID; +import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID_2; import static de.cotto.lndmanagej.ui.dto.warning.ChannelWarningDtoFixture.CHANNEL_WARNING_DTO; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; @@ -10,11 +10,12 @@ class ChannelWarningDtoTest { @Test void channelId() { - assertThat(CHANNEL_WARNING_DTO.channelId()).isEqualTo(CHANNEL_ID); + assertThat(CHANNEL_WARNING_DTO.channelId()).isEqualTo(CHANNEL_ID_2); } @Test void description() { - assertThat(CHANNEL_WARNING_DTO.description()).isEqualTo("Channel has accumulated 101,000 updates"); + assertThat(CHANNEL_WARNING_DTO.description()) + .isEqualTo("Channel balance ranged from 1% to 99% in the past 14 days"); } -} \ No newline at end of file +} diff --git a/ui/src/testFixtures/java/de/cotto/lndmanagej/ui/dto/warning/ChannelWarningDtoFixture.java b/ui/src/testFixtures/java/de/cotto/lndmanagej/ui/dto/warning/ChannelWarningDtoFixture.java index f2a09c28..3b01f531 100644 --- a/ui/src/testFixtures/java/de/cotto/lndmanagej/ui/dto/warning/ChannelWarningDtoFixture.java +++ b/ui/src/testFixtures/java/de/cotto/lndmanagej/ui/dto/warning/ChannelWarningDtoFixture.java @@ -5,8 +5,8 @@ public class ChannelWarningDtoFixture { public static final ChannelWarningDto CHANNEL_WARNING_DTO = - new ChannelWarningDto(CHANNEL_ID, "Channel has accumulated 101,000 updates"); + new ChannelWarningDto(CHANNEL_ID_2, "Channel balance ranged from 1% to 99% in the past 14 days"); public static final ChannelWarningDto CHANNEL_WARNING_DTO_2 = - new ChannelWarningDto(CHANNEL_ID_2, "Channel balance ranged from 2% to 97% in the past 7 days"); + new ChannelWarningDto(CHANNEL_ID, "Channel balance ranged from 2% to 97% in the past 7 days"); } diff --git a/web/src/integrationTest/java/de/cotto/lndmanagej/controller/ChannelControllerIT.java b/web/src/integrationTest/java/de/cotto/lndmanagej/controller/ChannelControllerIT.java index b336811b..b476d761 100644 --- a/web/src/integrationTest/java/de/cotto/lndmanagej/controller/ChannelControllerIT.java +++ b/web/src/integrationTest/java/de/cotto/lndmanagej/controller/ChannelControllerIT.java @@ -41,7 +41,7 @@ import static de.cotto.lndmanagej.model.NodeFixtures.ALIAS_2; import static de.cotto.lndmanagej.model.PolicyFixtures.POLICIES_FOR_LOCAL_CHANNEL; import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY_2; -import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.contains; import static org.hamcrest.core.Is.is; import static org.mockito.Mockito.when; @@ -196,9 +196,7 @@ void getChannelDetails() { .jsonPath("$.flowReport.totalReceivedMilliSat").value(is("63021")) .jsonPath("$.rating.rating").value(is(123)) .jsonPath("$.rating.message").value(is("")) - .jsonPath("$.warnings").value(containsInAnyOrder( - "Channel has accumulated 101,000 updates" - )); + .jsonPath("$.warnings").value(contains("Channel balance ranged from 2% to 97% in the past 7 days")); } @Test diff --git a/web/src/integrationTest/java/de/cotto/lndmanagej/controller/WarningsControllerIT.java b/web/src/integrationTest/java/de/cotto/lndmanagej/controller/WarningsControllerIT.java index 2830645d..bac7e573 100644 --- a/web/src/integrationTest/java/de/cotto/lndmanagej/controller/WarningsControllerIT.java +++ b/web/src/integrationTest/java/de/cotto/lndmanagej/controller/WarningsControllerIT.java @@ -27,6 +27,7 @@ import static de.cotto.lndmanagej.model.warnings.ChannelWarningsFixtures.CHANNEL_WARNINGS; import static de.cotto.lndmanagej.model.warnings.NodeWarningsFixtures.NODE_WARNINGS; import static de.cotto.lndmanagej.model.warnings.NodeWarningsFixtures.NODE_WARNINGS_2; +import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.is; @@ -75,8 +76,8 @@ void getWarningsForNode_empty() { void getWarningsForChannel() { when(channelWarningsService.getChannelWarnings(CHANNEL_ID)).thenReturn(CHANNEL_WARNINGS); webTestClient.get().uri(CHANNEL_PREFIX + WARNINGS).exchange().expectBody() - .jsonPath(WARNINGS_PATH).value(containsInAnyOrder( - "Channel has accumulated 101,000 updates" + .jsonPath(WARNINGS_PATH).value(contains( + "Channel balance ranged from 2% to 97% in the past 7 days" )); } @@ -116,8 +117,8 @@ void getWarnings() { "Node changed between online and offline 99 times in the past 14 days" )) .jsonPath("$.channelsWithWarnings[0].channelId").value(is(CHANNEL_ID.toString())) - .jsonPath("$.channelsWithWarnings[0].warnings").value(containsInAnyOrder( - "Channel has accumulated 101,000 updates" + .jsonPath("$.channelsWithWarnings[0].warnings").value(contains( + "Channel balance ranged from 2% to 97% in the past 7 days" )); } } diff --git a/web/src/test/java/de/cotto/lndmanagej/controller/dto/WarningsDtoTest.java b/web/src/test/java/de/cotto/lndmanagej/controller/dto/WarningsDtoTest.java index 2d7515f7..b9bf7cf6 100644 --- a/web/src/test/java/de/cotto/lndmanagej/controller/dto/WarningsDtoTest.java +++ b/web/src/test/java/de/cotto/lndmanagej/controller/dto/WarningsDtoTest.java @@ -15,7 +15,7 @@ void createFromModels() { "No flow in the past 16 days", "Node has been online 51% in the past 14 days", "Node changed between online and offline 123 times in the past 7 days", - "Channel has accumulated 101,000 updates" + "Channel balance ranged from 2% to 97% in the past 7 days" ))); } @@ -31,7 +31,7 @@ void createFromModel_node() { @Test void createFromModel_channel() { assertThat(WarningsDto.createFromModel(CHANNEL_WARNINGS)).isEqualTo(new WarningsDto(Set.of( - "Channel has accumulated 101,000 updates" + "Channel balance ranged from 2% to 97% in the past 7 days" ))); } -} \ No newline at end of file +}