Skip to content

test: add unit tests across lit-api-server modules (CPL-216)#277

Merged
GTC6244 merged 4 commits intonextfrom
feature/cpl-216-unit-tests-in-lit-api-server
Apr 14, 2026
Merged

test: add unit tests across lit-api-server modules (CPL-216)#277
GTC6244 merged 4 commits intonextfrom
feature/cpl-216-unit-tests-in-lit-api-server

Conversation

@GTC6244
Copy link
Copy Markdown
Contributor

@GTC6244 GTC6244 commented Apr 6, 2026

Summary

Adds 100 unit tests across 8 modules in lit-api-server to increase test coverage per CPL-216.

Parsing & Hashing (parse_with_hash.rs): 22 tests covering api_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_u256

Cryptographic Models (curve_type.rs): 14 tests covering FromStr, TryFrom<u8>, TryFrom<U256>, Into<U256>, Display, scalar_len, compressed_point_len, vrf_ctx, backup_prefix, into_iter, Default

Signing Schemes (signing_scheme.rs): 18 tests covering FromStr, u8 round-trip, serde JSON/bare, supports_algorithm, supports_curve, preferred_format, ecdsa_message_len, hash_prior_to_sending, id_sign_ctx, exhaustiveness assertion

AES 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 length

API Status (api_status.rs): 14 tests covering all status constructors (400-500), add_message, Display, From trait impls, serde round-trip

Chain Info (chain_info.rs): 15 tests covering try_from_str, chain_key, info() correctness, EVM/non-EVM/testnet filters, chain ID uniqueness, derivation path presence

Utilities (utils/mod.rs): 11 tests covering derivation paths, evm_address_from_public_key, get_random_secret

Billing (stripe.rs): 5 tests covering cents_to_display (with known sign-loss bug documented), cache_key determinism

Pre-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 comments
  • signing_scheme.rs: added exhaustiveness assertion for ALL_SCHEMES array
  • aes.rs: deduplicated test_key helper usage
  • utils/mod.rs: evm_address_from_public_key test now verifies actual address value
  • aes.rs: added tampered-ciphertext GCM auth tag test

PR 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

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>
@GTC6244 GTC6244 requested review from a team and Copilot April 6, 2026 14:10
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread lit-api-server/src/actions/aes.rs
Comment thread lit-api-server/src/utils/mod.rs
Comment thread lit-api-server/src/utils/mod.rs
Comment thread lit-api-server/src/actions/aes.rs
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>
@GTC6244 GTC6244 merged commit 05060b2 into next Apr 14, 2026
10 checks passed
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.

2 participants