hyperledger / hyperledger/fabric-x-evm

Testing and Validation

Open
#136 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
12
Forks
18
Avg merge
4d 18h
Merged PRs (30d)
23

Description

**Goal**: Ensure the implementation works correctly through comprehensive unit and integration tests, covering both happy paths and edge cases.

### Task 6.1: Unit Tests for TxQueue
**What to do**: Create comprehensive unit tests for all new TxQueue methods in `gateway/core/txqueue_test.go`.

**Details**:
- Test `IsPending()`:
- Returns true for transaction in pending queue
- Returns true for transaction in in-progress map
- Returns false for transaction in neither
- Test `Dequeue()` moves transaction from pending to in-progress
- Test `MarkCompleted()` removes transaction from in-progress
- Test concurrent access:
- Multiple goroutines calling `IsPending()` simultaneously
- Enqueue and Dequeue happening concurrently
- MarkCompleted called while IsPending is running
- Use Go's race detector: `go test -race`

**Why**: Unit tests catch bugs early and ensure thread-safety, which is critical for concurrent code.

### Task 6.2: Integration Test for Pending Transaction Flow
**What to do**: Create an end-to-end integration test that verifies the complete pending transaction lifecycle.

**Details**:
- Test scenario:
1. Start Gateway and Chain
2. Submit a transaction via `SendTransaction()`
3. Immediately call `TransactionByHash()` - should return `isPending = true`
4. Wait for block to be committed (may need to trigger block creation in test)
5. Call `TransactionByHash()` again - should return `isPending = false` with transaction data
- Add assertions at each step
- Use test helpers to create and sign transactions
- Consider adding timing assertions (pending status should last at least X milliseconds)

**Why**: Integration tests verify that all components work together correctly, catching issues that unit tests miss.

### Task 6.3: Test Callback Mechanism
**What to do**: Create tests specifically for the callback notification system.

**Details**:
- Test that callback is invoked when block is committed
- Test that callback receives correct transaction hashes
- Test that transactions are removed from in-progress map after callback
- Test callback with multiple transactions in one block
- Test callback with empty block (no transactions)
- Test that callback errors don't break block processing (use a callback that panics)

**Why**: The callback mechanism is the critical link between Chain and Gateway. Bugs here would break pending status tracking.

### Task 6.4: Test Edge Cases
**What to do**: Create tests for all the edge cases identified in Phase 5.

**Details**:
- Test transaction failure during processing:
- Mock `processTx()` to return an error
- Verify transaction is removed from in-progress map
- Verify subsequent `IsPending()` returns false
- Test duplicate submission:
- Submit same transaction twice
- Verify second submission is rejected or handled correctly
- Test Gateway shutdown with pending transactions:
- Enqueue transactions
- Call `Stop()`
- Verify clean shutdown
- Document that pending transactions are lost
- Test race conditions using `-race` flag

**Why**: Edge cases are where bugs hide. Thorough testing of failure scenarios ensures robustness in production.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with gateway/core/txqueue_test.go and inspect the TxQueue methods named in the task. Then trace SendTransaction(), TransactionByHash(), the Gateway and Chain test helpers, and the callback path. Run the unit and integration tests with go test -race; done means pending-state transitions, callbacks, failures, duplicates, shutdown, and concurrency cases are covered.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend, testing-qa
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.