Skip to content

crypto/tmhash: add tests for ValidateSHA256#7

Open
ahwlsqja wants to merge 1 commit intoakash-network:akash/v0.38.19from
ahwlsqja:test/add-validate-sha256-tests
Open

crypto/tmhash: add tests for ValidateSHA256#7
ahwlsqja wants to merge 1 commit intoakash-network:akash/v0.38.19from
ahwlsqja:test/add-validate-sha256-tests

Conversation

@ahwlsqja
Copy link
Copy Markdown

Summary

Add comprehensive test coverage for ValidateSHA256 function which is used during node startup to validate genesis document checksums.

Test Cases

  • Valid hex strings (lowercase, uppercase, mixed case)
  • Length validation (too short, too long, empty string)
  • Invalid character detection (non-hex chars, spaces, special chars)

Why

This function is called in node/setup.go:612 to validate genesis checksums during node initialization. Test coverage ensures:

  • Security: Invalid hashes are properly rejected
  • Reliability: Valid hashes are correctly accepted

Test Results

=== RUN TestValidateSHA256
--- PASS: TestValidateSHA256 (0.00s)
--- PASS: TestValidateSHA256/valid_lowercase_hex
--- PASS: TestValidateSHA256/valid_uppercase_hex
--- PASS: TestValidateSHA256/valid_mixed_case_hex
--- PASS: TestValidateSHA256/valid_all_zeros
--- PASS: TestValidateSHA256/valid_all_f's
--- PASS: TestValidateSHA256/too_short_-63_chars
--- PASS: TestValidateSHA256/too_long-_65_chars
--- PASS: TestValidateSHA256/empty_string
--- PASS: TestValidateSHA256/invalid_char_g_in_middle
--- PASS: TestValidateSHA256/invalid_char_z_at_start
--- PASS: TestValidateSHA256/space_in_middle
--- PASS: TestValidateSHA256/special_character
--- PASS: TestValidateSHA256/newline_character
PASS

Add comprehensive test coverage for ValidateSHA256 function which is
used during node startup to validate genesis document checksums.

Test cases include:
- Valid hex strings (lowercase, uppercase, mixed case)
- Length validation (too short, too long, empty string)
- Invalid character detection (non-hex chars, spaces, special chars)

This improves test coverage for a security-critical validation function.
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