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

DO NOT MERGE! (WIP) feat: add fixtures #11

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gonzalolpetraglia
Copy link
Collaborator

Fixtures

It is a good practice to have tests independent from each other. It is also very common to have multiple things to check in the same scenario, or even to do test doing different things in the same scenario.

If the setup of such an scenario is time-expensive, it is useful to be able to reproduce that scenario without running the setup process every time.

In the Ethereum ecosystem, fixtures serve that specific purpose.

What we expected

Given what we mentioned, we mainly expect from a fixture two things:

  1. After it was executed once, to not be executed again.
  2. Every time it is executed, it should return a result (which would be the equivalent to the scenario we expect) independent from other executions. Meaning that if we somehow modify (use) the returned value of execution N it should NOT modify the result of execution M.

Both of these requirements were put in into tests which are present on this branch.

What we did?

We tried to add fixtures but for the moment being this was not possible, at least in the ways we explored.

Memoizee

We explored using memoizee. We used it to save the result of the setup function and return the result of it, but, as expected, this does not work as it returns the reference of the previously returned results. Breaking test No 2.

Deep copy

We also explored using clone (or other similar ones, such as deepclone from lodash). This is the what is currently implemented in this branch, but this fails because of private members inside some of the classes used by this ecosystem.

Waffle way

Waffle uses a primitive of ganache/hardhat node which allows it to save a blockchain's state (evm_snapshot) and restore it later (evm_revert).

The code to implement fixtures having those primitives is very straight forward and can be seen at: https://github.com/TrueFiEng/Waffle/blob/0915e7274093f2a1fb1b2a8be0521470a9f8c2f4/waffle-provider/src/fixtures.ts .

Mina's local chain currently does not have those primitives.

@gonzalolpetraglia gonzalolpetraglia changed the title (WIP) feat: add fixtures DO NOT MERGE! (WIP) feat: add fixtures Oct 5, 2023
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.

1 participant