Updated on 2026-08-14
This commit is contained in:
parent
b88de49ba3
commit
664e71b782
11 changed files with 307 additions and 4 deletions
|
|
@ -2,7 +2,9 @@ package com.tangem.common.test.domain.walletmanager
|
|||
|
||||
import com.tangem.blockchainsdk.models.UpdateWalletManagerResult
|
||||
import com.tangem.blockchainsdk.models.UpdateWalletManagerResult.*
|
||||
import com.tangem.domain.models.currency.CryptoCurrency
|
||||
import com.tangem.domain.models.network.TxInfo
|
||||
import com.tangem.domain.models.yield.supply.YieldSupplyStatus
|
||||
import java.math.BigDecimal
|
||||
|
||||
/**
|
||||
|
|
@ -41,6 +43,41 @@ class MockUpdateWalletManagerResultFactory {
|
|||
)
|
||||
}
|
||||
|
||||
fun createVerifiedWithToken(): Verified {
|
||||
return Verified(
|
||||
selectedAddress = "0x1",
|
||||
addresses = setOf(Address(value = "0x1", type = Address.Type.Primary)),
|
||||
currenciesAmounts = setOf(
|
||||
CryptoCurrencyAmount.Token.BasicToken(
|
||||
value = BigDecimal.ONE,
|
||||
currencyRawId = CryptoCurrency.RawID("token"),
|
||||
contractAddress = "0xTokenAddress",
|
||||
),
|
||||
),
|
||||
currentTransactions = setOf(CryptoCurrencyTransaction.Coin(txInfo)),
|
||||
)
|
||||
}
|
||||
|
||||
fun createVerifiedWithSuppliedToken(): Verified {
|
||||
return Verified(
|
||||
selectedAddress = "0x1",
|
||||
addresses = setOf(Address(value = "0x1", type = Address.Type.Primary)),
|
||||
currenciesAmounts = setOf(
|
||||
CryptoCurrencyAmount.Token.YieldSupplyToken(
|
||||
value = BigDecimal.ONE,
|
||||
currencyRawId = CryptoCurrency.RawID("token"),
|
||||
contractAddress = "0xTokenAddress",
|
||||
yieldSupplyStatus = YieldSupplyStatus(
|
||||
isActive = true,
|
||||
isInitialized = true,
|
||||
isAllowedToSpend = false,
|
||||
),
|
||||
),
|
||||
),
|
||||
currentTransactions = setOf(CryptoCurrencyTransaction.Coin(txInfo)),
|
||||
)
|
||||
}
|
||||
|
||||
private companion object {
|
||||
|
||||
val txInfo = TxInfo(
|
||||
|
|
|
|||
|
|
@ -2,8 +2,6 @@ package com.tangem.datasource.local.network.entity
|
|||
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
import com.tangem.datasource.local.network.entity.NetworkStatusDM.NoAccount
|
||||
import com.tangem.datasource.local.network.entity.NetworkStatusDM.Verified
|
||||
import dev.onenowy.moshipolymorphicadapter.PolymorphicAdapterType
|
||||
import dev.onenowy.moshipolymorphicadapter.annotations.NameLabel
|
||||
import java.math.BigDecimal
|
||||
|
|
@ -44,6 +42,7 @@ sealed interface NetworkStatusDM {
|
|||
@Json(name = "selected_address") override val selectedAddress: String,
|
||||
@Json(name = "available_addresses") override val availableAddresses: Set<Address>,
|
||||
@Json(name = "amounts") val amounts: Map<String, BigDecimal>,
|
||||
@Json(name = "yield_supply_statuses") val yieldSupplyStatuses: Map<String, YieldSupplyStatus?> = emptyMap(),
|
||||
) : NetworkStatusDM
|
||||
|
||||
/**
|
||||
|
|
@ -107,4 +106,11 @@ sealed interface NetworkStatusDM {
|
|||
Secondary,
|
||||
}
|
||||
}
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class YieldSupplyStatus(
|
||||
@Json(name = "is_active") val isActive: Boolean,
|
||||
@Json(name = "is_initialized") val isInitialized: Boolean,
|
||||
@Json(name = "is_allowed_to_spend") val isAllowedToSpend: Boolean,
|
||||
)
|
||||
}
|
||||
|
|
@ -42,7 +42,10 @@ class NetworkStatusDMSerializationTest {
|
|||
{ "value": "0x123456", "type": "primary" },
|
||||
{ "value": "0xabcdef", "type": "secondary" }
|
||||
],
|
||||
"amounts": { "ETH": "1.2345" }
|
||||
"amounts": { "ETH": "1.2345" },
|
||||
"yield_supply_statuses": {
|
||||
"ETH": { "is_active": false, "is_initialized": false, "is_allowed_to_spend": false }
|
||||
}
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
|
|
@ -62,6 +65,13 @@ class NetworkStatusDMSerializationTest {
|
|||
NetworkStatusDM.Address("0xabcdef", NetworkStatusDM.Address.Type.Secondary),
|
||||
),
|
||||
amounts = mapOf("ETH" to BigDecimal("1.2345")),
|
||||
yieldSupplyStatuses = mapOf(
|
||||
"ETH" to NetworkStatusDM.YieldSupplyStatus(
|
||||
isActive = false,
|
||||
isInitialized = false,
|
||||
isAllowedToSpend = false,
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
Truth.assertThat(result).isEqualTo(expected)
|
||||
|
|
@ -82,6 +92,13 @@ class NetworkStatusDMSerializationTest {
|
|||
NetworkStatusDM.Address("0xabcdef", NetworkStatusDM.Address.Type.Secondary),
|
||||
),
|
||||
amounts = mapOf("ETH" to BigDecimal("1.2345")),
|
||||
yieldSupplyStatuses = mapOf(
|
||||
"ETH" to NetworkStatusDM.YieldSupplyStatus(
|
||||
isActive = false,
|
||||
isInitialized = false,
|
||||
isAllowedToSpend = false,
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
// Act
|
||||
|
|
@ -100,7 +117,10 @@ class NetworkStatusDMSerializationTest {
|
|||
{ "value": "0x123456", "type": "primary" },
|
||||
{ "value": "0xabcdef", "type": "secondary" }
|
||||
],
|
||||
"amounts": { "ETH": "1.2345" }
|
||||
"amounts": { "ETH": "1.2345" },
|
||||
"yield_supply_statuses": {
|
||||
"ETH": { "is_active": false, "is_initialized": false, "is_allowed_to_spend": false }
|
||||
}
|
||||
}
|
||||
""".stripJsonWhitespace()
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ internal object NetworkStatusDataModelConverter : Converter<NetworkStatus, Netwo
|
|||
selectedAddress = address.selectedAddress,
|
||||
availableAddresses = address.addresses,
|
||||
amounts = NetworkAmountsConverter.convertBack(value = status.amounts),
|
||||
yieldSupplyStatuses = NetworkYieldSupplyStatusConverter.convertBack(status.yieldSupplyStatuses),
|
||||
)
|
||||
}
|
||||
is NetworkStatus.NoAccount -> {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,46 @@
|
|||
package com.tangem.data.networks.converters
|
||||
|
||||
import com.tangem.datasource.local.network.entity.NetworkStatusDM
|
||||
import com.tangem.domain.models.currency.CryptoCurrency
|
||||
import com.tangem.domain.models.yield.supply.YieldSupplyStatus
|
||||
import com.tangem.utils.converter.TwoWayConverter
|
||||
import com.tangem.utils.extensions.mapNotNullValues
|
||||
|
||||
private typealias YieldSupplyStatusDataModel = Map<String, NetworkStatusDM.YieldSupplyStatus?>
|
||||
private typealias YieldSupplyStatusDomainModel = Map<CryptoCurrency.ID, YieldSupplyStatus?>
|
||||
|
||||
internal object NetworkYieldSupplyStatusConverter :
|
||||
TwoWayConverter<YieldSupplyStatusDataModel, YieldSupplyStatusDomainModel> {
|
||||
|
||||
override fun convert(value: YieldSupplyStatusDataModel): YieldSupplyStatusDomainModel {
|
||||
return value
|
||||
.mapKeys { CryptoCurrency.ID.fromValue(value = it.key) }
|
||||
.mapValues { (_, yieldSupplyStatus) ->
|
||||
if (yieldSupplyStatus != null) {
|
||||
YieldSupplyStatus(
|
||||
isActive = yieldSupplyStatus.isActive,
|
||||
isInitialized = yieldSupplyStatus.isInitialized,
|
||||
isAllowedToSpend = yieldSupplyStatus.isAllowedToSpend,
|
||||
)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun convertBack(value: YieldSupplyStatusDomainModel): YieldSupplyStatusDataModel {
|
||||
return value
|
||||
.mapKeys { (id, _) -> id.value }
|
||||
.mapNotNullValues { (_, yieldSupplyStatus) ->
|
||||
if (yieldSupplyStatus != null) {
|
||||
NetworkStatusDM.YieldSupplyStatus(
|
||||
isActive = yieldSupplyStatus.isActive,
|
||||
isInitialized = yieldSupplyStatus.isInitialized,
|
||||
isAllowedToSpend = yieldSupplyStatus.isAllowedToSpend,
|
||||
)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -29,6 +29,7 @@ internal object SimpleNetworkStatusConverter : Converter<NetworkStatusDM, Simple
|
|||
amounts = NetworkAmountsConverter.convert(value = value.amounts),
|
||||
pendingTransactions = emptyMap(),
|
||||
source = StatusSource.CACHE,
|
||||
yieldSupplyStatuses = NetworkYieldSupplyStatusConverter.convert(value = value.yieldSupplyStatuses),
|
||||
)
|
||||
}
|
||||
is NetworkStatusDM.NoAccount -> {
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import com.tangem.domain.models.network.Network
|
|||
import com.tangem.domain.models.network.NetworkAddress
|
||||
import com.tangem.domain.models.network.NetworkStatus
|
||||
import com.tangem.domain.models.network.NetworkStatus.Amount
|
||||
import com.tangem.domain.models.yield.supply.YieldSupplyStatus
|
||||
import org.junit.jupiter.api.TestInstance
|
||||
import org.junit.jupiter.params.ParameterizedTest
|
||||
import org.junit.jupiter.params.provider.MethodSource
|
||||
|
|
@ -59,6 +60,22 @@ internal class NetworkStatusDataModelConverterTest {
|
|||
) to Amount.NotFound,
|
||||
),
|
||||
pendingTransactions = mapOf(), // doesn't matter
|
||||
yieldSupplyStatuses = mapOf(
|
||||
ID(
|
||||
prefix = Prefix.COIN_PREFIX,
|
||||
body = Body.NetworkId(rawId = "BCH"),
|
||||
suffix = ID.Suffix.RawID(rawId = "bitcoin-cash"),
|
||||
) to YieldSupplyStatus(
|
||||
isActive = false,
|
||||
isInitialized = false,
|
||||
isAllowedToSpend = false,
|
||||
),
|
||||
ID(
|
||||
prefix = Prefix.COIN_PREFIX,
|
||||
body = Body.NetworkId(rawId = "BTC"),
|
||||
suffix = ID.Suffix.RawID(rawId = "bitcoin"),
|
||||
) to null,
|
||||
),
|
||||
source = StatusSource.ACTUAL, // doesn't matter
|
||||
),
|
||||
),
|
||||
|
|
@ -76,6 +93,13 @@ internal class NetworkStatusDataModelConverterTest {
|
|||
),
|
||||
),
|
||||
amounts = mapOf("coin⟨BCH⟩bitcoin-cash" to BigDecimal.ZERO),
|
||||
yieldSupplyStatuses = mapOf(
|
||||
"coin⟨BCH⟩bitcoin-cash" to NetworkStatusDM.YieldSupplyStatus(
|
||||
isActive = false,
|
||||
isInitialized = false,
|
||||
isAllowedToSpend = false,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
// endregion
|
||||
|
|
|
|||
|
|
@ -0,0 +1,83 @@
|
|||
package com.tangem.data.networks.converters
|
||||
|
||||
import com.google.common.truth.Truth
|
||||
import com.tangem.datasource.local.network.entity.NetworkStatusDM
|
||||
import com.tangem.domain.models.currency.CryptoCurrency.ID
|
||||
import com.tangem.domain.models.currency.CryptoCurrency.ID.Body
|
||||
import com.tangem.domain.models.currency.CryptoCurrency.ID.Prefix
|
||||
import com.tangem.domain.models.yield.supply.YieldSupplyStatus
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
internal class NetworkYieldSupplyStatusConverterTest {
|
||||
|
||||
@Test
|
||||
fun convert() {
|
||||
// Arrange
|
||||
val value = mapOf(
|
||||
"coin⟨ETH⟩ethereum" to NetworkStatusDM.YieldSupplyStatus(
|
||||
isActive = false,
|
||||
isInitialized = false,
|
||||
isAllowedToSpend = false,
|
||||
),
|
||||
"coin⟨ETH→12367123⟩ethereum" to null,
|
||||
)
|
||||
|
||||
// Act
|
||||
val actual = NetworkYieldSupplyStatusConverter.convert(value)
|
||||
|
||||
// Assert
|
||||
val expected = mapOf(
|
||||
ID(
|
||||
prefix = Prefix.COIN_PREFIX,
|
||||
body = Body.NetworkId(rawId = "ETH"),
|
||||
suffix = ID.Suffix.RawID(rawId = "ethereum"),
|
||||
) to YieldSupplyStatus(
|
||||
isActive = false,
|
||||
isInitialized = false,
|
||||
isAllowedToSpend = false,
|
||||
),
|
||||
ID(
|
||||
prefix = Prefix.COIN_PREFIX,
|
||||
body = Body.NetworkIdWithDerivationPath(rawId = "ETH", derivationPathHashCode = 12367123),
|
||||
suffix = ID.Suffix.RawID(rawId = "ethereum"),
|
||||
) to null,
|
||||
)
|
||||
|
||||
Truth.assertThat(actual).isEqualTo(expected)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun convertBack() {
|
||||
// Arrange
|
||||
val value = mapOf(
|
||||
ID(
|
||||
prefix = Prefix.COIN_PREFIX,
|
||||
body = Body.NetworkId(rawId = "ETH"),
|
||||
suffix = ID.Suffix.RawID(rawId = "ethereum"),
|
||||
) to YieldSupplyStatus(
|
||||
isActive = false,
|
||||
isInitialized = false,
|
||||
isAllowedToSpend = false,
|
||||
),
|
||||
ID(
|
||||
prefix = Prefix.COIN_PREFIX,
|
||||
body = Body.NetworkIdWithDerivationPath(rawId = "ETH", derivationPathHashCode = 12367123),
|
||||
suffix = ID.Suffix.RawID(rawId = "ethereum"),
|
||||
) to null,
|
||||
)
|
||||
|
||||
// Act
|
||||
val actual = NetworkYieldSupplyStatusConverter.convertBack(value)
|
||||
|
||||
// Assert
|
||||
val expected = mapOf(
|
||||
"coin⟨ETH⟩ethereum" to NetworkStatusDM.YieldSupplyStatus(
|
||||
isActive = false,
|
||||
isInitialized = false,
|
||||
isAllowedToSpend = false,
|
||||
),
|
||||
)
|
||||
|
||||
Truth.assertThat(actual).isEqualTo(expected)
|
||||
}
|
||||
}
|
||||
|
|
@ -12,6 +12,7 @@ import com.tangem.domain.models.network.Network
|
|||
import com.tangem.domain.models.network.NetworkAddress
|
||||
import com.tangem.domain.models.network.NetworkStatus
|
||||
import com.tangem.domain.models.network.NetworkStatus.Amount
|
||||
import com.tangem.domain.models.yield.supply.YieldSupplyStatus
|
||||
import org.junit.jupiter.api.TestInstance
|
||||
import org.junit.jupiter.params.ParameterizedTest
|
||||
import org.junit.jupiter.params.provider.MethodSource
|
||||
|
|
@ -68,6 +69,14 @@ internal class SimpleNetworkStatusConverterTest {
|
|||
"coin⟨BCH⟩bitcoin-cash" to BigDecimal.ZERO,
|
||||
"coin⟨ETH→12367123⟩ethereum" to BigDecimal.ONE,
|
||||
),
|
||||
yieldSupplyStatuses = mapOf(
|
||||
"coin⟨ETH⟩ethereum" to NetworkStatusDM.YieldSupplyStatus(
|
||||
isActive = false,
|
||||
isInitialized = false,
|
||||
isAllowedToSpend = false,
|
||||
),
|
||||
"coin⟨ETH⟩ethereum" to null,
|
||||
),
|
||||
),
|
||||
expected = SimpleNetworkStatus(
|
||||
id = Network.ID(
|
||||
|
|
@ -104,6 +113,22 @@ internal class SimpleNetworkStatusConverterTest {
|
|||
) to Amount.Loaded(value = BigDecimal.ONE),
|
||||
),
|
||||
pendingTransactions = emptyMap(),
|
||||
yieldSupplyStatuses = mapOf(
|
||||
ID(
|
||||
prefix = Prefix.COIN_PREFIX,
|
||||
body = Body.NetworkId(rawId = "ETH"),
|
||||
suffix = ID.Suffix.RawID(rawId = "ethereum"),
|
||||
) to YieldSupplyStatus(
|
||||
isActive = false,
|
||||
isInitialized = false,
|
||||
isAllowedToSpend = false,
|
||||
),
|
||||
ID(
|
||||
prefix = Prefix.COIN_PREFIX,
|
||||
body = Body.NetworkId(rawId = "ETH"),
|
||||
suffix = ID.Suffix.RawID(rawId = "ethereum"),
|
||||
) to null,
|
||||
),
|
||||
source = StatusSource.CACHE,
|
||||
),
|
||||
).let(Result.Companion::success),
|
||||
|
|
@ -178,6 +203,7 @@ internal class SimpleNetworkStatusConverterTest {
|
|||
),
|
||||
),
|
||||
amounts = emptyMap(),
|
||||
yieldSupplyStatuses = emptyMap(),
|
||||
),
|
||||
expected = Result.failure(
|
||||
exception = IllegalArgumentException("Selected address must not be null"),
|
||||
|
|
@ -193,6 +219,7 @@ internal class SimpleNetworkStatusConverterTest {
|
|||
selectedAddress = "0x1",
|
||||
availableAddresses = setOf(),
|
||||
amounts = emptyMap(),
|
||||
yieldSupplyStatuses = emptyMap(),
|
||||
),
|
||||
expected = Result.failure(
|
||||
exception = IllegalArgumentException("Selected address must not be null"),
|
||||
|
|
@ -217,6 +244,7 @@ internal class SimpleNetworkStatusConverterTest {
|
|||
),
|
||||
),
|
||||
amounts = emptyMap(),
|
||||
yieldSupplyStatuses = emptyMap(),
|
||||
),
|
||||
expected = Result.failure(
|
||||
exception = IllegalArgumentException("Selected address must not be null"),
|
||||
|
|
|
|||
|
|
@ -149,6 +149,11 @@ internal class CommonNetworkStatusFetcherTest {
|
|||
pendingTransactions = mapOf(
|
||||
CryptoCurrency.ID.fromValue(value = "token⟨ETH⟩NEVER-MIND⚓NEVER-MIND") to emptySet(),
|
||||
),
|
||||
yieldSupplyStatuses = mapOf(
|
||||
CryptoCurrency.ID.fromValue(
|
||||
value = "token⟨ETH⟩NEVER-MIND⚓NEVER-MIND",
|
||||
) to null,
|
||||
),
|
||||
)
|
||||
},
|
||||
),
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import com.tangem.domain.models.network.NetworkAddress
|
|||
import com.tangem.domain.models.network.NetworkStatus
|
||||
import com.tangem.domain.models.network.NetworkStatus.Amount
|
||||
import com.tangem.domain.models.network.TxInfo
|
||||
import com.tangem.domain.models.yield.supply.YieldSupplyStatus
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.junit.runners.Parameterized
|
||||
|
|
@ -222,6 +223,57 @@ internal class NetworkStatusFactoryTest(private val model: Model) {
|
|||
currencies.last().id to setOf(),
|
||||
),
|
||||
source = StatusSource.ACTUAL,
|
||||
yieldSupplyStatuses = mapOf(),
|
||||
),
|
||||
),
|
||||
createSuccess(
|
||||
result = updateWalletManagerResultFactory.createVerifiedWithToken(),
|
||||
currencies = currencies,
|
||||
status = NetworkStatus.Verified(
|
||||
address = NetworkAddress.Single(
|
||||
defaultAddress = NetworkAddress.Address(
|
||||
value = "0x1",
|
||||
type = NetworkAddress.Address.Type.Primary,
|
||||
),
|
||||
),
|
||||
amounts = mapOf(
|
||||
currencies.first().id to Amount.Loaded(BigDecimal.ONE),
|
||||
currencies.last().id to Amount.NotFound,
|
||||
),
|
||||
pendingTransactions = mapOf(
|
||||
currencies.first().id to setOf(txInfo),
|
||||
currencies.last().id to setOf(txInfo),
|
||||
),
|
||||
source = StatusSource.ACTUAL,
|
||||
yieldSupplyStatuses = mapOf(),
|
||||
),
|
||||
),
|
||||
createSuccess(
|
||||
result = updateWalletManagerResultFactory.createVerifiedWithSuppliedToken(),
|
||||
currencies = currencies,
|
||||
status = NetworkStatus.Verified(
|
||||
address = NetworkAddress.Single(
|
||||
defaultAddress = NetworkAddress.Address(
|
||||
value = "0x1",
|
||||
type = NetworkAddress.Address.Type.Primary,
|
||||
),
|
||||
),
|
||||
amounts = mapOf(
|
||||
currencies.first().id to Amount.Loaded(BigDecimal.ONE),
|
||||
currencies.last().id to Amount.NotFound,
|
||||
),
|
||||
pendingTransactions = mapOf(
|
||||
currencies.first().id to setOf(txInfo),
|
||||
currencies.last().id to setOf(txInfo),
|
||||
),
|
||||
source = StatusSource.ACTUAL,
|
||||
yieldSupplyStatuses = mapOf(
|
||||
currencies.first().id to YieldSupplyStatus(
|
||||
isActive = false,
|
||||
isInitialized = false,
|
||||
isAllowedToSpend = false,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
// endregion
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue