smartcontractkit / functions-hardhat-starter-kit

MIT License
144 stars 103 forks source link

Issue with Integrating localFunctionsTestnet and Hardhat's loadFixture Utility #196

Open tomasp1189 opened 9 months ago

tomasp1189 commented 9 months ago

Description: Hello, and thank you for providing this excellent boilerplate for working with Chainlink Functions.

I am currently developing a Smart Contract and utilizing your provided localFunctionsTestnet for testing. However, I've encountered an issue related to testing environments. Specifically, the need to manually run localFunctionsTestnet prevents me from taking full advantage of Hardhat's loadFixture utility, which is instrumental for snapshotting test states.

Problem: The localFunctionsTestnet, as part of the functions-toolkit, uses Ganache under the hood. This setup conflicts with Hardhat's default behavior, particularly with the loadFixture utility, which relies on Hardhat's in-memory network for snapshotting and reverting state between tests. The result is an inability to efficiently manage test state, leading to more complex and time-consuming test setups.

Expected Behavior: Ideally, I would like to seamlessly integrate the localFunctionsTestnet with Hardhat's testing environment, enabling me to use loadFixture for efficient test state management. This integration would greatly enhance the development workflow and testing efficiency.

Steps to Reproduce:

  1. Set up a Smart Contract project using the Chainlink Functions boilerplate.
  2. Implement unit tests using Hardhat's testing framework.
  3. Attempt to use Hardhat's loadFixture utility while localFunctionsTestnet is running.

Possible Solutions: I'm unsure of the best way to resolve this issue but have considered a few options:

  1. Adapting localFunctionsTestnet for Compatibility: Modify localFunctionsTestnet to work seamlessly with Hardhat's in-memory network, allowing us to use loadFixture effectively.
  2. Guidance on Managing Test States: Provide instructions or best practices for handling test states when using localFunctionsTestnet alongside Hardhat.
  3. Script to Replicate localFunctionsTestnet Setup in Hardhat: Develop a script to configure Hardhat's test environment similar to localFunctionsTestnet, ensuring consistency across testing platforms.

Thank you for your attention to this issue. Any guidance or updates to improve this integration would be greatly appreciated!

luislucena16 commented 5 months ago

hey @tomasp1189 could you attach a snapshot of the code you are using? as well as the specs to run it, it would be much easier/quicker to help you!