Skip to content

test(types): add unit tests for type parsing and formatting utilities#22

Open
jodator-ai wants to merge 1 commit intomm-zk-codex:mainfrom
jodator-ai:test/types-unit-tests
Open

test(types): add unit tests for type parsing and formatting utilities#22
jodator-ai wants to merge 1 commit intomm-zk-codex:mainfrom
jodator-ai:test/types-unit-tests

Conversation

@jodator-ai
Copy link
Copy Markdown

Summary

This PR adds a comprehensive #[cfg(test)] module to src/types.rs covering every pure utility function in that file. No other files are touched. All 47 new tests pass alongside the existing 122 tests (169 total).

What each test group validates

parse_address (8 tests)

Validates that EIP-55 checksummed addresses, lowercase hex addresses, and the zero address all parse correctly. Also checks the module's own DEFAULT_INTEROP_CENTER constant. Error path coverage: too-short strings, too-long strings, non-hex characters, and the behaviour when the 0x prefix is omitted (documents that alloy accepts bare hex and produces the same result as the prefixed form).

bytes_from_hex (7 tests)

Confirms correct decoding with and without the 0x prefix, empty string and "0x" both yield empty Bytes, leading/trailing whitespace is stripped, odd-length input returns a descriptive error containing "invalid hex", and non-hex characters are rejected.

parse_u256 (7 tests)

Covers decimal zero, a known 1e18 value, U256::MAX as a decimal string, overflow beyond U256::MAX, garbage input (checks error message contains "invalid uint256"), 0x-prefixed hex input, and documents the empty-string behaviour (alloy returns U256::ZERO).

format_hex (6 tests)

Verifies empty input produces "0x", output always starts with "0x", known byte patterns produce the expected lowercase hex string, and a round-trip with bytes_from_hex recovers the original bytes exactly.

require_signer_or_dry_run (5 tests)

Exhausts all four boolean combinations: signer-only succeeds, dry-run-only succeeds, both-true succeeds, neither-true returns an error. Two additional tests verify the error message embeds the command name that was passed in.

u256_to_string / b256_to_hex / address_to_hex (6 tests)

Checks zero and known decimal conversions for u256_to_string; checks b256_to_hex produces a "0x"-prefixed 66-character lowercase string; checks address_to_hex produces a "0x"-prefixed 42-character lowercase string.

parse_b256 (3 tests)

Valid 32-byte hex round-trip, all-zeros value, and too-short input returning an error mentioning "invalid bytes32".

Serde round-trips (4 tests)

ProofMessage serialises and deserialises without loss; verifies camelCase key renaming (txNumberInBatch not tx_number_in_batch). MessageInclusionProof full round-trip including nested struct and proof array. InteropCallView checks shadowAccount camelCase. StatusOutput checks bundleHash, bundleStatus camelCase keys and embedded values.

Test plan

  • cargo test passes with 169/169 tests (47 new, 122 pre-existing)
  • Only src/types.rs modified
  • No network, no RPC, no async runtime used in any test

🤖 Generated with Claude Code

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

1 participant