LimeChain / matchstick

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

multiple newMockEvent(), same reference? #319

Closed OlaStenberg closed 2 years ago

OlaStenberg commented 2 years ago

When I create two mock events with newMockEvent() and change e.g. the block timestamp, it changes on both of them. See screenshots below:

image image image

I expect the auctionEvent.block.timestamp to still be 1 after changing bidEvent.event.timestamp, seems it doesn't matter that I've created two separate mocks, seems to reference to the value

My current workaround is to set the second events timestamp after the first one has been used, but I'd prefer to do all my setup in the beginning of the test

georg-getz commented 2 years ago

Thanks for the bug report. I just released a new matchstick-as version (0.4.2) that fixes this problem.

Note 1: if you just update the package.json file to point to version 0.4.2 of matchstick-as but have no changes in the test file you will need to run the following command the first time: graph test -- -r to force the test wasm binaries to recompile Note 2: I see that you are manually assigning every field from the mock event to the event of the type you need, that can be done more easily using changetype like in here

OlaStenberg commented 2 years ago

Note 2: I see that you are manually assigning every field from the mock event to the event of the type you need, that can be done more easily using changetype like in here

Thanks, yeah I've used that in other subgraphs, but on this one I am working currently I was seeing syntax error, so I just did a quick workaround!

Thanks for the quick fix :-)