-
Notifications
You must be signed in to change notification settings - Fork 48
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
Use given
in __setup__
function
#1149
Comments
Hey @Pet3ris! We deliberately disabled usage of But we are open for discussion if you believe our line of thought is not correct 😉 But, the use case you described (having a long initialization step involving contract deployments etc. for several fuzzing test cases) is totally valid, and what's more: it's doable with current Protostar's feature set. Nothing prevents you from using both Example: @external
func __setup__() {
%{
context.contract = deploy(...)
context.parameter = 0xdeedbeef
%}
return;
}
@external
func setup_foo() {
%{ given(x = strategy.integers(min_value=context.parameter)) %}
return;
}
@external
func test_foo(x: felt) {
...
}
@external
func setup_bar() {
%{ given(y = strategy.integers(max_value=context.parameter)) %}
return;
}
@external
func test_bar(y: felt) {
...
} I am closing this issue as for now, because I hope this response solves your problem. Feel free to continue discussion if you have any questions or objections! 😃 |
@mkaput I completely emphatize with the approach you've taken :). My main challenge is that the code I need to run with fuzzing inputs is sufficiently computationally complex that I don't want to repeat it for every test case (I need to kick off transactions). Actually this feature helps improve performance rather than decrease it, let me explain it a little better.
In fact, I think this pattern encourages users to use fuzzing more carefully, sharing computation as much as possible. Alternatively, can I define a custom |
What prevents you from kicking off transactions in FYI Mind that |
I need to fire off transactions based on the variables in |
To give more context, this is what I'm trying to do: https://github.com/a16z/erc4626-tests/blob/main/ERC4626.test.sol. Note, in Foundry, one can re-use the same fuzzing inputs but cannot do computations after them (hence |
Oh, now I understand what's going on. Unfortunately, this idea is quite contradictory to the way how Protostar's test runner works under the hood (fuzzer is spun for each As a workaround, I wonder if it wouldn't work for you if you stick with a single test case and eventually chop it into multiple subroutines. Yes, I know this is suboptimal, because you have single test, which runs sequentially and failure in one subroutine stops executing others, but it should still be helpful in successful case. |
Thanks @mkaput - yeah I'll consider that, no worries. Completely understand the limitation. |
As a StarkNet smart contract developer, I want to use
given
in the__setup__
function to run a suite of tests on a contract that's been initiated by fuzzed parameters.In particular, I need to initiate random contract state using fuzzing, however, this initialization is by far the most expensive action in my contract suite. I would like to ideally run it in advance of tests rather than run it separately for each test where I need to use fuzzing.
Is there a way to hack this or do I have to just rely on individual setup functions to use fuzzing?
The text was updated successfully, but these errors were encountered: