Skip to content

Commit 5d672b9

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

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-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: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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 = """{"id":23,"result":{},"method":"wc_sessionUpdate","params":[{"approved":true,"chainId":420}]}"""
16+
val tested = json.toByteArray().toMethodCall()
17+
assertThat(tested).isInstanceOf(Session.MethodCall.SessionUpdate::class.java)
18+
assertThat(tested.id()).isEqualTo(42)
19+
val testedAndTyped = tested as Session.MethodCall.SessionUpdate
20+
assertThat(testedAndTyped.params.chainId).isEqualTo(420)
21+
assertThat(testedAndTyped.params.approved).isTrue
22+
}
23+
24+
}
25+
}
26+

0 commit comments

Comments
 (0)