File tree Expand file tree Collapse file tree 2 files changed +39
-1
lines changed
main/kotlin/org/walletconnect/impls
test/java/org/walletconnect Expand file tree Collapse file tree 2 files changed +39
-1
lines changed Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ class MoshiPayloadAdapter(moshi: Moshi) : Session.PayloadAdapter {
2828 /* *
2929 * Convert FROM request bytes
3030 */
31- private fun String.toMethodCall (): Session .MethodCall =
31+ internal fun String.toMethodCall (): Session .MethodCall =
3232 mapAdapter.fromJson(this )?.let {
3333 try {
3434 val method = it[" method" ]
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 TheWCSessionTest {
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.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+ }
You can’t perform that action at this time.
0 commit comments