2021-04-28 06:45:42 -07:00
|
|
|
package cash.z.ecc.android.sdk.jni
|
|
|
|
|
|
|
|
import cash.z.ecc.android.sdk.annotation.MaintainedTest
|
|
|
|
import cash.z.ecc.android.sdk.annotation.TestPurpose
|
2023-05-18 04:36:15 -07:00
|
|
|
import cash.z.ecc.android.sdk.internal.Backend
|
|
|
|
import cash.z.ecc.android.sdk.internal.getBranchIdForHeight
|
|
|
|
import cash.z.ecc.android.sdk.internal.jni.RustBackend
|
|
|
|
import cash.z.ecc.android.sdk.internal.network
|
2022-07-12 05:40:09 -07:00
|
|
|
import cash.z.ecc.android.sdk.model.BlockHeight
|
2022-08-02 06:29:09 -07:00
|
|
|
import cash.z.ecc.android.sdk.model.ZcashNetwork
|
2021-10-21 13:05:02 -07:00
|
|
|
import kotlinx.coroutines.runBlocking
|
2021-04-28 06:45:42 -07:00
|
|
|
import org.junit.Assert.assertEquals
|
|
|
|
import org.junit.Test
|
|
|
|
import org.junit.runner.RunWith
|
|
|
|
import org.junit.runners.Parameterized
|
2022-09-06 03:44:33 -07:00
|
|
|
import java.io.File
|
2021-04-28 06:45:42 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This test is intended to run to make sure that branch ID logic works across all target devices.
|
|
|
|
*/
|
|
|
|
@MaintainedTest(TestPurpose.REGRESSION)
|
|
|
|
@RunWith(Parameterized::class)
|
2022-07-12 05:40:09 -07:00
|
|
|
class BranchIdTest internal constructor(
|
2021-04-28 06:45:42 -07:00
|
|
|
private val networkName: String,
|
2022-07-12 05:40:09 -07:00
|
|
|
private val height: BlockHeight,
|
2021-04-28 07:12:41 -07:00
|
|
|
private val branchId: Long,
|
2021-04-28 06:45:42 -07:00
|
|
|
private val branchHex: String,
|
2023-04-10 07:35:40 -07:00
|
|
|
private val rustBackend: Backend
|
2021-04-28 06:45:42 -07:00
|
|
|
) {
|
|
|
|
|
|
|
|
@Test
|
2021-04-28 07:12:41 -07:00
|
|
|
fun testBranchId_Hex() {
|
2021-04-28 06:45:42 -07:00
|
|
|
val branchId = rustBackend.getBranchIdForHeight(height)
|
|
|
|
val clientBranch = "%x".format(branchId)
|
2021-04-28 07:12:41 -07:00
|
|
|
assertEquals("Invalid branch Id Hex value for $networkName at height $height on ${rustBackend.network.networkName}", branchHex, clientBranch)
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun testBranchId_Numeric() {
|
|
|
|
val actual = rustBackend.getBranchIdForHeight(height)
|
|
|
|
assertEquals("Invalid branch ID for $networkName at height $height on ${rustBackend.network.networkName}", branchId, actual)
|
2021-04-28 06:45:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
|
|
|
|
@JvmStatic
|
|
|
|
@Parameterized.Parameters
|
|
|
|
fun wallets(): List<Array<Any>> {
|
|
|
|
// init values don't matter for this test because we're just checking branchIds, which
|
|
|
|
// is an abnormal use of the SDK because this really should run at the rust level
|
|
|
|
// However, due to quirks on certain devices, we created this test at the Android level,
|
|
|
|
// as a sanity check
|
2022-09-06 03:44:33 -07:00
|
|
|
val testnetBackend = runBlocking {
|
2023-05-18 04:36:15 -07:00
|
|
|
RustBackend.new(
|
2022-09-06 03:44:33 -07:00
|
|
|
File(""),
|
|
|
|
File(""),
|
|
|
|
File(""),
|
2023-05-18 04:36:15 -07:00
|
|
|
File(""),
|
|
|
|
ZcashNetwork.Testnet.id,
|
2022-09-06 03:44:33 -07:00
|
|
|
)
|
|
|
|
}
|
|
|
|
val mainnetBackend = runBlocking {
|
2023-05-18 04:36:15 -07:00
|
|
|
RustBackend.new(
|
|
|
|
File(""),
|
2022-09-06 03:44:33 -07:00
|
|
|
File(""),
|
|
|
|
File(""),
|
|
|
|
File(""),
|
2023-05-18 04:36:15 -07:00
|
|
|
ZcashNetwork.Mainnet.id,
|
2022-09-06 03:44:33 -07:00
|
|
|
)
|
|
|
|
}
|
2021-04-28 06:45:42 -07:00
|
|
|
return listOf(
|
|
|
|
// Mainnet Cases
|
2022-08-12 08:05:00 -07:00
|
|
|
arrayOf("Sapling", BlockHeight.new(ZcashNetwork.Mainnet, 419_200), 1991772603L, "76b809bb", mainnetBackend),
|
|
|
|
arrayOf("Blossom", BlockHeight.new(ZcashNetwork.Mainnet, 653_600), 733220448L, "2bb40e60", mainnetBackend),
|
|
|
|
arrayOf("Heartwood", BlockHeight.new(ZcashNetwork.Mainnet, 903_000), 4122551051L, "f5b9230b", mainnetBackend),
|
|
|
|
arrayOf("Canopy", BlockHeight.new(ZcashNetwork.Mainnet, 1_046_400), 3925833126L, "e9ff75a6", mainnetBackend),
|
2021-04-28 06:45:42 -07:00
|
|
|
|
|
|
|
// Testnet Cases
|
2022-08-12 08:05:00 -07:00
|
|
|
arrayOf("Sapling", BlockHeight.new(ZcashNetwork.Testnet, 280_000), 1991772603L, "76b809bb", testnetBackend),
|
|
|
|
arrayOf("Blossom", BlockHeight.new(ZcashNetwork.Testnet, 584_000), 733220448L, "2bb40e60", testnetBackend),
|
|
|
|
arrayOf("Heartwood", BlockHeight.new(ZcashNetwork.Testnet, 903_800), 4122551051L, "f5b9230b", testnetBackend),
|
|
|
|
arrayOf("Canopy", BlockHeight.new(ZcashNetwork.Testnet, 1_028_500), 3925833126L, "e9ff75a6", testnetBackend)
|
2021-04-28 06:45:42 -07:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|