compute channel details in service

lots of refactoring, changes API
This commit is contained in:
Carsten Otto
2021-12-17 10:31:59 +01:00
parent 690960afc4
commit 71d12e52bb
40 changed files with 797 additions and 730 deletions

View File

@@ -9,16 +9,12 @@ import de.cotto.lndmanagej.controller.dto.PoliciesDto;
import de.cotto.lndmanagej.model.BalanceInformation;
import de.cotto.lndmanagej.model.Coins;
import de.cotto.lndmanagej.model.FeeReport;
import de.cotto.lndmanagej.model.LocalChannel;
import de.cotto.lndmanagej.model.Policies;
import de.cotto.lndmanagej.service.BalanceService;
import de.cotto.lndmanagej.service.ChannelDetailsService;
import de.cotto.lndmanagej.service.ChannelService;
import de.cotto.lndmanagej.service.FeeService;
import de.cotto.lndmanagej.service.NodeService;
import de.cotto.lndmanagej.service.OffChainCostService;
import de.cotto.lndmanagej.service.OnChainCostService;
import de.cotto.lndmanagej.service.PolicyService;
import de.cotto.lndmanagej.service.RebalanceService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
@@ -28,24 +24,19 @@ import org.mockito.junit.jupiter.MockitoExtension;
import java.util.Optional;
import static de.cotto.lndmanagej.model.BalanceInformationFixtures.BALANCE_INFORMATION;
import static de.cotto.lndmanagej.model.ChannelDetailsFixtures.CHANNEL_DETAILS;
import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID;
import static de.cotto.lndmanagej.model.CoopClosedChannelFixtures.CLOSED_CHANNEL;
import static de.cotto.lndmanagej.model.LocalOpenChannelFixtures.LOCAL_OPEN_CHANNEL;
import static de.cotto.lndmanagej.model.LocalOpenChannelFixtures.LOCAL_OPEN_CHANNEL_PRIVATE;
import static de.cotto.lndmanagej.model.NodeFixtures.ALIAS_2;
import static de.cotto.lndmanagej.model.OffChainCostsFixtures.OFF_CHAIN_COSTS;
import static de.cotto.lndmanagej.model.OnChainCostsFixtures.ON_CHAIN_COSTS;
import static de.cotto.lndmanagej.model.PolicyFixtures.POLICIES;
import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY_2;
import static de.cotto.lndmanagej.model.WaitingCloseChannelFixtures.WAITING_CLOSE_CHANNEL;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
class ChannelControllerTest {
private static final PoliciesDto FEE_CONFIGURATION_DTO = PoliciesDto.createFromModel(POLICIES);
private static final PoliciesDto POLICIES_DTO = PoliciesDto.createFromModel(POLICIES);
private static final ClosedChannelDetailsDto CLOSED_CHANNEL_DETAILS_DTO =
ClosedChannelDetailsDto.createFromModel(CLOSED_CHANNEL);
private static final FeeReport FEE_REPORT = new FeeReport(Coins.ofMilliSatoshis(1_234), Coins.ofMilliSatoshis(567));
@@ -56,18 +47,9 @@ class ChannelControllerTest {
@Mock
private ChannelService channelService;
@Mock
private NodeService nodeService;
@Mock
private BalanceService balanceService;
@Mock
private OnChainCostService onChainCostService;
@Mock
private OffChainCostService offChainCostService;
@Mock
private PolicyService policyService;
@@ -75,17 +57,7 @@ class ChannelControllerTest {
private FeeService feeService;
@Mock
private RebalanceService rebalanceService;
@BeforeEach
void setUp() {
lenient().when(onChainCostService.getOnChainCostsForChannelId(CHANNEL_ID)).thenReturn(ON_CHAIN_COSTS);
lenient().when(offChainCostService.getOffChainCostsForChannel(CHANNEL_ID)).thenReturn(OFF_CHAIN_COSTS);
lenient().when(policyService.getPolicies(CHANNEL_ID)).thenReturn(POLICIES);
lenient().when(feeService.getFeeReportForChannel(CHANNEL_ID)).thenReturn(FEE_REPORT);
lenient().when(rebalanceService.getRebalanceAmountFromChannel(CHANNEL_ID)).thenReturn(Coins.NONE);
lenient().when(rebalanceService.getRebalanceAmountToChannel(CHANNEL_ID)).thenReturn(Coins.NONE);
}
private ChannelDetailsService channelDetailsService;
@Test
void getBasicInformation_channel_not_found() {
@@ -95,14 +67,14 @@ class ChannelControllerTest {
@Test
void getBasicInformation() throws NotFoundException {
ChannelDto basicInformation = new ChannelDto(LOCAL_OPEN_CHANNEL, ClosedChannelDetailsDto.UNKNOWN);
ChannelDto basicInformation = new ChannelDto(LOCAL_OPEN_CHANNEL);
when(channelService.getLocalChannel(CHANNEL_ID)).thenReturn(Optional.of(LOCAL_OPEN_CHANNEL));
assertThat(channelController.getBasicInformation(CHANNEL_ID)).isEqualTo(basicInformation);
}
@Test
void getBasicInformation_closed_channel() throws NotFoundException {
ChannelDto basicInformation = new ChannelDto(CLOSED_CHANNEL, CLOSED_CHANNEL_DETAILS_DTO);
ChannelDto basicInformation = new ChannelDto(CLOSED_CHANNEL);
when(channelService.getLocalChannel(CHANNEL_ID)).thenReturn(Optional.of(CLOSED_CHANNEL));
assertThat(channelController.getBasicInformation(CHANNEL_ID)).isEqualTo(basicInformation);
}
@@ -115,60 +87,11 @@ class ChannelControllerTest {
@Test
void getDetails() throws NotFoundException {
ChannelDetailsDto expectedDetails = new ChannelDetailsDto(
LOCAL_OPEN_CHANNEL,
ALIAS_2,
LOCAL_OPEN_CHANNEL.getBalanceInformation(),
ON_CHAIN_COSTS,
OFF_CHAIN_COSTS,
FEE_CONFIGURATION_DTO,
ClosedChannelDetailsDto.UNKNOWN,
FEE_REPORT,
Coins.ofMilliSatoshis(1),
Coins.ofMilliSatoshis(2)
);
when(rebalanceService.getRebalanceAmountFromChannel(CHANNEL_ID)).thenReturn(Coins.ofMilliSatoshis(1));
when(rebalanceService.getRebalanceAmountToChannel(CHANNEL_ID)).thenReturn(Coins.ofMilliSatoshis(2));
when(nodeService.getAlias(PUBKEY_2)).thenReturn(ALIAS_2);
when(channelService.getLocalChannel(CHANNEL_ID)).thenReturn(Optional.of(LOCAL_OPEN_CHANNEL));
when(balanceService.getBalanceInformation(CHANNEL_ID))
.thenReturn(Optional.ofNullable(LOCAL_OPEN_CHANNEL.getBalanceInformation()));
when(channelDetailsService.getDetails(LOCAL_OPEN_CHANNEL)).thenReturn(CHANNEL_DETAILS);
assertThat(channelController.getDetails(CHANNEL_ID)).isEqualTo(expectedDetails);
}
@Test
void getDetails_private() throws NotFoundException {
ChannelDetailsDto expectedDetails = new ChannelDetailsDto(
LOCAL_OPEN_CHANNEL_PRIVATE,
ALIAS_2,
LOCAL_OPEN_CHANNEL_PRIVATE.getBalanceInformation(),
ON_CHAIN_COSTS,
OFF_CHAIN_COSTS,
FEE_CONFIGURATION_DTO,
ClosedChannelDetailsDto.UNKNOWN,
FEE_REPORT,
Coins.NONE,
Coins.NONE
);
when(nodeService.getAlias(PUBKEY_2)).thenReturn(ALIAS_2);
when(channelService.getLocalChannel(CHANNEL_ID)).thenReturn(Optional.of(LOCAL_OPEN_CHANNEL_PRIVATE));
when(balanceService.getBalanceInformation(CHANNEL_ID))
.thenReturn(Optional.ofNullable(LOCAL_OPEN_CHANNEL_PRIVATE.getBalanceInformation()));
assertThat(channelController.getDetails(CHANNEL_ID)).isEqualTo(expectedDetails);
}
@Test
void getDetails_closed() throws NotFoundException {
ChannelDetailsDto expectedDetails = mockForChannelWithoutPolicies(CLOSED_CHANNEL);
assertThat(channelController.getDetails(CHANNEL_ID)).isEqualTo(expectedDetails);
}
@Test
void getDetails_waiting_close() throws NotFoundException {
ChannelDetailsDto expectedDetails = mockForChannelWithoutPolicies(WAITING_CLOSE_CHANNEL);
assertThat(channelController.getDetails(CHANNEL_ID)).isEqualTo(expectedDetails);
assertThat(channelController.getDetails(CHANNEL_ID))
.isEqualTo(ChannelDetailsDto.createFromModel(CHANNEL_DETAILS));
}
@Test
@@ -189,12 +112,18 @@ class ChannelControllerTest {
void getPolicies() {
when(channelService.getLocalChannel(CHANNEL_ID)).thenReturn(Optional.of(LOCAL_OPEN_CHANNEL));
when(policyService.getPolicies(CHANNEL_ID)).thenReturn(POLICIES);
assertThat(channelController.getPolicies(CHANNEL_ID)).isEqualTo(FEE_CONFIGURATION_DTO);
assertThat(channelController.getPolicies(CHANNEL_ID)).isEqualTo(POLICIES_DTO);
}
@Test
void getPolicies_waiting_close() {
assertThat(channelController.getPolicies(CHANNEL_ID)).isEqualTo(PoliciesDto.EMPTY);
when(channelService.getLocalChannel(CHANNEL_ID)).thenReturn(Optional.of(WAITING_CLOSE_CHANNEL));
assertThat(channelController.getPolicies(CHANNEL_ID)).isEqualTo(PoliciesDto.createFromModel(Policies.UNKNOWN));
}
@Test
void getPolicies_channel_not_found() {
assertThat(channelController.getPolicies(CHANNEL_ID)).isEqualTo(PoliciesDto.createFromModel(Policies.UNKNOWN));
}
@Test
@@ -214,22 +143,4 @@ class ChannelControllerTest {
when(feeService.getFeeReportForChannel(CHANNEL_ID)).thenReturn(FEE_REPORT);
assertThat(channelController.getFeeReport(CHANNEL_ID)).isEqualTo(FeeReportDto.createFromModel(FEE_REPORT));
}
private ChannelDetailsDto mockForChannelWithoutPolicies(LocalChannel channel) {
when(nodeService.getAlias(PUBKEY_2)).thenReturn(ALIAS_2);
when(channelService.getLocalChannel(CHANNEL_ID)).thenReturn(Optional.of(channel));
when(balanceService.getBalanceInformation(CHANNEL_ID)).thenReturn(Optional.empty());
return new ChannelDetailsDto(
channel,
ALIAS_2,
BalanceInformation.EMPTY,
ON_CHAIN_COSTS,
OFF_CHAIN_COSTS,
PoliciesDto.EMPTY,
ClosedChannelDetailsDto.createFromModel(channel),
FEE_REPORT,
Coins.NONE,
Coins.NONE
);
}
}

View File

@@ -4,20 +4,19 @@ import de.cotto.lndmanagej.controller.dto.BalanceInformationDto;
import de.cotto.lndmanagej.controller.dto.ChannelsForNodeDto;
import de.cotto.lndmanagej.controller.dto.FeeReportDto;
import de.cotto.lndmanagej.controller.dto.NodeDetailsDto;
import de.cotto.lndmanagej.controller.dto.OffChainCostsDto;
import de.cotto.lndmanagej.controller.dto.OnChainCostsDto;
import de.cotto.lndmanagej.controller.dto.RebalanceReportDto;
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.OffChainCosts;
import de.cotto.lndmanagej.model.OnChainCosts;
import de.cotto.lndmanagej.model.Pubkey;
import de.cotto.lndmanagej.model.RebalanceReport;
import de.cotto.lndmanagej.service.BalanceService;
import de.cotto.lndmanagej.service.ChannelService;
import de.cotto.lndmanagej.service.FeeService;
import de.cotto.lndmanagej.service.NodeService;
import de.cotto.lndmanagej.service.OffChainCostService;
import de.cotto.lndmanagej.service.OnChainCostService;
import de.cotto.lndmanagej.service.RebalanceService;
import org.junit.jupiter.api.Test;
@@ -42,9 +41,9 @@ import static de.cotto.lndmanagej.model.LocalOpenChannelFixtures.LOCAL_OPEN_CHAN
import static de.cotto.lndmanagej.model.LocalOpenChannelFixtures.LOCAL_OPEN_CHANNEL_2;
import static de.cotto.lndmanagej.model.LocalOpenChannelFixtures.LOCAL_OPEN_CHANNEL_3;
import static de.cotto.lndmanagej.model.NodeFixtures.ALIAS_2;
import static de.cotto.lndmanagej.model.OffChainCostsFixtures.OFF_CHAIN_COSTS;
import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY;
import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY_2;
import static de.cotto.lndmanagej.model.RebalanceReportFixtures.REBALANCE_REPORT;
import static de.cotto.lndmanagej.model.WaitingCloseChannelFixtures.WAITING_CLOSE_CHANNEL;
import static de.cotto.lndmanagej.model.WaitingCloseChannelFixtures.WAITING_CLOSE_CHANNEL_2;
import static org.assertj.core.api.Assertions.assertThat;
@@ -67,9 +66,6 @@ class NodeControllerTest {
@Mock
private OnChainCostService onChainCostService;
@Mock
private OffChainCostService offChainCostService;
@Mock
private BalanceService balanceService;
@@ -89,11 +85,9 @@ class NodeControllerTest {
@Test
void getNodeDetails_no_channels() {
when(onChainCostService.getOnChainCostsForPeer(any())).thenReturn(OnChainCosts.NONE);
when(offChainCostService.getOffChainCostsForPeer(any())).thenReturn(OffChainCosts.NONE);
when(balanceService.getBalanceInformationForPeer(any(Pubkey.class))).thenReturn(BalanceInformation.EMPTY);
when(feeService.getFeeReportForPeer(any())).thenReturn(new FeeReport(Coins.NONE, Coins.NONE));
when(rebalanceService.getRebalanceAmountFromPeer(PUBKEY_2)).thenReturn(Coins.NONE);
when(rebalanceService.getRebalanceAmountToPeer(PUBKEY_2)).thenReturn(Coins.NONE);
when(rebalanceService.getReportForPeer(PUBKEY_2)).thenReturn(RebalanceReport.EMPTY);
NodeDetailsDto expectedDetails = new NodeDetailsDto(
PUBKEY_2,
ALIAS_2,
@@ -102,12 +96,10 @@ class NodeControllerTest {
List.of(),
List.of(),
OnChainCostsDto.createFromModel(OnChainCosts.NONE),
OffChainCostsDto.createFromModel(OffChainCosts.NONE),
BalanceInformationDto.createFromModel(BalanceInformation.EMPTY),
true,
new FeeReportDto("0", "0"),
"0",
"0"
RebalanceReportDto.createFromModel(RebalanceReport.EMPTY)
);
when(nodeService.getNode(PUBKEY_2)).thenReturn(new Node(PUBKEY_2, ALIAS_2, 0, true));
@@ -131,10 +123,8 @@ class NodeControllerTest {
Coins.ofSatoshis(789)
);
when(onChainCostService.getOnChainCostsForPeer(PUBKEY_2)).thenReturn(onChainCosts);
when(offChainCostService.getOffChainCostsForPeer(PUBKEY_2)).thenReturn(OFF_CHAIN_COSTS);
when(balanceService.getBalanceInformationForPeer(PUBKEY_2)).thenReturn(BALANCE_INFORMATION);
when(rebalanceService.getRebalanceAmountFromPeer(PUBKEY_2)).thenReturn(Coins.ofMilliSatoshis(111));
when(rebalanceService.getRebalanceAmountToPeer(PUBKEY_2)).thenReturn(Coins.ofMilliSatoshis(222));
when(rebalanceService.getReportForPeer(PUBKEY_2)).thenReturn(REBALANCE_REPORT);
when(feeService.getFeeReportForPeer(PUBKEY_2)).thenReturn(FEE_REPORT);
NodeDetailsDto expectedDetails = new NodeDetailsDto(
PUBKEY_2,
@@ -144,12 +134,10 @@ class NodeControllerTest {
List.of(CHANNEL_ID, CHANNEL_ID_2),
List.of(CHANNEL_ID, CHANNEL_ID_2, CHANNEL_ID_3),
OnChainCostsDto.createFromModel(onChainCosts),
OffChainCostsDto.createFromModel(OFF_CHAIN_COSTS),
BalanceInformationDto.createFromModel(BALANCE_INFORMATION),
false,
new FeeReportDto("1234", "567"),
"111",
"222"
FeeReportDto.createFromModel(FEE_REPORT),
RebalanceReportDto.createFromModel(REBALANCE_REPORT)
);
assertThat(nodeController.getDetails(PUBKEY_2)).isEqualTo(expectedDetails);
@@ -193,6 +181,6 @@ class NodeControllerTest {
@Test
void getFeeReport() {
when(feeService.getFeeReportForPeer(PUBKEY)).thenReturn(FEE_REPORT);
assertThat(nodeController.getFeeReport(PUBKEY)).isEqualTo(new FeeReportDto("1234", "567"));
assertThat(nodeController.getFeeReport(PUBKEY)).isEqualTo(FeeReportDto.createFromModel(FEE_REPORT));
}
}

View File

@@ -1,7 +1,6 @@
package de.cotto.lndmanagej.controller;
import de.cotto.lndmanagej.model.Coins;
import de.cotto.lndmanagej.service.OffChainCostService;
import de.cotto.lndmanagej.service.RebalanceService;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -21,57 +20,54 @@ class RebalancesControllerTest {
@InjectMocks
private RebalancesController rebalancesController;
@Mock
private OffChainCostService offChainCostService;
@Mock
private RebalanceService rebalanceService;
@Test
void getRebalanceSourceCostsForChannel() {
when(offChainCostService.getRebalanceSourceCostsForChannel(CHANNEL_ID)).thenReturn(COINS);
when(rebalanceService.getSourceCostsForChannel(CHANNEL_ID)).thenReturn(COINS);
assertThat(rebalancesController.getRebalanceSourceCostsForChannel(CHANNEL_ID)).isEqualTo(123);
}
@Test
void getRebalanceSourceCostsForPeer() {
when(offChainCostService.getRebalanceSourceCostsForPeer(PUBKEY)).thenReturn(COINS);
when(rebalanceService.getSourceCostsForPeer(PUBKEY)).thenReturn(COINS);
assertThat(rebalancesController.getRebalanceSourceCostsForPeer(PUBKEY)).isEqualTo(123);
}
@Test
void getRebalanceTargetCostsForChannel() {
when(offChainCostService.getRebalanceTargetCostsForChannel(CHANNEL_ID)).thenReturn(COINS);
when(rebalanceService.getTargetCostsForChannel(CHANNEL_ID)).thenReturn(COINS);
assertThat(rebalancesController.getRebalanceTargetCostsForChannel(CHANNEL_ID)).isEqualTo(123);
}
@Test
void getRebalanceTargetCostsForPeer() {
when(offChainCostService.getRebalanceTargetCostsForPeer(PUBKEY)).thenReturn(COINS);
when(rebalanceService.getTargetCostsForPeer(PUBKEY)).thenReturn(COINS);
assertThat(rebalancesController.getRebalanceTargetCostsForPeer(PUBKEY)).isEqualTo(123);
}
@Test
void getRebalanceSourceAmountForChannel() {
when(rebalanceService.getRebalanceAmountFromChannel(CHANNEL_ID)).thenReturn(COINS);
when(rebalanceService.getAmountFromChannel(CHANNEL_ID)).thenReturn(COINS);
assertThat(rebalancesController.getRebalanceSourceAmountForChannel(CHANNEL_ID)).isEqualTo(123);
}
@Test
void getRebalanceSourceAmountForPeer() {
when(rebalanceService.getRebalanceAmountFromPeer(PUBKEY)).thenReturn(COINS);
when(rebalanceService.getAmountFromPeer(PUBKEY)).thenReturn(COINS);
assertThat(rebalancesController.getRebalanceSourceAmountForPeer(PUBKEY)).isEqualTo(123);
}
@Test
void getRebalanceTargetAmountForChannel() {
when(rebalanceService.getRebalanceAmountToChannel(CHANNEL_ID)).thenReturn(COINS);
when(rebalanceService.getAmountToChannel(CHANNEL_ID)).thenReturn(COINS);
assertThat(rebalancesController.getRebalanceTargetAmountForChannel(CHANNEL_ID)).isEqualTo(123);
}
@Test
void getRebalanceTargetAmountForPeer() {
when(rebalanceService.getRebalanceAmountToPeer(PUBKEY)).thenReturn(COINS);
when(rebalanceService.getAmountToPeer(PUBKEY)).thenReturn(COINS);
assertThat(rebalancesController.getRebalanceTargetAmountForPeer(PUBKEY)).isEqualTo(123);
}
}

View File

@@ -4,19 +4,24 @@ import de.cotto.lndmanagej.model.ChannelStatus;
import de.cotto.lndmanagej.model.Coins;
import de.cotto.lndmanagej.model.FeeReport;
import de.cotto.lndmanagej.model.OpenInitiator;
import de.cotto.lndmanagej.model.Policies;
import de.cotto.lndmanagej.model.RebalanceReport;
import org.junit.jupiter.api.Test;
import static de.cotto.lndmanagej.model.BalanceInformationFixtures.BALANCE_INFORMATION;
import static de.cotto.lndmanagej.model.ChannelDetailsFixtures.CHANNEL_DETAILS;
import static de.cotto.lndmanagej.model.ChannelFixtures.CAPACITY;
import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID;
import static de.cotto.lndmanagej.model.ChannelPointFixtures.CHANNEL_POINT;
import static de.cotto.lndmanagej.model.CoopClosedChannelFixtures.CLOSED_CHANNEL;
import static de.cotto.lndmanagej.model.LocalOpenChannelFixtures.LOCAL_OPEN_CHANNEL;
import static de.cotto.lndmanagej.model.LocalOpenChannelFixtures.LOCAL_OPEN_CHANNEL_PRIVATE;
import static de.cotto.lndmanagej.model.NodeFixtures.ALIAS;
import static de.cotto.lndmanagej.model.OffChainCostsFixtures.OFF_CHAIN_COSTS;
import static de.cotto.lndmanagej.model.OnChainCostsFixtures.ON_CHAIN_COSTS;
import static de.cotto.lndmanagej.model.OpenCloseStatus.OPEN;
import static de.cotto.lndmanagej.model.PolicyFixtures.POLICIES;
import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY_2;
import static de.cotto.lndmanagej.model.RebalanceReportFixtures.REBALANCE_REPORT;
import static org.assertj.core.api.Assertions.assertThat;
class ChannelDetailsDtoTest {
@@ -30,14 +35,25 @@ class ChannelDetailsDtoTest {
ALIAS,
BALANCE_INFORMATION,
ON_CHAIN_COSTS,
OFF_CHAIN_COSTS,
PoliciesDto.EMPTY,
CLOSE_DETAILS,
Policies.UNKNOWN,
FEE_REPORT,
Coins.ofMilliSatoshis(123),
Coins.ofMilliSatoshis(456)
REBALANCE_REPORT
);
@Test
void createFromModel() {
ChannelDetailsDto expected = new ChannelDetailsDto(
LOCAL_OPEN_CHANNEL_PRIVATE,
ALIAS,
BALANCE_INFORMATION,
ON_CHAIN_COSTS,
POLICIES,
FEE_REPORT,
REBALANCE_REPORT
);
assertThat(ChannelDetailsDto.createFromModel(CHANNEL_DETAILS)).isEqualTo(expected);
}
@Test
void channelIdShort() {
assertThat(CHANNEL_DETAILS_DTO.channelIdShort()).isEqualTo(String.valueOf(CHANNEL_ID.getShortChannelId()));
@@ -90,12 +106,9 @@ class ChannelDetailsDtoTest {
ALIAS,
BALANCE_INFORMATION,
ON_CHAIN_COSTS,
OFF_CHAIN_COSTS,
PoliciesDto.EMPTY,
CLOSE_DETAILS,
Policies.UNKNOWN,
FEE_REPORT,
Coins.NONE,
Coins.NONE
RebalanceReport.EMPTY
);
ChannelStatusDto channelStatusDto =
ChannelStatusDto.createFromModel(new ChannelStatus(false, true, false, OPEN));
@@ -123,17 +136,9 @@ class ChannelDetailsDtoTest {
}
@Test
void offChainCosts() {
assertThat(CHANNEL_DETAILS_DTO.offChainCosts()).isEqualTo(OffChainCostsDto.createFromModel(OFF_CHAIN_COSTS));
}
void rebalanceReport() {
assertThat(CHANNEL_DETAILS_DTO.rebalanceReport())
.isEqualTo(RebalanceReportDto.createFromModel(REBALANCE_REPORT));
@Test
void rebalanceSourceAmount() {
assertThat(CHANNEL_DETAILS_DTO.rebalanceSourceAmount()).isEqualTo("123");
}
@Test
void rebalanceTargetAmount() {
assertThat(CHANNEL_DETAILS_DTO.rebalanceTargetAmount()).isEqualTo("456");
}
}

View File

@@ -18,7 +18,7 @@ import static org.assertj.core.api.Assertions.assertThat;
class ChannelDtoTest {
private static final ClosedChannelDetailsDto CLOSE_DETAILS =
ClosedChannelDetailsDto.createFromModel(CLOSED_CHANNEL);
private static final ChannelDto CHANNEL_DTO = new ChannelDto(CLOSED_CHANNEL, CLOSE_DETAILS);
private static final ChannelDto CHANNEL_DTO = new ChannelDto(CLOSED_CHANNEL);
@Test
void channelIdShort() {
@@ -57,13 +57,13 @@ class ChannelDtoTest {
@Test
void totalSent() {
assertThat(new ChannelDto(LOCAL_OPEN_CHANNEL, CLOSE_DETAILS).totalSent())
assertThat(new ChannelDto(LOCAL_OPEN_CHANNEL).totalSent())
.isEqualTo(String.valueOf(TOTAL_SENT.satoshis()));
}
@Test
void totalReceived() {
assertThat(new ChannelDto(LOCAL_OPEN_CHANNEL, CLOSE_DETAILS).totalReceived())
assertThat(new ChannelDto(LOCAL_OPEN_CHANNEL).totalReceived())
.isEqualTo(String.valueOf(TOTAL_RECEIVED.satoshis()));
}
@@ -79,7 +79,7 @@ class ChannelDtoTest {
@Test
void status() {
ChannelDto dto = new ChannelDto(LOCAL_OPEN_CHANNEL, CLOSE_DETAILS);
ChannelDto dto = new ChannelDto(LOCAL_OPEN_CHANNEL);
ChannelStatusDto channelStatusDto =
ChannelStatusDto.createFromModel(new ChannelStatus(false, true, false, OPEN));
assertThat(dto.status()).isEqualTo(channelStatusDto);

View File

@@ -1,22 +0,0 @@
package de.cotto.lndmanagej.controller.dto;
import de.cotto.lndmanagej.model.Coins;
import org.junit.jupiter.api.Test;
import static de.cotto.lndmanagej.model.OffChainCostsFixtures.OFF_CHAIN_COSTS;
import static org.assertj.core.api.Assertions.assertThat;
class OffChainCostsDtoTest {
@Test
void converts_to_msat_strings() {
OffChainCostsDto dto = new OffChainCostsDto(Coins.ofMilliSatoshis(1), Coins.ofMilliSatoshis(1_234));
assertThat(dto.rebalanceSource()).isEqualTo("1");
assertThat(dto.rebalanceTarget()).isEqualTo("1234");
}
@Test
void createFromModel() {
assertThat(OffChainCostsDto.createFromModel(OFF_CHAIN_COSTS))
.isEqualTo(new OffChainCostsDto("1000000", "2000000"));
}
}

View File

@@ -0,0 +1,44 @@
package de.cotto.lndmanagej.controller.dto;
import de.cotto.lndmanagej.model.Coins;
import org.junit.jupiter.api.Test;
import static de.cotto.lndmanagej.model.RebalanceReportFixtures.REBALANCE_REPORT;
import static org.assertj.core.api.Assertions.assertThat;
class RebalanceReportDtoTest {
private static final RebalanceReportDto REBALANCE_REPORT_DTO = new RebalanceReportDto(
Coins.ofMilliSatoshis(1_234),
Coins.ofSatoshis(9_000),
Coins.ofMilliSatoshis(567),
Coins.ofSatoshis(1_000)
);
@Test
void sourceCosts() {
assertThat(REBALANCE_REPORT_DTO.sourceCosts()).isEqualTo("1234");
}
@Test
void sourceAmount() {
assertThat(REBALANCE_REPORT_DTO.sourceAmount()).isEqualTo("9000000");
}
@Test
void targetCosts() {
assertThat(REBALANCE_REPORT_DTO.targetCosts()).isEqualTo("567");
}
@Test
void targetAmount() {
assertThat(REBALANCE_REPORT_DTO.targetAmount()).isEqualTo("1000000");
}
@Test
void createFromModel() {
assertThat(RebalanceReportDto.createFromModel(REBALANCE_REPORT)).isEqualTo(
new RebalanceReportDto("1000000", "665000", "2000000", "991000")
);
}
}