Updated on 2026-08-14
This commit is contained in:
parent
4c8af6b8e9
commit
1472431435
54 changed files with 370 additions and 352 deletions
|
|
@ -26,6 +26,8 @@ import com.tangem.datasource.local.preferences.utils.getSyncOrNull
|
|||
import com.tangem.datasource.local.preferences.utils.store
|
||||
import com.tangem.domain.account.featuretoggle.AccountsFeatureToggles
|
||||
import com.tangem.domain.common.wallets.UserWalletsListRepository
|
||||
import com.tangem.domain.common.wallets.getSyncOrNull
|
||||
import com.tangem.domain.common.wallets.getSyncStrict
|
||||
import com.tangem.domain.models.wallet.UserWallet
|
||||
import com.tangem.domain.models.wallet.UserWalletId
|
||||
import com.tangem.domain.wallets.models.SeedPhraseNotificationsStatus
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import arrow.core.getOrElse
|
|||
import com.tangem.common.extensions.ByteArrayKey
|
||||
import com.tangem.crypto.hdWallet.DerivationPath
|
||||
import com.tangem.domain.common.wallets.UserWalletsListRepository
|
||||
import com.tangem.domain.common.wallets.getSyncStrict
|
||||
import com.tangem.domain.models.account.DerivationIndex
|
||||
import com.tangem.domain.models.currency.CryptoCurrency
|
||||
import com.tangem.domain.models.network.Network
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import com.tangem.crypto.hdWallet.DerivationPath
|
|||
import com.tangem.data.common.network.NetworkFactory
|
||||
import com.tangem.data.wallets.derivations.MissedDerivationsFinder
|
||||
import com.tangem.domain.common.wallets.UserWalletsListRepository
|
||||
import com.tangem.domain.common.wallets.getSyncStrict
|
||||
import com.tangem.domain.models.account.DerivationIndex
|
||||
import com.tangem.domain.models.currency.CryptoCurrency
|
||||
import com.tangem.domain.models.network.Network
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import com.tangem.domain.models.wallet.UserWalletId
|
|||
import com.tangem.domain.wallets.derivations.ColdMapDerivationsRepository
|
||||
import com.tangem.utils.coroutines.TestingCoroutineDispatcherProvider
|
||||
import io.mockk.*
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.jupiter.api.AfterEach
|
||||
import org.junit.jupiter.api.Test
|
||||
|
|
@ -51,15 +52,21 @@ internal class DefaultDerivationsRepositoryTest {
|
|||
@Test
|
||||
fun `error if userWalletId not found`() = runTest {
|
||||
val currencies = MockCryptoCurrencyFactory(defaultUserWallet).ethereum.let(::listOf)
|
||||
coEvery { userWalletsListRepository.getSyncStrict(defaultUserWalletId) } throws IllegalStateException()
|
||||
val userWalletsFlow = MutableStateFlow<List<UserWallet>?>(null)
|
||||
|
||||
every { userWalletsListRepository.userWallets } returns userWalletsFlow
|
||||
|
||||
runCatching {
|
||||
repository.derivePublicKeys(userWalletId = defaultUserWalletId, currencies = currencies)
|
||||
}
|
||||
.onSuccess { error("Should throws exception") }
|
||||
.onFailure { Truth.assertThat(it).isInstanceOf(IllegalStateException::class.java) }
|
||||
.onFailure {
|
||||
Truth.assertThat(it).isInstanceOf(IllegalArgumentException::class.java)
|
||||
Truth.assertThat(it).hasMessageThat()
|
||||
.isEqualTo("Unable to find user wallet with provided ID: $defaultUserWalletId")
|
||||
}
|
||||
|
||||
coVerify(exactly = 1) { userWalletsListRepository.getSyncStrict(defaultUserWalletId) }
|
||||
coVerify(exactly = 1) { userWalletsListRepository.userWallets }
|
||||
coVerify(inverse = true) {
|
||||
coldDerivationsRepository.derivePublicKeysByNetworks(any(), any())
|
||||
userWalletsListRepository.saveWithoutLock(any(), any())
|
||||
|
|
@ -71,7 +78,7 @@ internal class DefaultDerivationsRepositoryTest {
|
|||
repository.derivePublicKeys(userWalletId = defaultUserWalletId, currencies = emptyList())
|
||||
|
||||
coVerify(inverse = true) {
|
||||
userWalletsListRepository.getSyncStrict(any())
|
||||
userWalletsListRepository.userWallets
|
||||
coldDerivationsRepository.derivePublicKeysByNetworks(any(), any())
|
||||
userWalletsListRepository.saveWithoutLock(any(), any())
|
||||
}
|
||||
|
|
@ -80,8 +87,10 @@ internal class DefaultDerivationsRepositoryTest {
|
|||
@Test
|
||||
fun `error if coldDerivationsRepository throws exception`() = runTest {
|
||||
val currencies = MockCryptoCurrencyFactory(defaultUserWallet).ethereum.let(::listOf)
|
||||
val userWalletsFlow = MutableStateFlow(listOf(defaultUserWallet))
|
||||
|
||||
every { userWalletsListRepository.userWallets } returns userWalletsFlow
|
||||
|
||||
coEvery { userWalletsListRepository.getSyncStrict(defaultUserWalletId) } returns defaultUserWallet
|
||||
coEvery {
|
||||
coldDerivationsRepository.derivePublicKeysByNetworks(
|
||||
userWallet = defaultUserWallet,
|
||||
|
|
@ -96,7 +105,7 @@ internal class DefaultDerivationsRepositoryTest {
|
|||
.onFailure { Truth.assertThat(it).isInstanceOf(IllegalStateException::class.java) }
|
||||
|
||||
coVerifyOrder {
|
||||
userWalletsListRepository.getSyncStrict(defaultUserWalletId)
|
||||
userWalletsListRepository.userWallets
|
||||
coldDerivationsRepository.derivePublicKeysByNetworks(
|
||||
userWallet = defaultUserWallet,
|
||||
networks = currencies.map(CryptoCurrency.Coin::network),
|
||||
|
|
@ -109,9 +118,11 @@ internal class DefaultDerivationsRepositoryTest {
|
|||
@Test
|
||||
fun `success case`() = runTest {
|
||||
val currencies = MockCryptoCurrencyFactory(defaultUserWallet).ethereum.let(::listOf)
|
||||
val userWalletsFlow = MutableStateFlow(listOf(defaultUserWallet))
|
||||
val updatedWallet = defaultUserWallet.copy(cardsInWallet = setOf("AC01"))
|
||||
|
||||
coEvery { userWalletsListRepository.getSyncStrict(defaultUserWalletId) } returns defaultUserWallet
|
||||
every { userWalletsListRepository.userWallets } returns userWalletsFlow
|
||||
|
||||
coEvery {
|
||||
coldDerivationsRepository.derivePublicKeysByNetworks(
|
||||
userWallet = defaultUserWallet,
|
||||
|
|
@ -125,7 +136,7 @@ internal class DefaultDerivationsRepositoryTest {
|
|||
repository.derivePublicKeys(userWalletId = defaultUserWalletId, currencies = currencies)
|
||||
|
||||
coVerifyOrder {
|
||||
userWalletsListRepository.getSyncStrict(defaultUserWalletId)
|
||||
userWalletsListRepository.userWallets
|
||||
coldDerivationsRepository.derivePublicKeysByNetworks(
|
||||
userWallet = defaultUserWallet,
|
||||
networks = currencies.map(CryptoCurrency.Coin::network),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue