Skip to content

Commit

Permalink
Merge pull request #607 from eth-brownie/feat-address-strategy-length
Browse files Browse the repository at this point in the history
Address strategy length
  • Loading branch information
iamdefinitelyahuman authored Jun 4, 2020
2 parents 51edd73 + 04b2f11 commit a5a8151
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
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)"

0 comments on commit a5a8151

Please sign in to comment.