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.
60 lines
1.9 KiB
60 lines
1.9 KiB
package cash.z.ecc.android.sdk.tool
|
|
|
|
import android.content.Context
|
|
import androidx.test.core.app.ApplicationProvider
|
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
|
import androidx.test.filters.SmallTest
|
|
import cash.z.ecc.android.sdk.model.ZcashNetwork
|
|
import cash.z.ecc.android.sdk.tool.CheckpointTool.IS_FALLBACK_ON_FAILURE
|
|
import kotlinx.coroutines.runBlocking
|
|
import org.junit.Assert.assertEquals
|
|
import org.junit.Test
|
|
import org.junit.runner.RunWith
|
|
|
|
@RunWith(AndroidJUnit4::class)
|
|
class CheckpointToolTest {
|
|
@Test
|
|
@SmallTest
|
|
fun birthday_height_from_filename() {
|
|
assertEquals(123, CheckpointTool.checkpointHeightFromFilename(ZcashNetwork.Mainnet, "123.json"))
|
|
}
|
|
|
|
@Test
|
|
@SmallTest
|
|
fun load_latest_birthday() {
|
|
// Using a separate directory, so that we don't have to keep updating this test each time
|
|
// mainnet or testnet changes
|
|
val directory = "co.electriccoin.zcash/checkpoint/goodnet"
|
|
|
|
val context = ApplicationProvider.getApplicationContext<Context>()
|
|
val birthday = runBlocking {
|
|
CheckpointTool.getFirstValidWalletBirthday(
|
|
context,
|
|
ZcashNetwork.Mainnet,
|
|
directory,
|
|
listOf("1300000.json", "1290000.json")
|
|
)
|
|
}
|
|
assertEquals(1300000, birthday.height.value)
|
|
}
|
|
|
|
@Test
|
|
@SmallTest
|
|
fun load_latest_birthday_fallback_on_bad_json() {
|
|
if (!IS_FALLBACK_ON_FAILURE) {
|
|
return
|
|
}
|
|
|
|
val directory = "co.electriccoin.zcash/checkpoint/badnet"
|
|
val context = ApplicationProvider.getApplicationContext<Context>()
|
|
val birthday = runBlocking {
|
|
CheckpointTool.getFirstValidWalletBirthday(
|
|
context,
|
|
ZcashNetwork.Mainnet,
|
|
directory,
|
|
listOf("1300000.json", "1290000.json")
|
|
)
|
|
}
|
|
assertEquals(1290000, birthday.height.value)
|
|
}
|
|
}
|
|
|