mirror of
https://github.com/aljazceru/lnd-manageJ.git
synced 2026-01-21 15:04:22 +01:00
139 lines
5.7 KiB
Java
139 lines
5.7 KiB
Java
package de.cotto.lndmanagej.controller;
|
|
|
|
import de.cotto.lndmanagej.model.Coins;
|
|
import de.cotto.lndmanagej.service.ChannelService;
|
|
import de.cotto.lndmanagej.service.FeeService;
|
|
import de.cotto.lndmanagej.service.NodeService;
|
|
import de.cotto.lndmanagej.service.OwnNodeService;
|
|
import org.junit.jupiter.api.Test;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
|
import org.springframework.boot.test.mock.mockito.MockBean;
|
|
import org.springframework.test.web.servlet.MockMvc;
|
|
|
|
import java.util.Set;
|
|
|
|
import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID;
|
|
import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID_3;
|
|
import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID_COMPACT;
|
|
import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID_COMPACT_3;
|
|
import static de.cotto.lndmanagej.model.LocalChannelFixtures.LOCAL_CHANNEL;
|
|
import static de.cotto.lndmanagej.model.LocalChannelFixtures.LOCAL_CHANNEL_3;
|
|
import static de.cotto.lndmanagej.model.LocalChannelFixtures.LOCAL_CHANNEL_TO_NODE_3;
|
|
import static de.cotto.lndmanagej.model.NodeFixtures.ALIAS;
|
|
import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY;
|
|
import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY_2;
|
|
import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY_3;
|
|
import static org.mockito.Mockito.when;
|
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
|
|
|
@WebMvcTest(controllers = LegacyController.class)
|
|
class LegacyControllerIT {
|
|
private static final String PUBKEY_BASE = "/legacy/node/" + PUBKEY;
|
|
private static final String CHANNEL_BASE = "/legacy/channel/" + CHANNEL_ID;
|
|
private static final long FEE_RATE = 123L;
|
|
private static final Coins BASE_FEE = Coins.ofMilliSatoshis(10L);
|
|
|
|
@Autowired
|
|
private MockMvc mockMvc;
|
|
|
|
@MockBean
|
|
private NodeService nodeService;
|
|
|
|
@MockBean
|
|
private ChannelService channelService;
|
|
|
|
@MockBean
|
|
private OwnNodeService ownNodeService;
|
|
|
|
@MockBean
|
|
private FeeService feeService;
|
|
|
|
@Test
|
|
void getAlias() throws Exception {
|
|
when(nodeService.getAlias(PUBKEY)).thenReturn(ALIAS);
|
|
mockMvc.perform(get(PUBKEY_BASE + "/alias")).andExpect(content().string(ALIAS));
|
|
}
|
|
|
|
@Test
|
|
void getAlias_error() throws Exception {
|
|
mockMvc.perform(get("/legacy/node/xxx/alias")).andExpect(status().isBadRequest());
|
|
}
|
|
|
|
@Test
|
|
void getOpenChannelIds_for_peer() throws Exception {
|
|
when(channelService.getOpenChannelsWith(PUBKEY)).thenReturn(Set.of(LOCAL_CHANNEL, LOCAL_CHANNEL_3));
|
|
mockMvc.perform(get(PUBKEY_BASE + "/open-channels"))
|
|
.andExpect(content().string(CHANNEL_ID + "\n" + CHANNEL_ID_3));
|
|
}
|
|
|
|
@Test
|
|
void getOpenChannelIds() throws Exception {
|
|
when(channelService.getOpenChannels()).thenReturn(Set.of(LOCAL_CHANNEL, LOCAL_CHANNEL_3));
|
|
mockMvc.perform(get("/legacy/open-channels"))
|
|
.andExpect(content().string(CHANNEL_ID + "\n" + CHANNEL_ID_3));
|
|
}
|
|
|
|
@Test
|
|
void getOpenChannelIdsCompact() throws Exception {
|
|
when(channelService.getOpenChannels()).thenReturn(Set.of(LOCAL_CHANNEL, LOCAL_CHANNEL_3));
|
|
mockMvc.perform(get("/legacy/open-channels/compact"))
|
|
.andExpect(content().string(CHANNEL_ID_COMPACT + "\n" + CHANNEL_ID_COMPACT_3));
|
|
}
|
|
|
|
@Test
|
|
void getOpenChannelIdsPretty() throws Exception {
|
|
when(channelService.getOpenChannels()).thenReturn(Set.of(LOCAL_CHANNEL, LOCAL_CHANNEL_3));
|
|
mockMvc.perform(get("/legacy/open-channels/pretty"))
|
|
.andExpect(status().isOk());
|
|
}
|
|
|
|
@Test
|
|
void isSyncedToChain_true() throws Exception {
|
|
when(ownNodeService.isSyncedToChain()).thenReturn(true);
|
|
mockMvc.perform(get("/legacy/synced-to-chain")).andExpect(content().string("true"));
|
|
}
|
|
|
|
@Test
|
|
void isSyncedToChain_false() throws Exception {
|
|
when(ownNodeService.isSyncedToChain()).thenReturn(false);
|
|
mockMvc.perform(get("/legacy/synced-to-chain")).andExpect(content().string("false"));
|
|
}
|
|
|
|
@Test
|
|
void getPeerPubkeys() throws Exception {
|
|
when(channelService.getOpenChannels()).thenReturn(Set.of(LOCAL_CHANNEL, LOCAL_CHANNEL_TO_NODE_3));
|
|
mockMvc.perform(get("/legacy/peer-pubkeys"))
|
|
.andExpect(content().string(PUBKEY_2 + "\n" + PUBKEY_3));
|
|
}
|
|
|
|
@Test
|
|
void getIncomingFeeRate() throws Exception {
|
|
when(feeService.getIncomingFeeRate(CHANNEL_ID)).thenReturn(FEE_RATE);
|
|
mockMvc.perform(get(CHANNEL_BASE + "/incoming-fee-rate"))
|
|
.andExpect(content().string(Long.toString(FEE_RATE)));
|
|
}
|
|
|
|
@Test
|
|
void getOutgoingFeeRate() throws Exception {
|
|
when(feeService.getOutgoingFeeRate(CHANNEL_ID)).thenReturn(FEE_RATE);
|
|
mockMvc.perform(get(CHANNEL_BASE + "/outgoing-fee-rate"))
|
|
.andExpect(content().string(Long.toString(FEE_RATE)));
|
|
}
|
|
|
|
@Test
|
|
void getIncomingBaseFee() throws Exception {
|
|
when(feeService.getIncomingBaseFee(CHANNEL_ID)).thenReturn(BASE_FEE);
|
|
mockMvc.perform(get(CHANNEL_BASE + "/incoming-base-fee"))
|
|
.andExpect(content().string(String.valueOf(BASE_FEE.milliSatoshis())));
|
|
}
|
|
|
|
@Test
|
|
void getOutgoingBaseFee() throws Exception {
|
|
when(feeService.getOutgoingBaseFee(CHANNEL_ID)).thenReturn(BASE_FEE);
|
|
mockMvc.perform(get(CHANNEL_BASE + "/outgoing-base-fee"))
|
|
.andExpect(content().string(String.valueOf(BASE_FEE.milliSatoshis())));
|
|
}
|
|
} |