From bbbc67e899bfde3f877a341871ab28cb13cac2d3 Mon Sep 17 00:00:00 2001 From: jeremy lee Date: Wed, 29 May 2024 22:17:06 -0400 Subject: [PATCH] finish refactor and update test --- .../router/skip/SkipChainProcessor.kt | 1 - .../processor/router/skip/SkipProcessor.kt | 8 ++-- .../v2/supervisor/OnboardingSupervisor.kt | 2 - .../router/skip/SkipProcessorTests.kt | 43 +++++++++++-------- .../tests/payloads/SkipChainsMock.kt | 23 +++++++++- 5 files changed, 50 insertions(+), 27 deletions(-) diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/skip/SkipChainProcessor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/skip/SkipChainProcessor.kt index 74cd7a1f3..07ee41a16 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/skip/SkipChainProcessor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/skip/SkipChainProcessor.kt @@ -5,7 +5,6 @@ import exchange.dydx.abacus.protocols.ParserProtocol internal class SkipChainProcessor(private val parser: ParserProtocol) { fun received( - existing: Map?, payload: Map ): SelectionOption { return SelectionOption( 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 e1f24a293..8aac5ef8e 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 @@ -96,7 +96,7 @@ internal class SkipProcessor( } override fun defaultChainId(): String? { - val selectedChain = parser.asNativeMap(this.chains?.find { parser.asString(parser.asNativeMap(it)?.get("chain_id")) === "1" }) + val selectedChain = parser.asNativeMap(this.chains?.find { parser.asString(parser.asNativeMap(it)?.get("chain_id")) == "1" }) return parser.asString(selectedChain?.get("chain_id")) } @@ -121,7 +121,7 @@ internal class SkipProcessor( val chainResources = mutableMapOf() chainId?.let { this.chains?.find { - parser.asString(parser.asNativeMap(it)?.get("chainId")) == chainId + parser.asString(parser.asNativeMap(it)?.get("chain_id")) == chainId }?.let { val processor = SkipChainResourceProcessor(parser) parser.asNativeMap(it)?.let { payload -> @@ -144,13 +144,13 @@ internal class SkipProcessor( for (chain in it) { parser.asNativeMap(chain)?.let { chain -> if (parser.asString(chain.get("chainType")) != "cosmos") { - options.add(chainProcessor.received(null, chain)) + options.add(chainProcessor.received(chain)) } } } } - 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/state/v2/supervisor/OnboardingSupervisor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/OnboardingSupervisor.kt index d45e7e42e..a6b197be1 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 @@ -23,12 +23,10 @@ import exchange.dydx.abacus.state.manager.HumanReadableTransferPayload import exchange.dydx.abacus.state.manager.HumanReadableWithdrawPayload 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.squidRoute import exchange.dydx.abacus.state.model.squidRouteV2 import exchange.dydx.abacus.state.model.squidStatus import exchange.dydx.abacus.state.model.squidV2SdkInfo -import exchange.dydx.abacus.state.model.transfer import exchange.dydx.abacus.utils.AnalyticsUtils import exchange.dydx.abacus.utils.IMap import exchange.dydx.abacus.utils.Logger 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 230a1c398..087484ef3 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,4 +1,6 @@ package exchange.dydx.abacus.processor.router.skip +import exchange.dydx.abacus.output.input.SelectionOption +import exchange.dydx.abacus.state.internalstate.InternalTransferInputState import exchange.dydx.abacus.tests.payloads.SkipChainsMock import exchange.dydx.abacus.utils.Parser import kotlinx.serialization.json.Json @@ -12,7 +14,8 @@ internal fun templateToJson(template: String): Map { class SkipProcessorTests { - internal val skipProcessor = SkipProcessor(parser = Parser()) + internal val internalState = InternalTransferInputState() + internal val skipProcessor = SkipProcessor(parser = Parser(), internalState = internalState) internal val skipChainsMock = SkipChainsMock() @Test @@ -24,28 +27,30 @@ class SkipProcessorTests { ), ) - val expected = mapOf( + 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"), + SelectionOption(stringKey = "cheqd", string = "cheqd", type = "cheqd-mainnet-1", iconUrl = "https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/cheqd-mainnet/chain.png"), + SelectionOption(stringKey = "kujira", string = "kujira", type = "kaiyo-1", iconUrl = "https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/kaiyo/chain.png"), + 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 expectedModified = mapOf( "transfer" to mapOf( - "depositOptions" to mapOf( - "chains" to listOf( - mapOf("stringKey" to "aura", "type" to "xstaxy-1", "iconUrl" to "https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/xstaxy/chain.png"), - mapOf("stringKey" to "cheqd", "type" to "cheqd-mainnet-1", "iconUrl" to "https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/cheqd-mainnet/chain.png"), - mapOf("stringKey" to "kujira", "type" to "kaiyo-1", "iconUrl" to "https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/kaiyo/chain.png"), - mapOf("stringKey" to "osmosis", "type" to "osmosis-1", "iconUrl" to "https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/osmosis/chain.png"), - mapOf("stringKey" to "stride", "type" to "stride-1", "iconUrl" to "https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/stride/chain.png"), - ), - ), - "withdrawalOptions" to mapOf( - "chains" to listOf( - mapOf("stringKey" to "aura", "type" to "xstaxy-1", "iconUrl" to "https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/xstaxy/chain.png"), - mapOf("stringKey" to "cheqd", "type" to "cheqd-mainnet-1", "iconUrl" to "https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/cheqd-mainnet/chain.png"), - mapOf("stringKey" to "kujira", "type" to "kaiyo-1", "iconUrl" to "https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/kaiyo/chain.png"), - mapOf("stringKey" to "osmosis", "type" to "osmosis-1", "iconUrl" to "https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/osmosis/chain.png"), - mapOf("stringKey" to "stride", "type" to "stride-1", "iconUrl" to "https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/stride/chain.png"), + "chain" to "1", + "resources" to mapOf( + "chainResources" to mapOf( + "1" to mapOf( + "chainName" to "Ethereum", + "chainId" to "1", + "iconUrl" to "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/info/logo.png", + ), ), ), ), ) - assertEquals(modified, expected) + assertEquals(expectedModified, modified) } } diff --git a/src/commonTest/kotlin/exchange.dydx.abacus/tests/payloads/SkipChainsMock.kt b/src/commonTest/kotlin/exchange.dydx.abacus/tests/payloads/SkipChainsMock.kt index 006fb7358..a25cf8b92 100644 --- a/src/commonTest/kotlin/exchange.dydx.abacus/tests/payloads/SkipChainsMock.kt +++ b/src/commonTest/kotlin/exchange.dydx.abacus/tests/payloads/SkipChainsMock.kt @@ -160,7 +160,28 @@ internal class SkipChainsMock { "cosmos_autopilot": false }, "is_testnet": false - } + }, + { + "chain_name": "Ethereum", + "chain_id": "1", + "pfm_enabled": false, + "cosmos_module_support": { + "authz": false, + "feegrant": false + }, + "supports_memo": false, + "logo_uri": "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/info/logo.png", + "bech32_prefix": "", + "fee_assets": [], + "chain_type": "evm", + "ibc_capabilities": { + "cosmos_pfm": false, + "cosmos_ibc_hooks": false, + "cosmos_memo": false, + "cosmos_autopilot": false + }, + "is_testnet": false + } ] }""" }