Skip to content

Commit

Permalink
fix tests and finish refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
yogurtandjam committed May 30, 2024
1 parent db6ec4e commit d1c085f
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ internal class SkipProcessor(
}
}
}
options.sortBy { parser.asString(parser.asNativeMap(it)?.get("stringKey")) }
options.sortBy { parser.asString(it.stringKey) }
return options
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,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"]),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,6 @@ internal class SquidProcessor(
override fun updateTokensDefaults(modified: MutableMap<String, Any>, 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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ 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
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,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
Expand All @@ -18,7 +19,8 @@ internal fun templateToJson(template: String): Map<String, Any> {
class SkipProcessorTests {

internal val internalState = InternalTransferInputState()
internal val skipProcessor = SkipProcessor(parser = Parser(), internalState = internalState)
internal val parser = Parser()
internal val skipProcessor = SkipProcessor(parser = parser, internalState = internalState)
internal val skipChainsMock = SkipChainsMock()
internal val skipTokensMock = SkipTokensMock()
internal val selectedChainId = "osmosis-1"
Expand Down Expand Up @@ -104,7 +106,7 @@ class SkipProcessorTests {
addTokens()
}

// ///////////////// UNIT TESTS //////////////////////
// ////////////////// UNIT TESTS //////////////////////
@Test
fun testFilteredTokens() {
val result = skipProcessor.filteredTokens(chainId = selectedChainId)
Expand Down Expand Up @@ -137,28 +139,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",
selectedTokenAddress to TransferInputTokenResource(
address = selectedTokenAddress,
symbol = selectedTokenSymbol,
decimals = parser.asInt(selectedTokenDecimals),
name = "some-name",
iconUrl = "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",
"testTokenKeyValue2" to TransferInputTokenResource(
address = "testTokenKeyValue2",
symbol = "ARB",
decimals = 8,
name = "some-name-2",
iconUrl = "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",
"testTokenKeyValue3" to TransferInputTokenResource(
address = "testTokenKeyValue3",
symbol = "ETH",
decimals = 5,
name = "some-name-3",
iconUrl = "some-logo-uri-3",
),
)
assertEquals(expected, result)
}

@Test
Expand Down Expand Up @@ -198,7 +201,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"),
Expand All @@ -207,23 +209,22 @@ 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",
chainId = 1,
iconUrl = "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/info/logo.png",
),
)
assertEquals(payload["chains"], skipProcessor.chains)
assertEquals(expectedChainResources, internalState.chainResources)

val expectedModified = mapOf(
"transfer" to mapOf(
"chain" to "1",
),
)

assertEquals(expectedChains, internalState.chains)
assertEquals(payload["chains"], skipProcessor.chains)
assertEquals(expectedChainResources, internalState.chainResources)
assertEquals(expectedModified, modified)
}

Expand All @@ -243,67 +244,62 @@ class SkipProcessorTests {
"is_testnet" to false,
),
)

val result = skipProcessor.receivedTokens(
val modified = skipProcessor.receivedTokens(
existing = mapOf(),
payload = payload,
)

val assets = mapOf(
"assets" to listOf(
mapOf(
"stringKey" to "Euro Coin",
"type" to "0x1aBaEA1f7C830bD89Acc67eC4af516284b1bC33c",
"iconUrl" to "https://raw.githubusercontent.com/axelarnetwork/axelar-configs/main/images/tokens/euroc.svg",
),
mapOf(
"stringKey" to "Real Yield USD",
"type" to "0x97e6E0a40a3D02F12d1cEC30ebfbAE04e37C119E",
"iconUrl" to "https://raw.githubusercontent.com/axelarnetwork/axelar-configs/main/images/tokens/yieldusd.svg",
),
mapOf(
"stringKey" to "Umee native token",
"type" to "0x923e030f951A2401426a3407a9bcc7EB715d9a0b",
"iconUrl" to "https://raw.githubusercontent.com/axelarnetwork/axelar-configs/main/images/tokens/umee.svg",
),
),
)
val expected = mapOf<String, Any>(
val expectedModified = mapOf(
"transfer" to mapOf(
"depositOptions" to assets.toMap(),
"withdrawalOptions" to assets.toMap(),
"token" to "0x97e6E0a40a3D02F12d1cEC30ebfbAE04e37C119E",
"resources" to mapOf(
"tokenResources" to mapOf(
"0x97e6E0a40a3D02F12d1cEC30ebfbAE04e37C119E" to mapOf(
"name" to "Real Yield USD",
"address" to "0x97e6E0a40a3D02F12d1cEC30ebfbAE04e37C119E",
"symbol" to "YieldUSD",
"decimals" to 18,
"iconUrl" to "https://raw.githubusercontent.com/axelarnetwork/axelar-configs/main/images/tokens/yieldusd.svg",
),
"0x1aBaEA1f7C830bD89Acc67eC4af516284b1bC33c" to mapOf(
"name" to "Euro Coin",
"address" to "0x1aBaEA1f7C830bD89Acc67eC4af516284b1bC33c",
"symbol" to "EUROC",
"decimals" to 6,
"iconUrl" to "https://raw.githubusercontent.com/axelarnetwork/axelar-configs/main/images/tokens/euroc.svg",
),
"0x923e030f951A2401426a3407a9bcc7EB715d9a0b" to mapOf(
"name" to "Umee native token",
"address" to "0x923e030f951A2401426a3407a9bcc7EB715d9a0b",
"symbol" to "UMEE",
"decimals" to 6,
"iconUrl" to "https://raw.githubusercontent.com/axelarnetwork/axelar-configs/main/images/tokens/umee.svg",
),
),
),
),
)
// For some reason jtest fails the test even though the diff checker can't find a difference
// https://dydx-team.slack.com/archives/C06S9ND5T40/p1717014127580439
assertEquals(expected.keys, result?.keys)
assertEquals(expected.toString(), result?.toString())
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)
}
}

0 comments on commit d1c085f

Please sign in to comment.