File tree Expand file tree Collapse file tree 2 files changed +40
-1
lines changed
main/kotlin/org/walletconnect/impls
test/java/org/walletconnect Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Original file line number Diff line number Diff 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 {
Original file line number Diff line number Diff line change 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+
You can’t perform that action at this time.
0 commit comments