Phase 3: Multi-Stage Oracle Resolution Integration Tests¶
Overview¶
This document describes the comprehensive integration testing implementation for the Multi-Stage Oracle Resolution system. These tests validate the complete oracle resolution workflow, including initial report submission, challenge periods, dispute resolution, and final settlement.
Implementation Summary¶
Test Suite Location¶
- Main Test File:
test/integration/oracle/multi-stage-resolution.test.js - Helper Functions:
test/integration/helpers/index.js - Deployment Fixture:
test/integration/fixtures/deploySystem.js
Test Coverage (14 Tests)¶
1. Happy Path: Unchallenged Resolution¶
Tests the standard workflow when no challenges are submitted: - Designated reporter submits initial report with bond - Challenge period expires without challenges - Owner finalizes resolution with reporter's values - Reporter bond is returned
2. Challenge Workflow: Successful Challenge¶
Tests the challenge mechanism and bond redistribution: - Reporter submits initial report - Challenger contests the report within challenge period - Owner accepts challenge and finalizes with challenger's values - Both bonds (reporter + challenger) are awarded to challenger
3. Challenge Rejection: Late Challenge¶
Tests challenge period enforcement: - Reporter submits initial report - Challenge period expires - Late challenge attempt is rejected
4. Dispute Escalation Workflow¶
Tests the UMA dispute escalation mechanism: - Reporter submits initial report - Challenger contests the report - Owner escalates to UMA dispute - Dispute is resolved and finalized
5. Bond Management and Access Control¶
Tests bond validation and access restrictions: - Incorrect bond amounts are rejected - Only designated reporters can submit reports - Only owner can finalize resolutions - Only owner can escalate to UMA
6. Multiple Resolutions in Parallel¶
Tests handling of multiple concurrent proposals: - Multiple proposals at different stages (reported, challenged, disputed) - Independent state management for each proposal - Correct finalization of each proposal
7. Edge Cases and Error Conditions¶
Tests error handling and validation: - Double reporting prevention - Double finalization prevention - Empty evidence handling (validation is off-chain)
8. Query Functions and State Verification¶
Tests the query interface and state transitions: - Resolution details at each stage (Unreported, DesignatedReporting, OpenChallenge, Dispute, Finalized) - Report and challenge information retrieval - State transition validation
Resolution Stages¶
The OracleResolver implements a multi-stage workflow:
- Unreported (0): Initial state, no report submitted
- DesignatedReporting (1): Report submitted, within challenge period
- OpenChallenge (2): Report has been challenged
- Dispute (3): Escalated to UMA dispute resolution
- Finalized (4): Resolution complete, values finalized
Helper Functions¶
Oracle-Specific Helpers¶
// Complete unchallenged resolution workflow
await completeOracleResolution(oracleResolver, accounts, proposalId, passValue, failValue, evidence);
// Submit initial oracle report
await submitOracleReport(oracleResolver, reporter, proposalId, passValue, failValue, evidence);
// Challenge an existing report
await challengeOracleReport(oracleResolver, challenger, proposalId, counterPassValue, counterFailValue, counterEvidence);
// Complete resolution with challenge workflow
const resolution = await completeOracleResolutionWithChallenge(
oracleResolver,
accounts,
proposalId,
{ passValue: 1000, failValue: 500, evidence: "Initial evidence" },
{ passValue: 800, failValue: 600, evidence: "Counter evidence" }
);
Running the Tests¶
# Run oracle integration tests only
npm run test:integration:oracle
# Run all integration tests
npm run test:integration
# Run with gas reporting
REPORT_GAS=true npm run test:integration:oracle
# Run specific test file
npx hardhat test test/integration/oracle/multi-stage-resolution.test.js
Test Results¶
All 14 integration tests pass successfully:
✓ Should complete oracle resolution without challenge
✓ Should handle challenge and award bonds to challenger
✓ Should reject challenge after challenge period expires
✓ Should escalate to UMA dispute resolution
✓ Should reject escalation if not in challenge stage
✓ Should require correct bond amounts
✓ Should enforce designated reporter access
✓ Should enforce owner-only finalization
✓ Should handle multiple proposals at different stages
✓ Should prevent double reporting
✓ Should prevent double finalization
✓ Should accept empty evidence (evidence validation is off-chain)
✓ Should return correct resolution details at each stage
✓ Should return detailed report and challenge information
14 passing (706ms)
Bond Amounts¶
- Reporter Bond: 100 ETH (
REPORTER_BOND) - Challenger Bond: 150 ETH (
CHALLENGER_BOND) - Challenge Period: 2 days (
CHALLENGE_PERIOD) - Settlement Window: 3 days (
SETTLEMENT_WINDOW)
Integration with System¶
The OracleResolver integrates with other system components:
- ProposalRegistry: Proposals are tracked and linked to oracle resolutions
- FutarchyGovernor: Proposal execution depends on oracle resolution outcomes
- ConditionalMarketFactory: Market settlement uses oracle resolution values
Security Considerations¶
✅ CodeQL Scan: No security vulnerabilities found ✅ Access Control: Designated reporter and owner-only functions properly enforced ✅ Reentrancy Protection: ReentrancyGuard modifier applied to sensitive functions ✅ Bond Management: Secure bond handling with validation and proper return mechanisms
Evidence Handling¶
Evidence is stored as bytes in the contract:
- Evidence can be IPFS hashes, URLs, or any encoded data
- On-chain validation is minimal (just storage)
- Real validation happens off-chain by governance participants
- Empty evidence is accepted (edge case test validates this)
Future Enhancements¶
Potential improvements for future phases:
- UMA Integration: Full integration with UMA's Optimistic Oracle V3
- Automated Finalization: Trustless finalization after challenge period
- Multi-Token Bonds: Support for bonds in different tokens
- Slashing Mechanism: More sophisticated slashing for malicious reporters
- Appeal Process: Additional dispute rounds beyond UMA
Related Documentation¶
- Integration Test README
- OracleResolver Contract
- OracleResolver Unit Tests
- Architecture Documentation
Changes Made¶
Modified Files¶
- test/integration/oracle/multi-stage-resolution.test.js (NEW)
- 14 comprehensive integration tests
- Tests all resolution stages and workflows
-
Edge case coverage
-
test/integration/helpers/index.js
- Updated
completeOracleResolution()to match new signature - Added
submitOracleReport()helper - Added
challengeOracleReport()helper -
Added
completeOracleResolutionWithChallenge()helper -
test/integration/fixtures/deploySystem.js
- Added reporter as designated reporter before ownership transfer
-
Modified ownership transfer to keep OracleResolver under owner control for testing
-
test/integration/README.md
- Documented oracle integration tests
- Updated coverage goals
-
Added oracle-specific helper documentation
-
package.json
- Added
test:integration:oraclenpm script
Conclusion¶
The Phase 3 integration tests provide comprehensive coverage of the Multi-Stage Oracle Resolution system, ensuring that:
- All resolution stages work correctly
- Bond management is secure and accurate
- Access control is properly enforced
- Edge cases are handled appropriately
- Multiple proposals can be processed in parallel
- Query functions provide accurate state information
All tests pass successfully, and no security vulnerabilities were found during the CodeQL scan.