From 68cfd21fe751eb689c86a03ca39ed29485764cf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Honza=20Rychnovsk=C3=BD?= Date: Mon, 8 Jan 2024 14:45:47 +0100 Subject: [PATCH] [#1287] Remove LightWalletEndpointExt public API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Closes #1287 - This refactored out all the occurrences of LightWalletEndpointExt and its functions and variables from the SDK’s public API. It preserves it in tests, demo app, and in the PersistableWallet for backward compatibility, although it’s not available from outside of the SDK. - Changelog updated --- CHANGELOG.md | 5 ++ .../darkside/test/DarksideTestCoordinator.kt | 2 +- .../android/sdk/darkside/test/TestWallet.kt | 2 +- .../LightWalletDarksideEndpointDefaultExt.kt | 26 ++++++++++ .../sdk/sample/demoapp/SampleCodeTest.kt | 4 +- .../z/ecc/android/sdk/demoapp/MainActivity.kt | 2 +- .../android/sdk/demoapp/SharedViewModel.kt | 2 +- .../ext/LightWalletEndpointDefaultExt.kt | 36 ++++++++++++++ .../screen/home/viewmodel/WalletViewModel.kt | 2 +- .../ui/screen/seed/view/ConfigureSeedView.kt | 2 +- .../sdk/model/PersistableWalletTest.kt | 14 +++++- .../android/sdk/model/PersistableWallet.kt | 40 +++++++++++++-- .../sdk/fixture/LightWalletEndpointFixture.kt | 38 ++++++++++++++ .../integration/service/ChangeServiceTest.kt | 7 +-- .../sdk/internal/SdkSynchronizerTest.kt | 11 ++--- .../android/sdk/util/BalancePrinterUtil.kt | 7 +-- .../ecc/android/sdk/util/DataDbScannerUtil.kt | 7 +-- .../cash/z/ecc/android/sdk/util/TestWallet.kt | 4 +- .../sdk/util/TransactionCounterUtil.kt | 5 +- .../sdk/model/LightWalletEndpointExt.kt | 49 ------------------- .../sdk/model/LightWalletEndpointTest.kt | 17 ------- 21 files changed, 177 insertions(+), 105 deletions(-) create mode 100644 darkside-test-lib/src/androidTest/java/cash/z/ecc/android/sdk/ext/LightWalletDarksideEndpointDefaultExt.kt create mode 100644 demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/ext/LightWalletEndpointDefaultExt.kt create mode 100644 sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/fixture/LightWalletEndpointFixture.kt delete mode 100644 sdk-lib/src/main/java/cash/z/ecc/android/sdk/model/LightWalletEndpointExt.kt delete mode 100644 sdk-lib/src/test/java/cash/z/ecc/android/sdk/model/LightWalletEndpointTest.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 25b37f6c..32e8d634 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,11 @@ and this library adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - `TransactionOverview.txIdString()` to provide a readable transaction ID to SDK-consuming apps +### Removed +- `LightWalletEndpointExt` and its functions and variables were removed from the SDK's public APIs entirely. It's + preserved only for testing and wallet Demo app purposes. The calling wallet app should provide its own + `LightWalletEndpoint` instance within `PersistableWallet` or `SdkSynchornizer` APIs. + ### Changed - Gradle 8.5 - Kotlin 1.9.21 diff --git a/darkside-test-lib/src/androidTest/java/cash/z/ecc/android/sdk/darkside/test/DarksideTestCoordinator.kt b/darkside-test-lib/src/androidTest/java/cash/z/ecc/android/sdk/darkside/test/DarksideTestCoordinator.kt index 5920c3e1..5a8d50ac 100644 --- a/darkside-test-lib/src/androidTest/java/cash/z/ecc/android/sdk/darkside/test/DarksideTestCoordinator.kt +++ b/darkside-test-lib/src/androidTest/java/cash/z/ecc/android/sdk/darkside/test/DarksideTestCoordinator.kt @@ -2,9 +2,9 @@ package cash.z.ecc.android.sdk.darkside.test import androidx.test.core.app.ApplicationProvider import androidx.test.platform.app.InstrumentationRegistry +import cash.z.ecc.android.sdk.ext.Darkside import cash.z.ecc.android.sdk.model.Account import cash.z.ecc.android.sdk.model.BlockHeight -import cash.z.ecc.android.sdk.model.Darkside import cash.z.ecc.android.sdk.model.ZcashNetwork import co.electriccoin.lightwallet.client.internal.DarksideApi import co.electriccoin.lightwallet.client.internal.new diff --git a/darkside-test-lib/src/androidTest/java/cash/z/ecc/android/sdk/darkside/test/TestWallet.kt b/darkside-test-lib/src/androidTest/java/cash/z/ecc/android/sdk/darkside/test/TestWallet.kt index 2310c5d1..3457942d 100644 --- a/darkside-test-lib/src/androidTest/java/cash/z/ecc/android/sdk/darkside/test/TestWallet.kt +++ b/darkside-test-lib/src/androidTest/java/cash/z/ecc/android/sdk/darkside/test/TestWallet.kt @@ -6,10 +6,10 @@ import cash.z.ecc.android.bip39.toSeed import cash.z.ecc.android.sdk.SdkSynchronizer import cash.z.ecc.android.sdk.Synchronizer import cash.z.ecc.android.sdk.WalletInitMode +import cash.z.ecc.android.sdk.ext.Darkside import cash.z.ecc.android.sdk.internal.Twig import cash.z.ecc.android.sdk.model.Account import cash.z.ecc.android.sdk.model.BlockHeight -import cash.z.ecc.android.sdk.model.Darkside import cash.z.ecc.android.sdk.model.WalletBalance import cash.z.ecc.android.sdk.model.Zatoshi import cash.z.ecc.android.sdk.model.ZcashNetwork diff --git a/darkside-test-lib/src/androidTest/java/cash/z/ecc/android/sdk/ext/LightWalletDarksideEndpointDefaultExt.kt b/darkside-test-lib/src/androidTest/java/cash/z/ecc/android/sdk/ext/LightWalletDarksideEndpointDefaultExt.kt new file mode 100644 index 00000000..9a20b194 --- /dev/null +++ b/darkside-test-lib/src/androidTest/java/cash/z/ecc/android/sdk/ext/LightWalletDarksideEndpointDefaultExt.kt @@ -0,0 +1,26 @@ +@file:Suppress("ktlint:standard:filename") + +package cash.z.ecc.android.sdk.ext + +import co.electriccoin.lightwallet.client.model.LightWalletEndpoint + +/* + * This is a set of the [LightWalletEndpoint] extension functions used for the darkside tests only and not part of the + * public APIs. + */ + +/** + * This is a special localhost value on the Android emulator, which allows it to contact + * the localhost of the computer running the emulator. + */ +private const val COMPUTER_LOCALHOST = "10.0.2.2" + +private const val DEFAULT_PORT = 9067 + +internal val LightWalletEndpoint.Companion.Darkside + get() = + LightWalletEndpoint( + COMPUTER_LOCALHOST, + DEFAULT_PORT, + isSecure = false + ) diff --git a/demo-app/src/androidTest/java/cash/z/wallet/sdk/sample/demoapp/SampleCodeTest.kt b/demo-app/src/androidTest/java/cash/z/wallet/sdk/sample/demoapp/SampleCodeTest.kt index 2d395a5e..3b68a48a 100644 --- a/demo-app/src/androidTest/java/cash/z/wallet/sdk/sample/demoapp/SampleCodeTest.kt +++ b/demo-app/src/androidTest/java/cash/z/wallet/sdk/sample/demoapp/SampleCodeTest.kt @@ -3,15 +3,15 @@ package cash.z.wallet.sdk.sample.demoapp import androidx.test.platform.app.InstrumentationRegistry import cash.z.ecc.android.sdk.Synchronizer import cash.z.ecc.android.sdk.WalletInitMode +import cash.z.ecc.android.sdk.demoapp.ext.Mainnet +import cash.z.ecc.android.sdk.demoapp.ext.defaultForNetwork import cash.z.ecc.android.sdk.demoapp.util.fromResources import cash.z.ecc.android.sdk.ext.convertZecToZatoshi import cash.z.ecc.android.sdk.ext.toHex import cash.z.ecc.android.sdk.internal.Twig import cash.z.ecc.android.sdk.model.Account import cash.z.ecc.android.sdk.model.BlockHeight -import cash.z.ecc.android.sdk.model.Mainnet import cash.z.ecc.android.sdk.model.ZcashNetwork -import cash.z.ecc.android.sdk.model.defaultForNetwork import cash.z.ecc.android.sdk.tool.DerivationTool import co.electriccoin.lightwallet.client.LightWalletClient import co.electriccoin.lightwallet.client.model.BlockHeightUnsafe diff --git a/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/MainActivity.kt b/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/MainActivity.kt index 87c84333..2f05afd0 100644 --- a/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/MainActivity.kt +++ b/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/MainActivity.kt @@ -20,9 +20,9 @@ import androidx.navigation.ui.navigateUp import androidx.navigation.ui.setupActionBarWithNavController import androidx.navigation.ui.setupWithNavController import androidx.viewbinding.ViewBinding +import cash.z.ecc.android.sdk.demoapp.ext.defaultForNetwork import cash.z.ecc.android.sdk.demoapp.util.fromResources import cash.z.ecc.android.sdk.model.ZcashNetwork -import cash.z.ecc.android.sdk.model.defaultForNetwork import co.electriccoin.lightwallet.client.LightWalletClient import co.electriccoin.lightwallet.client.model.LightWalletEndpoint import co.electriccoin.lightwallet.client.new diff --git a/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/SharedViewModel.kt b/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/SharedViewModel.kt index 048801be..20e17cb6 100644 --- a/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/SharedViewModel.kt +++ b/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/SharedViewModel.kt @@ -7,12 +7,12 @@ import cash.z.ecc.android.bip39.Mnemonics import cash.z.ecc.android.bip39.toSeed import cash.z.ecc.android.sdk.Synchronizer import cash.z.ecc.android.sdk.WalletInitMode +import cash.z.ecc.android.sdk.demoapp.ext.defaultForNetwork import cash.z.ecc.android.sdk.demoapp.util.fromResources import cash.z.ecc.android.sdk.ext.onFirst import cash.z.ecc.android.sdk.internal.Twig import cash.z.ecc.android.sdk.model.BlockHeight import cash.z.ecc.android.sdk.model.ZcashNetwork -import cash.z.ecc.android.sdk.model.defaultForNetwork import co.electriccoin.lightwallet.client.ext.BenchmarkingExt import co.electriccoin.lightwallet.client.fixture.BenchmarkingBlockRangeFixture import co.electriccoin.lightwallet.client.model.LightWalletEndpoint diff --git a/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/ext/LightWalletEndpointDefaultExt.kt b/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/ext/LightWalletEndpointDefaultExt.kt new file mode 100644 index 00000000..0b379bdf --- /dev/null +++ b/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/ext/LightWalletEndpointDefaultExt.kt @@ -0,0 +1,36 @@ +@file:Suppress("ktlint:standard:filename") + +package cash.z.ecc.android.sdk.demoapp.ext + +import cash.z.ecc.android.sdk.model.ZcashNetwork +import co.electriccoin.lightwallet.client.model.LightWalletEndpoint + +/* + * This set of extension functions suited for defaults for the Demo app is not part of the SDK's public APIs. + */ + +internal fun LightWalletEndpoint.Companion.defaultForNetwork(zcashNetwork: ZcashNetwork): LightWalletEndpoint { + return when (zcashNetwork.id) { + ZcashNetwork.Mainnet.id -> LightWalletEndpoint.Mainnet + ZcashNetwork.Testnet.id -> LightWalletEndpoint.Testnet + else -> error("Unknown network id: ${zcashNetwork.id}") + } +} + +private const val DEFAULT_PORT = 9067 + +internal val LightWalletEndpoint.Companion.Mainnet + get() = + LightWalletEndpoint( + "mainnet.lightwalletd.com", + DEFAULT_PORT, + isSecure = true + ) + +internal val LightWalletEndpoint.Companion.Testnet + get() = + LightWalletEndpoint( + "lightwalletd.testnet.electriccoin.co", + DEFAULT_PORT, + isSecure = true + ) diff --git a/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/ui/screen/home/viewmodel/WalletViewModel.kt b/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/ui/screen/home/viewmodel/WalletViewModel.kt index 8431063d..5ed2b1f7 100644 --- a/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/ui/screen/home/viewmodel/WalletViewModel.kt +++ b/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/ui/screen/home/viewmodel/WalletViewModel.kt @@ -9,6 +9,7 @@ import cash.z.ecc.android.sdk.Synchronizer import cash.z.ecc.android.sdk.WalletCoordinator import cash.z.ecc.android.sdk.WalletInitMode import cash.z.ecc.android.sdk.block.processor.CompactBlockProcessor +import cash.z.ecc.android.sdk.demoapp.ext.defaultForNetwork import cash.z.ecc.android.sdk.demoapp.getInstance import cash.z.ecc.android.sdk.demoapp.preference.EncryptedPreferenceKeys import cash.z.ecc.android.sdk.demoapp.preference.EncryptedPreferenceSingleton @@ -25,7 +26,6 @@ import cash.z.ecc.android.sdk.model.WalletBalance import cash.z.ecc.android.sdk.model.Zatoshi import cash.z.ecc.android.sdk.model.ZcashNetwork import cash.z.ecc.android.sdk.model.ZecSend -import cash.z.ecc.android.sdk.model.defaultForNetwork import cash.z.ecc.android.sdk.model.send import cash.z.ecc.android.sdk.tool.DerivationTool import co.electriccoin.lightwallet.client.model.LightWalletEndpoint diff --git a/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/ui/screen/seed/view/ConfigureSeedView.kt b/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/ui/screen/seed/view/ConfigureSeedView.kt index 93f94ff8..db3a91f1 100644 --- a/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/ui/screen/seed/view/ConfigureSeedView.kt +++ b/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/ui/screen/seed/view/ConfigureSeedView.kt @@ -17,11 +17,11 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview import cash.z.ecc.android.sdk.WalletInitMode import cash.z.ecc.android.sdk.demoapp.R +import cash.z.ecc.android.sdk.demoapp.ext.defaultForNetwork import cash.z.ecc.android.sdk.fixture.WalletFixture import cash.z.ecc.android.sdk.model.PersistableWallet import cash.z.ecc.android.sdk.model.SeedPhrase import cash.z.ecc.android.sdk.model.ZcashNetwork -import cash.z.ecc.android.sdk.model.defaultForNetwork import co.electriccoin.lightwallet.client.model.LightWalletEndpoint @Preview(name = "Seed") diff --git a/sdk-incubator-lib/src/androidTest/kotlin/cash/z/ecc/android/sdk/model/PersistableWalletTest.kt b/sdk-incubator-lib/src/androidTest/kotlin/cash/z/ecc/android/sdk/model/PersistableWalletTest.kt index b6329dac..c412bcdc 100644 --- a/sdk-incubator-lib/src/androidTest/kotlin/cash/z/ecc/android/sdk/model/PersistableWalletTest.kt +++ b/sdk-incubator-lib/src/androidTest/kotlin/cash/z/ecc/android/sdk/model/PersistableWalletTest.kt @@ -124,8 +124,20 @@ class PersistableWalletTest { // Wallet version one deserialized by code supporting version two val persistableWallet = PersistableWallet.from(json) assertEquals( - LightWalletEndpoint.defaultForNetwork(persistableWallet.network), + getLightWalletEndpointForNetwork(persistableWallet.network), persistableWallet.endpoint ) } + + @Test + @SmallTest + fun requireSecureMainnet() { + assertTrue(LightWalletEndpoint.Mainnet.isSecure) + } + + @Test + @SmallTest + fun requireSecureTestnet() { + assertTrue(LightWalletEndpoint.Testnet.isSecure) + } } diff --git a/sdk-incubator-lib/src/main/java/cash/z/ecc/android/sdk/model/PersistableWallet.kt b/sdk-incubator-lib/src/main/java/cash/z/ecc/android/sdk/model/PersistableWallet.kt index 93a2f5ba..991412c6 100644 --- a/sdk-incubator-lib/src/main/java/cash/z/ecc/android/sdk/model/PersistableWallet.kt +++ b/sdk-incubator-lib/src/main/java/cash/z/ecc/android/sdk/model/PersistableWallet.kt @@ -14,7 +14,7 @@ import org.json.JSONObject * Represents everything needed to save and restore a wallet. * * @param network the network in which the wallet operates - * @param endpoint the endpoint with witch the wallet communicates + * @param endpoint the endpoint with which the wallet communicates * @param birthday the birthday of the wallet * @param seedPhrase the seed phrase of the wallet * @param walletInitMode required parameter with one of [WalletInitMode] values. Use [WalletInitMode.NewWallet] when @@ -25,7 +25,7 @@ import org.json.JSONObject */ data class PersistableWallet( val network: ZcashNetwork, - val endpoint: LightWalletEndpoint = LightWalletEndpoint.defaultForNetwork(network), + val endpoint: LightWalletEndpoint, val birthday: BlockHeight?, val seedPhrase: SeedPhrase, val walletInitMode: WalletInitMode @@ -82,7 +82,7 @@ data class PersistableWallet( when (val version = getVersion(jsonObject)) { VERSION_1 -> { - endpoint = LightWalletEndpoint.defaultForNetwork(network) + endpoint = getLightWalletEndpointForNetwork(network) } VERSION_2 -> { endpoint = getEndpoint(jsonObject) @@ -139,7 +139,7 @@ data class PersistableWallet( * @return A new PersistableWallet with a random seed phrase. * * @param zcashNetwork the network in which the wallet operates - * @param endpoint the endpoint with witch the wallet communicates + * @param endpoint the endpoint with which the wallet communicates * @param walletInitMode required parameter with one of [WalletInitMode] values. Use [WalletInitMode.NewWallet] * when starting synchronizer for a newly created wallet. Or use [WalletInitMode.RestoreWallet] when * restoring an existing wallet that was created at some point in the past. Or use the last [WalletInitMode @@ -149,7 +149,7 @@ data class PersistableWallet( suspend fun new( application: Application, zcashNetwork: ZcashNetwork, - endpoint: LightWalletEndpoint = LightWalletEndpoint.defaultForNetwork(zcashNetwork), + endpoint: LightWalletEndpoint, walletInitMode: WalletInitMode ): PersistableWallet { val birthday = BlockHeight.ofLatestCheckpoint(application, zcashNetwork) @@ -200,3 +200,33 @@ private suspend fun newMnemonic() = } private suspend fun newSeedPhrase() = SeedPhrase(newMnemonic().map { it.concatToString() }) + +/* + * The following functions and variables are package private only and preserved to support backward compatibility for + * [PersistableWallet] and testing purposes. + */ +internal fun getLightWalletEndpointForNetwork(zcashNetwork: ZcashNetwork): LightWalletEndpoint { + return when (zcashNetwork.id) { + ZcashNetwork.Mainnet.id -> LightWalletEndpoint.Mainnet + ZcashNetwork.Testnet.id -> LightWalletEndpoint.Testnet + else -> error("Unknown network id: ${zcashNetwork.id}") + } +} + +private const val DEFAULT_PORT = 9067 + +internal val LightWalletEndpoint.Companion.Mainnet + get() = + LightWalletEndpoint( + "mainnet.lightwalletd.com", + DEFAULT_PORT, + isSecure = true + ) + +internal val LightWalletEndpoint.Companion.Testnet + get() = + LightWalletEndpoint( + "lightwalletd.testnet.electriccoin.co", + DEFAULT_PORT, + isSecure = true + ) diff --git a/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/fixture/LightWalletEndpointFixture.kt b/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/fixture/LightWalletEndpointFixture.kt new file mode 100644 index 00000000..9ef8e721 --- /dev/null +++ b/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/fixture/LightWalletEndpointFixture.kt @@ -0,0 +1,38 @@ +@file:Suppress("ktlint:standard:filename") + +package cash.z.ecc.android.sdk.fixture + +import cash.z.ecc.android.sdk.model.ZcashNetwork +import co.electriccoin.lightwallet.client.model.LightWalletEndpoint + +/* + * This is a set of extension functions for testing purposes only. + */ + +object LightWalletEndpointFixture { + private const val DEFAULT_PORT = 9067 + + val LightWalletEndpoint.Companion.Mainnet + get() = + LightWalletEndpoint( + "mainnet.lightwalletd.com", + DEFAULT_PORT, + isSecure = true + ) + + val LightWalletEndpoint.Companion.Testnet + get() = + LightWalletEndpoint( + "lightwalletd.testnet.electriccoin.co", + DEFAULT_PORT, + isSecure = true + ) + + fun newEndpointForNetwork(zcashNetwork: ZcashNetwork): LightWalletEndpoint { + return when (zcashNetwork.id) { + ZcashNetwork.Mainnet.id -> LightWalletEndpoint.Mainnet + ZcashNetwork.Testnet.id -> LightWalletEndpoint.Testnet + else -> error("Unknown network id: ${zcashNetwork.id}") + } + } +} diff --git a/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/integration/service/ChangeServiceTest.kt b/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/integration/service/ChangeServiceTest.kt index c4af8bdb..581e68c8 100644 --- a/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/integration/service/ChangeServiceTest.kt +++ b/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/integration/service/ChangeServiceTest.kt @@ -7,7 +7,6 @@ import cash.z.ecc.android.sdk.annotation.TestPurpose import cash.z.ecc.android.sdk.internal.Twig import cash.z.ecc.android.sdk.internal.block.CompactBlockDownloader import cash.z.ecc.android.sdk.internal.repository.CompactBlockRepository -import cash.z.ecc.android.sdk.model.Mainnet import cash.z.ecc.android.sdk.model.ZcashNetwork import cash.z.ecc.android.sdk.test.ScopedTest import co.electriccoin.lightwallet.client.LightWalletClient @@ -15,7 +14,6 @@ import co.electriccoin.lightwallet.client.model.BlockHeightUnsafe import co.electriccoin.lightwallet.client.model.LightWalletEndpoint import co.electriccoin.lightwallet.client.model.Response import co.electriccoin.lightwallet.client.new -import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.runTest import org.junit.After import org.junit.Assert.assertTrue @@ -31,7 +29,7 @@ import kotlin.test.Ignore @SmallTest class ChangeServiceTest : ScopedTest() { val network = ZcashNetwork.Mainnet - val lightWalletEndpoint = LightWalletEndpoint.Mainnet + val lightWalletEndpoint = LightWalletEndpoint("mainnet.lightwalletd.com", 9067, true) private val eccEndpoint = LightWalletEndpoint("lightwalletd.electriccoin.co", 9087, true) @Mock @@ -60,8 +58,7 @@ class ChangeServiceTest : ScopedTest() { } @Test - @OptIn(ExperimentalCoroutinesApi::class) - @Ignore + @Ignore("Disabled as not working currently") fun testSanityCheck() = runTest { // Test the result, only if there is no server communication problem. diff --git a/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/internal/SdkSynchronizerTest.kt b/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/internal/SdkSynchronizerTest.kt index db1e863c..fddb7338 100644 --- a/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/internal/SdkSynchronizerTest.kt +++ b/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/internal/SdkSynchronizerTest.kt @@ -5,10 +5,9 @@ import androidx.test.platform.app.InstrumentationRegistry import cash.z.ecc.android.bip39.Mnemonics import cash.z.ecc.android.sdk.Synchronizer import cash.z.ecc.android.sdk.WalletInitMode +import cash.z.ecc.android.sdk.fixture.LightWalletEndpointFixture import cash.z.ecc.android.sdk.fixture.WalletFixture import cash.z.ecc.android.sdk.model.ZcashNetwork -import cash.z.ecc.android.sdk.model.defaultForNetwork -import co.electriccoin.lightwallet.client.model.LightWalletEndpoint import kotlinx.coroutines.test.runTest import java.util.UUID import kotlin.test.Test @@ -28,7 +27,7 @@ class SdkSynchronizerTest { InstrumentationRegistry.getInstrumentation().context, ZcashNetwork.Mainnet, alias, - LightWalletEndpoint.defaultForNetwork(ZcashNetwork.Mainnet), + LightWalletEndpointFixture.newEndpointForNetwork(ZcashNetwork.Mainnet), Mnemonics.MnemonicCode(WalletFixture.SEED_PHRASE).toEntropy(), birthday = null, // Using existing wallet init mode as simplification for the test @@ -39,7 +38,7 @@ class SdkSynchronizerTest { InstrumentationRegistry.getInstrumentation().context, ZcashNetwork.Mainnet, alias, - LightWalletEndpoint.defaultForNetwork(ZcashNetwork.Mainnet), + LightWalletEndpointFixture.newEndpointForNetwork(ZcashNetwork.Mainnet), Mnemonics.MnemonicCode(WalletFixture.SEED_PHRASE).toEntropy(), birthday = null, // Using existing wallet init mode as simplification for the test @@ -64,7 +63,7 @@ class SdkSynchronizerTest { InstrumentationRegistry.getInstrumentation().context, ZcashNetwork.Mainnet, alias, - LightWalletEndpoint.defaultForNetwork(ZcashNetwork.Mainnet), + LightWalletEndpointFixture.newEndpointForNetwork(ZcashNetwork.Mainnet), Mnemonics.MnemonicCode(WalletFixture.SEED_PHRASE).toEntropy(), birthday = null, // Using existing wallet init mode as simplification for the test @@ -76,7 +75,7 @@ class SdkSynchronizerTest { InstrumentationRegistry.getInstrumentation().context, ZcashNetwork.Mainnet, alias, - LightWalletEndpoint.defaultForNetwork(ZcashNetwork.Mainnet), + LightWalletEndpointFixture.newEndpointForNetwork(ZcashNetwork.Mainnet), Mnemonics.MnemonicCode(WalletFixture.SEED_PHRASE).toEntropy(), birthday = null, // Using existing wallet init mode as simplification for the test diff --git a/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/util/BalancePrinterUtil.kt b/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/util/BalancePrinterUtil.kt index 9bdc4082..ef2cfa7c 100644 --- a/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/util/BalancePrinterUtil.kt +++ b/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/util/BalancePrinterUtil.kt @@ -4,15 +4,14 @@ import androidx.test.platform.app.InstrumentationRegistry import cash.z.ecc.android.sdk.CloseableSynchronizer import cash.z.ecc.android.sdk.Synchronizer import cash.z.ecc.android.sdk.WalletInitMode +import cash.z.ecc.android.sdk.fixture.LightWalletEndpointFixture import cash.z.ecc.android.sdk.internal.Twig import cash.z.ecc.android.sdk.internal.ext.deleteSuspend import cash.z.ecc.android.sdk.internal.model.Checkpoint import cash.z.ecc.android.sdk.model.BlockHeight import cash.z.ecc.android.sdk.model.ZcashNetwork -import cash.z.ecc.android.sdk.model.defaultForNetwork import cash.z.ecc.android.sdk.test.readFileLinesInFlow import cash.z.ecc.android.sdk.tool.CheckpointTool -import co.electriccoin.lightwallet.client.model.LightWalletEndpoint import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.map import kotlinx.coroutines.runBlocking @@ -96,9 +95,7 @@ class BalancePrinterUtil { Synchronizer.new( context, network, - lightWalletEndpoint = - LightWalletEndpoint - .defaultForNetwork(network), + lightWalletEndpoint = LightWalletEndpointFixture.newEndpointForNetwork(network), seed = seed, birthday = birthdayHeight, // Using existing wallet init mode as simplification for the test diff --git a/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/util/DataDbScannerUtil.kt b/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/util/DataDbScannerUtil.kt index 171e360b..2c6599df 100644 --- a/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/util/DataDbScannerUtil.kt +++ b/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/util/DataDbScannerUtil.kt @@ -5,10 +5,9 @@ import cash.z.ecc.android.sdk.CloseableSynchronizer import cash.z.ecc.android.sdk.SdkSynchronizer import cash.z.ecc.android.sdk.Synchronizer import cash.z.ecc.android.sdk.WalletInitMode +import cash.z.ecc.android.sdk.fixture.LightWalletEndpointFixture import cash.z.ecc.android.sdk.model.BlockHeight import cash.z.ecc.android.sdk.model.ZcashNetwork -import cash.z.ecc.android.sdk.model.defaultForNetwork -import co.electriccoin.lightwallet.client.model.LightWalletEndpoint import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking @@ -69,9 +68,7 @@ class DataDbScannerUtil { Synchronizer.newBlocking( context, ZcashNetwork.Mainnet, - lightWalletEndpoint = - LightWalletEndpoint - .defaultForNetwork(ZcashNetwork.Mainnet), + lightWalletEndpoint = LightWalletEndpointFixture.newEndpointForNetwork(ZcashNetwork.Mainnet), seed = byteArrayOf(), birthday = BlockHeight.new( diff --git a/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/util/TestWallet.kt b/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/util/TestWallet.kt index bb3d8533..d4ba0e5d 100644 --- a/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/util/TestWallet.kt +++ b/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/util/TestWallet.kt @@ -6,12 +6,12 @@ import cash.z.ecc.android.bip39.toSeed import cash.z.ecc.android.sdk.SdkSynchronizer import cash.z.ecc.android.sdk.Synchronizer import cash.z.ecc.android.sdk.WalletInitMode +import cash.z.ecc.android.sdk.fixture.LightWalletEndpointFixture import cash.z.ecc.android.sdk.internal.Twig import cash.z.ecc.android.sdk.internal.deriveUnifiedSpendingKey import cash.z.ecc.android.sdk.internal.jni.RustDerivationTool import cash.z.ecc.android.sdk.model.Account import cash.z.ecc.android.sdk.model.BlockHeight -import cash.z.ecc.android.sdk.model.Testnet import cash.z.ecc.android.sdk.model.WalletBalance import cash.z.ecc.android.sdk.model.Zatoshi import cash.z.ecc.android.sdk.model.ZcashNetwork @@ -35,7 +35,7 @@ class TestWallet( val seedPhrase: String, val alias: String = "TestWallet", val network: ZcashNetwork = ZcashNetwork.Testnet, - val endpoint: LightWalletEndpoint = LightWalletEndpoint.Testnet, + val endpoint: LightWalletEndpoint = LightWalletEndpointFixture.newEndpointForNetwork(ZcashNetwork.Testnet), startHeight: BlockHeight? = null ) { constructor( diff --git a/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/util/TransactionCounterUtil.kt b/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/util/TransactionCounterUtil.kt index 055fa2a7..4b5048dd 100644 --- a/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/util/TransactionCounterUtil.kt +++ b/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/util/TransactionCounterUtil.kt @@ -1,10 +1,10 @@ package cash.z.ecc.android.sdk.util import androidx.test.platform.app.InstrumentationRegistry +import cash.z.ecc.android.sdk.fixture.LightWalletEndpointFixture import cash.z.ecc.android.sdk.internal.Twig import cash.z.ecc.android.sdk.internal.model.ext.from import cash.z.ecc.android.sdk.model.BlockHeight -import cash.z.ecc.android.sdk.model.Mainnet import cash.z.ecc.android.sdk.model.ZcashNetwork import co.electriccoin.lightwallet.client.LightWalletClient import co.electriccoin.lightwallet.client.model.BlockHeightUnsafe @@ -15,7 +15,8 @@ import org.junit.Test class TransactionCounterUtil { private val context = InstrumentationRegistry.getInstrumentation().context - private val lightWalletClient = LightWalletClient.new(context, LightWalletEndpoint.Mainnet) + private val endpoint: LightWalletEndpoint = LightWalletEndpointFixture.newEndpointForNetwork(ZcashNetwork.Mainnet) + private val lightWalletClient = LightWalletClient.new(context, endpoint) @Test @Ignore("This test is broken") diff --git a/sdk-lib/src/main/java/cash/z/ecc/android/sdk/model/LightWalletEndpointExt.kt b/sdk-lib/src/main/java/cash/z/ecc/android/sdk/model/LightWalletEndpointExt.kt deleted file mode 100644 index c2af971a..00000000 --- a/sdk-lib/src/main/java/cash/z/ecc/android/sdk/model/LightWalletEndpointExt.kt +++ /dev/null @@ -1,49 +0,0 @@ -@file:Suppress("ktlint:standard:filename") - -package cash.z.ecc.android.sdk.model - -import co.electriccoin.lightwallet.client.model.LightWalletEndpoint - -/* - * This is a set of extension functions currently, because we expect them to change in the future. - */ - -fun LightWalletEndpoint.Companion.defaultForNetwork(zcashNetwork: ZcashNetwork): LightWalletEndpoint { - return when (zcashNetwork.id) { - ZcashNetwork.Mainnet.id -> LightWalletEndpoint.Mainnet - ZcashNetwork.Testnet.id -> LightWalletEndpoint.Testnet - else -> error("Unknown network id: ${zcashNetwork.id}") - } -} - -/** - * This is a special localhost value on the Android emulator, which allows it to contact - * the localhost of the computer running the emulator. - */ -private const val COMPUTER_LOCALHOST = "10.0.2.2" - -private const val DEFAULT_PORT = 9067 - -val LightWalletEndpoint.Companion.Mainnet - get() = - LightWalletEndpoint( - "mainnet.lightwalletd.com", - DEFAULT_PORT, - isSecure = true - ) - -val LightWalletEndpoint.Companion.Testnet - get() = - LightWalletEndpoint( - "lightwalletd.testnet.electriccoin.co", - DEFAULT_PORT, - isSecure = true - ) - -val LightWalletEndpoint.Companion.Darkside - get() = - LightWalletEndpoint( - COMPUTER_LOCALHOST, - DEFAULT_PORT, - isSecure = false - ) diff --git a/sdk-lib/src/test/java/cash/z/ecc/android/sdk/model/LightWalletEndpointTest.kt b/sdk-lib/src/test/java/cash/z/ecc/android/sdk/model/LightWalletEndpointTest.kt deleted file mode 100644 index 8993271d..00000000 --- a/sdk-lib/src/test/java/cash/z/ecc/android/sdk/model/LightWalletEndpointTest.kt +++ /dev/null @@ -1,17 +0,0 @@ -package cash.z.ecc.android.sdk.model - -import co.electriccoin.lightwallet.client.model.LightWalletEndpoint -import org.junit.Test -import kotlin.test.assertTrue - -class LightWalletEndpointTest { - @Test - fun requireSecureMainnet() { - assertTrue(LightWalletEndpoint.Mainnet.isSecure) - } - - @Test - fun requireSecureTestnet() { - assertTrue(LightWalletEndpoint.Testnet.isSecure) - } -}