Skip to content

Commit

Permalink
Remove verify context on request expiration
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubuid committed Aug 23, 2024
1 parent c8d5a44 commit 4c403a2
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal fun engineModule() = module {

single<GetPendingAuthenticateRequestUseCaseInterface> { GetPendingAuthenticateRequestUseCase(jsonRpcHistory = get(), serializer = get()) }

single { DeleteRequestByIdUseCase(jsonRpcHistory = get()) }
single { DeleteRequestByIdUseCase(jsonRpcHistory = get(), verifyContextStorageRepository = get()) }

single { GetPendingJsonRpcHistoryEntryByIdUseCase(jsonRpcHistory = get(), serializer = get()) }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package com.walletconnect.sign.json_rpc.domain

import com.walletconnect.android.internal.common.storage.rpc.JsonRpcHistory
import com.walletconnect.android.internal.common.storage.verify.VerifyContextStorageRepository
import kotlinx.coroutines.supervisorScope

internal class DeleteRequestByIdUseCase(private val jsonRpcHistory: JsonRpcHistory) {
internal class DeleteRequestByIdUseCase(
private val jsonRpcHistory: JsonRpcHistory,
private val verifyContextStorageRepository: VerifyContextStorageRepository
) {

suspend operator fun invoke(id: Long) {
supervisorScope {
jsonRpcHistory.deleteRecordById(id)
verifyContextStorageRepository.delete(id)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.walletconnect.sign

import com.walletconnect.android.internal.common.storage.rpc.JsonRpcHistory
import com.walletconnect.android.internal.common.storage.verify.VerifyContextStorageRepository
import com.walletconnect.sign.json_rpc.domain.DeleteRequestByIdUseCase
import io.mockk.coVerify
import io.mockk.mockk
import io.mockk.slot
import kotlinx.coroutines.runBlocking
import org.junit.Before
import org.junit.Test

class DeleteRequestByIdUseCaseTest {
private lateinit var jsonRpcHistory: JsonRpcHistory
private lateinit var verifyContextStorageRepository: VerifyContextStorageRepository
private lateinit var deleteRequestByIdUseCase: DeleteRequestByIdUseCase

@Before
fun setup() {
jsonRpcHistory = mockk(relaxed = true)
verifyContextStorageRepository = mockk(relaxed = true)
deleteRequestByIdUseCase = DeleteRequestByIdUseCase(jsonRpcHistory, verifyContextStorageRepository)
}

@Test
fun `invoke should delete record by id from jsonRpcHistory and verifyContextStorageRepository`() = runBlocking {
val idSlot = slot<Long>()
val id = 123L

deleteRequestByIdUseCase.invoke(id)

coVerify(exactly = 1) { jsonRpcHistory.deleteRecordById(capture(idSlot)) }
coVerify(exactly = 1) { verifyContextStorageRepository.delete(capture(idSlot)) }
}
}

0 comments on commit 4c403a2

Please sign in to comment.