Updated on 2026-08-14

This commit is contained in:
Tangem 2026-03-20 21:54:46 +04:00
parent 8b75e37e30
commit a9bca131c3
386 changed files with 1369 additions and 1347 deletions

View file

@ -8,7 +8,7 @@ import dagger.hilt.android.testing.OnComponentReadyRunner
import org.junit.rules.TestRule
import org.junit.runner.Description
import org.junit.runners.model.Statement
import timber.log.Timber
import com.tangem.utils.logging.TangemLogger
import java.lang.reflect.Field
class ApplicationInjectionExecutionRule(
@ -46,7 +46,7 @@ class ApplicationInjectionExecutionRule(
try {
originalVersionValues = FeatureToggles.entries.associateWith { it.version }
} catch (e: Exception) {
Timber.e("Failed to save original toggles values: ${e.message}")
TangemLogger.e("Failed to save original toggles values: ${e.message}")
}
}
@ -60,9 +60,10 @@ class ApplicationInjectionExecutionRule(
versionField.set(toggle, newVersion)
}
Timber.i("FeatureToggles.values updated: $toggleStates")
TangemLogger.i("FeatureToggles.values updated: $toggleStates")
} catch (e: Exception) {
Timber.e("FeatureToggles.values didn't change with error: ${e.message}")
TangemLogger.e("FeatureToggles.values didn't change with error: ${e.message}")
}
}
@ -75,9 +76,9 @@ class ApplicationInjectionExecutionRule(
versionField.set(toggle, originalVersion)
}
Timber.i("FeatureToggles.values restored")
TangemLogger.i("FeatureToggles.values restored")
} catch (e: Exception) {
Timber.e("FeatureToggles.values didn't restored with error: ${e.message}")
TangemLogger.e("FeatureToggles.values didn't restored with error: ${e.message}")
}
}

View file

@ -11,7 +11,7 @@ import kotlinx.coroutines.runBlocking
import org.junit.rules.TestRule
import org.junit.runner.Description
import org.junit.runners.model.Statement
import timber.log.Timber
import com.tangem.utils.logging.TangemLogger
/**
* A JUnit rule that sets up the API environment for tests based on annotations or instrumentation arguments.
@ -82,11 +82,11 @@ class ApiEnvironmentRule : TestRule {
val environment = ApiEnvironment.valueOf(parts[1])
apiConfigId to environment
} catch (e: IllegalArgumentException) {
Timber.w("Invalid config or environment: $configPair")
TangemLogger.w("Invalid config or environment: $configPair")
null
}
} else {
Timber.w("Invalid config format: $configPair. Expected format: 'ConfigId=Environment'")
TangemLogger.w("Invalid config format: $configPair. Expected format: 'ConfigId=Environment'")
null
}
}
@ -94,7 +94,7 @@ class ApiEnvironmentRule : TestRule {
DEFAULT_API_CONFIGS.associateWith { ApiEnvironment.MOCK } + parsedConfigs
} catch (e: Exception) {
Timber.w("Failed to parse environment configs: $envConfigArg")
TangemLogger.w("Failed to parse environment configs: $envConfigArg")
DEFAULT_API_CONFIGS.associateWith { ApiEnvironment.MOCK }
}
}
@ -115,7 +115,7 @@ class ApiEnvironmentRule : TestRule {
runBlocking {
targetEnvironments.forEach { (apiConfigId, environment) ->
changeEnvironment(apiConfigId.name, environment)
Timber.i("$apiConfigId environment set to: ${environment.name}")
TangemLogger.i("$apiConfigId environment set to: ${environment.name}")
}
}
}

View file

@ -3,7 +3,7 @@ package com.tangem.common.utils
import okhttp3.OkHttpClient
import okhttp3.Request
import org.json.JSONObject
import timber.log.Timber
import com.tangem.utils.logging.TangemLogger
import java.util.concurrent.TimeUnit
/**
@ -13,7 +13,7 @@ fun getWcUri(
network: String = "ethereum",
baseUrl: String = "[REDACTED_ENV_URL]"
): String? {
Timber.i("Getting WC URI for network: $network")
TangemLogger.i("Getting WC URI for network: $network")
val client = OkHttpClient.Builder()
.connectTimeout(30, TimeUnit.SECONDS) // Таймаут подключения
@ -29,31 +29,31 @@ fun getWcUri(
return try {
client.newCall(request).execute().use { response ->
Timber.i("Response code: ${response.code}")
TangemLogger.i("Response code: ${response.code}")
if (response.isSuccessful) {
val body = response.body?.string() ?: ""
Timber.i("Response body: $body")
TangemLogger.i("Response body: $body")
val jsonObject = JSONObject(body)
if (jsonObject.getBoolean("success")) {
val wcUri = jsonObject.getString("wcUri")
Timber.i("Got WC URI successfully: $wcUri")
TangemLogger.i("Got WC URI successfully: $wcUri")
wcUri
} else {
Timber.e("API returned error: ${jsonObject.optString("error", "Unknown")}")
TangemLogger.e("API returned error: ${jsonObject.optString("error", "Unknown")}")
null
}
} else {
val errorBody = response.body?.string() ?: "No error body"
Timber.e("Request failed: ${response.code}, body: $errorBody")
TangemLogger.e("Request failed: ${response.code}, body: $errorBody")
null
}
}
} catch (e: Exception) {
Timber.e(e, "Error getting WC URI")
TangemLogger.e("Error getting WC URI", e)
null
}
}
@ -61,7 +61,7 @@ fun getWcUri(
fun checkServiceHealth(
baseUrl: String = "[REDACTED_ENV_URL]"
): String? {
Timber.i("Checking service health")
TangemLogger.i("Checking service health")
val client = OkHttpClient()
val request = Request.Builder()
@ -71,14 +71,14 @@ fun checkServiceHealth(
return try {
client.newCall(request).execute().use { response ->
Timber.i("Response code: ${response.code}")
TangemLogger.i("Response code: ${response.code}")
if (response.isSuccessful) {
val body = response.body?.string() ?: ""
Timber.i("Response body: $body")
TangemLogger.i("Response body: $body")
if (body.isEmpty()) {
Timber.e("Response body is empty")
TangemLogger.e("Response body is empty")
return null
}
@ -86,20 +86,20 @@ fun checkServiceHealth(
val status = jsonObject.optString("status", "")
if (status.isNotEmpty()) {
Timber.i("Got status successfully: $status")
TangemLogger.i("Got status successfully: $status")
status
} else {
Timber.e("Status field is missing or empty")
TangemLogger.e("Status field is missing or empty")
null
}
} else {
val errorBody = response.body?.string() ?: "No error body"
Timber.e("Request failed: ${response.code}, body: $errorBody")
TangemLogger.e("Request failed: ${response.code}, body: $errorBody")
null
}
}
} catch (e: Exception) {
Timber.e(e, "Error checking health")
TangemLogger.e("Error checking health", e)
null
}
}

View file

@ -4,7 +4,7 @@ import com.tangem.datasource.utils.WireMockRedirectInterceptor
import okhttp3.*
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.RequestBody.Companion.toRequestBody
import timber.log.Timber
import com.tangem.utils.logging.TangemLogger
import java.io.IOException
private const val DEFAULT_WIREMOCK_URL = "[REDACTED_ENV_URL]"
@ -27,8 +27,8 @@ fun setWireMockScenarioState(
state: String,
baseUrl: String = getWireMockBaseUrl()
): Boolean {
Timber.i("=== WireMock Scenario Set ===")
Timber.i("Setting scenario '$scenarioName' to state: $state")
TangemLogger.i("=== WireMock Scenario Set ===")
TangemLogger.i("Setting scenario '$scenarioName' to state: $state")
val client = OkHttpClient()
val json = """{"state": "$state"}"""
val mediaType = "application/json".toMediaType()
@ -41,14 +41,14 @@ fun setWireMockScenarioState(
return try {
client.newCall(request).execute().use { response ->
val body = response.body?.string() ?: ""
Timber.d("WireMock scenario request URL: ${request.url}")
Timber.d("WireMock scenario request body: $json")
Timber.d("WireMock scenario response: ${response.code} - ${response.message}")
Timber.d("WireMock scenario response body: $body")
TangemLogger.d("WireMock scenario request URL: ${request.url}")
TangemLogger.d("WireMock scenario request body: $json")
TangemLogger.d("WireMock scenario response: ${response.code} - ${response.message}")
TangemLogger.d("WireMock scenario response body: $body")
response.isSuccessful
}
} catch (e: IOException) {
Timber.e(e, "WireMock scenario error")
TangemLogger.e("WireMock scenario error", e)
false
}
}
@ -67,12 +67,12 @@ fun checkWireMockStatus(baseUrl: String = getWireMockBaseUrl()): Boolean {
return try {
client.newCall(request).execute().use { response ->
val body = response.body?.string() ?: ""
Timber.d("WireMock status check: ${response.code}")
Timber.d("Available scenarios: $body")
TangemLogger.d("WireMock status check: ${response.code}")
TangemLogger.d("Available scenarios: $body")
response.isSuccessful
}
} catch (e: IOException) {
Timber.e(e, "WireMock not accessible")
TangemLogger.e("WireMock not accessible", e)
false
}
}
@ -82,12 +82,12 @@ fun checkWireMockStatus(baseUrl: String = getWireMockBaseUrl()): Boolean {
* @param baseUrl WireMock base URL (defaults to local override if set, otherwise remote)
*/
fun resetWireMockScenarios(baseUrl: String = getWireMockBaseUrl()): Boolean {
Timber.i("=== WireMock Scenarios Reset ===")
Timber.i("Base URL: $baseUrl")
TangemLogger.i("=== WireMock Scenarios Reset ===")
TangemLogger.i("Base URL: $baseUrl")
val client = OkHttpClient()
val url = "$baseUrl/__admin/scenarios/reset"
Timber.i("Request URL: $url")
TangemLogger.i("Request URL: $url")
val request = Request.Builder()
.url(url)
@ -95,19 +95,19 @@ fun resetWireMockScenarios(baseUrl: String = getWireMockBaseUrl()): Boolean {
.build()
return try {
Timber.d("Sending reset request...")
TangemLogger.d("Sending reset request...")
client.newCall(request).execute().use { response ->
Timber.d("Response code: ${response.code}")
Timber.d("Response message: ${response.message}")
TangemLogger.d("Response code: ${response.code}")
TangemLogger.d("Response message: ${response.message}")
val responseBody = response.body?.string() ?: ""
Timber.d("Response body: $responseBody")
TangemLogger.d("Response body: $responseBody")
val isSuccessful = response.isSuccessful
Timber.d("Is successful: $isSuccessful")
TangemLogger.d("Is successful: $isSuccessful")
isSuccessful
}
} catch (e: IOException) {
Timber.e(e, "Exception during reset")
TangemLogger.e("Exception during reset", e)
false
}
}
@ -124,7 +124,7 @@ fun resetWireMockScenarioState(
initialState: String = "Started",
baseUrl: String = getWireMockBaseUrl()
): Boolean {
Timber.i("=== WireMock Scenario Reset ===")
Timber.i("Resetting scenario '$scenarioName' to initial state: $initialState")
TangemLogger.i("=== WireMock Scenario Reset ===")
TangemLogger.i("Resetting scenario '$scenarioName' to initial state: $initialState")
return setWireMockScenarioState(scenarioName, initialState, baseUrl)
}