Skip to content

Commit

Permalink
Test fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubuid committed Sep 3, 2024
1 parent 3eb4a7c commit 598e3f3
Show file tree
Hide file tree
Showing 8 changed files with 275 additions and 226 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class CoreProtocol(private val koinApp: KoinApplication = wcKoinApp) : CoreInter
module { single { Echo } },
module { single { Push } },
module { single { Verify } },
coreJsonRpcModule(connectionType),
coreJsonRpcModule(),
corePairingModule(Pairing, PairingController),
keyServerModule(keyServerUrl),
explorerModule(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ internal class RelayJsonRpcInteractor(
override val wssConnectionState: StateFlow<WSSConnectionState> get() = relay.wssConnectionState

private var subscriptions = ObservableMap<String, String> { newMap -> if (newMap.isEmpty()) backoffStrategy.shouldBackoff(false) }
override val onResubscribe: Flow<Any?> = relay.onResubscribe
override val onResubscribe: Flow<Any?> get() = relay.onResubscribe

init {
manageSubscriptions()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class EventsRepositoryTest {
@Test
fun `insertOrAbort should insert event when telemetry is enabled`() = runTest(testDispatcher) {
val props = Props(event = "testEvent", type = "testType")
every { eventQueries.insertOrAbort(any(), any(), any(), any(), any(), any(), any(), any(), any(), any()) } just Runs
every { eventQueries.insertOrAbort(any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any()) } just Runs

repository.insertOrAbortTelemetry(props)

Expand All @@ -61,15 +61,16 @@ class EventsRepositoryTest {
trace = null,
correlation_id = any(),
client_id = any(),
direction = any()
direction = any(),
user_agent = any()
)
}
}

@Test
fun `insertOrAbort should insert event `() = runTest(testDispatcher) {
val props = Props(event = "testEvent", type = "testType")
every { eventQueries.insertOrAbort(any(), any(), any(), any(), any(), any(), any(), any(), any(), any()) } just Runs
every { eventQueries.insertOrAbort(any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any()) } just Runs

repository.insertOrAbort(props)

Expand All @@ -84,7 +85,8 @@ class EventsRepositoryTest {
trace = null,
correlation_id = any(),
client_id = any(),
direction = any()
direction = any(),
user_agent = any()
)
}
}
Expand All @@ -97,14 +99,14 @@ class EventsRepositoryTest {
repository.insertOrAbortTelemetry(props)

verify(exactly = 0) {
eventQueries.insertOrAbort(any(), any(), any(), any(), any(), any(), any(), any(), any(), any())
eventQueries.insertOrAbort(any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any())
}
}

@Test
fun `insertOrAbort should throw SQLiteException when insertion fails`() = runTest(testDispatcher) {
val props = Props(event = "testEvent", type = "testType")
every { eventQueries.insertOrAbort(any(), any(), any(), any(), any(), any(), any(), any(), any(), any()) } throws SQLiteException()
every { eventQueries.insertOrAbort(any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any()) } throws SQLiteException()

assertFailsWith<SQLiteException> {
repository.insertOrAbortTelemetry(props)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.walletconnect.android.internal

import com.tinder.scarlet.WebSocket
import com.walletconnect.android.internal.common.connection.ConnectivityState
import com.walletconnect.android.internal.common.connection.DefaultConnectionLifecycle
import com.walletconnect.android.internal.common.connection.ManualConnectionLifecycle
import com.walletconnect.android.internal.common.di.AndroidCommonDITags
import com.walletconnect.android.internal.common.scope
import com.walletconnect.android.relay.ConnectionType
Expand Down Expand Up @@ -34,6 +36,8 @@ import org.koin.dsl.module
class RelayClientTests {
private lateinit var relayClient: RelayClient
private val mockRelayService = mockk<RelayService>(relaxed = true)
private val defaultConnectionLifecycleMock = mockk<DefaultConnectionLifecycle>(relaxed = true)
private val manualConnectionLifecycleMock = mockk<ManualConnectionLifecycle>(relaxed = true)
private val mockLogger = mockk<Logger>(relaxed = true)
private val mockNetworkState = mockk<ConnectivityState>(relaxed = true)
private val testDispatcher = StandardTestDispatcher()
Expand All @@ -47,6 +51,8 @@ class RelayClientTests {
single(named(AndroidCommonDITags.RELAY_SERVICE)) { mockRelayService }
single(named(AndroidCommonDITags.LOGGER)) { mockLogger }
single(named(AndroidCommonDITags.CONNECTIVITY_STATE)) { mockNetworkState }
single(named(AndroidCommonDITags.MANUAL_CONNECTION_LIFECYCLE)) { manualConnectionLifecycleMock }
single(named(AndroidCommonDITags.DEFAULT_CONNECTION_LIFECYCLE)) { defaultConnectionLifecycleMock }
})
}

Expand All @@ -73,7 +79,7 @@ class RelayClientTests {

relayClient.initialize(ConnectionType.MANUAL) { error ->
assertEquals(
"Error while connecting, please check your Internet connection or contact support: java.lang.Throwable: Network failure",
"Error while connecting, please check your Internet connection or contact support: Network failure",
error.message
)
scope.coroutineContext.cancelChildren()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.walletconnect.android.internal.domain

import com.walletconnect.android.internal.common.ConditionalExponentialBackoffStrategy
import com.walletconnect.android.internal.common.JsonRpcResponse
import com.walletconnect.android.internal.common.connection.DefaultConnectionLifecycle
import com.walletconnect.android.internal.common.crypto.codec.Codec
import com.walletconnect.android.internal.common.exception.WalletConnectException
import com.walletconnect.android.internal.common.json_rpc.data.JsonRpcSerializer
Expand Down Expand Up @@ -42,8 +41,6 @@ internal class RelayerInteractorTest {
every { subscriptionRequest } returns flow { }
}

private val defaultConnectionLifecycle: DefaultConnectionLifecycle = mockk()

private val backoffStrategy: ConditionalExponentialBackoffStrategy = mockk()

private val jsonRpcHistory: JsonRpcHistory = mockk {
Expand Down Expand Up @@ -76,8 +73,9 @@ internal class RelayerInteractorTest {
}

private val sut =
spyk(RelayJsonRpcInteractor(relay, codec, jsonRpcHistory, pushMessagesRepository, logger, defaultConnectionLifecycle, backoffStrategy), recordPrivateCalls = true) {
spyk(RelayJsonRpcInteractor(relay, codec, jsonRpcHistory, pushMessagesRepository, logger, backoffStrategy), recordPrivateCalls = true) {
every { checkNetworkConnectivity() } answers { }
every { relay.onResubscribe } returns flow { }
}

private val topicVO = Topic("mockkTopic")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ abstract class BaseRelayClient : RelayInterface {
lateinit var connectionLifecycle: ConnectionLifecycle
protected var logger: Logger
private val resultState: MutableSharedFlow<RelayDTO> = MutableSharedFlow()
private var connectionState: MutableStateFlow<ConnectionState> = MutableStateFlow(ConnectionState.Idle)
internal var connectionState: MutableStateFlow<ConnectionState> = MutableStateFlow(ConnectionState.Idle)
private var unAckedTopics: MutableList<String> = mutableListOf()
private var isConnecting: Boolean = false
private var retryCount: Int = 0
Expand Down
Loading

0 comments on commit 598e3f3

Please sign in to comment.