Updated on 2026-08-14
This commit is contained in:
commit
a0c9ace219
1607 changed files with 40580 additions and 16776 deletions
|
|
@ -23,9 +23,9 @@ fun getL2CompatibilityTokenComparison(token: UserTokensResponse.Token, currencyI
|
|||
|
||||
fun List<CoinsResponse.Coin.Network>.applyL2Compatibility(coinId: String): List<CoinsResponse.Coin.Network> {
|
||||
return if (coinId == ETHEREUM_COIN_ID) {
|
||||
val l2Networks = l2BlockchainsList.map {
|
||||
val l2Networks = l2BlockchainsList.map { blockchain ->
|
||||
CoinsResponse.Coin.Network(
|
||||
networkId = it.toNetworkId(),
|
||||
networkId = blockchain.toNetworkId(),
|
||||
)
|
||||
}
|
||||
this + l2Networks
|
||||
|
|
@ -37,9 +37,9 @@ fun List<CoinsResponse.Coin.Network>.applyL2Compatibility(coinId: String): List<
|
|||
fun TokenMarketInfoResponse.applyL2Compatibility(coinId: String): TokenMarketInfoResponse {
|
||||
val networks = this.networks ?: return this
|
||||
return if (coinId == ETHEREUM_COIN_ID) {
|
||||
val l2Networks = l2BlockchainsList.map {
|
||||
val l2Networks = l2BlockchainsList.map { blockchain ->
|
||||
TokenMarketInfoResponse.Network(
|
||||
networkId = it.toNetworkId(),
|
||||
networkId = blockchain.toNetworkId(),
|
||||
contractAddress = null,
|
||||
decimalCount = null,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -37,8 +37,8 @@ internal class BlockchainProvidersResponseLoader @Inject constructor(
|
|||
remote = remoteResponse,
|
||||
)
|
||||
},
|
||||
onFailure = {
|
||||
Timber.e(it, "Failed to load blockchain provider types from backend")
|
||||
onFailure = { throwable ->
|
||||
Timber.e(throwable, "Failed to load blockchain provider types from backend")
|
||||
localResponse
|
||||
},
|
||||
)
|
||||
|
|
|
|||
|
|
@ -30,8 +30,8 @@ internal class BlockchainProvidersResponseMerger @Inject internal constructor(
|
|||
*/
|
||||
fun merge(local: BlockchainProvidersResponse, remote: BlockchainProvidersResponse): BlockchainProvidersResponse {
|
||||
val remoteWithoutInvalidProviders = remote
|
||||
.mapValues {
|
||||
it.value
|
||||
.mapValues { entry ->
|
||||
entry.value
|
||||
.filterUnsupportedProviders()
|
||||
.filterInvalidProviders()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,10 +52,10 @@ internal class DevBlockchainProvidersTypesManager(
|
|||
}
|
||||
|
||||
override suspend fun update(blockchain: Blockchain, providers: List<ProviderType>) {
|
||||
changedBlockchainProvidersStore.updateData {
|
||||
changedBlockchainProvidersStore.updateData { blockchainProviders ->
|
||||
val providerModels = BlockchainProviderTypesConverter.convertBack(value = mapOf(blockchain to providers))
|
||||
|
||||
it + providerModels
|
||||
blockchainProviders + providerModels
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ internal enum class ProviderTypeIdMapping(val id: String, val providerType: Prov
|
|||
BitcoinBlockcypher(id = "blockcypher", providerType = ProviderType.BitcoinLike.Blockcypher),
|
||||
CardanoAdalite(id = "adalite", providerType = ProviderType.Cardano.Adalite),
|
||||
CardanoRosetta(id = "tangemRosetta", providerType = ProviderType.Cardano.Rosetta),
|
||||
CardanoMock(id = "mock", providerType = ProviderType.Mock),
|
||||
ChiaFireAcademy(id = "fireAcademy", providerType = ProviderType.Chia.FireAcademy),
|
||||
ChiaTangem(id = "tangemChia", providerType = ProviderType.Chia.Tangem),
|
||||
ChiaTangemNew(id = "tangemChia3", providerType = ProviderType.Chia.TangemNew),
|
||||
|
|
@ -26,5 +27,4 @@ internal enum class ProviderTypeIdMapping(val id: String, val providerType: Prov
|
|||
AlephiumTangem(id = "tangemAlephium", providerType = ProviderType.Alephium.Tangem),
|
||||
Blink(id = "blink", providerType = ProviderType.Blink),
|
||||
Tatum(id = "tatum", providerType = ProviderType.PolkadotLike.Tatum),
|
||||
;
|
||||
}
|
||||
|
|
@ -167,6 +167,11 @@ fun Blockchain.Companion.fromNetworkId(networkId: String): Blockchain? {
|
|||
"pepecoin/test" -> Blockchain.PepecoinTestnet
|
||||
"hyperevm" -> Blockchain.Hyperliquid
|
||||
"hyperevm/test" -> Blockchain.HyperliquidTestnet
|
||||
"quai-network" -> Blockchain.Quai
|
||||
"quai-network/test" -> Blockchain.QuaiTestnet
|
||||
// "linea" -> Blockchain.Linea
|
||||
// "linea/test" -> Blockchain.LineaTestnet
|
||||
// "arbitrum-nova" -> Blockchain.ArbitrumNova
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
|
@ -331,6 +336,11 @@ fun Blockchain.toNetworkId(): String {
|
|||
Blockchain.PepecoinTestnet -> "pepecoin/test"
|
||||
Blockchain.Hyperliquid -> "hyperevm"
|
||||
Blockchain.HyperliquidTestnet -> "hyperevm/test"
|
||||
Blockchain.Quai -> "quai-network"
|
||||
Blockchain.QuaiTestnet -> "quai-network/test"
|
||||
// Blockchain.Linea -> "linea"
|
||||
// Blockchain.LineaTestnet -> "linea/test"
|
||||
// Blockchain.ArbitrumNova -> "arbitrum-nova"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -435,6 +445,9 @@ fun Blockchain.toCoinId(): String {
|
|||
Blockchain.ZkLinkNova, Blockchain.ZkLinkNovaTestnet -> "zklink-ethereum"
|
||||
Blockchain.Pepecoin, Blockchain.PepecoinTestnet -> "pepecoin-network"
|
||||
Blockchain.Hyperliquid, Blockchain.HyperliquidTestnet -> "hyperliquid"
|
||||
Blockchain.Quai, Blockchain.QuaiTestnet -> "quai-network"
|
||||
// Blockchain.Linea, Blockchain.LineaTestnet -> "linea-ethereum"
|
||||
// Blockchain.ArbitrumNova -> "arbitrum-nova-ethereum"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import java.math.BigDecimal
|
|||
object BlockchainUtils {
|
||||
|
||||
private const val XRP_X_ADDRESS = 'X'
|
||||
const val SOLANA_TRANSACTION_SIZE_THRESHOLD_BYTES = 930
|
||||
|
||||
/** Decodes XRP Blockchain address */
|
||||
fun decodeRippleXAddress(xAddress: String, blockchainId: String): XrpTaggedAddress? {
|
||||
|
|
@ -158,6 +159,13 @@ object BlockchainUtils {
|
|||
return isSolana(blockchainId) || isBSC(blockchainId) || isTon(blockchainId)
|
||||
}
|
||||
|
||||
/** Checks if the blockchain uses case-insensitive contract addresses */
|
||||
fun isCaseInsensitiveContractAddress(blockchainId: String): Boolean {
|
||||
val blockchain = Blockchain.fromId(blockchainId)
|
||||
|
||||
return blockchain.isEvm()
|
||||
}
|
||||
|
||||
private fun getNetworkStandardName(blockchain: Blockchain): String {
|
||||
return when (blockchain) {
|
||||
Blockchain.Ethereum, Blockchain.EthereumTestnet -> "ERC20"
|
||||
|
|
|
|||
|
|
@ -3,35 +3,73 @@ package com.tangem.lib.crypto.derivation
|
|||
import com.tangem.blockchain.common.Blockchain
|
||||
import com.tangem.blockchain.common.isUTXO
|
||||
import com.tangem.crypto.hdWallet.DerivationPath
|
||||
import com.tangem.domain.models.network.Network
|
||||
import timber.log.Timber
|
||||
|
||||
/**
|
||||
* Utility class to recognize the account node in a derivation path based on the blockchain type.
|
||||
* Derivation path schema: [ m / purpose' / coin_type' / account' / change / address_index ].
|
||||
*
|
||||
* @param blockchain the blockchain for which the account node is to be recognized
|
||||
* @property blockchain the blockchain for which the account node is to be recognized
|
||||
*
|
||||
* @see [iOS](https://github.com/tangem-developments/tangem-app-ios/blob/f5312a8177afbebda2ff2ed93771f11fae4837bb/Tangem/Domain/Accounts/Common/AccountDerivationPathHelper.swift)
|
||||
[REDACTED_AUTHOR]
|
||||
*/
|
||||
class AccountNodeRecognizer(blockchain: Blockchain) {
|
||||
class AccountNodeRecognizer(private val blockchain: Blockchain) {
|
||||
|
||||
/** Index of the account node in the derivation path */
|
||||
val accountNodeIndex: Int = if (blockchain.isUTXO) {
|
||||
UTXO_BLOCKCHAIN_NODE_INDEX
|
||||
} else {
|
||||
NON_UTXO_BLOCKCHAIN_NODE_INDEX
|
||||
/**
|
||||
* Index of the account node in the [derivationPath]
|
||||
*/
|
||||
@Suppress("MagicNumber")
|
||||
fun getAccountNodeIndex(derivationPath: DerivationPath): Int? {
|
||||
val nodesCount = derivationPath.nodes.size
|
||||
|
||||
val index = when {
|
||||
blockchain == Blockchain.Tezos -> {
|
||||
UTXO_BLOCKCHAIN_NODE_INDEX.takeIf { nodesCount == 4 }
|
||||
}
|
||||
blockchain == Blockchain.Quai || blockchain.isUTXO -> {
|
||||
UTXO_BLOCKCHAIN_NODE_INDEX.takeIf { nodesCount == 5 }
|
||||
}
|
||||
!blockchain.isUTXO -> {
|
||||
(nodesCount - 1).takeIf { nodesCount == 3 || nodesCount == 5 }
|
||||
}
|
||||
else -> null
|
||||
}
|
||||
|
||||
if (index == null) {
|
||||
Timber.e("Cannot determine account node index for ${blockchain.fullName}: ${derivationPath.rawPath}")
|
||||
}
|
||||
|
||||
return index
|
||||
}
|
||||
|
||||
/** Recognizes the account node value from the given [derivationPath] */
|
||||
fun recognize(derivationPath: Network.DerivationPath): Long? {
|
||||
val derivationPathValue = derivationPath.value ?: return null
|
||||
|
||||
return recognize(derivationPathValue = derivationPathValue)
|
||||
}
|
||||
|
||||
/** Recognizes the account node value from the given derivation path string [derivationPathValue] */
|
||||
fun recognize(derivationPathValue: String): Long? {
|
||||
if (derivationPathValue.isBlank()) return null
|
||||
|
||||
return runCatching {
|
||||
recognize(derivationPath = DerivationPath(rawPath = derivationPathValue))
|
||||
}
|
||||
.getOrNull()
|
||||
val cardSdkDerivationPath = DerivationPath(rawPath = derivationPathValue)
|
||||
recognize(derivationPath = cardSdkDerivationPath)
|
||||
}.getOrNull()
|
||||
}
|
||||
|
||||
/** Recognizes the account node value from the given [derivationPath] */
|
||||
fun recognize(derivationPath: DerivationPath): Long? {
|
||||
return runCatching {
|
||||
if (!blockchain.isAccountsSupported()) {
|
||||
Timber.e("Account derivation is not supported for blockchain: ${blockchain.fullName}")
|
||||
return null
|
||||
}
|
||||
|
||||
val accountNodeIndex = getAccountNodeIndex(derivationPath) ?: return null
|
||||
val accountNode = derivationPath.nodes.getOrNull(accountNodeIndex)
|
||||
|
||||
accountNode?.getIndex(includeHardened = false)
|
||||
|
|
@ -39,8 +77,180 @@ class AccountNodeRecognizer(blockchain: Blockchain) {
|
|||
.getOrNull()
|
||||
}
|
||||
|
||||
@Suppress("LongMethod")
|
||||
private fun Blockchain.isAccountsSupported(): Boolean {
|
||||
return when (this) {
|
||||
Blockchain.Bitcoin,
|
||||
Blockchain.Litecoin,
|
||||
Blockchain.Stellar,
|
||||
Blockchain.Ethereum,
|
||||
Blockchain.EthereumPow,
|
||||
Blockchain.Dischain,
|
||||
Blockchain.EthereumClassic,
|
||||
Blockchain.RSK,
|
||||
Blockchain.BitcoinCash,
|
||||
Blockchain.Binance,
|
||||
Blockchain.Cardano,
|
||||
Blockchain.XRP,
|
||||
Blockchain.Ducatus,
|
||||
Blockchain.Tezos,
|
||||
Blockchain.Dogecoin,
|
||||
Blockchain.BSC,
|
||||
Blockchain.Polygon,
|
||||
Blockchain.Avalanche,
|
||||
Blockchain.Solana,
|
||||
Blockchain.Fantom,
|
||||
Blockchain.Polkadot,
|
||||
Blockchain.Kusama,
|
||||
Blockchain.AlephZero,
|
||||
Blockchain.Tron,
|
||||
Blockchain.Arbitrum,
|
||||
Blockchain.Dash,
|
||||
Blockchain.Gnosis,
|
||||
Blockchain.Optimism,
|
||||
Blockchain.TON,
|
||||
Blockchain.Kava,
|
||||
Blockchain.Kaspa,
|
||||
Blockchain.Ravencoin,
|
||||
Blockchain.Cosmos,
|
||||
Blockchain.TerraV1,
|
||||
Blockchain.TerraV2,
|
||||
Blockchain.Cronos,
|
||||
Blockchain.Telos,
|
||||
Blockchain.OctaSpace,
|
||||
Blockchain.Near,
|
||||
Blockchain.Decimal,
|
||||
Blockchain.VeChain,
|
||||
Blockchain.XDC,
|
||||
Blockchain.Algorand,
|
||||
Blockchain.Shibarium,
|
||||
Blockchain.Aptos,
|
||||
Blockchain.Hedera,
|
||||
Blockchain.Areon,
|
||||
Blockchain.Playa3ull,
|
||||
Blockchain.PulseChain,
|
||||
Blockchain.Aurora,
|
||||
Blockchain.Manta,
|
||||
Blockchain.ZkSyncEra,
|
||||
Blockchain.Moonbeam,
|
||||
Blockchain.PolygonZkEVM,
|
||||
Blockchain.Moonriver,
|
||||
Blockchain.Mantle,
|
||||
Blockchain.Flare,
|
||||
Blockchain.Taraxa,
|
||||
Blockchain.Radiant,
|
||||
Blockchain.Base,
|
||||
Blockchain.Joystream,
|
||||
Blockchain.Bittensor,
|
||||
Blockchain.Koinos,
|
||||
Blockchain.InternetComputer,
|
||||
Blockchain.Cyber,
|
||||
Blockchain.Blast,
|
||||
Blockchain.Sui,
|
||||
Blockchain.Filecoin,
|
||||
Blockchain.Sei,
|
||||
Blockchain.EnergyWebChain,
|
||||
Blockchain.EnergyWebX,
|
||||
Blockchain.Core,
|
||||
Blockchain.Canxium,
|
||||
Blockchain.Casper,
|
||||
Blockchain.Chiliz,
|
||||
Blockchain.Xodex,
|
||||
Blockchain.Clore,
|
||||
Blockchain.Fact0rn,
|
||||
Blockchain.OdysseyChain,
|
||||
Blockchain.Bitrock,
|
||||
Blockchain.ApeChain,
|
||||
Blockchain.Sonic,
|
||||
Blockchain.Alephium,
|
||||
Blockchain.VanarChain,
|
||||
Blockchain.ZkLinkNova,
|
||||
Blockchain.Pepecoin,
|
||||
Blockchain.Hyperliquid,
|
||||
Blockchain.Scroll,
|
||||
// Blockchain.Linea,
|
||||
// Blockchain.ArbitrumNova,
|
||||
Blockchain.Quai,
|
||||
-> true
|
||||
Blockchain.Nexa, // unsupported network
|
||||
Blockchain.Chia,
|
||||
-> false
|
||||
// region Testnet
|
||||
Blockchain.Unknown,
|
||||
Blockchain.ArbitrumTestnet,
|
||||
Blockchain.AvalancheTestnet,
|
||||
Blockchain.BinanceTestnet,
|
||||
Blockchain.BSCTestnet,
|
||||
Blockchain.BitcoinTestnet,
|
||||
Blockchain.BitcoinCashTestnet,
|
||||
Blockchain.CosmosTestnet,
|
||||
Blockchain.EthereumTestnet,
|
||||
Blockchain.EthereumClassicTestnet,
|
||||
Blockchain.FantomTestnet,
|
||||
Blockchain.NearTestnet,
|
||||
Blockchain.PolkadotTestnet,
|
||||
Blockchain.KavaTestnet,
|
||||
Blockchain.PolygonTestnet,
|
||||
Blockchain.SeiTestnet,
|
||||
Blockchain.StellarTestnet,
|
||||
Blockchain.SolanaTestnet,
|
||||
Blockchain.TronTestnet,
|
||||
Blockchain.OptimismTestnet,
|
||||
Blockchain.EthereumPowTestnet,
|
||||
Blockchain.KaspaTestnet,
|
||||
Blockchain.TelosTestnet,
|
||||
Blockchain.TONTestnet,
|
||||
Blockchain.RavencoinTestnet,
|
||||
Blockchain.AlephZeroTestnet,
|
||||
Blockchain.OctaSpaceTestnet,
|
||||
Blockchain.ChiaTestnet,
|
||||
Blockchain.DecimalTestnet,
|
||||
Blockchain.XDCTestnet,
|
||||
Blockchain.VeChainTestnet,
|
||||
Blockchain.AptosTestnet,
|
||||
Blockchain.ShibariumTestnet,
|
||||
Blockchain.AlgorandTestnet,
|
||||
Blockchain.HederaTestnet,
|
||||
Blockchain.AuroraTestnet,
|
||||
Blockchain.AreonTestnet,
|
||||
Blockchain.PulseChainTestnet,
|
||||
Blockchain.ZkSyncEraTestnet,
|
||||
Blockchain.NexaTestnet,
|
||||
Blockchain.MoonbeamTestnet,
|
||||
Blockchain.MantaTestnet,
|
||||
Blockchain.PolygonZkEVMTestnet,
|
||||
Blockchain.BaseTestnet,
|
||||
Blockchain.MoonriverTestnet,
|
||||
Blockchain.MantleTestnet,
|
||||
Blockchain.FlareTestnet,
|
||||
Blockchain.TaraxaTestnet,
|
||||
Blockchain.KoinosTestnet,
|
||||
Blockchain.BlastTestnet,
|
||||
Blockchain.CyberTestnet,
|
||||
Blockchain.SuiTestnet,
|
||||
Blockchain.EnergyWebChainTestnet,
|
||||
Blockchain.EnergyWebXTestnet,
|
||||
Blockchain.CasperTestnet,
|
||||
Blockchain.CoreTestnet,
|
||||
Blockchain.ChilizTestnet,
|
||||
Blockchain.AlephiumTestnet,
|
||||
Blockchain.VanarChainTestnet,
|
||||
Blockchain.OdysseyChainTestnet,
|
||||
Blockchain.BitrockTestnet,
|
||||
Blockchain.SonicTestnet,
|
||||
Blockchain.ApeChainTestnet,
|
||||
Blockchain.ScrollTestnet,
|
||||
Blockchain.ZkLinkNovaTestnet,
|
||||
Blockchain.PepecoinTestnet,
|
||||
Blockchain.HyperliquidTestnet,
|
||||
Blockchain.QuaiTestnet,
|
||||
// Blockchain.LineaTestnet,
|
||||
-> false
|
||||
// endregion
|
||||
}
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val UTXO_BLOCKCHAIN_NODE_INDEX = 2
|
||||
const val NON_UTXO_BLOCKCHAIN_NODE_INDEX = 4
|
||||
}
|
||||
}
|
||||
|
|
@ -24,8 +24,8 @@ class MutableDerivationPath internal constructor(val value: DerivationPath) {
|
|||
fun replaceAccountNode(value: Long, blockchain: Blockchain): MutableDerivationPath {
|
||||
val mutableNodes = this@MutableDerivationPath.value.nodes.toMutableList()
|
||||
|
||||
val accountNodeIndex = AccountNodeRecognizer(blockchain).accountNodeIndex
|
||||
val accountNode = mutableNodes.getOrNull(accountNodeIndex)
|
||||
val accountNodeIndex = AccountNodeRecognizer(blockchain).getAccountNodeIndex(this@MutableDerivationPath.value)
|
||||
val accountNode = accountNodeIndex?.let(mutableNodes::getOrNull)
|
||||
|
||||
if (accountNode != null) {
|
||||
mutableNodes[accountNodeIndex] = when (accountNode) {
|
||||
|
|
|
|||
|
|
@ -9,13 +9,13 @@ import org.junit.jupiter.api.Test
|
|||
internal class AccountNodeRecognizerTest {
|
||||
|
||||
private val utxoBlockchain = Blockchain.Bitcoin
|
||||
private val nonUtxoBlockchain = Blockchain.Ethereum
|
||||
private val ethLikeBlockchain = Blockchain.Ethereum
|
||||
|
||||
@Nested
|
||||
inner class RecognizeAsDerivationPath {
|
||||
|
||||
@Test
|
||||
fun `returns account node value for UTXO blockchain`() {
|
||||
fun `returns account node value for a derivation path with 5 nodes and UTXO blockchain`() {
|
||||
// Arrange
|
||||
val recognizer = AccountNodeRecognizer(utxoBlockchain)
|
||||
val derivationPath = DerivationPath(rawPath = "m/44'/0'/1'/0/0")
|
||||
|
|
@ -29,10 +29,104 @@ internal class AccountNodeRecognizerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun `returns account node value for non-UTXO blockchain`() {
|
||||
fun `returns account node value for a derivation path with 4 nodes and UTXO blockchain`() {
|
||||
// Arrange
|
||||
val recognizer = AccountNodeRecognizer(nonUtxoBlockchain)
|
||||
val derivationPath = DerivationPath(rawPath = "m/44'/0'/0'/0/0")
|
||||
val recognizer = AccountNodeRecognizer(utxoBlockchain)
|
||||
val derivationPath = DerivationPath(rawPath = "m/44'/0'/1'/0")
|
||||
|
||||
// Act
|
||||
val actual = recognizer.recognize(derivationPath)
|
||||
|
||||
// Assert
|
||||
Truth.assertThat(actual).isNull()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `returns account node value for a derivation path with 5 nodes and non-UTXO blockchain`() {
|
||||
// Arrange
|
||||
val recognizer = AccountNodeRecognizer(ethLikeBlockchain)
|
||||
val derivationPath = DerivationPath(rawPath = "m/44'/0'/1'/2/3")
|
||||
|
||||
// Act
|
||||
val actual = recognizer.recognize(derivationPath)
|
||||
|
||||
// Assert
|
||||
val expected = 3
|
||||
Truth.assertThat(actual).isEqualTo(expected)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `returns account node value for a derivation path with 4 nodes and non-UTXO blockchain`() {
|
||||
// Arrange
|
||||
val recognizer = AccountNodeRecognizer(ethLikeBlockchain)
|
||||
val derivationPath = DerivationPath(rawPath = "m/44'/0'/1'/2")
|
||||
|
||||
// Act
|
||||
val actual = recognizer.recognize(derivationPath)
|
||||
|
||||
// Assert
|
||||
Truth.assertThat(actual).isNull()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `returns account node value for a derivation path with 3 nodes and non-UTXO blockchain`() {
|
||||
// Arrange
|
||||
val recognizer = AccountNodeRecognizer(ethLikeBlockchain)
|
||||
val derivationPath = DerivationPath(rawPath = "m/44'/0'/1'")
|
||||
|
||||
// Act
|
||||
val actual = recognizer.recognize(derivationPath)
|
||||
|
||||
// Assert
|
||||
val expected = 1
|
||||
Truth.assertThat(actual).isEqualTo(expected)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `returns account node value for a derivation path with 4 nodes and Tezos blockchain`() {
|
||||
// Arrange
|
||||
val recognizer = AccountNodeRecognizer(Blockchain.Tezos)
|
||||
val derivationPath = DerivationPath(rawPath = "m/44'/0'/0/5'")
|
||||
|
||||
// Act
|
||||
val actual = recognizer.recognize(derivationPath)
|
||||
|
||||
// Assert
|
||||
val expected = 0
|
||||
Truth.assertThat(actual).isEqualTo(expected)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `returns account node value for a derivation path with 5 nodes and Tezos blockchain`() {
|
||||
// Arrange
|
||||
val recognizer = AccountNodeRecognizer(Blockchain.Tezos)
|
||||
val derivationPath = DerivationPath(rawPath = "m/44'/0'/0'/5/1")
|
||||
|
||||
// Act
|
||||
val actual = recognizer.recognize(derivationPath)
|
||||
|
||||
// Assert
|
||||
Truth.assertThat(actual).isNull()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `returns account node value for a derivation path with 4 nodes and Quai blockchain`() {
|
||||
// Arrange
|
||||
val recognizer = AccountNodeRecognizer(Blockchain.Quai)
|
||||
val derivationPath = DerivationPath(rawPath = "m/44'/0'/0/5'")
|
||||
|
||||
// Act
|
||||
val actual = recognizer.recognize(derivationPath)
|
||||
|
||||
// Assert
|
||||
Truth.assertThat(actual).isNull()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `returns account node value for a derivation path with 5 nodes and Quai blockchain`() {
|
||||
// Arrange
|
||||
val recognizer = AccountNodeRecognizer(Blockchain.Quai)
|
||||
val derivationPath = DerivationPath(rawPath = "m/44'/0'/0'/5/1")
|
||||
|
||||
// Act
|
||||
val actual = recognizer.recognize(derivationPath)
|
||||
|
|
@ -45,7 +139,7 @@ internal class AccountNodeRecognizerTest {
|
|||
@Test
|
||||
fun `returns null if derivation path is shorter than expected`() {
|
||||
// Arrange
|
||||
val recognizer = AccountNodeRecognizer(nonUtxoBlockchain)
|
||||
val recognizer = AccountNodeRecognizer(ethLikeBlockchain)
|
||||
val derivationPath = DerivationPath(rawPath = "m/44'/0'")
|
||||
|
||||
// Act
|
||||
|
|
@ -60,13 +154,13 @@ internal class AccountNodeRecognizerTest {
|
|||
inner class RecognizeAsString {
|
||||
|
||||
@Test
|
||||
fun `returns account node value for UTXO blockchain`() {
|
||||
fun `returns account node value for a derivation path with 5 nodes and UTXO blockchain`() {
|
||||
// Arrange
|
||||
val recognizer = AccountNodeRecognizer(utxoBlockchain)
|
||||
val derivationPath = "m/44'/0'/1'/0/0"
|
||||
val derivationPathValue = "m/44'/0'/1'/0/0"
|
||||
|
||||
// Act
|
||||
val actual = recognizer.recognize(derivationPath)
|
||||
val actual = recognizer.recognize(derivationPathValue)
|
||||
|
||||
// Assert
|
||||
val expected = 1
|
||||
|
|
@ -74,13 +168,107 @@ internal class AccountNodeRecognizerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun `returns account node value for non-UTXO blockchain`() {
|
||||
fun `returns account node value for a derivation path with 4 nodes and UTXO blockchain`() {
|
||||
// Arrange
|
||||
val recognizer = AccountNodeRecognizer(nonUtxoBlockchain)
|
||||
val derivationPath = "m/44'/0'/0'/0/0"
|
||||
val recognizer = AccountNodeRecognizer(utxoBlockchain)
|
||||
val derivationPathValue = "m/44'/0'/1'/0"
|
||||
|
||||
// Act
|
||||
val actual = recognizer.recognize(derivationPath)
|
||||
val actual = recognizer.recognize(derivationPathValue)
|
||||
|
||||
// Assert
|
||||
Truth.assertThat(actual).isNull()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `returns account node value for a derivation path with 5 nodes and non-UTXO blockchain`() {
|
||||
// Arrange
|
||||
val recognizer = AccountNodeRecognizer(ethLikeBlockchain)
|
||||
val derivationPathValue = "m/44'/0'/1'/2/3"
|
||||
|
||||
// Act
|
||||
val actual = recognizer.recognize(derivationPathValue)
|
||||
|
||||
// Assert
|
||||
val expected = 3
|
||||
Truth.assertThat(actual).isEqualTo(expected)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `returns account node value for a derivation path with 4 nodes and non-UTXO blockchain`() {
|
||||
// Arrange
|
||||
val recognizer = AccountNodeRecognizer(ethLikeBlockchain)
|
||||
val derivationPathValue = "m/44'/0'/1'/2"
|
||||
|
||||
// Act
|
||||
val actual = recognizer.recognize(derivationPathValue)
|
||||
|
||||
// Assert
|
||||
Truth.assertThat(actual).isNull()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `returns account node value for a derivation path with 3 nodes and non-UTXO blockchain`() {
|
||||
// Arrange
|
||||
val recognizer = AccountNodeRecognizer(ethLikeBlockchain)
|
||||
val derivationPathValue = "m/44'/0'/1'"
|
||||
|
||||
// Act
|
||||
val actual = recognizer.recognize(derivationPathValue)
|
||||
|
||||
// Assert
|
||||
val expected = 1
|
||||
Truth.assertThat(actual).isEqualTo(expected)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `returns account node value for a derivation path with 4 nodes and Tezos blockchain`() {
|
||||
// Arrange
|
||||
val recognizer = AccountNodeRecognizer(Blockchain.Tezos)
|
||||
val derivationPathValue = "m/44'/0'/0/5'"
|
||||
|
||||
// Act
|
||||
val actual = recognizer.recognize(derivationPathValue)
|
||||
|
||||
// Assert
|
||||
val expected = 0
|
||||
Truth.assertThat(actual).isEqualTo(expected)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `returns account node value for a derivation path with 5 nodes and Tezos blockchain`() {
|
||||
// Arrange
|
||||
val recognizer = AccountNodeRecognizer(Blockchain.Tezos)
|
||||
val derivationPathValue = "m/44'/0'/0'/5/1"
|
||||
|
||||
// Act
|
||||
val actual = recognizer.recognize(derivationPathValue)
|
||||
|
||||
// Assert
|
||||
Truth.assertThat(actual).isNull()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `returns account node value for a derivation path with 4 nodes and Quai blockchain`() {
|
||||
// Arrange
|
||||
val recognizer = AccountNodeRecognizer(Blockchain.Quai)
|
||||
val derivationPathValue = "m/44'/0'/0/5'"
|
||||
|
||||
// Act
|
||||
val actual = recognizer.recognize(derivationPathValue)
|
||||
|
||||
// Assert
|
||||
Truth.assertThat(actual).isNull()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `returns account node value for a derivation path with 5 nodes and Quai blockchain`() {
|
||||
// Arrange
|
||||
val recognizer = AccountNodeRecognizer(Blockchain.Quai)
|
||||
val derivationPathValue = "m/44'/0'/0'/5/1"
|
||||
|
||||
// Act
|
||||
val actual = recognizer.recognize(derivationPathValue)
|
||||
|
||||
// Assert
|
||||
val expected = 0
|
||||
|
|
@ -90,11 +278,11 @@ internal class AccountNodeRecognizerTest {
|
|||
@Test
|
||||
fun `returns null if derivation path is shorter than expected`() {
|
||||
// Arrange
|
||||
val recognizer = AccountNodeRecognizer(nonUtxoBlockchain)
|
||||
val derivationPath = "m/44'/0'"
|
||||
val recognizer = AccountNodeRecognizer(ethLikeBlockchain)
|
||||
val derivationPathValue = "m/44'/0'"
|
||||
|
||||
// Act
|
||||
val actual = recognizer.recognize(derivationPath)
|
||||
val actual = recognizer.recognize(derivationPathValue)
|
||||
|
||||
// Assert
|
||||
Truth.assertThat(actual).isNull()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue