Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(provider): MockProvider #2137

Merged
merged 11 commits into from
Mar 6, 2025
Merged

feat(provider): MockProvider #2137

merged 11 commits into from
Mar 6, 2025

Conversation

yash-atreya
Copy link
Member

Motivation

Closes #1148

Solution

WIP

  • Introduce MockLayer, MockProvider, Asserter.
  • Mocked responses are pushed into the Asserter
  • Asserter queue is FIFO
  • MockProvider pops the Asserter to get the next response and deserializes it into response type.

e.g

let (provider, asserter) = ProviderBuilder::mocked();

asserter.push_success(21965802);
asserter.push_success(21965803);
asserter.push_err(TransportError::NullResp);

let response = provider.get_block_number().await.unwrap();
assert_eq!(response, 21965802);

let response = provider.get_block_number().await.unwrap();
assert_eq!(response, 21965803);

let err_res = provider.get_block_number().await.unwrap_err();
assert!(matches!(err_res, TransportError::NullResp));

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

what's missing here?

@yash-atreya yash-atreya marked this pull request as ready for review March 6, 2025 06:55
@yash-atreya yash-atreya requested a review from mattsse March 6, 2025 07:05
Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

makes sense,

maybe this would also be possible by mocking the transport, but this should cover most usecases

@yash-atreya yash-atreya merged commit 76735d0 into main Mar 6, 2025
27 checks passed
@yash-atreya yash-atreya deleted the yash/mock-provider branch March 6, 2025 07:14
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.

[Feature] Examples of Provider mocking
2 participants