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

Address strategy length #607

Merged
merged 3 commits into from
Jun 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 4 additions & 2 deletions brownie/test/strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@ def _decimal_strategy(


@_exclude_filter
def _address_strategy() -> SearchStrategy:
return _DeferredStrategyRepr(lambda: st.sampled_from(list(network.accounts)), "accounts")
def _address_strategy(length: Optional[int] = None) -> SearchStrategy:
return _DeferredStrategyRepr(
lambda: st.sampled_from(list(network.accounts)[:length]), "accounts"
)


@_exclude_filter
Expand Down
1 change: 1 addition & 0 deletions docs/tests-hypothesis-property.rst
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ Address

Optional keyword arguments:

* ``length``: The number of :func:`Account <brownie.network.account.Account>` objects to include in the strategy. If the :func:`Accounts <brownie.network.account.Accounts>` container holds less than this number of objects, the entire container is used.
* ``excludes``: An object, iterable or callable used to filter strategy results.

.. code-block:: python
Expand Down
5 changes: 5 additions & 0 deletions tests/test/strategies/test_address.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,10 @@ def test_given(accounts, value):
assert isinstance(value, Account)


@given(value=strategy("address", length=3))
def test_length(accounts, value):
assert accounts.index(value) < 3


def test_repr():
assert repr(strategy("address")) == "sampled_from(accounts)"