CodexRestoreStateTest.kt

2.0 KB · raw

1package com.peachpasswords.ui.codex23import com.peachpasswords.codex.CodexCodec4import com.peachpasswords.codex.CodexErrorCode5import org.junit.Assert.assertEquals6import org.junit.Test7import kotlin.random.Random89class CodexRestoreStateTest {1011    @Test12    fun codexRestoreShortfall_reportsMissingCodeCounts() {13        val rng = Random(36)14        val compressed = CodexCodec.deflate(ByteArray(5000) { rng.nextInt().toByte() })15        val (envelopes, layout) = CodexCodec.encodeToEnvelopes(compressed, "PX-TEST-0001")16        val parityInFirstStripe = layout.parityChunks / layout.stripeCount17        val survivors = envelopes18            .filterNot { it.s == 0 && it.i <= parityInFirstStripe }1920        val shortfall = codexRestoreShortfall(survivors)2122        assertEquals(layout.totalChunks - parityInFirstStripe - 1, shortfall?.found)23        assertEquals(1, shortfall?.missing)24        assertEquals(0, shortfall?.ready)25        assertEquals(layout.stripeCount, shortfall?.total)26    }2728    @Test29    fun codexRestoreErrorMessage_matchesBrowserRestoreCopy() {30        assertEquals(31            "wrong master password. try again.",32            codexRestoreErrorMessage(CodexErrorCode.RESTORE_FAILED, "WRONG_PASSPHRASE"),33        )34        assertEquals(35            "the reconstructed vault is unreadable. please re-scan the Codex.",36            codexRestoreErrorMessage(CodexErrorCode.INVALID_VAULT_BLOB, null),37        )38        assertEquals(39            "vault integrity check failed. please re-scan the Codex.",40            codexRestoreErrorMessage(CodexErrorCode.RECONSTRUCTION_FINGERPRINT_MISMATCH, null),41        )42        assertEquals(43            "no Codex codes found in this PDF. make sure you're selecting a Peach Codex PDF, not a different document.",44            codexRestoreErrorMessage(CodexErrorCode.INSUFFICIENT_CHUNKS, "No Aztec codes could be read from this file"),45        )46        assertEquals(47            "restoration failed. please try again.",48            codexRestoreErrorMessage(CodexErrorCode.RESTORE_FAILED, null),49        )50    }51}