diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/skip/SkipProcessor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/skip/SkipProcessor.kt index 1d8ae4ae0..8b215649e 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/skip/SkipProcessor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/skip/SkipProcessor.kt @@ -219,7 +219,7 @@ internal class SkipProcessor( } } } - options.sortBy { parser.asString(parser.asNativeMap(it)?.get("stringKey")) } + options.sortBy { parser.asString(it.stringKey) } return options } } diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/skip/SkipTokenResourceProcessor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/skip/SkipTokenResourceProcessor.kt index 27a32a708..149e23111 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/skip/SkipTokenResourceProcessor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/skip/SkipTokenResourceProcessor.kt @@ -15,7 +15,7 @@ internal class SkipTokenResourceProcessor( address = parser.asString(payload["denom"]), symbol = parser.asString(payload["symbol"]), decimals = parser.asInt(payload["decimals"]), - iconUrl = parser.asString(payload["logo_urk"]), + iconUrl = parser.asString(payload["logo_uri"]), ) } } diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/squid/SquidProcessor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/squid/SquidProcessor.kt index c0362a6be..f1d7c1e40 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/squid/SquidProcessor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/squid/SquidProcessor.kt @@ -173,8 +173,6 @@ internal class SquidProcessor( override fun updateTokensDefaults(modified: MutableMap, selectedChainId: String?) { val tokenOptions = tokenOptions(selectedChainId) internalState.tokens = tokenOptions - modified.safeSet("transfer.depositOptions.assets", tokenOptions) - modified.safeSet("transfer.withdrawalOptions.assets", tokenOptions) modified.safeSet("transfer.token", defaultTokenAddress(selectedChainId)) internalState.tokenResources = tokenResources(selectedChainId) } diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/OnboardingSupervisor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/OnboardingSupervisor.kt index 0404e940f..4214fb79b 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/OnboardingSupervisor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/OnboardingSupervisor.kt @@ -25,6 +25,7 @@ import exchange.dydx.abacus.state.manager.pendingCctpWithdraw import exchange.dydx.abacus.state.model.TradingStateMachine import exchange.dydx.abacus.state.model.TransferInputField import exchange.dydx.abacus.state.model.routerChains +import exchange.dydx.abacus.state.model.routerTokens import exchange.dydx.abacus.state.model.squidRoute import exchange.dydx.abacus.state.model.squidRouteV2 import exchange.dydx.abacus.state.model.squidStatus diff --git a/src/commonTest/kotlin/exchange.dydx.abacus/processor/router/skip/SkipProcessorTests.kt b/src/commonTest/kotlin/exchange.dydx.abacus/processor/router/skip/SkipProcessorTests.kt index 2d1812f4e..bab34cea4 100644 --- a/src/commonTest/kotlin/exchange.dydx.abacus/processor/router/skip/SkipProcessorTests.kt +++ b/src/commonTest/kotlin/exchange.dydx.abacus/processor/router/skip/SkipProcessorTests.kt @@ -1,6 +1,7 @@ package exchange.dydx.abacus.processor.router.skip import exchange.dydx.abacus.output.input.SelectionOption import exchange.dydx.abacus.output.input.TransferInputChainResource +import exchange.dydx.abacus.output.input.TransferInputTokenResource import exchange.dydx.abacus.state.internalstate.InternalTransferInputState import exchange.dydx.abacus.tests.payloads.SkipChainsMock import exchange.dydx.abacus.tests.payloads.SkipTokensMock @@ -17,7 +18,13 @@ internal fun templateToJson(template: String): Map { class SkipProcessorTests { +<<<<<<< HEAD internal val skipProcessor = SkipProcessor(parser = Parser(), internalState = InternalTransferInputState()) +======= + internal val internalState = InternalTransferInputState() + internal val parser = Parser() + internal val skipProcessor = SkipProcessor(parser = parser, internalState = internalState) +>>>>>>> d1c085f (fix tests and finish refactor) internal val skipChainsMock = SkipChainsMock() internal val skipTokensMock = SkipTokensMock() internal val selectedChainId = "osmosis-1" @@ -103,7 +110,7 @@ class SkipProcessorTests { addTokens() } -// ///////////////// UNIT TESTS ////////////////////// +// ////////////////// UNIT TESTS ////////////////////// @Test fun testFilteredTokens() { val result = skipProcessor.filteredTokens(chainId = selectedChainId) @@ -136,28 +143,29 @@ class SkipProcessorTests { fun testTokenResources() { val result = skipProcessor.tokenResources(selectedChainId) val expected = mapOf( - selectedTokenAddress to mapOf( - "address" to selectedTokenAddress, - "symbol" to selectedTokenSymbol, - "decimals" to selectedTokenDecimals, - "name" to "some-name", - "iconUrl" to "some-logo-uri", - ), - "testTokenKeyValue2" to mapOf( - "address" to "testTokenKeyValue2", - "symbol" to "ARB", - "decimals" to 8, - "name" to "some-name-2", - "iconUrl" to "some-logo-uri-2", - ), - "testTokenKeyValue3" to mapOf( - "address" to "testTokenKeyValue3", - "symbol" to "ETH", - "decimals" to 5, - "name" to "some-name-3", - "iconUrl" to "some-logo-uri-3", + selectedTokenAddress to TransferInputTokenResource( + address = selectedTokenAddress, + symbol = selectedTokenSymbol, + decimals = parser.asInt(selectedTokenDecimals), + name = "some-name", + iconUrl = "some-logo-uri", + ), + "testTokenKeyValue2" to TransferInputTokenResource( + address = "testTokenKeyValue2", + symbol = "ARB", + decimals = 8, + name = "some-name-2", + iconUrl = "some-logo-uri-2", + ), + "testTokenKeyValue3" to TransferInputTokenResource( + address = "testTokenKeyValue3", + symbol = "ETH", + decimals = 5, + name = "some-name-3", + iconUrl = "some-logo-uri-3", ), ) + assertEquals(expected, result) } @Test @@ -197,7 +205,6 @@ class SkipProcessorTests { existing = mapOf(), payload = payload, ) - val expectedChains = listOf( SelectionOption(stringKey = "Ethereum", string = "Ethereum", type = "1", iconUrl = "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/info/logo.png"), SelectionOption(stringKey = "aura", string = "aura", type = "xstaxy-1", iconUrl = "https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/xstaxy/chain.png"), @@ -206,8 +213,6 @@ class SkipProcessorTests { SelectionOption(stringKey = "osmosis", string = "osmosis", type = "osmosis-1", iconUrl = "https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/osmosis/chain.png"), SelectionOption(stringKey = "stride", string = "stride", type = "stride-1", iconUrl = "https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/stride/chain.png"), ) - assertEquals(expectedChains, internalState.chains) - val expectedChainResources = mapOf( "1" to TransferInputChainResource( chainName = "Ethereum", @@ -222,6 +227,85 @@ class SkipProcessorTests { "chain" to "1", ), ) + + assertEquals(expectedChains, internalState.chains) + assertEquals(payload["chains"], skipProcessor.chains) + assertEquals(expectedChainResources, internalState.chainResources) + assertEquals(expectedModified, modified) + } + + @Test + fun testReceivedTokens() { + val payload = templateToJson(skipTokensMock.payload) + skipProcessor.skipTokens = null + skipProcessor.chains = listOf( + mapOf( + "chain_name" to "aura", + "chain_id" to "1", + "pfm_enabled" to false, + "supports_memo" to true, + "logo_uri" to "https ://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/xstaxy/chain.png", + "bech32_prefix" to "aura", + "chain_type" to "cosmos", + "is_testnet" to false, + ), + ) + val modified = skipProcessor.receivedTokens( + existing = mapOf(), + payload = payload, + ) + val expectedModified = mapOf( + "transfer" to mapOf( + "token" to "0x97e6E0a40a3D02F12d1cEC30ebfbAE04e37C119E", + ), + ) + val expectedTokens = listOf( + SelectionOption( + stringKey = "Euro Coin", + string = "Euro Coin", + type = "0x1aBaEA1f7C830bD89Acc67eC4af516284b1bC33c", + iconUrl = "https://raw.githubusercontent.com/axelarnetwork/axelar-configs/main/images/tokens/euroc.svg", + ), + SelectionOption( + stringKey = "Real Yield USD", + string = "Real Yield USD", + type = "0x97e6E0a40a3D02F12d1cEC30ebfbAE04e37C119E", + iconUrl = "https://raw.githubusercontent.com/axelarnetwork/axelar-configs/main/images/tokens/yieldusd.svg", + ), + SelectionOption( + stringKey = "Umee native token", + string = "Umee native token", + type = "0x923e030f951A2401426a3407a9bcc7EB715d9a0b", + iconUrl = "https://raw.githubusercontent.com/axelarnetwork/axelar-configs/main/images/tokens/umee.svg", + ), + ) + val expectedTokenResources = mapOf( + "0x97e6E0a40a3D02F12d1cEC30ebfbAE04e37C119E" to TransferInputTokenResource( + name = "Real Yield USD", + address = "0x97e6E0a40a3D02F12d1cEC30ebfbAE04e37C119E", + symbol = "YieldUSD", + decimals = 18, + iconUrl = "https://raw.githubusercontent.com/axelarnetwork/axelar-configs/main/images/tokens/yieldusd.svg", + ), + "0x1aBaEA1f7C830bD89Acc67eC4af516284b1bC33c" to TransferInputTokenResource( + name = "Euro Coin", + address = "0x1aBaEA1f7C830bD89Acc67eC4af516284b1bC33c", + symbol = "EUROC", + decimals = 6, + iconUrl = "https://raw.githubusercontent.com/axelarnetwork/axelar-configs/main/images/tokens/euroc.svg", + ), + "0x923e030f951A2401426a3407a9bcc7EB715d9a0b" to TransferInputTokenResource( + name = "Umee native token", + address = "0x923e030f951A2401426a3407a9bcc7EB715d9a0b", + symbol = "UMEE", + decimals = 6, + iconUrl = "https://raw.githubusercontent.com/axelarnetwork/axelar-configs/main/images/tokens/umee.svg", + ), + ) + assertEquals(expectedModified, modified) + assertEquals(payload["chain_to_assets_map"], skipProcessor.skipTokens) + assertEquals(expectedTokens, internalState.tokens) + assertEquals(expectedTokenResources, internalState.tokenResources) } }