Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

test: use --isolate for test #35

Merged
merged 5 commits into from
May 7, 2024
Merged

test: use --isolate for test #35

merged 5 commits into from
May 7, 2024

Conversation

ChefMist
Copy link
Collaborator

@ChefMist ChefMist commented May 6, 2024

This PR migrate forge test to forge test --isolate.

From https://book.getfoundry.sh/reference/cli/forge/test - on what --isolate flag does

      --isolate
          Whether to enable isolation of calls. In isolation mode all top-level calls are executed
          as a separate transaction in a separate EVM context, enabling more precise gas accounting
          and transaction state changes

Context

  1. --isolate will give us more accurate gas estimation as each call will now include a new transaction (21k) gas overhead
  2. As we are using transient storage/ transient load, using --isolate will ensure that we don't use the tstore value in previous call.
  3. It will also allow us to measure gas more accurately and see the benefit of transient storage in <WIP> feat: set reserveOf transient #33 where we no longer update reserveOfVault


// If the test is run with `--isolate` flag, the value should be 0
// as --isolate run each top level call as seperate transaction, so tload will return 0
assertEq(val, 0, "did you forget to use --isolate flag for 'forge test'?");
Copy link
Collaborator

@chefburger chefburger May 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems a bit counter-intuitive to me. Just to confirm, does that mean:

  1. Both storageLib.tstore(1, 2); and uint256 val = storageLib.tload(1); are separate txs
  2. But if there are some external calls inside for example storageLib.tload it will behave like normal function call instead of stacking up another new tx

Copy link
Collaborator Author

@ChefMist ChefMist May 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Both storageLib.tstore(1, 2); and uint256 val = storageLib.tload(1); are separate txs

Yes, they will run as seperate transaction which is why tload(1) will return 0 not 2 if you run test with forge test --isolate

  1. If there are more external calls inside for example storageLib.tload it will behave like normal function call instead of stacking up another new tx

Yes. the seperate transaction is only from top level call.

Do you have a recommendation for the comment on the test or assert error message so it can be clearer? we can update to it

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ehhh, maybe we can mention it in README or FAQ somewhere. That should avoid most unnecessary debugging if someone encounters it 😂

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated readme with details 😁

chefburger
chefburger previously approved these changes May 7, 2024
chefburger
chefburger previously approved these changes May 7, 2024
Copy link
Collaborator

@chefburger chefburger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@ChefMist ChefMist merged commit ee06ebc into main May 7, 2024
2 checks passed
@ChefMist ChefMist deleted the feat/use-isolate-test branch May 7, 2024 07:41
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants