DO NOT MERGE! (WIP) feat: add fixtures #11
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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.