Skip to content
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
2 changes: 1 addition & 1 deletion docs/contracts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ To run this example, you will need to install a few extra features:
>>> w3 = Web3(Web3.EthereumTesterProvider())

# set pre-funded account as sender
>>> w3.eth.defaultAccount = w3.eth.accounts[0]
>>> w3.eth.default_account = w3.eth.accounts[0]

# get bytecode
>>> bytecode = compiled_sol['contracts']['Greeter.sol']['Greeter']['evm']['bytecode']['object']
Expand Down
4 changes: 2 additions & 2 deletions docs/middleware.rst
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ Signing

.. py:method:: web3.middleware.construct_sign_and_send_raw_middleware(private_key_or_account)

This middleware automatically captures transactions, signs them, and sends them as raw transactions. The from field on the transaction, or ``w3.eth.defaultAccount`` must be set to the address of the private key for this middleware to have any effect.
This middleware automatically captures transactions, signs them, and sends them as raw transactions. The from field on the transaction, or ``w3.eth.default_account`` must be set to the address of the private key for this middleware to have any effect.

* ``private_key_or_account`` A single private key or a tuple, list or set of private keys.

Expand All @@ -420,5 +420,5 @@ This middleware automatically captures transactions, signs them, and sends them
>>> from eth_account import Account
>>> acct = Account.create('KEYSMASH FJAFJKLDSKF7JKFDJ 1530')
>>> w3.middleware_onion.add(construct_sign_and_send_raw_middleware(acct))
>>> w3.eth.defaultAccount = acct.address
>>> w3.eth.default_account = acct.address
# Now you can send a tx from acct.address without having to build and sign each raw transaction
7 changes: 6 additions & 1 deletion docs/web3.eth.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,16 @@ Properties
The following properties are available on the ``web3.eth`` namespace.


.. py:attribute:: Eth.defaultAccount
.. py:attribute:: Eth.default_account

The ethereum address that will be used as the default ``from`` address for
all transactions.

.. py:attribute:: Eth.defaultAccount

.. warning:: Deprecated: This property is deprecated in favor of
:attr:`~web3.eth.Eth.default_account`


.. py:attribute:: Eth.defaultBlock

Expand Down
1 change: 1 addition & 0 deletions newsfragments/1848.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Move ``defaultAccount`` to ``default_account``. Deprecate ``defaultAccount``.
12 changes: 6 additions & 6 deletions tests/core/contracts/test_contract_transact_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,29 +155,29 @@ def test_transacting_with_contract_with_arguments(web3,
def test_deploy_when_default_account_is_set(web3,
wait_for_transaction,
STRING_CONTRACT):
web3.eth.defaultAccount = web3.eth.accounts[1]
assert web3.eth.defaultAccount is not empty
web3.eth.default_account = web3.eth.accounts[1]
assert web3.eth.default_account is not empty

StringContract = web3.eth.contract(**STRING_CONTRACT)

deploy_txn = StringContract.constructor("Caqalai").transact()
web3.eth.waitForTransactionReceipt(deploy_txn)
txn_after = web3.eth.getTransaction(deploy_txn)
assert txn_after['from'] == web3.eth.defaultAccount
assert txn_after['from'] == web3.eth.default_account


def test_transact_when_default_account_is_set(web3,
wait_for_transaction,
math_contract,
transact):
web3.eth.defaultAccount = web3.eth.accounts[1]
assert web3.eth.defaultAccount is not empty
web3.eth.default_account = web3.eth.accounts[1]
assert web3.eth.default_account is not empty

txn_hash = transact(contract=math_contract,
contract_function='increment')
wait_for_transaction(web3, txn_hash)
txn_after = web3.eth.getTransaction(txn_hash)
assert txn_after['from'] == web3.eth.defaultAccount
assert txn_after['from'] == web3.eth.default_account


def test_transacting_with_contract_with_string_argument(web3, string_contract, transact, call):
Expand Down
36 changes: 0 additions & 36 deletions tests/core/eth-module/test_defaultAccount_api.py

This file was deleted.

70 changes: 70 additions & 0 deletions tests/core/eth-module/test_default_account_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import pytest


@pytest.fixture(autouse=True)
def wait_for_first_block(web3, wait_for_block):
wait_for_block(web3)


def test_uses_default_account_when_set(web3, extra_accounts,
wait_for_transaction):
web3.eth.default_account = extra_accounts[2]
assert web3.eth.default_account == extra_accounts[2]

txn_hash = web3.eth.sendTransaction({
"to": extra_accounts[1],
"value": 1234,
})

wait_for_transaction(web3, txn_hash)

txn = web3.eth.getTransaction(txn_hash)
assert txn['from'] == extra_accounts[2]


def test_uses_defaultAccount_when_set_with_warning(web3, extra_accounts,
wait_for_transaction):
with pytest.warns(DeprecationWarning):
web3.eth.defaultAccount = extra_accounts[2]
assert web3.eth.defaultAccount == extra_accounts[2]

txn_hash = web3.eth.sendTransaction({
"to": extra_accounts[1],
"value": 1234,
})

wait_for_transaction(web3, txn_hash)

txn = web3.eth.getTransaction(txn_hash)
assert txn['from'] == extra_accounts[2]


def test_uses_given_from_address_when_provided(web3, extra_accounts,
wait_for_transaction):
web3.eth.default_account = extra_accounts[2]
txn_hash = web3.eth.sendTransaction({
"from": extra_accounts[5],
"to": extra_accounts[1],
"value": 1234,
})

wait_for_transaction(web3, txn_hash)

txn = web3.eth.getTransaction(txn_hash)
assert txn['from'] == extra_accounts[5]


def test_uses_given_from_address_when_provided_with_warning(web3, extra_accounts,
wait_for_transaction):
with pytest.warns(DeprecationWarning):
web3.eth.defaultAccount = extra_accounts[2]
txn_hash = web3.eth.sendTransaction({
"from": extra_accounts[5],
"to": extra_accounts[1],
"value": 1234,
})

wait_for_transaction(web3, txn_hash)

txn = web3.eth.getTransaction(txn_hash)
assert txn['from'] == extra_accounts[5]
2 changes: 1 addition & 1 deletion tests/core/pm-module/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def setup_w3():
pyevm_backend = PyEVMBackend(genesis_parameters=custom_genesis_params)
t = EthereumTester(backend=pyevm_backend)
w3 = Web3(Web3.EthereumTesterProvider(ethereum_tester=t))
w3.eth.defaultAccount = w3.eth.accounts[0]
w3.eth.default_account = w3.eth.accounts[0]
w3.eth.defaultContractFactory = LinkableContract
w3.enable_unstable_package_management_api()
return w3
Expand Down
2 changes: 1 addition & 1 deletion tests/core/pm-module/test_ens_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def ens_setup(deployer):
@pytest.fixture
def ens(ens_setup, mocker):
mocker.patch('web3.middleware.stalecheck._isfresh', return_value=True)
ens_setup.web3.eth.defaultAccount = ens_setup.web3.eth.coinbase
ens_setup.web3.eth.default_account = ens_setup.web3.eth.coinbase
ens_setup.web3.enable_unstable_package_management_api()
return ens_setup

Expand Down
2 changes: 1 addition & 1 deletion tests/core/pm-module/test_registry_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
@pytest.fixture
def fresh_w3():
w3 = Web3(Web3.EthereumTesterProvider())
w3.eth.defaultAccount = w3.eth.accounts[0]
w3.eth.default_account = w3.eth.accounts[0]
w3.eth.defaultContractFactory = LinkableContract
w3.enable_unstable_package_management_api()
return w3
Expand Down
2 changes: 1 addition & 1 deletion tests/ens/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def ens_setup():
@pytest.fixture
def ens(ens_setup, mocker):
mocker.patch('web3.middleware.stalecheck._isfresh', return_value=True)
ens_setup.web3.eth.defaultAccount = ens_setup.web3.eth.coinbase
ens_setup.web3.eth.default_account = ens_setup.web3.eth.coinbase
return ens_setup


Expand Down
2 changes: 1 addition & 1 deletion tests/ethpm/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def fetch_manifest_path(name, version):
@pytest.fixture
def w3():
w3 = Web3(Web3.EthereumTesterProvider())
w3.eth.defaultAccount = w3.eth.accounts[0]
w3.eth.default_account = w3.eth.accounts[0]
return w3


Expand Down
36 changes: 18 additions & 18 deletions web3/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,9 +633,9 @@ def estimateGas(
self.check_forbidden_keys_in_transaction(estimate_gas_transaction,
["data", "to"])

if self.web3.eth.defaultAccount is not empty:
# type ignored b/c check prevents an empty defaultAccount
estimate_gas_transaction.setdefault('from', self.web3.eth.defaultAccount) # type: ignore # noqa: E501
if self.web3.eth.default_account is not empty:
# type ignored b/c check prevents an empty default_account
estimate_gas_transaction.setdefault('from', self.web3.eth.default_account) # type: ignore # noqa: E501

estimate_gas_transaction['data'] = self.data_in_transaction

Expand All @@ -652,9 +652,9 @@ def transact(self, transaction: Optional[TxParams] = None) -> HexBytes:
self.check_forbidden_keys_in_transaction(transact_transaction,
["data", "to"])

if self.web3.eth.defaultAccount is not empty:
# type ignored b/c check prevents an empty defaultAccount
transact_transaction.setdefault('from', self.web3.eth.defaultAccount) # type: ignore
if self.web3.eth.default_account is not empty:
# type ignored b/c check prevents an empty default_account
transact_transaction.setdefault('from', self.web3.eth.default_account) # type: ignore

transact_transaction['data'] = self.data_in_transaction

Expand All @@ -674,9 +674,9 @@ def buildTransaction(self, transaction: Optional[TxParams] = None) -> TxParams:
self.check_forbidden_keys_in_transaction(built_transaction,
["data", "to"])

if self.web3.eth.defaultAccount is not empty:
# type ignored b/c check prevents an empty defaultAccount
built_transaction.setdefault('from', self.web3.eth.defaultAccount) # type: ignore
if self.web3.eth.default_account is not empty:
# type ignored b/c check prevents an empty default_account
built_transaction.setdefault('from', self.web3.eth.default_account) # type: ignore

built_transaction['data'] = self.data_in_transaction
built_transaction['to'] = Address(b'')
Expand Down Expand Up @@ -933,9 +933,9 @@ def call(

if self.address:
call_transaction.setdefault('to', self.address)
if self.web3.eth.defaultAccount is not empty:
# type ignored b/c check prevents an empty defaultAccount
call_transaction.setdefault('from', self.web3.eth.defaultAccount) # type: ignore
if self.web3.eth.default_account is not empty:
# type ignored b/c check prevents an empty default_account
call_transaction.setdefault('from', self.web3.eth.default_account) # type: ignore

if 'to' not in call_transaction:
if isinstance(self, type):
Expand Down Expand Up @@ -975,9 +975,9 @@ def transact(self, transaction: Optional[TxParams] = None) -> HexBytes:

if self.address is not None:
transact_transaction.setdefault('to', self.address)
if self.web3.eth.defaultAccount is not empty:
# type ignored b/c check prevents an empty defaultAccount
transact_transaction.setdefault('from', self.web3.eth.defaultAccount) # type: ignore
if self.web3.eth.default_account is not empty:
# type ignored b/c check prevents an empty default_account
transact_transaction.setdefault('from', self.web3.eth.default_account) # type: ignore

if 'to' not in transact_transaction:
if isinstance(self, type):
Expand Down Expand Up @@ -1017,9 +1017,9 @@ def estimateGas(

if self.address:
estimate_gas_transaction.setdefault('to', self.address)
if self.web3.eth.defaultAccount is not empty:
# type ignored b/c check prevents an empty defaultAccount
estimate_gas_transaction.setdefault('from', self.web3.eth.defaultAccount) # type: ignore # noqa: E501
if self.web3.eth.default_account is not empty:
# type ignored b/c check prevents an empty default_account
estimate_gas_transaction.setdefault('from', self.web3.eth.default_account) # type: ignore # noqa: E501

if 'to' not in estimate_gas_transaction:
if isinstance(self, type):
Expand Down
Loading