LimeChain / matchstick

🔥 Unit testing framework for Subgraph development on The Graph protocol. ⚙️
MIT License
207 stars 17 forks source link

Implement loadInBlock #400

Closed dimitrovmaksim closed 12 months ago

dimitrovmaksim commented 12 months ago

loadInBlock

Description:

loadInBlock tries to load an entity from some kind of a cache that persists for the time a specific block is being indexed. The entity will be present in the cache only if it was created or updated in that block.

For example event A occurs in block 123, in our handler we create an entity B with ID the address (0x0...1) of the emitter contract C. Later in that block another event A is emitted by contract C. If we try to load the entity using B.loadInBlock("0x0...1") we should get the entity we have created during the first occurrence of the event A.

But if in block 124, contract C has once again emitted event A and we try to load the entity using B.loadInBlock("0x0...1"), the function will return null because the entity is no more in the cache and instead we should try to load it from the database.

Matchstick implementation:

My proposed solution would be to:

  1. Have the default loadInBlock behaviour to return null
  2. Add a mock cashe store
  3. Add a function that mocks the entity in the cache store with user defined
  4. Add a function to remove/clean the cache store