Skip to content

test(rpc): cover BatchSizeLimitMiddleware with max_entries=0#154

Open
Kewe63 wants to merge 1 commit into
circlefin:mainfrom
Kewe63:test/batch-size-limit-edge-cases
Open

test(rpc): cover BatchSizeLimitMiddleware with max_entries=0#154
Kewe63 wants to merge 1 commit into
circlefin:mainfrom
Kewe63:test/batch-size-limit-edge-cases

Conversation

@Kewe63

@Kewe63 Kewe63 commented Jun 15, 2026

Copy link
Copy Markdown

Summary

BatchSizeLimitMiddleware accepts a max_entries: usize and rejects any batch whose length exceeds it. The CLI value parser parse_max_batch_entries rejects 0 with must be >= 1, so the runtime cap is always at least 1. However, the in-process BatchSizeLimitMiddleware::new constructor has no such guard — callers can intentionally build a "no batches allowed" layer with max_entries = 0, and the middleware must behave sensibly in that case.

This corner case had no test coverage.


Fix

Added a focused test locking in the documented behavior for max_entries = 0:

  • Any non-empty batch is rejected with BATCH_TOO_LARGE_ERROR_CODE, and the error message names the offending size and limit.
  • Empty batches are deliberately not asserted on: MockRpcService rejects empty batches with a different error code (-32600 "Invalid request"), and pinning the middleware's response shape on top of that quirk would lock in the wrong contract. The empty-batch case is left to the JSON-RPC layer below the middleware.

Changes

File: crates/arc-evm-node/src/ (batch size limit tests)

  • Added batch_size_limit_max_entries_zero test covering the max_entries = 0 case with non-empty batch inputs.

How to Test

# Batch size limit tests
cargo test -p arc-evm-node --lib batch_size_limit
# ✅ 7 passed, 0 failed

# Format & lint
cargo fmt --check -p arc-evm-node
cargo clippy -p arc-evm-node --tests -- -D warnings
# ✅ Both clean

Risk & Impact

None. Test-only addition — no production code modified. Locks in correct middleware behavior for an untested constructor edge case.

Type: 🧪 Test coverage

The middleware's `max_entries = 0` corner case (allowed in-process
because `BatchSizeLimitMiddleware::new` has no guard, even though
the CLI value parser `parse_max_batch_entries` rejects 0) was
untested. Add a focused test that locks in the documented behaviour:
any non-empty batch is rejected with `BATCH_TOO_LARGE_ERROR_CODE`,
and the error message names the offending size and limit.

An empty-batch pass-through test was considered and dropped: the
`MockRpcService` itself rejects empty batches with a different
error code (-32600 'Invalid request'), and asserting on the
final response shape would lock in that quirk rather than the
middleware's contract. The empty-batch case is left to the
JSON-RPC layer below the middleware.
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