Skip to content

Conversation

@roman98Z
Copy link

Add Comprehensive E2E Tests for Unshielded Balances and DUST/cNIGHT Features

Overview

This Pull Request implements comprehensive end-to-end tests for two critical features in the Midnight Indexer ecosystem, addressing the following GitHub issues:

  • Add e2e tests for contract unshielded balances (High Priority)
  • Plan and implement tests for DUST/cNIGHT features once integration is available (High Priority)

Changes Summary

1. Unshielded Balances E2E Testing

Added a new test function test_unshielded_balances_e2e() that validates the complete lifecycle of unshielded balance management for contract actions. This test ensures data consistency and correctness across the entire indexer stack.

Key validations:

  • Contract actions have unshielded balances correctly populated from blockchain data
  • Balance data consistency between GraphQL queries and WebSocket subscriptions
  • Token types and amounts are valid and properly formatted
  • ContractDeploy actions have empty balances as per specification
  • Proper handling of contracts with zero balances

Test coverage:

  • Query-subscription consistency checks
  • Token type validation (hex-encoded format)
  • Amount parsing and validation (u128 format)
  • Edge case handling (empty balances, deploy vs call actions)

2. Enhanced DUST Generation Status Testing

Extended the existing test_dust_generation_status_query() function with comprehensive validation scenarios for DUST/cNIGHT functionality.

New test scenarios:

  • Empty reward address list handling
  • Unregistered Cardano stake addresses validation
  • Duplicate address handling
  • Single address queries
  • Numeric field validation (generation_rate, current_capacity, night_balance)

Improvements:

  • Better logging and test output for debugging
  • Validation of all numeric fields as proper u128 values
  • Descriptive assertion messages for easier troubleshooting

3. Improved DUST Ledger Events Subscription

Enhanced test_dust_ledger_events_subscription() with additional validation and better error handling.

Enhancements:

  • Logging for test visibility and debugging
  • Graceful handling when no DUST events are present
  • Structural validation of event data
  • Count verification for expected events

Technical Details

Code Quality:

  • Follows existing code patterns and conventions in the repository
  • Uses proper Rust error handling with anyhow::Context
  • Comprehensive assertions with descriptive error messages
  • No breaking changes to existing functionality
  • Compiles cleanly with cargo check (no warnings or errors)

Testing Approach:

  • Integration with existing E2E test framework
  • Uses GraphQL queries and subscriptions via indexer API
  • Validates data consistency across multiple API endpoints
  • Tests both success and edge case scenarios

Files Modified

  • indexer-tests/src/e2e.rs: Added ~200 lines of new test code

Testing

The code has been validated with:

cargo check --package indexer-tests

Result: ✅ Compiles successfully with no warnings or errors

Impact

This PR significantly improves test coverage for:

  1. Unshielded balance management - Critical for contract state tracking
  2. DUST generation mechanics - Essential for the Midnight privacy features
  3. Data consistency - Ensures reliability across query and subscription APIs

Next Steps

After this PR is merged, the test suite will:

  • Automatically validate unshielded balance correctness in CI/CD
  • Catch regressions in DUST generation status calculations
  • Ensure API consistency between queries and subscriptions

Related Documentation

…eatures

This commit implements end-to-end tests for two critical features:

1. **Unshielded Balances Testing** (`test_unshielded_balances_e2e`):
   - Validates that contract actions have unshielded balances correctly populated
   - Ensures consistency between GraphQL queries and subscriptions
   - Verifies balance amounts and token types are valid
   - Confirms that ContractDeploy actions have empty balances (per specification)
   - Tests edge cases including contracts with zero balances

2. **Enhanced DUST Generation Status Testing** (`test_dust_generation_status_query`):
   - Extended existing tests with additional validation scenarios
   - Tests empty reward address lists
   - Validates unregistered addresses return correct zero values
   - Tests duplicate address handling
   - Tests single address queries
   - Validates numeric string parsing for generation_rate, current_capacity, and night_balance

3. **Improved DUST Ledger Events Subscription** (`test_dust_ledger_events_subscription`):
   - Added logging for better test visibility
   - Enhanced validation for DUST ledger event structure
   - Graceful handling when no DUST events are present in test data

**Technical Details:**
- All tests follow existing patterns in the codebase
- Tests use GraphQL queries and subscriptions via the indexer API
- Proper error handling with anyhow::Context
- Comprehensive assertions with descriptive error messages
- No breaking changes to existing functionality

**Testing:**
- Code compiles successfully with `cargo check`
- No warnings or errors
- Follows Rust best practices and project conventions

Addresses issues:
- Add e2e tests for contract unshielded balances
- Plan and implement tests for DUST/cNIGHT features once integration is available
@roman98Z roman98Z requested a review from a team as a code owner December 22, 2025 23:19
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Manus AI seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

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