Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests for rust crates #26

Merged
merged 37 commits into from
Jan 17, 2025
Merged

Tests for rust crates #26

merged 37 commits into from
Jan 17, 2025

Conversation

ametel01
Copy link
Collaborator

No description provided.

ametel01 and others added 30 commits January 14, 2025 05:25
Add extensive test suite for Relayer including:
- Valid/invalid Ethereum address formats
- Environment variable handling
- Edge cases for hex values
- Private key validation
- Whitespace and empty string handling
- Unicode character handling
- Case sensitivity tests
- Maximum value tests

Tests ensure robust input validation and error handling
in the Relayer implementation."
Add comprehensive test suite for account.rs including:
- Basic account creation tests
- Edge cases for private key and address
- MMR proof verification tests
- Empty input validation tests
…netAccount

- Added basic unit tests for StarknetAccount creation and MMR proof verification
- Added mock tests for StarknetProvider's methods:
  - get_latest_mmr_block
  - get_min_mmr_block
  - get_mmr_state
  - get_latest_relayed_block
- Fixed Felt creation method (from_hex_str -> from_hex)
- Fixed closure ownership issues with move keyword
- Removed unused variables and imports
- Added test dependencies in Cargo.toml

The changes include:
- Basic tests for account creation with success and error cases
- Tests for MMR proof verification with empty proofs and hashes
- Mock setup for provider tests using mockall
- Fixed compiler warnings and errors
- Improved code organization and test structure
- Created tests/api_tests.rs with endpoint tests
- Moved API logic from main.rs to api.rs
- Created lib.rs to expose public API
- Added tests for verify-blocks endpoint, batch size, and app state
- Add test_get_env_var for environment variable retrieval
- Add test_get_var for type parsing from env vars
- Add test_felt_conversion for Felt type conversions
- Add test_get_or_create_db_path for database path handling
- Added mock traits for testing dependencies (DatabaseUtils, EnvVarReader, StarknetProviderFactory)
- Added test-only constructor new_with_deps for dependency injection
- Added basic unit tests:
  - Valid initialization
  - Zero polling interval error
  - Missing database file error
  - Invalid chain ID error
- Fixed visibility issues with test dependencies
- Removed unused imports and traits
- Add tests for AccumulatorBuilder constructor with valid/invalid inputs
- Add tests for batch processing with invalid inputs
- Add test for MMR state updates with invalid block range
- Add test for batch result handling with proof verification skipped
- Mock StarknetAccount for testing purposes
Added comprehensive unit tests for the BatchProcessor module to verify its core functionality:

- Added tests for batch range calculations and bounds checking
- Added tests for batch size validation and processor creation
- Added tests for error cases with invalid inputs
- Added mock implementations for ProofGenerator and MMRStateManager
- Fixed test assertions to match actual implementation behavior
- Added dead code annotations to suppress warnings for test-only code

The tests cover:
- calculate_batch_bounds
- calculate_batch_range
- calculate_start_block
- batch processor creation
- batch range validation
- invalid input handling
- getter methods

This improves test coverage and verifies the batch processing logic works as expected.
Added comprehensive unit tests for the MMRStateManager module:

- Added test_update_state_without_guest_output to verify MMR state updates without guest output
- Added test_update_state_with_empty_headers to verify empty headers handling
- Added test_append_headers_with_empty_hash to verify empty hash validation
- Added test_create_new_state to verify state creation
- Added setup_test helper function with proper test dependencies
- Fixed SQLite table creation for tests
- Added debug logging for better test diagnostics

The tests cover:
- MMR state updates
- Header validation
- Empty input handling
- State creation
- Database setup
- Added comprehensive tests for U256 hex validation
- Fixed error handling consistency in validate_u256_hex
- Added test cases for:
  - Valid hex strings with 0x prefix
  - Invalid hex strings without prefix
  - Empty strings
  - Strings exceeding max length
  - Non-hex characters
- Ensured consistent InvalidU256Hex error type
- Added error message validation test
- Improved code documentation

The validation now properly handles all edge cases and returns
consistent error types for better error handling downstream.
- Removed test_batch_proof test that required complex mocking of risc0_zkvm::Receipt
- This test was providing minimal value as it only tested a simple getter
- Other tests in the module provide better coverage of core functionality
- Reduces dependency coupling with risc0_zkvm internals
- Fixed test_generate_stark_proof_invalid_input and test_generate_groth16_proof_invalid_input
- Added proper type parameters and constructor arguments for ProofGenerator
- Used Vec<u8> as test input type to test empty input cases
- Removed redundant whitespace
- Tests now properly verify error handling for invalid inputs

The tests now correctly verify that the proof generator rejects empty inputs
while maintaining the original test intent.
Added tests for IPFS utilities:
- Added TestIpfsApi trait for mocking IPFS operations
- Added MockIpfsClient with in-memory storage
- Added TestIpfsManager for test isolation
- Added test_upload_and_fetch to verify file operations
- Added test_connection_check for connectivity testing
- Added proper error handling and assertions
- Improved test readability with clear setup/verify phases

The test suite provides good coverage of core IPFS operations
while avoiding issues with sealed traits and maintaining
clean test architecture.
Added error handling tests for IPFS operations:
- Added file size limit validation in TestIpfsManager
- Added IPFS hash validation in fetch_db
- Added test_file_size_limit for oversized files (2MB)
- Added test_invalid_file_path for nonexistent files
- Added test_invalid_hash for malformed IPFS hashes
- Added test_empty_file for edge case handling
- Removed unused stream import

The test suite now covers both success and error paths,
ensuring proper validation and error handling in the IPFS
operations.
- Add Dockerfile for state-proof-api service
- Update build scripts to include state-proof-api image
- Add state-proof-api service to docker-compose.services.yml
- Configure API to run on port 3000 with batch size 4
- Added new get_hourly_block_headers_in_range function to fetch one block header per hour
- Uses PostgreSQL date_trunc to group blocks by hour
- Returns first block from each hour within the specified range
- Maintains existing interface and return types for seamless integration
…ation

Added INFO level logging for block verification requests that includes:
- Starting block number
- Ending block number
- Total blocks in range
- Update Dockerfile.api with RISC Zero toolchain and dependencies
  * Add build dependencies (curl, git, build-essential)
  * Configure cargo for git CLI fetching
  * Install and configure RISC Zero toolchain
  * Add runtime SSL dependencies

- Add state-proof-api and fetch-fees-proof services
  * Configure state-proof-api with RISC Zero toolchain (port 3000)
  * Set up fetch-fees-proof with API_URL configuration
  * Include environment file handling

- Update build infrastructure
  * Add both services to build-services.sh and build-images.sh
  * Update build commands with BINARY arg
  * Configure docker-compose.services.yml with new services
  * Set up service dependencies and networking

Both services are configured for fossil-network integration with
appropriate environment and network settings. Build commands now use
consistent Dockerfile.api with BINARY arguments.

Co-authored-by: Claude <[email protected]>
- Update PyO3 version to 0.23.3 across all dependencies
- Add patch section for garaga_rs and PyO3 dependencies
- Add build.rs to properly handle Python linking on macOS arm64
- Update environment variables for Python development
- Configure publisher crate as both cdylib and rlib

Technical changes:
- Add dynamic Python version detection in build.rs
- Add proper linking flags for macOS
- Set PYO3_PYTHON environment variable
- Fix garaga_rs dependency conflicts
- Added test module for ValidatorBuilder with basic test coverage
- Added tests for validator construction, header validation, batch processing
- Added mocks for StarknetProvider and MMR state
- Added test cases for both success and error scenarios
- Added #[allow(dead_code)] attributes to test-only structs
- Add input validation for hex string length and characters in u256_from_hex
- Fix test cases to use proper 64-character hex strings
- Replace should_panic test with proper error case testing
- Add comprehensive test cases for MmrState and MmrSnapshot
- Use ByteArray::from instead of from_hex for IPFS hashes
- Move CLI argument handling and business logic from bin/build_mmr.rs to src/cli/build_mmr.rs
- Create new cli module in src/cli/mod.rs
- Simplify binary to only handle argument parsing and running the main function
- Improve separation of concerns and code organization
- Make CLI logic more testable by moving it into the library
- Add tests for CLI argument parsing and validation
- Add test for conflicting arguments handling
- Create test utilities for environment file setup
- Add tempfile dependency for test environment
- Fix test environment setup with temporary .env file
- Extract business logic from bin/update_mmr.rs to cli/update_mmr.rs
- Add batch_size as CLI argument with default value 1024
- Add comprehensive test suite for Config and Args
- Improve test reliability with proper env var handling
- Clean up imports and code formatting
- Align extract_fees arguments with operations.rs signature
- Add batch_size and skip_proof_verification parameters
- Fix environment variable handling in tests
- Use from_env() instead of from_env_test() for consistent error handling
- Fix test_config_invalid_chain_id to properly test parse errors
- Fix test_config_missing_env to test missing env vars
- Remove unnecessary error message assertions to make tests more robust
- Clean up test environment setup and teardown
- Change address validation to expect 66 characters (0x + 64 hex chars)
- Update error messages to reference Starknet address format
- Fix test_max_values to use valid Starknet address
- Update test cases to use correct address length
- Add IPFS hash retrieval and logging in update_mmr_with_new_headers
- Log IPFS hash after successful batch processing
- Ensure MMR state is properly saved during client updates
- Add debug logging for IPFS operations

This fixes an issue where client updates were not being properly saved
to IPFS, making it difficult to verify the state transitions later.
… only

- Move Python configuration into a separate function
- Add cfg attribute to only run Python setup on Apple platforms
- Keep wrapper.h invalidation check for all platforms
- Fix GitHub Actions compilation errors on Linux
…l-light-client into tests-for-rust-crates

merge remote with local
@ametel01 ametel01 merged commit 1f8d1df into main Jan 17, 2025
2 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.

1 participant