-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
feat(forge
): simulating multiple transactions in a single test with a dependency tree
#8485
Comments
As a concrete example: Suppose I'm testing a wallet that, within the same transaction, is created at a specific address, performs some tasks, and then selfdestructs. How do I check that after the transaction, the code is indeed gone? |
Thanks for considering an extension. Yes, this looks like the same issue. But actually, my desires would go even further. Suppose we want to demonstrate that the order of transactions has/does not have an effect. Then I would like to run a test in forge, remember the results, run another test (same initial setup, but different (trans)actions), and then compare the results of the two tests. So the idea would be to have not only a single sequence of transactions within a test (like we are just discussing), but several of them in parallel from the same initial conditions. Is this something that forge possibly can do, or is this totally against the basic concept of forge? |
what I was thinking at was to have capability of inline configuring a test like /// forge-config: default.unit.prereqs=create_contract,selfdestroy_contract`
function testSelfdestroy() public where |
forge
): simulating multiple transactions in a single test with a dependency tree
Looks great, seems to solve my original problem! Do you see a possibility to use forge for a test that compares the results of several sequences of transactions that are executed from the same initial conditions, e.g., to demonstrate that there is a transaction order dependence? As I understand it, your extension would allow us to execute a sequence of transactions within a single test, which improves the current situation with at most two transactions (the setup and the test). |
hm, you mean like instead |
My current use case is to demonstrate existential properties (mostly known failures: There is a sequence of calls that leads to some problematic behavior). One case that doesn't work well with forge at the moment is the demonstration that there is a transaction order dependence, since this would require
setup -> shuffle[tx1, tx2,.. ] -> test |
I think we could have a strategy to test all permutations, let's have basic support in and we can expand after. |
@grandizzy Thanks for adding |
Do you have any ideas how one could have a test comparing the results of two tests? Say, run several transactions in one order and also in a another, different one, and then assert that the two states differ (thus demonstrating a transaction order dependence)? |
hey @gsalzer maybe you could use |
Hey @grandizzy Do you know how could I run thousands of tokens transfers on a single test, and that each transfer would be treated as an individual tx?
|
@stalinMacias did you try isolation mode?
This or beforeTestSetup should work I think |
@grandizzy Thanks for the super quick answer. I've just tried but the out of gas error still shows up.
Any other idea that comes up to your mind? |
hm, maybe bump the gas limit Or split the 2 for loops in multiple loops and calls / txes and configure them in beforeTestSetup |
Component
Forge
Describe the feature you would like
With
forge
, is it possible to simulate multiple transactions (in a single block or in multiple ones) within a single test? If not, are there plans to extendforge
into this direction?Currently, the answer to the first question seems to be yes and no. Yes, because we can set the block number, the sender, tx.origin etc to multiple values within a test. No, because not all aspects of a transaction are simulated faithfully. As an example, the code of a contract that has self-destructed is not removed, even if we increase the block number (in the hope to start a new transaction with the new block). Confusingly, the code is removed if the contract already selfdestructs in
function setUp()
.Can we assume that each test is a separate transaction? If yes, is there a way of running tests in a fixed order, without resetting the environment in between? Would this be a way to simulate a sequence of transactions? How precise is this simulation?
Additional context
No response
The text was updated successfully, but these errors were encountered: