Skip to content

Commit

Permalink
[#1595] Remove BlockHeight check
Browse files Browse the repository at this point in the history
- The check for sapling activation height inside the BlockHeight component is no longer correct
  • Loading branch information
HonzaR committed Sep 26, 2024
1 parent 2ae711e commit e9158a5
Show file tree
Hide file tree
Showing 42 changed files with 146 additions and 336 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import cash.z.ecc.android.sdk.darkside.test.DarksideTestCoordinator
import cash.z.ecc.android.sdk.darkside.test.ScopedTest
import cash.z.ecc.android.sdk.model.BlockHeight
import cash.z.ecc.android.sdk.model.ZcashNetwork
import org.junit.BeforeClass
import org.junit.Ignore
import org.junit.Test
Expand All @@ -22,7 +21,7 @@ class InboundTxTests : ScopedTest() {

@Test
fun testLatestHeight() {
validator.validateLatestHeight(BlockHeight.new(ZcashNetwork.Mainnet, targetTxBlock.value - 1))
validator.validateLatestHeight(BlockHeight.new(targetTxBlock.value - 1))
}

@Test
Expand Down Expand Up @@ -83,8 +82,8 @@ class InboundTxTests : ScopedTest() {
"https://raw.githubusercontent.com/zcash-hackworks/darksidewalletd-test-data/master/transactions/recv/71935e29127a7de0b96081f4c8a42a9c11584d83adedfaab414362a6f3d965cf.txt"
)

private val firstBlock = BlockHeight.new(ZcashNetwork.Mainnet, 663150L)
private val targetTxBlock = BlockHeight.new(ZcashNetwork.Mainnet, 663188L)
private val firstBlock = BlockHeight.new(663150L)
private val targetTxBlock = BlockHeight.new(663188L)
private const val LAST_BLOCK_HASH = "2fc7b4682f5ba6ba6f86e170b40f0aa9302e1d3becb2a6ee0db611ff87835e4a"
private val sithLord = DarksideTestCoordinator()
private val validator = sithLord.validator
Expand All @@ -98,7 +97,7 @@ class InboundTxTests : ScopedTest() {
chainMaker
.resetBlocks(BLOCKS_URL, startHeight = firstBlock, tipHeight = targetTxBlock)
.stageEmptyBlocks(firstBlock + 1, 100)
.applyTipHeight(BlockHeight.new(ZcashNetwork.Mainnet, targetTxBlock.value - 1))
.applyTipHeight(BlockHeight.new(targetTxBlock.value - 1))

// sithLord.await()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class DarksideTestCoordinator(val wallet: TestWallet) {
endpoint: LightWalletEndpoint = LightWalletEndpoint.Darkside
) : this(TestWallet(seedPhrase, alias, network, endpoint, startHeight = startHeight))

private val targetHeight = BlockHeight.new(wallet.network, 663250)
private val targetHeight = BlockHeight.new(663250L)
private val context = InstrumentationRegistry.getInstrumentation().context

// dependencies: private
Expand Down Expand Up @@ -306,7 +306,7 @@ class DarksideTestCoordinator(val wallet: TestWallet) {
"https://raw.githubusercontent.com/zcash-hackworks/darksidewalletd-test-data/master/basic-reorg/after-small-reorg.txt"
private const val LARGE_REORG =
"https://raw.githubusercontent.com/zcash-hackworks/darksidewalletd-test-data/master/basic-reorg/after-large-reorg.txt"
private val DEFAULT_START_HEIGHT = BlockHeight.new(ZcashNetwork.Mainnet, 663150)
private val DEFAULT_START_HEIGHT = BlockHeight.new(663150L)
private const val DEFAULT_SEED_PHRASE =
"still champion voice habit trend flight survey between bitter process artefact blind carbon truly" +
" provide dizzy crush flush breeze blouse charge solid fish spread"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class TestWallet(
}

suspend fun shieldFunds(): TestWallet {
synchronizer.refreshUtxos(Account.DEFAULT, BlockHeight.new(ZcashNetwork.Mainnet, 935000)).let { count ->
synchronizer.refreshUtxos(Account.DEFAULT, BlockHeight.new(935000L)).let { count ->
Twig.debug { "FOUND $count new UTXOs" }
}

Expand Down Expand Up @@ -163,46 +163,33 @@ class TestWallet(
"column rhythm acoustic gym cost fit keen maze fence seed mail medal shrimp tell relief clip" +
" cannon foster soldier shallow refuse lunar parrot banana",
BlockHeight.new(
ZcashNetwork.Testnet,
1_355_928
1_355_928L
),
BlockHeight.new(ZcashNetwork.Mainnet, 1_000_000)
BlockHeight.new(1_000_000L)
),
SAMPLE_WALLET(
"input frown warm senior anxiety abuse yard prefer churn reject people glimpse govern glory" +
" crumble swallow verb laptop switch trophy inform friend permit purpose",
BlockHeight.new(
ZcashNetwork.Testnet,
1_330_190
),
BlockHeight.new(ZcashNetwork.Mainnet, 1_000_000)
BlockHeight.new(1_330_190L),
BlockHeight.new(1_000_000L)
),
DEV_WALLET(
"still champion voice habit trend flight survey between bitter process artefact blind carbon" +
" truly provide dizzy crush flush breeze blouse charge solid fish spread",
BlockHeight.new(
ZcashNetwork.Testnet,
1_000_000
),
BlockHeight.new(ZcashNetwork.Mainnet, 991645)
BlockHeight.new(1_000_000L),
BlockHeight.new(991645L)
),
ALICE(
"quantum whisper lion route fury lunar pelican image job client hundred sauce chimney barely" +
" life cliff spirit admit weekend message recipe trumpet impact kitten",
BlockHeight.new(
ZcashNetwork.Testnet,
1_330_190
),
BlockHeight.new(ZcashNetwork.Mainnet, 1_000_000)
BlockHeight.new(1_330_190L),
BlockHeight.new(1_000_000L)
),
BOB(
"canvas wine sugar acquire garment spy tongue odor hole cage year habit bullet make label" +
" human unit option top calm neutral try vocal arena",
BlockHeight.new(
ZcashNetwork.Testnet,
1_330_190
),
BlockHeight.new(ZcashNetwork.Mainnet, 1_000_000)
BlockHeight.new(1_330_190L),
BlockHeight.new(1_000_000L)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,9 @@ class SampleCodeTest {
@Suppress("ktlint:standard:multiline-expression-wrapping")
val blockRange =
BlockHeightUnsafe(
BlockHeight.new(
ZcashNetwork.Mainnet,
500_000
).value
BlockHeight.new(500_000L).value
)..BlockHeightUnsafe(
(
BlockHeight.new(
ZcashNetwork.Mainnet,
500_009
).value
)
(BlockHeight.new(500_009L).value)
)

val lightWalletClient = LightWalletClient.new(context, lightwalletdHost)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class SharedViewModel(application: Application) : AndroidViewModel(application)
seed = seedBytes,
birthday =
if (BenchmarkingExt.isBenchmarking()) {
BlockHeight.new(ZcashNetwork.Mainnet, BenchmarkingBlockRangeFixture.new().start)
BlockHeight.new(BenchmarkingBlockRangeFixture.new().start)
} else {
birthdayHeight.value
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package cash.z.ecc.android.sdk.demoapp.demos.listutxos

import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
Expand Down Expand Up @@ -57,7 +56,7 @@ class ListUtxosFragment : BaseDemoFragment<FragmentListUtxosBinding>() {
binding.inputRangeStart.setText(
ZcashNetwork.fromResources(requireApplicationContext()).saplingActivationHeight.toString()
)
binding.inputRangeEnd.setText(getUxtoEndHeight(requireApplicationContext()).value.toString())
binding.inputRangeEnd.setText(getUxtoEndHeight().value.toString())

binding.buttonLoad.setOnClickListener {
mainActivity()?.hideKeyboard()
Expand Down Expand Up @@ -237,7 +236,7 @@ class ListUtxosFragment : BaseDemoFragment<FragmentListUtxosBinding>() {
}

@Suppress("MagicNumber")
private fun getUxtoEndHeight(context: Context): BlockHeight {
return BlockHeight.new(ZcashNetwork.fromResources(context), 968085L)
private fun getUxtoEndHeight(): BlockHeight {
return BlockHeight.new(968085L)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ private fun RestoreWalletSection(

val blockHeight =
walletBirthdayString.toLongOrNull()?.let { blockHeight ->
BlockHeight.new(zcashNetwork, blockHeight)
BlockHeight.new(blockHeight)
} ?: zcashNetwork.saplingActivationHeight // fallback to last known valid value

val wallet =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ object PersistableWalletFixture {

// These came from the mainnet 1500000.json file
@Suppress("MagicNumber")
val BIRTHDAY = BlockHeight.new(ZcashNetwork.Mainnet, 1500000L)
val BIRTHDAY = BlockHeight.new(1500000L)

val SEED_PHRASE = SeedPhraseFixture.new()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class PersistableWalletTest {
val json = PersistableWalletFixture.new().toJson()
assertEquals(
PersistableWalletFixture.BIRTHDAY.value,
PersistableWallet.getBirthday(json, PersistableWalletFixture.NETWORK)!!.value
PersistableWallet.getBirthday(json)!!.value
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ sealed class WalletFixture {
fun lastKnownBirthday(zcashNetwork: ZcashNetwork) =
when (zcashNetwork.id) {
ZcashNetwork.ID_TESTNET -> {
BlockHeight.new(zcashNetwork, 2170000L)
BlockHeight.new(2170000L)
}
ZcashNetwork.ID_MAINNET -> {
BlockHeight.new(zcashNetwork, 1935000L)
BlockHeight.new(1935000L)
}
else -> error("Unknown network $zcashNetwork")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ data class PersistableWallet(
fun from(jsonObject: JSONObject): PersistableWallet {
// Common parameters
val network = getNetwork(jsonObject)
val birthday = getBirthday(jsonObject, network)
val birthday = getBirthday(jsonObject)
val seedPhrase = getSeedPhrase(jsonObject)
// From version 2
val endpoint: LightWalletEndpoint
Expand Down Expand Up @@ -124,13 +124,10 @@ data class PersistableWallet(
return ZcashNetwork.from(networkId)
}

internal fun getBirthday(
jsonObject: JSONObject,
network: ZcashNetwork
): BlockHeight? {
internal fun getBirthday(jsonObject: JSONObject): BlockHeight? {
return if (jsonObject.has(KEY_BIRTHDAY)) {
val birthdayBlockHeightLong = jsonObject.getLong(KEY_BIRTHDAY)
BlockHeight.new(network, birthdayBlockHeightLong)
BlockHeight.new(birthdayBlockHeightLong)
} else {
null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class AssetTest {

assertEquals(
"File: ${it.filename}",
CheckpointTool.checkpointHeightFromFilename(network, it.filename).value,
CheckpointTool.checkpointHeightFromFilename(it.filename).value,
jsonObject.getLong("height")
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class TestnetIntegrationTest : ScopedTest() {
lightWalletEndpoint =
lightWalletEndpoint,
seed = seed,
birthday = BlockHeight.new(ZcashNetwork.Testnet, BIRTHDAY_HEIGHT),
birthday = BlockHeight.new(BIRTHDAY_HEIGHT),
// Using existing wallet init mode as simplification for the test
walletInitMode = WalletInitMode.ExistingWallet
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import cash.z.ecc.android.sdk.internal.ext.existsSuspend
import cash.z.ecc.android.sdk.internal.ext.listSuspend
import cash.z.ecc.android.sdk.internal.ext.mkdirsSuspend
import cash.z.ecc.android.sdk.model.BlockHeight
import cash.z.ecc.android.sdk.model.ZcashNetwork
import cash.z.ecc.fixture.FakeRustBackendFixture
import cash.z.ecc.fixture.FilePathFixture
import co.electriccoin.lightwallet.client.fixture.ListOfCompactBlocksFixture
Expand Down Expand Up @@ -76,7 +75,6 @@ class FileCompactBlockRepositoryTest {
@Test
fun findCompactBlockTest() =
runTest {
val network = ZcashNetwork.Testnet
val rustBackend = FakeRustBackendFixture().new()
val blockRepository =
getMockedFileCompactBlockRepository(
Expand All @@ -90,17 +88,14 @@ class FileCompactBlockRepositoryTest {

val firstPersistedBlock =
blockRepository.findCompactBlock(
BlockHeight.new(network, blocks.first().height)
BlockHeight.new(blockHeight = blocks.first().height)
)
val lastPersistedBlock =
blockRepository.findCompactBlock(
BlockHeight.new(network, blocks.last().height)
BlockHeight.new(blockHeight = blocks.last().height)
)
val notPersistedBlockHeight =
BlockHeight.new(
network,
blockHeight = blocks.last().height + 1
)
BlockHeight.new(blockHeight = blocks.last().height + 1)

assertNotNull(firstPersistedBlock)
assertNotNull(lastPersistedBlock)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,57 +84,57 @@ class BranchIdTest internal constructor(
// Mainnet Cases
arrayOf(
"Sapling",
BlockHeight.new(ZcashNetwork.Mainnet, 419_200),
BlockHeight.new(419_200L),
1991772603L,
"76b809bb",
mainnetBackend
),
arrayOf(
"Blossom",
BlockHeight.new(ZcashNetwork.Mainnet, 653_600),
BlockHeight.new(653_600L),
733220448L,
"2bb40e60",
mainnetBackend
),
arrayOf(
"Heartwood",
BlockHeight.new(ZcashNetwork.Mainnet, 903_000),
BlockHeight.new(903_000L),
4122551051L,
"f5b9230b",
mainnetBackend
),
arrayOf(
"Canopy",
BlockHeight.new(ZcashNetwork.Mainnet, 1_046_400),
BlockHeight.new(1_046_400L),
3925833126L,
"e9ff75a6",
mainnetBackend
),
// Testnet Cases
arrayOf(
"Sapling",
BlockHeight.new(ZcashNetwork.Testnet, 280_000),
BlockHeight.new(280_000L),
1991772603L,
"76b809bb",
testnetBackend
),
arrayOf(
"Blossom",
BlockHeight.new(ZcashNetwork.Testnet, 584_000),
BlockHeight.new(584_000L),
733220448L,
"2bb40e60",
testnetBackend
),
arrayOf(
"Heartwood",
BlockHeight.new(ZcashNetwork.Testnet, 903_800),
BlockHeight.new(903_800L),
4122551051L,
"f5b9230b",
testnetBackend
),
arrayOf(
"Canopy",
BlockHeight.new(ZcashNetwork.Testnet, 1_028_500),
BlockHeight.new(1_028_500L),
3925833126L,
"e9ff75a6",
testnetBackend
Expand Down
Loading

0 comments on commit e9158a5

Please sign in to comment.