-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement skipping invalid relays in RelayPool
- Loading branch information
1 parent
ac44694
commit 31d28c6
Showing
2 changed files
with
61 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 45 additions & 1 deletion
46
app/src/test/kotlin/net/primal/android/networking/relays/RelayPoolTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,47 @@ | ||
package net.primal.android.networking.relays | ||
|
||
class RelayPoolTest | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import kotlinx.coroutines.flow.flowOf | ||
import kotlinx.coroutines.test.runTest | ||
import net.primal.android.test.advanceUntilIdleAndDelay | ||
import net.primal.android.user.active.ActiveAccountStore | ||
import net.primal.android.user.active.ActiveUserAccountState | ||
import net.primal.android.user.domain.Relay | ||
import net.primal.android.user.domain.UserAccount | ||
import okhttp3.OkHttpClient | ||
import org.junit.Test | ||
|
||
@OptIn(ExperimentalCoroutinesApi::class) | ||
class RelayPoolTest { | ||
|
||
private fun buildActiveAccountStore( | ||
relays: List<Relay> = emptyList() | ||
) = mockk<ActiveAccountStore>(relaxed = true) { | ||
every { activeAccountState } returns flowOf( | ||
ActiveUserAccountState.ActiveUserAccount( | ||
data = UserAccount | ||
.buildLocal(pubkey = "") | ||
.copy(relays = relays) | ||
) | ||
) | ||
} | ||
|
||
@Test | ||
fun `invalid relays does not cause the crash`() = runTest { | ||
RelayPool( | ||
okHttpClient = OkHttpClient(), | ||
activeAccountStore = buildActiveAccountStore( | ||
relays = listOf( | ||
Relay(url = "abcdefghijkl", true, true), | ||
Relay(url = "wss://nostr-relay.untethr.me\t", true, true), | ||
Relay(url = "⬤ wss://nostr-pub.wellorder.net", true, true), | ||
Relay(url = "wss://filter.nostr.wine/npubxyz\n", true, true), | ||
) | ||
) | ||
) | ||
advanceUntilIdleAndDelay() | ||
} | ||
|
||
} |