You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 

59 lines
2.3 KiB

package cash.z.ecc.android.sdk.jni
import cash.z.ecc.android.sdk.annotation.MaintainedTest
import cash.z.ecc.android.sdk.annotation.TestPurpose
import cash.z.ecc.android.sdk.model.BlockHeight
import cash.z.ecc.android.sdk.model.ZcashNetwork
import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
/**
* This test is intended to run to make sure that branch ID logic works across all target devices.
*/
@MaintainedTest(TestPurpose.REGRESSION)
@RunWith(Parameterized::class)
class BranchIdTest internal constructor(
private val networkName: String,
private val height: BlockHeight,
private val branchId: Long,
private val branchHex: String,
private val rustBackend: RustBackendWelding
) {
@Test
fun testBranchId_Hex() {
val branchId = rustBackend.getBranchIdForHeight(height)
val clientBranch = "%x".format(branchId)
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)
}
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
val testnetBackend = runBlocking { RustBackend.init("", "", "", ZcashNetwork.Testnet, ZcashNetwork.Testnet.saplingActivationHeight) }
val mainnetBackend = runBlocking { RustBackend.init("", "", "", ZcashNetwork.Mainnet, ZcashNetwork.Mainnet.saplingActivationHeight) }
return listOf(
// Mainnet Cases
arrayOf("Sapling", 1, 1991772603L, "76b809bb", mainnetBackend),
// Testnet Cases
arrayOf("Sapling", 1, 1991772603L, "76b809bb", testnetBackend),
)
}
}
}