-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
178 additions
and
21 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
...androidTest/kotlin/com/gemwallet/android/blockchain/clients/xrp/TestXrpAccountsService.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,27 @@ | ||
package com.gemwallet.android.blockchain.clients.xrp | ||
|
||
import com.gemwallet.android.blockchain.clients.xrp.services.XrpAccountsService | ||
import com.gemwallet.android.blockchain.rpc.model.JSONRpcRequest | ||
import com.wallet.core.blockchain.xrp.models.XRPAccount | ||
import com.wallet.core.blockchain.xrp.models.XRPAccountResult | ||
import com.wallet.core.blockchain.xrp.models.XRPResult | ||
|
||
internal class TestXrpAccountsService( | ||
val balance: String = "", | ||
) : XrpAccountsService { | ||
var requestAccount: String? = "" | ||
|
||
override suspend fun account(request: JSONRpcRequest<List<Map<String, String>>>): Result<XRPResult<XRPAccountResult>> { | ||
requestAccount = request.params[0]["account"] | ||
return Result.success( | ||
XRPResult( | ||
XRPAccountResult( | ||
XRPAccount( | ||
Balance = balance, | ||
Sequence = 92788459, | ||
) | ||
) | ||
) | ||
) | ||
} | ||
} |
113 changes: 113 additions & 0 deletions
113
...c/androidTest/kotlin/com/gemwallet/android/blockchain/clients/xrp/TestXrpBalanceClient.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,113 @@ | ||
package com.gemwallet.android.blockchain.clients.xrp | ||
|
||
import com.gemwallet.android.blockchain.clients.xrp.services.XrpAccountsService | ||
import com.gemwallet.android.blockchain.includeLibs | ||
import com.gemwallet.android.blockchain.rpc.model.JSONRpcRequest | ||
import com.gemwallet.android.ext.toIdentifier | ||
import com.wallet.core.blockchain.xrp.models.XRPAccount | ||
import com.wallet.core.blockchain.xrp.models.XRPAccountResult | ||
import com.wallet.core.blockchain.xrp.models.XRPResult | ||
import com.wallet.core.primitives.AssetId | ||
import com.wallet.core.primitives.Chain | ||
import junit.framework.TestCase.assertEquals | ||
import junit.framework.TestCase.assertNotNull | ||
import kotlinx.coroutines.runBlocking | ||
import org.junit.Test | ||
|
||
class TestXrpBalanceClient { | ||
companion object { | ||
init { | ||
includeLibs() | ||
} | ||
} | ||
|
||
@Test | ||
fun testXrp_native_balance() { | ||
val accountsService = TestXrpAccountsService("2104374") | ||
val balanceClient = XrpBalanceClient( | ||
chain = Chain.Xrp, | ||
accountsService = accountsService | ||
) | ||
val result = runBlocking { | ||
balanceClient.getNativeBalance(Chain.Xrp, "rwCq6DCHa6HPFyfvabvzcX1y5wABw5KdiN") | ||
} | ||
assertEquals("rwCq6DCHa6HPFyfvabvzcX1y5wABw5KdiN", accountsService.requestAccount) | ||
assertNotNull(result) | ||
assertEquals("1104374", result.balance.available) | ||
assertEquals("0", result.balance.frozen) | ||
assertEquals("0", result.balance.locked) | ||
assertEquals("0", result.balance.staked) | ||
assertEquals("0", result.balance.rewards) | ||
assertEquals("1000000", result.balance.reserved) | ||
assertEquals("0", result.balance.pending) | ||
assertEquals(1.104374, result.balanceAmount.available) | ||
assertEquals(0.0, result.balanceAmount.frozen) | ||
assertEquals(0.0, result.balanceAmount.locked) | ||
assertEquals(0.0, result.balanceAmount.staked) | ||
assertEquals(0.0, result.balanceAmount.rewards) | ||
assertEquals(1.0, result.balanceAmount.reserved) | ||
assertEquals(0.0, result.balanceAmount.pending) | ||
assertEquals(1.104374, result.totalAmount) | ||
assertEquals(AssetId(Chain.Xrp).toIdentifier(), result.asset.id.toIdentifier()) | ||
} | ||
|
||
@Test | ||
fun testXrp_native_fail_balance() { | ||
val accountsService = TestXrpAccountsService("") | ||
val balanceClient = XrpBalanceClient( | ||
chain = Chain.Xrp, | ||
accountsService = accountsService | ||
) | ||
val result = runBlocking { | ||
balanceClient.getNativeBalance(Chain.Xrp, "rwCq6DCHa6HPFyfvabvzcX1y5wABw5KdiN") | ||
} | ||
assertEquals("rwCq6DCHa6HPFyfvabvzcX1y5wABw5KdiN", accountsService.requestAccount) | ||
assertNotNull(result) | ||
assertEquals("0", result.balance.available) | ||
assertEquals("0", result.balance.frozen) | ||
assertEquals("0", result.balance.locked) | ||
assertEquals("0", result.balance.staked) | ||
assertEquals("0", result.balance.rewards) | ||
assertEquals("1000000", result.balance.reserved) | ||
assertEquals("0", result.balance.pending) | ||
assertEquals(0.0, result.balanceAmount.available) | ||
assertEquals(0.0, result.balanceAmount.frozen) | ||
assertEquals(0.0, result.balanceAmount.locked) | ||
assertEquals(0.0, result.balanceAmount.staked) | ||
assertEquals(0.0, result.balanceAmount.rewards) | ||
assertEquals(1.0, result.balanceAmount.reserved) | ||
assertEquals(0.0, result.balanceAmount.pending) | ||
assertEquals(0.0, result.totalAmount) | ||
assertEquals(AssetId(Chain.Xrp).toIdentifier(), result.asset.id.toIdentifier()) | ||
} | ||
|
||
@Test | ||
fun testXrp_native_zero_balance() { | ||
val accountsService = TestXrpAccountsService("1000000") | ||
val balanceClient = XrpBalanceClient( | ||
chain = Chain.Xrp, | ||
accountsService = accountsService | ||
) | ||
val result = runBlocking { | ||
balanceClient.getNativeBalance(Chain.Xrp, "rwCq6DCHa6HPFyfvabvzcX1y5wABw5KdiN") | ||
} | ||
assertEquals("rwCq6DCHa6HPFyfvabvzcX1y5wABw5KdiN", accountsService.requestAccount) | ||
assertNotNull(result) | ||
assertEquals("0", result.balance.available) | ||
assertEquals("0", result.balance.frozen) | ||
assertEquals("0", result.balance.locked) | ||
assertEquals("0", result.balance.staked) | ||
assertEquals("0", result.balance.rewards) | ||
assertEquals("1000000", result.balance.reserved) | ||
assertEquals("0", result.balance.pending) | ||
assertEquals(0.0, result.balanceAmount.available) | ||
assertEquals(0.0, result.balanceAmount.frozen) | ||
assertEquals(0.0, result.balanceAmount.locked) | ||
assertEquals(0.0, result.balanceAmount.staked) | ||
assertEquals(0.0, result.balanceAmount.rewards) | ||
assertEquals(1.0, result.balanceAmount.reserved) | ||
assertEquals(0.0, result.balanceAmount.pending) | ||
assertEquals(0.0, result.totalAmount) | ||
assertEquals(AssetId(Chain.Xrp).toIdentifier(), result.asset.id.toIdentifier()) | ||
} | ||
} |
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
1 change: 1 addition & 0 deletions
1
blockchain/src/main/java/com/gemwallet/android/blockchain/clients/xrp/XrpSignerPreloader.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
27 changes: 27 additions & 0 deletions
27
...src/main/java/com/gemwallet/android/blockchain/clients/xrp/services/XrpAccountsService.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,27 @@ | ||
package com.gemwallet.android.blockchain.clients.xrp.services | ||
|
||
import com.gemwallet.android.blockchain.clients.xrp.XrpMethod | ||
import com.gemwallet.android.blockchain.clients.xrp.XrpRpcClient | ||
import com.gemwallet.android.blockchain.rpc.model.JSONRpcRequest | ||
import com.wallet.core.blockchain.xrp.models.XRPAccountResult | ||
import com.wallet.core.blockchain.xrp.models.XRPResult | ||
import retrofit2.http.Body | ||
import retrofit2.http.POST | ||
|
||
interface XrpAccountsService { | ||
@POST("/") | ||
suspend fun account(@Body request: JSONRpcRequest<List<Map<String, String>>>): Result<XRPResult<XRPAccountResult>> | ||
} | ||
|
||
internal suspend fun XrpAccountsService.account(address: String): Result<XRPResult<XRPAccountResult>> { | ||
val request = JSONRpcRequest.create( | ||
XrpMethod.Account, | ||
listOf( | ||
mapOf( | ||
"account" to address, | ||
"ledger_index" to "current", | ||
) | ||
) | ||
) | ||
return account(request) | ||
} |
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