Skip to content

Commit

Permalink
Merge pull request #38 from reown-com/develop
Browse files Browse the repository at this point in the history
BOM_1.1.0
  • Loading branch information
jakubuid authored Dec 20, 2024
2 parents 947b366 + cbeb3c4 commit 6ab21c4
Show file tree
Hide file tree
Showing 70 changed files with 3,831 additions and 208 deletions.
3 changes: 1 addition & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.apache.http.impl.client.HttpClients
import org.apache.http.util.EntityUtils
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.sonarqube.gradle.SonarExtension
import java.net.URL
import java.util.Base64
import javax.xml.parsers.DocumentBuilderFactory

Expand Down Expand Up @@ -108,8 +109,6 @@ task<Delete>("clean") {
delete(rootProject.layout.buildDirectory)
}



nexusPublishing {
repositories {
// project.version = "-SNAPSHOT"
Expand Down
16 changes: 8 additions & 8 deletions buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ const val KEY_PUBLISH_ARTIFACT_ID = "PUBLISH_ARTIFACT_ID"
const val KEY_SDK_NAME = "SDK_NAME"

//Latest versions
const val BOM_VERSION = "1.0.4"
const val FOUNDATION_VERSION = "1.0.4"
const val CORE_VERSION = "1.0.4"
const val SIGN_VERSION = "1.0.4"
const val NOTIFY_VERSION = "1.0.4"
const val WALLETKIT_VERSION = "1.0.4"
const val APPKIT_VERSION = "1.0.4"
const val MODAL_CORE_VERSION = "1.0.4"
const val BOM_VERSION = "1.1.0"
const val FOUNDATION_VERSION = "1.1.0"
const val CORE_VERSION = "1.1.0"
const val SIGN_VERSION = "1.1.0"
const val NOTIFY_VERSION = "1.1.0"
const val WALLETKIT_VERSION = "1.1.0"
const val APPKIT_VERSION = "1.1.0"
const val MODAL_CORE_VERSION = "1.1.0"

//Artifact ids
const val ANDROID_BOM = "android-bom"
Expand Down
6 changes: 6 additions & 0 deletions foundation/src/test/kotlin/com/reown/foundation/RelayTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,12 @@ class RelayTest {
val (clientA: RelayInterface, clientB: RelayInterface) = initTwoClients(packageName = "com.test.failure")

clientA.eventsFlow.onEach { event ->
println("Test Result: A event: $event")
when (event) {
is Relay.Model.Event.OnConnectionFailed -> {
println("Test Result: A onFailed")
if (event.throwable.message?.contains("403") == true) {
println("Test Result: A Success")
testState.compareAndSet(expect = TestState.Idle, update = TestState.Success)
}
}
Expand All @@ -96,9 +99,12 @@ class RelayTest {
}.launchIn(testScope)

clientB.eventsFlow.onEach { event ->
println("Test Result: B event: $event")
when (event) {
is Relay.Model.Event.OnConnectionFailed -> {
println("Test Result: B onFailed")
if (event.throwable.message?.contains("403") == true) {
println("Test Result: B Success")
testState.compareAndSet(expect = TestState.Idle, update = TestState.Success)
}
}
Expand Down
28 changes: 28 additions & 0 deletions product/walletkit/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import com.android.build.api.dsl.Packaging
import java.net.URL

plugins {
id("com.android.library")
id(libs.plugins.kotlin.android.get().pluginId)
Expand Down Expand Up @@ -33,6 +36,7 @@ android {
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "${rootDir.path}/gradle/proguard-rules/sdk-rules.pro", "${projectDir}/web3wallet-rules.pro")
}
}

lint {
abortOnError = true
ignoreWarnings = true
Expand All @@ -43,6 +47,12 @@ android {
sourceCompatibility = jvmVersion
targetCompatibility = jvmVersion
}

packaging {
jniLibs.pickFirsts.add("lib/arm64-v8a/libuniffi_yttrium.so")
jniLibs.pickFirsts.add("lib/armeabi-v7a/libuniffi_yttrium.so")
}

kotlinOptions {
jvmTarget = jvmVersion.toString()
freeCompilerArgs = freeCompilerArgs + "-opt-in=kotlin.time.ExperimentalTime"
Expand All @@ -54,6 +64,9 @@ android {
}

dependencies {
implementation("net.java.dev.jna:jna:5.15.0@aar")
implementation("com.github.reown-com:yttrium:0.4.11")

implementation(platform(libs.firebase.bom))
implementation(libs.firebase.messaging)

Expand All @@ -62,4 +75,19 @@ dependencies {

releaseImplementation("com.reown:android-core:$CORE_VERSION")
releaseImplementation("com.reown:sign:$SIGN_VERSION")

testImplementation(libs.bundles.androidxTest)
testImplementation(libs.robolectric)
testImplementation(libs.json)
testImplementation(libs.coroutines.test)
testImplementation(libs.bundles.scarlet.test)
testImplementation(libs.bundles.sqlDelight.test)
testImplementation(libs.koin.test)

androidTestImplementation(libs.mockk.android)
androidTestImplementation(libs.coroutines.test)
androidTestImplementation(libs.core)

androidTestUtil(libs.androidx.testOrchestrator)
androidTestImplementation(libs.bundles.androidxAndroidTest)
}
7 changes: 7 additions & 0 deletions product/walletkit/lint.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<lint>
<!-- Exclude the 'kotlin-bindings' directory from all lint checks -->
<issue id="all">
<ignore path="build/yttrium/kotlin-bindings/**" />
</issue>
</lint>
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package com.reown.walletkit

import com.reown.walletkit.client.Wallet
import com.reown.walletkit.use_cases.ChainAbstractionStatusUseCase
import io.mockk.coEvery
import io.mockk.mockk
import junit.framework.TestCase.assertTrue
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.async
import kotlinx.coroutines.test.runTest
import org.junit.Test
import uniffi.uniffi_yttrium.ChainAbstractionClient
import uniffi.yttrium.StatusResponse
import uniffi.yttrium.StatusResponseCompleted
import uniffi.yttrium.StatusResponseError
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine

@ExperimentalCoroutinesApi
class ChainAbstractionStatusUseCaseTest {
private val chainAbstractionClient: ChainAbstractionClient = mockk()
private val chainAbstractionStatusUseCase = ChainAbstractionStatusUseCase(chainAbstractionClient)

@Test
fun shouldCallOnSuccessWhenStatusIsCompleted() = runTest {
val fulfilmentId = "123"
val checkIn = 1000L
val completedResult = StatusResponse.Completed(StatusResponseCompleted(createdAt = 1u))

coEvery { chainAbstractionClient.status(fulfilmentId) } returns completedResult

val result = async {
suspendCoroutine { continuation ->
chainAbstractionStatusUseCase.invoke(
fulfilmentId,
checkIn,
onSuccess = {
continuation.resume(true)
},
onError = {
continuation.resume(false)
}
)
}
}.await()

assertTrue(result)
}

@Test
fun shouldCallOnErrorWhenStatusIsError() = runTest {
val fulfilmentId = "123"
val checkIn = 1000L
val errorResult = StatusResponse.Error(StatusResponseError(createdAt = 1u, error = "error"))

coEvery { chainAbstractionClient.status(fulfilmentId) } returns errorResult

val result = async {
suspendCoroutine { continuation ->
chainAbstractionStatusUseCase.invoke(
fulfilmentId,
checkIn,
onSuccess = {
continuation.resume(true)
},
onError = {
continuation.resume(it)
}
)
}
}.await()

assertTrue(result is Wallet.Model.Status.Error)
}

@Test
fun shouldCallOnErrorWhenErrorIsThrown() = runTest {
val fulfilmentId = "123"
val checkIn = 1000L

coEvery { chainAbstractionClient.status(fulfilmentId) } throws RuntimeException("error")

val result = async {
suspendCoroutine { continuation ->
chainAbstractionStatusUseCase.invoke(
fulfilmentId,
checkIn,
onSuccess = {
continuation.resume(false)
},
onError = {
continuation.resume(true)
}
)
}
}.await()

assertTrue(result)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
package com.reown.walletkit

import com.reown.walletkit.client.Wallet
import com.reown.walletkit.client.toWallet
import com.reown.walletkit.use_cases.GetTransactionDetailsUseCase
import io.mockk.coEvery
import io.mockk.mockk
import junit.framework.TestCase.assertTrue
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.async
import kotlinx.coroutines.test.runTest
import org.junit.Test
import uniffi.uniffi_yttrium.ChainAbstractionClient
import uniffi.yttrium.Amount
import uniffi.yttrium.FeeEstimatedTransaction
import uniffi.yttrium.Transaction
import uniffi.yttrium.TransactionFee
import uniffi.yttrium.TxnDetails
import uniffi.yttrium.UiFields
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine

@ExperimentalCoroutinesApi
class GetTransactionDetailsUseCaseTest {
private val chainAbstractionClient: ChainAbstractionClient = mockk()
private val getTransactionDetailsUseCase = GetTransactionDetailsUseCase(chainAbstractionClient)

@Test
fun shouldCallOnSuccessWithExpectedResultWhenClientSucceeds() = runTest {
val available = Wallet.Model.PrepareSuccess.Available(
fulfilmentId = "123",
checkIn = 11,
initialTransaction = transaction.toWallet(),
transactions = listOf(transaction.toWallet()),
funding = listOf(Wallet.Model.FundingMetadata(chainId = "1", tokenContract = "token", symbol = "s", amount = "11", decimals = 18, bridgingFee = "0")),
initialTransactionMetadata = Wallet.Model.InitialTransactionMetadata(transferTo = "aa", amount = "11", tokenContract = "cc", symbol = "s", decimals = 18)
)
val resultFields = UiFields(
route = listOf(txDetails),
initial = txDetails,
bridge = listOf(TransactionFee(Amount("11", "18", 2u, "22", "1222"), Amount("11", "18", 2u, "22", "1222"))),
localTotal = Amount("11", "18", 2u, "22", "1222"),
localBridgeTotal = Amount("11", "18", 2u, "22", "1222"),
localRouteTotal = Amount("11", "18", 2u, "22", "1222"),
)

coEvery { chainAbstractionClient.getUiFields(any(), any()) } returns resultFields

val result = async {
suspendCoroutine { continuation ->
getTransactionDetailsUseCase.invoke(
available,
onSuccess = {
continuation.resume(true)
},
onError = {
continuation.resume(false)
}
)
}
}.await()

assertTrue(result)
}

@Test
fun shouldCallOnErrorWhenClientThrowsAnException() = runTest {
val available = Wallet.Model.PrepareSuccess.Available(
fulfilmentId = "123",
checkIn = 11,
initialTransaction = transaction.toWallet(),
transactions = listOf(transaction.toWallet()),
funding = listOf(Wallet.Model.FundingMetadata(chainId = "1", tokenContract = "token", symbol = "s", amount = "11", decimals = 18, bridgingFee = "0")),
initialTransactionMetadata = Wallet.Model.InitialTransactionMetadata(transferTo = "aa", amount = "11", tokenContract = "cc", symbol = "s", decimals = 18)
)
val exception = Exception("Some error occurred")

coEvery { chainAbstractionClient.getUiFields(any(), any()) } throws exception

val result = async {
suspendCoroutine { continuation ->
getTransactionDetailsUseCase.invoke(
available,
onSuccess = {
println("success: $it")
continuation.resume(false)
},
onError = {
println("test1 error: $it")
continuation.resume(true)
}
)
}
}.await()

assertTrue(result)
}

companion object {
val transaction = Transaction(
from = "from",
to = "to",
value = "value",
input = "data",
nonce = "nonce",
gasLimit = "gas",
chainId = "1"
)

private val feeEstimatedTransactionMetadata = FeeEstimatedTransaction(
from = "from",
to = "to",
value = "value",
input = "data",
nonce = "nonce",
gasLimit = "gas",
chainId = "1",
maxPriorityFeePerGas = "11",
maxFeePerGas = "33"
)

val txDetails = TxnDetails(
transaction = feeEstimatedTransactionMetadata,
fee = TransactionFee(Amount("11", "18", 2u, "22", "1222"), Amount("11", "18", 2u, "22", "1222")),
)
}
}
Loading

0 comments on commit 6ab21c4

Please sign in to comment.