Skip to content

test(crypto): add property-based tests for crypto codecs and envelope… - #1806

Open
Anadudev wants to merge 1 commit into
Stellar-Mail:mainfrom
Anadudev:test/property-based-crypto-1723
Open

test(crypto): add property-based tests for crypto codecs and envelope…#1806
Anadudev wants to merge 1 commit into
Stellar-Mail:mainfrom
Anadudev:test/property-based-crypto-1723

Conversation

@Anadudev

Copy link
Copy Markdown

Closes #1723

Proposed Changes

Property-Based Testing Suite (tests/unit/crypto/property.test.ts)

  • Added a property-based test suite with seedable pseudo-random generators (Mulberry32 PRNG) for byte arrays, hex/base64 strings, and versioned envelopes:
    • Codec Round-Trips: Proved fromHex(toHex(bytes)) === bytes and fromBase64(toBase64(bytes)) === bytes hold for 100+ generated byte arrays of arbitrary length (0 to 512 bytes).
    • Rejection Invariants: Verified that odd-length hex, mixed-case hex, non-hex alphabets, invalid base64 characters, misplaced base64 padding, non-4 base64 lengths, and byte length mismatches strictly throw CodecError.
    • Seal-Open Invariants: Verified that 20 generated valid envelopes pass sealEnvelope -> openEnvelope with exact code point and structure recovery.
    • Tamper Fail-Closed Invariants: Verified that single-byte mutations to nonces, MACs, ciphertext, content commitments, or recipient keys strictly fail closed across generated envelopes.
    • Reproducible Seed Reporting: Ensured any assertion error reports the exact random seed (seed: ${seed}) for deterministic bug reproduction.

Verification Plan

Automated Tests

  • Executed node node_modules/vitest/vitest.mjs run tests/unit/crypto/property.test.ts: 5 property tests passed in 140ms.
  • Executed node node_modules/vitest/vitest.mjs run tests/unit/crypto: 27 test files passed, 245/245 tests passed.
  • Executed npx eslint tests/unit/crypto/property.test.ts: 0 lint errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add property-based tests for crypto codecs and envelope invariants

1 participant