Skip to content

test(drive-abci): improve abci handler test coverage#3326

Merged
QuantumExplorer merged 3 commits into
v3.1-devfrom
test/drive-abci-handler-coverage
Mar 15, 2026
Merged

test(drive-abci): improve abci handler test coverage#3326
QuantumExplorer merged 3 commits into
v3.1-devfrom
test/drive-abci-handler-coverage

Conversation

@QuantumExplorer

@QuantumExplorer QuantumExplorer commented Mar 15, 2026

Copy link
Copy Markdown
Member

Issue being fixed or feature implemented

Improve test coverage for the packages/rs-drive-abci/src/abci/handler/ module by adding unit tests for previously uncovered error branches and edge cases.

What was done?

Added targeted unit tests to five handler files that previously lacked test coverage for error paths:

info.rs (2 tests):

  • ABCI version mismatch returns proper error
  • Successful handshake returns valid response with version info

extend_vote.rs (4 tests):

  • Missing block execution context returns error
  • Block hash mismatch returns "request does not match current block" error
  • Height mismatch returns error
  • Matching block with empty withdrawals succeeds

verify_vote_extension.rs (5 tests):

  • No block execution context returns Reject status
  • Height mismatch returns Reject status
  • Empty matching withdrawals returns Accept status
  • Mismatched withdrawal vote extensions returns Reject status
  • Different round but same height still returns Accept (correct behavior per code comments)

finalize_block.rs (2 tests):

  • No transaction started returns "not in transaction" error
  • Transaction exists but no block execution context returns proper error

init_chain.rs (1 test):

  • Existing block execution context is properly dropped during init_chain

How Has This Been Tested?

All 47 handler tests pass:

cargo test --package drive-abci --lib --features mocks -- abci::handler
test result: ok. 47 passed; 0 failed; 0 ignored; 0 measured; 1893 filtered out

Code passes clippy with no warnings:

cargo clippy --package drive-abci --lib --features mocks -- -D warnings

Breaking Changes

None. This PR only adds test code.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed

Summary by CodeRabbit

  • Tests
    • Added extensive unit tests across ABCI handlers (extend vote, verify vote extension, finalize block, info, init chain). Includes new test helpers and covers error scenarios when required contexts or versions are missing/mismatched, state-drop behavior, parameter validation, and successful execution paths. No public interfaces changed.

@github-actions github-actions Bot added this to the v3.1.0 milestone Mar 15, 2026
@coderabbitai

coderabbitai Bot commented Mar 15, 2026

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@QuantumExplorer has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 17 minutes and 12 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ba43233e-480c-4f04-855d-f7b4bd99887f

📥 Commits

Reviewing files that changed from the base of the PR and between 9246a69 and 0c65541.

📒 Files selected for processing (5)
  • packages/rs-drive-abci/src/abci/handler/extend_vote.rs
  • packages/rs-drive-abci/src/abci/handler/finalize_block.rs
  • packages/rs-drive-abci/src/abci/handler/info.rs
  • packages/rs-drive-abci/src/abci/handler/init_chain.rs
  • packages/rs-drive-abci/src/abci/handler/verify_vote_extension.rs
📝 Walkthrough

Walkthrough

Adds unit test modules to five ABCI handler files (extend_vote, finalize_block, info, init_chain, verify_vote_extension). Tests cover block execution context validation, height/round/hash/withdrawal mismatch cases, and success paths; no public APIs or core logic were changed.

Changes

Cohort / File(s) Summary
ABCI Handler Tests
packages/rs-drive-abci/src/abci/handler/extend_vote.rs, packages/rs-drive-abci/src/abci/handler/finalize_block.rs, packages/rs-drive-abci/src/abci/handler/info.rs, packages/rs-drive-abci/src/abci/handler/init_chain.rs, packages/rs-drive-abci/src/abci/handler/verify_vote_extension.rs
Added #[cfg(test)] modules with helpers and unit tests. Cover missing block execution context, block hash/height/round mismatches, withdrawal mismatch cases, and success scenarios. All tests instantiate a FullAbciApplication with mock RPC/TestPlatform; no exported signatures changed.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I hopped through tests with nimble feet,

checking hashes, rounds, and contexts neat.
No API changed, just trust increased,
five handlers guarded—bugs decreased.
🥕✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 71.43% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main purpose of the pull request: adding unit tests to improve test coverage for ABCI handler modules. It directly relates to the changeset's primary objective.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch test/drive-abci-handler-coverage
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (3)
packages/rs-drive-abci/src/abci/handler/finalize_block.rs (1)

132-138: Prefer matching error variants instead of message substrings in assertions.

These assertions are brittle to wording changes. Matching Error::Execution(ExecutionError::...) keeps tests stable while still validating behavior.

♻️ Proposed test assertion refactor
-        let result = finalize_block::<_, MockCoreRPCLike>(&app, request);
-        assert!(result.is_err());
-        let err_string = result.unwrap_err().to_string();
-        assert!(
-            err_string.contains("not in transaction")
-                || err_string.contains("trying to finalize block without"),
-            "Expected 'not in transaction' error, got: {}",
-            err_string
-        );
+        let result = finalize_block::<_, MockCoreRPCLike>(&app, request);
+        assert!(
+            matches!(result, Err(Error::Execution(ExecutionError::NotInTransaction(_)))),
+            "Expected NotInTransaction error, got: {result:?}"
+        );
@@
-        let result = finalize_block::<_, MockCoreRPCLike>(&app, request);
-        assert!(result.is_err());
-        let err_string = result.unwrap_err().to_string();
-        assert!(
-            err_string.contains("block execution context must be set"),
-            "Expected 'block execution context must be set' error, got: {}",
-            err_string
-        );
+        let result = finalize_block::<_, MockCoreRPCLike>(&app, request);
+        assert!(
+            matches!(
+                result,
+                Err(Error::Execution(ExecutionError::CorruptedCodeExecution(_)))
+            ),
+            "Expected CorruptedCodeExecution error, got: {result:?}"
+        );

Also applies to: 161-166

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/rs-drive-abci/src/abci/handler/finalize_block.rs` around lines 132 -
138, The test currently converts the error to a string and asserts on substrings
(using result.unwrap_err().to_string() and err_string.contains(...)); replace
this brittle check by matching the concrete error variant returned (e.g., match
on the error from result.unwrap_err() and assert it is
Error::Execution(ExecutionError::NotInTransaction) or the appropriate variant),
doing the same refactor for the similar block around lines 161-166; reference
the result variable and the existing unwrap_err() call and replace the substring
checks with pattern matching against the Error and ExecutionError enum variants
to make the assertion robust.
packages/rs-drive-abci/src/abci/handler/extend_vote.rs (1)

165-189: Tighten the height-mismatch assertion to avoid false positives.

At Line 188, assert!(result.is_err()) will pass for any error path. Assert the specific wrong-block signal so this test only validates the intended branch.

Suggested test assertion refinement
-        let result = extend_vote::<_, MockCoreRPCLike>(&app, request);
-        assert!(result.is_err());
+        let result = extend_vote::<_, MockCoreRPCLike>(&app, request);
+        assert!(result.is_err());
+        let err_string = result.unwrap_err().to_string();
+        assert!(
+            err_string.contains("request does not match current block"),
+            "Expected wrong block error, got: {}",
+            err_string
+        );
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/rs-drive-abci/src/abci/handler/extend_vote.rs` around lines 165 -
189, The test extend_vote_fails_when_height_does_not_match currently asserts any
error (assert!(result.is_err())); change it to assert the specific wrong-block
error returned by extend_vote so the test only passes for the intended branch:
call result.unwrap_err() (or match result) and assert it equals or matches the
wrong-block variant/error code emitted by extend_vote (e.g., the
WrongBlock/WrongHeight signal from the ABci error type), referencing the
extend_vote::<_, MockCoreRPCLike> call and the RequestExtendVote used in the
test to locate the check.
packages/rs-drive-abci/src/abci/handler/info.rs (1)

153-156: Use exact handshake expectations instead of broad checks.

At Line 154-155, !is_empty() and > 0 are permissive. Asserting the concrete expected values makes this test more regression-resistant.

Suggested assertion strengthening
         assert_eq!(response.last_block_height, 0);
-        assert!(!response.version.is_empty());
-        assert!(response.app_version > 0);
+        assert_eq!(response.version, env!("CARGO_PKG_VERSION"));
+        assert_eq!(
+            response.app_version,
+            DESIRED_PLATFORM_VERSION.protocol_version as u64
+        );
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/rs-drive-abci/src/abci/handler/info.rs` around lines 153 - 156, The
test currently uses permissive checks for handshake values; replace
assert!(!response.version.is_empty()) and assert!(response.app_version > 0) with
exact equality checks against the known expected handshake constants:
assert_eq!(response.version, <expected_version>) and
assert_eq!(response.app_version, <expected_app_version>), where
<expected_version> should be the package/version constant (e.g.
env!("CARGO_PKG_VERSION") or your crate's VERSION) and <expected_app_version>
the agreed app version constant used by the ABCI handshake (or a literal
expected value); keep the existing assert_eq!(response.last_block_height, 0)
as-is. Ensure you reference the constants you use (e.g.,
env!("CARGO_PKG_VERSION") or crate::APP_VERSION) so the test asserts the
concrete expected handshake values.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/rs-drive-abci/src/abci/handler/init_chain.rs`:
- Around line 117-124: After calling init_chain::<_, MockCoreRPCLike>(&app,
request) replace the unused _result with a captured result and add an explicit
assertion that the block execution context was cleared—e.g., call the
accessor/take method or inspect the field (block_execution_context or
take_block_execution_context()) and assert it is None/empty
(assert!(app.block_execution_context.is_none()) or
assert!(app.take_block_execution_context().is_none())). Keep the init_chain call
but add this concrete assertion immediately after to fail the test if context
clearing regresses.

---

Nitpick comments:
In `@packages/rs-drive-abci/src/abci/handler/extend_vote.rs`:
- Around line 165-189: The test extend_vote_fails_when_height_does_not_match
currently asserts any error (assert!(result.is_err())); change it to assert the
specific wrong-block error returned by extend_vote so the test only passes for
the intended branch: call result.unwrap_err() (or match result) and assert it
equals or matches the wrong-block variant/error code emitted by extend_vote
(e.g., the WrongBlock/WrongHeight signal from the ABci error type), referencing
the extend_vote::<_, MockCoreRPCLike> call and the RequestExtendVote used in the
test to locate the check.

In `@packages/rs-drive-abci/src/abci/handler/finalize_block.rs`:
- Around line 132-138: The test currently converts the error to a string and
asserts on substrings (using result.unwrap_err().to_string() and
err_string.contains(...)); replace this brittle check by matching the concrete
error variant returned (e.g., match on the error from result.unwrap_err() and
assert it is Error::Execution(ExecutionError::NotInTransaction) or the
appropriate variant), doing the same refactor for the similar block around lines
161-166; reference the result variable and the existing unwrap_err() call and
replace the substring checks with pattern matching against the Error and
ExecutionError enum variants to make the assertion robust.

In `@packages/rs-drive-abci/src/abci/handler/info.rs`:
- Around line 153-156: The test currently uses permissive checks for handshake
values; replace assert!(!response.version.is_empty()) and
assert!(response.app_version > 0) with exact equality checks against the known
expected handshake constants: assert_eq!(response.version, <expected_version>)
and assert_eq!(response.app_version, <expected_app_version>), where
<expected_version> should be the package/version constant (e.g.
env!("CARGO_PKG_VERSION") or your crate's VERSION) and <expected_app_version>
the agreed app version constant used by the ABCI handshake (or a literal
expected value); keep the existing assert_eq!(response.last_block_height, 0)
as-is. Ensure you reference the constants you use (e.g.,
env!("CARGO_PKG_VERSION") or crate::APP_VERSION) so the test asserts the
concrete expected handshake values.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1284f068-80f1-49f7-b5ff-5f68b2728f65

📥 Commits

Reviewing files that changed from the base of the PR and between d604d92 and 8f6221d.

📒 Files selected for processing (5)
  • packages/rs-drive-abci/src/abci/handler/extend_vote.rs
  • packages/rs-drive-abci/src/abci/handler/finalize_block.rs
  • packages/rs-drive-abci/src/abci/handler/info.rs
  • packages/rs-drive-abci/src/abci/handler/init_chain.rs
  • packages/rs-drive-abci/src/abci/handler/verify_vote_extension.rs

Comment thread packages/rs-drive-abci/src/abci/handler/init_chain.rs
@codecov

codecov Bot commented Mar 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.62533% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.26%. Comparing base (6a60c5b) to head (0c65541).
⚠️ Report is 1 commits behind head on v3.1-dev.

Files with missing lines Patch % Lines
...s/rs-drive-abci/src/abci/handler/finalize_block.rs 88.57% 4 Missing ⚠️
...ages/rs-drive-abci/src/abci/handler/extend_vote.rs 97.43% 3 Missing ⚠️
packages/rs-drive-abci/src/abci/handler/info.rs 97.22% 1 Missing ⚠️
...kages/rs-drive-abci/src/abci/handler/init_chain.rs 97.95% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           v3.1-dev    #3326      +/-   ##
============================================
+ Coverage     73.13%   73.26%   +0.13%     
============================================
  Files          3291     3291              
  Lines        271091   272261    +1170     
============================================
+ Hits         198261   199479    +1218     
+ Misses        72830    72782      -48     
Components Coverage Δ
dpp 60.40% <ø> (+0.02%) ⬆️
drive 78.31% <ø> (ø)
drive-abci 85.76% <97.62%> (+0.25%) ⬆️
sdk 31.25% <ø> (ø)
dapi-client 79.06% <ø> (ø)
platform-version ∅ <ø> (∅)
platform-value 58.46% <ø> (ø)
platform-wallet 60.40% <ø> (ø)
drive-proof-verifier ∅ <ø> (∅)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

QuantumExplorer and others added 3 commits March 16, 2026 05:12
Add unit tests for ABCI handler error branches and edge cases:
- info: ABCI version mismatch error, successful handshake response
- extend_vote: missing block context, block hash mismatch, height mismatch, success path
- verify_vote_extension: no block context, height mismatch, withdrawal mismatch,
  different round acceptance, success path
- finalize_block: no transaction error, missing block execution context error
- init_chain: existing block execution context drop path

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Address CodeRabbit review feedback: replace comment-only verification
with an explicit assertion that block_execution_context is cleared
after init_chain processes an existing context.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- extend_vote: tighten height-mismatch test to assert specific error message
- finalize_block: use matches! with error variants instead of string contains
- info: assert exact expected values for version and app_version

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@QuantumExplorer QuantumExplorer force-pushed the test/drive-abci-handler-coverage branch from de72caa to 0c65541 Compare March 15, 2026 22:12
@QuantumExplorer QuantumExplorer merged commit 8954eeb into v3.1-dev Mar 15, 2026
19 checks passed
@QuantumExplorer QuantumExplorer deleted the test/drive-abci-handler-coverage branch March 15, 2026 22:35
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