From 25b41b13d6a4e5c650f35b620f7e838c51c02f2a Mon Sep 17 00:00:00 2001 From: kubel Date: Tue, 6 Aug 2024 12:23:34 +0200 Subject: [PATCH] Publish session settle before proposal approve --- .../SignClientInstrumentedAndroidTest.kt | 37 +++++++++++-------- .../use_case/calls/ApproveSessionUseCase.kt | 5 ++- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/protocol/sign/src/androidTest/kotlin/com/walletconnect/sign/test/client/SignClientInstrumentedAndroidTest.kt b/protocol/sign/src/androidTest/kotlin/com/walletconnect/sign/test/client/SignClientInstrumentedAndroidTest.kt index df17e9d0f..71af311c5 100644 --- a/protocol/sign/src/androidTest/kotlin/com/walletconnect/sign/test/client/SignClientInstrumentedAndroidTest.kt +++ b/protocol/sign/src/androidTest/kotlin/com/walletconnect/sign/test/client/SignClientInstrumentedAndroidTest.kt @@ -60,6 +60,20 @@ class SignClientInstrumentedAndroidTest { launch(walletDelegate, dappDelegate) } + @Test + fun receiveSessionProposal() { + Timber.d("receiveRejectSession: start") + + val walletDelegate = object : WalletDelegate() { + override fun onSessionProposal(sessionProposal: Sign.Model.SessionProposal, verifyContext: Sign.Model.VerifyContext) { + scenarioExtension.closeAsSuccess().also { Timber.d("proposal received: finish") } + } + } + val dappDelegate = object : DappDelegate() {} + + launch(walletDelegate, dappDelegate) + } + @Test fun receiveRejectSession() { Timber.d("receiveRejectSession: start") @@ -312,22 +326,13 @@ class SignClientInstrumentedAndroidTest { } private fun pairDappAndWallet(onPairSuccess: (pairing: Core.Model.Pairing) -> Unit) { - TestClient.Dapp.Pairing.getPairings().let { pairings -> - if (pairings.isEmpty()) { - Timber.d("pairings.isEmpty() == true") - - val pairing: Core.Model.Pairing = (TestClient.Dapp.Pairing.create(onError = ::globalOnError) ?: fail("Unable to create a Pairing")) as Core.Model.Pairing - Timber.d("DappClient.pairing.create: $pairing") - - TestClient.Wallet.Pairing.pair(Core.Params.Pair(pairing.uri), onError = ::globalOnError, onSuccess = { - Timber.d("WalletClient.pairing.pair: $pairing") - onPairSuccess(pairing) - }) - } else { - Timber.d("pairings.isEmpty() == false") - fail("Pairing already exists. Storage must be cleared in between runs") - } - } + val pairing: Core.Model.Pairing = (TestClient.Dapp.Pairing.create(onError = ::globalOnError) ?: fail("Unable to create a Pairing")) as Core.Model.Pairing + Timber.d("DappClient.pairing.create: $pairing") + + TestClient.Wallet.Pairing.pair(Core.Params.Pair(pairing.uri), onError = ::globalOnError, onSuccess = { + Timber.d("WalletClient.pairing.pair: $pairing") + onPairSuccess(pairing) + }) } private fun pairAndConnect() { diff --git a/protocol/sign/src/main/kotlin/com/walletconnect/sign/engine/use_case/calls/ApproveSessionUseCase.kt b/protocol/sign/src/main/kotlin/com/walletconnect/sign/engine/use_case/calls/ApproveSessionUseCase.kt index eabbb6783..5ad0f991a 100644 --- a/protocol/sign/src/main/kotlin/com/walletconnect/sign/engine/use_case/calls/ApproveSessionUseCase.kt +++ b/protocol/sign/src/main/kotlin/com/walletconnect/sign/engine/use_case/calls/ApproveSessionUseCase.kt @@ -156,6 +156,9 @@ internal class ApproveSessionUseCase( }.also { logger.error("Subscribe to session topic failure: $error") } onFailure(error) }) + + sessionSettle(request.id, proposal, sessionTopic, request.topic) + trace.add(Trace.Session.PUBLISHING_SESSION_APPROVE).also { logger.log("Publishing session approve on topic: $sessionTopic") } jsonRpcInteractor.respondWithParams(request, approvalParams, irnParams, onSuccess = { @@ -169,8 +172,6 @@ internal class ApproveSessionUseCase( }.also { logger.error("Session approve failure, topic: $sessionTopic: $error") } onFailure(error) }) - - sessionSettle(request.id, proposal, sessionTopic, request.topic) } catch (e: Exception) { if (e is NoRelayConnectionException) insertEventUseCase(Props(type = EventType.Error.NO_WSS_CONNECTION, properties = Properties(trace = trace, topic = pairingTopic))) if (e is NoInternetConnectionException) insertEventUseCase(Props(type = EventType.Error.NO_INTERNET_CONNECTION, properties = Properties(trace = trace, topic = pairingTopic)))