Skip to content

test: adversarial coverage for set_emit_v2_compat (#1068) - #1227

Closed
Manager-dev1515 wants to merge 1 commit into
RevoraOrg:masterfrom
Manager-dev1515:test/adversarial-set-emit-v2-compat-1068
Closed

Manager-dev1515 wants to merge 1 commit into
RevoraOrg:masterfrom
Manager-dev1515:test/adversarial-set-emit-v2-compat-1068

Conversation

@Manager-dev1515

Copy link
Copy Markdown

Adds src/test_set_emit_v2_compat.rs — a focused standalone test module with 21 deterministic tests covering every meaningful behaviour of:

pub fn set_emit_v2_compat(env, caller, enabled) -> Result<(), RevoraError>

What changed

src/test_set_emit_v2_compat.rs (new file)
21 tests across 9 categories — all passing in CI (Ubuntu, cargo test).

src/lib.rs
Added '#[cfg(test)] mod test_set_emit_v2_compat;' to the test-module registry.

Coverage added

Category Test name
Default true before any call default_is_true_before_set
Admin disables flag admin_can_disable
Admin enables flag admin_can_enable
Toggle false -> true admin_can_re_enable_after_disable
Full round-trip true/false/true/false set_emit_v2_compat_full_roundtrip
Idempotent set-true set_same_value_true_is_idempotent
Idempotent set-false set_same_value_false_is_idempotent
NotInitialized — no admin set returns_not_initialized_when_no_admin
NotAuthorized — wrong caller wrong_caller_returns_not_authorized
State unchanged after rejected call wrong_caller_does_not_mutate_state
Layer-1 host auth boundary (ignored) no_auth_mock_panics_layer1
ev_v2c event emitted on enable emits_event_on_enable
ev_v2c event emitted on disable emits_event_on_disable
No event on rejected call no_event_emitted_on_rejected_call
supported_event_versions reflects flag supported_event_versions_reflects_flag
V2 suppressed when flag=false v2_events_suppressed_when_compat_disabled
V2 emitted when flag=true v2_events_emitted_when_compat_enabled
V3 always emitted regardless of flag v3_events_always_emitted
Frozen contract still accepts change flag_can_be_set_when_contract_frozen
Paused contract still accepts change flag_can_be_set_when_contract_paused
Flag isolated per contract instance flag_is_isolated_per_contract_instance

Why each category matters

Auth layer split:
Layer-1 (require_auth) aborts the WASM process without returning a typed
error. Layer-2 (caller != admin) returns NotAuthorized and is catchable
via try_*. Tests separately document and exercise both layers.

NotInitialized boundary:
The function reads DataKey::Admin; calling it on a fresh contract (no
set_admin yet) must return NotInitialized, not panic.

State immutability on rejection:
wrong_caller_does_not_mutate_state starts from a known non-default state
(flag=false) and confirms a rejected call cannot flip it back to true.

Event correctness:
Both the presence and the boolean data payload of ev_v2c are asserted.
A rejected call must produce zero ev_v2c events.

V2/V3 effect:
Three tests verify the end-to-end effect of the flag on actual event
emission from report_revenue: V2 events suppressed when false, emitted
when true, and V3 always present regardless.

No freeze/pause guard:
set_emit_v2_compat intentionally omits require_not_frozen and
require_not_paused so indexer operators can always complete a migration
window cutover. Two tests confirm this absence is intentional and stable.

Isolation:
The flag lives in per-contract persistent storage; two independent
contract instances must not share flag state.

Public contract preservation

set_emit_v2_compat signature and behaviour are unchanged. No production code was modified; the only lib.rs change is the #[cfg(test)] module declaration.

Closes #1068

@drips-wave

drips-wave Bot commented Sep 27, 2026

Copy link
Copy Markdown

@Manager-dev1515 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Manager-dev1515
Manager-dev1515 force-pushed the test/adversarial-set-emit-v2-compat-1068 branch from c854ca2 to 4b302d6 Compare October 15, 2026 21:54
Adds src/test_set_emit_v2_compat.rs — a focused standalone test module
with 21 deterministic tests covering every meaningful behaviour of:

  pub fn set_emit_v2_compat(env, caller, enabled) -> Result<(), RevoraError>

src/test_set_emit_v2_compat.rs  (new file)
  21 tests across 9 categories — all passing in CI (Ubuntu, cargo test).

src/lib.rs
  Added '#[cfg(test)] mod test_set_emit_v2_compat;' to the test-module registry.

| Category                                  | Test name                                               |
|-------------------------------------------|---------------------------------------------------------|
| Default true before any call              | default_is_true_before_set                              |
| Admin disables flag                       | admin_can_disable                                       |
| Admin enables flag                        | admin_can_enable                                        |
| Toggle false -> true                      | admin_can_re_enable_after_disable                       |
| Full round-trip true/false/true/false     | set_emit_v2_compat_full_roundtrip                       |
| Idempotent set-true                       | set_same_value_true_is_idempotent                       |
| Idempotent set-false                      | set_same_value_false_is_idempotent                      |
| NotInitialized — no admin set             | returns_not_initialized_when_no_admin                   |
| NotAuthorized — wrong caller              | wrong_caller_returns_not_authorized                     |
| State unchanged after rejected call       | wrong_caller_does_not_mutate_state                      |
| Layer-1 host auth boundary (ignored)      | no_auth_mock_panics_layer1                              |
| ev_v2c event emitted on enable            | emits_event_on_enable                                   |
| ev_v2c event emitted on disable           | emits_event_on_disable                                  |
| No event on rejected call                 | no_event_emitted_on_rejected_call                       |
| supported_event_versions reflects flag    | supported_event_versions_reflects_flag                  |
| V2 suppressed when flag=false             | v2_events_suppressed_when_compat_disabled               |
| V2 emitted when flag=true                 | v2_events_emitted_when_compat_enabled                   |
| V3 always emitted regardless of flag      | v3_events_always_emitted                                |
| Frozen contract still accepts change      | flag_can_be_set_when_contract_frozen                    |
| Paused contract still accepts change      | flag_can_be_set_when_contract_paused                    |
| Flag isolated per contract instance       | flag_is_isolated_per_contract_instance                  |

Auth layer split:
  Layer-1 (require_auth) aborts the WASM process without returning a typed
  error. Layer-2 (caller != admin) returns NotAuthorized and is catchable
  via try_*. Tests separately document and exercise both layers.

NotInitialized boundary:
  The function reads DataKey::Admin; calling it on a fresh contract (no
  set_admin yet) must return NotInitialized, not panic.

State immutability on rejection:
  wrong_caller_does_not_mutate_state starts from a known non-default state
  (flag=false) and confirms a rejected call cannot flip it back to true.

Event correctness:
  Both the presence and the boolean data payload of ev_v2c are asserted.
  A rejected call must produce zero ev_v2c events.

V2/V3 effect:
  Three tests verify the end-to-end effect of the flag on actual event
  emission from report_revenue: V2 events suppressed when false, emitted
  when true, and V3 always present regardless.

No freeze/pause guard:
  set_emit_v2_compat intentionally omits require_not_frozen and
  require_not_paused so indexer operators can always complete a migration
  window cutover. Two tests confirm this absence is intentional and stable.

Isolation:
  The flag lives in per-contract persistent storage; two independent
  contract instances must not share flag state.

set_emit_v2_compat signature and behaviour are unchanged. No production
code was modified; the only lib.rs change is the #[cfg(test)] module
declaration.

Closes RevoraOrg#1068
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 adversarial coverage for set_emit_v2_compat in lib

3 participants