Skip to content

test: add regression tests for beyond-count and off-by-one settlement listing boundaries#227

Open
onyekachi66 wants to merge 1 commit into
AnchorNet-Org:mainfrom
onyekachi66:main
Open

test: add regression tests for beyond-count and off-by-one settlement listing boundaries#227
onyekachi66 wants to merge 1 commit into
AnchorNet-Org:mainfrom
onyekachi66:main

Conversation

@onyekachi66

Copy link
Copy Markdown

Closes #150

Overview

This PR addresses a test-coverage gap identified in the settlement pagination logic. Specifically, the boundary where the paginated request parameter start exceeds the total number of settlements (settlement_count()) did not have explicit, dedicated coverage to prevent regression panics.

While the existing implementation correctly handles this under-the-hood (using loop guards like id <= count with (out.len() as u32) < limit), this PR guarantees safety at these boundaries for external integrators who might naively increment start beyond the available index set.


Changes Made

Tests Added in src/test.rs

Added two new unit tests to explicitly lock down the behavior of the following four APIs:

  1. list_settlements
  2. list_settlements_by_anchor
  3. list_settlements_by_asset
  4. list_settlements_by_status

1. test_list_settlements_beyond_count

  • Scenario: Checks pagination behavior when the start parameter is set significantly higher than the total number of settlements.
  • Verification: Initializes an environment with two active settlements and queries all four endpoints with a start value of 100. Asserts that all endpoints successfully return an empty Vec rather than throwing an error or panicking.

2. test_list_settlements_off_by_one_boundary

  • Scenario: Targets the critical off-by-one boundary where the start parameter is exactly equal to settlement_count() + 1.
  • Verification: Initializes an environment with two active settlements (IDs 1 and 2, total settlement_count() = 2). Queries all four endpoints with start set to 3. Asserts that each call returns an empty Vec without panic.

Acceptance Criteria Checklist

  • Tested list_settlements beyond-count boundary.
  • Tested list_settlements_by_anchor beyond-count boundary.
  • Tested list_settlements_by_asset beyond-count boundary.
  • Tested list_settlements_by_status beyond-count boundary.
  • Explicitly verified the start == count + 1 off-by-one boundary.
  • Ensured no panics or errors occur at these boundaries.

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.

Add regression test that list_settlements(start, limit) with start beyond settlement_count returns an empty page

1 participant