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 31, 2024
1 parent df8cc99 commit 1296b6b
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 28 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 @@ -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"]),
)
}
}
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,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
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 @@ -17,7 +18,13 @@ internal fun templateToJson(template: String): Map<String, Any> {

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"
Expand Down Expand Up @@ -103,7 +110,7 @@ class SkipProcessorTests {
addTokens()
}

// ///////////////// UNIT TESTS //////////////////////
// ////////////////// UNIT TESTS //////////////////////
@Test
fun testFilteredTokens() {
val result = skipProcessor.filteredTokens(chainId = selectedChainId)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"),
Expand All @@ -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",
Expand All @@ -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)
}
}

0 comments on commit 1296b6b

Please sign in to comment.