[#891] ZEC/TAZ currency distinction
This commit is contained in:
parent
bf3b6b32c5
commit
72564db24a
|
@ -0,0 +1,48 @@
|
|||
package cash.z.ecc.sdk.type
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import androidx.test.filters.SmallTest
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
import kotlin.test.assertNotSame
|
||||
|
||||
class ZcashCurrencyTest {
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
fun check_is_zec_type() {
|
||||
assertEquals(
|
||||
ZcashCurrency.ZEC,
|
||||
ZcashCurrency.fromResources(ApplicationProvider.getApplicationContext())
|
||||
)
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
fun wrong_network_type() {
|
||||
assertNotSame(
|
||||
ZcashCurrency.TAZ.network,
|
||||
ZcashCurrency.fromResources(ApplicationProvider.getApplicationContext()).network
|
||||
)
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
fun check_zec_properties() {
|
||||
val zecType = ZcashCurrency.ZEC
|
||||
|
||||
assertEquals(ZcashCurrency.ZEC.id, zecType.id)
|
||||
assertEquals(ZcashCurrency.ZEC.name, zecType.name)
|
||||
assertEquals(ZcashCurrency.ZEC.network, zecType.network)
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
fun check_taz_properties() {
|
||||
val tazType = ZcashCurrency.TAZ
|
||||
|
||||
assertEquals(ZcashCurrency.TAZ.id, tazType.id)
|
||||
assertEquals(ZcashCurrency.TAZ.name, tazType.name)
|
||||
assertEquals(ZcashCurrency.TAZ.network, tazType.network)
|
||||
}
|
||||
}
|
|
@ -8,12 +8,14 @@ import cash.z.ecc.sdk.fixture.Zip321UriParseFixture
|
|||
data class ZecRequest(val address: WalletAddress.Unified, val amount: Zatoshi, val message: ZecRequestMessage) {
|
||||
|
||||
// TODO [#397]: Waiting for an implementation of Uri parser in SDK project
|
||||
// TODO [#397]: https://github.com/zcash/zcash-android-wallet-sdk/issues/397
|
||||
suspend fun toUri(): String {
|
||||
return Zip321UriBuildFixture.new(this)
|
||||
}
|
||||
|
||||
companion object {
|
||||
// TODO [#397]: Waiting for an implementation of Uri parser in SDK project
|
||||
// TODO [#397]: https://github.com/zcash/zcash-android-wallet-sdk/issues/397
|
||||
suspend fun fromUri(uriString: String): ZecRequest {
|
||||
return Zip321UriParseFixture.new(uriString)
|
||||
}
|
||||
|
@ -28,6 +30,7 @@ value class ZecRequestMessage(val value: String) {
|
|||
|
||||
companion object {
|
||||
// TODO [#219]: Define a maximum message length
|
||||
// TODO [#219]: https://github.com/zcash/secant-android-wallet/issues/219
|
||||
// Also note that the length varies from what the user types in versus the encoded version
|
||||
// that is actually sent.
|
||||
const val MAX_MESSAGE_LENGTH = 320
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
package cash.z.ecc.sdk.type
|
||||
|
||||
import android.content.Context
|
||||
import cash.z.ecc.android.sdk.model.ZcashNetwork
|
||||
|
||||
/**
|
||||
* This class provides Zcash currency types with a distinction mechanism. There is the ZEC currency type, which applies
|
||||
* to the Mainnet network type, and TAZ, which applies to the Testnet network type. The currencies can't be mismatched
|
||||
* and are tightly connected to their network type.
|
||||
*
|
||||
* To get some TAZs to your test wallet, visit Testnet faucet: https://faucet.zecpages.com/
|
||||
*/
|
||||
sealed class ZcashCurrency(
|
||||
val id: Int = 0,
|
||||
val name: String = "TAZ",
|
||||
val network: ZcashNetwork = ZcashNetwork.Testnet
|
||||
) {
|
||||
object TAZ : ZcashCurrency(id = 0, name = "TAZ", network = ZcashNetwork.Testnet)
|
||||
|
||||
object ZEC : ZcashCurrency(id = 1, name = "ZEC", network = ZcashNetwork.Mainnet)
|
||||
|
||||
override fun toString(): String = "ZcashCurrency: id=$id, name=$name, network:$network"
|
||||
|
||||
companion object {
|
||||
fun fromResources(context: Context) =
|
||||
when (ZcashNetwork.fromResources(context)) {
|
||||
ZcashNetwork.Mainnet ->
|
||||
ZEC
|
||||
ZcashNetwork.Testnet ->
|
||||
TAZ
|
||||
else ->
|
||||
error("Not supported ZcashNetwork type while getting ZcashCurrency type.")
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue