Skip to content

Commit

Permalink
fix and finish tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yogurtandjam committed May 29, 2024
1 parent 5b0f0a0 commit a8dc02b
Showing 1 changed file with 103 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,29 @@ class SkipProcessorTests {
"denom" to selectedTokenAddress,
"symbol" to selectedTokenSymbol,
"decimals" to selectedTokenDecimals,
"name" to "some-name",
"logo_uri" to "some-logo-uri",
),
mapOf(
"denom" to "testTokenKeyValue2",
"symbol" to "ARB",
"decimals" to 8
"decimals" to 8,
"name" to "some-name-2",
"logo_uri" to "some-logo-uri-2"
),
mapOf(
"denom" to "testTokenKeyValue3",
"symbol" to "ETH",
"decimals" to 5
"denom" to "testTokenKeyValue3",
"symbol" to "ETH",
"decimals" to 5,
"name" to "some-name-3",
"logo_uri" to "some-logo-uri-3"
),
)

/**
* Adds tokens to the skipProcessor instance
* This is a reduced scope mock that is to be used for UNIT TESTS ONLY.
* Integration tests should use the skipChainsMock or skipTokensMock structures.
* The test tokens fixture looks like this:
* {
* "osmosis-1": {
Expand Down Expand Up @@ -89,43 +97,7 @@ class SkipProcessorTests {
internal fun setUp() {
addTokens()
}

@Test
fun testReceivedChains() {
val payload = templateToJson(
skipChainsMock.payload,
)
val modified = skipProcessor.receivedChains(
existing = mapOf(),
payload = payload,
)

val expected = 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"),
),
),
),
)
assertEquals(expected, modified)
assertEquals(payload["chains"], skipProcessor.chains)
}

/////////////////// UNIT TESTS //////////////////////
@Test
fun testFilteredTokens() {
val result = skipProcessor.filteredTokens(chainId = selectedChainId)
Expand Down Expand Up @@ -156,14 +128,94 @@ class SkipProcessorTests {

@Test
fun testTokenResources() {
// TODO: implement
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"
),
)
}

@Test
fun testTokenOptions() {
// TODO: implement
val result = skipProcessor.tokenOptions(selectedChainId)
val expected = listOf(
mapOf(
"stringKey" to "some-name",
"type" to selectedTokenAddress,
"iconUrl" to "some-logo-uri",
),
mapOf(
"stringKey" to "some-name-2",
"type" to "testTokenKeyValue2",
"iconUrl" to "some-logo-uri-2"
),
mapOf(
"stringKey" to "some-name-3",
"type" to "testTokenKeyValue3",
"iconUrl" to "some-logo-uri-3"
),
)
assertEquals(expected, result)
}

///////////////// INTEGRATION TESTS ////////////////////

@Test
fun testReceivedChains() {
val payload = templateToJson(
skipChainsMock.payload,
)
val result = skipProcessor.receivedChains(
existing = mapOf(),
payload = payload,
)

val expected = 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"),
),
),
),
)
assertEquals(expected, result)
assertEquals(payload["chains"], skipProcessor.chains)
}


@Test
fun testReceivedTokens() {
val payload = templateToJson(skipTokensMock.payload)
Expand All @@ -181,7 +233,7 @@ class SkipProcessorTests {
),
)

val modified = skipProcessor.receivedTokens(
val result = skipProcessor.receivedTokens(
existing = mapOf(),
payload = payload
)
Expand All @@ -205,10 +257,10 @@ class SkipProcessorTests {
)
)
)
val expected = mapOf(
val expected = mapOf<String, Any>(
"transfer" to mapOf(
"depositOptions" to assets,
"withdrawalOptions" to assets,
"depositOptions" to assets.toMap(),
"withdrawalOptions" to assets.toMap(),
"token" to "0x97e6E0a40a3D02F12d1cEC30ebfbAE04e37C119E",
"resources" to mapOf(
"tokenResources" to mapOf(
Expand Down Expand Up @@ -237,6 +289,9 @@ class SkipProcessorTests {
)
)
)
assertEquals(expected, modified)
// 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())
}
}

0 comments on commit a8dc02b

Please sign in to comment.