Skip to content

Commit

Permalink
expose silent parameter to transfer
Browse files Browse the repository at this point in the history
- Accounts.transfer() now accepts silent: bool as parameter and forwards it to TransactionReceipt.
- Test done to check if console output is printed
- Updated API docs
- Added info and PR to CHANGELOG.md
  • Loading branch information
matnad authored and iamdefinitelyahuman committed May 2, 2020
1 parent f80d6c1 commit ef67355
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ This changelog format is based on [Keep a Changelog](https://keepachangelog.com/
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased](https://github.com/iamdefinitelyahuman/brownie)
### Changed
- Exposed `silent` parameter to `Account.transfer()` ([#472](https://github.com/iamdefinitelyahuman/brownie/pull/472))

## [1.8.0](https://github.com/iamdefinitelyahuman/brownie/tree/v1.8.0) - 2020-04-30
### Added
Expand Down
4 changes: 3 additions & 1 deletion brownie/network/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ def transfer(
gas_limit: Optional[int] = None,
gas_price: Optional[int] = None,
data: str = None,
silent: bool = False,
) -> "TransactionReceipt":
"""
Broadcast a transaction from this account.
Expand All @@ -327,6 +328,7 @@ def transfer(
gas_limit: Gas limit of the transaction.
gas_price: Gas price of the transaction.
data: Hexstring of data to include in transaction.
silent: Toggles console verbosity.
Returns:
TransactionReceipt object
Expand All @@ -351,7 +353,7 @@ def transfer(
if rpc.is_active():
rpc._add_to_undo_buffer(self.transfer, (to, amount, gas_limit, gas_price, data), {})

return TransactionReceipt(txid, self, revert_data=revert_data)
return TransactionReceipt(txid, self, silent=silent, revert_data=revert_data)


class Account(_PrivateKeyAccount):
Expand Down
3 changes: 2 additions & 1 deletion docs/api-network.rst
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ Account Methods
>>> accounts[0].estimate_gas(accounts[1], "1 ether")
21000
.. py:classmethod:: Account.transfer(self, to=None, amount=0, gas_limit=None, gas_price=None, data=None)
.. py:classmethod:: Account.transfer(self, to=None, amount=0, gas_limit=None, gas_price=None, data=None, silent=False)
Broadcasts a transaction from this account.

Expand All @@ -302,6 +302,7 @@ Account Methods
* ``gas_limit``: Gas limit for the transaction. The given value is converted to :func:`Wei <brownie.convert.datatypes.Wei>`. If none is given, the price is set using ``eth_estimateGas``.
* ``gas_price``: Gas price for the transaction. The given value is converted to :func:`Wei <brownie.convert.datatypes.Wei>`. If none is given, the price is set using ``eth_gasPrice``.
* ``data``: Transaction data hexstring.
* ``silent``: Toggles console verbosity. If ``True`` is given, suppresses all console output for this transaction.

Returns a :func:`TransactionReceipt <brownie.network.transaction.TransactionReceipt>` instance.

Expand Down
7 changes: 7 additions & 0 deletions tests/network/transaction/test_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ def test_contract_address(accounts, tester):
assert tester.tx.receiver is None


@pytest.mark.parametrize("silent", [False, True])
def test_silent_mode(accounts, tester, console_mode, capsys, silent):
accounts[0].transfer(accounts[1], "1 ether", silent=silent)
captured = capsys.readouterr()
assert (captured.out == "") == silent


def test_input(accounts, tester):
data = tester.revertStrings.encode_input(5)
tx = accounts[0].transfer(tester.address, 0, data=data)
Expand Down

0 comments on commit ef67355

Please sign in to comment.