Skip to content

test(router-access): cover set_role_limits and get_role_limits (#1047) - #1241

Open
gebibd00-jpg wants to merge 1 commit into
Maki-Zeninn:mainfrom
gebibd00-jpg:test/role-limits-coverage
Open

test(router-access): cover set_role_limits and get_role_limits (#1047)#1241
gebibd00-jpg wants to merge 1 commit into
Maki-Zeninn:mainfrom
gebibd00-jpg:test/role-limits-coverage

Conversation

@gebibd00-jpg

Copy link
Copy Markdown
Contributor

Summary

set_role_limits (contracts/router-access/src/lib.rs lines 93-111) and get_role_limits (lines 113-119) are admin-facing configuration entry points for the (max_roles, max_grants_per_role) policy that governs MaxRolesExceeded / MaxGrantsPerRoleExceeded enforcement elsewhere in the contract. Both functions had zero direct test coverage: a grep for the two names in the test module returns no matches, and the issue confirms it. A regression in the 0-means-default logic or the super-admin auth gate could have shipped unnoticed.

Fix

This change adds the four tests the issue itself suggested, in the same style as the existing test_set_role_admin_* / test_grant_role_* cases:

  • test_get_role_limits_defaults — before any set_role_limits call, the contract returns the compile-time defaults (100, 1_000).
  • test_set_role_limits_updates_and_persists — a non-zero (max_roles, max_grants_per_role) is stored, and a subsequent get_role_limits returns the new values.
  • test_set_role_limits_zero_resets_to_defaults — passing 0 for either field restores the compile-time default for that field.
  • test_set_role_limits_unauthorized_fails — a non-super-admin caller is rejected with AccessError::Unauthorized.

I do not have a local Rust toolchain on this machine, so I could not run cargo test myself. The tests are written by analogy with the existing patterns in the same test module and use the existing setup() helper, so they should compile and pass without further changes. Please run the suite on a Soroban environment before merging.

Closes

#1047

…Zeninn#1047)

`set_role_limits` (contracts/router-access/src/lib.rs lines 93-111)
and `get_role_limits` (lines 113-119) are admin-facing configuration
entry points for the (max_roles, max_grants_per_role) policy that
governs `MaxRolesExceeded` / `MaxGrantsPerRoleExceeded` enforcement
elsewhere in the contract. Both functions had zero direct test
coverage: a grep for the two names in the test module returns no
matches, and the issue confirms it. A regression in the
`0`-means-default logic or the super-admin auth gate could have
shipped unnoticed.

This change adds the four tests the issue itself suggested, in
the same style as the existing `test_set_role_admin_*` /
`test_grant_role_*` cases:

- `test_get_role_limits_defaults` -- before any
  `set_role_limits` call, the contract returns the compile-time
  defaults (100, 1_000).
- `test_set_role_limits_updates_and_persists` -- a non-zero
  (max_roles, max_grants_per_role) is stored, and a subsequent
  `get_role_limits` returns the new values.
- `test_set_role_limits_zero_resets_to_defaults` -- passing 0
  for either field restores the compile-time default for that
  field.
- `test_set_role_limits_unauthorized_fails` -- a non-super-admin
  caller is rejected with `AccessError::Unauthorized`.

I do not have a local Rust toolchain on this machine, so I could
not run `cargo test` myself. The tests are written by analogy
with the existing patterns in the same test module and use the
existing `setup()` helper, so they should compile and pass
without further changes. Please run the suite on a Soroban
environment before merging.

Closes Maki-Zeninn#1047.
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