Updated on 2026-08-14

This commit is contained in:
Tangem 2026-02-12 11:50:44 +04:00
parent 4c8af6b8e9
commit 1472431435
54 changed files with 370 additions and 352 deletions

View file

@ -9,6 +9,7 @@ import com.tangem.datasource.local.token.UserTokensResponseStore
import com.tangem.domain.account.featuretoggle.AccountsFeatureToggles
import com.tangem.domain.card.common.util.cardTypesResolver
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.common.wallets.getSyncStrict
import com.tangem.domain.demo.models.DemoConfig
import com.tangem.domain.models.account.DerivationIndex
import com.tangem.domain.models.currency.CryptoCurrency

View file

@ -13,6 +13,7 @@ import com.tangem.datasource.local.appsflyer.AppsFlyerStore
import com.tangem.datasource.local.token.UserTokensResponseStore
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.models.wallet.UserWallet
import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.utils.coroutines.CoroutineDispatcherProvider

View file

@ -5,6 +5,7 @@ import com.tangem.datasource.api.tangemTech.TangemTechApi
import com.tangem.datasource.api.tangemTech.converters.WalletIdBodyConverter
import com.tangem.datasource.local.appsflyer.AppsFlyerStore
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.common.wallets.getSyncOrNull
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.utils.coroutines.CoroutineDispatcherProvider

View file

@ -24,6 +24,7 @@ import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.test.core.ProvideTestModels
import io.mockk.*
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Nested
@ -78,11 +79,12 @@ internal class DefaultCardCryptoCurrencyFactoryTest {
fun `create currencies in ETH for multi-currency wallet`(model: CreateTestModel.MultiWallet) = runTest {
// Arrange
val userWallet = createMultiWallet()
val userWalletsFlow = MutableStateFlow(listOf(userWallet))
val userTokensResponse = model.userTokensResponse
val network = ethereum.network
every { accountsFeatureToggles.isFeatureEnabled } returns false
coEvery { userWalletsListRepository.getSyncStrict(id = userWallet.walletId) } returns userWallet
every { userWalletsListRepository.userWallets } returns userWalletsFlow
coEvery { userTokensResponseStore.getSyncOrNull(userWallet.walletId) } returns userTokensResponse
// Act
@ -94,7 +96,7 @@ internal class DefaultCardCryptoCurrencyFactoryTest {
Truth.assertThat(actual).isEqualTo(expected)
coVerifyOrder {
userWalletsListRepository.getSyncStrict(id = userWallet.walletId)
userWalletsListRepository.userWallets
userTokensResponseStore.getSyncOrNull(userWalletId = userWallet.walletId)
}
}
@ -130,8 +132,9 @@ internal class DefaultCardCryptoCurrencyFactoryTest {
fun `create currencies for single-currency wallet (ETH)`(model: CreateTestModel.SingleWallet) = runTest {
// Arrange
val userWallet = createSingleWallet()
val userWalletsFlow = MutableStateFlow(listOf(userWallet))
coEvery { userWalletsListRepository.getSyncStrict(id = userWallet.walletId) } returns userWallet
every { userWalletsListRepository.userWallets } returns userWalletsFlow
// Act
val actual = factory.create(userWalletId = userWallet.walletId, network = model.network)
@ -142,7 +145,7 @@ internal class DefaultCardCryptoCurrencyFactoryTest {
Truth.assertThat(actual).isEqualTo(expected)
coVerifyOrder {
userWalletsListRepository.getSyncStrict(id = userWallet.walletId)
userWalletsListRepository.userWallets
userWallet.scanResponse.cardTypesResolver.getBlockchain()
}
@ -168,8 +171,9 @@ internal class DefaultCardCryptoCurrencyFactoryTest {
) = runTest {
// Arrange
val userWallet = MockUserWalletFactory.createSingleWalletWithToken()
val userWalletsFlow = MutableStateFlow(listOf(userWallet))
coEvery { userWalletsListRepository.getSyncStrict(id = userWallet.walletId) } returns userWallet
every { userWalletsListRepository.userWallets } returns userWalletsFlow
// Act
val actual = factory.create(userWalletId = userWallet.walletId, network = model.network)
@ -186,7 +190,7 @@ internal class DefaultCardCryptoCurrencyFactoryTest {
Truth.assertThat(actual).isEqualTo(expected)
coVerifyOrder {
userWalletsListRepository.getSyncStrict(id = userWallet.walletId)
userWalletsListRepository.userWallets
userWallet.scanResponse.cardTypesResolver.getBlockchain()
}

View file

@ -14,6 +14,7 @@ import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.utils.coroutines.TestingCoroutineDispatcherProvider
import io.mockk.*
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
@ -118,8 +119,10 @@ class UserTokensSaverTest {
val error = ApiResponseError.UnknownException(Exception("API Error"))
var onFailSendCalled = false
val userWalletsFlow = MutableStateFlow(listOf(userWallet))
every { accountsFeatureToggles.isFeatureEnabled } returns true
coEvery { userWalletsListRepository.getSyncOrNull(userWalletId) } returns userWallet
every { userWalletsListRepository.userWallets } returns userWalletsFlow
coEvery { enricher(userWalletId, response) } returns enrichedResponse
coEvery { tangemTechApi.saveTokens(any(), any()) } returns ApiResponse.Error(error) as ApiResponse<Unit>
@ -132,6 +135,7 @@ class UserTokensSaverTest {
// THEN
coVerifyOrder {
userWalletsListRepository.userWallets
enricher(userWalletId, response)
tangemTechApi.saveTokens(userWalletId.stringValue, enrichedResponse)
}
@ -165,7 +169,9 @@ class UserTokensSaverTest {
walletType = WalletType.COLD,
)
coEvery { userWalletsListRepository.getSyncOrNull(userWalletId) } returns userWallet
val userWalletsFlow = MutableStateFlow(listOf(userWallet))
every { userWalletsListRepository.userWallets } returns userWalletsFlow
coEvery { enricher(userWalletId, response) } returns enrichedResponse
coEvery {
tangemTechApi.saveTokens(userWalletId.stringValue, enrichedResponse)
@ -177,6 +183,7 @@ class UserTokensSaverTest {
// THEN
coVerifyOrder {
enricher(userWalletId, response)
userWalletsListRepository.userWallets
tangemTechApi.saveTokens(userWalletId.stringValue, enrichedResponse)
}
}

View file

@ -14,6 +14,7 @@ import com.tangem.domain.wallets.models.AppsFlyerConversionData
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
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.Nested
@ -65,7 +66,9 @@ internal class DefaultWalletServerBinderTest {
)
val apiResponse = ApiResponse.Success(Unit)
coEvery { userWalletsListRepository.getSyncOrNull(userWalletId) } returns userWallet
val userWalletsFlow = MutableStateFlow(listOf(userWallet))
every { userWalletsListRepository.userWallets } returns userWalletsFlow
coEvery { appsFlyerStore.get() } returns conversionData
coEvery { tangemTechApi.createWallet(requestBody) } returns apiResponse
@ -74,7 +77,7 @@ internal class DefaultWalletServerBinderTest {
Truth.assertThat(actual).isEqualTo(apiResponse)
coVerifyOrder {
userWalletsListRepository.getSyncOrNull(userWalletId)
userWalletsListRepository.userWallets
appsFlyerStore.get()
tangemTechApi.createWallet(requestBody)
}
@ -82,15 +85,15 @@ internal class DefaultWalletServerBinderTest {
@Test
fun `bind will skipped if userWalletsListRepository returns null`() = runTest {
coEvery { userWalletsListRepository.getSyncOrNull(userWalletId) } returns null
val userWalletsFlow = MutableStateFlow<List<UserWallet>?>(null)
every { userWalletsListRepository.userWallets } returns userWalletsFlow
val actual = binder.bind(userWalletId = userWalletId)
Truth.assertThat(actual).isEqualTo(null)
coVerifyOrder {
userWalletsListRepository.getSyncOrNull(userWalletId)
}
coVerifyOrder { userWalletsListRepository.userWallets }
coVerify(inverse = true) {
appsFlyerStore.get()
@ -107,7 +110,9 @@ internal class DefaultWalletServerBinderTest {
)
val apiResponse = ApiResponse.Success(Unit)
coEvery { userWalletsListRepository.getSyncOrNull(userWalletId) } returns userWallet
val userWalletsFlow = MutableStateFlow(listOf(userWallet))
every { userWalletsListRepository.userWallets } returns userWalletsFlow
coEvery { appsFlyerStore.get() } returns null
coEvery { tangemTechApi.createWallet(requestBody) } returns apiResponse
@ -116,7 +121,7 @@ internal class DefaultWalletServerBinderTest {
Truth.assertThat(actual).isEqualTo(apiResponse)
coVerifyOrder {
userWalletsListRepository.getSyncOrNull(userWalletId)
userWalletsListRepository.userWallets
appsFlyerStore.get()
tangemTechApi.createWallet(requestBody)
}
@ -133,7 +138,9 @@ internal class DefaultWalletServerBinderTest {
)
val apiResponse = ApiResponse.Error(ApiResponseError.TimeoutException()) as ApiResponse<Unit>
coEvery { userWalletsListRepository.getSyncOrNull(userWalletId) } returns userWallet
val userWalletsFlow = MutableStateFlow(listOf(userWallet))
every { userWalletsListRepository.userWallets } returns userWalletsFlow
coEvery { appsFlyerStore.get() } returns conversionData
coEvery { tangemTechApi.createWallet(requestBody) } returns apiResponse
@ -142,7 +149,7 @@ internal class DefaultWalletServerBinderTest {
Truth.assertThat(actual).isEqualTo(apiResponse)
coVerifyOrder {
userWalletsListRepository.getSyncOrNull(userWalletId)
userWalletsListRepository.userWallets
appsFlyerStore.get()
tangemTechApi.createWallet(requestBody)
}