Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

feat: impl PubsubClient for MockProvider #2538

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

dereksione
Copy link

@dereksione dereksione commented Aug 7, 2023

Motivation

The current implementation of mock provider doesn't support any of the eth JSON RPC endpoints that establish subscriptions. Supporting this would allow for unit tests and smoke tests for implementations that depend on these features.

Solution

This implementation extends the idea of the mock provider being a sink of pre-rendered responses piped in before beginning the testing process. There is a simple public facing function setup_subscription that takes all the previously pushed responses and converts them into a stream that can be subscribed to using any of the eth JSONRPC requests that create such subscriptions.

Internally, the implementation is a little convoluted because the PubsubClient takes an immutable reference to self. The requirements of the task is that we need the mutable sender of a stream that we can push things to. The solution implemented here uses an intermediary stream that is initialized before the subscribe function is called, and it forwards all of its data to the stream that is returned by the subscribe function in the PubsubClient trait.

PR Checklist

  • Added Tests
  • Added easy to use public facing API
  • Add documentation

@dereksione dereksione force-pushed the mock-provider-pubsub-impl branch from a1fba9e to b13b5a1 Compare August 7, 2023 07:57
ethers-providers/src/rpc/provider.rs Outdated Show resolved Hide resolved
ethers-providers/src/rpc/transports/mock.rs Show resolved Hide resolved
Copy link
Collaborator

@DaniPopes DaniPopes left a comment

Choose a reason for hiding this comment

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

Also needs a rebase and clippy fix.

@dereksione dereksione force-pushed the mock-provider-pubsub-impl branch from d17c8ba to ad05fc2 Compare August 18, 2023 09:42
@dereksione dereksione force-pushed the mock-provider-pubsub-impl branch from ad05fc2 to 6512c99 Compare August 18, 2023 09:44
@dereksione dereksione requested a review from DaniPopes August 18, 2023 10:10
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants