Skip to content

test(#443): cover oracle timeout fallback path (trigger_randomness_fa…#539

Merged
Otaiki1 merged 2 commits into
crackedstudio:masterfrom
ademolacomfort:issue-443-oracle-timeout-fallback-tests
Jun 30, 2026
Merged

test(#443): cover oracle timeout fallback path (trigger_randomness_fa…#539
Otaiki1 merged 2 commits into
crackedstudio:masterfrom
ademolacomfort:issue-443-oracle-timeout-fallback-tests

Conversation

@ademolacomfort

Copy link
Copy Markdown
Contributor

Description

Added automated coverage for the oracle-timeout recovery mechanism, which had none. Three tests in the raffle-instance test module exercise both fallback branches and the timeout guard:

  • fallback_with_refund_cancels_raffle: after the timeout elapses, trigger_randomness_fallback(caller, do_refund=true) cancels the raffle, clears the DrawingLock, and lets buyers reclaim funds via refund_ticket.
  • fallback_without_refund_uses_internal_seed: the do_refund=false branch finalizes the raffle via the internal seed, selects a winner, and clears the DrawingLock.
  • fallback_too_early_is_rejected: calling before request_ledger + ORACLE_TIMEOUT_LEDGERS returns Error::FallbackTooEarly.

Fixed an inverted guard in trigger_randomness_fallback that made the path unreachable: it rejected with DrawingAlreadyInProgress whenever DrawingLock was set, but that lock is held for the entire "awaiting oracle" window (set by transition_to_drawing and required as true by the sibling provide_randomness). The guard now requires the lock to be held and returns DrawingAlreadyComplete when it is cleared, matching provide_randomness.

Tests reuse the existing setup_external_drawing_raffle fixture.

Brief summary of what this PR does.

Closes #443

Testing

  • I ran cargo test and all tests pass
  • I added tests for the new behavior
  • I ran cargo fmt --all -- --check
  • I ran cargo clippy --all-targets -- -D warnings

Contract Changes

  • No on-chain ABI changes (storage keys, function signatures, error codes unchanged)
  • ABI changes are documented and backward-compatible
  • If breaking: migration path is described below

Changelog

  • CHANGELOG.md updated under [Unreleased]

Security

  • This change does not introduce new trust assumptions
  • This change does not affect fund custody logic

ademolacomfort and others added 2 commits June 30, 2026 00:42
…randomness_fallback)

Add automated coverage for the oracle-timeout recovery mechanism, which had
none. Three tests in the raffle-instance test module exercise both fallback
branches and the timeout guard:

- fallback_with_refund_cancels_raffle: after the timeout elapses,
  trigger_randomness_fallback(caller, do_refund=true) cancels the raffle,
  clears the DrawingLock, and lets buyers reclaim funds via refund_ticket.
- fallback_without_refund_uses_internal_seed: the do_refund=false branch
  finalizes the raffle via the internal seed, selects a winner, and clears
  the DrawingLock.
- fallback_too_early_is_rejected: calling before request_ledger +
  ORACLE_TIMEOUT_LEDGERS returns Error::FallbackTooEarly.

Fix an inverted guard in trigger_randomness_fallback that made the path
unreachable: it rejected with DrawingAlreadyInProgress whenever DrawingLock
was set, but that lock is held for the entire "awaiting oracle" window (set
by transition_to_drawing and required as true by the sibling
provide_randomness). The guard now requires the lock to be held and returns
DrawingAlreadyComplete when it is cleared, matching provide_randomness.

Tests reuse the existing setup_external_drawing_raffle fixture.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@Otaiki1 Otaiki1 merged commit 3168320 into crackedstudio:master Jun 30, 2026
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.

[TEST] Add test for oracle timeout fallback path (trigger_randomness_fallback)

2 participants