-
Notifications
You must be signed in to change notification settings - Fork 12
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: add isolate mode JS integration test #652
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand that the test contract is a copy of an existing solidity test, but I think we can do something much simpler, if we only care about testing that isolate mode is enabled:
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'?");
}
}
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;
}
}
(copied from https://github.com/pancakeswap/pancake-v4-core/blob/857b4bf8055e74465900b5c15997fa100ee3044a/test/Isolate.t.sol)
I'd rather use this simpler version because it's easier to understand what is testing and why it works.
readonly artifacts: Artifact[]; | ||
readonly testSuiteIds: ArtifactId[]; | ||
|
||
constructor(artifacts: Artifact[], testSuiteIds: ArtifactId[]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normally a static async constructor means a private constructor, unless you want to allow creating instances directly too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks fixed in 4f96f26
@fvictorio thanks fixed here: Simplify isolate mode test and add inverse test |
17413be
to
d8b5ead
Compare
2551244
to
06f314a
Compare
import "./test.sol"; | ||
import "./Vm.sol"; | ||
|
||
contract IsolateModeTest is DSTest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a mention here that this was taken from the Pancakeswap repo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor comment, feel free to merge after fixing that.
There is a Rust Solidity test runner integration test that tests that the isolate flag works by checking the gas report. I copied the same test i to the JS integration test to make sure that the enabling isolate mode works from JS as well.
I've also abstracted out the JS Solidity test runner integration test context to be able to be used from multiple test source files.