LimeChain / matchstick

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

Is there a way to delete the data sources from a test to the other? #426

Open clauBv23 opened 4 months ago

clauBv23 commented 4 months ago

Hi there:

I'm trying to test some logic that involves the creation of new templates. But when checking the created templates from one test to the other they are not being initialized and continue existing. For cleaning the store exists the clearStore I was wondering if there is a similar function for creating the data source.

I mean, let's say I have something like this:

describe('handle....', () => {
  afterAll(() => {
    clearStore();
      });

  test('it should work on way 1 ', () => {
        ... some code here 
        assert.dataSourceCount('NewTemplate', 1);   // want to check the template was created 
        ... other checks
   });

   test('it should work on way 2 ', () => {
        ... some code here 
        assert.dataSourceCount('NewTemplate', 1);     // want to check the template was created but at this point, the template from 
        ... other checks                             //     the previous test will exist so there will be 2 templates instead of 1
   });
});

I would like to be able to clean the data sources to test their existence properly, having a function like clearStore to clear the data sources clearDataSources will help.

Thanks

kaihiroi commented 10 hours ago

Hello! I'm not sure if this will be helpful, but I've encountered a similar issue. In the end, I found that using dataSourceMock for testing worked well for me. https://thegraph.com/docs/en/developing/unit-testing-framework/#testing-dynamic-data-sources