Skip to content

Conversation

devin-ai-integration[bot]
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot commented Oct 10, 2025

Summary

Adds MockEntropy contract implementing the IEntropyV2 interface to enable local testing of entropy-dependent contracts. The mock supports a two-phase request/reveal pattern where developers can control the timing and values of random number callbacks.

Rationale

Developers need a way to test entropy-based contracts locally without depending on actual entropy providers. The key requirement was enabling testing of different interleavings - developers can request multiple random numbers and then reveal them in any order with custom values.

Two-phase testing pattern:

  1. requestV2() → returns sequence number, stores request
  2. mockReveal(provider, sequenceNumber, customRandomBytes) → triggers callback with developer-specified random value

This allows testing scenarios like request A, request B, reveal B first, then reveal A with different random values.

Key Implementation Details

  • Provider Management: Supports multiple providers with independent sequence tracking
  • Fee Structure: feeInWei initialized to 1 in provider info, but getFeeV2() methods return 0 for testing simplicity
  • Callback Safety: Uses assembly to check contract code size before invoking _entropyCallback
  • Event Emission: Emits Requested and Revealed events consistent with real Entropy contract

How has this been tested?

  • Added comprehensive test suite with 8 test cases
  • Tests cover basic request/reveal, different interleavings, multiple providers, custom random numbers
  • All Foundry tests pass
  • Pre-commit hooks (formatting, linting) pass

Test scenarios include:

  • Basic request → reveal → callback flow
  • Multiple requests with out-of-order reveals (interleaving)
  • Multiple providers with independent sequences
  • Custom random number values (0, max uint256, hash values)
  • Gas limit handling and provider info queries

Human Review Checklist

  • Interface Completeness: Verify all IEntropyV2 methods are properly implemented
  • Callback Mechanism: Review assembly code size check and callback invocation for edge cases
  • Fee Inconsistency: Confirm intentional difference between feeInWei = 1 and getFeeV2() = 0
  • State Management: Check provider info and request tracking across multiple providers
  • Test Coverage: Ensure test cases adequately cover potential edge cases and failure modes

Link to Devin run: https://app.devin.ai/sessions/0d7e089bd7eb4ef5bd60d3baff368b69
Requested by: Jayant ([email protected])

Package version bumped: @pythnetwork/entropy-sdk-solidity from 2.0.0 → 2.1.0

- Implements IEntropyV2 interface with two-step request/reveal pattern
- requestV2() stores request and returns sequence number
- mockReveal() allows manual callback triggering with custom random numbers
- Enables testing different interleavings of requests and reveals
- Includes comprehensive test suite demonstrating usage patterns
- Simplifies testing by removing fee requirements and commitment validation

Co-Authored-By: Jayant <[email protected]>
Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Copy link

vercel bot commented Oct 10, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
api-reference Ready Ready Preview Comment Oct 10, 2025 2:33pm
component-library Ready Ready Preview Comment Oct 10, 2025 2:33pm
developer-hub Ready Ready Preview Comment Oct 10, 2025 2:33pm
4 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
entropy-explorer Skipped Skipped Oct 10, 2025 2:33pm
insights Skipped Skipped Oct 10, 2025 2:33pm
proposals Skipped Skipped Oct 10, 2025 2:33pm
staking Skipped Skipped Oct 10, 2025 2:33pm

defaultProvider = _defaultProvider;

providers[_defaultProvider].sequenceNumber = 1;
providers[_defaultProvider].feeInWei = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please initialize this to 1

- Set feeInWei to 1 in MockEntropy constructor and _requestV2
- Update package.json version from 2.0.0 to 2.1.0
- Update test assertion to expect feeInWei = 1

Co-Authored-By: Jayant <[email protected]>
@tejasbadadare tejasbadadare merged commit 9e519a9 into main Oct 10, 2025
11 checks passed
@tejasbadadare tejasbadadare deleted the devin/1760065850-mock-entropy-contract branch October 10, 2025 21:00
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.

2 participants