add model for on chain costs

This commit is contained in:
Carsten Otto
2021-12-10 14:24:26 +01:00
parent 5858a84ef9
commit 3c0fca7d5c
20 changed files with 234 additions and 125 deletions

View File

@@ -6,13 +6,13 @@ import de.cotto.lndmanagej.controller.dto.ChannelDto;
import de.cotto.lndmanagej.controller.dto.ClosedChannelDetailsDto;
import de.cotto.lndmanagej.controller.dto.FeeReportDto;
import de.cotto.lndmanagej.controller.dto.OffChainCostsDto;
import de.cotto.lndmanagej.controller.dto.OnChainCostsDto;
import de.cotto.lndmanagej.controller.dto.PoliciesDto;
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.model.OnChainCosts;
import de.cotto.lndmanagej.service.BalanceService;
import de.cotto.lndmanagej.service.ChannelService;
import de.cotto.lndmanagej.service.FeeService;
@@ -49,13 +49,12 @@ class ChannelControllerTest {
private static final Coins CLOSE_COSTS = Coins.ofSatoshis(2);
private static final Coins SOURCE_COSTS = Coins.ofSatoshis(3);
private static final Coins TARGET_COSTS = Coins.ofSatoshis(4);
private static final OnChainCostsDto ON_CHAIN_COSTS = new OnChainCostsDto(OPEN_COSTS, CLOSE_COSTS);
private static final OnChainCosts ON_CHAIN_COSTS = new OnChainCosts(OPEN_COSTS, CLOSE_COSTS);
private static final OffChainCostsDto OFF_CHAIN_COSTS = new OffChainCostsDto(SOURCE_COSTS, TARGET_COSTS);
private static final PoliciesDto FEE_CONFIGURATION_DTO = PoliciesDto.createFromModel(POLICIES);
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.createFromModel(FEE_REPORT);
@InjectMocks
private ChannelController channelController;
@@ -83,8 +82,7 @@ class ChannelControllerTest {
@BeforeEach
void setUp() {
lenient().when(onChainCostService.getOpenCostsForChannelId(CHANNEL_ID)).thenReturn(Optional.of(OPEN_COSTS));
lenient().when(onChainCostService.getCloseCostsForChannelId(CHANNEL_ID)).thenReturn(Optional.of(CLOSE_COSTS));
lenient().when(onChainCostService.getOnChainCostsForChannelId(CHANNEL_ID)).thenReturn(ON_CHAIN_COSTS);
lenient().when(offChainCostService.getRebalanceSourceCostsForChannel(CHANNEL_ID)).thenReturn(SOURCE_COSTS);
lenient().when(offChainCostService.getRebalanceTargetCostsForChannel(CHANNEL_ID)).thenReturn(TARGET_COSTS);
lenient().when(policyService.getPolicies(CHANNEL_ID)).thenReturn(POLICIES);
@@ -127,7 +125,7 @@ class ChannelControllerTest {
OFF_CHAIN_COSTS,
FEE_CONFIGURATION_DTO,
ClosedChannelDetailsDto.UNKNOWN,
FEE_REPORT_DTO
FEE_REPORT
);
when(nodeService.getAlias(PUBKEY_2)).thenReturn(ALIAS_2);
when(channelService.getLocalChannel(CHANNEL_ID)).thenReturn(Optional.of(LOCAL_OPEN_CHANNEL));
@@ -147,7 +145,7 @@ class ChannelControllerTest {
OFF_CHAIN_COSTS,
FEE_CONFIGURATION_DTO,
ClosedChannelDetailsDto.UNKNOWN,
FEE_REPORT_DTO
FEE_REPORT
);
when(nodeService.getAlias(PUBKEY_2)).thenReturn(ALIAS_2);
when(channelService.getLocalChannel(CHANNEL_ID)).thenReturn(Optional.of(LOCAL_OPEN_CHANNEL_PRIVATE));
@@ -214,7 +212,7 @@ class ChannelControllerTest {
@Test
void getFeeReport() {
when(feeService.getFeeReportForChannel(CHANNEL_ID)).thenReturn(FEE_REPORT);
assertThat(channelController.getFeeReport(CHANNEL_ID)).isEqualTo(FEE_REPORT_DTO);
assertThat(channelController.getFeeReport(CHANNEL_ID)).isEqualTo(FeeReportDto.createFromModel(FEE_REPORT));
}
private ChannelDetailsDto mockForChannelWithoutPolicies(
@@ -233,7 +231,7 @@ class ChannelControllerTest {
OFF_CHAIN_COSTS,
PoliciesDto.EMPTY,
new ClosedChannelDetailsDto(closeInitiator, closeHeight),
FEE_REPORT_DTO
FEE_REPORT
);
}
}

View File

@@ -10,6 +10,7 @@ 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.OnChainCosts;
import de.cotto.lndmanagej.model.Pubkey;
import de.cotto.lndmanagej.service.BalanceService;
import de.cotto.lndmanagej.service.ChannelService;
@@ -81,8 +82,7 @@ class NodeControllerTest {
@Test
void getNodeDetails_no_channels() {
when(onChainCostService.getOpenCostsWith(any())).thenReturn(Coins.NONE);
when(onChainCostService.getCloseCostsWith(any())).thenReturn(Coins.NONE);
when(onChainCostService.getOnChainCostsForPeer(any())).thenReturn(OnChainCosts.NONE);
when(offChainCostService.getRebalanceSourceCostsForPeer(any())).thenReturn(Coins.NONE);
when(offChainCostService.getRebalanceTargetCostsForPeer(any())).thenReturn(Coins.NONE);
when(balanceService.getBalanceInformationForPeer(any(Pubkey.class))).thenReturn(BalanceInformation.EMPTY);
@@ -94,7 +94,7 @@ class NodeControllerTest {
List.of(),
List.of(),
List.of(),
new OnChainCostsDto(Coins.NONE, Coins.NONE),
OnChainCostsDto.createFromModel(OnChainCosts.NONE),
new OffChainCostsDto(Coins.NONE, Coins.NONE),
BalanceInformationDto.createFromModel(BalanceInformation.EMPTY),
true,
@@ -116,12 +116,13 @@ class NodeControllerTest {
when(channelService.getForceClosingChannelsWith(PUBKEY_2)).thenReturn(
Set.of(FORCE_CLOSING_CHANNEL, FORCE_CLOSING_CHANNEL_2, FORCE_CLOSING_CHANNEL_3)
);
Coins openCosts = Coins.ofSatoshis(123);
Coins closeCosts = Coins.ofSatoshis(456);
OnChainCosts onChainCosts = new OnChainCosts(
Coins.ofSatoshis(123),
Coins.ofSatoshis(456)
);
Coins rebalanceSourceCosts = Coins.ofMilliSatoshis(1);
Coins rebalanceTargetCosts = Coins.ofMilliSatoshis(2);
when(onChainCostService.getOpenCostsWith(PUBKEY_2)).thenReturn(openCosts);
when(onChainCostService.getCloseCostsWith(PUBKEY_2)).thenReturn(closeCosts);
when(onChainCostService.getOnChainCostsForPeer(PUBKEY_2)).thenReturn(onChainCosts);
when(offChainCostService.getRebalanceSourceCostsForPeer(PUBKEY_2)).thenReturn(rebalanceSourceCosts);
when(offChainCostService.getRebalanceTargetCostsForPeer(PUBKEY_2)).thenReturn(rebalanceTargetCosts);
when(balanceService.getBalanceInformationForPeer(PUBKEY_2)).thenReturn(BALANCE_INFORMATION);
@@ -133,7 +134,7 @@ class NodeControllerTest {
List.of(CHANNEL_ID_2, CHANNEL_ID_3),
List.of(CHANNEL_ID, CHANNEL_ID_2),
List.of(CHANNEL_ID, CHANNEL_ID_2, CHANNEL_ID_3),
new OnChainCostsDto(openCosts, closeCosts),
OnChainCostsDto.createFromModel(onChainCosts),
new OffChainCostsDto(rebalanceSourceCosts, rebalanceTargetCosts),
BalanceInformationDto.createFromModel(BALANCE_INFORMATION),
false,

View File

@@ -12,6 +12,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
import java.util.Optional;
import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID;
import static de.cotto.lndmanagej.model.OnChainCostsFixtures.ON_CHAIN_COSTS;
import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
@@ -27,12 +28,9 @@ class OnChainCostsControllerTest {
@Test
void getCostsForPeer() {
Coins openCosts = Coins.ofSatoshis(123);
Coins closeCosts = Coins.ofSatoshis(456);
when(onChainCostService.getOpenCostsWith(PUBKEY)).thenReturn(openCosts);
when(onChainCostService.getCloseCostsWith(PUBKEY)).thenReturn(closeCosts);
OnChainCostsDto expected = new OnChainCostsDto(openCosts, closeCosts);
assertThat(onChainCostsController.getCostsForPeer(PUBKEY)).isEqualTo(expected);
when(onChainCostService.getOnChainCostsForPeer(PUBKEY)).thenReturn(ON_CHAIN_COSTS);
assertThat(onChainCostsController.getCostsForPeer(PUBKEY))
.isEqualTo(OnChainCostsDto.createFromModel(ON_CHAIN_COSTS));
}
@Test

View File

@@ -2,6 +2,8 @@ package de.cotto.lndmanagej.controller.dto;
import de.cotto.lndmanagej.model.ChannelStatus;
import de.cotto.lndmanagej.model.Coins;
import de.cotto.lndmanagej.model.FeeReport;
import de.cotto.lndmanagej.model.OnChainCosts;
import de.cotto.lndmanagej.model.OpenInitiator;
import org.junit.jupiter.api.Test;
@@ -18,12 +20,12 @@ import static org.assertj.core.api.Assertions.assertThat;
class ChannelDetailsDtoTest {
private static final OnChainCostsDto ON_CHAIN_COSTS = new OnChainCostsDto(Coins.ofSatoshis(1), Coins.ofSatoshis(2));
private static final OnChainCosts ON_CHAIN_COSTS = new OnChainCosts(Coins.ofSatoshis(1), Coins.ofSatoshis(2));
private static final OffChainCostsDto OFF_CHAIN_COSTS =
new OffChainCostsDto(Coins.ofSatoshis(3), Coins.ofSatoshis(4));
private static final ClosedChannelDetailsDto CLOSE_DETAILS = new ClosedChannelDetailsDto("abc", 123);
private static final FeeReportDto FEE_REPORT =
new FeeReportDto(Coins.ofMilliSatoshis(1234), Coins.ofMilliSatoshis(567));
private static final FeeReport FEE_REPORT =
new FeeReport(Coins.ofMilliSatoshis(1234), Coins.ofMilliSatoshis(567));
private static final ChannelDetailsDto CHANNEL_DETAILS_DTO = new ChannelDetailsDto(
CLOSED_CHANNEL,
ALIAS,
@@ -109,12 +111,12 @@ class ChannelDetailsDtoTest {
@Test
void feeReport() {
assertThat(CHANNEL_DETAILS_DTO.feeReport()).isEqualTo(FEE_REPORT);
assertThat(CHANNEL_DETAILS_DTO.feeReport()).isEqualTo(FeeReportDto.createFromModel(FEE_REPORT));
}
@Test
void onChainCosts() {
assertThat(CHANNEL_DETAILS_DTO.onChainCosts()).isEqualTo(ON_CHAIN_COSTS);
assertThat(CHANNEL_DETAILS_DTO.onChainCosts()).isEqualTo(OnChainCostsDto.createFromModel(ON_CHAIN_COSTS));
}
@Test

View File

@@ -0,0 +1,14 @@
package de.cotto.lndmanagej.controller.dto;
import org.junit.jupiter.api.Test;
import static de.cotto.lndmanagej.model.OnChainCostsFixtures.ON_CHAIN_COSTS;
import static org.assertj.core.api.Assertions.assertThat;
class OnChainCostsDtoTest {
@Test
void createFromModel() {
assertThat(OnChainCostsDto.createFromModel(ON_CHAIN_COSTS))
.isEqualTo(new OnChainCostsDto("1000", "2000"));
}
}