Skip to content

Commit

Permalink
Update test fixture to use Sol v0.8.25; Update geth:
Browse files Browse the repository at this point in the history
- Remove pending block reliance; set dev period to 1 second
- Use the latest geth 1.14.5 for integration; re-generate fixture
- Tweaks to the fixture generation based on geth updates
- re-compile test contracts with Solidity v0.8.25
- Remove support for non-existent client properties:
  - ``eth_coinbase``
  - ``eth_mining``
  - ``eth_hashrate``
  - ``eth_submitHashrate``
  - ``eth_submitWork``
  - ``eth_getWork``
- Update py-geth to use the newly released beta
- quick lint fixes
- Fix remaining tests that rely on mining:
- newsfragment for ethereum#3307
  • Loading branch information
fselmo committed Jun 20, 2024
1 parent a721a41 commit 371b3a0
Show file tree
Hide file tree
Showing 64 changed files with 263 additions and 708 deletions.
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ version: 2.1
parameters:
geth_version:
# update default value when updating geth integration test fixture
default: "v1.13.14"
default: "v1.14.5"
type: string
pygeth_version:
# update default value when updating geth integration test fixture
default: "4.3.0"
default: "5.0.0b1"
type: string
go_version:
default: "1.20.2"
default: "1.22.4"
type: string

common: &common
Expand Down
12 changes: 0 additions & 12 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,6 @@ def _skip_if_testrpc(w3):
return _skip_if_testrpc


@pytest.fixture()
def wait_for_miner_start():
def _wait_for_miner_start(w3, timeout=60):
poll_delay_counter = PollDelayCounter()
with Timeout(timeout) as timeout:
while not w3.eth.mining or not w3.eth.hashrate:
time.sleep(poll_delay_counter())
timeout.check()

return _wait_for_miner_start


@pytest.fixture(scope="module")
def wait_for_block():
def _wait_for_block(w3, block_number=1, timeout=None):
Expand Down
4 changes: 2 additions & 2 deletions docs/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -373,13 +373,13 @@ Geth Fixtures

.. code:: sh
$ python -m geth.install v1.13.14
$ python -m geth.install v1.14.5
2. Specify the Geth binary and run the fixture creation script (from within the web3.py directory):

.. code:: sh
$ GETH_BINARY=~/.py-geth/geth-v1.13.14/bin/geth python ./tests/integration/generate_fixtures/go_ethereum.py ./tests/integration/geth-1.13.14-fixture
$ GETH_BINARY=~/.py-geth/geth-v1.14.5/bin/geth python ./tests/integration/generate_fixtures/go_ethereum.py ./tests/integration/geth-1.14.5-fixture
3. The output of this script is your fixture, a zip file, which is now stored in ``/tests/integration/``.
Update the ``/tests/integration/go_ethereum/conftest.py`` and
Expand Down
2 changes: 1 addition & 1 deletion docs/middleware.rst
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ middleware is:
# confirm that the connection succeeded
>>> w3.client_version
'Geth/v1.13.14-stable-4bb3c89d/linux-amd64/go1.20.2'
'Geth/v1.14.5-stable-4bb3c89d/linux-amd64/go1.22.4'
This example connects to a local ``geth --dev`` instance on Linux with a
unique IPC location and loads the middleware:
Expand Down
10 changes: 5 additions & 5 deletions docs/web3.contract.rst
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ Each Contract Factory exposes the following methods.

.. code-block:: python
>>> deploy_txn = token_contract.constructor(web3.eth.coinbase, 12345).transact()
>>> deploy_txn = token_contract.constructor(web3.eth.accounts[0], 12345).transact()
>>> txn_receipt = web3.eth.get_transaction_receipt(deploy_txn)
>>> txn_receipt['contractAddress']
'0x4c0883a69102937d6231471b5dbb6204fe5129617082792ae468d01a3f362318'
Expand All @@ -259,7 +259,7 @@ Each Contract Factory exposes the following methods.

.. code-block:: python
>>> token_contract.constructor(web3.eth.coinbase, 12345).estimate_gas()
>>> token_contract.constructor(web3.eth.accounts[0], 12345).estimate_gas()
12563
.. py:classmethod:: Contract.constructor(*args, **kwargs).build_transaction(transaction=None)
Expand All @@ -281,7 +281,7 @@ Each Contract Factory exposes the following methods.
'gasPrice': w3.eth.gas_price,
'chainId': None
}
>>> contract_data = token_contract.constructor(web3.eth.coinbase, 12345).build_transaction(transaction)
>>> contract_data = token_contract.constructor(web3.eth.accounts[0], 12345).build_transaction(transaction)
>>> web3.eth.send_transaction(contract_data)
.. _contract_create_filter:
Expand Down Expand Up @@ -777,8 +777,8 @@ Methods
>>> my_contract.functions.multiply7(3).call()
21
>>> token_contract.functions.myBalance().call({'from': web3.eth.coinbase})
12345 # the token balance for `web3.eth.coinbase`
>>> token_contract.functions.myBalance().call({'from': web3.eth.accounts[0]})
12345 # the token balance for `web3.eth.accounts[0]`
>>> token_contract.functions.myBalance().call({'from': web3.eth.accounts[1]})
54321 # the token balance for the account `web3.eth.accounts[1]`
Expand Down
76 changes: 8 additions & 68 deletions docs/web3.eth.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,42 +79,6 @@ The following properties are available on the ``web3.eth`` namespace.
})
.. py:attribute:: Eth.coinbase
* Delegates to ``eth_coinbase`` RPC Method

Returns the current *Coinbase* address.

.. code-block:: python
>>> web3.eth.coinbase
'0xC014BA5EC014ba5ec014Ba5EC014ba5Ec014bA5E'
.. py:attribute:: Eth.mining
* Delegates to ``eth_mining`` RPC Method

Returns boolean as to whether the node is currently mining.

.. code-block:: python
>>> web3.eth.mining
False
.. py:attribute:: Eth.hashrate
* Delegates to ``eth_hashrate`` RPC Method

Returns the current number of hashes per second the node is mining with.

.. code-block:: python
>>> web3.eth.hashrate
906
.. py:attribute:: Eth.max_priority_fee
* Delegates to ``eth_maxPriorityFeePerGas`` RPC Method
Expand Down Expand Up @@ -720,15 +684,15 @@ The following methods are available on the ``web3.eth`` namespace.
# simple example (web3.py and / or client determines gas and fees, typically defaults to a dynamic fee transaction post London fork)
>>> web3.eth.send_transaction({
'to': '0x582AC4D8929f58c217d4a52aDD361AE470a8a4cD',
'from': web3.eth.coinbase,
'from': web3.eth.accounts[0],
'value': 12345
})
# Dynamic fee transaction, introduced by EIP-1559:
HexBytes('0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331')
>>> web3.eth.send_transaction({
'to': '0x582AC4D8929f58c217d4a52aDD361AE470a8a4cD',
'from': web3.eth.coinbase,
'from': web3.eth.accounts[0],
'value': 12345,
'gas': 21000,
'maxFeePerGas': web3.to_wei(250, 'gwei'),
Expand All @@ -740,7 +704,7 @@ The following methods are available on the ``web3.eth`` namespace.
HexBytes('0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331')
>>> web3.eth.send_transaction({
'to': '0x582AC4D8929f58c217d4a52aDD361AE470a8a4cD',
'from': web3.eth.coinbase,
'from': web3.eth.accounts[0],
'value': 12345,
'gas': 21000,
'gasPrice': web3.to_wei(50, 'gwei'),
Expand All @@ -758,7 +722,7 @@ The following methods are available on the ``web3.eth`` namespace.
.. code-block:: python
>>> signed_txn = w3.eth.sign_transaction(dict(
nonce=w3.eth.get_transaction_count(w3.eth.coinbase),
nonce=w3.eth.get_transaction_count(w3.eth.accounts[0]),
maxFeePerGas=2000000000,
maxPriorityFeePerGas=1000000000,
gas=100000,
Expand Down Expand Up @@ -839,13 +803,13 @@ The following methods are available on the ``web3.eth`` namespace.
>>> tx = web3.eth.send_transaction({
'to': '0x582AC4D8929f58c217d4a52aDD361AE470a8a4cD',
'from': web3.eth.coinbase,
'from': web3.eth.accounts[0],
'value': 1000
})
HexBytes('0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331')
>>> web3.eth.replace_transaction('0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331', {
'to': '0x582AC4D8929f58c217d4a52aDD361AE470a8a4cD',
'from': web3.eth.coinbase,
'from': web3.eth.accounts[0],
'value': 2000
})
HexBytes('0x4177e670ec6431606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1528989')
Expand All @@ -870,7 +834,7 @@ The following methods are available on the ``web3.eth`` namespace.
>>> tx = web3.eth.send_transaction({
'to': '0x582AC4D8929f58c217d4a52aDD361AE470a8a4cD',
'from': web3.eth.coinbase,
'from': web3.eth.accounts[0],
'value': 1000
})
HexBytes('0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331')
Expand Down Expand Up @@ -1072,7 +1036,7 @@ The following methods are available on the ``web3.eth`` namespace.

.. code-block:: python
>>> web3.eth.estimate_gas({'to': '0xd3CdA913deB6f67967B99D67aCDFa1712C293601', 'from':web3.eth.coinbase, 'value': 12345})
>>> web3.eth.estimate_gas({'to': '0xd3CdA913deB6f67967B99D67aCDFa1712C293601', 'from':web3.eth.accounts[0], 'value': 12345})
21000
Expand Down Expand Up @@ -1279,30 +1243,6 @@ with the filtering API.
filter, running :meth:`~Eth.get_filter_logs`, and then uninstalling the filter. See
:meth:`~Eth.filter` for details on allowed filter parameters.

.. py:method:: Eth.submit_hashrate(hashrate, nodeid)
* Delegates to ``eth_submitHashrate`` RPC Method

.. code-block:: python
>>> node_id = '59daa26581d0acd1fce254fb7e85952f4c09d0915afd33d3886cd914bc7d283c'
>>> web3.eth.submit_hashrate(5000, node_id)
True
.. py:method:: Eth.submit_work(nonce, pow_hash, mix_digest)
* Delegates to ``eth_submitWork`` RPC Method.

.. code-block:: python
>>> web3.eth.submit_work(
1,
'0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef',
'0xD1FE5700000000000000000000000000D1FE5700000000000000000000000000',
)
True

Contracts
---------
Expand Down
1 change: 1 addition & 0 deletions newsfragments/3307.internal.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Re-compile test contracts with Solidity v0.8.25 to ensure compatibility.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
],
"test": [
"eth-tester[py-evm]>=0.11.0b1,<0.13.0b1",
"py-geth>=4.1.0",
"py-geth>=5.0.0b1",
"pytest-asyncio>=0.18.1,<0.23",
"pytest-mock>=1.10",
"pytest-xdist>=2.4.0",
Expand Down
6 changes: 4 additions & 2 deletions tests/core/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,15 @@ def __init__(self, a, b):
@pytest_asyncio.fixture
async def async_w3():
w3 = AsyncWeb3(AsyncEthereumTesterProvider())
w3.eth.default_account = await w3.eth.coinbase
accounts = await w3.eth.accounts
w3.eth.default_account = accounts[0]
return w3


@pytest_asyncio.fixture
async def async_w3_non_strict_abi():
w3 = AsyncWeb3(AsyncEthereumTesterProvider())
w3.strict_bytes_type_checking = False
w3.eth.default_account = await w3.eth.coinbase
accounts = await w3.eth.accounts
w3.eth.default_account = accounts[0]
return w3
4 changes: 2 additions & 2 deletions tests/core/contracts/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def event_contract(

event_contract_factory = w3.eth.contract(**EVENT_CONTRACT_DATA)
deploy_txn_hash = event_contract_factory.constructor().transact(
{"from": w3.eth.coinbase, "gas": 1000000}
{"from": w3.eth.accounts[0], "gas": 1000000}
)
deploy_receipt = wait_for_transaction(w3, deploy_txn_hash)
contract_address = address_conversion_func(deploy_receipt["contractAddress"])
Expand All @@ -251,7 +251,7 @@ def indexed_event_contract(

indexed_event_contract_factory = w3.eth.contract(**INDEXED_EVENT_CONTRACT_DATA)
deploy_txn_hash = indexed_event_contract_factory.constructor().transact(
{"from": w3.eth.coinbase, "gas": 1000000}
{"from": w3.eth.accounts[0], "gas": 1000000}
)
deploy_receipt = wait_for_transaction(w3, deploy_txn_hash)
contract_address = address_conversion_func(deploy_receipt["contractAddress"])
Expand Down
19 changes: 10 additions & 9 deletions tests/core/contracts/test_contract_constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def test_contract_constructor_build_transaction_no_constructor(
{"from": address_conversion_func(w3.eth.accounts[0])}
)
txn = w3.eth.get_transaction(txn_hash)
nonce = w3.eth.get_transaction_count(w3.eth.coinbase)
nonce = w3.eth.get_transaction_count(w3.eth.accounts[0])
unsent_txn = math_contract_factory.constructor().build_transaction({"nonce": nonce})
assert txn["input"] == HexBytes(unsent_txn["data"])

Expand All @@ -238,7 +238,7 @@ def test_contract_constructor_build_transaction_without_arguments(
{"from": address_conversion_func(w3.eth.accounts[0])}
)
txn = w3.eth.get_transaction(txn_hash)
nonce = w3.eth.get_transaction_count(w3.eth.coinbase)
nonce = w3.eth.get_transaction_count(w3.eth.accounts[0])
unsent_txn = math_contract_factory.constructor().build_transaction({"nonce": nonce})
assert txn["input"] == HexBytes(unsent_txn["data"])

Expand Down Expand Up @@ -268,7 +268,9 @@ def test_contract_constructor_build_transaction_with_arguments(
*constructor_args, **constructor_kwargs
).transact({"from": address_conversion_func(w3_non_strict_abi.eth.accounts[0])})
txn = w3_non_strict_abi.eth.get_transaction(txn_hash)
nonce = w3_non_strict_abi.eth.get_transaction_count(w3_non_strict_abi.eth.coinbase)
nonce = w3_non_strict_abi.eth.get_transaction_count(
w3_non_strict_abi.eth.accounts[0]
)
unsent_txn = non_strict_contract_with_constructor_args_factory.constructor(
*constructor_args, **constructor_kwargs
).build_transaction({"nonce": nonce})
Expand Down Expand Up @@ -526,8 +528,7 @@ async def test_async_contract_constructor_build_transaction_no_constructor(
{"from": address_conversion_func(async_w3_accounts[0])}
)
txn = await async_w3.eth.get_transaction(txn_hash)
async_w3_coinbase = await async_w3.eth.coinbase
nonce = await async_w3.eth.get_transaction_count(async_w3_coinbase)
nonce = await async_w3.eth.get_transaction_count(async_w3_accounts[0])
unsent_txn = await async_math_contract_factory.constructor().build_transaction(
{"nonce": nonce}
)
Expand All @@ -548,8 +549,7 @@ async def test_async_contract_constructor_build_transaction_without_arguments(
{"from": address_conversion_func(async_w3_accounts[0])}
)
txn = await async_w3.eth.get_transaction(txn_hash)
async_w3_coinbase = await async_w3.eth.coinbase
nonce = await async_w3.eth.get_transaction_count(async_w3_coinbase)
nonce = await async_w3.eth.get_transaction_count(async_w3_accounts[0])
unsent_txn = await async_math_contract_factory.constructor().build_transaction(
{"nonce": nonce}
)
Expand Down Expand Up @@ -585,8 +585,9 @@ async def test_async_contract_constructor_build_transaction_with_arguments(
).transact({"from": address_conversion_func(async_w3_accounts[0])})
)
txn = await async_w3_non_strict_abi.eth.get_transaction(txn_hash)
async_w3_coinbase = await async_w3_non_strict_abi.eth.coinbase
nonce = await async_w3_non_strict_abi.eth.get_transaction_count(async_w3_coinbase)
nonce = await async_w3_non_strict_abi.eth.get_transaction_count(
async_w3_accounts[0]
)
unsent_txn = (
await async_non_strict_constructor_with_args_contract_factory.constructor(
*constructor_args, **constructor_kwargs
Expand Down
3 changes: 2 additions & 1 deletion tests/core/contracts/test_contract_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ def async_eth_tester():
@pytest_asyncio.fixture()
async def async_w3():
async_w3 = AsyncWeb3(AsyncEthereumTesterProvider())
async_w3.eth.default_account = await async_w3.eth.coinbase
accounts = await async_w3.eth.accounts
async_w3.eth.default_account = accounts[0]
return async_w3


Expand Down
10 changes: 6 additions & 4 deletions tests/core/contracts/test_contract_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
@pytest.fixture()
def math_addr(math_contract_factory, address_conversion_func):
w3 = math_contract_factory.w3
deploy_txn = math_contract_factory.constructor().transact({"from": w3.eth.coinbase})
deploy_txn = math_contract_factory.constructor().transact(
{"from": w3.eth.accounts[0]}
)
deploy_receipt = w3.eth.wait_for_transaction_receipt(deploy_txn)
assert deploy_receipt is not None
return address_conversion_func(deploy_receipt["contractAddress"])
Expand All @@ -28,7 +30,7 @@ def test_contract_with_unset_address(math_contract_factory):
def test_contract_with_name_address(math_contract_factory, math_addr):
with contract_ens_addresses(math_contract_factory, [("thedao.eth", math_addr)]):
mc = math_contract_factory(address="thedao.eth")
caller = mc.w3.eth.coinbase
caller = mc.w3.eth.accounts[0]
assert mc.address == "thedao.eth"
assert mc.functions.return13().call({"from": caller}) == 13

Expand All @@ -48,7 +50,7 @@ def test_contract_with_name_address_from_eth_contract(
bytecode_runtime=math_contract_runtime,
)

caller = mc.w3.eth.coinbase
caller = mc.w3.eth.accounts[0]
assert mc.address == "thedao.eth"
assert mc.functions.return13().call({"from": caller}) == 13

Expand All @@ -58,7 +60,7 @@ def test_contract_with_name_address_changing(math_contract_factory, math_addr):
with contract_ens_addresses(math_contract_factory, [("thedao.eth", math_addr)]):
mc = math_contract_factory(address="thedao.eth")

caller = mc.w3.eth.coinbase
caller = mc.w3.eth.accounts[0]
assert mc.address == "thedao.eth"

# what happens when name returns no address at all
Expand Down
Loading

0 comments on commit 371b3a0

Please sign in to comment.