Skip to content

feat(resolution): validate MarketsContract address at init and on eac… - #505

Merged
dultimateade merged 2 commits into
dultimateade:mainfrom
swantaafuwai-hub:feat/resolution-markets-contract-validation
Nov 24, 2026
Merged

dultimateade merged 2 commits into
dultimateade:mainfrom
swantaafuwai-hub:feat/resolution-markets-contract-validation

Conversation

@swantaafuwai-hub

Copy link
Copy Markdown
Contributor

closes #449
closes #450
closes #451
closes #452

…h resolve

The resolution contract now rejects a misconfigured markets_contract address at initialization rather than deferring the failure to the first cross-contract call, where the error would surface as an opaque host trap.

Changes

  • errors.rs — add two new stable error variants: MarketsContractInvalid = 12 Thrown when env.try_invoke_contract on the markets address fails (missing entrypoint, wrong type, host panic). Covers both init-time and per-resolve re-validation failures. MarketsVersionMismatch = 13 Thrown when the live version() return value no longer matches the value that was recorded at initialization, indicating a contract substitution or unexpected upgrade.

  • lib.rs — implement the full contract (was a one-entrypoint stub):

    • DataKey enum: Initialized, Admin, MarketsContract, ExpectedMarketsVersion (all instance storage).
    • call_markets_version() private helper: calls version() cross-contract via env.try_invoke_contract; maps any failure to MarketsContractInvalid.
    • initialize(admin, markets_contract): requires admin auth, guards double-init, probes version() on markets_contract, stores the address and the returned version as ExpectedMarketsVersion.
    • resolve(admin, market_id, outcome): requires admin auth, re-probes version() on the stored address before every state update; returns MarketsVersionMismatch if the live version differs from the stored one.
    • Read-only views: version() (unchanged, returns 7), markets_contract(), expected_markets_version().
  • tests/error_tests.rs — extend discriminant-stability, ordering, and uniqueness assertions to cover the two new variants (12, 13).

  • tests/init_validation_tests.rs — new integration test file (9 tests) using in-file stub contracts to cover: happy-path init, invalid address rejection, double-init, resolve-before-init, non-admin resolve, version re-validation pass, version mismatch (address patched via as_contract), None views before init, and version() availability without init.

  • Cargo.toml — register the new [[test]] target.

…h resolve

The resolution contract now rejects a misconfigured markets_contract
address at initialization rather than deferring the failure to the first
cross-contract call, where the error would surface as an opaque host trap.

Changes
-------
* errors.rs — add two new stable error variants:
    MarketsContractInvalid = 12
      Thrown when env.try_invoke_contract on the markets address fails
      (missing entrypoint, wrong type, host panic). Covers both init-time
      and per-resolve re-validation failures.
    MarketsVersionMismatch = 13
      Thrown when the live version() return value no longer matches the
      value that was recorded at initialization, indicating a contract
      substitution or unexpected upgrade.

* lib.rs — implement the full contract (was a one-entrypoint stub):
  - DataKey enum: Initialized, Admin, MarketsContract,
    ExpectedMarketsVersion (all instance storage).
  - call_markets_version() private helper: calls version() cross-contract
    via env.try_invoke_contract; maps any failure to MarketsContractInvalid.
  - initialize(admin, markets_contract): requires admin auth, guards
    double-init, probes version() on markets_contract, stores the address
    and the returned version as ExpectedMarketsVersion.
  - resolve(admin, market_id, outcome): requires admin auth, re-probes
    version() on the stored address before every state update; returns
    MarketsVersionMismatch if the live version differs from the stored one.
  - Read-only views: version() (unchanged, returns 7), markets_contract(),
    expected_markets_version().

* tests/error_tests.rs — extend discriminant-stability, ordering, and
  uniqueness assertions to cover the two new variants (12, 13).

* tests/init_validation_tests.rs — new integration test file (9 tests)
  using in-file stub contracts to cover: happy-path init, invalid address
  rejection, double-init, resolve-before-init, non-admin resolve, version
  re-validation pass, version mismatch (address patched via as_contract),
  None views before init, and version() availability without init.

* Cargo.toml — register the new [[test]] target.
@drips-wave

drips-wave Bot commented Nov 24, 2026

Copy link
Copy Markdown

@swantaafuwai-hub 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

@dultimateade
dultimateade merged commit 21c650d into dultimateade:main Nov 24, 2026
0 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment