move feeconfiguration to policies (local+remote)

This commit is contained in:
Carsten Otto
2021-11-28 12:57:02 +01:00
parent 7c64fe172b
commit b6f79d7cb7
21 changed files with 238 additions and 228 deletions

View File

@@ -3,25 +3,22 @@ package de.cotto.lndmanagej.service;
import de.cotto.lndmanagej.grpc.GrpcFees;
import de.cotto.lndmanagej.model.ChannelId;
import de.cotto.lndmanagej.model.Coins;
import de.cotto.lndmanagej.model.FeeConfiguration;
import de.cotto.lndmanagej.model.Policies;
import de.cotto.lndmanagej.model.Policy;
import org.springframework.stereotype.Component;
@Component
public class FeeService {
public class PolicyService {
private final GrpcFees grpcFees;
public FeeService(GrpcFees grpcFees) {
public PolicyService(GrpcFees grpcFees) {
this.grpcFees = grpcFees;
}
public FeeConfiguration getFeeConfiguration(ChannelId channelId) {
return new FeeConfiguration(
getOutgoingFeeRate(channelId),
getOutgoingBaseFee(channelId),
getIncomingFeeRate(channelId),
getIncomingBaseFee(channelId),
isEnabledLocal(channelId),
isEnabledRemote(channelId)
public Policies getPolicies(ChannelId channelId) {
return new Policies(
new Policy(getOutgoingFeeRate(channelId), getOutgoingBaseFee(channelId), isEnabledLocal(channelId)),
new Policy(getIncomingFeeRate(channelId), getIncomingBaseFee(channelId), isEnabledRemote(channelId))
);
}

View File

@@ -2,7 +2,8 @@ package de.cotto.lndmanagej.service;
import de.cotto.lndmanagej.grpc.GrpcFees;
import de.cotto.lndmanagej.model.Coins;
import de.cotto.lndmanagej.model.FeeConfiguration;
import de.cotto.lndmanagej.model.Policies;
import de.cotto.lndmanagej.model.Policy;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
@@ -17,57 +18,50 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
class FeeServiceTest {
class PolicyServiceTest {
@InjectMocks
private FeeService feeService;
private PolicyService policyService;
@Mock
private GrpcFees grpcFees;
@Test
void getFeeConfiguration() {
FeeConfiguration expected = new FeeConfiguration(
789,
Coins.ofMilliSatoshis(111),
123,
Coins.ofMilliSatoshis(456),
true,
false
void getPolicies() {
Policies expected = new Policies(
new Policy(789, Coins.ofMilliSatoshis(111), true),
new Policy(123, Coins.ofMilliSatoshis(456), false)
);
mockFees();
when(grpcFees.isEnabledLocal(CHANNEL_ID)).thenReturn(Optional.of(true));
when(grpcFees.isEnabledRemote(CHANNEL_ID)).thenReturn(Optional.of(false));
assertThat(policyService.getPolicies(CHANNEL_ID)).isEqualTo(expected);
}
@Test
void getPolicies_enabled_disabled_swapped() {
Policies expected = new Policies(
new Policy(789, Coins.ofMilliSatoshis(111), false),
new Policy(123, Coins.ofMilliSatoshis(456), true)
);
mockFees();
when(grpcFees.isEnabledLocal(CHANNEL_ID)).thenReturn(Optional.of(false));
when(grpcFees.isEnabledRemote(CHANNEL_ID)).thenReturn(Optional.of(true));
assertThat(policyService.getPolicies(CHANNEL_ID)).isEqualTo(expected);
}
@Test
void getPolicies_not_found() {
assertThatIllegalStateException().isThrownBy(() -> policyService.getPolicies(CHANNEL_ID));
}
private void mockFees() {
when(grpcFees.getOutgoingFeeRate(CHANNEL_ID)).thenReturn(Optional.of(789L));
when(grpcFees.getOutgoingBaseFee(CHANNEL_ID)).thenReturn(Optional.of(Coins.ofMilliSatoshis(111)));
when(grpcFees.getIncomingFeeRate(CHANNEL_ID)).thenReturn(Optional.of(123L));
when(grpcFees.getIncomingBaseFee(CHANNEL_ID)).thenReturn(Optional.of(Coins.ofMilliSatoshis(456)));
when(grpcFees.isEnabledLocal(CHANNEL_ID)).thenReturn(Optional.of(true));
when(grpcFees.isEnabledRemote(CHANNEL_ID)).thenReturn(Optional.of(false));
assertThat(feeService.getFeeConfiguration(CHANNEL_ID)).isEqualTo(expected);
}
@Test
void getFeeConfiguration_swapped() {
FeeConfiguration expected = new FeeConfiguration(
123,
Coins.ofMilliSatoshis(456),
789,
Coins.ofMilliSatoshis(111),
false,
true
);
when(grpcFees.getOutgoingFeeRate(CHANNEL_ID)).thenReturn(Optional.of(123L));
when(grpcFees.getOutgoingBaseFee(CHANNEL_ID)).thenReturn(Optional.of(Coins.ofMilliSatoshis(456)));
when(grpcFees.getIncomingFeeRate(CHANNEL_ID)).thenReturn(Optional.of(789L));
when(grpcFees.getIncomingBaseFee(CHANNEL_ID)).thenReturn(Optional.of(Coins.ofMilliSatoshis(111)));
when(grpcFees.isEnabledLocal(CHANNEL_ID)).thenReturn(Optional.of(false));
when(grpcFees.isEnabledRemote(CHANNEL_ID)).thenReturn(Optional.of(true));
assertThat(feeService.getFeeConfiguration(CHANNEL_ID)).isEqualTo(expected);
}
@Test
void getFeeConfiguration_not_found() {
assertThatIllegalStateException().isThrownBy(() -> feeService.getFeeConfiguration(CHANNEL_ID));
}
}

View File

@@ -1,11 +0,0 @@
package de.cotto.lndmanagej.model;
public record FeeConfiguration(
long outgoingFeeRate,
Coins outgoingBaseFee,
long incomingFeeRate,
Coins incomingBaseFee,
boolean enabledLocal,
boolean enabledRemote
) {
}

View File

@@ -0,0 +1,7 @@
package de.cotto.lndmanagej.model;
public record Policies(
Policy local,
Policy remote
) {
}

View File

@@ -0,0 +1,4 @@
package de.cotto.lndmanagej.model;
public record Policy(long feeRate, Coins baseFee, boolean enabled) {
}

View File

@@ -1,38 +0,0 @@
package de.cotto.lndmanagej.model;
import org.junit.jupiter.api.Test;
import static de.cotto.lndmanagej.model.FeeConfigurationFixtures.FEE_CONFIGURATION;
import static org.assertj.core.api.Assertions.assertThat;
class FeeConfigurationTest {
@Test
void outgoingFeeRate() {
assertThat(FEE_CONFIGURATION.outgoingFeeRate()).isEqualTo(1);
}
@Test
void outgoingBaseFee() {
assertThat(FEE_CONFIGURATION.outgoingBaseFee()).isEqualTo(Coins.ofMilliSatoshis(2));
}
@Test
void incomingFeeRate() {
assertThat(FEE_CONFIGURATION.incomingFeeRate()).isEqualTo(3);
}
@Test
void incomingBaseFee() {
assertThat(FEE_CONFIGURATION.incomingBaseFee()).isEqualTo(Coins.ofMilliSatoshis(4));
}
@Test
void enabledLocal() {
assertThat(FEE_CONFIGURATION.enabledLocal()).isFalse();
}
@Test
void enabledRemote() {
assertThat(FEE_CONFIGURATION.enabledRemote()).isTrue();
}
}

View File

@@ -0,0 +1,20 @@
package de.cotto.lndmanagej.model;
import org.junit.jupiter.api.Test;
import static de.cotto.lndmanagej.model.PolicyFixtures.POLICIES;
import static de.cotto.lndmanagej.model.PolicyFixtures.POLICY_1;
import static de.cotto.lndmanagej.model.PolicyFixtures.POLICY_2;
import static org.assertj.core.api.Assertions.assertThat;
class PoliciesTest {
@Test
void local() {
assertThat(POLICIES.local()).isEqualTo(POLICY_1);
}
@Test
void remote() {
assertThat(POLICIES.remote()).isEqualTo(POLICY_2);
}
}

View File

@@ -0,0 +1,23 @@
package de.cotto.lndmanagej.model;
import org.junit.jupiter.api.Test;
import static de.cotto.lndmanagej.model.PolicyFixtures.POLICY_1;
import static org.assertj.core.api.Assertions.assertThat;
class PolicyTest {
@Test
void feeRate() {
assertThat(POLICY_1.feeRate()).isEqualTo(100L);
}
@Test
void baseFee() {
assertThat(POLICY_1.baseFee()).isEqualTo(Coins.ofMilliSatoshis(10));
}
@Test
void enabled() {
assertThat(POLICY_1.enabled()).isFalse();
}
}

View File

@@ -1,13 +0,0 @@
package de.cotto.lndmanagej.model;
public class FeeConfigurationFixtures {
public static final FeeConfiguration FEE_CONFIGURATION =
new FeeConfiguration(
1,
Coins.ofMilliSatoshis(2),
3,
Coins.ofMilliSatoshis(4),
false,
true
);
}

View File

@@ -0,0 +1,8 @@
package de.cotto.lndmanagej.model;
public class PolicyFixtures {
public static final Policy POLICY_1 = new Policy(100, Coins.ofMilliSatoshis(10), false);
public static final Policy POLICY_2 = new Policy(222, Coins.ofMilliSatoshis(0), true);
public static final Policies POLICIES = new Policies(POLICY_1, POLICY_2);
}

View File

@@ -4,9 +4,9 @@ import de.cotto.lndmanagej.metrics.Metrics;
import de.cotto.lndmanagej.model.Coins;
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.OnChainCostService;
import de.cotto.lndmanagej.service.PolicyService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
@@ -20,7 +20,6 @@ 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.ChannelPointFixtures.CHANNEL_POINT;
import static de.cotto.lndmanagej.model.FeeConfigurationFixtures.FEE_CONFIGURATION;
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.LocalOpenChannelFixtures.LOCAL_OPEN_CHANNEL_PRIVATE;
@@ -29,6 +28,7 @@ import static de.cotto.lndmanagej.model.LocalOpenChannelFixtures.TOTAL_RECEIVED_
import static de.cotto.lndmanagej.model.LocalOpenChannelFixtures.TOTAL_SENT;
import static de.cotto.lndmanagej.model.LocalOpenChannelFixtures.TOTAL_SENT_2;
import static de.cotto.lndmanagej.model.NodeFixtures.ALIAS_2;
import static de.cotto.lndmanagej.model.PolicyFixtures.POLICIES;
import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY_2;
import static org.hamcrest.core.Is.is;
import static org.mockito.Mockito.when;
@@ -60,7 +60,7 @@ class ChannelControllerIT {
private BalanceService balanceService;
@MockBean
private FeeService feeService;
private PolicyService policyService;
@Test
void getBasicInformation_not_found() throws Exception {
@@ -96,7 +96,7 @@ class ChannelControllerIT {
@Test
void getChannelDetails() throws Exception {
when(feeService.getFeeConfiguration(CHANNEL_ID)).thenReturn(FEE_CONFIGURATION);
when(policyService.getPolicies(CHANNEL_ID)).thenReturn(POLICIES);
when(nodeService.getAlias(PUBKEY_2)).thenReturn(ALIAS_2);
when(channelService.getLocalChannel(CHANNEL_ID)).thenReturn(Optional.of(LOCAL_OPEN_CHANNEL_PRIVATE));
when(onChainCostService.getOpenCosts(CHANNEL_ID)).thenReturn(Optional.of(Coins.ofSatoshis(1000)));
@@ -126,12 +126,12 @@ class ChannelControllerIT {
.andExpect(jsonPath("$.balance.remoteBalance", is("223")))
.andExpect(jsonPath("$.balance.remoteReserve", is("20")))
.andExpect(jsonPath("$.balance.remoteAvailable", is("203")))
.andExpect(jsonPath("$.feeConfiguration.enabledLocal", is(false)))
.andExpect(jsonPath("$.feeConfiguration.enabledRemote", is(true)))
.andExpect(jsonPath("$.feeConfiguration.outgoingFeeRatePpm", is(1)))
.andExpect(jsonPath("$.feeConfiguration.outgoingBaseFeeMilliSat", is(2)))
.andExpect(jsonPath("$.feeConfiguration.incomingFeeRatePpm", is(3)))
.andExpect(jsonPath("$.feeConfiguration.incomingBaseFeeMilliSat", is(4)));
.andExpect(jsonPath("$.policies.local.enabled", is(false)))
.andExpect(jsonPath("$.policies.remote.enabled", is(true)))
.andExpect(jsonPath("$.policies.local.feeRatePpm", is(100)))
.andExpect(jsonPath("$.policies.local.baseFeeMilliSat", is(10)))
.andExpect(jsonPath("$.policies.remote.feeRatePpm", is(222)))
.andExpect(jsonPath("$.policies.remote.baseFeeMilliSat", is(0)));
}
@Test
@@ -154,15 +154,15 @@ class ChannelControllerIT {
}
@Test
void getFeeConfiguration() throws Exception {
void getPolicies() throws Exception {
when(channelService.getLocalChannel(CHANNEL_ID)).thenReturn(Optional.of(LOCAL_OPEN_CHANNEL));
when(feeService.getFeeConfiguration(CHANNEL_ID)).thenReturn(FEE_CONFIGURATION);
mockMvc.perform(get(CHANNEL_PREFIX + "/fee-configuration"))
.andExpect(jsonPath("$.outgoingFeeRatePpm", is(1)))
.andExpect(jsonPath("$.outgoingBaseFeeMilliSat", is(2)))
.andExpect(jsonPath("$.incomingFeeRatePpm", is(3)))
.andExpect(jsonPath("$.incomingBaseFeeMilliSat", is(4)))
.andExpect(jsonPath("$.enabledLocal", is(false)))
.andExpect(jsonPath("$.enabledRemote", is(true)));
when(policyService.getPolicies(CHANNEL_ID)).thenReturn(POLICIES);
mockMvc.perform(get(CHANNEL_PREFIX + "/policies"))
.andExpect(jsonPath("$.local.feeRatePpm", is(100)))
.andExpect(jsonPath("$.local.baseFeeMilliSat", is(10)))
.andExpect(jsonPath("$.remote.feeRatePpm", is(222)))
.andExpect(jsonPath("$.remote.baseFeeMilliSat", is(0)))
.andExpect(jsonPath("$.local.enabled", is(false)))
.andExpect(jsonPath("$.remote.enabled", is(true)));
}
}

View File

@@ -4,22 +4,22 @@ import com.codahale.metrics.MetricRegistry;
import de.cotto.lndmanagej.controller.dto.BalanceInformationDto;
import de.cotto.lndmanagej.controller.dto.ChannelDetailsDto;
import de.cotto.lndmanagej.controller.dto.ChannelDto;
import de.cotto.lndmanagej.controller.dto.FeeConfigurationDto;
import de.cotto.lndmanagej.controller.dto.ObjectMapperConfiguration;
import de.cotto.lndmanagej.controller.dto.OnChainCostsDto;
import de.cotto.lndmanagej.controller.dto.PoliciesDto;
import de.cotto.lndmanagej.metrics.Metrics;
import de.cotto.lndmanagej.model.BalanceInformation;
import de.cotto.lndmanagej.model.ChannelId;
import de.cotto.lndmanagej.model.Coins;
import de.cotto.lndmanagej.model.FeeConfiguration;
import de.cotto.lndmanagej.model.LocalChannel;
import de.cotto.lndmanagej.model.OpenCloseStatus;
import de.cotto.lndmanagej.model.Policies;
import de.cotto.lndmanagej.model.Pubkey;
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.OnChainCostService;
import de.cotto.lndmanagej.service.PolicyService;
import org.springframework.context.annotation.Import;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
@@ -37,14 +37,14 @@ public class ChannelController {
private final Metrics metrics;
private final BalanceService balanceService;
private final OnChainCostService onChainCostService;
private final FeeService feeService;
private final PolicyService policyService;
public ChannelController(
ChannelService channelService,
NodeService nodeService,
BalanceService balanceService,
OnChainCostService onChainCostService,
FeeService feeService,
PolicyService policyService,
Metrics metrics
) {
this.channelService = channelService;
@@ -52,7 +52,7 @@ public class ChannelController {
this.balanceService = balanceService;
this.onChainCostService = onChainCostService;
this.metrics = metrics;
this.feeService = feeService;
this.policyService = policyService;
}
@GetMapping("/")
@@ -79,7 +79,7 @@ public class ChannelController {
remoteAlias,
getBalanceInformation(channelId),
getOnChainCosts(channelId),
getFeeConfiguration(localChannel)
getPolicies(localChannel)
);
}
@@ -91,19 +91,19 @@ public class ChannelController {
return BalanceInformationDto.createFrom(balanceInformation);
}
@GetMapping("/fee-configuration")
public FeeConfigurationDto getFeeConfiguration(@PathVariable ChannelId channelId) {
metrics.mark(MetricRegistry.name(getClass(), "getFeeConfiguration"));
@GetMapping("/policies")
public PoliciesDto getPolicies(@PathVariable ChannelId channelId) {
metrics.mark(MetricRegistry.name(getClass(), "getPolicies"));
LocalChannel localChannel = channelService.getLocalChannel(channelId).orElse(null);
return getFeeConfiguration(localChannel);
return getPolicies(localChannel);
}
private FeeConfigurationDto getFeeConfiguration(@Nullable LocalChannel channel) {
private PoliciesDto getPolicies(@Nullable LocalChannel channel) {
if (channel == null || channel.getStatus().openCloseStatus() != OpenCloseStatus.OPEN) {
return FeeConfigurationDto.EMPTY;
return PoliciesDto.EMPTY;
}
FeeConfiguration feeConfiguration = feeService.getFeeConfiguration(channel.getId());
return FeeConfigurationDto.createFrom(feeConfiguration);
Policies policies = policyService.getPolicies(channel.getId());
return PoliciesDto.createFrom(policies);
}
private BalanceInformation getBalanceInformation(ChannelId channelId) {

View File

@@ -21,14 +21,14 @@ public record ChannelDetailsDto(
ChannelStatusDto status,
BalanceInformationDto balance,
OnChainCostsDto onChainCosts,
FeeConfigurationDto feeConfiguration
PoliciesDto policies
) {
public ChannelDetailsDto(
ChannelDto channelDto,
String remoteAlias,
BalanceInformation balanceInformation,
OnChainCostsDto onChainCosts,
FeeConfigurationDto feeConfiguration
PoliciesDto policies
) {
this(
channelDto.channelIdShort(),
@@ -45,7 +45,7 @@ public record ChannelDetailsDto(
channelDto.status(),
BalanceInformationDto.createFrom(balanceInformation),
onChainCosts,
feeConfiguration
policies
);
}
@@ -54,14 +54,14 @@ public record ChannelDetailsDto(
String remoteAlias,
BalanceInformation balanceInformation,
OnChainCostsDto onChainCosts,
FeeConfigurationDto feeConfiguration
PoliciesDto policies
) {
this(
new ChannelDto(localChannel),
remoteAlias,
balanceInformation,
onChainCosts,
feeConfiguration
policies
);
}
}

View File

@@ -1,33 +0,0 @@
package de.cotto.lndmanagej.controller.dto;
import de.cotto.lndmanagej.model.FeeConfiguration;
public record FeeConfigurationDto(
long outgoingFeeRatePpm,
long outgoingBaseFeeMilliSat,
long incomingFeeRatePpm,
long incomingBaseFeeMilliSat,
boolean enabledLocal,
boolean enabledRemote
) {
public static final FeeConfigurationDto EMPTY =
new FeeConfigurationDto(
0,
0,
0,
0,
false,
false
);
public static FeeConfigurationDto createFrom(FeeConfiguration feeConfiguration) {
return new FeeConfigurationDto(
feeConfiguration.outgoingFeeRate(),
feeConfiguration.outgoingBaseFee().milliSatoshis(),
feeConfiguration.incomingFeeRate(),
feeConfiguration.incomingBaseFee().milliSatoshis(),
feeConfiguration.enabledLocal(),
feeConfiguration.enabledRemote()
);
}
}

View File

@@ -0,0 +1,18 @@
package de.cotto.lndmanagej.controller.dto;
import de.cotto.lndmanagej.model.Policies;
public record PoliciesDto(
PolicyDto local,
PolicyDto remote
) {
public static final PoliciesDto EMPTY =
new PoliciesDto(PolicyDto.EMPTY, PolicyDto.EMPTY);
public static PoliciesDto createFrom(Policies policies) {
return new PoliciesDto(
PolicyDto.createFrom(policies.local()),
PolicyDto.createFrom(policies.remote())
);
}
}

View File

@@ -0,0 +1,24 @@
package de.cotto.lndmanagej.controller.dto;
import de.cotto.lndmanagej.model.Policy;
public record PolicyDto(
long feeRatePpm,
long baseFeeMilliSat,
boolean enabled
) {
public static final PolicyDto EMPTY =
new PolicyDto(
0,
0,
false
);
public static PolicyDto createFrom(Policy policy) {
return new PolicyDto(
policy.feeRate(),
policy.baseFee().milliSatoshis(),
policy.enabled()
);
}
}

View File

@@ -3,17 +3,17 @@ package de.cotto.lndmanagej.controller;
import de.cotto.lndmanagej.controller.dto.BalanceInformationDto;
import de.cotto.lndmanagej.controller.dto.ChannelDetailsDto;
import de.cotto.lndmanagej.controller.dto.ChannelDto;
import de.cotto.lndmanagej.controller.dto.FeeConfigurationDto;
import de.cotto.lndmanagej.controller.dto.OnChainCostsDto;
import de.cotto.lndmanagej.controller.dto.PoliciesDto;
import de.cotto.lndmanagej.metrics.Metrics;
import de.cotto.lndmanagej.model.BalanceInformation;
import de.cotto.lndmanagej.model.Coins;
import de.cotto.lndmanagej.model.LocalChannel;
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.OnChainCostService;
import de.cotto.lndmanagej.service.PolicyService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -26,10 +26,10 @@ import java.util.Optional;
import static de.cotto.lndmanagej.model.BalanceInformationFixtures.BALANCE_INFORMATION;
import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID;
import static de.cotto.lndmanagej.model.CoopClosedChannelFixtures.CLOSED_CHANNEL;
import static de.cotto.lndmanagej.model.FeeConfigurationFixtures.FEE_CONFIGURATION;
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.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;
@@ -44,7 +44,7 @@ class ChannelControllerTest {
private static final Coins OPEN_COSTS = Coins.ofSatoshis(1);
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 FeeConfigurationDto FEE_CONFIGURATION_DTO = FeeConfigurationDto.createFrom(FEE_CONFIGURATION);
private static final PoliciesDto FEE_CONFIGURATION_DTO = PoliciesDto.createFrom(POLICIES);
@InjectMocks
private ChannelController channelController;
@@ -65,13 +65,13 @@ class ChannelControllerTest {
private OnChainCostService onChainCostService;
@Mock
private FeeService feeService;
private PolicyService policyService;
@BeforeEach
void setUp() {
lenient().when(onChainCostService.getOpenCosts(CHANNEL_ID)).thenReturn(Optional.of(OPEN_COSTS));
lenient().when(onChainCostService.getCloseCosts(CHANNEL_ID)).thenReturn(Optional.of(CLOSE_COSTS));
lenient().when(feeService.getFeeConfiguration(CHANNEL_ID)).thenReturn(FEE_CONFIGURATION);
lenient().when(policyService.getPolicies(CHANNEL_ID)).thenReturn(POLICIES);
}
@Test
@@ -131,13 +131,13 @@ class ChannelControllerTest {
@Test
void getDetails_closed() throws NotFoundException {
ChannelDetailsDto expectedDetails = mockForChannelWithoutFeeConfiguration(CLOSED_CHANNEL);
ChannelDetailsDto expectedDetails = mockForChannelWithoutPolicies(CLOSED_CHANNEL);
assertThat(channelController.getDetails(CHANNEL_ID)).isEqualTo(expectedDetails);
}
@Test
void getDetails_waiting_close() throws NotFoundException {
ChannelDetailsDto expectedDetails = mockForChannelWithoutFeeConfiguration(WAITING_CLOSE_CHANNEL);
ChannelDetailsDto expectedDetails = mockForChannelWithoutPolicies(WAITING_CLOSE_CHANNEL);
assertThat(channelController.getDetails(CHANNEL_ID)).isEqualTo(expectedDetails);
}
@@ -158,19 +158,19 @@ class ChannelControllerTest {
}
@Test
void getFeeConfiguration() {
void getPolicies() {
when(channelService.getLocalChannel(CHANNEL_ID)).thenReturn(Optional.of(LOCAL_OPEN_CHANNEL));
when(feeService.getFeeConfiguration(CHANNEL_ID)).thenReturn(FEE_CONFIGURATION);
assertThat(channelController.getFeeConfiguration(CHANNEL_ID)).isEqualTo(FEE_CONFIGURATION_DTO);
verify(metrics).mark(argThat(name -> name.endsWith(".getFeeConfiguration")));
when(policyService.getPolicies(CHANNEL_ID)).thenReturn(POLICIES);
assertThat(channelController.getPolicies(CHANNEL_ID)).isEqualTo(FEE_CONFIGURATION_DTO);
verify(metrics).mark(argThat(name -> name.endsWith(".getPolicies")));
}
@Test
void getFeeConfiguration_waiting_close() {
assertThat(channelController.getFeeConfiguration(CHANNEL_ID)).isEqualTo(FeeConfigurationDto.EMPTY);
void getPolicies_waiting_close() {
assertThat(channelController.getPolicies(CHANNEL_ID)).isEqualTo(PoliciesDto.EMPTY);
}
private ChannelDetailsDto mockForChannelWithoutFeeConfiguration(LocalChannel channel) {
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());
@@ -179,7 +179,7 @@ class ChannelControllerTest {
ALIAS_2,
BalanceInformation.EMPTY,
ON_CHAIN_COSTS,
FeeConfigurationDto.EMPTY
PoliciesDto.EMPTY
);
}
}

View File

@@ -24,7 +24,7 @@ class ChannelDetailsDtoTest {
ALIAS,
BALANCE_INFORMATION,
ON_CHAIN_COSTS,
FeeConfigurationDto.EMPTY
PoliciesDto.EMPTY
);
@Test
@@ -79,7 +79,7 @@ class ChannelDetailsDtoTest {
ALIAS,
BALANCE_INFORMATION,
ON_CHAIN_COSTS,
FeeConfigurationDto.EMPTY
PoliciesDto.EMPTY
);
ChannelStatusDto channelStatusDto =
ChannelStatusDto.createFrom(new ChannelStatus(false, true, false, OPEN));

View File

@@ -1,24 +0,0 @@
package de.cotto.lndmanagej.controller.dto;
import org.junit.jupiter.api.Test;
import static de.cotto.lndmanagej.model.FeeConfigurationFixtures.FEE_CONFIGURATION;
import static org.assertj.core.api.Assertions.assertThat;
class FeeConfigurationDtoTest {
@Test
void createFrom() {
FeeConfigurationDto expected = new FeeConfigurationDto(
1,
2,
3,
4,
false,
true
);
FeeConfigurationDto dto = FeeConfigurationDto.createFrom(FEE_CONFIGURATION);
assertThat(dto).isEqualTo(expected);
}
}

View File

@@ -0,0 +1,19 @@
package de.cotto.lndmanagej.controller.dto;
import org.junit.jupiter.api.Test;
import static de.cotto.lndmanagej.model.PolicyFixtures.POLICIES;
import static de.cotto.lndmanagej.model.PolicyFixtures.POLICY_1;
import static de.cotto.lndmanagej.model.PolicyFixtures.POLICY_2;
import static org.assertj.core.api.Assertions.assertThat;
class PoliciesDtoTest {
@Test
void createFrom() {
PoliciesDto expected = new PoliciesDto(PolicyDto.createFrom(POLICY_1), PolicyDto.createFrom(POLICY_2));
PoliciesDto dto = PoliciesDto.createFrom(POLICIES);
assertThat(dto).isEqualTo(expected);
}
}

View File

@@ -0,0 +1,15 @@
package de.cotto.lndmanagej.controller.dto;
import org.junit.jupiter.api.Test;
import static de.cotto.lndmanagej.model.PolicyFixtures.POLICY_1;
import static org.assertj.core.api.Assertions.assertThat;
class PolicyDtoTest {
@Test
void createFrom() {
PolicyDto expected = new PolicyDto(100, 10, false);
PolicyDto dto = PolicyDto.createFrom(POLICY_1);
assertThat(dto).isEqualTo(expected);
}
}