Skip to content

Commit 1e6b0a2

Browse files
committed
test: remove LoggingKt static mocks and fix stale onramp tests
trace() now no-ops before initialization, so mockkStatic(LoggingKt) is no longer needed. Removed from all 19 test files. Also fixed OnRampControllerTest (removed stale useSandbox param, added featureFlags dep, updated validation order to match production) and CoinbaseOnRampEventHandlerTest (commit_success is now skipped).
1 parent 48187b9 commit 1e6b0a2

20 files changed

Lines changed: 45 additions & 197 deletions

File tree

apps/flipcash/features/cash/src/test/kotlin/com/flipcash/app/cash/internal/CashScreenViewModelTest.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ import com.getcode.util.resources.ResourceHelper
2626
import com.getcode.view.LoadingSuccessState
2727
import io.mockk.every
2828
import io.mockk.mockk
29-
import io.mockk.mockkStatic
30-
import io.mockk.unmockkStatic
3129
import kotlinx.coroutines.ExperimentalCoroutinesApi
3230
import kotlinx.coroutines.flow.MutableStateFlow
3331
import kotlinx.coroutines.flow.emptyFlow
@@ -66,8 +64,6 @@ class CashScreenViewModelTest {
6664
@Before
6765
fun setUp() {
6866
BottomBarManager.clear()
69-
mockkStatic("com.getcode.utils.LoggingKt")
70-
every { com.getcode.utils.trace(any(), any(), any(), any(), any()) } returns Unit
7167

7268
// Stub resource strings used by the ViewModel
7369
every { resources.getString(R.string.error_title_youNeedMoreCash) } returns "error_title_youNeedMoreCash"
@@ -88,7 +84,6 @@ class CashScreenViewModelTest {
8884
@After
8985
fun tearDown() {
9086
BottomBarManager.clear()
91-
unmockkStatic("com.getcode.utils.LoggingKt")
9287
}
9388

9489
private fun createViewModel(): CashScreenViewModel {

apps/flipcash/features/contact-verification/src/test/kotlin/com/flipcash/app/contact/verification/internal/email/EmailVerificationViewModelErrorTest.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import com.flipcash.app.core.MainCoroutineRule
1010
import com.flipcash.app.core.dispatchers.TestDispatchers
1111
import io.mockk.every
1212
import io.mockk.mockk
13-
import io.mockk.mockkStatic
14-
import io.mockk.unmockkStatic
1513
import kotlinx.coroutines.ExperimentalCoroutinesApi
1614
import kotlinx.coroutines.test.UnconfinedTestDispatcher
1715
import kotlinx.coroutines.test.advanceUntilIdle
@@ -41,8 +39,6 @@ class EmailVerificationViewModelErrorTest {
4139
@Before
4240
fun setUp() {
4341
BottomBarManager.clear()
44-
mockkStatic("com.getcode.utils.LoggingKt")
45-
every { com.getcode.utils.trace(any(), any(), any(), any(), any()) } returns Unit
4642

4743
every { resources.getString(R.string.error_title_failedToSendCodeToEmail) } returns "error_title_failedToSendCodeToEmail"
4844
every { resources.getString(R.string.error_description_failedToSendCodeToEmail) } returns "error_description_failedToSendCodeToEmail"
@@ -61,7 +57,6 @@ class EmailVerificationViewModelErrorTest {
6157
@After
6258
fun tearDown() {
6359
BottomBarManager.clear()
64-
unmockkStatic("com.getcode.utils.LoggingKt")
6560
}
6661

6762
private fun createViewModel(): EmailVerificationViewModel {

apps/flipcash/features/contact-verification/src/test/kotlin/com/flipcash/app/contact/verification/internal/phone/PhoneVerificationViewModelErrorTest.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import com.flipcash.app.core.MainCoroutineRule
1111
import com.flipcash.app.core.dispatchers.TestDispatchers
1212
import io.mockk.every
1313
import io.mockk.mockk
14-
import io.mockk.mockkStatic
15-
import io.mockk.unmockkStatic
1614
import kotlinx.coroutines.ExperimentalCoroutinesApi
1715
import kotlinx.coroutines.test.UnconfinedTestDispatcher
1816
import kotlinx.coroutines.test.advanceUntilIdle
@@ -43,8 +41,6 @@ class PhoneVerificationViewModelErrorTest {
4341
@Before
4442
fun setUp() {
4543
BottomBarManager.clear()
46-
mockkStatic("com.getcode.utils.LoggingKt")
47-
every { com.getcode.utils.trace(any(), any(), any(), any(), any()) } returns Unit
4844

4945
every { resources.getString(R.string.error_title_failedToSendCodeToPhone) } returns "error_title_failedToSendCodeToPhone"
5046
every { resources.getString(R.string.error_description_failedToSendCodeToPhone) } returns "error_description_failedToSendCodeToPhone"
@@ -59,7 +55,6 @@ class PhoneVerificationViewModelErrorTest {
5955
@After
6056
fun tearDown() {
6157
BottomBarManager.clear()
62-
unmockkStatic("com.getcode.utils.LoggingKt")
6358
}
6459

6560
private fun createViewModel(): PhoneVerificationViewModel {

apps/flipcash/features/login/src/test/kotlin/com/flipcash/app/login/router/LoginViewModelErrorTest.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ class LoginViewModelErrorTest {
4747
@Before
4848
fun setUp() {
4949
BottomBarManager.clear()
50-
mockkStatic("com.getcode.utils.LoggingKt")
51-
every { com.getcode.utils.trace(any(), any(), any(), any(), any()) } returns Unit
5250
// android.util.Base64 is stubbed in unit tests; mock it so encodeBase64() doesn't NPE
5351
mockkStatic(android.util.Base64::class)
5452
every { android.util.Base64.encodeToString(any(), any()) } answers { java.util.Base64.getEncoder().encodeToString(firstArg()) }
@@ -61,7 +59,6 @@ class LoginViewModelErrorTest {
6159
@After
6260
fun tearDown() {
6361
BottomBarManager.clear()
64-
unmockkStatic("com.getcode.utils.LoggingKt")
6562
unmockkStatic(android.util.Base64::class)
6663
}
6764

apps/flipcash/features/transactions/src/test/kotlin/com/flipcash/app/transactions/internal/TransactionHistoryViewModelErrorTest.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ import com.flipcash.app.core.MainCoroutineRule
1414
import com.flipcash.app.core.dispatchers.TestDispatchers
1515
import io.mockk.every
1616
import io.mockk.mockk
17-
import io.mockk.mockkStatic
18-
import io.mockk.unmockkStatic
1917
import kotlinx.coroutines.ExperimentalCoroutinesApi
2018
import kotlinx.coroutines.test.UnconfinedTestDispatcher
2119
import kotlinx.coroutines.test.advanceUntilIdle
@@ -50,8 +48,6 @@ class TransactionHistoryViewModelErrorTest {
5048
@Before
5149
fun setUp() {
5250
BottomBarManager.clear()
53-
mockkStatic("com.getcode.utils.LoggingKt")
54-
every { com.getcode.utils.trace(any(), any(), any(), any(), any()) } returns Unit
5551

5652
every { userManager.accountCluster } returns accountCluster
5753
every { resources.getString(R.string.error_title_failedToCancelTransfer) } returns "error_title_failedToCancelTransfer"
@@ -61,7 +57,6 @@ class TransactionHistoryViewModelErrorTest {
6157
@After
6258
fun tearDown() {
6359
BottomBarManager.clear()
64-
unmockkStatic("com.getcode.utils.LoggingKt")
6560
}
6661

6762
private fun createViewModel(): TransactionHistoryViewModel {

apps/flipcash/features/withdrawal/src/test/kotlin/com/flipcash/app/withdrawal/WithdrawalViewModelErrorTest.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ import com.flipcash.app.core.MainCoroutineRule
1414
import com.flipcash.app.core.dispatchers.TestDispatchers
1515
import io.mockk.every
1616
import io.mockk.mockk
17-
import io.mockk.mockkStatic
18-
import io.mockk.unmockkStatic
1917
import kotlinx.coroutines.ExperimentalCoroutinesApi
2018
import kotlinx.coroutines.test.UnconfinedTestDispatcher
2119
import kotlinx.coroutines.test.advanceUntilIdle
@@ -46,8 +44,6 @@ class WithdrawalViewModelErrorTest {
4644
@Before
4745
fun setUp() {
4846
BottomBarManager.clear()
49-
mockkStatic("com.getcode.utils.LoggingKt")
50-
every { com.getcode.utils.trace(any(), any(), any(), any(), any()) } returns Unit
5147

5248
every { resources.getString(R.string.error_title_failedWithdrawal) } returns "error_title_failedWithdrawal"
5349
every { resources.getString(R.string.error_description_failedWithdrawal) } returns "error_description_failedWithdrawal"
@@ -56,7 +52,6 @@ class WithdrawalViewModelErrorTest {
5652
@After
5753
fun tearDown() {
5854
BottomBarManager.clear()
59-
unmockkStatic("com.getcode.utils.LoggingKt")
6055
}
6156

6257
private fun createViewModel(): WithdrawalViewModel {

apps/flipcash/shared/authentication/src/test/kotlin/com/flipcash/app/auth/AuthManagerTest.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ import io.mockk.coEvery
1717
import io.mockk.coVerify
1818
import io.mockk.every
1919
import io.mockk.mockk
20-
import io.mockk.mockkStatic
21-
import io.mockk.unmockkStatic
2220
import io.mockk.verify
2321
import kotlinx.coroutines.Dispatchers
2422
import kotlinx.coroutines.ExperimentalCoroutinesApi
@@ -59,8 +57,6 @@ class AuthManagerTest {
5957
@Before
6058
fun setUp() {
6159
Dispatchers.setMain(testDispatcher)
62-
mockkStatic("com.getcode.utils.LoggingKt")
63-
every { com.getcode.utils.trace(any(), any(), any(), any(), any()) } returns Unit
6460

6561
coEvery { pushTokenProvider.getToken() } returns "fake-token"
6662

@@ -88,7 +84,6 @@ class AuthManagerTest {
8884
@After
8985
fun tearDown() {
9086
Dispatchers.resetMain()
91-
unmockkStatic("com.getcode.utils.LoggingKt")
9287
}
9388

9489
@Test

apps/flipcash/shared/onramp/coinbase/src/test/kotlin/com/flipcash/app/onramp/OnRampControllerTest.kt

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,24 @@ package com.flipcash.app.onramp
22

33
import com.coinbase.onramp.api.CoinbaseApi
44
import com.coinbase.onramp.data.OnRampApiConfig
5+
import com.flipcash.app.featureflags.FeatureFlagController
56
import com.flipcash.services.models.UserProfile
67
import com.flipcash.services.user.UserManager
78
import com.getcode.opencode.exchange.Exchange
9+
import com.getcode.opencode.internal.solana.extensions.timelockSwapAccounts
810
import com.getcode.opencode.model.accounts.AccountCluster
911
import com.getcode.opencode.model.financial.CurrencyCode
1012
import com.getcode.opencode.model.financial.Fiat
13+
import com.getcode.opencode.model.financial.Token
14+
import com.getcode.opencode.model.financial.usdf
1115
import com.getcode.solana.keys.PublicKey
1216
import io.mockk.every
1317
import io.mockk.mockk
18+
import io.mockk.mockkStatic
19+
import io.mockk.unmockkStatic
1420
import kotlinx.coroutines.ExperimentalCoroutinesApi
1521
import kotlinx.coroutines.test.runTest
22+
import org.junit.After
1623
import org.junit.Before
1724
import org.junit.Test
1825
import org.junit.runner.RunWith
@@ -30,45 +37,56 @@ class OnRampControllerTest {
3037
private val api = mockk<CoinbaseApi>(relaxed = true)
3138
private val userManager = mockk<UserManager>(relaxed = true)
3239
private val exchange = mockk<Exchange>(relaxed = true)
40+
private val featureFlags = mockk<FeatureFlagController>(relaxed = true)
3341

3442
private val onRampApiEndpoint = OnRampApiConfig(
3543
scheme = "https",
3644
host = "api.example.com",
3745
path = "onramp/v1/buy",
3846
method = "POST",
39-
useSandbox = false,
4047
)
4148

4249
private lateinit var controller: OnRampController
4350

4451
@Before
4552
fun setUp() {
53+
// Token.usdf triggers Ed25519 native lib via deriveVirtualMachineAccount;
54+
// mock the extension property and timelockSwapAccounts to avoid the native call
55+
mockkStatic("com.getcode.opencode.model.financial.MintMetadataKt")
56+
mockkStatic("com.getcode.opencode.internal.solana.extensions.TokenKt")
57+
val fakeToken = mockk<Token>(relaxed = true)
58+
every { Token.usdf } returns fakeToken
59+
every { fakeToken.timelockSwapAccounts(any()) } returns mockk(relaxed = true)
60+
4661
controller = OnRampController(
4762
jwtProvider = jwtProvider,
4863
onRampApiEndpoint = onRampApiEndpoint,
4964
api = api,
5065
userManager = userManager,
5166
exchange = exchange,
67+
featureFlags = featureFlags,
5268
)
5369
}
5470

55-
private fun stubAccountId(present: Boolean = true) {
71+
@After
72+
fun tearDown() {
73+
unmockkStatic("com.getcode.opencode.model.financial.MintMetadataKt")
74+
unmockkStatic("com.getcode.opencode.internal.solana.extensions.TokenKt")
75+
}
76+
77+
private fun stubAccountCluster(present: Boolean = true) {
5678
if (present) {
57-
every { userManager.accountId } returns listOf(1, 2, 3, 4).map { it.toByte() }
79+
every { userManager.accountCluster } returns mockk<AccountCluster>(relaxed = true)
5880
} else {
59-
every { userManager.accountId } returns null
81+
every { userManager.accountCluster } returns null
6082
}
6183
}
6284

63-
private fun stubDepositAddress(present: Boolean = true) {
85+
private fun stubAccountId(present: Boolean = true) {
6486
if (present) {
65-
val address = PublicKey(ByteArray(32).toList())
66-
val cluster = mockk<AccountCluster>(relaxed = true) {
67-
every { usdfDepositAddress } returns address
68-
}
69-
every { userManager.accountCluster } returns cluster
87+
every { userManager.accountId } returns listOf(1, 2, 3, 4).map { it.toByte() }
7088
} else {
71-
every { userManager.accountCluster } returns null
89+
every { userManager.accountId } returns null
7290
}
7391
}
7492

@@ -83,39 +101,39 @@ class OnRampControllerTest {
83101
}
84102

85103
private fun stubValidUser() {
104+
stubAccountCluster()
86105
stubAccountId()
87-
stubDepositAddress()
88106
stubProfile()
89107
}
90108

91109
// region placeOrderInclusiveOfFees validation
92110

93111
@Test
94-
fun `placeOrderInclusiveOfFees fails when accountId is null`() = runTest {
95-
stubAccountId(present = false)
96-
stubDepositAddress()
112+
fun `placeOrderInclusiveOfFees fails when owner is null`() = runTest {
113+
stubAccountCluster(present = false)
114+
stubAccountId()
97115
stubProfile()
98116

99117
val result = controller.placeOrderInclusiveOfFees(Fiat(10, CurrencyCode.USD))
100118
assertTrue(result.isFailure)
101-
assertTrue(result.exceptionOrNull()?.message?.contains("User ID") == true)
119+
assertTrue(result.exceptionOrNull()?.message?.contains("Owner") == true)
102120
}
103121

104122
@Test
105-
fun `placeOrderInclusiveOfFees fails when deposit address is null`() = runTest {
106-
stubAccountId()
107-
stubDepositAddress(present = false)
123+
fun `placeOrderInclusiveOfFees fails when accountId is null`() = runTest {
124+
stubAccountCluster()
125+
stubAccountId(present = false)
108126
stubProfile()
109127

110128
val result = controller.placeOrderInclusiveOfFees(Fiat(10, CurrencyCode.USD))
111129
assertTrue(result.isFailure)
112-
assertTrue(result.exceptionOrNull()?.message?.contains("Deposit address") == true)
130+
assertTrue(result.exceptionOrNull()?.message?.contains("User ID") == true)
113131
}
114132

115133
@Test
116134
fun `placeOrderInclusiveOfFees fails when email is null`() = runTest {
135+
stubAccountCluster()
117136
stubAccountId()
118-
stubDepositAddress()
119137
stubProfile(email = null, phone = "+11234567890")
120138

121139
val result = controller.placeOrderInclusiveOfFees(Fiat(10, CurrencyCode.USD))
@@ -126,8 +144,8 @@ class OnRampControllerTest {
126144

127145
@Test
128146
fun `placeOrderInclusiveOfFees fails when phone is null`() = runTest {
147+
stubAccountCluster()
129148
stubAccountId()
130-
stubDepositAddress()
131149
stubProfile(email = "test@test.com", phone = null)
132150

133151
val result = controller.placeOrderInclusiveOfFees(Fiat(10, CurrencyCode.USD))
@@ -138,8 +156,8 @@ class OnRampControllerTest {
138156

139157
@Test
140158
fun `placeOrderInclusiveOfFees returns VerificationRequired with correct flags`() = runTest {
159+
stubAccountCluster()
141160
stubAccountId()
142-
stubDepositAddress()
143161
stubProfile(email = null, phone = null)
144162

145163
val result = controller.placeOrderInclusiveOfFees(Fiat(10, CurrencyCode.USD))
@@ -156,8 +174,8 @@ class OnRampControllerTest {
156174

157175
@Test
158176
fun `placeOrderExclusiveOfFees fails when accountId is null`() = runTest {
177+
stubAccountCluster()
159178
stubAccountId(present = false)
160-
stubDepositAddress()
161179
stubProfile()
162180

163181
val result = controller.placeOrderExclusiveOfFees(Fiat(10, CurrencyCode.USD))
@@ -177,8 +195,8 @@ class OnRampControllerTest {
177195

178196
@Test
179197
fun `placeOrderExclusiveOfFees fails when email and phone both null`() = runTest {
198+
stubAccountCluster()
180199
stubAccountId()
181-
stubDepositAddress()
182200
stubProfile(email = null, phone = null)
183201

184202
val result = controller.placeOrderExclusiveOfFees(Fiat(10, CurrencyCode.USD))

apps/flipcash/shared/onramp/coinbase/src/test/kotlin/com/flipcash/app/onramp/internal/CoinbaseOnRampEventHandlerTest.kt

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
package com.flipcash.app.onramp.internal
22

3-
import io.mockk.every
4-
import io.mockk.mockkStatic
5-
import io.mockk.unmockkStatic
6-
import org.junit.After
7-
import org.junit.Before
83
import org.junit.Test
94
import org.junit.runner.RunWith
105
import org.robolectric.RobolectricTestRunner
@@ -19,17 +14,6 @@ import kotlin.test.assertTrue
1914
@Config(manifest = Config.NONE)
2015
class CoinbaseOnRampEventHandlerTest {
2116

22-
@Before
23-
fun setUp() {
24-
mockkStatic("com.getcode.utils.LoggingKt")
25-
every { com.getcode.utils.trace(any(), any(), any(), any(), any()) } returns Unit
26-
}
27-
28-
@After
29-
fun tearDown() {
30-
unmockkStatic("com.getcode.utils.LoggingKt")
31-
}
32-
3317
private var successCount = 0
3418
private var cancelCount = 0
3519
private var autoClickCount = 0
@@ -52,9 +36,9 @@ class CoinbaseOnRampEventHandlerTest {
5236
}
5337

5438
@Test
55-
fun commitSuccessTriggersPaymentSuccess() {
39+
fun commitSuccessIsExplicitlySkipped() {
5640
handler.handleEvent("""{"eventName":"onramp_api.commit_success"}""")
57-
assertEquals(1, successCount)
41+
assertEquals(0, successCount, "commit_success should not trigger onPaymentSuccess")
5842
}
5943

6044
@Test

0 commit comments

Comments
 (0)