diff --git a/protocol/sign/src/main/kotlin/com/walletconnect/sign/di/EngineModule.kt b/protocol/sign/src/main/kotlin/com/walletconnect/sign/di/EngineModule.kt index 502e34c24..2f29c4c24 100644 --- a/protocol/sign/src/main/kotlin/com/walletconnect/sign/di/EngineModule.kt +++ b/protocol/sign/src/main/kotlin/com/walletconnect/sign/di/EngineModule.kt @@ -25,7 +25,7 @@ internal fun engineModule() = module { single { GetPendingAuthenticateRequestUseCase(jsonRpcHistory = get(), serializer = get()) } - single { DeleteRequestByIdUseCase(jsonRpcHistory = get()) } + single { DeleteRequestByIdUseCase(jsonRpcHistory = get(), verifyContextStorageRepository = get()) } single { GetPendingJsonRpcHistoryEntryByIdUseCase(jsonRpcHistory = get(), serializer = get()) } diff --git a/protocol/sign/src/main/kotlin/com/walletconnect/sign/json_rpc/domain/DeleteRequestByIdUseCase.kt b/protocol/sign/src/main/kotlin/com/walletconnect/sign/json_rpc/domain/DeleteRequestByIdUseCase.kt index c888cef44..8fef1eb48 100644 --- a/protocol/sign/src/main/kotlin/com/walletconnect/sign/json_rpc/domain/DeleteRequestByIdUseCase.kt +++ b/protocol/sign/src/main/kotlin/com/walletconnect/sign/json_rpc/domain/DeleteRequestByIdUseCase.kt @@ -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) } } } \ No newline at end of file diff --git a/protocol/sign/src/test/kotlin/com/walletconnect/sign/DeleteRequestByIdUseCaseTest.kt b/protocol/sign/src/test/kotlin/com/walletconnect/sign/DeleteRequestByIdUseCaseTest.kt new file mode 100644 index 000000000..68b5f22fa --- /dev/null +++ b/protocol/sign/src/test/kotlin/com/walletconnect/sign/DeleteRequestByIdUseCaseTest.kt @@ -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() + val id = 123L + + deleteRequestByIdUseCase.invoke(id) + + coVerify(exactly = 1) { jsonRpcHistory.deleteRecordById(capture(idSlot)) } + coVerify(exactly = 1) { verifyContextStorageRepository.delete(capture(idSlot)) } + } +} \ No newline at end of file