From e42a106a35dbc97d6ef867dc25492d5ca994c762 Mon Sep 17 00:00:00 2001 From: Carsten Otto Date: Tue, 30 Nov 2021 13:49:38 +0100 Subject: [PATCH] add fee report model --- .../cotto/lndmanagej/service/FeeService.java | 30 ++++++--- .../lndmanagej/service/FeeServiceTest.java | 62 +++++++------------ .../de/cotto/lndmanagej/model/FeeReport.java | 4 ++ .../cotto/lndmanagej/model/FeeReportTest.java | 20 ++++++ .../controller/ChannelControllerIT.java | 11 ++-- .../controller/NodeControllerIT.java | 8 +-- .../controller/ChannelController.java | 4 +- .../lndmanagej/controller/NodeController.java | 2 +- .../controller/dto/FeeReportDto.java | 5 ++ .../controller/ChannelControllerTest.java | 11 ++-- .../controller/NodeControllerTest.java | 12 ++-- .../controller/dto/FeeReportDtoTest.java | 7 +++ 12 files changed, 102 insertions(+), 74 deletions(-) create mode 100644 model/src/main/java/de/cotto/lndmanagej/model/FeeReport.java create mode 100644 model/src/test/java/de/cotto/lndmanagej/model/FeeReportTest.java diff --git a/backend/src/main/java/de/cotto/lndmanagej/service/FeeService.java b/backend/src/main/java/de/cotto/lndmanagej/service/FeeService.java index d2332b0f..3e1d77e9 100644 --- a/backend/src/main/java/de/cotto/lndmanagej/service/FeeService.java +++ b/backend/src/main/java/de/cotto/lndmanagej/service/FeeService.java @@ -3,6 +3,7 @@ package de.cotto.lndmanagej.service; import de.cotto.lndmanagej.model.Channel; import de.cotto.lndmanagej.model.ChannelId; import de.cotto.lndmanagej.model.Coins; +import de.cotto.lndmanagej.model.FeeReport; import de.cotto.lndmanagej.model.ForwardingEvent; import de.cotto.lndmanagej.model.Pubkey; import de.cotto.lndmanagej.statistics.ForwardingEventsDao; @@ -18,29 +19,38 @@ public class FeeService { this.channelService = channelService; } - public Coins getEarnedFeesForChannel(ChannelId channelId) { - return forwardingEventsDao.getEventsWithOutgoingChannel(channelId).parallelStream() - .map(ForwardingEvent::fees) - .reduce(Coins.NONE, Coins::add); + public FeeReport getFeeReportForPeer(Pubkey pubkey) { + return new FeeReport(getEarnedFeesForPeer(pubkey), getSourcedFeesForPeer(pubkey)); } - public Coins getSourcedFeesForChannel(ChannelId channelId) { - return forwardingEventsDao.getEventsWithIncomingChannel(channelId).parallelStream() - .map(ForwardingEvent::fees) - .reduce(Coins.NONE, Coins::add); + public FeeReport getFeeReportForChannel(ChannelId channelId) { + return new FeeReport(getEarnedFeesForChannel(channelId), getSourcedFeesForChannel(channelId)); } - public Coins getEarnedFeesForPeer(Pubkey peer) { + private Coins getEarnedFeesForPeer(Pubkey peer) { return channelService.getAllChannelsWith(peer).parallelStream() .map(Channel::getId) .map(this::getEarnedFeesForChannel) .reduce(Coins.NONE, Coins::add); } - public Coins getSourcedFeesForPeer(Pubkey peer) { + private Coins getSourcedFeesForPeer(Pubkey peer) { return channelService.getAllChannelsWith(peer).parallelStream() .map(Channel::getId) .map(this::getSourcedFeesForChannel) .reduce(Coins.NONE, Coins::add); } + + private Coins getEarnedFeesForChannel(ChannelId channelId) { + return forwardingEventsDao.getEventsWithOutgoingChannel(channelId).parallelStream() + .map(ForwardingEvent::fees) + .reduce(Coins.NONE, Coins::add); + } + + private Coins getSourcedFeesForChannel(ChannelId channelId) { + return forwardingEventsDao.getEventsWithIncomingChannel(channelId).parallelStream() + .map(ForwardingEvent::fees) + .reduce(Coins.NONE, Coins::add); + } + } diff --git a/backend/src/test/java/de/cotto/lndmanagej/service/FeeServiceTest.java b/backend/src/test/java/de/cotto/lndmanagej/service/FeeServiceTest.java index f4f62018..3ffda375 100644 --- a/backend/src/test/java/de/cotto/lndmanagej/service/FeeServiceTest.java +++ b/backend/src/test/java/de/cotto/lndmanagej/service/FeeServiceTest.java @@ -1,6 +1,7 @@ package de.cotto.lndmanagej.service; import de.cotto.lndmanagej.model.Coins; +import de.cotto.lndmanagej.model.FeeReport; import de.cotto.lndmanagej.statistics.ForwardingEventsDao; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -34,54 +35,39 @@ class FeeServiceTest { private ChannelService channelService; @Test - void getEarnedFeesForChannel() { + void getFeeReportForChannel() { when(dao.getEventsWithOutgoingChannel(CHANNEL_ID)).thenReturn(List.of(FORWARDING_EVENT, FORWARDING_EVENT_2)); - assertThat(feeService.getEarnedFeesForChannel(CHANNEL_ID)).isEqualTo(Coins.ofMilliSatoshis(101)); + when(dao.getEventsWithIncomingChannel(CHANNEL_ID)).thenReturn(List.of(FORWARDING_EVENT_2, FORWARDING_EVENT_3)); + assertThat(feeService.getFeeReportForChannel(CHANNEL_ID)) + .isEqualTo(new FeeReport(Coins.ofMilliSatoshis(101), Coins.ofMilliSatoshis(5_001))); } @Test - void getEarnedFeesForChannel_no_forward() { - assertThat(feeService.getEarnedFeesForChannel(CHANNEL_ID)).isEqualTo(Coins.NONE); + void getFeeReportForChannel_no_forward() { + when(dao.getEventsWithOutgoingChannel(CHANNEL_ID)).thenReturn(List.of()); + when(dao.getEventsWithIncomingChannel(CHANNEL_ID)).thenReturn(List.of()); + assertThat(feeService.getFeeReportForChannel(CHANNEL_ID)).isEqualTo(new FeeReport(Coins.NONE, Coins.NONE)); } @Test - void getEarnedFeesForPeer_no_channel() { - assertThat(feeService.getEarnedFeesForPeer(PUBKEY)).isEqualTo(Coins.NONE); - } + void getFeeReportForPeer() { + when(dao.getEventsWithOutgoingChannel(CLOSED_CHANNEL.getId())).thenReturn(List.of(FORWARDING_EVENT)); + when(dao.getEventsWithOutgoingChannel(WAITING_CLOSE_CHANNEL_2.getId())).thenReturn(List.of()); + when(dao.getEventsWithOutgoingChannel(LOCAL_OPEN_CHANNEL_3.getId())).thenReturn(List.of(FORWARDING_EVENT_3)); - @Test - void getSourcedFeesForChannel() { - when(dao.getEventsWithIncomingChannel(CHANNEL_ID)).thenReturn(List.of(FORWARDING_EVENT, FORWARDING_EVENT_2)); - assertThat(feeService.getSourcedFeesForChannel(CHANNEL_ID)).isEqualTo(Coins.ofMilliSatoshis(101)); - } - - @Test - void getSourcedFeesForChannel_no_forward() { - assertThat(feeService.getSourcedFeesForChannel(CHANNEL_ID)).isEqualTo(Coins.NONE); - } - - @Test - void getSourcedFeesForPeer_no_channel() { - assertThat(feeService.getSourcedFeesForPeer(PUBKEY)).isEqualTo(Coins.NONE); - } - - @Test - void getEarnedFeesForPeer() { - when(dao.getEventsWithOutgoingChannel(CLOSED_CHANNEL.getId())).thenReturn(List.of(FORWARDING_EVENT_3)); - when(dao.getEventsWithOutgoingChannel(WAITING_CLOSE_CHANNEL_2.getId())).thenReturn(List.of(FORWARDING_EVENT)); - when(dao.getEventsWithOutgoingChannel(LOCAL_OPEN_CHANNEL_3.getId())).thenReturn(List.of(FORWARDING_EVENT_2)); - when(channelService.getAllChannelsWith(PUBKEY)) - .thenReturn(Set.of(CLOSED_CHANNEL, WAITING_CLOSE_CHANNEL_2, LOCAL_OPEN_CHANNEL_3)); - assertThat(feeService.getEarnedFeesForPeer(PUBKEY)).isEqualTo(Coins.ofMilliSatoshis(5_101)); - } - - @Test - void getSourcedFeesForPeer() { when(dao.getEventsWithIncomingChannel(CLOSED_CHANNEL.getId())).thenReturn(List.of(FORWARDING_EVENT_3)); - when(dao.getEventsWithIncomingChannel(WAITING_CLOSE_CHANNEL_2.getId())).thenReturn(List.of(FORWARDING_EVENT)); - when(dao.getEventsWithIncomingChannel(LOCAL_OPEN_CHANNEL_3.getId())).thenReturn(List.of(FORWARDING_EVENT_2)); + when(dao.getEventsWithIncomingChannel(WAITING_CLOSE_CHANNEL_2.getId())).thenReturn(List.of(FORWARDING_EVENT_2)); + when(dao.getEventsWithIncomingChannel(LOCAL_OPEN_CHANNEL_3.getId())).thenReturn(List.of()); + when(channelService.getAllChannelsWith(PUBKEY)) .thenReturn(Set.of(CLOSED_CHANNEL, WAITING_CLOSE_CHANNEL_2, LOCAL_OPEN_CHANNEL_3)); - assertThat(feeService.getSourcedFeesForPeer(PUBKEY)).isEqualTo(Coins.ofMilliSatoshis(5_101)); + + assertThat(feeService.getFeeReportForPeer(PUBKEY)) + .isEqualTo(new FeeReport(Coins.ofMilliSatoshis(5_100), Coins.ofMilliSatoshis(5_001))); + } + + @Test + void getFeeReportForPeer_no_channel() { + assertThat(feeService.getFeeReportForPeer(PUBKEY)).isEqualTo(new FeeReport(Coins.NONE, Coins.NONE)); } } \ No newline at end of file diff --git a/model/src/main/java/de/cotto/lndmanagej/model/FeeReport.java b/model/src/main/java/de/cotto/lndmanagej/model/FeeReport.java new file mode 100644 index 00000000..79d351b3 --- /dev/null +++ b/model/src/main/java/de/cotto/lndmanagej/model/FeeReport.java @@ -0,0 +1,4 @@ +package de.cotto.lndmanagej.model; + +public record FeeReport(Coins earned, Coins sourced) { +} diff --git a/model/src/test/java/de/cotto/lndmanagej/model/FeeReportTest.java b/model/src/test/java/de/cotto/lndmanagej/model/FeeReportTest.java new file mode 100644 index 00000000..94920526 --- /dev/null +++ b/model/src/test/java/de/cotto/lndmanagej/model/FeeReportTest.java @@ -0,0 +1,20 @@ +package de.cotto.lndmanagej.model; + +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +class FeeReportTest { + + private static final FeeReport FEE_REPORT = new FeeReport(Coins.ofMilliSatoshis(1_234), Coins.ofMilliSatoshis(567)); + + @Test + void earned() { + assertThat(FEE_REPORT.earned()).isEqualTo(Coins.ofMilliSatoshis(1_234)); + } + + @Test + void sourced() { + assertThat(FEE_REPORT.sourced()).isEqualTo(Coins.ofMilliSatoshis(567)); + } +} \ No newline at end of file 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 8c8f8485..48ccaebc 100644 --- a/web/src/integrationTest/java/de/cotto/lndmanagej/controller/ChannelControllerIT.java +++ b/web/src/integrationTest/java/de/cotto/lndmanagej/controller/ChannelControllerIT.java @@ -3,6 +3,7 @@ package de.cotto.lndmanagej.controller; import de.cotto.lndmanagej.metrics.Metrics; import de.cotto.lndmanagej.model.ChannelIdResolver; import de.cotto.lndmanagej.model.Coins; +import de.cotto.lndmanagej.model.FeeReport; import de.cotto.lndmanagej.service.BalanceService; import de.cotto.lndmanagej.service.ChannelService; import de.cotto.lndmanagej.service.FeeService; @@ -44,6 +45,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. class ChannelControllerIT { private static final String CHANNEL_PREFIX = "/api/channel/" + CHANNEL_ID.getShortChannelId(); private static final String DETAILS_PREFIX = CHANNEL_PREFIX + "/details"; + private static final FeeReport FEE_REPORT = new FeeReport(Coins.ofMilliSatoshis(1_234), Coins.ofMilliSatoshis(567)); @Autowired private MockMvc mockMvc; @@ -126,8 +128,7 @@ class ChannelControllerIT { when(onChainCostService.getOpenCosts(CHANNEL_ID)).thenReturn(Optional.of(Coins.ofSatoshis(1000))); when(onChainCostService.getCloseCosts(CHANNEL_ID)).thenReturn(Optional.of(Coins.ofSatoshis(2000))); when(balanceService.getBalanceInformation(CHANNEL_ID)).thenReturn(Optional.of(BALANCE_INFORMATION_2)); - when(feeService.getEarnedFeesForChannel(CHANNEL_ID)).thenReturn(Coins.ofMilliSatoshis(1_234)); - when(feeService.getSourcedFeesForChannel(CHANNEL_ID)).thenReturn(Coins.ofMilliSatoshis(567)); + when(feeService.getFeeReportForChannel(CHANNEL_ID)).thenReturn(FEE_REPORT); mockMvc.perform(get(DETAILS_PREFIX)) .andExpect(jsonPath("$.channelIdShort", is(String.valueOf(CHANNEL_ID.getShortChannelId())))) .andExpect(jsonPath("$.channelIdCompact", is(CHANNEL_ID.getCompactForm()))) @@ -165,8 +166,7 @@ class ChannelControllerIT { @Test void getChannelDetails_closed_channel() throws Exception { when(channelService.getLocalChannel(CHANNEL_ID)).thenReturn(Optional.of(CLOSED_CHANNEL)); - when(feeService.getEarnedFeesForChannel(CHANNEL_ID)).thenReturn(Coins.NONE); - when(feeService.getSourcedFeesForChannel(CHANNEL_ID)).thenReturn(Coins.NONE); + when(feeService.getFeeReportForChannel(CHANNEL_ID)).thenReturn(new FeeReport(Coins.NONE, Coins.NONE)); mockMvc.perform(get(DETAILS_PREFIX)) .andExpect(jsonPath("$.closeDetails.initiator", is("REMOTE"))) .andExpect(jsonPath("$.closeDetails.height", is(987_654))) @@ -227,8 +227,7 @@ class ChannelControllerIT { @Test void getFeeReport() throws Exception { - when(feeService.getEarnedFeesForChannel(CHANNEL_ID)).thenReturn(Coins.ofMilliSatoshis(1_234)); - when(feeService.getSourcedFeesForChannel(CHANNEL_ID)).thenReturn(Coins.ofMilliSatoshis(567)); + when(feeService.getFeeReportForChannel(CHANNEL_ID)).thenReturn(FEE_REPORT); mockMvc.perform(get(CHANNEL_PREFIX + "/fee-report")) .andExpect(jsonPath("$.earned", is("1234"))) .andExpect(jsonPath("$.sourced", is("567"))); diff --git a/web/src/integrationTest/java/de/cotto/lndmanagej/controller/NodeControllerIT.java b/web/src/integrationTest/java/de/cotto/lndmanagej/controller/NodeControllerIT.java index 2d513277..308ceeff 100644 --- a/web/src/integrationTest/java/de/cotto/lndmanagej/controller/NodeControllerIT.java +++ b/web/src/integrationTest/java/de/cotto/lndmanagej/controller/NodeControllerIT.java @@ -3,6 +3,7 @@ package de.cotto.lndmanagej.controller; import de.cotto.lndmanagej.metrics.Metrics; import de.cotto.lndmanagej.model.ChannelIdResolver; import de.cotto.lndmanagej.model.Coins; +import de.cotto.lndmanagej.model.FeeReport; import de.cotto.lndmanagej.model.Node; import de.cotto.lndmanagej.service.BalanceService; import de.cotto.lndmanagej.service.ChannelService; @@ -40,6 +41,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. @WebMvcTest(controllers = NodeController.class) class NodeControllerIT { private static final String NODE_PREFIX = "/api/node/" + PUBKEY_2; + private static final FeeReport FEE_REPORT = new FeeReport(Coins.ofMilliSatoshis(1_234), Coins.ofMilliSatoshis(567)); @Autowired private MockMvc mockMvc; @@ -84,8 +86,7 @@ class NodeControllerIT { when(onChainCostService.getOpenCostsWith(PUBKEY_2)).thenReturn(Coins.ofSatoshis(123)); when(onChainCostService.getCloseCostsWith(PUBKEY_2)).thenReturn(Coins.ofSatoshis(456)); when(balanceService.getBalanceInformation(PUBKEY_2)).thenReturn(BALANCE_INFORMATION); - when(feeService.getEarnedFeesForPeer(PUBKEY_2)).thenReturn(Coins.ofMilliSatoshis(1_234)); - when(feeService.getSourcedFeesForPeer(PUBKEY_2)).thenReturn(Coins.ofMilliSatoshis(567)); + when(feeService.getFeeReportForPeer(PUBKEY_2)).thenReturn(FEE_REPORT); List channelIds = List.of(CHANNEL_ID.toString(), CHANNEL_ID_2.toString()); List closedChannelIds = List.of(CHANNEL_ID.toString(), CHANNEL_ID_3.toString()); List waitingCloseChannelIds = List.of(CHANNEL_ID.toString()); @@ -142,8 +143,7 @@ class NodeControllerIT { @Test void getFeeReport() throws Exception { - when(feeService.getEarnedFeesForPeer(PUBKEY_2)).thenReturn(Coins.ofMilliSatoshis(1_234)); - when(feeService.getSourcedFeesForPeer(PUBKEY_2)).thenReturn(Coins.ofMilliSatoshis(567)); + when(feeService.getFeeReportForPeer(PUBKEY_2)).thenReturn(FEE_REPORT); mockMvc.perform(get(NODE_PREFIX + "/fee-report")) .andExpect(jsonPath("$.earned", is("1234"))) .andExpect(jsonPath("$.sourced", is("567"))); diff --git a/web/src/main/java/de/cotto/lndmanagej/controller/ChannelController.java b/web/src/main/java/de/cotto/lndmanagej/controller/ChannelController.java index f96abba4..1c605c9a 100644 --- a/web/src/main/java/de/cotto/lndmanagej/controller/ChannelController.java +++ b/web/src/main/java/de/cotto/lndmanagej/controller/ChannelController.java @@ -126,9 +126,7 @@ public class ChannelController { } private FeeReportDto getFeeReportDto(ChannelId channelId) { - Coins earned = feeService.getEarnedFeesForChannel(channelId); - Coins sourced = feeService.getSourcedFeesForChannel(channelId); - return new FeeReportDto(earned, sourced); + return FeeReportDto.createFrom(feeService.getFeeReportForChannel(channelId)); } private PoliciesDto getPoliciesForChannel(@Nullable LocalChannel channel) { diff --git a/web/src/main/java/de/cotto/lndmanagej/controller/NodeController.java b/web/src/main/java/de/cotto/lndmanagej/controller/NodeController.java index bfd1e2fd..d5e721ed 100644 --- a/web/src/main/java/de/cotto/lndmanagej/controller/NodeController.java +++ b/web/src/main/java/de/cotto/lndmanagej/controller/NodeController.java @@ -110,7 +110,7 @@ public class NodeController { } private FeeReportDto getFeeReportDto(Pubkey pubkey) { - return new FeeReportDto(feeService.getEarnedFeesForPeer(pubkey), feeService.getSourcedFeesForPeer(pubkey)); + return FeeReportDto.createFrom(feeService.getFeeReportForPeer(pubkey)); } private List toSortedList(Set channels) { diff --git a/web/src/main/java/de/cotto/lndmanagej/controller/dto/FeeReportDto.java b/web/src/main/java/de/cotto/lndmanagej/controller/dto/FeeReportDto.java index 11feb446..7347b915 100644 --- a/web/src/main/java/de/cotto/lndmanagej/controller/dto/FeeReportDto.java +++ b/web/src/main/java/de/cotto/lndmanagej/controller/dto/FeeReportDto.java @@ -1,6 +1,7 @@ package de.cotto.lndmanagej.controller.dto; import de.cotto.lndmanagej.model.Coins; +import de.cotto.lndmanagej.model.FeeReport; public record FeeReportDto(String earned, String sourced) { public FeeReportDto(Coins earned, Coins sourced) { @@ -9,4 +10,8 @@ public record FeeReportDto(String earned, String sourced) { String.valueOf(sourced.milliSatoshis()) ); } + + public static FeeReportDto createFrom(FeeReport feeReport) { + return new FeeReportDto(feeReport.earned(), feeReport.sourced()); + } } diff --git a/web/src/test/java/de/cotto/lndmanagej/controller/ChannelControllerTest.java b/web/src/test/java/de/cotto/lndmanagej/controller/ChannelControllerTest.java index 00ecf25d..86c8f32d 100644 --- a/web/src/test/java/de/cotto/lndmanagej/controller/ChannelControllerTest.java +++ b/web/src/test/java/de/cotto/lndmanagej/controller/ChannelControllerTest.java @@ -11,6 +11,7 @@ import de.cotto.lndmanagej.metrics.Metrics; import de.cotto.lndmanagej.model.BalanceInformation; import de.cotto.lndmanagej.model.CloseInitiator; import de.cotto.lndmanagej.model.Coins; +import de.cotto.lndmanagej.model.FeeReport; import de.cotto.lndmanagej.model.LocalChannel; import de.cotto.lndmanagej.service.BalanceService; import de.cotto.lndmanagej.service.ChannelService; @@ -49,10 +50,10 @@ class ChannelControllerTest { private static final Coins CLOSE_COSTS = Coins.ofSatoshis(2); private static final OnChainCostsDto ON_CHAIN_COSTS = new OnChainCostsDto(OPEN_COSTS, CLOSE_COSTS); private static final PoliciesDto FEE_CONFIGURATION_DTO = PoliciesDto.createFrom(POLICIES); - private static final FeeReportDto FEE_REPORT_DTO = - new FeeReportDto(Coins.ofMilliSatoshis(1234), Coins.ofMilliSatoshis(567)); private static final ClosedChannelDetailsDto CLOSED_CHANNEL_DETAILS_DTO = new ClosedChannelDetailsDto(CloseInitiator.REMOTE, 987_654); + private static final FeeReport FEE_REPORT = new FeeReport(Coins.ofMilliSatoshis(1_234), Coins.ofMilliSatoshis(567)); + private static final FeeReportDto FEE_REPORT_DTO = FeeReportDto.createFrom(FEE_REPORT); @InjectMocks private ChannelController channelController; @@ -83,8 +84,7 @@ class ChannelControllerTest { lenient().when(onChainCostService.getOpenCosts(CHANNEL_ID)).thenReturn(Optional.of(OPEN_COSTS)); lenient().when(onChainCostService.getCloseCosts(CHANNEL_ID)).thenReturn(Optional.of(CLOSE_COSTS)); lenient().when(policyService.getPolicies(CHANNEL_ID)).thenReturn(POLICIES); - lenient().when(feeService.getEarnedFeesForChannel(CHANNEL_ID)).thenReturn(Coins.ofMilliSatoshis(1_234)); - lenient().when(feeService.getSourcedFeesForChannel(CHANNEL_ID)).thenReturn(Coins.ofMilliSatoshis(567)); + lenient().when(feeService.getFeeReportForChannel(CHANNEL_ID)).thenReturn(FEE_REPORT); } @Test @@ -214,8 +214,7 @@ class ChannelControllerTest { @Test void getFeeReport() { - when(feeService.getEarnedFeesForChannel(CHANNEL_ID)).thenReturn(Coins.ofMilliSatoshis(1_234)); - when(feeService.getSourcedFeesForChannel(CHANNEL_ID)).thenReturn(Coins.ofMilliSatoshis(567)); + when(feeService.getFeeReportForChannel(CHANNEL_ID)).thenReturn(FEE_REPORT); assertThat(channelController.getFeeReport(CHANNEL_ID)).isEqualTo(FEE_REPORT_DTO); verify(metrics).mark(argThat(name -> name.endsWith(".getFeeReport"))); } diff --git a/web/src/test/java/de/cotto/lndmanagej/controller/NodeControllerTest.java b/web/src/test/java/de/cotto/lndmanagej/controller/NodeControllerTest.java index 654d7005..a006fe8a 100644 --- a/web/src/test/java/de/cotto/lndmanagej/controller/NodeControllerTest.java +++ b/web/src/test/java/de/cotto/lndmanagej/controller/NodeControllerTest.java @@ -8,6 +8,7 @@ import de.cotto.lndmanagej.controller.dto.OnChainCostsDto; import de.cotto.lndmanagej.metrics.Metrics; import de.cotto.lndmanagej.model.BalanceInformation; import de.cotto.lndmanagej.model.Coins; +import de.cotto.lndmanagej.model.FeeReport; import de.cotto.lndmanagej.model.Node; import de.cotto.lndmanagej.model.Pubkey; import de.cotto.lndmanagej.service.BalanceService; @@ -49,6 +50,8 @@ import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) class NodeControllerTest { + private static final FeeReport FEE_REPORT = new FeeReport(Coins.ofMilliSatoshis(1_234), Coins.ofMilliSatoshis(567)); + @InjectMocks private NodeController nodeController; @@ -83,8 +86,7 @@ class NodeControllerTest { when(onChainCostService.getOpenCostsWith(any())).thenReturn(Coins.NONE); when(onChainCostService.getCloseCostsWith(any())).thenReturn(Coins.NONE); when(balanceService.getBalanceInformation(any(Pubkey.class))).thenReturn(BalanceInformation.EMPTY); - when(feeService.getEarnedFeesForPeer(any())).thenReturn(Coins.NONE); - when(feeService.getSourcedFeesForPeer(any())).thenReturn(Coins.NONE); + when(feeService.getFeeReportForPeer(any())).thenReturn(new FeeReport(Coins.NONE, Coins.NONE)); NodeDetailsDto expectedDetails = new NodeDetailsDto( PUBKEY_2, ALIAS_2, @@ -119,8 +121,7 @@ class NodeControllerTest { when(onChainCostService.getOpenCostsWith(PUBKEY_2)).thenReturn(openCosts); when(onChainCostService.getCloseCostsWith(PUBKEY_2)).thenReturn(closeCosts); when(balanceService.getBalanceInformation(PUBKEY_2)).thenReturn(BALANCE_INFORMATION); - when(feeService.getEarnedFeesForPeer(any())).thenReturn(Coins.ofMilliSatoshis(1234)); - when(feeService.getSourcedFeesForPeer(any())).thenReturn(Coins.ofMilliSatoshis(567)); + when(feeService.getFeeReportForPeer(PUBKEY_2)).thenReturn(FEE_REPORT); NodeDetailsDto expectedDetails = new NodeDetailsDto( PUBKEY_2, ALIAS_2, @@ -176,8 +177,7 @@ class NodeControllerTest { @Test void getFeeReport() { - when(feeService.getEarnedFeesForPeer(PUBKEY)).thenReturn(Coins.ofMilliSatoshis(1_234)); - when(feeService.getSourcedFeesForPeer(PUBKEY)).thenReturn(Coins.ofMilliSatoshis(567)); + when(feeService.getFeeReportForPeer(PUBKEY)).thenReturn(FEE_REPORT); assertThat(nodeController.getFeeReport(PUBKEY)).isEqualTo(new FeeReportDto("1234", "567")); verify(metrics).mark(argThat(name -> name.endsWith(".getFeeReport"))); } diff --git a/web/src/test/java/de/cotto/lndmanagej/controller/dto/FeeReportDtoTest.java b/web/src/test/java/de/cotto/lndmanagej/controller/dto/FeeReportDtoTest.java index 12e2a4e5..a2a8646c 100644 --- a/web/src/test/java/de/cotto/lndmanagej/controller/dto/FeeReportDtoTest.java +++ b/web/src/test/java/de/cotto/lndmanagej/controller/dto/FeeReportDtoTest.java @@ -1,6 +1,7 @@ package de.cotto.lndmanagej.controller.dto; import de.cotto.lndmanagej.model.Coins; +import de.cotto.lndmanagej.model.FeeReport; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -19,4 +20,10 @@ class FeeReportDtoTest { void sourced() { assertThat(FEE_REPORT_DTO.sourced()).isEqualTo("567"); } + + @Test + void createFrom() { + assertThat(FeeReportDto.createFrom(new FeeReport(Coins.ofSatoshis(1), Coins.ofSatoshis(2)))) + .isEqualTo(new FeeReportDto("1000", "2000")); + } } \ No newline at end of file