-
Notifications
You must be signed in to change notification settings - Fork 116
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: ponder test #1410
Comments
Thanks @typedarray! I'll share some thoughts, though I'm newish to this domain so pls contextualize accordingly. I think my ideal scenario would look like this in the end for me as a dev:
So that makes the testing flow pretty clean and straightforward. LogBuilder I think would be a provided Ponder utility (or maybe something exists already) to create the properly encoded topics array and data field. The buildLog function converts human-readable inputs and handles all the low-level details of encoding them into the format needed for synthetic log testing. And then I'm sure there's a smart way to integrate the above MyswapTestScenarios with the existing Ponder config to avoid duplication, but directionally the above is what I'd think. |
I was testing ponder indexing on the public API level.
There was not need to mock anything, but I appreciate this setup would not work well if I had to index some third-party contracts that I could not deploy to the local network. |
Problem / use case
It can be useful to write unit tests for indexing functions to confirm their behavior over a specific sequence of events.
It's not always convenient (or possible?) to validate your indexing logic only using
ponder dev
andponder start
. For example: you have a specific sequence of events that appears to cause an indexing error. You can't run only the snippet of history in question, because it relies on older events. Your app is large, so it takes minutes or hours to reproduce the error. This is a bad feedback loop for development.To solve for this, we could introduce a pattern to unit test indexing functions. This way, you could manually construct the sequence of events to rapidly reproduce and fix the error.
Proposed solution
The general flow of a test could be:
This could go in two directions - a native, opinionated
ponder test
command, or some way to run indexing functions "headlessly" like Hono's testing helper. I personally lean towards a native command.IMO, the most obvious choice would be a very thin wrapper over Vitest - we already use Vite internally to execute user code, and we use Vitest for the framework test suite so we're familiar with it.
A basic test could look something like this:
The hardest part will be designing an intuitive API for building or generating the mock event data.
The text was updated successfully, but these errors were encountered: