Skip to content

Commit

Permalink
Add test for format=nodeId and shortChannelId
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohit Kumar committed Aug 31, 2023
1 parent 6f6807c commit c60dda4
Show file tree
Hide file tree
Showing 4 changed files with 242 additions and 90 deletions.
76 changes: 58 additions & 18 deletions src/nativeTest/kotlin/commands/FindRouteBetweenNodesTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,67 @@ import kotlin.test.*

@OptIn(ExperimentalCli::class)
class FindRouteBetweenNodesCommandTest {
private fun runTest(eclairClient: IEclairClientBuilder): DummyResultWriter {
private fun runTest(eclairClient: IEclairClientBuilder, format: String? = null): DummyResultWriter {
val resultWriter = DummyResultWriter()
val command = FindRouteBetweenNodesCommand(resultWriter, eclairClient)
val parser = ArgParser("test")
parser.subcommands(command)
parser.parse(
arrayOf(
"findroutebetweennodes",
"-p",
"password",
"--sourceNodeId",
"03c5b161c16e9f8ef3f3bccfb74a6e9a3b423dd41fe2848174b7209f1c2ea25dad",
"--targetNodeId",
"02f666711319435b7905dd77d10c269d8d50c02668b975f526577167d370b50a3e",
"--amountMsat",
"1000"
)
val arguments = mutableListOf(
"findroutebetweennodes",
"-p",
"password",
"--sourceNodeId",
"03c5b161c16e9f8ef3f3bccfb74a6e9a3b423dd41fe2848174b7209f1c2ea25dad",
"--targetNodeId",
"02f666711319435b7905dd77d10c269d8d50c02668b975f526577167d370b50a3e",
"--amountMsat",
"1000"
)
format?.let { arguments.addAll(listOf("--format", it)) }
parser.parse(arguments.toTypedArray())
return resultWriter
}

@Test
fun `successful request`() {
fun `successful request via nodeId`() {
val resultWriter =
runTest(DummyEclairClient(findroutebetweennodesResponse = DummyEclairClient.validFindRouteBetweenNodesResponse))
runTest(DummyEclairClient(), "nodeId")
assertNull(resultWriter.lastError)
assertNotNull(resultWriter.lastResult)
val format = Json { ignoreUnknownKeys = true }
assertEquals(
format.decodeFromString(
FindRouteResponse.serializer(),
DummyEclairClient.validFindRouteBetweenNodesResponse
DummyEclairClient.validRouteResponseNodeId
),
format.decodeFromString(FindRouteResponse.serializer(), resultWriter.lastResult!!),
)
}

@Test
fun `successful request via shortChannelId`() {
val resultWriter = runTest(DummyEclairClient(), "shortChannelId")
assertNull(resultWriter.lastError)
assertNotNull(resultWriter.lastResult)
val format = Json { ignoreUnknownKeys = true }
assertEquals(
format.decodeFromString(FindRouteResponse.serializer(), DummyEclairClient.validRouteResponseShortChannelId),
format.decodeFromString(FindRouteResponse.serializer(), resultWriter.lastResult!!)
)
}

@Test
fun `successful request via full`() {
val resultWriter = runTest(DummyEclairClient(), "full")
assertNull(resultWriter.lastError)
assertNotNull(resultWriter.lastResult)
val format = Json { ignoreUnknownKeys = true }
assertEquals(
format.decodeFromString(FindRouteResponse.serializer(), DummyEclairClient.validRouteResponseFull),
format.decodeFromString(FindRouteResponse.serializer(), resultWriter.lastResult!!),
)
}

@Test
fun `api error`() {
val error = ApiError(42, "test failure message")
Expand All @@ -59,8 +83,24 @@ class FindRouteBetweenNodesCommandTest {
}

@Test
fun `serialization error`() {
val resultWriter = runTest(DummyEclairClient(findroutebetweennodesResponse = "{invalidJson}"))
fun `serialization error via nodeId`() {
val resultWriter = runTest(DummyEclairClient(findrouteResponseNodeId = "{invalidJson}"), "nodeId")
assertNull(resultWriter.lastResult)
assertNotNull(resultWriter.lastError)
assertTrue(resultWriter.lastError!!.message.contains("api response could not be parsed"))
}

@Test
fun `serialization error via shortChannelId`() {
val resultWriter = runTest(DummyEclairClient(findrouteResponseShortChannelId = "{invalidJson}"), "shortChannelId")
assertNull(resultWriter.lastResult)
assertNotNull(resultWriter.lastError)
assertTrue(resultWriter.lastError!!.message.contains("api response could not be parsed"))
}

@Test
fun `serialization error via full`() {
val resultWriter = runTest(DummyEclairClient(findrouteResponseFull = "{invalidJson}"), "full")
assertNull(resultWriter.lastResult)
assertNotNull(resultWriter.lastError)
assertTrue(resultWriter.lastError!!.message.contains("api response could not be parsed"))
Expand Down
70 changes: 54 additions & 16 deletions src/nativeTest/kotlin/commands/FindRouteTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,55 @@ import kotlin.test.*

@OptIn(ExperimentalCli::class)
class FindRouteCommandTest {
private fun runTest(eclairClient: IEclairClientBuilder): DummyResultWriter {
private fun runTest(eclairClient: IEclairClientBuilder, format: String? = null): DummyResultWriter {
val resultWriter = DummyResultWriter()
val command = FindRouteCommand(resultWriter, eclairClient)
val parser = ArgParser("test")
parser.subcommands(command)
parser.parse(
arrayOf(
"findroute",
"-p",
"password",
"--invoice",
"lnbcrt10n1pjduajwpp5s6dsm9vk3q0ntxeq2zd6d4jz8mv8wau75dugud5puc3lltwp68esdqsd3shgetnw33k7er9sp5rye5z7eccrg7kx9jj6u24q2aumgl09e0e894w6hdceyk60g7a2hsmqz9gxqrrsscqp79q7sqqqqqqqqqqqqqqqqqqqsqqqqqysgq9fktzq8fpyey9js0x85t6s5mtcwqzmmd4ql9cjq04f4tunlysje894mdcmhjwkewrk5wn2ylv3da64pda7tj04s3m90en5t6p7yyglgpue2lzz",
"--format",
"full"
)
val arguments = mutableListOf(
"findroute",
"-p",
"password",
"--invoice",
"lnbcrt10n1pjduajwpp5s6dsm9vk3q0ntxeq2zd6d4jz8mv8wau75dugud5puc3lltwp68esdqsd3shgetnw33k7er9sp5rye5z7eccrg7kx9jj6u24q2aumgl09e0e894w6hdceyk60g7a2hsmqz9gxqrrsscqp79q7sqqqqqqqqqqqqqqqqqqqsqqqqqysgq9fktzq8fpyey9js0x85t6s5mtcwqzmmd4ql9cjq04f4tunlysje894mdcmhjwkewrk5wn2ylv3da64pda7tj04s3m90en5t6p7yyglgpue2lzz"
)
format?.let { arguments.addAll(listOf("--format", it)) }
parser.parse(arguments.toTypedArray())
return resultWriter
}

@Test
fun `successful request`() {
val resultWriter = runTest(DummyEclairClient(findrouteResponse = DummyEclairClient.validFindRouteResponse))
fun `successful request via nodeId`() {
val resultWriter = runTest(DummyEclairClient(), "nodeId")
assertNull(resultWriter.lastError)
assertNotNull(resultWriter.lastResult)
val format = Json { ignoreUnknownKeys = true }
assertEquals(
format.decodeFromString(FindRouteResponse.serializer(), DummyEclairClient.validFindRouteResponse),
format.decodeFromString(FindRouteResponse.serializer(), DummyEclairClient.validRouteResponseNodeId),
format.decodeFromString(FindRouteResponse.serializer(), resultWriter.lastResult!!),
)
}

@Test
fun `successful request via shortChannelId`() {
val resultWriter = runTest(DummyEclairClient(), "shortChannelId")
assertNull(resultWriter.lastError)
assertNotNull(resultWriter.lastResult)
val format = Json { ignoreUnknownKeys = true }
assertEquals(
format.decodeFromString(FindRouteResponse.serializer(), DummyEclairClient.validRouteResponseShortChannelId),
format.decodeFromString(FindRouteResponse.serializer(), resultWriter.lastResult!!),
)
}

@Test
fun `successful request via full`() {
val resultWriter = runTest(DummyEclairClient(), "full")
assertNull(resultWriter.lastError)
assertNotNull(resultWriter.lastResult)
val format = Json { ignoreUnknownKeys = true }
assertEquals(
format.decodeFromString(FindRouteResponse.serializer(), DummyEclairClient.validRouteResponseFull),
format.decodeFromString(FindRouteResponse.serializer(), resultWriter.lastResult!!),
)
}
Expand All @@ -53,8 +75,24 @@ class FindRouteCommandTest {
}

@Test
fun `serialization error`() {
val resultWriter = runTest(DummyEclairClient(findrouteResponse = "{invalidJson}"))
fun `serialization error via nodeId`() {
val resultWriter = runTest(DummyEclairClient(findrouteResponseNodeId = "{invalidJson}"), "nodeId")
assertNull(resultWriter.lastResult)
assertNotNull(resultWriter.lastError)
assertTrue(resultWriter.lastError!!.message.contains("api response could not be parsed"))
}

@Test
fun `serialization error via shortChannelId`() {
val resultWriter = runTest(DummyEclairClient(findrouteResponseShortChannelId = "{invalidJson}"), "shortChannelId")
assertNull(resultWriter.lastResult)
assertNotNull(resultWriter.lastError)
assertTrue(resultWriter.lastError!!.message.contains("api response could not be parsed"))
}

@Test
fun `serialization error via full`() {
val resultWriter = runTest(DummyEclairClient(findrouteResponseFull = "{invalidJson}"), "full")
assertNull(resultWriter.lastResult)
assertNotNull(resultWriter.lastError)
assertTrue(resultWriter.lastError!!.message.contains("api response could not be parsed"))
Expand Down
73 changes: 56 additions & 17 deletions src/nativeTest/kotlin/commands/FindRouteToNodeTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,57 @@ import kotlin.test.*

@OptIn(ExperimentalCli::class)
class FindRouteToNodeTestCommandTest {
private fun runTest(eclairClient: IEclairClientBuilder): DummyResultWriter {
private fun runTest(eclairClient: IEclairClientBuilder, format: String? = null): DummyResultWriter {
val resultWriter = DummyResultWriter()
val command = FindRouteToNodeCommand(resultWriter, eclairClient)
val parser = ArgParser("test")
parser.subcommands(command)
parser.parse(
arrayOf(
"findroutetonode",
"-p",
"password",
"--nodeId",
"02f666711319435b7905dd77d10c269d8d50c02668b975f526577167d370b50a3e",
"--amountMsat",
"1000"
)
val arguments = mutableListOf(
"findroutetonode",
"-p",
"password",
"--nodeId",
"02f666711319435b7905dd77d10c269d8d50c02668b975f526577167d370b50a3e",
"--amountMsat",
"1000"
)
format?.let { arguments.addAll(listOf("--format", it)) }
parser.parse(arguments.toTypedArray())
return resultWriter
}

@Test
fun `successful request`() {
val resultWriter =
runTest(DummyEclairClient(findroutetonodeResponse = DummyEclairClient.validFindRouteToNodeResponse))
fun `successful request via nodeId`() {
val resultWriter = runTest(DummyEclairClient(), "nodeId")
assertNull(resultWriter.lastError)
assertNotNull(resultWriter.lastResult)
val format = Json { ignoreUnknownKeys = true }
assertEquals(
format.decodeFromString(FindRouteResponse.serializer(), DummyEclairClient.validFindRouteToNodeResponse),
format.decodeFromString(FindRouteResponse.serializer(), DummyEclairClient.validRouteResponseNodeId),
format.decodeFromString(FindRouteResponse.serializer(), resultWriter.lastResult!!),
)
}

@Test
fun `successful request via shortChannelId`() {
val resultWriter = runTest(DummyEclairClient(), "shortChannelId")
assertNull(resultWriter.lastError)
assertNotNull(resultWriter.lastResult)
val format = Json { ignoreUnknownKeys = true }
assertEquals(
format.decodeFromString(FindRouteResponse.serializer(), DummyEclairClient.validRouteResponseShortChannelId),
format.decodeFromString(FindRouteResponse.serializer(), resultWriter.lastResult!!)
)
}

@Test
fun `successful request via full`() {
val resultWriter = runTest(DummyEclairClient(), "full")
assertNull(resultWriter.lastError)
assertNotNull(resultWriter.lastResult)
val format = Json { ignoreUnknownKeys = true }
assertEquals(
format.decodeFromString(FindRouteResponse.serializer(), DummyEclairClient.validRouteResponseFull),
format.decodeFromString(FindRouteResponse.serializer(), resultWriter.lastResult!!),
)
}
Expand All @@ -54,8 +77,24 @@ class FindRouteToNodeTestCommandTest {
}

@Test
fun `serialization error`() {
val resultWriter = runTest(DummyEclairClient(findroutetonodeResponse = "{invalidJson}"))
fun `serialization error via nodeId`() {
val resultWriter = runTest(DummyEclairClient(findrouteResponseNodeId = "{invalidJson}"), "nodeId")
assertNull(resultWriter.lastResult)
assertNotNull(resultWriter.lastError)
assertTrue(resultWriter.lastError!!.message.contains("api response could not be parsed"))
}

@Test
fun `serialization error via shortChannelId`() {
val resultWriter = runTest(DummyEclairClient(findrouteResponseShortChannelId = "{invalidJson}"), "shortChannelId")
assertNull(resultWriter.lastResult)
assertNotNull(resultWriter.lastError)
assertTrue(resultWriter.lastError!!.message.contains("api response could not be parsed"))
}

@Test
fun `serialization error via full`() {
val resultWriter = runTest(DummyEclairClient(findrouteResponseFull = "{invalidJson}"), "full")
assertNull(resultWriter.lastResult)
assertNotNull(resultWriter.lastError)
assertTrue(resultWriter.lastError!!.message.contains("api response could not be parsed"))
Expand Down
Loading

0 comments on commit c60dda4

Please sign in to comment.