Skip to content

Commit 2ff8396

Browse files
committed
Add test for parsing session update
to validate PR #76
1 parent 1486aa2 commit 2ff8396

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

lib/src/main/kotlin/org/walletconnect/impls/MoshiPayloadAdapter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class MoshiPayloadAdapter(moshi: Moshi) : Session.PayloadAdapter {
9393
/**
9494
* Convert FROM request bytes
9595
*/
96-
private fun ByteArray.toMethodCall(): Session.MethodCall =
96+
fun ByteArray.toMethodCall(): Session.MethodCall =
9797
String(this).let { json ->
9898
mapAdapter.fromJson(json)?.let {
9999
try {
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package org.walletconnect
2+
3+
import com.squareup.moshi.Moshi
4+
import org.assertj.core.api.Assertions.assertThat
5+
import org.junit.jupiter.api.Test
6+
import org.walletconnect.impls.MoshiPayloadAdapter
7+
8+
9+
class TheWCSession {
10+
11+
@Test
12+
fun canParseSessionUpdate() {
13+
val adapter = MoshiPayloadAdapter(Moshi.Builder().build())
14+
with(adapter) {
15+
val json = """{
16+
|"id":42,
17+
|"result":{},
18+
|"method":"wc_sessionUpdate",
19+
|"params":[{
20+
| "approved":true,
21+
| "chainId":420,
22+
| "accounts":["0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045","0xb8c2c29ee19d8307cb7255e1cd9cbde883a267d5"]
23+
|}]
24+
|}""".trimMargin()
25+
val tested = json.toByteArray().toMethodCall()
26+
assertThat(tested).isInstanceOf(Session.MethodCall.SessionUpdate::class.java)
27+
assertThat(tested.id()).isEqualTo(42)
28+
val testedAndTyped = tested as Session.MethodCall.SessionUpdate
29+
30+
assertThat(testedAndTyped.params.approved).isTrue
31+
assertThat(testedAndTyped.params.accounts).isEqualTo(
32+
listOf("0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045", "0xb8c2c29ee19d8307cb7255e1cd9cbde883a267d5")
33+
)
34+
assertThat(testedAndTyped.params.chainId).isEqualTo(420)
35+
}
36+
37+
}
38+
}
39+

0 commit comments

Comments
 (0)