Skip to content

Code Coverage Improvement - avoiding dead codes, improving test scenarios and cases #139

Closed
mudigal wants to merge 15 commits into
devfrom
feat/improve-code-coverage
Closed

Code Coverage Improvement - avoiding dead codes, improving test scenarios and cases #139
mudigal wants to merge 15 commits into
devfrom
feat/improve-code-coverage

Conversation

@mudigal

@mudigal mudigal commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator

Summary

Comprehensive test coverage improvement across the entire codebase, raising pallet coverage from 62% to 80% and provider-node coverage from 26% to 78%.

Pallet tests

  • 47 new tests for pallet-storage-provider: challenge costs, checkpoints, replicas, events, and runtime API
  • 8 new success-path tests for pallet-drive-registry: drive CRUD, sharing/unsharing, admin delegation (exercises previously-uncovered _internal functions)

Provider-node tests

  • 50+ new integration tests across API endpoints, file system, S3, error paths, edge cases, and storage utilities
  • 6 new challenge responder tests with realistic storage data setup and proof generation
  • Extracted chain traits from background coordinators for testability
  • Moved coordinator mock tests to integration tests for CI coverage visibility

CI improvements

  • Measure all 3 pallets together (pallet-storage-provider, pallet-drive-registry, pallet-s3-registry) in a single coverage run
  • Dynamically discover integration test targets for provider-node coverage
  • Fix Zombienet smoke test flakiness: use //Bob for S3 demo to avoid nonce contention with provider node running as //Alice
  • Reduce SC test flakiness by switching to dev-mode and simplifying CI matrix

Test plan

  • cargo test --workspace — all tests pass
  • cargo clippy --all-targets --all-features --workspace -- -D warnings — clean
  • CI coverage gate passes (62% → 80% pallet, 26% → 78% provider)

mudigal added 3 commits June 5, 2026 12:20
…oints

Add 16 new tests to api_integration.rs covering stats, chunk_proof,
mmr_peaks, mmr_subtree, fetch_nodes, checkpoint coordination, replica
sync status, and delete happy path. Create fs_integration.rs with 14
tests covering all 6 FS endpoints (put/get/delete file, mkdir, ls,
index_root) including edge cases like invalid paths, overwrites, large
multi-chunk files, and directory-as-file errors.
The CI coverage job used `cargo llvm-cov --lib` which only runs unit
tests inside src/. This missed all 56 integration tests in tests/*.rs,
reporting 30% instead of the actual ~42%. Change to `--tests` so
integration tests are included in the coverage measurement.
@mudigal mudigal self-assigned this Jun 5, 2026
mudigal added 10 commits June 5, 2026 22:10
…HTTP tests only

Add auth_integration and disk_integration test suites that exercise
the HTTP API with mocked chain dependencies (MockResolver) and the
DiskStorage (RocksDB) backend respectively. Update CI coverage to
measure only integration tests (--test flags) instead of --tests,
so coverage reflects code reachable through the public API.
…ators for testability

Extract chain interactions from AgreementCoordinator, ChallengeResponder,
CheckpointCoordinator, and ReplicaSyncCoordinator behind per-coordinator
traits (AgreementChainClient, ChallengeChainClient, CheckpointChainClient,
ReplicaSyncChainClient), following the existing MembershipResolver pattern.

Each coordinator now takes a `Box<dyn XChainClient>` instead of hardcoding
`Option<OnlineClient<PolkadotConfig>>`, enabling mock-based unit testing
without a live chain. Adds 30 new unit tests across all four coordinators.
The base branch may not have all integration test files that exist on the
PR branch. Dynamically check which test files exist before passing --test
flags to cargo llvm-cov. Also treat empty coverage values as 0 to prevent
awk syntax errors in the comparison step.
… for CI coverage

Move 29 coordinator mock tests from #[cfg(test)] blocks in source files
to integration test files under provider-node/tests/. CI measures
provider-node coverage from integration tests only, so these tests were
invisible to the coverage gate despite exercising production code paths.

- Create 4 integration test files (agreement, challenge, checkpoint, replica)
- Remove #[cfg(test)] blocks from the 4 coordinator source files
- Make tested methods pub so integration tests can call them
- Use newtype SharedMock wrappers to satisfy orphan rules
- Add new test targets to CI coverage discovery loop in check.yml
…coverage exclusion

Move production Subxt chain client implementations into dedicated *_subxt.rs
files so they can be excluded from CI coverage metrics alongside command.rs,
cli.rs, and main.rs. This shrinks the coverage denominator to only testable
code, giving a more accurate picture of actual test coverage.
…ifying CI matrix

- Remove runtime-matrix job — both test jobs now use single runtime (web3-storage-paseo)
- integration-tests → "Zombienet Smoke Test": keeps relay-chain topology, runs demo + fs-demo-ci + s3-demo-ci, drops redundant disk provider
- sc-integration-tests → dev-mode chain (2s blocks, instant finality) to fix sc-token-gated timeout flakiness
- Layer 0 comprehensive coverage remains in e2e-integration-tests (dev-mode, ~100 test cases)
…ases, and storage utilities

Cover previously untested code paths to increase provider-node coverage:
- storage_integration.rs: 23 tests for hex encode/decode, merkle tree building, chunk collection, and tree size calculation
- api_integration.rs: 11 tests for invalid hex, missing nodes, invalid base64, and signing-unavailable error paths
- fs_integration.rs: 4 tests for empty body, mkdir validation, delete-then-list, and nested directories
- s3_integration.rs: 5 tests for HEAD/DELETE nonexistent, empty body, metadata roundtrip, and empty bucket listing
- replica_sync_coordinator_integration.rs: 7 tests for get_active_replica_duties filter paths and handle commands
…, events, and runtime API

Cover previously untested pallet logic: challenge response cost splits
across 5 time brackets, multi-challenge slashing, provider checkpoint
leader election with real Sr25519 signatures, grace period fallback,
reward pool distribution, replica sync flow with error paths, event
assertions for 6 core extrinsics, and 12 runtime API query tests.
…ponder

Add 8 success-path tests to pallet-drive-registry exercising the
previously untested _internal functions (create_bucket_internal,
request_primary_agreement_internal, cleanup_bucket_internal,
set_member_internal, remove_member_internal) via a setup_provider()
helper that follows the S3 pallet pattern.

Add 7 challenge responder integration tests with realistic storage
data setup (init bucket, store chunk, build Merkle tree, commit to
MMR) covering the full respond_to_challenge() path: successful proof
generation and submission, missing bucket, bad chunk index, submission
failure, callback invocation, and pause/resume behavior.

Update CI coverage to measure all 3 pallets together instead of only
pallet-storage-provider, with benchmarking file exclusions.
…r node

The Zombienet smoke test fails with stale nonce (1010) on the S3 demo
because both the demo client and the provider node's background
coordinators (agreement, checkpoint) submit transactions as //Alice.
Switch S3 CI test to //Bob to eliminate the race condition.

Also remove storage_integration.rs — its utility function tests are
redundant since all functions are already exercised through the endpoint
integration tests.
@mudigal mudigal changed the title test(provider-node): add integration tests for all untested HTTP endpoints test: improve code coverage across pallets, provider-node, and CI Jun 8, 2026
@mudigal mudigal changed the title test: improve code coverage across pallets, provider-node, and CI Code Coverage Improvement - avoiding dead codes, improving test scenarios and cases Jun 8, 2026
@mudigal mudigal enabled auto-merge (squash) June 8, 2026 06:30
mudigal added 2 commits June 8, 2026 13:52
…ops, glob CI test list

- checkpoint.rs: replace if/else fallback with direct assert_ok! for deterministic test
- challenge_responder/checkpoint_coordinator: replace 300ms fixed sleeps with
  tokio::time::timeout poll loops (5s timeout, 10ms poll) for CI robustness
- check.yml: replace hardcoded integration test list with glob-based discovery
…CI coverage

HIGH:
- command.rs: replace expect() with error return in sync_multiaddr_on_chain
- agreement_coordinator_subxt.rs: replace expect() with defensive continue on key parsing
- mock.rs: add warning comment about run_to_block not calling pallet hooks

MEDIUM:
- check.yml: add TEST_FLAGS guard on PR side, validate coverage values are non-empty
- replica_sync mock: remove dead block_on methods (panic footgun in async context)
- misc.rs: fix remove_slashed_works to slash reserved balance (matches production)
- lib.rs: restrict _subxt modules to pub(crate) visibility
@mudigal

mudigal commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator Author

Superseded by 4 smaller PRs for easier review:

# PR Base Lines Description
1 #145 dev ~3300 Refactor: extract chain traits + CI hardening
2 #146 dev ~1600 Pallet tests (independent)
3 #147 #145 ~2200 HTTP + storage integration tests
4 #148 #147 ~1800 Coordinator mock tests + FS pallet tests

All tests verified passing on the final branch.

@mudigal mudigal closed this Jun 8, 2026
auto-merge was automatically disabled June 8, 2026 19:23

Pull request was closed

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