-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from reown-com/develop
BOM_1.1.0
- Loading branch information
Showing
70 changed files
with
3,831 additions
and
208 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
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
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
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
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 |
---|---|---|
@@ -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> |
100 changes: 100 additions & 0 deletions
100
...walletkit/src/androidTest/kotlin/com/reown/walletkit/ChainAbstractionStatusUseCaseTest.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 |
---|---|---|
@@ -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) | ||
} | ||
} |
127 changes: 127 additions & 0 deletions
127
.../walletkit/src/androidTest/kotlin/com/reown/walletkit/GetTransactionDetailsUseCaseTest.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 |
---|---|---|
@@ -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")), | ||
) | ||
} | ||
} |
Oops, something went wrong.