Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

test: use --isolate for test #35

Merged
merged 5 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .forge-snapshots/BinHookTest#testBurnSucceedsWithHook.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
143699
181691
Original file line number Diff line number Diff line change
@@ -1 +1 @@
135043
185995
Original file line number Diff line number Diff line change
@@ -1 +1 @@
108914
137174
2 changes: 1 addition & 1 deletion .forge-snapshots/BinHookTest#testMintSucceedsWithHook.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
301091
330199
2 changes: 1 addition & 1 deletion .forge-snapshots/BinHookTest#testSwapSucceedsWithHook.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
139136
192828
Original file line number Diff line number Diff line change
@@ -1 +1 @@
90479
146325
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5062
32866
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9179
30395
Original file line number Diff line number Diff line change
@@ -1 +1 @@
65672
158380
Original file line number Diff line number Diff line change
@@ -1 +1 @@
149227
303978
2 changes: 1 addition & 1 deletion .forge-snapshots/BinPoolManagerTest#testGasBurnOneBin.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
66851
139534
2 changes: 1 addition & 1 deletion .forge-snapshots/BinPoolManagerTest#testGasDonate.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
52444
125312
Original file line number Diff line number Diff line change
@@ -1 +1 @@
968444
1013228
Original file line number Diff line number Diff line change
@@ -1 +1 @@
119958
341242
Original file line number Diff line number Diff line change
@@ -1 +1 @@
337634
380578
Original file line number Diff line number Diff line change
@@ -1 +1 @@
54695
149339
Original file line number Diff line number Diff line change
@@ -1 +1 @@
89312
187600
Original file line number Diff line number Diff line change
@@ -1 +1 @@
91297
193585
Original file line number Diff line number Diff line change
@@ -1 +1 @@
70741
145829
Original file line number Diff line number Diff line change
@@ -1 +1 @@
319341
349945
2 changes: 1 addition & 1 deletion .forge-snapshots/BinPoolManagerTest#testNoOpGas_Burn.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
41503
76799
Original file line number Diff line number Diff line change
@@ -1 +1 @@
19392
54412
Original file line number Diff line number Diff line change
@@ -1 +1 @@
37117
64865
2 changes: 1 addition & 1 deletion .forge-snapshots/BinPoolManagerTest#testNoOpGas_Mint.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
39136
69792
2 changes: 1 addition & 1 deletion .forge-snapshots/BinPoolManagerTest#testNoOpGas_Swap.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
22507
57711
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8148
42036
Original file line number Diff line number Diff line change
@@ -1 +1 @@
348848
401304
Original file line number Diff line number Diff line change
@@ -1 +1 @@
59396
182292
Original file line number Diff line number Diff line change
@@ -1 +1 @@
242441
269977
2 changes: 1 addition & 1 deletion .forge-snapshots/CLPoolManagerTest#donateBothTokens.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
82514
175650
2 changes: 1 addition & 1 deletion .forge-snapshots/CLPoolManagerTest#gasDonateOneToken.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
52476
117100
Original file line number Diff line number Diff line change
@@ -1 +1 @@
36547
59579
Original file line number Diff line number Diff line change
@@ -1 +1 @@
42374
129146
Original file line number Diff line number Diff line change
@@ -1 +1 @@
54672
149040
Original file line number Diff line number Diff line change
@@ -1 +1 @@
100748
177536
Original file line number Diff line number Diff line change
@@ -1 +1 @@
25040458
25138122
2 changes: 1 addition & 1 deletion .forge-snapshots/CLPoolManagerTest#swap_simple.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
35872
79216
Original file line number Diff line number Diff line change
@@ -1 +1 @@
101510
158626
2 changes: 1 addition & 1 deletion .forge-snapshots/CLPoolManagerTest#swap_withHooks.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
41522
95654
2 changes: 1 addition & 1 deletion .forge-snapshots/CLPoolManagerTest#swap_withNative.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
35875
79219
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4835
32627
Original file line number Diff line number Diff line change
@@ -1 +1 @@
19218
54130
Original file line number Diff line number Diff line change
@@ -1 +1 @@
37497
65293
Original file line number Diff line number Diff line change
@@ -1 +1 @@
29405
59921
2 changes: 1 addition & 1 deletion .forge-snapshots/CLPoolManagerTest#testNoOp_gas_Swap.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
21667
57143
2 changes: 1 addition & 1 deletion .forge-snapshots/VaultTest#collectFee.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
25576
53332
Original file line number Diff line number Diff line change
@@ -1 +1 @@
120730
159214
2 changes: 1 addition & 1 deletion .forge-snapshots/VaultTest#lockSettledWhenFlashloan.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
156938
103410
Original file line number Diff line number Diff line change
@@ -1 +1 @@
45186
118170
2 changes: 1 addition & 1 deletion .forge-snapshots/VaultTest#lockSettledWhenSwap.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
45185
118169
2 changes: 1 addition & 1 deletion .forge-snapshots/VaultTest#registerPoolManager.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
24484
47916
2 changes: 1 addition & 1 deletion .forge-snapshots/VaultTest#testLock_NoOp.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
11327
32799
Original file line number Diff line number Diff line change
@@ -1 +1 @@
71681
99905
Original file line number Diff line number Diff line change
@@ -1 +1 @@
33288
55012
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ jobs:
version: nightly

- name: Run tests
run: forge test -vvv
run: forge test --isolate -vvv
env:
FOUNDRY_PROFILE: ${{ github.ref_name == 'main' && 'ci_main' || 'ci' }}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
},
"scripts": {
"compile": "forge compile",
"test": "forge test",
"dev": "forge test -vvv -w",
"snapshot": "rm -fr .forge-snapshots && forge test",
"test": "forge test --isolate",
"dev": "forge test --isolate -vvv -w",
"snapshot": "rm -fr .forge-snapshots && forge test --isolate",
"prettier": "forge fmt src/ && forge fmt test/",
"prettier-check": "forge fmt --check",
"prepare": "husky install"
Expand Down
40 changes: 40 additions & 0 deletions test/Isolate.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.24;

import "forge-std/Test.sol";

/// @dev A test contract to ensure developers are using `--isolate` flag when running forge test
contract IsolateTest is Test {
StorageLib storageLib;

function setUp() public {
storageLib = new StorageLib();
}

function testIsolateTest() public {
// tstore key: 1 with value :2
storageLib.tstore(1, 2);

// toload key: 1
uint256 val = storageLib.tload(1);

// 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 😁

}
}

contract StorageLib {
function tstore(uint256 key, uint256 val) public {
assembly {
tstore(key, val)
}
}

function tload(uint256 key) public view returns (uint256 val) {
assembly {
val := tload(key)
}
return val;
}
}
Loading