foundry-rs / foundry-toolchain

GitHub action to install Foundry
Apache License 2.0
225 stars 92 forks source link

Cache RPC responses #19

Closed PaulRBerg closed 1 year ago

PaulRBerg commented 1 year ago

As discussed here and here, this PR upstreams my RPC caching method in foundry-toolchain itself.

I explained how the caching works in the README, but I will paste it here as well:

This action matches Forge's behavior and caches all RPC responses in the ~/.foundry/cache/rpc directory. This is done to speed up the tests and avoid hitting the rate limit of your RPC provider.

The logic of the caching is as follows:

  • Always load the latest valid cache, and always create a new one with the updated cache.
  • When there are no changes to the fork tests, the cache does not change but the key does, since the key is > based on the commit hash.
  • When the fork tests are changed, both the cache and the key are updated.

Side note: this PR also installs Prettier and adds a basic config file.

I tested this in my private repo that has fork tests, and both restoring the cache and saving it worked as expected:

restore-cache save-cache

Feel free to test in your repos, too:

- name: "Install Foundry"
  uses: "paulrberg/foundry-toolchain@caching"