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

Update test suite, update Solidity version for compiling test contracts, remove deprecated JSON-RPC methods #3307

Merged
merged 5 commits into from
Jun 26, 2024
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: 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
19 changes: 5 additions & 14 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 Expand Up @@ -82,14 +70,17 @@ def _wait_for_transaction(w3, txn_hash, timeout=120):
return _wait_for_transaction


@pytest.fixture()
@pytest.fixture
def w3():
return Web3(EthereumTesterProvider())
w3 = Web3(EthereumTesterProvider())
w3.eth.default_account = w3.eth.accounts[0]
return w3


@pytest.fixture(scope="module")
def w3_non_strict_abi():
w3 = Web3(EthereumTesterProvider())
w3.eth.default_account = w3.eth.accounts[0]
w3.strict_bytes_type_checking = False
return w3

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
6 changes: 2 additions & 4 deletions tests/core/contracts/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,7 @@ def event_contract(
wait_for_block(w3)

event_contract_factory = w3.eth.contract(**EVENT_CONTRACT_DATA)
deploy_txn_hash = event_contract_factory.constructor().transact(
{"from": w3.eth.coinbase, "gas": 1000000}
)
deploy_txn_hash = event_contract_factory.constructor().transact({"gas": 1000000})
deploy_receipt = wait_for_transaction(w3, deploy_txn_hash)
contract_address = address_conversion_func(deploy_receipt["contractAddress"])

Expand All @@ -251,7 +249,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}
{"gas": 1000000}
)
deploy_receipt = wait_for_transaction(w3, deploy_txn_hash)
contract_address = address_conversion_func(deploy_receipt["contractAddress"])
Expand Down
Loading