test: add unit tests across lit-api-server modules (CPL-216)#277
Merged
test: add unit tests across lit-api-server modules (CPL-216)#277
Conversation
Add 100 unit tests covering parsing utilities, cryptographic models, AES encryption, API status helpers, chain info lookups, billing helpers, and derivation path generation. Tests exercise round-trip conversions, edge cases, error paths, and enum exhaustiveness. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds extensive unit test coverage across lit-api-server modules to support CPL-216’s coverage goals.
Changes:
- Added unit tests for parsing/hashing utilities and derivation/address helpers.
- Added unit tests for cryptographic enums/models (
CurveType,SigningScheme) including serialization and conversion behavior. - Added unit tests for AES-GCM encryption/decryption, API status helpers, chain info helpers, and Stripe formatting/cache-key behavior.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| lit-api-server/src/utils/parse_with_hash.rs | Adds tests for hashing, U256 parsing, H160 parsing, and array parsing helpers. |
| lit-api-server/src/utils/mod.rs | Adds tests for derivation path helpers, EVM address derivation, and random secret generation. |
| lit-api-server/src/utils/chain_info.rs | Adds tests for Chain parsing, info correctness, filters, and chain-id uniqueness. |
| lit-api-server/src/stripe.rs | Adds tests for cents_to_display formatting (incl. documented known bug) and cache key determinism. |
| lit-api-server/src/core/v1/models/signing_scheme.rs | Adds tests for conversions, serde behavior, support predicates, and exhaustiveness checks. |
| lit-api-server/src/core/v1/models/curve_type.rs | Adds tests for parsing, conversions, iterator completeness, and basic invariants. |
| lit-api-server/src/core/v1/helpers/api_status.rs | Adds tests for constructors, conversions, Display, and serde round-trip. |
| lit-api-server/src/actions/aes.rs | Adds async tests for AES encrypt/decrypt behavior, error paths, and tamper handling. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
1 task
The empty line between the doc comment and `rewrite_imports` function triggered `clippy::empty_line_after_doc_comments`, failing CI. Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds 100 unit tests across 8 modules in
lit-api-serverto increase test coverage per CPL-216.Parsing & Hashing (
parse_with_hash.rs): 22 tests coveringapi_key_hash,usage_api_key_to_hash,parse_u256,wallet_string_to_h160,ipfs_cid_to_u256,hex_array_to_u256_array,hex_array_to_h160_array,string_group_id_to_u256Cryptographic Models (
curve_type.rs): 14 tests coveringFromStr,TryFrom<u8>,TryFrom<U256>,Into<U256>, Display, scalar_len, compressed_point_len, vrf_ctx, backup_prefix, into_iter, DefaultSigning Schemes (
signing_scheme.rs): 18 tests coveringFromStr, u8 round-trip, serde JSON/bare,supports_algorithm,supports_curve,preferred_format,ecdsa_message_len,hash_prior_to_sending,id_sign_ctx, exhaustiveness assertionAES Encryption (
aes.rs): 11 tests covering encrypt/decrypt round-trip, nondeterministic nonces, wrong-key rejection, short/invalid/tampered ciphertext, empty string behavior, unicode, invalid key lengthAPI Status (
api_status.rs): 14 tests covering all status constructors (400-500),add_message, Display, From trait impls, serde round-tripChain Info (
chain_info.rs): 15 tests coveringtry_from_str, chain_key, info() correctness, EVM/non-EVM/testnet filters, chain ID uniqueness, derivation path presenceUtilities (
utils/mod.rs): 11 tests covering derivation paths,evm_address_from_public_key,get_random_secretBilling (
stripe.rs): 5 tests coveringcents_to_display(with known sign-loss bug documented),cache_keydeterminismPre-Landing Review
Pre-Landing Review: 6 issues found, all auto-fixed:
aes.rs: empty-string encrypt test now asserts decrypt failure (documents behavior gap)stripe.rs:cents_to_display(-1)test now documents known sign-loss bug via commentssigning_scheme.rs: added exhaustiveness assertion forALL_SCHEMESarrayaes.rs: deduplicated test_key helper usageutils/mod.rs:evm_address_from_public_keytest now verifies actual address valueaes.rs: added tampered-ciphertext GCM auth tag testPR Quality Score: 9.5/10
Test plan
cargo test --lib— 146 passed, 0 failed (9 filtered: platform-specific dstack/cpu_overload tests)cargo fmt --all -- --check— clean🤖 Generated with Claude Code