Repository navigation
feat(resolution): validate MarketsContract address at init and on eac… - #505
Merged
dultimateade merged 2 commits intoNov 24, 2026
Conversation
…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.
|
@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! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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):
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.