Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pm47 committed Jul 9, 2024
1 parent 146ffd4 commit d1daf8d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1775,7 +1775,7 @@ data class DNSAddressRequest(override val chainHash: BlockHash, val offer: Offer
override fun read(input: Input): DNSAddressRequest {
return DNSAddressRequest(
chainHash = BlockHash(LightningCodecs.bytes(input, 32)),
offer = OfferTypes.Offer.decode(LightningCodecs.bytes(input, LightningCodecs.u16(input)).decodeToString()).get(),
offer = OfferTypes.Offer(OfferTypes.Offer.tlvSerializer.read(LightningCodecs.bytes(input, LightningCodecs.u16(input)))),
languageSubtag = LightningCodecs.bytes(input, LightningCodecs.u16(input)).decodeToString()
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import fr.acinq.lightning.tests.utils.LightningTestSuite
import fr.acinq.lightning.utils.msat
import fr.acinq.lightning.utils.sat
import fr.acinq.lightning.utils.toByteVector
import fr.acinq.lightning.wire.OfferTypes.Offer
import fr.acinq.secp256k1.Hex
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.jsonArray
Expand Down Expand Up @@ -874,4 +875,19 @@ class LightningCodecsTestsCommon : LightningTestSuite() {
val onionMessage = OnionMessages.buildMessage(randomKey(), randomKey(), listOf(), OnionMessages.Destination.Recipient(EncodedNodeId(randomKey().publicKey()), null), TlvStream.empty()).right!!
assertEquals(onionMessage, OnionMessage.read(onionMessage.write()))
}

@Test
fun `encode and decode dns address request`() {
val encoded = "lno1qgsyxjtl6luzd9t3pr62xr7eemp6awnejusgf6gw45q75vcfqqqqqqqgqyeq5ym0venx2u3qwa5hg6pqw96kzmn5d968jys3v9kxjcm9gp3xjemndphhqtnrdak3gqqkyypsmuhrtwfzm85mht4a3vcp0yrlgua3u3m5uqpc6kf7nqjz6v70qwg"
val offer = Offer.decode(encoded).get()

val msg = DNSAddressRequest(Chain.Testnet.chainHash, offer, "en")
assertEquals(msg, LightningMessage.decode(LightningMessage.encode(msg)))
}

@Test
fun `encode and decode dns address response`() {
val msg = DNSAddressResponse(Chain.Testnet.chainHash, "foo@bar.baz")
assertEquals(msg, LightningMessage.decode(LightningMessage.encode(msg)))
}
}

0 comments on commit d1daf8d

Please sign in to comment.