Updated on 2026-08-14
This commit is contained in:
parent
4c8af6b8e9
commit
1472431435
54 changed files with 370 additions and 352 deletions
|
|
@ -18,6 +18,7 @@ import com.tangem.datasource.api.stakekit.models.response.model.YieldDTO
|
|||
import com.tangem.datasource.local.token.P2PEthPoolVaultsStore
|
||||
import com.tangem.datasource.local.token.StakingYieldsStore
|
||||
import com.tangem.domain.common.wallets.UserWalletsListRepository
|
||||
import com.tangem.domain.common.wallets.getSyncOrNull
|
||||
import com.tangem.domain.core.utils.catchOn
|
||||
import com.tangem.domain.models.staking.StakingID
|
||||
import com.tangem.domain.models.wallet.UserWallet
|
||||
|
|
|
|||
|
|
@ -16,12 +16,12 @@ import com.tangem.datasource.local.token.P2PEthPoolVaultsStore
|
|||
import com.tangem.datasource.local.token.StakingYieldsStore
|
||||
import com.tangem.domain.common.wallets.UserWalletsListRepository
|
||||
import com.tangem.domain.models.staking.StakingID
|
||||
import com.tangem.domain.models.wallet.UserWalletId
|
||||
import com.tangem.domain.staking.multi.MultiStakingBalanceFetcher
|
||||
import com.tangem.test.core.assertEitherLeft
|
||||
import com.tangem.test.core.assertEitherRight
|
||||
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
|
||||
|
|
@ -62,7 +62,9 @@ internal class DefaultMultiStakingBalanceFetcherTest {
|
|||
// Arrange
|
||||
val params = MultiStakingBalanceFetcher.Params(userWalletId = userWalletId, stakingIds = tonAndSolanaIds)
|
||||
|
||||
coEvery { userWalletsListRepository.getSyncOrNull(params.userWalletId) } returns userWallet
|
||||
val userWalletsFlow = MutableStateFlow(listOf(userWallet))
|
||||
|
||||
every { userWalletsListRepository.userWallets } returns userWalletsFlow
|
||||
|
||||
val yields = listOf(MockYieldDTOFactory.create(tonId), MockYieldDTOFactory.create(solanaId))
|
||||
coEvery { stakingYieldsStore.getSyncWithTimeout() } returns yields
|
||||
|
|
@ -80,7 +82,7 @@ internal class DefaultMultiStakingBalanceFetcherTest {
|
|||
|
||||
// Assert
|
||||
coVerifyOrder {
|
||||
userWalletsListRepository.getSyncOrNull(params.userWalletId)
|
||||
userWalletsListRepository.userWallets
|
||||
stakeKitBalancesStore.refresh(userWalletId = params.userWalletId, stakingIds = tonAndSolanaIds)
|
||||
stakingYieldsStore.getSyncWithTimeout()
|
||||
stakeKitApi.getMultipleYieldBalances(requests)
|
||||
|
|
@ -97,7 +99,9 @@ internal class DefaultMultiStakingBalanceFetcherTest {
|
|||
// Arrange
|
||||
val params = MultiStakingBalanceFetcher.Params(userWalletId = userWalletId, stakingIds = tonAndSolanaIds)
|
||||
|
||||
coEvery { userWalletsListRepository.getSyncOrNull(params.userWalletId) } returns userWallet
|
||||
val userWalletsFlow = MutableStateFlow(listOf(userWallet))
|
||||
|
||||
every { userWalletsListRepository.userWallets } returns userWalletsFlow
|
||||
|
||||
val yields = listOf(MockYieldDTOFactory.create(tonId))
|
||||
coEvery { stakingYieldsStore.getSyncWithTimeout() } returns yields
|
||||
|
|
@ -112,7 +116,7 @@ internal class DefaultMultiStakingBalanceFetcherTest {
|
|||
|
||||
// Assert
|
||||
coVerifyOrder {
|
||||
userWalletsListRepository.getSyncOrNull(params.userWalletId)
|
||||
userWalletsListRepository.userWallets
|
||||
stakeKitBalancesStore.refresh(userWalletId = params.userWalletId, stakingIds = tonAndSolanaIds)
|
||||
stakingYieldsStore.getSyncWithTimeout()
|
||||
stakeKitBalancesStore.storeError(userWalletId = userWalletId, stakingIds = setOf(solanaId))
|
||||
|
|
@ -129,13 +133,15 @@ internal class DefaultMultiStakingBalanceFetcherTest {
|
|||
val params = MultiStakingBalanceFetcher.Params(userWalletId = userWalletId, stakingIds = tonAndSolanaIds)
|
||||
|
||||
val userWallet = MockUserWalletFactory.create().copy(isMultiCurrency = false)
|
||||
coEvery { userWalletsListRepository.getSyncOrNull(params.userWalletId) } returns userWallet
|
||||
val userWalletsFlow = MutableStateFlow(listOf(userWallet))
|
||||
|
||||
every { userWalletsListRepository.userWallets } returns userWalletsFlow
|
||||
|
||||
// Actual
|
||||
val actual = fetcher.invoke(params)
|
||||
|
||||
// Assert
|
||||
coVerifyOrder { userWalletsListRepository.getSyncOrNull(params.userWalletId) }
|
||||
coVerifyOrder { userWalletsListRepository.userWallets }
|
||||
|
||||
coVerify(inverse = true) {
|
||||
stakeKitBalancesStore.refresh(userWalletId = any(), stakingIds = any())
|
||||
|
|
@ -155,13 +161,14 @@ internal class DefaultMultiStakingBalanceFetcherTest {
|
|||
// Arrange
|
||||
val params = MultiStakingBalanceFetcher.Params(userWalletId = userWalletId, stakingIds = tonAndSolanaIds)
|
||||
|
||||
coEvery { userWalletsListRepository.getSyncOrNull(params.userWalletId) } returns null
|
||||
val userWalletsFlow = MutableStateFlow(null)
|
||||
coEvery { userWalletsListRepository.userWallets } returns userWalletsFlow
|
||||
|
||||
// Actual
|
||||
val actual = fetcher.invoke(params)
|
||||
|
||||
// Assert
|
||||
coVerifyOrder { userWalletsListRepository.getSyncOrNull(params.userWalletId) }
|
||||
coVerifyOrder { userWalletsListRepository.userWallets }
|
||||
|
||||
coVerify(inverse = true) {
|
||||
stakeKitBalancesStore.refresh(userWalletId = any(), stakingIds = any())
|
||||
|
|
@ -181,7 +188,9 @@ internal class DefaultMultiStakingBalanceFetcherTest {
|
|||
// Arrange
|
||||
val params = MultiStakingBalanceFetcher.Params(userWalletId = userWalletId, stakingIds = tonAndSolanaIds)
|
||||
|
||||
coEvery { userWalletsListRepository.getSyncOrNull(params.userWalletId) } returns userWallet
|
||||
val userWalletsFlow = MutableStateFlow(listOf(userWallet))
|
||||
|
||||
every { userWalletsListRepository.userWallets } returns userWalletsFlow
|
||||
coEvery { stakingYieldsStore.getSyncWithTimeout() } returns null
|
||||
|
||||
// Actual
|
||||
|
|
@ -189,7 +198,7 @@ internal class DefaultMultiStakingBalanceFetcherTest {
|
|||
|
||||
// Assert
|
||||
coVerifyOrder {
|
||||
userWalletsListRepository.getSyncOrNull(params.userWalletId)
|
||||
userWalletsListRepository.userWallets
|
||||
stakeKitBalancesStore.refresh(params.userWalletId, tonAndSolanaIds)
|
||||
stakingYieldsStore.getSyncWithTimeout()
|
||||
stakeKitBalancesStore.storeError(userWalletId, tonAndSolanaIds)
|
||||
|
|
@ -210,7 +219,9 @@ internal class DefaultMultiStakingBalanceFetcherTest {
|
|||
// Arrange
|
||||
val params = MultiStakingBalanceFetcher.Params(userWalletId = userWalletId, stakingIds = tonAndSolanaIds)
|
||||
|
||||
coEvery { userWalletsListRepository.getSyncOrNull(params.userWalletId) } returns userWallet
|
||||
val userWalletsFlow = MutableStateFlow(listOf(userWallet))
|
||||
|
||||
every { userWalletsListRepository.userWallets } returns userWalletsFlow
|
||||
coEvery { stakingYieldsStore.getSyncWithTimeout() } returns emptyList()
|
||||
|
||||
// Actual
|
||||
|
|
@ -218,7 +229,7 @@ internal class DefaultMultiStakingBalanceFetcherTest {
|
|||
|
||||
// Assert
|
||||
coVerifyOrder {
|
||||
userWalletsListRepository.getSyncOrNull(params.userWalletId)
|
||||
userWalletsListRepository.userWallets
|
||||
stakeKitBalancesStore.refresh(userWalletId = params.userWalletId, stakingIds = tonAndSolanaIds)
|
||||
stakingYieldsStore.getSyncWithTimeout()
|
||||
stakeKitBalancesStore.storeError(userWalletId, tonAndSolanaIds)
|
||||
|
|
@ -239,7 +250,9 @@ internal class DefaultMultiStakingBalanceFetcherTest {
|
|||
// Arrange
|
||||
val params = MultiStakingBalanceFetcher.Params(userWalletId = userWalletId, stakingIds = tonAndSolanaIds)
|
||||
|
||||
coEvery { userWalletsListRepository.getSyncOrNull(params.userWalletId) } returns userWallet
|
||||
val userWalletsFlow = MutableStateFlow(listOf(userWallet))
|
||||
|
||||
every { userWalletsListRepository.userWallets } returns userWalletsFlow
|
||||
|
||||
val yields = listOf(
|
||||
MockYieldDTOFactory.create(tonId).copy(id = null),
|
||||
|
|
@ -252,7 +265,7 @@ internal class DefaultMultiStakingBalanceFetcherTest {
|
|||
|
||||
// Assert
|
||||
coVerifyOrder {
|
||||
userWalletsListRepository.getSyncOrNull(params.userWalletId)
|
||||
userWalletsListRepository.userWallets
|
||||
stakeKitBalancesStore.refresh(userWalletId = params.userWalletId, stakingIds = tonAndSolanaIds)
|
||||
stakingYieldsStore.getSyncWithTimeout()
|
||||
stakeKitBalancesStore.storeError(userWalletId, tonAndSolanaIds)
|
||||
|
|
@ -273,7 +286,9 @@ internal class DefaultMultiStakingBalanceFetcherTest {
|
|||
// Arrange
|
||||
val params = MultiStakingBalanceFetcher.Params(userWalletId = userWalletId, stakingIds = tonAndSolanaIds)
|
||||
|
||||
coEvery { userWalletsListRepository.getSyncOrNull(params.userWalletId) } returns userWallet
|
||||
val userWalletsFlow = MutableStateFlow(listOf(userWallet))
|
||||
|
||||
every { userWalletsListRepository.userWallets } returns userWalletsFlow
|
||||
|
||||
val yields = listOf(MockYieldDTOFactory.create(StakingID(integrationId = "polygon", address = "0x1")))
|
||||
coEvery { stakingYieldsStore.getSyncWithTimeout() } returns yields
|
||||
|
|
@ -283,7 +298,7 @@ internal class DefaultMultiStakingBalanceFetcherTest {
|
|||
|
||||
// Assert
|
||||
coVerifyOrder {
|
||||
userWalletsListRepository.getSyncOrNull(params.userWalletId)
|
||||
userWalletsListRepository.userWallets
|
||||
stakeKitBalancesStore.refresh(userWalletId = params.userWalletId, stakingIds = tonAndSolanaIds)
|
||||
stakingYieldsStore.getSyncWithTimeout()
|
||||
stakeKitBalancesStore.storeError(userWalletId, tonAndSolanaIds)
|
||||
|
|
@ -310,7 +325,9 @@ internal class DefaultMultiStakingBalanceFetcherTest {
|
|||
// Arrange
|
||||
val params = MultiStakingBalanceFetcher.Params(userWalletId = userWalletId, stakingIds = tonAndSolanaIds)
|
||||
|
||||
coEvery { userWalletsListRepository.getSyncOrNull(params.userWalletId) } returns userWallet
|
||||
val userWalletsFlow = MutableStateFlow(listOf(userWallet))
|
||||
|
||||
every { userWalletsListRepository.userWallets } returns userWalletsFlow
|
||||
|
||||
val yields = listOf(MockYieldDTOFactory.create(tonId), MockYieldDTOFactory.create(solanaId))
|
||||
coEvery { stakingYieldsStore.getSyncWithTimeout() } returns yields
|
||||
|
|
@ -328,7 +345,7 @@ internal class DefaultMultiStakingBalanceFetcherTest {
|
|||
|
||||
// Assert
|
||||
coVerifyOrder {
|
||||
userWalletsListRepository.getSyncOrNull(params.userWalletId)
|
||||
userWalletsListRepository.userWallets
|
||||
stakeKitBalancesStore.refresh(userWalletId = params.userWalletId, stakingIds = tonAndSolanaIds)
|
||||
stakingYieldsStore.getSyncWithTimeout()
|
||||
stakeKitApi.getMultipleYieldBalances(requests)
|
||||
|
|
@ -343,8 +360,8 @@ internal class DefaultMultiStakingBalanceFetcherTest {
|
|||
}
|
||||
|
||||
private companion object {
|
||||
val userWalletId = UserWalletId("011")
|
||||
val userWallet = MockUserWalletFactory.create()
|
||||
val userWalletId = userWallet.walletId
|
||||
|
||||
val tonId = MockYieldBalanceWrapperDTOFactory.defaultStakingId
|
||||
val solanaId = StakingID(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue