Skip to content

Commit

Permalink
finish refactor and update test
Browse files Browse the repository at this point in the history
  • Loading branch information
yogurtandjam committed May 30, 2024
1 parent 6b85a5b commit bbbc67e
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import exchange.dydx.abacus.protocols.ParserProtocol

internal class SkipChainProcessor(private val parser: ParserProtocol) {
fun received(
existing: Map<String, Any>?,
payload: Map<String, Any>
): SelectionOption {
return SelectionOption(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
Expand All @@ -121,7 +121,7 @@ internal class SkipProcessor(
val chainResources = mutableMapOf<String, Any>()
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 ->
Expand All @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -12,7 +14,8 @@ internal fun templateToJson(template: String): Map<String, Any> {

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
Expand All @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]
}"""
}

0 comments on commit bbbc67e

Please sign in to comment.