test(types): add unit tests for type parsing and formatting utilities#22
Open
jodator-ai wants to merge 1 commit intomm-zk-codex:mainfrom
Open
test(types): add unit tests for type parsing and formatting utilities#22jodator-ai wants to merge 1 commit intomm-zk-codex:mainfrom
jodator-ai wants to merge 1 commit intomm-zk-codex:mainfrom
Conversation
Co-Authored-By: Claude Sonnet 4.6 <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
This PR adds a comprehensive
#[cfg(test)]module tosrc/types.rscovering 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_CENTERconstant. Error path coverage: too-short strings, too-long strings, non-hex characters, and the behaviour when the0xprefix 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
0xprefix, empty string and"0x"both yield emptyBytes, 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::MAXas a decimal string, overflow beyondU256::MAX, garbage input (checks error message contains"invalid uint256"),0x-prefixed hex input, and documents the empty-string behaviour (alloy returnsU256::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 withbytes_from_hexrecovers 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; checksb256_to_hexproduces a"0x"-prefixed 66-character lowercase string; checksaddress_to_hexproduces 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)
ProofMessageserialises and deserialises without loss; verifiescamelCasekey renaming (txNumberInBatchnottx_number_in_batch).MessageInclusionProoffull round-trip including nested struct and proof array.InteropCallViewchecksshadowAccountcamelCase.StatusOutputchecksbundleHash,bundleStatuscamelCase keys and embedded values.Test plan
cargo testpasses with 169/169 tests (47 new, 122 pre-existing)src/types.rsmodified🤖 Generated with Claude Code