-
Notifications
You must be signed in to change notification settings - Fork 51
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
add env addresses to address strategy. Resolves #208 #222
add env addresses to address strategy. Resolves #208 #222
Conversation
…v. Using all the env addresses in address strategy
boa/test/strategies.py
Outdated
|
||
# TODO: add addresses generated by the env through the env.generate_address() method | ||
env_accounts = ( | ||
{obj.address for obj in boa.env._code_registry.values()} |
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.
it's a bit weird here to introduce a dependency on the global env. should we maybe make it parametrizable? like if None
is provided then we use boa.env
, but otherwise a specific env can be given.
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.
something like that?
@_exclude_filter
def _address_strategy(length: Optional[int] = 100, environment: Optional[EnvType] = None) -> SearchStrategy:
if environment is None:
environment = boa.env
# TODO: add addresses generated by the env through the env.generate_address() method
env_accounts = (
{obj.address for obj in environment._code_registry.values()}
)
# generate `length` random addresses
random_strings = generate_random_string(length)
random_accounts = {format_addr(i) for i in random_strings}
return _DeferredStrategyRepr(
lambda: st.sampled_from(list(env_accounts | random_accounts)), "accounts"
)
Then would need to modify all tests to pass a specific env
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.
strategies are only used by pytest right? it would make sense to use the environment that is available in the context of the tests.
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.
that's true, but you can set up contracts without using the global env
boa/test/strategies.py
Outdated
return _DeferredStrategyRepr( | ||
lambda: st.sampled_from(list(accounts)[:length]), "accounts" | ||
lambda: st.sampled_from(list(env_accounts | random_accounts)), "accounts" |
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 think using st.one_of(st.sampled_from(list(env_accounts), list(random_accounts)))
will generate a slightly better distribution
we can also use st.binary()
for the random addresses actually
What I did
included in address strategy all env contract addresses + eoa
How I did it
How to verify it
Description for the changelog
Cute Animal Picture