Skip to content

Commit

Permalink
capture hex response
Browse files Browse the repository at this point in the history
  • Loading branch information
decentralgabe committed Aug 13, 2024
1 parent c819561 commit f5e5337
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ internal class DhtClient(
* @throws PkarrRecordNotFoundException if the record is not found.
* @throws PkarrRecordResponseException if the response from the dht gateway is not successful.
*/
@OptIn(ExperimentalStdlibApi::class)
@Throws(PkarrRecordResponseException::class, PkarrRecordNotFoundException::class)
fun pkarrGet(id: String): Bep44Message {
val publicKey = ZBase32.decode(id)
Expand Down
18 changes: 14 additions & 4 deletions dids/src/test/kotlin/web5/sdk/dids/methods/dht/DidDhtTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,17 @@ class DidDhtTest {

@Test
fun `resolves a known did dht value`() {
val api = DidDhtApi { }
// known DID associated with our mock response, needed to verify the payload's signature
val hexResponse = "20dd194c19c350b5ee4e0e596d21fdf777a1c420bf2220ea2474bd5264d845b0aa308e23e7c826c2a912" +
"01a626742bdfb226c1ac2674030b287d414416b9ad080000000066a8fc66000084000000000400000000035f6b30045f64696400" +
"0010000100001c20003231743d303b6b3d68635732626b53634f33396d63756430655a756b7074736c75796665515249505a735" +
"26e5f4231724f5755035f7330045f646964000010000100001c2000302f69643d7066693b743d5046493b73653d68747470733a" +
"2f2f74742d6d6f636b2d706669732e7462646465762e6f7267045f646964346f7a6e3563353172756f377a363375316837343875" +
"673772773570316d71333835337974726435676174753961386d6d3866316f000010000100001c20002e2d763d303b766d3d6b30" +
"3b617574683d6b303b61736d3d6b303b696e763d6b303b64656c3d6b303b7376633d7330045f646964346f7a6e3563353172756f3" +
"77a363375316837343875673772773570316d71333835337974726435676174753961386d6d3866316f000002000100001c20001b0e" +
"68747470733a2f2f64696464687406746264646576036f726700"
val api = DidDhtApi { engine = mockEngine(hexResponse) }
val knownDid = "did:dht:ozn5c51ruo7z63u1h748ug7rw5p1mq3853ytrd5gatu9a8mm8f1o"

assertDoesNotThrow {
Expand All @@ -178,13 +187,14 @@ class DidDhtTest {
}
}

@OptIn(ExperimentalStdlibApi::class)
private fun mockEngine() = MockEngine { request ->
val hexResponse = "1ad37b5b8ed6c5fc87b64fe4849d81e7446c31b36138d03b9f6d68837123d6ae6aedf91e0340a7c83cd53b95a600" +
private val knownHexResponse =
"1ad37b5b8ed6c5fc87b64fe4849d81e7446c31b36138d03b9f6d68837123d6ae6aedf91e0340a7c83cd53b95a600" +
"ffe4a2264c3c677d7d16ca6bd30e05fa820c00000000659dd40e000004000000000200000000035f6b30045f64696400001000010000" +
"1c2000373669643d303b743d303b6b3d63506262357357792d553547333854424a79504d6f4b714632746f4c563563395a317748456b" +
"7448764c6fc0100010000100001c20002322766d3d6b303b617574683d6b303b61736d3d6b303b696e763d6b303b64656c3d6b30"

@OptIn(ExperimentalStdlibApi::class)
private fun mockEngine(hexResponse: String = knownHexResponse) = MockEngine { request ->
when {
request.url.encodedPath == "/" && request.method == HttpMethod.Put -> {
respond("Success", HttpStatusCode.OK)
Expand Down

0 comments on commit f5e5337

Please sign in to comment.