mirror of
https://github.com/aljazceru/lnd-manageJ.git
synced 2026-01-27 09:54:51 +01:00
parse channel ID from all supported formats
This commit is contained in:
committed by
Carsten Otto
parent
6695e74b46
commit
aa51837cd6
@@ -1,6 +1,7 @@
|
||||
package de.cotto.lndmanagej.controller;
|
||||
|
||||
import de.cotto.lndmanagej.model.ChannelIdResolver;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
@@ -10,9 +11,11 @@ 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.ChannelIdFixtures.CHANNEL_ID_COMPACT;
|
||||
import static de.cotto.lndmanagej.model.ChannelPointFixtures.CHANNEL_POINT;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@@ -50,4 +53,70 @@ class ChannelIdConverterTest {
|
||||
assertThatExceptionOfType(IllegalArgumentException.class)
|
||||
.isThrownBy(() -> channelIdConverter.convert(CHANNEL_POINT.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
class TryToConvert {
|
||||
@Test
|
||||
void valid_short_channel_id() {
|
||||
assertThat(channelIdConverter.tryToConvert(String.valueOf(CHANNEL_ID.getShortChannelId())))
|
||||
.contains(CHANNEL_ID);
|
||||
}
|
||||
|
||||
@Test
|
||||
void just_numbers_small_number() {
|
||||
assertThat(channelIdConverter.tryToConvert("123")).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void just_numbers_too_early() {
|
||||
assertThat(channelIdConverter.tryToConvert("430103660018532351")).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void compact_form_valid() {
|
||||
assertThat(channelIdConverter.tryToConvert(CHANNEL_ID_COMPACT)).contains(CHANNEL_ID);
|
||||
}
|
||||
|
||||
@Test
|
||||
void compact_form_too_early() {
|
||||
assertThat(channelIdConverter.tryToConvert("300000x123x1")).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void compact_lnd_form_valid() {
|
||||
assertThat(channelIdConverter.tryToConvert(CHANNEL_ID.getCompactFormLnd())).contains(CHANNEL_ID);
|
||||
}
|
||||
|
||||
@Test
|
||||
void compact_lnd_form_too_early() {
|
||||
assertThat(channelIdConverter.tryToConvert("300000:123:1")).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void channel_point_valid() {
|
||||
when(channelIdResolver.resolveFromChannelPoint(CHANNEL_POINT)).thenReturn(Optional.of(CHANNEL_ID));
|
||||
assertThat(channelIdConverter.tryToConvert(CHANNEL_POINT.toString())).contains(CHANNEL_ID);
|
||||
}
|
||||
|
||||
@Test
|
||||
void channel_point_not_found() {
|
||||
assertThat(channelIdConverter.tryToConvert(CHANNEL_POINT.toString())).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void channel_point_lookalike() {
|
||||
assertThat(channelIdConverter.tryToConvert("abc:1")).isEmpty();
|
||||
verifyNoInteractions(channelIdResolver);
|
||||
}
|
||||
|
||||
@Test
|
||||
void weird_string() {
|
||||
assertThat(channelIdConverter.tryToConvert("[123$!12123.. peter")).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void empty_string() {
|
||||
assertThat(channelIdConverter.tryToConvert("[123$!12123.. peter")).isEmpty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user