web3 6.20.3__py3-none-any.whl → 7.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ens/__init__.py +13 -2
- ens/_normalization.py +2 -17
- ens/async_ens.py +33 -21
- ens/base_ens.py +3 -1
- ens/ens.py +16 -11
- ens/exceptions.py +16 -29
- ens/specs/nf.json +1 -1
- ens/specs/normalization_spec.json +1 -1
- ens/utils.py +52 -63
- web3/__init__.py +20 -24
- web3/_utils/abi.py +115 -271
- web3/_utils/async_transactions.py +7 -4
- web3/_utils/batching.py +217 -0
- web3/_utils/blocks.py +6 -2
- web3/_utils/caching.py +128 -5
- web3/_utils/compat/__init__.py +2 -3
- web3/_utils/contract_sources/compile_contracts.py +1 -1
- web3/_utils/contract_sources/contract_data/arrays_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/bytes_contracts.py +5 -5
- web3/_utils/contract_sources/contract_data/constructor_contracts.py +7 -7
- web3/_utils/contract_sources/contract_data/contract_caller_tester.py +3 -3
- web3/_utils/contract_sources/contract_data/emitter_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/event_contracts.py +5 -5
- web3/_utils/contract_sources/contract_data/extended_resolver.py +3 -3
- web3/_utils/contract_sources/contract_data/fallback_function_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/function_name_tester_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/math_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/offchain_lookup.py +3 -3
- web3/_utils/contract_sources/contract_data/offchain_resolver.py +3 -3
- web3/_utils/contract_sources/contract_data/panic_errors_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/payable_tester.py +3 -3
- web3/_utils/contract_sources/contract_data/receive_function_contracts.py +5 -5
- web3/_utils/contract_sources/contract_data/reflector_contracts.py +3 -3
- web3/_utils/contract_sources/contract_data/revert_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/simple_resolver.py +3 -3
- web3/_utils/contract_sources/contract_data/storage_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/string_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/tuple_contracts.py +5 -5
- web3/_utils/contracts.py +130 -236
- web3/_utils/datatypes.py +5 -1
- web3/_utils/decorators.py +13 -23
- web3/_utils/empty.py +1 -1
- web3/_utils/encoding.py +16 -12
- web3/_utils/ens.py +2 -1
- web3/_utils/error_formatters_utils.py +5 -3
- web3/_utils/events.py +66 -69
- web3/_utils/fee_utils.py +1 -3
- web3/_utils/filters.py +24 -22
- web3/_utils/formatters.py +2 -2
- web3/_utils/http.py +5 -3
- web3/_utils/http_session_manager.py +303 -0
- web3/_utils/math.py +14 -15
- web3/_utils/method_formatters.py +34 -36
- web3/_utils/module.py +2 -1
- web3/_utils/module_testing/__init__.py +0 -3
- web3/_utils/module_testing/eth_module.py +695 -643
- web3/_utils/module_testing/module_testing_utils.py +61 -34
- web3/_utils/module_testing/persistent_connection_provider.py +56 -25
- web3/_utils/module_testing/utils.py +258 -0
- web3/_utils/module_testing/web3_module.py +438 -17
- web3/_utils/normalizers.py +13 -11
- web3/_utils/rpc_abi.py +5 -32
- web3/_utils/threads.py +8 -7
- web3/_utils/transactions.py +14 -12
- web3/_utils/type_conversion.py +5 -1
- web3/_utils/validation.py +17 -17
- web3/auto/gethdev.py +7 -2
- web3/beacon/__init__.py +6 -1
- web3/beacon/async_beacon.py +9 -5
- web3/beacon/{main.py → beacon.py} +7 -5
- web3/contract/__init__.py +7 -0
- web3/contract/async_contract.py +47 -46
- web3/contract/base_contract.py +183 -158
- web3/contract/contract.py +49 -43
- web3/contract/utils.py +203 -59
- web3/datastructures.py +79 -31
- web3/eth/__init__.py +7 -0
- web3/eth/async_eth.py +39 -51
- web3/eth/base_eth.py +17 -10
- web3/eth/eth.py +30 -68
- web3/exceptions.py +108 -82
- web3/gas_strategies/time_based.py +8 -6
- web3/geth.py +1 -254
- web3/main.py +75 -122
- web3/manager.py +316 -146
- web3/method.py +38 -31
- web3/middleware/__init__.py +67 -89
- web3/middleware/attrdict.py +36 -49
- web3/middleware/base.py +174 -0
- web3/middleware/buffered_gas_estimate.py +20 -21
- web3/middleware/filter.py +157 -117
- web3/middleware/formatting.py +124 -108
- web3/middleware/gas_price_strategy.py +20 -32
- web3/middleware/names.py +29 -26
- web3/middleware/proof_of_authority.py +68 -0
- web3/middleware/pythonic.py +2 -2
- web3/middleware/signing.py +74 -89
- web3/middleware/stalecheck.py +52 -79
- web3/middleware/validation.py +5 -13
- web3/module.py +54 -10
- web3/providers/__init__.py +10 -6
- web3/providers/async_base.py +117 -39
- web3/providers/auto.py +3 -3
- web3/providers/base.py +89 -33
- web3/providers/eth_tester/__init__.py +5 -0
- web3/providers/eth_tester/defaults.py +1 -64
- web3/providers/eth_tester/main.py +99 -31
- web3/providers/eth_tester/middleware.py +45 -73
- web3/providers/ipc.py +42 -46
- web3/providers/{websocket/websocket.py → legacy_websocket.py} +32 -7
- web3/providers/persistent/__init__.py +22 -0
- web3/providers/persistent/async_ipc.py +153 -0
- web3/providers/{persistent.py → persistent/persistent.py} +106 -25
- web3/providers/persistent/persistent_connection.py +84 -0
- web3/providers/{websocket → persistent}/request_processor.py +94 -32
- web3/providers/persistent/utils.py +43 -0
- web3/providers/{websocket/websocket_v2.py → persistent/websocket.py} +29 -28
- web3/providers/rpc/__init__.py +11 -0
- web3/providers/rpc/async_rpc.py +171 -0
- web3/providers/rpc/rpc.py +179 -0
- web3/providers/rpc/utils.py +92 -0
- web3/testing.py +4 -4
- web3/tools/benchmark/main.py +22 -22
- web3/tools/benchmark/node.py +2 -8
- web3/tools/benchmark/reporting.py +2 -2
- web3/tools/benchmark/utils.py +1 -1
- web3/tracing.py +9 -5
- web3/types.py +30 -107
- web3/utils/__init__.py +58 -5
- web3/utils/abi.py +575 -10
- web3/utils/async_exception_handling.py +19 -7
- web3/utils/caching.py +32 -13
- web3/utils/exception_handling.py +7 -5
- {web3-6.20.3.dist-info → web3-7.0.0.dist-info}/LICENSE +1 -1
- web3-7.0.0.dist-info/METADATA +112 -0
- web3-7.0.0.dist-info/RECORD +167 -0
- {web3-6.20.3.dist-info → web3-7.0.0.dist-info}/top_level.txt +0 -1
- ethpm/__init__.py +0 -20
- ethpm/_utils/__init__.py +0 -0
- ethpm/_utils/backend.py +0 -93
- ethpm/_utils/cache.py +0 -44
- ethpm/_utils/chains.py +0 -119
- ethpm/_utils/contract.py +0 -35
- ethpm/_utils/deployments.py +0 -145
- ethpm/_utils/ipfs.py +0 -116
- ethpm/_utils/protobuf/__init__.py +0 -0
- ethpm/_utils/protobuf/ipfs_file_pb2.py +0 -33
- ethpm/_utils/registry.py +0 -29
- ethpm/assets/__init__.py +0 -0
- ethpm/assets/ens/v3.json +0 -1
- ethpm/assets/escrow/with_bytecode_v3.json +0 -1
- ethpm/assets/ipfs_file.proto +0 -32
- ethpm/assets/owned/output_v3.json +0 -1
- ethpm/assets/owned/with_contract_type_v3.json +0 -1
- ethpm/assets/registry/contracts/Authority.sol +0 -156
- ethpm/assets/registry/contracts/IndexedOrderedSetLib.sol +0 -106
- ethpm/assets/registry/contracts/PackageDB.sol +0 -225
- ethpm/assets/registry/contracts/PackageRegistry.sol +0 -361
- ethpm/assets/registry/contracts/PackageRegistryInterface.sol +0 -97
- ethpm/assets/registry/contracts/ReleaseDB.sol +0 -309
- ethpm/assets/registry/contracts/ReleaseValidator.sol +0 -152
- ethpm/assets/registry/solc_input.json +0 -1
- ethpm/assets/registry/solc_output.json +0 -1
- ethpm/assets/registry/v3.json +0 -1
- ethpm/assets/safe-math-lib/v3-strict-no-deployments.json +0 -1
- ethpm/assets/simple-registry/contracts/Ownable.sol +0 -63
- ethpm/assets/simple-registry/contracts/PackageRegistry.sol +0 -373
- ethpm/assets/simple-registry/contracts/PackageRegistryInterface.sol +0 -96
- ethpm/assets/simple-registry/solc_input.json +0 -33
- ethpm/assets/simple-registry/solc_output.json +0 -1
- ethpm/assets/simple-registry/v3.json +0 -1
- ethpm/assets/standard-token/output_v3.json +0 -1
- ethpm/assets/standard-token/with_bytecode_v3.json +0 -1
- ethpm/assets/vyper_registry/0.1.0.json +0 -1
- ethpm/assets/vyper_registry/registry.vy +0 -216
- ethpm/assets/vyper_registry/registry_with_delete.vy +0 -244
- ethpm/backends/__init__.py +0 -0
- ethpm/backends/base.py +0 -43
- ethpm/backends/http.py +0 -108
- ethpm/backends/ipfs.py +0 -219
- ethpm/backends/registry.py +0 -154
- ethpm/constants.py +0 -17
- ethpm/contract.py +0 -187
- ethpm/dependencies.py +0 -58
- ethpm/deployments.py +0 -80
- ethpm/ethpm-spec/examples/escrow/1.0.0-pretty.json +0 -146
- ethpm/ethpm-spec/examples/escrow/1.0.0.json +0 -1
- ethpm/ethpm-spec/examples/escrow/contracts/Escrow.sol +0 -32
- ethpm/ethpm-spec/examples/escrow/contracts/SafeSendLib.sol +0 -20
- ethpm/ethpm-spec/examples/escrow/v3-pretty.json +0 -171
- ethpm/ethpm-spec/examples/escrow/v3.json +0 -1
- ethpm/ethpm-spec/examples/owned/1.0.0-pretty.json +0 -21
- ethpm/ethpm-spec/examples/owned/1.0.0.json +0 -1
- ethpm/ethpm-spec/examples/owned/contracts/Owned.sol +0 -12
- ethpm/ethpm-spec/examples/owned/v3-pretty.json +0 -27
- ethpm/ethpm-spec/examples/owned/v3.json +0 -1
- ethpm/ethpm-spec/examples/piper-coin/1.0.0-pretty.json +0 -31
- ethpm/ethpm-spec/examples/piper-coin/1.0.0.json +0 -1
- ethpm/ethpm-spec/examples/piper-coin/v3-pretty.json +0 -21
- ethpm/ethpm-spec/examples/piper-coin/v3.json +0 -1
- ethpm/ethpm-spec/examples/safe-math-lib/1.0.0-pretty.json +0 -85
- ethpm/ethpm-spec/examples/safe-math-lib/1.0.0.json +0 -1
- ethpm/ethpm-spec/examples/safe-math-lib/contracts/SafeMathLib.sol +0 -24
- ethpm/ethpm-spec/examples/safe-math-lib/v3-pretty.json +0 -117
- ethpm/ethpm-spec/examples/safe-math-lib/v3.json +0 -1
- ethpm/ethpm-spec/examples/standard-token/1.0.0-pretty.json +0 -55
- ethpm/ethpm-spec/examples/standard-token/1.0.0.json +0 -1
- ethpm/ethpm-spec/examples/standard-token/contracts/AbstractToken.sol +0 -20
- ethpm/ethpm-spec/examples/standard-token/contracts/StandardToken.sol +0 -84
- ethpm/ethpm-spec/examples/standard-token/v3-pretty.json +0 -460
- ethpm/ethpm-spec/examples/standard-token/v3.json +0 -1
- ethpm/ethpm-spec/examples/transferable/1.0.0-pretty.json +0 -21
- ethpm/ethpm-spec/examples/transferable/1.0.0.json +0 -1
- ethpm/ethpm-spec/examples/transferable/contracts/Transferable.sol +0 -14
- ethpm/ethpm-spec/examples/transferable/v3-pretty.json +0 -27
- ethpm/ethpm-spec/examples/transferable/v3.json +0 -1
- ethpm/ethpm-spec/examples/wallet/1.0.0-pretty.json +0 -120
- ethpm/ethpm-spec/examples/wallet/1.0.0.json +0 -1
- ethpm/ethpm-spec/examples/wallet/contracts/Wallet.sol +0 -41
- ethpm/ethpm-spec/examples/wallet/v3-pretty.json +0 -181
- ethpm/ethpm-spec/examples/wallet/v3.json +0 -1
- ethpm/ethpm-spec/examples/wallet-with-send/1.0.0-pretty.json +0 -135
- ethpm/ethpm-spec/examples/wallet-with-send/1.0.0.json +0 -1
- ethpm/ethpm-spec/examples/wallet-with-send/contracts/WalletWithSend.sol +0 -18
- ethpm/ethpm-spec/examples/wallet-with-send/v3-pretty.json +0 -207
- ethpm/ethpm-spec/examples/wallet-with-send/v3.json +0 -1
- ethpm/ethpm-spec/spec/package.spec.json +0 -379
- ethpm/ethpm-spec/spec/v3.spec.json +0 -483
- ethpm/exceptions.py +0 -68
- ethpm/package.py +0 -438
- ethpm/tools/__init__.py +0 -4
- ethpm/tools/builder.py +0 -930
- ethpm/tools/checker.py +0 -312
- ethpm/tools/get_manifest.py +0 -19
- ethpm/uri.py +0 -141
- ethpm/validation/__init__.py +0 -0
- ethpm/validation/manifest.py +0 -146
- ethpm/validation/misc.py +0 -39
- ethpm/validation/package.py +0 -80
- ethpm/validation/uri.py +0 -163
- web3/_utils/contract_sources/contract_data/address_reflector.py +0 -29
- web3/_utils/miner.py +0 -88
- web3/_utils/module_testing/go_ethereum_personal_module.py +0 -323
- web3/_utils/request.py +0 -265
- web3/middleware/abi.py +0 -11
- web3/middleware/async_cache.py +0 -99
- web3/middleware/cache.py +0 -374
- web3/middleware/exception_handling.py +0 -49
- web3/middleware/exception_retry_request.py +0 -188
- web3/middleware/fixture.py +0 -190
- web3/middleware/geth_poa.py +0 -81
- web3/middleware/normalize_request_parameters.py +0 -11
- web3/middleware/simulate_unmined_transaction.py +0 -43
- web3/pm.py +0 -602
- web3/providers/async_rpc.py +0 -99
- web3/providers/rpc.py +0 -98
- web3/providers/websocket/__init__.py +0 -11
- web3/providers/websocket/websocket_connection.py +0 -42
- web3/tools/__init__.py +0 -4
- web3/tools/pytest_ethereum/__init__.py +0 -0
- web3/tools/pytest_ethereum/_utils.py +0 -145
- web3/tools/pytest_ethereum/deployer.py +0 -48
- web3/tools/pytest_ethereum/exceptions.py +0 -22
- web3/tools/pytest_ethereum/linker.py +0 -128
- web3/tools/pytest_ethereum/plugins.py +0 -33
- web3-6.20.3.dist-info/METADATA +0 -104
- web3-6.20.3.dist-info/RECORD +0 -283
- web3-6.20.3.dist-info/entry_points.txt +0 -2
- /web3/_utils/{function_identifiers.py → abi_element_identifiers.py} +0 -0
- {web3-6.20.3.dist-info → web3-7.0.0.dist-info}/WHEEL +0 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import asyncio
|
|
1
2
|
import json
|
|
2
3
|
import math
|
|
3
4
|
import pytest
|
|
@@ -10,6 +11,7 @@ from typing import (
|
|
|
10
11
|
Any,
|
|
11
12
|
Callable,
|
|
12
13
|
List,
|
|
14
|
+
Type,
|
|
13
15
|
Union,
|
|
14
16
|
cast,
|
|
15
17
|
)
|
|
@@ -40,15 +42,15 @@ from hexbytes import (
|
|
|
40
42
|
HexBytes,
|
|
41
43
|
)
|
|
42
44
|
|
|
43
|
-
from web3._utils.empty import (
|
|
44
|
-
empty,
|
|
45
|
-
)
|
|
46
45
|
from web3._utils.ens import (
|
|
47
46
|
ens_addresses,
|
|
48
47
|
)
|
|
49
48
|
from web3._utils.error_formatters_utils import (
|
|
50
49
|
PANIC_ERROR_CODES,
|
|
51
50
|
)
|
|
51
|
+
from web3._utils.fee_utils import (
|
|
52
|
+
PRIORITY_FEE_MIN,
|
|
53
|
+
)
|
|
52
54
|
from web3._utils.method_formatters import (
|
|
53
55
|
to_hex_if_integer,
|
|
54
56
|
)
|
|
@@ -56,8 +58,12 @@ from web3._utils.module_testing.module_testing_utils import (
|
|
|
56
58
|
assert_contains_log,
|
|
57
59
|
async_mock_offchain_lookup_request_response,
|
|
58
60
|
flaky_geth_dev_mining,
|
|
61
|
+
flaky_with_xfail_on_exception,
|
|
59
62
|
mock_offchain_lookup_request_response,
|
|
60
63
|
)
|
|
64
|
+
from web3._utils.module_testing.utils import (
|
|
65
|
+
RequestMocker,
|
|
66
|
+
)
|
|
61
67
|
from web3._utils.type_conversion import (
|
|
62
68
|
to_hex_if_bytes,
|
|
63
69
|
)
|
|
@@ -71,27 +77,25 @@ from web3.exceptions import (
|
|
|
71
77
|
MultipleFailedRequests,
|
|
72
78
|
NameNotFound,
|
|
73
79
|
OffchainLookup,
|
|
80
|
+
RequestTimedOut,
|
|
74
81
|
TimeExhausted,
|
|
75
82
|
TooManyRequests,
|
|
76
83
|
TransactionNotFound,
|
|
77
84
|
TransactionTypeMismatch,
|
|
85
|
+
Web3RPCError,
|
|
78
86
|
Web3ValidationError,
|
|
87
|
+
Web3ValueError,
|
|
79
88
|
)
|
|
80
89
|
from web3.middleware import (
|
|
81
|
-
|
|
82
|
-
)
|
|
83
|
-
from web3.middleware.fixture import (
|
|
84
|
-
async_construct_error_generator_middleware,
|
|
85
|
-
async_construct_result_generator_middleware,
|
|
86
|
-
construct_error_generator_middleware,
|
|
90
|
+
ExtraDataToPOAMiddleware,
|
|
87
91
|
)
|
|
88
92
|
from web3.types import (
|
|
89
93
|
ENS,
|
|
90
94
|
BlockData,
|
|
91
|
-
CallOverrideParams,
|
|
92
95
|
FilterParams,
|
|
93
96
|
Nonce,
|
|
94
97
|
RPCEndpoint,
|
|
98
|
+
StateOverrideParams,
|
|
95
99
|
SyncStatus,
|
|
96
100
|
TxData,
|
|
97
101
|
TxParams,
|
|
@@ -177,11 +181,13 @@ class AsyncEthModuleTest:
|
|
|
177
181
|
|
|
178
182
|
@pytest.mark.asyncio
|
|
179
183
|
async def test_eth_send_transaction_legacy(
|
|
180
|
-
self,
|
|
184
|
+
self,
|
|
185
|
+
async_w3: "AsyncWeb3",
|
|
186
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
181
187
|
) -> None:
|
|
182
188
|
txn_params: TxParams = {
|
|
183
|
-
"from":
|
|
184
|
-
"to":
|
|
189
|
+
"from": async_keyfile_account_address_dual_type,
|
|
190
|
+
"to": async_keyfile_account_address_dual_type,
|
|
185
191
|
"value": Wei(1),
|
|
186
192
|
"gas": 21000,
|
|
187
193
|
"gasPrice": await async_w3.eth.gas_price,
|
|
@@ -197,11 +203,13 @@ class AsyncEthModuleTest:
|
|
|
197
203
|
|
|
198
204
|
@pytest.mark.asyncio
|
|
199
205
|
async def test_eth_modify_transaction_legacy(
|
|
200
|
-
self,
|
|
206
|
+
self,
|
|
207
|
+
async_w3: "AsyncWeb3",
|
|
208
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
201
209
|
) -> None:
|
|
202
210
|
txn_params: TxParams = {
|
|
203
|
-
"from":
|
|
204
|
-
"to":
|
|
211
|
+
"from": async_keyfile_account_address_dual_type,
|
|
212
|
+
"to": async_keyfile_account_address_dual_type,
|
|
205
213
|
"value": Wei(1),
|
|
206
214
|
"gas": 21000,
|
|
207
215
|
"gasPrice": async_w3.to_wei(
|
|
@@ -211,7 +219,7 @@ class AsyncEthModuleTest:
|
|
|
211
219
|
txn_hash = await async_w3.eth.send_transaction(txn_params)
|
|
212
220
|
|
|
213
221
|
modified_txn_hash = await async_w3.eth.modify_transaction(
|
|
214
|
-
txn_hash, gasPrice=(cast(
|
|
222
|
+
txn_hash, gasPrice=(cast(Wei, txn_params["gasPrice"] * 2)), value=Wei(2)
|
|
215
223
|
)
|
|
216
224
|
modified_txn = await async_w3.eth.get_transaction(modified_txn_hash)
|
|
217
225
|
|
|
@@ -227,11 +235,13 @@ class AsyncEthModuleTest:
|
|
|
227
235
|
|
|
228
236
|
@pytest.mark.asyncio
|
|
229
237
|
async def test_eth_modify_transaction(
|
|
230
|
-
self,
|
|
238
|
+
self,
|
|
239
|
+
async_w3: "AsyncWeb3",
|
|
240
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
231
241
|
) -> None:
|
|
232
242
|
txn_params: TxParams = {
|
|
233
|
-
"from":
|
|
234
|
-
"to":
|
|
243
|
+
"from": async_keyfile_account_address_dual_type,
|
|
244
|
+
"to": async_keyfile_account_address_dual_type,
|
|
235
245
|
"value": Wei(1),
|
|
236
246
|
"gas": 21000,
|
|
237
247
|
"maxPriorityFeePerGas": async_w3.to_wei(1, "gwei"),
|
|
@@ -241,9 +251,9 @@ class AsyncEthModuleTest:
|
|
|
241
251
|
|
|
242
252
|
modified_txn_hash = await async_w3.eth.modify_transaction(
|
|
243
253
|
txn_hash,
|
|
244
|
-
value=2,
|
|
245
|
-
maxPriorityFeePerGas=(cast(Wei, txn_params["maxPriorityFeePerGas"]
|
|
246
|
-
maxFeePerGas=(cast(Wei, txn_params["maxFeePerGas"]
|
|
254
|
+
value=Wei(2),
|
|
255
|
+
maxPriorityFeePerGas=(cast(Wei, txn_params["maxPriorityFeePerGas"] * 2)),
|
|
256
|
+
maxFeePerGas=(cast(Wei, txn_params["maxFeePerGas"] * 2)),
|
|
247
257
|
)
|
|
248
258
|
modified_txn = await async_w3.eth.get_transaction(modified_txn_hash)
|
|
249
259
|
|
|
@@ -263,11 +273,13 @@ class AsyncEthModuleTest:
|
|
|
263
273
|
|
|
264
274
|
@pytest.mark.asyncio
|
|
265
275
|
async def test_async_eth_sign_transaction(
|
|
266
|
-
self,
|
|
276
|
+
self,
|
|
277
|
+
async_w3: "AsyncWeb3",
|
|
278
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
267
279
|
) -> None:
|
|
268
280
|
txn_params: TxParams = {
|
|
269
|
-
"from":
|
|
270
|
-
"to":
|
|
281
|
+
"from": async_keyfile_account_address_dual_type,
|
|
282
|
+
"to": async_keyfile_account_address_dual_type,
|
|
271
283
|
"value": Wei(1),
|
|
272
284
|
"gas": 21000,
|
|
273
285
|
"maxFeePerGas": async_w3.to_wei(2, "gwei"),
|
|
@@ -276,7 +288,7 @@ class AsyncEthModuleTest:
|
|
|
276
288
|
}
|
|
277
289
|
result = await async_w3.eth.sign_transaction(txn_params)
|
|
278
290
|
signatory_account = async_w3.eth.account.recover_transaction(result["raw"])
|
|
279
|
-
assert
|
|
291
|
+
assert async_keyfile_account_address_dual_type == signatory_account
|
|
280
292
|
assert result["tx"]["to"] == txn_params["to"]
|
|
281
293
|
assert result["tx"]["value"] == txn_params["value"]
|
|
282
294
|
assert result["tx"]["gas"] == txn_params["gas"]
|
|
@@ -290,7 +302,7 @@ class AsyncEthModuleTest:
|
|
|
290
302
|
async def test_eth_sign_typed_data(
|
|
291
303
|
self,
|
|
292
304
|
async_w3: "AsyncWeb3",
|
|
293
|
-
|
|
305
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
294
306
|
async_skip_if_testrpc: Callable[["AsyncWeb3"], None],
|
|
295
307
|
) -> None:
|
|
296
308
|
validJSONMessage = """
|
|
@@ -335,7 +347,7 @@ class AsyncEthModuleTest:
|
|
|
335
347
|
async_skip_if_testrpc(async_w3)
|
|
336
348
|
signature = HexBytes(
|
|
337
349
|
await async_w3.eth.sign_typed_data(
|
|
338
|
-
|
|
350
|
+
async_keyfile_account_address_dual_type, json.loads(validJSONMessage)
|
|
339
351
|
)
|
|
340
352
|
)
|
|
341
353
|
assert len(signature) == 32 + 32 + 1
|
|
@@ -344,7 +356,7 @@ class AsyncEthModuleTest:
|
|
|
344
356
|
async def test_invalid_eth_sign_typed_data(
|
|
345
357
|
self,
|
|
346
358
|
async_w3: "AsyncWeb3",
|
|
347
|
-
|
|
359
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
348
360
|
async_skip_if_testrpc: Callable[["AsyncWeb3"], None],
|
|
349
361
|
) -> None:
|
|
350
362
|
async_skip_if_testrpc(async_w3)
|
|
@@ -388,20 +400,21 @@ class AsyncEthModuleTest:
|
|
|
388
400
|
}
|
|
389
401
|
"""
|
|
390
402
|
with pytest.raises(
|
|
391
|
-
|
|
403
|
+
Web3ValueError,
|
|
392
404
|
match=r".*Expected 2 items for array type Person\[2\], got 1 items.*",
|
|
393
405
|
):
|
|
394
406
|
await async_w3.eth.sign_typed_data(
|
|
395
|
-
|
|
407
|
+
async_keyfile_account_address_dual_type,
|
|
408
|
+
json.loads(invalid_typed_message),
|
|
396
409
|
)
|
|
397
410
|
|
|
398
411
|
@pytest.mark.asyncio
|
|
399
412
|
async def test_async_eth_sign_transaction_legacy(
|
|
400
|
-
self, async_w3: "AsyncWeb3",
|
|
413
|
+
self, async_w3: "AsyncWeb3", async_keyfile_account_address: ChecksumAddress
|
|
401
414
|
) -> None:
|
|
402
415
|
txn_params: TxParams = {
|
|
403
|
-
"from":
|
|
404
|
-
"to":
|
|
416
|
+
"from": async_keyfile_account_address,
|
|
417
|
+
"to": async_keyfile_account_address,
|
|
405
418
|
"value": Wei(1),
|
|
406
419
|
"gas": 21000,
|
|
407
420
|
"gasPrice": await async_w3.eth.gas_price,
|
|
@@ -409,7 +422,7 @@ class AsyncEthModuleTest:
|
|
|
409
422
|
}
|
|
410
423
|
result = await async_w3.eth.sign_transaction(txn_params)
|
|
411
424
|
signatory_account = async_w3.eth.account.recover_transaction(result["raw"])
|
|
412
|
-
assert
|
|
425
|
+
assert async_keyfile_account_address == signatory_account
|
|
413
426
|
assert result["tx"]["to"] == txn_params["to"]
|
|
414
427
|
assert result["tx"]["value"] == txn_params["value"]
|
|
415
428
|
assert result["tx"]["gas"] == txn_params["gas"]
|
|
@@ -418,11 +431,11 @@ class AsyncEthModuleTest:
|
|
|
418
431
|
|
|
419
432
|
@pytest.mark.asyncio
|
|
420
433
|
async def test_async_eth_sign_transaction_hex_fees(
|
|
421
|
-
self, async_w3: "AsyncWeb3",
|
|
434
|
+
self, async_w3: "AsyncWeb3", async_keyfile_account_address: ChecksumAddress
|
|
422
435
|
) -> None:
|
|
423
436
|
txn_params: TxParams = {
|
|
424
|
-
"from":
|
|
425
|
-
"to":
|
|
437
|
+
"from": async_keyfile_account_address,
|
|
438
|
+
"to": async_keyfile_account_address,
|
|
426
439
|
"value": Wei(1),
|
|
427
440
|
"gas": 21000,
|
|
428
441
|
"maxFeePerGas": hex(async_w3.to_wei(2, "gwei")),
|
|
@@ -431,7 +444,7 @@ class AsyncEthModuleTest:
|
|
|
431
444
|
}
|
|
432
445
|
result = await async_w3.eth.sign_transaction(txn_params)
|
|
433
446
|
signatory_account = async_w3.eth.account.recover_transaction(result["raw"])
|
|
434
|
-
assert
|
|
447
|
+
assert async_keyfile_account_address == signatory_account
|
|
435
448
|
assert result["tx"]["to"] == txn_params["to"]
|
|
436
449
|
assert result["tx"]["value"] == txn_params["value"]
|
|
437
450
|
assert result["tx"]["gas"] == txn_params["gas"]
|
|
@@ -446,9 +459,11 @@ class AsyncEthModuleTest:
|
|
|
446
459
|
reason="async name_to_address_middleware has not been implemented yet"
|
|
447
460
|
)
|
|
448
461
|
async def test_async_eth_sign_transaction_ens_names(
|
|
449
|
-
self, async_w3: "AsyncWeb3",
|
|
462
|
+
self, async_w3: "AsyncWeb3", async_keyfile_account_address: ChecksumAddress
|
|
450
463
|
) -> None:
|
|
451
|
-
with ens_addresses(
|
|
464
|
+
with ens_addresses(
|
|
465
|
+
async_w3, {"unlocked-account.eth": async_keyfile_account_address}
|
|
466
|
+
):
|
|
452
467
|
txn_params: TxParams = {
|
|
453
468
|
"from": "unlocked-account.eth",
|
|
454
469
|
"to": "unlocked-account.eth",
|
|
@@ -460,8 +475,8 @@ class AsyncEthModuleTest:
|
|
|
460
475
|
}
|
|
461
476
|
result = await async_w3.eth.sign_transaction(txn_params)
|
|
462
477
|
signatory_account = async_w3.eth.account.recover_transaction(result["raw"])
|
|
463
|
-
assert
|
|
464
|
-
assert result["tx"]["to"] ==
|
|
478
|
+
assert async_keyfile_account_address == signatory_account
|
|
479
|
+
assert result["tx"]["to"] == async_keyfile_account_address
|
|
465
480
|
assert result["tx"]["value"] == txn_params["value"]
|
|
466
481
|
assert result["tx"]["gas"] == txn_params["gas"]
|
|
467
482
|
assert result["tx"]["maxFeePerGas"] == txn_params["maxFeePerGas"]
|
|
@@ -473,16 +488,19 @@ class AsyncEthModuleTest:
|
|
|
473
488
|
|
|
474
489
|
@pytest.mark.asyncio
|
|
475
490
|
async def test_eth_send_transaction(
|
|
476
|
-
self,
|
|
491
|
+
self,
|
|
492
|
+
async_w3: "AsyncWeb3",
|
|
493
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
477
494
|
) -> None:
|
|
478
495
|
txn_params: TxParams = {
|
|
479
|
-
"from":
|
|
480
|
-
"to":
|
|
496
|
+
"from": async_keyfile_account_address_dual_type,
|
|
497
|
+
"to": async_keyfile_account_address_dual_type,
|
|
481
498
|
"value": Wei(1),
|
|
482
499
|
"gas": 21000,
|
|
483
500
|
"maxFeePerGas": async_w3.to_wei(3, "gwei"),
|
|
484
501
|
"maxPriorityFeePerGas": async_w3.to_wei(1, "gwei"),
|
|
485
502
|
}
|
|
503
|
+
|
|
486
504
|
txn_hash = await async_w3.eth.send_transaction(txn_params)
|
|
487
505
|
txn = await async_w3.eth.get_transaction(txn_hash)
|
|
488
506
|
|
|
@@ -492,18 +510,21 @@ class AsyncEthModuleTest:
|
|
|
492
510
|
assert txn["gas"] == 21000
|
|
493
511
|
assert txn["maxFeePerGas"] == txn_params["maxFeePerGas"]
|
|
494
512
|
assert txn["maxPriorityFeePerGas"] == txn_params["maxPriorityFeePerGas"]
|
|
495
|
-
assert txn["gasPrice"]
|
|
513
|
+
assert txn["gasPrice"] <= txn["maxFeePerGas"] # effective gas price
|
|
496
514
|
|
|
497
515
|
@pytest.mark.asyncio
|
|
498
516
|
async def test_eth_send_transaction_default_fees(
|
|
499
|
-
self,
|
|
517
|
+
self,
|
|
518
|
+
async_w3: "AsyncWeb3",
|
|
519
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
500
520
|
) -> None:
|
|
501
521
|
txn_params: TxParams = {
|
|
502
|
-
"from":
|
|
503
|
-
"to":
|
|
522
|
+
"from": async_keyfile_account_address_dual_type,
|
|
523
|
+
"to": async_keyfile_account_address_dual_type,
|
|
504
524
|
"value": Wei(1),
|
|
505
525
|
"gas": 21000,
|
|
506
526
|
}
|
|
527
|
+
|
|
507
528
|
txn_hash = await async_w3.eth.send_transaction(txn_params)
|
|
508
529
|
txn = await async_w3.eth.get_transaction(txn_hash)
|
|
509
530
|
|
|
@@ -513,15 +534,17 @@ class AsyncEthModuleTest:
|
|
|
513
534
|
assert txn["gas"] == 21000
|
|
514
535
|
assert is_integer(txn["maxPriorityFeePerGas"])
|
|
515
536
|
assert is_integer(txn["maxFeePerGas"])
|
|
516
|
-
assert txn["gasPrice"]
|
|
537
|
+
assert txn["gasPrice"] <= txn["maxFeePerGas"] # effective gas price
|
|
517
538
|
|
|
518
539
|
@pytest.mark.asyncio
|
|
519
540
|
async def test_eth_send_transaction_hex_fees(
|
|
520
|
-
self,
|
|
541
|
+
self,
|
|
542
|
+
async_w3: "AsyncWeb3",
|
|
543
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
521
544
|
) -> None:
|
|
522
545
|
txn_params: TxParams = {
|
|
523
|
-
"from":
|
|
524
|
-
"to":
|
|
546
|
+
"from": async_keyfile_account_address_dual_type,
|
|
547
|
+
"to": async_keyfile_account_address_dual_type,
|
|
525
548
|
"value": Wei(1),
|
|
526
549
|
"gas": 21000,
|
|
527
550
|
"maxFeePerGas": hex(250 * 10**9),
|
|
@@ -539,11 +562,13 @@ class AsyncEthModuleTest:
|
|
|
539
562
|
|
|
540
563
|
@pytest.mark.asyncio
|
|
541
564
|
async def test_eth_send_transaction_no_gas(
|
|
542
|
-
self,
|
|
565
|
+
self,
|
|
566
|
+
async_w3: "AsyncWeb3",
|
|
567
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
543
568
|
) -> None:
|
|
544
569
|
txn_params: TxParams = {
|
|
545
|
-
"from":
|
|
546
|
-
"to":
|
|
570
|
+
"from": async_keyfile_account_address_dual_type,
|
|
571
|
+
"to": async_keyfile_account_address_dual_type,
|
|
547
572
|
"value": Wei(1),
|
|
548
573
|
"maxFeePerGas": Wei(250 * 10**9),
|
|
549
574
|
"maxPriorityFeePerGas": Wei(2 * 10**9),
|
|
@@ -558,11 +583,13 @@ class AsyncEthModuleTest:
|
|
|
558
583
|
|
|
559
584
|
@pytest.mark.asyncio
|
|
560
585
|
async def test_eth_send_transaction_with_gas_price(
|
|
561
|
-
self,
|
|
586
|
+
self,
|
|
587
|
+
async_w3: "AsyncWeb3",
|
|
588
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
562
589
|
) -> None:
|
|
563
590
|
txn_params: TxParams = {
|
|
564
|
-
"from":
|
|
565
|
-
"to":
|
|
591
|
+
"from": async_keyfile_account_address_dual_type,
|
|
592
|
+
"to": async_keyfile_account_address_dual_type,
|
|
566
593
|
"value": Wei(1),
|
|
567
594
|
"gas": 21000,
|
|
568
595
|
"gasPrice": Wei(1),
|
|
@@ -574,11 +601,13 @@ class AsyncEthModuleTest:
|
|
|
574
601
|
|
|
575
602
|
@pytest.mark.asyncio
|
|
576
603
|
async def test_eth_send_transaction_no_priority_fee(
|
|
577
|
-
self,
|
|
604
|
+
self,
|
|
605
|
+
async_w3: "AsyncWeb3",
|
|
606
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
578
607
|
) -> None:
|
|
579
608
|
txn_params: TxParams = {
|
|
580
|
-
"from":
|
|
581
|
-
"to":
|
|
609
|
+
"from": async_keyfile_account_address_dual_type,
|
|
610
|
+
"to": async_keyfile_account_address_dual_type,
|
|
582
611
|
"value": Wei(1),
|
|
583
612
|
"gas": 21000,
|
|
584
613
|
"maxFeePerGas": Wei(250 * 10**9),
|
|
@@ -590,12 +619,14 @@ class AsyncEthModuleTest:
|
|
|
590
619
|
|
|
591
620
|
@pytest.mark.asyncio
|
|
592
621
|
async def test_eth_send_transaction_no_max_fee(
|
|
593
|
-
self,
|
|
622
|
+
self,
|
|
623
|
+
async_w3: "AsyncWeb3",
|
|
624
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
594
625
|
) -> None:
|
|
595
626
|
maxPriorityFeePerGas = async_w3.to_wei(2, "gwei")
|
|
596
627
|
txn_params: TxParams = {
|
|
597
|
-
"from":
|
|
598
|
-
"to":
|
|
628
|
+
"from": async_keyfile_account_address_dual_type,
|
|
629
|
+
"to": async_keyfile_account_address_dual_type,
|
|
599
630
|
"value": Wei(1),
|
|
600
631
|
"gas": 21000,
|
|
601
632
|
"maxPriorityFeePerGas": maxPriorityFeePerGas,
|
|
@@ -613,11 +644,13 @@ class AsyncEthModuleTest:
|
|
|
613
644
|
|
|
614
645
|
@pytest.mark.asyncio
|
|
615
646
|
async def test_eth_send_transaction_max_fee_less_than_tip(
|
|
616
|
-
self,
|
|
647
|
+
self,
|
|
648
|
+
async_w3: "AsyncWeb3",
|
|
649
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
617
650
|
) -> None:
|
|
618
651
|
txn_params: TxParams = {
|
|
619
|
-
"from":
|
|
620
|
-
"to":
|
|
652
|
+
"from": async_keyfile_account_address_dual_type,
|
|
653
|
+
"to": async_keyfile_account_address_dual_type,
|
|
621
654
|
"value": Wei(1),
|
|
622
655
|
"gas": 21000,
|
|
623
656
|
"maxFeePerGas": Wei(1 * 10**9),
|
|
@@ -630,14 +663,16 @@ class AsyncEthModuleTest:
|
|
|
630
663
|
|
|
631
664
|
@pytest.mark.asyncio
|
|
632
665
|
async def test_validation_middleware_chain_id_mismatch(
|
|
633
|
-
self,
|
|
666
|
+
self,
|
|
667
|
+
async_w3: "AsyncWeb3",
|
|
668
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
634
669
|
) -> None:
|
|
635
670
|
wrong_chain_id = 1234567890
|
|
636
671
|
actual_chain_id = await async_w3.eth.chain_id
|
|
637
672
|
|
|
638
673
|
txn_params: TxParams = {
|
|
639
|
-
"from":
|
|
640
|
-
"to":
|
|
674
|
+
"from": async_keyfile_account_address_dual_type,
|
|
675
|
+
"to": async_keyfile_account_address_dual_type,
|
|
641
676
|
"value": Wei(1),
|
|
642
677
|
"gas": 21000,
|
|
643
678
|
"maxFeePerGas": async_w3.to_wei(2, "gwei"),
|
|
@@ -652,52 +687,53 @@ class AsyncEthModuleTest:
|
|
|
652
687
|
await async_w3.eth.send_transaction(txn_params)
|
|
653
688
|
|
|
654
689
|
@pytest.mark.asyncio
|
|
655
|
-
async def
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
)
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
return_block_with_long_extra_data, "extradata", layer=0
|
|
668
|
-
)
|
|
669
|
-
block = await async_w3.eth.get_block("latest")
|
|
690
|
+
async def test_ExtraDataToPOAMiddleware(
|
|
691
|
+
self, async_w3: "AsyncWeb3", request_mocker: Type[RequestMocker]
|
|
692
|
+
) -> None:
|
|
693
|
+
async_w3.middleware_onion.inject(ExtraDataToPOAMiddleware, "poa", layer=0)
|
|
694
|
+
extra_data = f"0x{'ff' * 33}"
|
|
695
|
+
|
|
696
|
+
async with request_mocker(
|
|
697
|
+
async_w3,
|
|
698
|
+
mock_results={"eth_getBlockByNumber": {"extraData": extra_data}},
|
|
699
|
+
):
|
|
700
|
+
block = await async_w3.eth.get_block("latest")
|
|
701
|
+
|
|
670
702
|
assert "extraData" not in block
|
|
671
|
-
assert block["proofOfAuthorityData"] ==
|
|
703
|
+
assert block["proofOfAuthorityData"] == to_bytes(hexstr=extra_data)
|
|
672
704
|
|
|
673
705
|
# clean up
|
|
674
706
|
async_w3.middleware_onion.remove("poa")
|
|
675
|
-
async_w3.middleware_onion.remove("extradata")
|
|
676
707
|
|
|
677
708
|
@pytest.mark.asyncio
|
|
678
|
-
async def
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
"
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
709
|
+
async def test_async_eth_send_raw_transaction(
|
|
710
|
+
self, async_w3: "AsyncWeb3", keyfile_account_pkey: HexStr
|
|
711
|
+
) -> None:
|
|
712
|
+
keyfile_account = async_w3.eth.account.from_key(keyfile_account_pkey)
|
|
713
|
+
txn = {
|
|
714
|
+
"chainId": 131277322940537, # the chainId set for the fixture
|
|
715
|
+
"from": keyfile_account.address,
|
|
716
|
+
"to": keyfile_account.address,
|
|
717
|
+
"value": Wei(0),
|
|
718
|
+
"gas": 21000,
|
|
719
|
+
"nonce": await async_w3.eth.get_transaction_count(
|
|
720
|
+
keyfile_account.address, "pending"
|
|
721
|
+
),
|
|
722
|
+
"gasPrice": 10**9,
|
|
723
|
+
}
|
|
724
|
+
signed = keyfile_account.sign_transaction(txn)
|
|
725
|
+
txn_hash = await async_w3.eth.send_raw_transaction(signed.raw_transaction)
|
|
726
|
+
assert txn_hash == HexBytes(signed.hash)
|
|
693
727
|
|
|
694
728
|
@pytest.mark.asyncio
|
|
695
|
-
async def
|
|
696
|
-
self,
|
|
729
|
+
async def test_GasPriceStrategyMiddleware(
|
|
730
|
+
self,
|
|
731
|
+
async_w3: "AsyncWeb3",
|
|
732
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
697
733
|
) -> None:
|
|
698
734
|
txn_params: TxParams = {
|
|
699
|
-
"from":
|
|
700
|
-
"to":
|
|
735
|
+
"from": async_keyfile_account_address_dual_type,
|
|
736
|
+
"to": async_keyfile_account_address_dual_type,
|
|
701
737
|
"value": Wei(1),
|
|
702
738
|
"gas": 21000,
|
|
703
739
|
}
|
|
@@ -716,11 +752,13 @@ class AsyncEthModuleTest:
|
|
|
716
752
|
|
|
717
753
|
@pytest.mark.asyncio
|
|
718
754
|
async def test_gas_price_strategy_middleware_hex_value(
|
|
719
|
-
self,
|
|
755
|
+
self,
|
|
756
|
+
async_w3: "AsyncWeb3",
|
|
757
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
720
758
|
) -> None:
|
|
721
759
|
txn_params: TxParams = {
|
|
722
|
-
"from":
|
|
723
|
-
"to":
|
|
760
|
+
"from": async_keyfile_account_address_dual_type,
|
|
761
|
+
"to": async_keyfile_account_address_dual_type,
|
|
724
762
|
"value": Wei(1),
|
|
725
763
|
"gas": 21000,
|
|
726
764
|
}
|
|
@@ -744,13 +782,13 @@ class AsyncEthModuleTest:
|
|
|
744
782
|
async def test_gas_price_from_strategy_bypassed_for_dynamic_fee_txn(
|
|
745
783
|
self,
|
|
746
784
|
async_w3: "AsyncWeb3",
|
|
747
|
-
|
|
785
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
748
786
|
max_fee: Wei,
|
|
749
787
|
) -> None:
|
|
750
788
|
max_priority_fee = async_w3.to_wei(1, "gwei")
|
|
751
789
|
txn_params: TxParams = {
|
|
752
|
-
"from":
|
|
753
|
-
"to":
|
|
790
|
+
"from": async_keyfile_account_address_dual_type,
|
|
791
|
+
"to": async_keyfile_account_address_dual_type,
|
|
754
792
|
"value": Wei(1),
|
|
755
793
|
"gas": 21000,
|
|
756
794
|
"maxPriorityFeePerGas": max_priority_fee,
|
|
@@ -773,7 +811,7 @@ class AsyncEthModuleTest:
|
|
|
773
811
|
else 2 * latest_block["baseFeePerGas"] + max_priority_fee
|
|
774
812
|
)
|
|
775
813
|
assert txn["maxPriorityFeePerGas"] == max_priority_fee
|
|
776
|
-
assert txn["gasPrice"]
|
|
814
|
+
assert txn["gasPrice"] <= txn["maxFeePerGas"] # effective gas price
|
|
777
815
|
|
|
778
816
|
async_w3.eth.set_gas_price_strategy(None) # reset strategy
|
|
779
817
|
|
|
@@ -781,11 +819,11 @@ class AsyncEthModuleTest:
|
|
|
781
819
|
async def test_gas_price_from_strategy_bypassed_for_dynamic_fee_txn_no_tip(
|
|
782
820
|
self,
|
|
783
821
|
async_w3: "AsyncWeb3",
|
|
784
|
-
|
|
822
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
785
823
|
) -> None:
|
|
786
824
|
txn_params: TxParams = {
|
|
787
|
-
"from":
|
|
788
|
-
"to":
|
|
825
|
+
"from": async_keyfile_account_address_dual_type,
|
|
826
|
+
"to": async_keyfile_account_address_dual_type,
|
|
789
827
|
"value": Wei(1),
|
|
790
828
|
"gas": 21000,
|
|
791
829
|
"maxFeePerGas": Wei(1000000000),
|
|
@@ -805,12 +843,14 @@ class AsyncEthModuleTest:
|
|
|
805
843
|
|
|
806
844
|
@pytest.mark.asyncio
|
|
807
845
|
async def test_eth_estimate_gas(
|
|
808
|
-
self,
|
|
846
|
+
self,
|
|
847
|
+
async_w3: "AsyncWeb3",
|
|
848
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
809
849
|
) -> None:
|
|
810
850
|
gas_estimate = await async_w3.eth.estimate_gas(
|
|
811
851
|
{
|
|
812
|
-
"from":
|
|
813
|
-
"to":
|
|
852
|
+
"from": async_keyfile_account_address_dual_type,
|
|
853
|
+
"to": async_keyfile_account_address_dual_type,
|
|
814
854
|
"value": Wei(1),
|
|
815
855
|
}
|
|
816
856
|
)
|
|
@@ -841,9 +881,10 @@ class AsyncEthModuleTest:
|
|
|
841
881
|
self,
|
|
842
882
|
async_w3: "AsyncWeb3",
|
|
843
883
|
async_math_contract: "AsyncContract",
|
|
844
|
-
params:
|
|
884
|
+
params: StateOverrideParams,
|
|
845
885
|
) -> None:
|
|
846
|
-
|
|
886
|
+
accounts = await async_w3.eth.accounts
|
|
887
|
+
txn_params: TxParams = {"from": accounts[0]}
|
|
847
888
|
|
|
848
889
|
# assert does not raise
|
|
849
890
|
await async_w3.eth.estimate_gas(
|
|
@@ -891,60 +932,25 @@ class AsyncEthModuleTest:
|
|
|
891
932
|
max_priority_fee = await async_w3.eth.max_priority_fee
|
|
892
933
|
assert is_integer(max_priority_fee)
|
|
893
934
|
|
|
894
|
-
@pytest.mark.asyncio
|
|
895
|
-
async def test_eth_max_priority_fee_with_fee_history_calculation_error_dict(
|
|
896
|
-
self, async_w3: "AsyncWeb3"
|
|
897
|
-
) -> None:
|
|
898
|
-
fail_max_prio_middleware = await async_construct_error_generator_middleware(
|
|
899
|
-
{
|
|
900
|
-
RPCEndpoint("eth_maxPriorityFeePerGas"): lambda *_: {
|
|
901
|
-
"error": {
|
|
902
|
-
"code": -32601,
|
|
903
|
-
"message": (
|
|
904
|
-
"The method eth_maxPriorityFeePerGas does "
|
|
905
|
-
"not exist/is not available"
|
|
906
|
-
),
|
|
907
|
-
}
|
|
908
|
-
}
|
|
909
|
-
}
|
|
910
|
-
)
|
|
911
|
-
async_w3.middleware_onion.add(
|
|
912
|
-
fail_max_prio_middleware, name="fail_max_prio_middleware"
|
|
913
|
-
)
|
|
914
|
-
|
|
915
|
-
with pytest.warns(
|
|
916
|
-
UserWarning,
|
|
917
|
-
match=(
|
|
918
|
-
"There was an issue with the method eth_maxPriorityFeePerGas."
|
|
919
|
-
" Calculating using eth_feeHistory."
|
|
920
|
-
),
|
|
921
|
-
):
|
|
922
|
-
await async_w3.eth.max_priority_fee
|
|
923
|
-
|
|
924
|
-
async_w3.middleware_onion.remove("fail_max_prio_middleware") # clean up
|
|
925
|
-
|
|
926
935
|
@pytest.mark.asyncio
|
|
927
936
|
async def test_eth_max_priority_fee_with_fee_history_calculation(
|
|
928
|
-
self, async_w3: "AsyncWeb3"
|
|
937
|
+
self, async_w3: "AsyncWeb3", request_mocker: Type[RequestMocker]
|
|
929
938
|
) -> None:
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
fail_max_prio_middleware, name="fail_max_prio_middleware"
|
|
935
|
-
)
|
|
936
|
-
|
|
937
|
-
with pytest.warns(
|
|
938
|
-
UserWarning,
|
|
939
|
-
match=(
|
|
940
|
-
"There was an issue with the method eth_maxPriorityFeePerGas. "
|
|
941
|
-
"Calculating using eth_feeHistory."
|
|
942
|
-
),
|
|
939
|
+
async with request_mocker(
|
|
940
|
+
async_w3,
|
|
941
|
+
mock_errors={RPCEndpoint("eth_maxPriorityFeePerGas"): {}},
|
|
942
|
+
mock_results={RPCEndpoint("eth_feeHistory"): {"reward": [[0]]}},
|
|
943
943
|
):
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
944
|
+
with pytest.warns(
|
|
945
|
+
UserWarning,
|
|
946
|
+
match=(
|
|
947
|
+
"There was an issue with the method eth_maxPriorityFeePerGas. "
|
|
948
|
+
"Calculating using eth_feeHistory."
|
|
949
|
+
),
|
|
950
|
+
):
|
|
951
|
+
priority_fee = await async_w3.eth.max_priority_fee
|
|
952
|
+
assert is_integer(priority_fee)
|
|
953
|
+
assert priority_fee == PRIORITY_FEE_MIN
|
|
948
954
|
|
|
949
955
|
@pytest.mark.asyncio
|
|
950
956
|
async def test_eth_getBlockByHash(
|
|
@@ -974,9 +980,8 @@ class AsyncEthModuleTest:
|
|
|
974
980
|
async def test_eth_getBlockByNumber_latest(
|
|
975
981
|
self, async_w3: "AsyncWeb3", async_empty_block: BlockData
|
|
976
982
|
) -> None:
|
|
977
|
-
current_block_number = await async_w3.eth.block_number
|
|
978
983
|
block = await async_w3.eth.get_block("latest")
|
|
979
|
-
assert block["
|
|
984
|
+
assert block["hash"] is not None
|
|
980
985
|
|
|
981
986
|
@pytest.mark.asyncio
|
|
982
987
|
async def test_eth_getBlockByNumber_not_found(
|
|
@@ -989,9 +994,8 @@ class AsyncEthModuleTest:
|
|
|
989
994
|
async def test_eth_getBlockByNumber_pending(
|
|
990
995
|
self, async_w3: "AsyncWeb3", async_empty_block: BlockData
|
|
991
996
|
) -> None:
|
|
992
|
-
current_block_number = await async_w3.eth.block_number
|
|
993
997
|
block = await async_w3.eth.get_block("pending")
|
|
994
|
-
assert block["
|
|
998
|
+
assert block["hash"] is None
|
|
995
999
|
|
|
996
1000
|
@pytest.mark.asyncio
|
|
997
1001
|
async def test_eth_getBlockByNumber_earliest(
|
|
@@ -1018,6 +1022,39 @@ class AsyncEthModuleTest:
|
|
|
1018
1022
|
assert block is not None
|
|
1019
1023
|
assert isinstance(block["number"], int)
|
|
1020
1024
|
|
|
1025
|
+
@pytest.mark.asyncio
|
|
1026
|
+
async def test_eth_getBlockReceipts_hash(
|
|
1027
|
+
self, async_w3: "AsyncWeb3", async_empty_block: BlockData
|
|
1028
|
+
) -> None:
|
|
1029
|
+
receipts = await async_w3.eth.get_block_receipts(async_empty_block["hash"])
|
|
1030
|
+
assert isinstance(receipts, list)
|
|
1031
|
+
|
|
1032
|
+
@pytest.mark.asyncio
|
|
1033
|
+
async def test_eth_getBlockReceipts_not_found(self, async_w3: "AsyncWeb3") -> None:
|
|
1034
|
+
with pytest.raises(BlockNotFound):
|
|
1035
|
+
await async_w3.eth.get_block_receipts(UNKNOWN_HASH)
|
|
1036
|
+
|
|
1037
|
+
@pytest.mark.asyncio
|
|
1038
|
+
async def test_eth_getBlockReceipts_with_integer(
|
|
1039
|
+
self, async_w3: "AsyncWeb3", async_empty_block: BlockData
|
|
1040
|
+
) -> None:
|
|
1041
|
+
receipts = await async_w3.eth.get_block_receipts(async_empty_block["number"])
|
|
1042
|
+
assert isinstance(receipts, list)
|
|
1043
|
+
|
|
1044
|
+
@pytest.mark.asyncio
|
|
1045
|
+
async def test_eth_getBlockReceipts_safe(
|
|
1046
|
+
self, async_w3: "AsyncWeb3", async_empty_block: BlockData
|
|
1047
|
+
) -> None:
|
|
1048
|
+
receipts = await async_w3.eth.get_block_receipts("safe")
|
|
1049
|
+
assert isinstance(receipts, list)
|
|
1050
|
+
|
|
1051
|
+
@pytest.mark.asyncio
|
|
1052
|
+
async def test_eth_getBlockReceipts_finalized(
|
|
1053
|
+
self, async_w3: "AsyncWeb3", async_empty_block: BlockData
|
|
1054
|
+
) -> None:
|
|
1055
|
+
receipts = await async_w3.eth.get_block_receipts("finalized")
|
|
1056
|
+
assert isinstance(receipts, list)
|
|
1057
|
+
|
|
1021
1058
|
@pytest.mark.asyncio
|
|
1022
1059
|
async def test_eth_get_block_by_number_full_transactions(
|
|
1023
1060
|
self, async_w3: "AsyncWeb3", async_block_with_txn: BlockData
|
|
@@ -1047,22 +1084,26 @@ class AsyncEthModuleTest:
|
|
|
1047
1084
|
self,
|
|
1048
1085
|
async_w3: "AsyncWeb3",
|
|
1049
1086
|
async_block_with_txn: BlockData,
|
|
1050
|
-
|
|
1087
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
1051
1088
|
) -> None:
|
|
1052
1089
|
# eth_getRawTransactionByBlockNumberAndIndex: block identifier
|
|
1053
|
-
# send a txn to make sure pending block has at least one txn
|
|
1054
1090
|
await async_w3.eth.send_transaction(
|
|
1055
1091
|
{
|
|
1056
|
-
"from":
|
|
1057
|
-
"to":
|
|
1092
|
+
"from": async_keyfile_account_address_dual_type,
|
|
1093
|
+
"to": async_keyfile_account_address_dual_type,
|
|
1058
1094
|
"value": Wei(1),
|
|
1059
1095
|
}
|
|
1060
1096
|
)
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1097
|
+
|
|
1098
|
+
async def wait_for_block_with_txn() -> HexBytes:
|
|
1099
|
+
while True:
|
|
1100
|
+
try:
|
|
1101
|
+
return await async_w3.eth.get_raw_transaction_by_block("latest", 0)
|
|
1102
|
+
except TransactionNotFound:
|
|
1103
|
+
await asyncio.sleep(0.1)
|
|
1104
|
+
continue
|
|
1105
|
+
|
|
1106
|
+
raw_txn = await asyncio.wait_for(wait_for_block_with_txn(), timeout=5)
|
|
1066
1107
|
assert is_bytes(raw_txn)
|
|
1067
1108
|
|
|
1068
1109
|
# eth_getRawTransactionByBlockNumberAndIndex: block number
|
|
@@ -1102,26 +1143,26 @@ class AsyncEthModuleTest:
|
|
|
1102
1143
|
) -> None:
|
|
1103
1144
|
unknown_identifier = "unknown"
|
|
1104
1145
|
with pytest.raises(
|
|
1105
|
-
|
|
1146
|
+
Web3ValueError,
|
|
1106
1147
|
match=(
|
|
1107
1148
|
"Value did not match any of the recognized block identifiers: "
|
|
1108
1149
|
f"{unknown_identifier}"
|
|
1109
1150
|
),
|
|
1110
1151
|
):
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
)
|
|
1152
|
+
# type ignored because we are testing an invalid block identifier
|
|
1153
|
+
await async_w3.eth.get_raw_transaction_by_block(unknown_identifier, 0) # type: ignore # noqa: E501
|
|
1114
1154
|
|
|
1115
1155
|
@pytest.mark.asyncio
|
|
1116
1156
|
async def test_eth_get_balance(self, async_w3: "AsyncWeb3") -> None:
|
|
1117
|
-
|
|
1157
|
+
accounts = await async_w3.eth.accounts
|
|
1158
|
+
account = accounts[0]
|
|
1118
1159
|
|
|
1119
1160
|
with pytest.raises(InvalidAddress):
|
|
1120
1161
|
await async_w3.eth.get_balance(
|
|
1121
|
-
ChecksumAddress(HexAddress(HexStr(
|
|
1162
|
+
ChecksumAddress(HexAddress(HexStr(account.lower())))
|
|
1122
1163
|
)
|
|
1123
1164
|
|
|
1124
|
-
balance = await async_w3.eth.get_balance(
|
|
1165
|
+
balance = await async_w3.eth.get_balance(account)
|
|
1125
1166
|
|
|
1126
1167
|
assert is_integer(balance)
|
|
1127
1168
|
assert balance >= 0
|
|
@@ -1158,12 +1199,12 @@ class AsyncEthModuleTest:
|
|
|
1158
1199
|
async def test_eth_create_access_list(
|
|
1159
1200
|
self,
|
|
1160
1201
|
async_w3: "AsyncWeb3",
|
|
1161
|
-
|
|
1202
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
1162
1203
|
async_math_contract: "AsyncContract",
|
|
1163
1204
|
) -> None:
|
|
1164
1205
|
# build txn
|
|
1165
1206
|
txn = await async_math_contract.functions.incrementCounter(1).build_transaction(
|
|
1166
|
-
{"from":
|
|
1207
|
+
{"from": async_keyfile_account_address_dual_type}
|
|
1167
1208
|
)
|
|
1168
1209
|
|
|
1169
1210
|
# create access list
|
|
@@ -1174,7 +1215,7 @@ class AsyncEthModuleTest:
|
|
|
1174
1215
|
assert len(access_list) > 0
|
|
1175
1216
|
assert access_list[0]["address"] is not None
|
|
1176
1217
|
assert is_checksum_address(access_list[0]["address"])
|
|
1177
|
-
assert len(access_list[0]["storageKeys"][0]) ==
|
|
1218
|
+
assert len(access_list[0]["storageKeys"][0]) == 66
|
|
1178
1219
|
assert int(response["gasUsed"]) >= 0
|
|
1179
1220
|
|
|
1180
1221
|
# assert the result can be used directly in a transaction dict
|
|
@@ -1186,10 +1227,12 @@ class AsyncEthModuleTest:
|
|
|
1186
1227
|
|
|
1187
1228
|
@pytest.mark.asyncio
|
|
1188
1229
|
async def test_eth_get_transaction_count(
|
|
1189
|
-
self,
|
|
1230
|
+
self,
|
|
1231
|
+
async_w3: "AsyncWeb3",
|
|
1232
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
1190
1233
|
) -> None:
|
|
1191
1234
|
transaction_count = await async_w3.eth.get_transaction_count(
|
|
1192
|
-
|
|
1235
|
+
async_keyfile_account_address_dual_type
|
|
1193
1236
|
)
|
|
1194
1237
|
assert is_integer(transaction_count)
|
|
1195
1238
|
assert transaction_count >= 0
|
|
@@ -1198,11 +1241,13 @@ class AsyncEthModuleTest:
|
|
|
1198
1241
|
async def test_eth_call(
|
|
1199
1242
|
self, async_w3: "AsyncWeb3", async_math_contract: "AsyncContract"
|
|
1200
1243
|
) -> None:
|
|
1201
|
-
|
|
1244
|
+
accounts = await async_w3.eth.accounts
|
|
1245
|
+
account = accounts[0]
|
|
1246
|
+
|
|
1202
1247
|
txn_params = async_math_contract._prepare_transaction(
|
|
1203
|
-
|
|
1248
|
+
abi_element_identifier="add",
|
|
1204
1249
|
fn_args=(7, 11),
|
|
1205
|
-
transaction={"from":
|
|
1250
|
+
transaction={"from": account, "to": async_math_contract.address},
|
|
1206
1251
|
)
|
|
1207
1252
|
call_result = await async_w3.eth.call(txn_params)
|
|
1208
1253
|
assert is_string(call_result)
|
|
@@ -1215,10 +1260,11 @@ class AsyncEthModuleTest:
|
|
|
1215
1260
|
async_w3: "AsyncWeb3",
|
|
1216
1261
|
async_revert_contract: "AsyncContract",
|
|
1217
1262
|
) -> None:
|
|
1218
|
-
|
|
1263
|
+
accounts = await async_w3.eth.accounts
|
|
1264
|
+
account = accounts[0]
|
|
1219
1265
|
txn_params = async_revert_contract._prepare_transaction(
|
|
1220
|
-
|
|
1221
|
-
transaction={"from":
|
|
1266
|
+
abi_element_identifier="normalFunction",
|
|
1267
|
+
transaction={"from": account, "to": async_revert_contract.address},
|
|
1222
1268
|
)
|
|
1223
1269
|
call_result = await async_w3.eth.call(txn_params)
|
|
1224
1270
|
(result,) = async_w3.codec.decode(["bool"], call_result)
|
|
@@ -1270,10 +1316,10 @@ class AsyncEthModuleTest:
|
|
|
1270
1316
|
self,
|
|
1271
1317
|
async_w3: "AsyncWeb3",
|
|
1272
1318
|
async_math_contract: "AsyncContract",
|
|
1273
|
-
params:
|
|
1319
|
+
params: StateOverrideParams,
|
|
1274
1320
|
) -> None:
|
|
1275
|
-
|
|
1276
|
-
txn_params: TxParams = {"from":
|
|
1321
|
+
accounts = await async_w3.eth.accounts
|
|
1322
|
+
txn_params: TxParams = {"from": accounts[0]}
|
|
1277
1323
|
|
|
1278
1324
|
# assert does not raise
|
|
1279
1325
|
await async_w3.eth.call(
|
|
@@ -1284,11 +1330,11 @@ class AsyncEthModuleTest:
|
|
|
1284
1330
|
async def test_eth_call_with_0_result(
|
|
1285
1331
|
self, async_w3: "AsyncWeb3", async_math_contract: "AsyncContract"
|
|
1286
1332
|
) -> None:
|
|
1287
|
-
|
|
1333
|
+
accounts = await async_w3.eth.accounts
|
|
1288
1334
|
txn_params = async_math_contract._prepare_transaction(
|
|
1289
|
-
|
|
1335
|
+
abi_element_identifier="add",
|
|
1290
1336
|
fn_args=(0, 0),
|
|
1291
|
-
transaction={"from":
|
|
1337
|
+
transaction={"from": accounts[0], "to": async_math_contract.address},
|
|
1292
1338
|
)
|
|
1293
1339
|
call_result = await async_w3.eth.call(txn_params)
|
|
1294
1340
|
assert is_string(call_result)
|
|
@@ -1300,12 +1346,12 @@ class AsyncEthModuleTest:
|
|
|
1300
1346
|
self,
|
|
1301
1347
|
async_w3: "AsyncWeb3",
|
|
1302
1348
|
async_revert_contract: "AsyncContract",
|
|
1303
|
-
|
|
1349
|
+
async_keyfile_account_address: ChecksumAddress,
|
|
1304
1350
|
) -> None:
|
|
1305
1351
|
txn_params = async_revert_contract._prepare_transaction(
|
|
1306
|
-
|
|
1352
|
+
abi_element_identifier="revertWithMessage",
|
|
1307
1353
|
transaction={
|
|
1308
|
-
"from":
|
|
1354
|
+
"from": async_keyfile_account_address,
|
|
1309
1355
|
"to": async_revert_contract.address,
|
|
1310
1356
|
},
|
|
1311
1357
|
)
|
|
@@ -1319,13 +1365,13 @@ class AsyncEthModuleTest:
|
|
|
1319
1365
|
self,
|
|
1320
1366
|
async_w3: "AsyncWeb3",
|
|
1321
1367
|
async_revert_contract: "AsyncContract",
|
|
1322
|
-
|
|
1368
|
+
async_keyfile_account_address: ChecksumAddress,
|
|
1323
1369
|
) -> None:
|
|
1324
1370
|
with pytest.raises(ContractLogicError, match="execution reverted"):
|
|
1325
1371
|
txn_params = async_revert_contract._prepare_transaction(
|
|
1326
|
-
|
|
1372
|
+
abi_element_identifier="revertWithoutMessage",
|
|
1327
1373
|
transaction={
|
|
1328
|
-
"from":
|
|
1374
|
+
"from": async_keyfile_account_address,
|
|
1329
1375
|
"to": async_revert_contract.address,
|
|
1330
1376
|
},
|
|
1331
1377
|
)
|
|
@@ -1336,15 +1382,16 @@ class AsyncEthModuleTest:
|
|
|
1336
1382
|
self,
|
|
1337
1383
|
async_w3: "AsyncWeb3",
|
|
1338
1384
|
async_revert_contract: "AsyncContract",
|
|
1339
|
-
|
|
1385
|
+
async_keyfile_account_address: ChecksumAddress,
|
|
1340
1386
|
) -> None:
|
|
1341
1387
|
data = async_revert_contract.encode_abi(
|
|
1342
|
-
|
|
1388
|
+
abi_element_identifier="UnauthorizedWithMessage",
|
|
1389
|
+
args=["You are not authorized"],
|
|
1343
1390
|
)
|
|
1344
1391
|
txn_params = async_revert_contract._prepare_transaction(
|
|
1345
|
-
|
|
1392
|
+
abi_element_identifier="customErrorWithMessage",
|
|
1346
1393
|
transaction={
|
|
1347
|
-
"from":
|
|
1394
|
+
"from": async_keyfile_account_address,
|
|
1348
1395
|
"to": async_revert_contract.address,
|
|
1349
1396
|
},
|
|
1350
1397
|
)
|
|
@@ -1356,13 +1403,13 @@ class AsyncEthModuleTest:
|
|
|
1356
1403
|
self,
|
|
1357
1404
|
async_w3: "AsyncWeb3",
|
|
1358
1405
|
async_revert_contract: "AsyncContract",
|
|
1359
|
-
|
|
1406
|
+
async_keyfile_account_address: ChecksumAddress,
|
|
1360
1407
|
) -> None:
|
|
1361
|
-
data = async_revert_contract.encode_abi(
|
|
1408
|
+
data = async_revert_contract.encode_abi(abi_element_identifier="Unauthorized")
|
|
1362
1409
|
txn_params = async_revert_contract._prepare_transaction(
|
|
1363
|
-
|
|
1410
|
+
abi_element_identifier="customErrorWithoutMessage",
|
|
1364
1411
|
transaction={
|
|
1365
|
-
"from":
|
|
1412
|
+
"from": async_keyfile_account_address,
|
|
1366
1413
|
"to": async_revert_contract.address,
|
|
1367
1414
|
},
|
|
1368
1415
|
)
|
|
@@ -1405,7 +1452,7 @@ class AsyncEthModuleTest:
|
|
|
1405
1452
|
self,
|
|
1406
1453
|
async_w3: "AsyncWeb3",
|
|
1407
1454
|
async_offchain_lookup_contract: "AsyncContract",
|
|
1408
|
-
|
|
1455
|
+
async_keyfile_account_address: ChecksumAddress,
|
|
1409
1456
|
monkeypatch: "MonkeyPatch",
|
|
1410
1457
|
) -> None:
|
|
1411
1458
|
normalized_contract_address = to_hex_if_bytes(
|
|
@@ -1469,7 +1516,7 @@ class AsyncEthModuleTest:
|
|
|
1469
1516
|
self,
|
|
1470
1517
|
async_w3: "AsyncWeb3",
|
|
1471
1518
|
async_offchain_lookup_contract: "AsyncContract",
|
|
1472
|
-
|
|
1519
|
+
async_keyfile_account_address: ChecksumAddress,
|
|
1473
1520
|
monkeypatch: "MonkeyPatch",
|
|
1474
1521
|
) -> None:
|
|
1475
1522
|
normalized_contract_address = to_hex_if_bytes(
|
|
@@ -1502,7 +1549,7 @@ class AsyncEthModuleTest:
|
|
|
1502
1549
|
default_max_redirects = async_w3.provider.ccip_read_max_redirects
|
|
1503
1550
|
|
|
1504
1551
|
async_w3.provider.ccip_read_max_redirects = max_redirects
|
|
1505
|
-
with pytest.raises(
|
|
1552
|
+
with pytest.raises(Web3ValueError, match="at least 4"):
|
|
1506
1553
|
await async_offchain_lookup_contract.caller().testOffchainLookup(
|
|
1507
1554
|
OFFCHAIN_LOOKUP_TEST_DATA
|
|
1508
1555
|
)
|
|
@@ -1514,7 +1561,7 @@ class AsyncEthModuleTest:
|
|
|
1514
1561
|
self,
|
|
1515
1562
|
async_w3: "AsyncWeb3",
|
|
1516
1563
|
async_offchain_lookup_contract: "AsyncContract",
|
|
1517
|
-
|
|
1564
|
+
async_keyfile_account_address: ChecksumAddress,
|
|
1518
1565
|
monkeypatch: "MonkeyPatch",
|
|
1519
1566
|
) -> None:
|
|
1520
1567
|
normalized_contract_address = to_hex_if_bytes(
|
|
@@ -1538,7 +1585,7 @@ class AsyncEthModuleTest:
|
|
|
1538
1585
|
self,
|
|
1539
1586
|
async_w3: "AsyncWeb3",
|
|
1540
1587
|
async_offchain_lookup_contract: "AsyncContract",
|
|
1541
|
-
|
|
1588
|
+
async_keyfile_account_address: ChecksumAddress,
|
|
1542
1589
|
monkeypatch: "MonkeyPatch",
|
|
1543
1590
|
status_code_non_4xx_error: int,
|
|
1544
1591
|
) -> None:
|
|
@@ -1576,7 +1623,7 @@ class AsyncEthModuleTest:
|
|
|
1576
1623
|
self,
|
|
1577
1624
|
async_w3: "AsyncWeb3",
|
|
1578
1625
|
async_offchain_lookup_contract: "AsyncContract",
|
|
1579
|
-
|
|
1626
|
+
async_keyfile_account_address: ChecksumAddress,
|
|
1580
1627
|
monkeypatch: "MonkeyPatch",
|
|
1581
1628
|
) -> None:
|
|
1582
1629
|
normalized_contract_address = to_hex_if_bytes(
|
|
@@ -1597,7 +1644,6 @@ class AsyncEthModuleTest:
|
|
|
1597
1644
|
@pytest.mark.asyncio
|
|
1598
1645
|
async def test_eth_call_offchain_lookup_raises_when_all_supplied_urls_fail(
|
|
1599
1646
|
self,
|
|
1600
|
-
async_w3: "AsyncWeb3",
|
|
1601
1647
|
async_offchain_lookup_contract: "AsyncContract",
|
|
1602
1648
|
) -> None:
|
|
1603
1649
|
# GET and POST requests should fail since responses are not mocked
|
|
@@ -1611,9 +1657,7 @@ class AsyncEthModuleTest:
|
|
|
1611
1657
|
@pytest.mark.asyncio
|
|
1612
1658
|
async def test_eth_call_continuous_offchain_lookup_raises_with_too_many_requests(
|
|
1613
1659
|
self,
|
|
1614
|
-
async_w3: "AsyncWeb3",
|
|
1615
1660
|
async_offchain_lookup_contract: "AsyncContract",
|
|
1616
|
-
async_unlocked_account: ChecksumAddress,
|
|
1617
1661
|
monkeypatch: "MonkeyPatch",
|
|
1618
1662
|
) -> None:
|
|
1619
1663
|
normalized_contract_address = to_hex_if_bytes(
|
|
@@ -1627,23 +1671,12 @@ class AsyncEthModuleTest:
|
|
|
1627
1671
|
with pytest.raises(TooManyRequests, match="Too many CCIP read redirects"):
|
|
1628
1672
|
await async_offchain_lookup_contract.caller().continuousOffchainLookup() # noqa: E501 type: ignore
|
|
1629
1673
|
|
|
1630
|
-
@pytest.mark.asyncio
|
|
1631
|
-
async def test_async_eth_hashrate(self, async_w3: "AsyncWeb3") -> None:
|
|
1632
|
-
hashrate = await async_w3.eth.hashrate
|
|
1633
|
-
assert is_integer(hashrate)
|
|
1634
|
-
assert hashrate >= 0
|
|
1635
|
-
|
|
1636
1674
|
@pytest.mark.asyncio
|
|
1637
1675
|
async def test_async_eth_chain_id(self, async_w3: "AsyncWeb3") -> None:
|
|
1638
1676
|
chain_id = await async_w3.eth.chain_id
|
|
1639
1677
|
# chain id value from geth fixture genesis file
|
|
1640
1678
|
assert chain_id == 131277322940537
|
|
1641
1679
|
|
|
1642
|
-
@pytest.mark.asyncio
|
|
1643
|
-
async def test_async_eth_mining(self, async_w3: "AsyncWeb3") -> None:
|
|
1644
|
-
mining = await async_w3.eth.mining
|
|
1645
|
-
assert is_boolean(mining)
|
|
1646
|
-
|
|
1647
1680
|
@pytest.mark.asyncio
|
|
1648
1681
|
async def test_async_eth_get_transaction_receipt_mined(
|
|
1649
1682
|
self,
|
|
@@ -1665,14 +1698,17 @@ class AsyncEthModuleTest:
|
|
|
1665
1698
|
assert isinstance(effective_gas_price, int)
|
|
1666
1699
|
assert effective_gas_price > 0
|
|
1667
1700
|
|
|
1701
|
+
@flaky_geth_dev_mining
|
|
1668
1702
|
@pytest.mark.asyncio
|
|
1669
1703
|
async def test_async_eth_get_transaction_receipt_unmined(
|
|
1670
|
-
self,
|
|
1704
|
+
self,
|
|
1705
|
+
async_w3: "AsyncWeb3",
|
|
1706
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
1671
1707
|
) -> None:
|
|
1672
1708
|
txn_hash = await async_w3.eth.send_transaction(
|
|
1673
1709
|
{
|
|
1674
|
-
"from":
|
|
1675
|
-
"to":
|
|
1710
|
+
"from": async_keyfile_account_address_dual_type,
|
|
1711
|
+
"to": async_keyfile_account_address_dual_type,
|
|
1676
1712
|
"value": Wei(1),
|
|
1677
1713
|
"gas": 21000,
|
|
1678
1714
|
"maxFeePerGas": async_w3.to_wei(3, "gwei"),
|
|
@@ -1728,14 +1764,17 @@ class AsyncEthModuleTest:
|
|
|
1728
1764
|
assert isinstance(effective_gas_price, int)
|
|
1729
1765
|
assert effective_gas_price > 0
|
|
1730
1766
|
|
|
1767
|
+
@flaky_geth_dev_mining
|
|
1731
1768
|
@pytest.mark.asyncio
|
|
1732
1769
|
async def test_async_eth_wait_for_transaction_receipt_unmined(
|
|
1733
|
-
self,
|
|
1770
|
+
self,
|
|
1771
|
+
async_w3: "AsyncWeb3",
|
|
1772
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
1734
1773
|
) -> None:
|
|
1735
1774
|
txn_hash = await async_w3.eth.send_transaction(
|
|
1736
1775
|
{
|
|
1737
|
-
"from":
|
|
1738
|
-
"to":
|
|
1776
|
+
"from": async_keyfile_account_address_dual_type,
|
|
1777
|
+
"to": async_keyfile_account_address_dual_type,
|
|
1739
1778
|
"value": Wei(1),
|
|
1740
1779
|
"gas": 21000,
|
|
1741
1780
|
"maxFeePerGas": async_w3.to_wei(3, "gwei"),
|
|
@@ -1779,8 +1818,7 @@ class AsyncEthModuleTest:
|
|
|
1779
1818
|
accounts = await async_w3.eth.accounts
|
|
1780
1819
|
assert is_list_like(accounts)
|
|
1781
1820
|
assert len(accounts) != 0
|
|
1782
|
-
assert all(
|
|
1783
|
-
assert await async_w3.eth.coinbase in accounts
|
|
1821
|
+
assert all(is_checksum_address(account) for account in accounts)
|
|
1784
1822
|
|
|
1785
1823
|
@pytest.mark.asyncio
|
|
1786
1824
|
async def test_async_eth_get_logs_without_logs(
|
|
@@ -1800,7 +1838,7 @@ class AsyncEthModuleTest:
|
|
|
1800
1838
|
"fromBlock": async_block_with_txn_with_log["number"],
|
|
1801
1839
|
"toBlock": BlockNumber(async_block_with_txn_with_log["number"] - 1),
|
|
1802
1840
|
}
|
|
1803
|
-
with pytest.raises(
|
|
1841
|
+
with pytest.raises(Web3RPCError):
|
|
1804
1842
|
result = await async_w3.eth.get_logs(filter_params)
|
|
1805
1843
|
|
|
1806
1844
|
# Test with `address`
|
|
@@ -1990,26 +2028,26 @@ class AsyncEthModuleTest:
|
|
|
1990
2028
|
async def test_async_eth_get_storage_at_invalid_address(
|
|
1991
2029
|
self, async_w3: "AsyncWeb3"
|
|
1992
2030
|
) -> None:
|
|
1993
|
-
|
|
2031
|
+
accounts = await async_w3.eth.accounts
|
|
1994
2032
|
with pytest.raises(InvalidAddress):
|
|
1995
2033
|
await async_w3.eth.get_storage_at(
|
|
1996
|
-
ChecksumAddress(HexAddress(HexStr(
|
|
2034
|
+
ChecksumAddress(HexAddress(HexStr(accounts[0].lower()))), 0
|
|
1997
2035
|
)
|
|
1998
2036
|
|
|
1999
2037
|
def test_async_provider_default_account(
|
|
2000
|
-
self,
|
|
2038
|
+
self,
|
|
2039
|
+
async_w3: "AsyncWeb3",
|
|
2040
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
2001
2041
|
) -> None:
|
|
2002
|
-
|
|
2003
|
-
default_account = async_w3.eth.default_account
|
|
2004
|
-
assert default_account is empty
|
|
2042
|
+
current_default_account = async_w3.eth.default_account
|
|
2005
2043
|
|
|
2006
2044
|
# check setter
|
|
2007
|
-
async_w3.eth.default_account =
|
|
2045
|
+
async_w3.eth.default_account = async_keyfile_account_address_dual_type
|
|
2008
2046
|
default_account = async_w3.eth.default_account
|
|
2009
|
-
assert default_account ==
|
|
2047
|
+
assert default_account == async_keyfile_account_address_dual_type
|
|
2010
2048
|
|
|
2011
2049
|
# reset to default
|
|
2012
|
-
async_w3.eth.default_account =
|
|
2050
|
+
async_w3.eth.default_account = current_default_account
|
|
2013
2051
|
|
|
2014
2052
|
def test_async_provider_default_block(
|
|
2015
2053
|
self,
|
|
@@ -2091,17 +2129,20 @@ class AsyncEthModuleTest:
|
|
|
2091
2129
|
|
|
2092
2130
|
@pytest.mark.asyncio
|
|
2093
2131
|
async def test_async_eth_sign(
|
|
2094
|
-
self,
|
|
2132
|
+
self,
|
|
2133
|
+
async_w3: "AsyncWeb3",
|
|
2134
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
2095
2135
|
) -> None:
|
|
2096
2136
|
signature = await async_w3.eth.sign(
|
|
2097
|
-
|
|
2137
|
+
async_keyfile_account_address_dual_type,
|
|
2138
|
+
text="Message tö sign. Longer than hash!",
|
|
2098
2139
|
)
|
|
2099
2140
|
assert is_bytes(signature)
|
|
2100
2141
|
assert len(signature) == 32 + 32 + 1
|
|
2101
2142
|
|
|
2102
2143
|
# test other formats
|
|
2103
2144
|
hexsign = await async_w3.eth.sign(
|
|
2104
|
-
|
|
2145
|
+
async_keyfile_account_address_dual_type,
|
|
2105
2146
|
hexstr=HexStr(
|
|
2106
2147
|
"0x4d6573736167652074c3b6207369676e2e204c6f6e676572207468616e206861736821" # noqa: E501
|
|
2107
2148
|
),
|
|
@@ -2109,19 +2150,20 @@ class AsyncEthModuleTest:
|
|
|
2109
2150
|
assert hexsign == signature
|
|
2110
2151
|
|
|
2111
2152
|
intsign = await async_w3.eth.sign(
|
|
2112
|
-
|
|
2153
|
+
async_keyfile_account_address_dual_type,
|
|
2113
2154
|
0x4D6573736167652074C3B6207369676E2E204C6F6E676572207468616E206861736821,
|
|
2114
2155
|
)
|
|
2115
2156
|
assert intsign == signature
|
|
2116
2157
|
|
|
2117
2158
|
bytessign = await async_w3.eth.sign(
|
|
2118
|
-
|
|
2159
|
+
async_keyfile_account_address_dual_type,
|
|
2119
2160
|
b"Message t\xc3\xb6 sign. Longer than hash!",
|
|
2120
2161
|
)
|
|
2121
2162
|
assert bytessign == signature
|
|
2122
2163
|
|
|
2123
2164
|
new_signature = await async_w3.eth.sign(
|
|
2124
|
-
|
|
2165
|
+
async_keyfile_account_address_dual_type,
|
|
2166
|
+
text="different message is different",
|
|
2125
2167
|
)
|
|
2126
2168
|
assert new_signature != signature
|
|
2127
2169
|
|
|
@@ -2130,10 +2172,12 @@ class AsyncEthModuleTest:
|
|
|
2130
2172
|
reason="Async middleware to convert ENS names to addresses is missing"
|
|
2131
2173
|
)
|
|
2132
2174
|
async def test_async_eth_sign_ens_names(
|
|
2133
|
-
self,
|
|
2175
|
+
self,
|
|
2176
|
+
async_w3: "AsyncWeb3",
|
|
2177
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
2134
2178
|
) -> None:
|
|
2135
2179
|
with ens_addresses(
|
|
2136
|
-
async_w3, {"unlocked-acct.eth":
|
|
2180
|
+
async_w3, {"unlocked-acct.eth": async_keyfile_account_address_dual_type}
|
|
2137
2181
|
):
|
|
2138
2182
|
signature = await async_w3.eth.sign(
|
|
2139
2183
|
ENS("unlocked-acct.eth"), text="Message tö sign. Longer than hash!"
|
|
@@ -2144,11 +2188,13 @@ class AsyncEthModuleTest:
|
|
|
2144
2188
|
@flaky_geth_dev_mining
|
|
2145
2189
|
@pytest.mark.asyncio
|
|
2146
2190
|
async def test_async_eth_replace_transaction_legacy(
|
|
2147
|
-
self,
|
|
2191
|
+
self,
|
|
2192
|
+
async_w3: "AsyncWeb3",
|
|
2193
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
2148
2194
|
) -> None:
|
|
2149
2195
|
txn_params: TxParams = {
|
|
2150
|
-
"from":
|
|
2151
|
-
"to":
|
|
2196
|
+
"from": async_keyfile_account_address_dual_type,
|
|
2197
|
+
"to": async_keyfile_account_address_dual_type,
|
|
2152
2198
|
"value": Wei(1),
|
|
2153
2199
|
"gas": 21000,
|
|
2154
2200
|
"gasPrice": async_w3.to_wei(1, "gwei"),
|
|
@@ -2172,14 +2218,16 @@ class AsyncEthModuleTest:
|
|
|
2172
2218
|
@flaky_geth_dev_mining
|
|
2173
2219
|
@pytest.mark.asyncio
|
|
2174
2220
|
async def test_async_eth_replace_transaction(
|
|
2175
|
-
self,
|
|
2221
|
+
self,
|
|
2222
|
+
async_w3: "AsyncWeb3",
|
|
2223
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
2176
2224
|
) -> None:
|
|
2177
2225
|
two_gwei_in_wei = async_w3.to_wei(2, "gwei")
|
|
2178
2226
|
three_gwei_in_wei = async_w3.to_wei(3, "gwei")
|
|
2179
2227
|
|
|
2180
2228
|
txn_params: TxParams = {
|
|
2181
|
-
"from":
|
|
2182
|
-
"to":
|
|
2229
|
+
"from": async_keyfile_account_address_dual_type,
|
|
2230
|
+
"to": async_keyfile_account_address_dual_type,
|
|
2183
2231
|
"value": Wei(1),
|
|
2184
2232
|
"gas": 21000,
|
|
2185
2233
|
"maxFeePerGas": two_gwei_in_wei,
|
|
@@ -2207,11 +2255,13 @@ class AsyncEthModuleTest:
|
|
|
2207
2255
|
@flaky_geth_dev_mining
|
|
2208
2256
|
@pytest.mark.asyncio
|
|
2209
2257
|
async def test_async_eth_replace_transaction_underpriced(
|
|
2210
|
-
self,
|
|
2258
|
+
self,
|
|
2259
|
+
async_w3: "AsyncWeb3",
|
|
2260
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
2211
2261
|
) -> None:
|
|
2212
2262
|
txn_params: TxParams = {
|
|
2213
|
-
"from":
|
|
2214
|
-
"to":
|
|
2263
|
+
"from": async_keyfile_account_address_dual_type,
|
|
2264
|
+
"to": async_keyfile_account_address_dual_type,
|
|
2215
2265
|
"value": Wei(1),
|
|
2216
2266
|
"gas": 21000,
|
|
2217
2267
|
"maxFeePerGas": async_w3.to_wei(3, "gwei"),
|
|
@@ -2223,17 +2273,19 @@ class AsyncEthModuleTest:
|
|
|
2223
2273
|
txn_params["maxFeePerGas"] = one_gwei_in_wei
|
|
2224
2274
|
txn_params["maxPriorityFeePerGas"] = one_gwei_in_wei
|
|
2225
2275
|
|
|
2226
|
-
with pytest.raises(
|
|
2276
|
+
with pytest.raises(Web3RPCError, match="replacement transaction underpriced"):
|
|
2227
2277
|
await async_w3.eth.replace_transaction(txn_hash, txn_params)
|
|
2228
2278
|
|
|
2229
2279
|
@flaky_geth_dev_mining
|
|
2230
2280
|
@pytest.mark.asyncio
|
|
2231
2281
|
async def test_async_eth_replace_transaction_non_existing_transaction(
|
|
2232
|
-
self,
|
|
2282
|
+
self,
|
|
2283
|
+
async_w3: "AsyncWeb3",
|
|
2284
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
2233
2285
|
) -> None:
|
|
2234
2286
|
txn_params: TxParams = {
|
|
2235
|
-
"from":
|
|
2236
|
-
"to":
|
|
2287
|
+
"from": async_keyfile_account_address_dual_type,
|
|
2288
|
+
"to": async_keyfile_account_address_dual_type,
|
|
2237
2289
|
"value": Wei(1),
|
|
2238
2290
|
"gas": 21000,
|
|
2239
2291
|
"maxFeePerGas": async_w3.to_wei(3, "gwei"),
|
|
@@ -2250,11 +2302,13 @@ class AsyncEthModuleTest:
|
|
|
2250
2302
|
@flaky_geth_dev_mining
|
|
2251
2303
|
@pytest.mark.asyncio
|
|
2252
2304
|
async def test_async_eth_replace_transaction_already_mined(
|
|
2253
|
-
self,
|
|
2305
|
+
self,
|
|
2306
|
+
async_w3: "AsyncWeb3",
|
|
2307
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
2254
2308
|
) -> None:
|
|
2255
2309
|
txn_params: TxParams = {
|
|
2256
|
-
"from":
|
|
2257
|
-
"to":
|
|
2310
|
+
"from": async_keyfile_account_address_dual_type,
|
|
2311
|
+
"to": async_keyfile_account_address_dual_type,
|
|
2258
2312
|
"value": Wei(1),
|
|
2259
2313
|
"gas": 21000,
|
|
2260
2314
|
"maxFeePerGas": async_w3.to_wei(2, "gwei"),
|
|
@@ -2265,17 +2319,17 @@ class AsyncEthModuleTest:
|
|
|
2265
2319
|
|
|
2266
2320
|
txn_params["maxFeePerGas"] = async_w3.to_wei(3, "gwei")
|
|
2267
2321
|
txn_params["maxPriorityFeePerGas"] = async_w3.to_wei(2, "gwei")
|
|
2268
|
-
with pytest.raises(
|
|
2322
|
+
with pytest.raises(Web3ValueError, match="Supplied transaction with hash"):
|
|
2269
2323
|
await async_w3.eth.replace_transaction(txn_hash, txn_params)
|
|
2270
2324
|
|
|
2271
2325
|
@flaky_geth_dev_mining
|
|
2272
2326
|
@pytest.mark.asyncio
|
|
2273
2327
|
async def test_async_eth_replace_transaction_incorrect_nonce(
|
|
2274
|
-
self, async_w3: "AsyncWeb3",
|
|
2328
|
+
self, async_w3: "AsyncWeb3", async_keyfile_account_address: ChecksumAddress
|
|
2275
2329
|
) -> None:
|
|
2276
2330
|
txn_params: TxParams = {
|
|
2277
|
-
"from":
|
|
2278
|
-
"to":
|
|
2331
|
+
"from": async_keyfile_account_address,
|
|
2332
|
+
"to": async_keyfile_account_address,
|
|
2279
2333
|
"value": Wei(1),
|
|
2280
2334
|
"gas": 21000,
|
|
2281
2335
|
"maxFeePerGas": async_w3.to_wei(2, "gwei"),
|
|
@@ -2287,17 +2341,19 @@ class AsyncEthModuleTest:
|
|
|
2287
2341
|
txn_params["maxFeePerGas"] = async_w3.to_wei(3, "gwei")
|
|
2288
2342
|
txn_params["maxPriorityFeePerGas"] = async_w3.to_wei(2, "gwei")
|
|
2289
2343
|
txn_params["nonce"] = Nonce(txn["nonce"] + 1)
|
|
2290
|
-
with pytest.raises(
|
|
2344
|
+
with pytest.raises(Web3ValueError):
|
|
2291
2345
|
await async_w3.eth.replace_transaction(txn_hash, txn_params)
|
|
2292
2346
|
|
|
2293
2347
|
@flaky_geth_dev_mining
|
|
2294
2348
|
@pytest.mark.asyncio
|
|
2295
2349
|
async def test_async_eth_replace_transaction_gas_price_too_low(
|
|
2296
|
-
self,
|
|
2350
|
+
self,
|
|
2351
|
+
async_w3: "AsyncWeb3",
|
|
2352
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
2297
2353
|
) -> None:
|
|
2298
2354
|
txn_params: TxParams = {
|
|
2299
|
-
"from":
|
|
2300
|
-
"to":
|
|
2355
|
+
"from": async_keyfile_account_address_dual_type,
|
|
2356
|
+
"to": async_keyfile_account_address_dual_type,
|
|
2301
2357
|
"value": Wei(1),
|
|
2302
2358
|
"gas": 21000,
|
|
2303
2359
|
"gasPrice": async_w3.to_wei(2, "gwei"),
|
|
@@ -2305,19 +2361,22 @@ class AsyncEthModuleTest:
|
|
|
2305
2361
|
txn_hash = await async_w3.eth.send_transaction(txn_params)
|
|
2306
2362
|
|
|
2307
2363
|
txn_params["gasPrice"] = async_w3.to_wei(1, "gwei")
|
|
2308
|
-
with pytest.raises(
|
|
2364
|
+
with pytest.raises(Web3ValueError):
|
|
2309
2365
|
await async_w3.eth.replace_transaction(txn_hash, txn_params)
|
|
2310
2366
|
|
|
2311
|
-
@
|
|
2367
|
+
@flaky_with_xfail_on_exception(
|
|
2368
|
+
reason="Very flaky on CI runs, hard to reproduce locally.",
|
|
2369
|
+
exception=RequestTimedOut,
|
|
2370
|
+
)
|
|
2312
2371
|
@pytest.mark.asyncio
|
|
2313
2372
|
async def test_async_eth_replace_transaction_gas_price_defaulting_minimum(
|
|
2314
|
-
self, async_w3: "AsyncWeb3",
|
|
2373
|
+
self, async_w3: "AsyncWeb3", async_keyfile_account_address: ChecksumAddress
|
|
2315
2374
|
) -> None:
|
|
2316
2375
|
gas_price = async_w3.to_wei(1, "gwei")
|
|
2317
2376
|
|
|
2318
2377
|
txn_params: TxParams = {
|
|
2319
|
-
"from":
|
|
2320
|
-
"to":
|
|
2378
|
+
"from": async_keyfile_account_address,
|
|
2379
|
+
"to": async_keyfile_account_address,
|
|
2321
2380
|
"value": Wei(1),
|
|
2322
2381
|
"gas": 21000,
|
|
2323
2382
|
"gasPrice": gas_price,
|
|
@@ -2332,14 +2391,17 @@ class AsyncEthModuleTest:
|
|
|
2332
2391
|
gas_price * 1.125
|
|
2333
2392
|
) # minimum gas price
|
|
2334
2393
|
|
|
2335
|
-
@
|
|
2394
|
+
@flaky_with_xfail_on_exception(
|
|
2395
|
+
reason="Very flaky on CI runs, hard to reproduce locally.",
|
|
2396
|
+
exception=RequestTimedOut,
|
|
2397
|
+
)
|
|
2336
2398
|
@pytest.mark.asyncio
|
|
2337
2399
|
async def test_async_eth_replace_transaction_gas_price_defaulting_strategy_higher(
|
|
2338
|
-
self, async_w3: "AsyncWeb3",
|
|
2400
|
+
self, async_w3: "AsyncWeb3", async_keyfile_account_address: ChecksumAddress
|
|
2339
2401
|
) -> None:
|
|
2340
2402
|
txn_params: TxParams = {
|
|
2341
|
-
"from":
|
|
2342
|
-
"to":
|
|
2403
|
+
"from": async_keyfile_account_address,
|
|
2404
|
+
"to": async_keyfile_account_address,
|
|
2343
2405
|
"value": Wei(1),
|
|
2344
2406
|
"gas": 21000,
|
|
2345
2407
|
"gasPrice": async_w3.to_wei(1, "gwei"),
|
|
@@ -2361,16 +2423,19 @@ class AsyncEthModuleTest:
|
|
|
2361
2423
|
) # Strategy provides higher gas price
|
|
2362
2424
|
async_w3.eth.set_gas_price_strategy(None) # reset strategy
|
|
2363
2425
|
|
|
2364
|
-
@
|
|
2426
|
+
@flaky_with_xfail_on_exception(
|
|
2427
|
+
reason="Very flaky on CI runs, hard to reproduce locally.",
|
|
2428
|
+
exception=RequestTimedOut,
|
|
2429
|
+
)
|
|
2365
2430
|
@pytest.mark.asyncio
|
|
2366
2431
|
async def test_async_eth_replace_transaction_gas_price_defaulting_strategy_lower(
|
|
2367
|
-
self, async_w3: "AsyncWeb3",
|
|
2432
|
+
self, async_w3: "AsyncWeb3", async_keyfile_account_address: ChecksumAddress
|
|
2368
2433
|
) -> None:
|
|
2369
2434
|
gas_price = async_w3.to_wei(2, "gwei")
|
|
2370
2435
|
|
|
2371
2436
|
txn_params: TxParams = {
|
|
2372
|
-
"from":
|
|
2373
|
-
"to":
|
|
2437
|
+
"from": async_keyfile_account_address,
|
|
2438
|
+
"to": async_keyfile_account_address,
|
|
2374
2439
|
"value": Wei(1),
|
|
2375
2440
|
"gas": 21000,
|
|
2376
2441
|
"gasPrice": gas_price,
|
|
@@ -2459,19 +2524,6 @@ class EthModuleTest:
|
|
|
2459
2524
|
assert is_integer(sync_dict["currentBlock"])
|
|
2460
2525
|
assert is_integer(sync_dict["highestBlock"])
|
|
2461
2526
|
|
|
2462
|
-
def test_eth_coinbase(self, w3: "Web3") -> None:
|
|
2463
|
-
coinbase = w3.eth.coinbase
|
|
2464
|
-
assert is_checksum_address(coinbase)
|
|
2465
|
-
|
|
2466
|
-
def test_eth_mining(self, w3: "Web3") -> None:
|
|
2467
|
-
mining = w3.eth.mining
|
|
2468
|
-
assert is_boolean(mining)
|
|
2469
|
-
|
|
2470
|
-
def test_eth_hashrate(self, w3: "Web3") -> None:
|
|
2471
|
-
hashrate = w3.eth.hashrate
|
|
2472
|
-
assert is_integer(hashrate)
|
|
2473
|
-
assert hashrate >= 0
|
|
2474
|
-
|
|
2475
2527
|
def test_eth_chain_id(self, w3: "Web3") -> None:
|
|
2476
2528
|
chain_id = w3.eth.chain_id
|
|
2477
2529
|
# chain id value from geth fixture genesis file
|
|
@@ -2515,65 +2567,30 @@ class EthModuleTest:
|
|
|
2515
2567
|
max_priority_fee = w3.eth.max_priority_fee
|
|
2516
2568
|
assert is_integer(max_priority_fee)
|
|
2517
2569
|
|
|
2518
|
-
def test_eth_max_priority_fee_with_fee_history_calculation_error_dict(
|
|
2519
|
-
self, w3: "Web3"
|
|
2520
|
-
) -> None:
|
|
2521
|
-
fail_max_prio_middleware = construct_error_generator_middleware(
|
|
2522
|
-
{
|
|
2523
|
-
RPCEndpoint("eth_maxPriorityFeePerGas"): lambda *_: {
|
|
2524
|
-
"error": {
|
|
2525
|
-
"code": -32601,
|
|
2526
|
-
"message": (
|
|
2527
|
-
"The method eth_maxPriorityFeePerGas does "
|
|
2528
|
-
"not exist/is not available"
|
|
2529
|
-
),
|
|
2530
|
-
}
|
|
2531
|
-
}
|
|
2532
|
-
}
|
|
2533
|
-
)
|
|
2534
|
-
w3.middleware_onion.add(
|
|
2535
|
-
fail_max_prio_middleware, name="fail_max_prio_middleware"
|
|
2536
|
-
)
|
|
2537
|
-
|
|
2538
|
-
with pytest.warns(
|
|
2539
|
-
UserWarning,
|
|
2540
|
-
match=(
|
|
2541
|
-
"There was an issue with the method eth_maxPriorityFeePerGas."
|
|
2542
|
-
" Calculating using eth_feeHistory."
|
|
2543
|
-
),
|
|
2544
|
-
):
|
|
2545
|
-
w3.eth.max_priority_fee
|
|
2546
|
-
|
|
2547
|
-
w3.middleware_onion.remove("fail_max_prio_middleware") # clean up
|
|
2548
|
-
|
|
2549
2570
|
def test_eth_max_priority_fee_with_fee_history_calculation(
|
|
2550
|
-
self, w3: "Web3"
|
|
2571
|
+
self, w3: "Web3", request_mocker: Type[RequestMocker]
|
|
2551
2572
|
) -> None:
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
fail_max_prio_middleware, name="fail_max_prio_middleware"
|
|
2557
|
-
)
|
|
2558
|
-
|
|
2559
|
-
with pytest.warns(
|
|
2560
|
-
UserWarning,
|
|
2561
|
-
match=(
|
|
2562
|
-
"There was an issue with the method eth_maxPriorityFeePerGas."
|
|
2563
|
-
" Calculating using eth_feeHistory."
|
|
2564
|
-
),
|
|
2573
|
+
with request_mocker(
|
|
2574
|
+
w3,
|
|
2575
|
+
mock_errors={RPCEndpoint("eth_maxPriorityFeePerGas"): {}},
|
|
2576
|
+
mock_results={RPCEndpoint("eth_feeHistory"): {"reward": [[0]]}},
|
|
2565
2577
|
):
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2578
|
+
with pytest.warns(
|
|
2579
|
+
UserWarning,
|
|
2580
|
+
match=(
|
|
2581
|
+
"There was an issue with the method eth_maxPriorityFeePerGas. "
|
|
2582
|
+
"Calculating using eth_feeHistory."
|
|
2583
|
+
),
|
|
2584
|
+
):
|
|
2585
|
+
max_priority_fee = w3.eth.max_priority_fee
|
|
2586
|
+
assert is_integer(max_priority_fee)
|
|
2587
|
+
assert max_priority_fee == PRIORITY_FEE_MIN
|
|
2570
2588
|
|
|
2571
2589
|
def test_eth_accounts(self, w3: "Web3") -> None:
|
|
2572
2590
|
accounts = w3.eth.accounts
|
|
2573
2591
|
assert is_list_like(accounts)
|
|
2574
2592
|
assert len(accounts) != 0
|
|
2575
|
-
assert all(
|
|
2576
|
-
assert w3.eth.coinbase in accounts
|
|
2593
|
+
assert all(is_checksum_address(account) for account in accounts)
|
|
2577
2594
|
|
|
2578
2595
|
def test_eth_block_number(self, w3: "Web3") -> None:
|
|
2579
2596
|
block_number = w3.eth.block_number
|
|
@@ -2586,12 +2603,12 @@ class EthModuleTest:
|
|
|
2586
2603
|
assert block_number >= 0
|
|
2587
2604
|
|
|
2588
2605
|
def test_eth_get_balance(self, w3: "Web3") -> None:
|
|
2589
|
-
|
|
2606
|
+
account = w3.eth.accounts[0]
|
|
2590
2607
|
|
|
2591
2608
|
with pytest.raises(InvalidAddress):
|
|
2592
|
-
w3.eth.get_balance(ChecksumAddress(HexAddress(HexStr(
|
|
2609
|
+
w3.eth.get_balance(ChecksumAddress(HexAddress(HexStr(account.lower()))))
|
|
2593
2610
|
|
|
2594
|
-
balance = w3.eth.get_balance(
|
|
2611
|
+
balance = w3.eth.get_balance(account)
|
|
2595
2612
|
|
|
2596
2613
|
assert is_integer(balance)
|
|
2597
2614
|
assert balance >= 0
|
|
@@ -2653,24 +2670,26 @@ class EthModuleTest:
|
|
|
2653
2670
|
assert storage == HexBytes(f"0x{'00' * 31}01")
|
|
2654
2671
|
|
|
2655
2672
|
def test_eth_get_storage_at_invalid_address(self, w3: "Web3") -> None:
|
|
2656
|
-
|
|
2673
|
+
account = w3.eth.accounts[0]
|
|
2657
2674
|
with pytest.raises(InvalidAddress):
|
|
2658
2675
|
w3.eth.get_storage_at(
|
|
2659
|
-
ChecksumAddress(HexAddress(HexStr(
|
|
2676
|
+
ChecksumAddress(HexAddress(HexStr(account.lower()))), 0
|
|
2660
2677
|
)
|
|
2661
2678
|
|
|
2662
2679
|
def test_eth_get_transaction_count(
|
|
2663
|
-
self, w3: "Web3",
|
|
2680
|
+
self, w3: "Web3", keyfile_account_address_dual_type: ChecksumAddress
|
|
2664
2681
|
) -> None:
|
|
2665
|
-
transaction_count = w3.eth.get_transaction_count(
|
|
2682
|
+
transaction_count = w3.eth.get_transaction_count(
|
|
2683
|
+
keyfile_account_address_dual_type
|
|
2684
|
+
)
|
|
2666
2685
|
assert is_integer(transaction_count)
|
|
2667
2686
|
assert transaction_count >= 0
|
|
2668
2687
|
|
|
2669
2688
|
def test_eth_get_transaction_count_ens_name(
|
|
2670
|
-
self, w3: "Web3",
|
|
2689
|
+
self, w3: "Web3", keyfile_account_address_dual_type: ChecksumAddress
|
|
2671
2690
|
) -> None:
|
|
2672
2691
|
with ens_addresses(
|
|
2673
|
-
w3, {"unlocked-acct-dual-type.eth":
|
|
2692
|
+
w3, {"unlocked-acct-dual-type.eth": keyfile_account_address_dual_type}
|
|
2674
2693
|
):
|
|
2675
2694
|
transaction_count = w3.eth.get_transaction_count(
|
|
2676
2695
|
ENS("unlocked-acct-dual-type.eth")
|
|
@@ -2679,10 +2698,10 @@ class EthModuleTest:
|
|
|
2679
2698
|
assert transaction_count >= 0
|
|
2680
2699
|
|
|
2681
2700
|
def test_eth_get_transaction_count_invalid_address(self, w3: "Web3") -> None:
|
|
2682
|
-
|
|
2701
|
+
account = w3.eth.accounts[0]
|
|
2683
2702
|
with pytest.raises(InvalidAddress):
|
|
2684
2703
|
w3.eth.get_transaction_count(
|
|
2685
|
-
ChecksumAddress(HexAddress(HexStr(
|
|
2704
|
+
ChecksumAddress(HexAddress(HexStr(account.lower())))
|
|
2686
2705
|
)
|
|
2687
2706
|
|
|
2688
2707
|
def test_eth_getBlockTransactionCountByHash_empty_block(
|
|
@@ -2768,12 +2787,12 @@ class EthModuleTest:
|
|
|
2768
2787
|
def test_eth_create_access_list(
|
|
2769
2788
|
self,
|
|
2770
2789
|
w3: "Web3",
|
|
2771
|
-
|
|
2790
|
+
keyfile_account_address_dual_type: ChecksumAddress,
|
|
2772
2791
|
math_contract: "Contract",
|
|
2773
2792
|
) -> None:
|
|
2774
2793
|
# build txn
|
|
2775
2794
|
txn = math_contract.functions.incrementCounter(1).build_transaction(
|
|
2776
|
-
{"from":
|
|
2795
|
+
{"from": keyfile_account_address_dual_type}
|
|
2777
2796
|
)
|
|
2778
2797
|
|
|
2779
2798
|
# create access list
|
|
@@ -2784,7 +2803,7 @@ class EthModuleTest:
|
|
|
2784
2803
|
assert len(access_list) > 0
|
|
2785
2804
|
assert access_list[0]["address"] is not None
|
|
2786
2805
|
assert is_checksum_address(access_list[0]["address"])
|
|
2787
|
-
assert len(access_list[0]["storageKeys"][0]) ==
|
|
2806
|
+
assert len(access_list[0]["storageKeys"][0]) == 66
|
|
2788
2807
|
assert int(response["gasUsed"]) >= 0
|
|
2789
2808
|
|
|
2790
2809
|
# assert the result can be used directly in a transaction dict
|
|
@@ -2795,17 +2814,17 @@ class EthModuleTest:
|
|
|
2795
2814
|
w3.eth.send_transaction(txn)
|
|
2796
2815
|
|
|
2797
2816
|
def test_eth_sign(
|
|
2798
|
-
self, w3: "Web3",
|
|
2817
|
+
self, w3: "Web3", keyfile_account_address_dual_type: ChecksumAddress
|
|
2799
2818
|
) -> None:
|
|
2800
2819
|
signature = w3.eth.sign(
|
|
2801
|
-
|
|
2820
|
+
keyfile_account_address_dual_type, text="Message tö sign. Longer than hash!"
|
|
2802
2821
|
)
|
|
2803
2822
|
assert is_bytes(signature)
|
|
2804
2823
|
assert len(signature) == 32 + 32 + 1
|
|
2805
2824
|
|
|
2806
2825
|
# test other formats
|
|
2807
2826
|
hexsign = w3.eth.sign(
|
|
2808
|
-
|
|
2827
|
+
keyfile_account_address_dual_type,
|
|
2809
2828
|
hexstr=HexStr(
|
|
2810
2829
|
"0x4d6573736167652074c3b6207369676e2e204c6f6e676572207468616e206861736821" # noqa: E501
|
|
2811
2830
|
),
|
|
@@ -2813,25 +2832,28 @@ class EthModuleTest:
|
|
|
2813
2832
|
assert hexsign == signature
|
|
2814
2833
|
|
|
2815
2834
|
intsign = w3.eth.sign(
|
|
2816
|
-
|
|
2835
|
+
keyfile_account_address_dual_type,
|
|
2817
2836
|
0x4D6573736167652074C3B6207369676E2E204C6F6E676572207468616E206861736821,
|
|
2818
2837
|
)
|
|
2819
2838
|
assert intsign == signature
|
|
2820
2839
|
|
|
2821
2840
|
bytessign = w3.eth.sign(
|
|
2822
|
-
|
|
2841
|
+
keyfile_account_address_dual_type,
|
|
2842
|
+
b"Message t\xc3\xb6 sign. Longer than hash!",
|
|
2823
2843
|
)
|
|
2824
2844
|
assert bytessign == signature
|
|
2825
2845
|
|
|
2826
2846
|
new_signature = w3.eth.sign(
|
|
2827
|
-
|
|
2847
|
+
keyfile_account_address_dual_type, text="different message is different"
|
|
2828
2848
|
)
|
|
2829
2849
|
assert new_signature != signature
|
|
2830
2850
|
|
|
2831
2851
|
def test_eth_sign_ens_names(
|
|
2832
|
-
self, w3: "Web3",
|
|
2852
|
+
self, w3: "Web3", keyfile_account_address_dual_type: ChecksumAddress
|
|
2833
2853
|
) -> None:
|
|
2834
|
-
with ens_addresses(
|
|
2854
|
+
with ens_addresses(
|
|
2855
|
+
w3, {"unlocked-acct.eth": keyfile_account_address_dual_type}
|
|
2856
|
+
):
|
|
2835
2857
|
signature = w3.eth.sign(
|
|
2836
2858
|
"unlocked-acct.eth", text="Message tö sign. Longer than hash!"
|
|
2837
2859
|
)
|
|
@@ -2841,7 +2863,7 @@ class EthModuleTest:
|
|
|
2841
2863
|
def test_eth_sign_typed_data(
|
|
2842
2864
|
self,
|
|
2843
2865
|
w3: "Web3",
|
|
2844
|
-
|
|
2866
|
+
keyfile_account_address_dual_type: ChecksumAddress,
|
|
2845
2867
|
skip_if_testrpc: Callable[["Web3"], None],
|
|
2846
2868
|
) -> None:
|
|
2847
2869
|
validJSONMessage = """
|
|
@@ -2886,7 +2908,7 @@ class EthModuleTest:
|
|
|
2886
2908
|
skip_if_testrpc(w3)
|
|
2887
2909
|
signature = HexBytes(
|
|
2888
2910
|
w3.eth.sign_typed_data(
|
|
2889
|
-
|
|
2911
|
+
keyfile_account_address_dual_type, json.loads(validJSONMessage)
|
|
2890
2912
|
)
|
|
2891
2913
|
)
|
|
2892
2914
|
assert len(signature) == 32 + 32 + 1
|
|
@@ -2894,7 +2916,7 @@ class EthModuleTest:
|
|
|
2894
2916
|
def test_invalid_eth_sign_typed_data(
|
|
2895
2917
|
self,
|
|
2896
2918
|
w3: "Web3",
|
|
2897
|
-
|
|
2919
|
+
keyfile_account_address_dual_type: ChecksumAddress,
|
|
2898
2920
|
skip_if_testrpc: Callable[["Web3"], None],
|
|
2899
2921
|
) -> None:
|
|
2900
2922
|
skip_if_testrpc(w3)
|
|
@@ -2938,19 +2960,19 @@ class EthModuleTest:
|
|
|
2938
2960
|
}
|
|
2939
2961
|
"""
|
|
2940
2962
|
with pytest.raises(
|
|
2941
|
-
|
|
2963
|
+
Web3ValueError,
|
|
2942
2964
|
match=r".*Expected 2 items for array type Person\[2\], got 1 items.*",
|
|
2943
2965
|
):
|
|
2944
2966
|
w3.eth.sign_typed_data(
|
|
2945
|
-
|
|
2967
|
+
keyfile_account_address_dual_type, json.loads(invalid_typed_message)
|
|
2946
2968
|
)
|
|
2947
2969
|
|
|
2948
2970
|
def test_eth_sign_transaction_legacy(
|
|
2949
|
-
self, w3: "Web3",
|
|
2971
|
+
self, w3: "Web3", keyfile_account_address: ChecksumAddress
|
|
2950
2972
|
) -> None:
|
|
2951
2973
|
txn_params: TxParams = {
|
|
2952
|
-
"from":
|
|
2953
|
-
"to":
|
|
2974
|
+
"from": keyfile_account_address,
|
|
2975
|
+
"to": keyfile_account_address,
|
|
2954
2976
|
"value": Wei(1),
|
|
2955
2977
|
"gas": 21000,
|
|
2956
2978
|
"gasPrice": w3.eth.gas_price,
|
|
@@ -2958,7 +2980,7 @@ class EthModuleTest:
|
|
|
2958
2980
|
}
|
|
2959
2981
|
result = w3.eth.sign_transaction(txn_params)
|
|
2960
2982
|
signatory_account = w3.eth.account.recover_transaction(result["raw"])
|
|
2961
|
-
assert
|
|
2983
|
+
assert keyfile_account_address == signatory_account
|
|
2962
2984
|
assert result["tx"]["to"] == txn_params["to"]
|
|
2963
2985
|
assert result["tx"]["value"] == txn_params["value"]
|
|
2964
2986
|
assert result["tx"]["gas"] == txn_params["gas"]
|
|
@@ -2966,11 +2988,11 @@ class EthModuleTest:
|
|
|
2966
2988
|
assert result["tx"]["nonce"] == txn_params["nonce"]
|
|
2967
2989
|
|
|
2968
2990
|
def test_eth_sign_transaction(
|
|
2969
|
-
self, w3: "Web3",
|
|
2991
|
+
self, w3: "Web3", keyfile_account_address: ChecksumAddress
|
|
2970
2992
|
) -> None:
|
|
2971
2993
|
txn_params: TxParams = {
|
|
2972
|
-
"from":
|
|
2973
|
-
"to":
|
|
2994
|
+
"from": keyfile_account_address,
|
|
2995
|
+
"to": keyfile_account_address,
|
|
2974
2996
|
"value": Wei(1),
|
|
2975
2997
|
"gas": 21000,
|
|
2976
2998
|
"maxFeePerGas": w3.to_wei(2, "gwei"),
|
|
@@ -2979,7 +3001,7 @@ class EthModuleTest:
|
|
|
2979
3001
|
}
|
|
2980
3002
|
result = w3.eth.sign_transaction(txn_params)
|
|
2981
3003
|
signatory_account = w3.eth.account.recover_transaction(result["raw"])
|
|
2982
|
-
assert
|
|
3004
|
+
assert keyfile_account_address == signatory_account
|
|
2983
3005
|
assert result["tx"]["to"] == txn_params["to"]
|
|
2984
3006
|
assert result["tx"]["value"] == txn_params["value"]
|
|
2985
3007
|
assert result["tx"]["gas"] == txn_params["gas"]
|
|
@@ -2990,11 +3012,11 @@ class EthModuleTest:
|
|
|
2990
3012
|
assert result["tx"]["nonce"] == txn_params["nonce"]
|
|
2991
3013
|
|
|
2992
3014
|
def test_eth_sign_transaction_hex_fees(
|
|
2993
|
-
self, w3: "Web3",
|
|
3015
|
+
self, w3: "Web3", keyfile_account_address: ChecksumAddress
|
|
2994
3016
|
) -> None:
|
|
2995
3017
|
txn_params: TxParams = {
|
|
2996
|
-
"from":
|
|
2997
|
-
"to":
|
|
3018
|
+
"from": keyfile_account_address,
|
|
3019
|
+
"to": keyfile_account_address,
|
|
2998
3020
|
"value": Wei(1),
|
|
2999
3021
|
"gas": 21000,
|
|
3000
3022
|
"maxFeePerGas": hex(w3.to_wei(2, "gwei")),
|
|
@@ -3003,7 +3025,7 @@ class EthModuleTest:
|
|
|
3003
3025
|
}
|
|
3004
3026
|
result = w3.eth.sign_transaction(txn_params)
|
|
3005
3027
|
signatory_account = w3.eth.account.recover_transaction(result["raw"])
|
|
3006
|
-
assert
|
|
3028
|
+
assert keyfile_account_address == signatory_account
|
|
3007
3029
|
assert result["tx"]["to"] == txn_params["to"]
|
|
3008
3030
|
assert result["tx"]["value"] == txn_params["value"]
|
|
3009
3031
|
assert result["tx"]["gas"] == txn_params["gas"]
|
|
@@ -3014,9 +3036,9 @@ class EthModuleTest:
|
|
|
3014
3036
|
assert result["tx"]["nonce"] == txn_params["nonce"]
|
|
3015
3037
|
|
|
3016
3038
|
def test_eth_sign_transaction_ens_names(
|
|
3017
|
-
self, w3: "Web3",
|
|
3039
|
+
self, w3: "Web3", keyfile_account_address: ChecksumAddress
|
|
3018
3040
|
) -> None:
|
|
3019
|
-
with ens_addresses(w3, {"unlocked-account.eth":
|
|
3041
|
+
with ens_addresses(w3, {"unlocked-account.eth": keyfile_account_address}):
|
|
3020
3042
|
txn_params: TxParams = {
|
|
3021
3043
|
"from": "unlocked-account.eth",
|
|
3022
3044
|
"to": "unlocked-account.eth",
|
|
@@ -3028,8 +3050,8 @@ class EthModuleTest:
|
|
|
3028
3050
|
}
|
|
3029
3051
|
result = w3.eth.sign_transaction(txn_params)
|
|
3030
3052
|
signatory_account = w3.eth.account.recover_transaction(result["raw"])
|
|
3031
|
-
assert
|
|
3032
|
-
assert result["tx"]["to"] ==
|
|
3053
|
+
assert keyfile_account_address == signatory_account
|
|
3054
|
+
assert result["tx"]["to"] == keyfile_account_address
|
|
3033
3055
|
assert result["tx"]["value"] == txn_params["value"]
|
|
3034
3056
|
assert result["tx"]["gas"] == txn_params["gas"]
|
|
3035
3057
|
assert result["tx"]["maxFeePerGas"] == txn_params["maxFeePerGas"]
|
|
@@ -3040,12 +3062,12 @@ class EthModuleTest:
|
|
|
3040
3062
|
assert result["tx"]["nonce"] == txn_params["nonce"]
|
|
3041
3063
|
|
|
3042
3064
|
def test_eth_send_transaction_addr_checksum_required(
|
|
3043
|
-
self, w3: "Web3",
|
|
3065
|
+
self, w3: "Web3", keyfile_account_address: ChecksumAddress
|
|
3044
3066
|
) -> None:
|
|
3045
|
-
non_checksum_addr =
|
|
3067
|
+
non_checksum_addr = keyfile_account_address.lower()
|
|
3046
3068
|
txn_params: TxParams = {
|
|
3047
|
-
"from":
|
|
3048
|
-
"to":
|
|
3069
|
+
"from": keyfile_account_address,
|
|
3070
|
+
"to": keyfile_account_address,
|
|
3049
3071
|
"value": Wei(1),
|
|
3050
3072
|
"gas": 21000,
|
|
3051
3073
|
"maxFeePerGas": w3.to_wei(2, "gwei"),
|
|
@@ -3065,11 +3087,11 @@ class EthModuleTest:
|
|
|
3065
3087
|
w3.eth.send_transaction(invalid_params)
|
|
3066
3088
|
|
|
3067
3089
|
def test_eth_send_transaction_legacy(
|
|
3068
|
-
self, w3: "Web3",
|
|
3090
|
+
self, w3: "Web3", keyfile_account_address_dual_type: ChecksumAddress
|
|
3069
3091
|
) -> None:
|
|
3070
3092
|
txn_params: TxParams = {
|
|
3071
|
-
"from":
|
|
3072
|
-
"to":
|
|
3093
|
+
"from": keyfile_account_address_dual_type,
|
|
3094
|
+
"to": keyfile_account_address_dual_type,
|
|
3073
3095
|
"value": Wei(1),
|
|
3074
3096
|
"gas": 21000,
|
|
3075
3097
|
"gasPrice": w3.to_wei(
|
|
@@ -3086,16 +3108,17 @@ class EthModuleTest:
|
|
|
3086
3108
|
assert txn["gasPrice"] == txn_params["gasPrice"]
|
|
3087
3109
|
|
|
3088
3110
|
def test_eth_send_transaction(
|
|
3089
|
-
self, w3: "Web3",
|
|
3111
|
+
self, w3: "Web3", keyfile_account_address_dual_type: ChecksumAddress
|
|
3090
3112
|
) -> None:
|
|
3091
3113
|
txn_params: TxParams = {
|
|
3092
|
-
"from":
|
|
3093
|
-
"to":
|
|
3114
|
+
"from": keyfile_account_address_dual_type,
|
|
3115
|
+
"to": keyfile_account_address_dual_type,
|
|
3094
3116
|
"value": Wei(1),
|
|
3095
3117
|
"gas": 21000,
|
|
3096
3118
|
"maxFeePerGas": w3.to_wei(3, "gwei"),
|
|
3097
3119
|
"maxPriorityFeePerGas": w3.to_wei(1, "gwei"),
|
|
3098
3120
|
}
|
|
3121
|
+
|
|
3099
3122
|
txn_hash = w3.eth.send_transaction(txn_params)
|
|
3100
3123
|
txn = w3.eth.get_transaction(txn_hash)
|
|
3101
3124
|
|
|
@@ -3105,23 +3128,25 @@ class EthModuleTest:
|
|
|
3105
3128
|
assert txn["gas"] == 21000
|
|
3106
3129
|
assert txn["maxFeePerGas"] == txn_params["maxFeePerGas"]
|
|
3107
3130
|
assert txn["maxPriorityFeePerGas"] == txn_params["maxPriorityFeePerGas"]
|
|
3108
|
-
assert txn["gasPrice"]
|
|
3131
|
+
assert txn["gasPrice"] <= txn["maxFeePerGas"] # effective gas price
|
|
3109
3132
|
|
|
3110
3133
|
def test_eth_send_transaction_with_nonce(
|
|
3111
|
-
self, w3: "Web3",
|
|
3134
|
+
self, w3: "Web3", keyfile_account_address: ChecksumAddress
|
|
3112
3135
|
) -> None:
|
|
3113
3136
|
max_priority_fee_per_gas = w3.to_wei(1.234, "gwei")
|
|
3114
3137
|
max_fee_per_gas = Wei(
|
|
3115
3138
|
w3.eth.get_block("latest")["baseFeePerGas"] + max_priority_fee_per_gas
|
|
3116
3139
|
)
|
|
3117
3140
|
txn_params: TxParams = {
|
|
3118
|
-
"from":
|
|
3119
|
-
"to":
|
|
3141
|
+
"from": keyfile_account_address,
|
|
3142
|
+
"to": keyfile_account_address,
|
|
3120
3143
|
"value": Wei(1),
|
|
3121
3144
|
"gas": 21000,
|
|
3122
3145
|
"maxFeePerGas": max_fee_per_gas,
|
|
3123
3146
|
"maxPriorityFeePerGas": max_priority_fee_per_gas,
|
|
3124
|
-
"nonce": Nonce(
|
|
3147
|
+
"nonce": Nonce(
|
|
3148
|
+
w3.eth.get_transaction_count(keyfile_account_address, "pending")
|
|
3149
|
+
),
|
|
3125
3150
|
}
|
|
3126
3151
|
txn_hash = w3.eth.send_transaction(txn_params)
|
|
3127
3152
|
txn = w3.eth.get_transaction(txn_hash)
|
|
@@ -3137,11 +3162,11 @@ class EthModuleTest:
|
|
|
3137
3162
|
assert is_integer(txn_params["maxFeePerGas"])
|
|
3138
3163
|
|
|
3139
3164
|
def test_eth_send_transaction_default_fees(
|
|
3140
|
-
self, w3: "Web3",
|
|
3165
|
+
self, w3: "Web3", keyfile_account_address_dual_type: ChecksumAddress
|
|
3141
3166
|
) -> None:
|
|
3142
3167
|
txn_params: TxParams = {
|
|
3143
|
-
"from":
|
|
3144
|
-
"to":
|
|
3168
|
+
"from": keyfile_account_address_dual_type,
|
|
3169
|
+
"to": keyfile_account_address_dual_type,
|
|
3145
3170
|
"value": Wei(1),
|
|
3146
3171
|
"gas": 21000,
|
|
3147
3172
|
}
|
|
@@ -3154,14 +3179,14 @@ class EthModuleTest:
|
|
|
3154
3179
|
assert txn["gas"] == 21000
|
|
3155
3180
|
assert is_integer(txn["maxPriorityFeePerGas"])
|
|
3156
3181
|
assert is_integer(txn["maxFeePerGas"])
|
|
3157
|
-
assert txn["gasPrice"]
|
|
3182
|
+
assert txn["gasPrice"] <= txn["maxFeePerGas"] # effective gas price
|
|
3158
3183
|
|
|
3159
3184
|
def test_eth_send_transaction_hex_fees(
|
|
3160
|
-
self, w3: "Web3",
|
|
3185
|
+
self, w3: "Web3", keyfile_account_address_dual_type: ChecksumAddress
|
|
3161
3186
|
) -> None:
|
|
3162
3187
|
txn_params: TxParams = {
|
|
3163
|
-
"from":
|
|
3164
|
-
"to":
|
|
3188
|
+
"from": keyfile_account_address_dual_type,
|
|
3189
|
+
"to": keyfile_account_address_dual_type,
|
|
3165
3190
|
"value": Wei(1),
|
|
3166
3191
|
"gas": 21000,
|
|
3167
3192
|
"maxFeePerGas": hex(250 * 10**9),
|
|
@@ -3178,11 +3203,11 @@ class EthModuleTest:
|
|
|
3178
3203
|
assert txn["maxPriorityFeePerGas"] == 2 * 10**9
|
|
3179
3204
|
|
|
3180
3205
|
def test_eth_send_transaction_no_gas(
|
|
3181
|
-
self, w3: "Web3",
|
|
3206
|
+
self, w3: "Web3", keyfile_account_address_dual_type: ChecksumAddress
|
|
3182
3207
|
) -> None:
|
|
3183
3208
|
txn_params: TxParams = {
|
|
3184
|
-
"from":
|
|
3185
|
-
"to":
|
|
3209
|
+
"from": keyfile_account_address_dual_type,
|
|
3210
|
+
"to": keyfile_account_address_dual_type,
|
|
3186
3211
|
"value": Wei(1),
|
|
3187
3212
|
"maxFeePerGas": Wei(250 * 10**9),
|
|
3188
3213
|
"maxPriorityFeePerGas": Wei(2 * 10**9),
|
|
@@ -3196,11 +3221,11 @@ class EthModuleTest:
|
|
|
3196
3221
|
assert txn["gas"] == 121000 # 21000 + buffer
|
|
3197
3222
|
|
|
3198
3223
|
def test_eth_send_transaction_with_gas_price(
|
|
3199
|
-
self, w3: "Web3",
|
|
3224
|
+
self, w3: "Web3", keyfile_account_address_dual_type: ChecksumAddress
|
|
3200
3225
|
) -> None:
|
|
3201
3226
|
txn_params: TxParams = {
|
|
3202
|
-
"from":
|
|
3203
|
-
"to":
|
|
3227
|
+
"from": keyfile_account_address_dual_type,
|
|
3228
|
+
"to": keyfile_account_address_dual_type,
|
|
3204
3229
|
"value": Wei(1),
|
|
3205
3230
|
"gas": 21000,
|
|
3206
3231
|
"gasPrice": Wei(1),
|
|
@@ -3211,11 +3236,11 @@ class EthModuleTest:
|
|
|
3211
3236
|
w3.eth.send_transaction(txn_params)
|
|
3212
3237
|
|
|
3213
3238
|
def test_eth_send_transaction_no_priority_fee(
|
|
3214
|
-
self, w3: "Web3",
|
|
3239
|
+
self, w3: "Web3", keyfile_account_address_dual_type: ChecksumAddress
|
|
3215
3240
|
) -> None:
|
|
3216
3241
|
txn_params: TxParams = {
|
|
3217
|
-
"from":
|
|
3218
|
-
"to":
|
|
3242
|
+
"from": keyfile_account_address_dual_type,
|
|
3243
|
+
"to": keyfile_account_address_dual_type,
|
|
3219
3244
|
"value": Wei(1),
|
|
3220
3245
|
"gas": 21000,
|
|
3221
3246
|
"maxFeePerGas": Wei(250 * 10**9),
|
|
@@ -3226,12 +3251,12 @@ class EthModuleTest:
|
|
|
3226
3251
|
w3.eth.send_transaction(txn_params)
|
|
3227
3252
|
|
|
3228
3253
|
def test_eth_send_transaction_no_max_fee(
|
|
3229
|
-
self, w3: "Web3",
|
|
3254
|
+
self, w3: "Web3", keyfile_account_address_dual_type: ChecksumAddress
|
|
3230
3255
|
) -> None:
|
|
3231
3256
|
max_priority_fee_per_gas = w3.to_wei(2, "gwei")
|
|
3232
3257
|
txn_params: TxParams = {
|
|
3233
|
-
"from":
|
|
3234
|
-
"to":
|
|
3258
|
+
"from": keyfile_account_address_dual_type,
|
|
3259
|
+
"to": keyfile_account_address_dual_type,
|
|
3235
3260
|
"value": Wei(1),
|
|
3236
3261
|
"gas": 21000,
|
|
3237
3262
|
"maxPriorityFeePerGas": max_priority_fee_per_gas,
|
|
@@ -3248,11 +3273,11 @@ class EthModuleTest:
|
|
|
3248
3273
|
assert is_integer(txn["maxFeePerGas"])
|
|
3249
3274
|
|
|
3250
3275
|
def test_eth_send_transaction_max_fee_less_than_tip(
|
|
3251
|
-
self, w3: "Web3",
|
|
3276
|
+
self, w3: "Web3", keyfile_account_address_dual_type: ChecksumAddress
|
|
3252
3277
|
) -> None:
|
|
3253
3278
|
txn_params: TxParams = {
|
|
3254
|
-
"from":
|
|
3255
|
-
"to":
|
|
3279
|
+
"from": keyfile_account_address_dual_type,
|
|
3280
|
+
"to": keyfile_account_address_dual_type,
|
|
3256
3281
|
"value": Wei(1),
|
|
3257
3282
|
"gas": 21000,
|
|
3258
3283
|
"maxFeePerGas": Wei(1 * 10**9),
|
|
@@ -3264,14 +3289,14 @@ class EthModuleTest:
|
|
|
3264
3289
|
w3.eth.send_transaction(txn_params)
|
|
3265
3290
|
|
|
3266
3291
|
def test_validation_middleware_chain_id_mismatch(
|
|
3267
|
-
self, w3: "Web3",
|
|
3292
|
+
self, w3: "Web3", keyfile_account_address_dual_type: ChecksumAddress
|
|
3268
3293
|
) -> None:
|
|
3269
3294
|
wrong_chain_id = 1234567890
|
|
3270
3295
|
actual_chain_id = w3.eth.chain_id
|
|
3271
3296
|
|
|
3272
3297
|
txn_params: TxParams = {
|
|
3273
|
-
"from":
|
|
3274
|
-
"to":
|
|
3298
|
+
"from": keyfile_account_address_dual_type,
|
|
3299
|
+
"to": keyfile_account_address_dual_type,
|
|
3275
3300
|
"value": Wei(1),
|
|
3276
3301
|
"gas": Wei(21000),
|
|
3277
3302
|
"maxFeePerGas": w3.to_wei(2, "gwei"),
|
|
@@ -3289,12 +3314,15 @@ class EthModuleTest:
|
|
|
3289
3314
|
"max_fee", (1000000000, None), ids=["with_max_fee", "without_max_fee"]
|
|
3290
3315
|
)
|
|
3291
3316
|
def test_gas_price_from_strategy_bypassed_for_dynamic_fee_txn(
|
|
3292
|
-
self,
|
|
3317
|
+
self,
|
|
3318
|
+
w3: "Web3",
|
|
3319
|
+
keyfile_account_address_dual_type: ChecksumAddress,
|
|
3320
|
+
max_fee: Wei,
|
|
3293
3321
|
) -> None:
|
|
3294
3322
|
max_priority_fee = w3.to_wei(1, "gwei")
|
|
3295
3323
|
txn_params: TxParams = {
|
|
3296
|
-
"from":
|
|
3297
|
-
"to":
|
|
3324
|
+
"from": keyfile_account_address_dual_type,
|
|
3325
|
+
"to": keyfile_account_address_dual_type,
|
|
3298
3326
|
"value": Wei(1),
|
|
3299
3327
|
"gas": 21000,
|
|
3300
3328
|
"maxPriorityFeePerGas": max_priority_fee,
|
|
@@ -3317,18 +3345,18 @@ class EthModuleTest:
|
|
|
3317
3345
|
else 2 * latest_block["baseFeePerGas"] + max_priority_fee
|
|
3318
3346
|
)
|
|
3319
3347
|
assert txn["maxPriorityFeePerGas"] == max_priority_fee
|
|
3320
|
-
assert txn["gasPrice"]
|
|
3348
|
+
assert txn["gasPrice"] <= txn["maxFeePerGas"] # effective gas price
|
|
3321
3349
|
|
|
3322
3350
|
w3.eth.set_gas_price_strategy(None) # reset strategy
|
|
3323
3351
|
|
|
3324
3352
|
def test_gas_price_from_strategy_bypassed_for_dynamic_fee_txn_no_tip(
|
|
3325
3353
|
self,
|
|
3326
3354
|
w3: "Web3",
|
|
3327
|
-
|
|
3355
|
+
keyfile_account_address_dual_type: ChecksumAddress,
|
|
3328
3356
|
) -> None:
|
|
3329
3357
|
txn_params: TxParams = {
|
|
3330
|
-
"from":
|
|
3331
|
-
"to":
|
|
3358
|
+
"from": keyfile_account_address_dual_type,
|
|
3359
|
+
"to": keyfile_account_address_dual_type,
|
|
3332
3360
|
"value": Wei(1),
|
|
3333
3361
|
"gas": 21000,
|
|
3334
3362
|
"maxFeePerGas": Wei(1000000000),
|
|
@@ -3346,12 +3374,12 @@ class EthModuleTest:
|
|
|
3346
3374
|
|
|
3347
3375
|
w3.eth.set_gas_price_strategy(None) # reset strategy
|
|
3348
3376
|
|
|
3349
|
-
def
|
|
3350
|
-
self, w3: "Web3",
|
|
3377
|
+
def test_gas_price_strategy_hex_value(
|
|
3378
|
+
self, w3: "Web3", keyfile_account_address_dual_type: ChecksumAddress
|
|
3351
3379
|
) -> None:
|
|
3352
3380
|
txn_params: TxParams = {
|
|
3353
|
-
"from":
|
|
3354
|
-
"to":
|
|
3381
|
+
"from": keyfile_account_address_dual_type,
|
|
3382
|
+
"to": keyfile_account_address_dual_type,
|
|
3355
3383
|
"value": Wei(1),
|
|
3356
3384
|
"gas": 21000,
|
|
3357
3385
|
}
|
|
@@ -3370,11 +3398,11 @@ class EthModuleTest:
|
|
|
3370
3398
|
|
|
3371
3399
|
@flaky_geth_dev_mining
|
|
3372
3400
|
def test_eth_replace_transaction_legacy(
|
|
3373
|
-
self, w3: "Web3",
|
|
3401
|
+
self, w3: "Web3", keyfile_account_address_dual_type: ChecksumAddress
|
|
3374
3402
|
) -> None:
|
|
3375
3403
|
txn_params: TxParams = {
|
|
3376
|
-
"from":
|
|
3377
|
-
"to":
|
|
3404
|
+
"from": keyfile_account_address_dual_type,
|
|
3405
|
+
"to": keyfile_account_address_dual_type,
|
|
3378
3406
|
"value": Wei(1),
|
|
3379
3407
|
"gas": 21000,
|
|
3380
3408
|
"gasPrice": w3.to_wei(
|
|
@@ -3399,14 +3427,14 @@ class EthModuleTest:
|
|
|
3399
3427
|
|
|
3400
3428
|
@flaky_geth_dev_mining
|
|
3401
3429
|
def test_eth_replace_transaction(
|
|
3402
|
-
self, w3: "Web3",
|
|
3430
|
+
self, w3: "Web3", keyfile_account_address_dual_type: ChecksumAddress
|
|
3403
3431
|
) -> None:
|
|
3404
3432
|
two_gwei_in_wei = w3.to_wei(2, "gwei")
|
|
3405
3433
|
three_gwei_in_wei = w3.to_wei(3, "gwei")
|
|
3406
3434
|
|
|
3407
3435
|
txn_params: TxParams = {
|
|
3408
|
-
"from":
|
|
3409
|
-
"to":
|
|
3436
|
+
"from": keyfile_account_address_dual_type,
|
|
3437
|
+
"to": keyfile_account_address_dual_type,
|
|
3410
3438
|
"value": Wei(1),
|
|
3411
3439
|
"gas": 21000,
|
|
3412
3440
|
"maxFeePerGas": two_gwei_in_wei,
|
|
@@ -3433,11 +3461,11 @@ class EthModuleTest:
|
|
|
3433
3461
|
|
|
3434
3462
|
@flaky_geth_dev_mining
|
|
3435
3463
|
def test_eth_replace_transaction_underpriced(
|
|
3436
|
-
self, w3: "Web3",
|
|
3464
|
+
self, w3: "Web3", keyfile_account_address_dual_type: ChecksumAddress
|
|
3437
3465
|
) -> None:
|
|
3438
3466
|
txn_params: TxParams = {
|
|
3439
|
-
"from":
|
|
3440
|
-
"to":
|
|
3467
|
+
"from": keyfile_account_address_dual_type,
|
|
3468
|
+
"to": keyfile_account_address_dual_type,
|
|
3441
3469
|
"value": Wei(1),
|
|
3442
3470
|
"gas": 21000,
|
|
3443
3471
|
"maxFeePerGas": w3.to_wei(3, "gwei"),
|
|
@@ -3449,16 +3477,16 @@ class EthModuleTest:
|
|
|
3449
3477
|
txn_params["maxFeePerGas"] = one_gwei_in_wei
|
|
3450
3478
|
txn_params["maxPriorityFeePerGas"] = one_gwei_in_wei
|
|
3451
3479
|
|
|
3452
|
-
with pytest.raises(
|
|
3480
|
+
with pytest.raises(Web3RPCError, match="replacement transaction underpriced"):
|
|
3453
3481
|
w3.eth.replace_transaction(txn_hash, txn_params)
|
|
3454
3482
|
|
|
3455
3483
|
@flaky_geth_dev_mining
|
|
3456
3484
|
def test_eth_replace_transaction_non_existing_transaction(
|
|
3457
|
-
self, w3: "Web3",
|
|
3485
|
+
self, w3: "Web3", keyfile_account_address_dual_type: ChecksumAddress
|
|
3458
3486
|
) -> None:
|
|
3459
3487
|
txn_params: TxParams = {
|
|
3460
|
-
"from":
|
|
3461
|
-
"to":
|
|
3488
|
+
"from": keyfile_account_address_dual_type,
|
|
3489
|
+
"to": keyfile_account_address_dual_type,
|
|
3462
3490
|
"value": Wei(1),
|
|
3463
3491
|
"gas": 21000,
|
|
3464
3492
|
"maxFeePerGas": w3.to_wei(3, "gwei"),
|
|
@@ -3474,11 +3502,11 @@ class EthModuleTest:
|
|
|
3474
3502
|
|
|
3475
3503
|
@flaky_geth_dev_mining
|
|
3476
3504
|
def test_eth_replace_transaction_already_mined(
|
|
3477
|
-
self, w3: "Web3",
|
|
3505
|
+
self, w3: "Web3", keyfile_account_address_dual_type: ChecksumAddress
|
|
3478
3506
|
) -> None:
|
|
3479
3507
|
txn_params: TxParams = {
|
|
3480
|
-
"from":
|
|
3481
|
-
"to":
|
|
3508
|
+
"from": keyfile_account_address_dual_type,
|
|
3509
|
+
"to": keyfile_account_address_dual_type,
|
|
3482
3510
|
"value": Wei(1),
|
|
3483
3511
|
"gas": 21000,
|
|
3484
3512
|
"maxFeePerGas": w3.to_wei(2, "gwei"),
|
|
@@ -3489,16 +3517,16 @@ class EthModuleTest:
|
|
|
3489
3517
|
|
|
3490
3518
|
txn_params["maxFeePerGas"] = w3.to_wei(3, "gwei")
|
|
3491
3519
|
txn_params["maxPriorityFeePerGas"] = w3.to_wei(2, "gwei")
|
|
3492
|
-
with pytest.raises(
|
|
3520
|
+
with pytest.raises(Web3ValueError, match="Supplied transaction with hash"):
|
|
3493
3521
|
w3.eth.replace_transaction(txn_hash, txn_params)
|
|
3494
3522
|
|
|
3495
3523
|
@flaky_geth_dev_mining
|
|
3496
3524
|
def test_eth_replace_transaction_incorrect_nonce(
|
|
3497
|
-
self, w3: "Web3",
|
|
3525
|
+
self, w3: "Web3", keyfile_account_address: ChecksumAddress
|
|
3498
3526
|
) -> None:
|
|
3499
3527
|
txn_params: TxParams = {
|
|
3500
|
-
"from":
|
|
3501
|
-
"to":
|
|
3528
|
+
"from": keyfile_account_address,
|
|
3529
|
+
"to": keyfile_account_address,
|
|
3502
3530
|
"value": Wei(1),
|
|
3503
3531
|
"gas": 21000,
|
|
3504
3532
|
"maxFeePerGas": w3.to_wei(2, "gwei"),
|
|
@@ -3510,16 +3538,16 @@ class EthModuleTest:
|
|
|
3510
3538
|
txn_params["maxFeePerGas"] = w3.to_wei(3, "gwei")
|
|
3511
3539
|
txn_params["maxPriorityFeePerGas"] = w3.to_wei(2, "gwei")
|
|
3512
3540
|
txn_params["nonce"] = Nonce(txn["nonce"] + 1)
|
|
3513
|
-
with pytest.raises(
|
|
3541
|
+
with pytest.raises(Web3ValueError):
|
|
3514
3542
|
w3.eth.replace_transaction(txn_hash, txn_params)
|
|
3515
3543
|
|
|
3516
3544
|
@flaky_geth_dev_mining
|
|
3517
3545
|
def test_eth_replace_transaction_gas_price_too_low(
|
|
3518
|
-
self, w3: "Web3",
|
|
3546
|
+
self, w3: "Web3", keyfile_account_address_dual_type: ChecksumAddress
|
|
3519
3547
|
) -> None:
|
|
3520
3548
|
txn_params: TxParams = {
|
|
3521
|
-
"from":
|
|
3522
|
-
"to":
|
|
3549
|
+
"from": keyfile_account_address_dual_type,
|
|
3550
|
+
"to": keyfile_account_address_dual_type,
|
|
3523
3551
|
"value": Wei(1),
|
|
3524
3552
|
"gas": 21000,
|
|
3525
3553
|
"gasPrice": w3.to_wei(2, "gwei"),
|
|
@@ -3527,18 +3555,18 @@ class EthModuleTest:
|
|
|
3527
3555
|
txn_hash = w3.eth.send_transaction(txn_params)
|
|
3528
3556
|
|
|
3529
3557
|
txn_params["gasPrice"] = w3.to_wei(1, "gwei")
|
|
3530
|
-
with pytest.raises(
|
|
3558
|
+
with pytest.raises(Web3ValueError):
|
|
3531
3559
|
w3.eth.replace_transaction(txn_hash, txn_params)
|
|
3532
3560
|
|
|
3533
3561
|
@flaky_geth_dev_mining
|
|
3534
3562
|
def test_eth_replace_transaction_gas_price_defaulting_minimum(
|
|
3535
|
-
self, w3: "Web3",
|
|
3563
|
+
self, w3: "Web3", keyfile_account_address: ChecksumAddress
|
|
3536
3564
|
) -> None:
|
|
3537
3565
|
gas_price = w3.to_wei(1, "gwei")
|
|
3538
3566
|
|
|
3539
3567
|
txn_params: TxParams = {
|
|
3540
|
-
"from":
|
|
3541
|
-
"to":
|
|
3568
|
+
"from": keyfile_account_address,
|
|
3569
|
+
"to": keyfile_account_address,
|
|
3542
3570
|
"value": Wei(1),
|
|
3543
3571
|
"gas": 21000,
|
|
3544
3572
|
"gasPrice": gas_price,
|
|
@@ -3555,11 +3583,11 @@ class EthModuleTest:
|
|
|
3555
3583
|
|
|
3556
3584
|
@flaky_geth_dev_mining
|
|
3557
3585
|
def test_eth_replace_transaction_gas_price_defaulting_strategy_higher(
|
|
3558
|
-
self, w3: "Web3",
|
|
3586
|
+
self, w3: "Web3", keyfile_account_address: ChecksumAddress
|
|
3559
3587
|
) -> None:
|
|
3560
3588
|
txn_params: TxParams = {
|
|
3561
|
-
"from":
|
|
3562
|
-
"to":
|
|
3589
|
+
"from": keyfile_account_address,
|
|
3590
|
+
"to": keyfile_account_address,
|
|
3563
3591
|
"value": Wei(1),
|
|
3564
3592
|
"gas": 21000,
|
|
3565
3593
|
"gasPrice": w3.to_wei(1, "gwei"),
|
|
@@ -3583,13 +3611,12 @@ class EthModuleTest:
|
|
|
3583
3611
|
|
|
3584
3612
|
@flaky_geth_dev_mining
|
|
3585
3613
|
def test_eth_replace_transaction_gas_price_defaulting_strategy_lower(
|
|
3586
|
-
self, w3: "Web3",
|
|
3614
|
+
self, w3: "Web3", keyfile_account_address: ChecksumAddress
|
|
3587
3615
|
) -> None:
|
|
3588
3616
|
gas_price = w3.to_wei(2, "gwei")
|
|
3589
|
-
|
|
3590
3617
|
txn_params: TxParams = {
|
|
3591
|
-
"from":
|
|
3592
|
-
"to":
|
|
3618
|
+
"from": keyfile_account_address,
|
|
3619
|
+
"to": keyfile_account_address,
|
|
3593
3620
|
"value": Wei(1),
|
|
3594
3621
|
"gas": 21000,
|
|
3595
3622
|
"gasPrice": gas_price,
|
|
@@ -3609,11 +3636,11 @@ class EthModuleTest:
|
|
|
3609
3636
|
w3.eth.set_gas_price_strategy(None) # reset strategy
|
|
3610
3637
|
|
|
3611
3638
|
def test_eth_modify_transaction_legacy(
|
|
3612
|
-
self, w3: "Web3",
|
|
3639
|
+
self, w3: "Web3", keyfile_account_address: ChecksumAddress
|
|
3613
3640
|
) -> None:
|
|
3614
3641
|
txn_params: TxParams = {
|
|
3615
|
-
"from":
|
|
3616
|
-
"to":
|
|
3642
|
+
"from": keyfile_account_address,
|
|
3643
|
+
"to": keyfile_account_address,
|
|
3617
3644
|
"value": Wei(1),
|
|
3618
3645
|
"gas": 21000,
|
|
3619
3646
|
"gasPrice": w3.to_wei(
|
|
@@ -3623,7 +3650,7 @@ class EthModuleTest:
|
|
|
3623
3650
|
txn_hash = w3.eth.send_transaction(txn_params)
|
|
3624
3651
|
|
|
3625
3652
|
modified_txn_hash = w3.eth.modify_transaction(
|
|
3626
|
-
txn_hash, gasPrice=(cast(
|
|
3653
|
+
txn_hash, gasPrice=(cast(Wei, txn_params["gasPrice"] * 2)), value=Wei(2)
|
|
3627
3654
|
)
|
|
3628
3655
|
modified_txn = w3.eth.get_transaction(modified_txn_hash)
|
|
3629
3656
|
|
|
@@ -3638,11 +3665,11 @@ class EthModuleTest:
|
|
|
3638
3665
|
assert modified_txn["gasPrice"] == cast(int, txn_params["gasPrice"]) * 2
|
|
3639
3666
|
|
|
3640
3667
|
def test_eth_modify_transaction(
|
|
3641
|
-
self, w3: "Web3",
|
|
3668
|
+
self, w3: "Web3", keyfile_account_address: ChecksumAddress
|
|
3642
3669
|
) -> None:
|
|
3643
3670
|
txn_params: TxParams = {
|
|
3644
|
-
"from":
|
|
3645
|
-
"to":
|
|
3671
|
+
"from": keyfile_account_address,
|
|
3672
|
+
"to": keyfile_account_address,
|
|
3646
3673
|
"value": Wei(1),
|
|
3647
3674
|
"gas": 21000,
|
|
3648
3675
|
"maxPriorityFeePerGas": w3.to_wei(1, "gwei"),
|
|
@@ -3652,9 +3679,9 @@ class EthModuleTest:
|
|
|
3652
3679
|
|
|
3653
3680
|
modified_txn_hash = w3.eth.modify_transaction(
|
|
3654
3681
|
txn_hash,
|
|
3655
|
-
value=2,
|
|
3656
|
-
maxPriorityFeePerGas=(cast(Wei, txn_params["maxPriorityFeePerGas"]
|
|
3657
|
-
maxFeePerGas=(cast(Wei, txn_params["maxFeePerGas"]
|
|
3682
|
+
value=Wei(2),
|
|
3683
|
+
maxPriorityFeePerGas=(cast(Wei, txn_params["maxPriorityFeePerGas"] * 2)),
|
|
3684
|
+
maxFeePerGas=(cast(Wei, txn_params["maxFeePerGas"] * 2)),
|
|
3658
3685
|
)
|
|
3659
3686
|
modified_txn = w3.eth.get_transaction(modified_txn_hash)
|
|
3660
3687
|
|
|
@@ -3673,30 +3700,27 @@ class EthModuleTest:
|
|
|
3673
3700
|
assert modified_txn["maxFeePerGas"] == cast(Wei, txn_params["maxFeePerGas"]) * 2
|
|
3674
3701
|
|
|
3675
3702
|
def test_eth_send_raw_transaction(
|
|
3676
|
-
self, w3: "Web3",
|
|
3677
|
-
) -> None:
|
|
3678
|
-
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
)
|
|
3691
|
-
txn_hash = w3.eth.send_raw_transaction(signed_tx.rawTransaction)
|
|
3692
|
-
assert txn_hash == signed_tx.hash
|
|
3703
|
+
self, w3: "Web3", keyfile_account_pkey: HexStr
|
|
3704
|
+
) -> None:
|
|
3705
|
+
keyfile_account = w3.eth.account.from_key(keyfile_account_pkey)
|
|
3706
|
+
txn = {
|
|
3707
|
+
"chainId": 131277322940537, # the chainId set for the fixture
|
|
3708
|
+
"from": keyfile_account.address,
|
|
3709
|
+
"to": keyfile_account.address,
|
|
3710
|
+
"value": Wei(0),
|
|
3711
|
+
"gas": 21000,
|
|
3712
|
+
"nonce": w3.eth.get_transaction_count(keyfile_account.address, "pending"),
|
|
3713
|
+
"gasPrice": 10**9,
|
|
3714
|
+
}
|
|
3715
|
+
signed = keyfile_account.sign_transaction(txn)
|
|
3716
|
+
txn_hash = w3.eth.send_raw_transaction(signed.raw_transaction)
|
|
3717
|
+
assert txn_hash == HexBytes(signed.hash)
|
|
3693
3718
|
|
|
3694
3719
|
def test_eth_call(self, w3: "Web3", math_contract: "Contract") -> None:
|
|
3695
|
-
coinbase = w3.eth.coinbase
|
|
3696
3720
|
txn_params = math_contract._prepare_transaction(
|
|
3697
|
-
|
|
3721
|
+
abi_element_identifier="add",
|
|
3698
3722
|
fn_args=(7, 11),
|
|
3699
|
-
transaction={"from":
|
|
3723
|
+
transaction={"from": w3.eth.accounts[0], "to": math_contract.address},
|
|
3700
3724
|
)
|
|
3701
3725
|
call_result = w3.eth.call(txn_params)
|
|
3702
3726
|
assert is_string(call_result)
|
|
@@ -3706,10 +3730,9 @@ class EthModuleTest:
|
|
|
3706
3730
|
def test_eth_call_with_override_code(
|
|
3707
3731
|
self, w3: "Web3", revert_contract: "Contract"
|
|
3708
3732
|
) -> None:
|
|
3709
|
-
coinbase = w3.eth.coinbase
|
|
3710
3733
|
txn_params = revert_contract._prepare_transaction(
|
|
3711
|
-
|
|
3712
|
-
transaction={"from":
|
|
3734
|
+
abi_element_identifier="normalFunction",
|
|
3735
|
+
transaction={"from": w3.eth.accounts[0], "to": revert_contract.address},
|
|
3713
3736
|
)
|
|
3714
3737
|
call_result = w3.eth.call(txn_params)
|
|
3715
3738
|
(result,) = w3.codec.decode(["bool"], call_result)
|
|
@@ -3758,9 +3781,9 @@ class EthModuleTest:
|
|
|
3758
3781
|
self,
|
|
3759
3782
|
w3: "Web3",
|
|
3760
3783
|
math_contract: "Contract",
|
|
3761
|
-
params:
|
|
3784
|
+
params: StateOverrideParams,
|
|
3762
3785
|
) -> None:
|
|
3763
|
-
txn_params: TxParams = {"from": w3.eth.
|
|
3786
|
+
txn_params: TxParams = {"from": w3.eth.accounts[0]}
|
|
3764
3787
|
|
|
3765
3788
|
# assert does not raise
|
|
3766
3789
|
w3.eth.call(txn_params, "latest", {math_contract.address: params})
|
|
@@ -3768,11 +3791,10 @@ class EthModuleTest:
|
|
|
3768
3791
|
def test_eth_call_with_0_result(
|
|
3769
3792
|
self, w3: "Web3", math_contract: "Contract"
|
|
3770
3793
|
) -> None:
|
|
3771
|
-
coinbase = w3.eth.coinbase
|
|
3772
3794
|
txn_params = math_contract._prepare_transaction(
|
|
3773
|
-
|
|
3795
|
+
abi_element_identifier="add",
|
|
3774
3796
|
fn_args=(0, 0),
|
|
3775
|
-
transaction={"from":
|
|
3797
|
+
transaction={"from": w3.eth.accounts[0], "to": math_contract.address},
|
|
3776
3798
|
)
|
|
3777
3799
|
call_result = w3.eth.call(txn_params)
|
|
3778
3800
|
assert is_string(call_result)
|
|
@@ -3783,12 +3805,12 @@ class EthModuleTest:
|
|
|
3783
3805
|
self,
|
|
3784
3806
|
w3: "Web3",
|
|
3785
3807
|
revert_contract: "Contract",
|
|
3786
|
-
|
|
3808
|
+
keyfile_account_address: ChecksumAddress,
|
|
3787
3809
|
) -> None:
|
|
3788
3810
|
txn_params = revert_contract._prepare_transaction(
|
|
3789
|
-
|
|
3811
|
+
abi_element_identifier="revertWithMessage",
|
|
3790
3812
|
transaction={
|
|
3791
|
-
"from":
|
|
3813
|
+
"from": keyfile_account_address,
|
|
3792
3814
|
"to": revert_contract.address,
|
|
3793
3815
|
},
|
|
3794
3816
|
)
|
|
@@ -3803,13 +3825,13 @@ class EthModuleTest:
|
|
|
3803
3825
|
self,
|
|
3804
3826
|
w3: "Web3",
|
|
3805
3827
|
revert_contract: "Contract",
|
|
3806
|
-
|
|
3828
|
+
keyfile_account_address: ChecksumAddress,
|
|
3807
3829
|
) -> None:
|
|
3808
3830
|
with pytest.raises(ContractLogicError, match="execution reverted"):
|
|
3809
3831
|
txn_params = revert_contract._prepare_transaction(
|
|
3810
|
-
|
|
3832
|
+
abi_element_identifier="revertWithoutMessage",
|
|
3811
3833
|
transaction={
|
|
3812
|
-
"from":
|
|
3834
|
+
"from": keyfile_account_address,
|
|
3813
3835
|
"to": revert_contract.address,
|
|
3814
3836
|
},
|
|
3815
3837
|
)
|
|
@@ -3819,15 +3841,16 @@ class EthModuleTest:
|
|
|
3819
3841
|
self,
|
|
3820
3842
|
w3: "Web3",
|
|
3821
3843
|
revert_contract: "Contract",
|
|
3822
|
-
|
|
3844
|
+
keyfile_account_address: ChecksumAddress,
|
|
3823
3845
|
) -> None:
|
|
3824
3846
|
data = revert_contract.encode_abi(
|
|
3825
|
-
|
|
3847
|
+
abi_element_identifier="UnauthorizedWithMessage",
|
|
3848
|
+
args=["You are not authorized"],
|
|
3826
3849
|
)
|
|
3827
3850
|
txn_params = revert_contract._prepare_transaction(
|
|
3828
|
-
|
|
3851
|
+
abi_element_identifier="customErrorWithMessage",
|
|
3829
3852
|
transaction={
|
|
3830
|
-
"from":
|
|
3853
|
+
"from": keyfile_account_address,
|
|
3831
3854
|
"to": revert_contract.address,
|
|
3832
3855
|
},
|
|
3833
3856
|
)
|
|
@@ -3839,13 +3862,13 @@ class EthModuleTest:
|
|
|
3839
3862
|
self,
|
|
3840
3863
|
w3: "Web3",
|
|
3841
3864
|
revert_contract: "Contract",
|
|
3842
|
-
|
|
3865
|
+
keyfile_account_address: ChecksumAddress,
|
|
3843
3866
|
) -> None:
|
|
3844
|
-
data = revert_contract.encode_abi(
|
|
3867
|
+
data = revert_contract.encode_abi(abi_element_identifier="Unauthorized")
|
|
3845
3868
|
txn_params = revert_contract._prepare_transaction(
|
|
3846
|
-
|
|
3869
|
+
abi_element_identifier="customErrorWithoutMessage",
|
|
3847
3870
|
transaction={
|
|
3848
|
-
"from":
|
|
3871
|
+
"from": keyfile_account_address,
|
|
3849
3872
|
"to": revert_contract.address,
|
|
3850
3873
|
},
|
|
3851
3874
|
)
|
|
@@ -3887,7 +3910,7 @@ class EthModuleTest:
|
|
|
3887
3910
|
self,
|
|
3888
3911
|
w3: "Web3",
|
|
3889
3912
|
offchain_lookup_contract: "Contract",
|
|
3890
|
-
|
|
3913
|
+
keyfile_account_address: ChecksumAddress,
|
|
3891
3914
|
monkeypatch: "MonkeyPatch",
|
|
3892
3915
|
) -> None:
|
|
3893
3916
|
normalized_contract_address = to_hex_if_bytes(
|
|
@@ -3942,7 +3965,7 @@ class EthModuleTest:
|
|
|
3942
3965
|
self,
|
|
3943
3966
|
w3: "Web3",
|
|
3944
3967
|
offchain_lookup_contract: "Contract",
|
|
3945
|
-
|
|
3968
|
+
keyfile_account_address: ChecksumAddress,
|
|
3946
3969
|
monkeypatch: "MonkeyPatch",
|
|
3947
3970
|
) -> None:
|
|
3948
3971
|
normalized_contract_address = to_hex_if_bytes(
|
|
@@ -3973,7 +3996,7 @@ class EthModuleTest:
|
|
|
3973
3996
|
default_max_redirects = w3.provider.ccip_read_max_redirects
|
|
3974
3997
|
|
|
3975
3998
|
w3.provider.ccip_read_max_redirects = max_redirects
|
|
3976
|
-
with pytest.raises(
|
|
3999
|
+
with pytest.raises(Web3ValueError, match="at least 4"):
|
|
3977
4000
|
offchain_lookup_contract.functions.testOffchainLookup(
|
|
3978
4001
|
OFFCHAIN_LOOKUP_TEST_DATA
|
|
3979
4002
|
).call()
|
|
@@ -3984,7 +4007,7 @@ class EthModuleTest:
|
|
|
3984
4007
|
self,
|
|
3985
4008
|
w3: "Web3",
|
|
3986
4009
|
offchain_lookup_contract: "Contract",
|
|
3987
|
-
|
|
4010
|
+
keyfile_account_address: ChecksumAddress,
|
|
3988
4011
|
monkeypatch: "MonkeyPatch",
|
|
3989
4012
|
) -> None:
|
|
3990
4013
|
normalized_contract_address = to_hex_if_bytes(
|
|
@@ -4006,7 +4029,7 @@ class EthModuleTest:
|
|
|
4006
4029
|
self,
|
|
4007
4030
|
w3: "Web3",
|
|
4008
4031
|
offchain_lookup_contract: "Contract",
|
|
4009
|
-
|
|
4032
|
+
keyfile_account_address: ChecksumAddress,
|
|
4010
4033
|
monkeypatch: "MonkeyPatch",
|
|
4011
4034
|
status_code_non_4xx_error: int,
|
|
4012
4035
|
) -> None:
|
|
@@ -4043,7 +4066,7 @@ class EthModuleTest:
|
|
|
4043
4066
|
self,
|
|
4044
4067
|
w3: "Web3",
|
|
4045
4068
|
offchain_lookup_contract: "Contract",
|
|
4046
|
-
|
|
4069
|
+
keyfile_account_address: ChecksumAddress,
|
|
4047
4070
|
monkeypatch: "MonkeyPatch",
|
|
4048
4071
|
) -> None:
|
|
4049
4072
|
normalized_contract_address = to_hex_if_bytes(
|
|
@@ -4062,7 +4085,6 @@ class EthModuleTest:
|
|
|
4062
4085
|
|
|
4063
4086
|
def test_eth_call_offchain_lookup_raises_when_all_supplied_urls_fail(
|
|
4064
4087
|
self,
|
|
4065
|
-
w3: "Web3",
|
|
4066
4088
|
offchain_lookup_contract: "Contract",
|
|
4067
4089
|
) -> None:
|
|
4068
4090
|
# GET and POST requests should fail since responses are not mocked
|
|
@@ -4075,9 +4097,7 @@ class EthModuleTest:
|
|
|
4075
4097
|
|
|
4076
4098
|
def test_eth_call_continuous_offchain_lookup_raises_with_too_many_requests(
|
|
4077
4099
|
self,
|
|
4078
|
-
w3: "Web3",
|
|
4079
4100
|
offchain_lookup_contract: "Contract",
|
|
4080
|
-
unlocked_account: ChecksumAddress,
|
|
4081
4101
|
monkeypatch: "MonkeyPatch",
|
|
4082
4102
|
) -> None:
|
|
4083
4103
|
normalized_contract_address = to_hex_if_bytes(
|
|
@@ -4094,15 +4114,15 @@ class EthModuleTest:
|
|
|
4094
4114
|
self,
|
|
4095
4115
|
w3: "Web3",
|
|
4096
4116
|
revert_contract: "Contract",
|
|
4097
|
-
|
|
4117
|
+
keyfile_account_address: ChecksumAddress,
|
|
4098
4118
|
) -> None:
|
|
4099
4119
|
with pytest.raises(
|
|
4100
4120
|
ContractLogicError, match="execution reverted: Function has been reverted"
|
|
4101
4121
|
):
|
|
4102
4122
|
txn_params = revert_contract._prepare_transaction(
|
|
4103
|
-
|
|
4123
|
+
abi_element_identifier="revertWithMessage",
|
|
4104
4124
|
transaction={
|
|
4105
|
-
"from":
|
|
4125
|
+
"from": keyfile_account_address,
|
|
4106
4126
|
"to": revert_contract.address,
|
|
4107
4127
|
},
|
|
4108
4128
|
)
|
|
@@ -4112,13 +4132,13 @@ class EthModuleTest:
|
|
|
4112
4132
|
self,
|
|
4113
4133
|
w3: "Web3",
|
|
4114
4134
|
revert_contract: "Contract",
|
|
4115
|
-
|
|
4135
|
+
keyfile_account_address: ChecksumAddress,
|
|
4116
4136
|
) -> None:
|
|
4117
4137
|
with pytest.raises(ContractLogicError, match="execution reverted"):
|
|
4118
4138
|
txn_params = revert_contract._prepare_transaction(
|
|
4119
|
-
|
|
4139
|
+
abi_element_identifier="revertWithoutMessage",
|
|
4120
4140
|
transaction={
|
|
4121
|
-
"from":
|
|
4141
|
+
"from": keyfile_account_address,
|
|
4122
4142
|
"to": revert_contract.address,
|
|
4123
4143
|
},
|
|
4124
4144
|
)
|
|
@@ -4128,15 +4148,16 @@ class EthModuleTest:
|
|
|
4128
4148
|
self,
|
|
4129
4149
|
w3: "Web3",
|
|
4130
4150
|
revert_contract: "Contract",
|
|
4131
|
-
|
|
4151
|
+
keyfile_account_address: ChecksumAddress,
|
|
4132
4152
|
) -> None:
|
|
4133
4153
|
data = revert_contract.encode_abi(
|
|
4134
|
-
|
|
4154
|
+
abi_element_identifier="UnauthorizedWithMessage",
|
|
4155
|
+
args=["You are not authorized"],
|
|
4135
4156
|
)
|
|
4136
4157
|
txn_params = revert_contract._prepare_transaction(
|
|
4137
|
-
|
|
4158
|
+
abi_element_identifier="customErrorWithMessage",
|
|
4138
4159
|
transaction={
|
|
4139
|
-
"from":
|
|
4160
|
+
"from": keyfile_account_address,
|
|
4140
4161
|
"to": revert_contract.address,
|
|
4141
4162
|
},
|
|
4142
4163
|
)
|
|
@@ -4148,13 +4169,13 @@ class EthModuleTest:
|
|
|
4148
4169
|
self,
|
|
4149
4170
|
w3: "Web3",
|
|
4150
4171
|
revert_contract: "Contract",
|
|
4151
|
-
|
|
4172
|
+
keyfile_account_address: ChecksumAddress,
|
|
4152
4173
|
) -> None:
|
|
4153
|
-
data = revert_contract.encode_abi(
|
|
4174
|
+
data = revert_contract.encode_abi(abi_element_identifier="Unauthorized")
|
|
4154
4175
|
txn_params = revert_contract._prepare_transaction(
|
|
4155
|
-
|
|
4176
|
+
abi_element_identifier="customErrorWithoutMessage",
|
|
4156
4177
|
transaction={
|
|
4157
|
-
"from":
|
|
4178
|
+
"from": keyfile_account_address,
|
|
4158
4179
|
"to": revert_contract.address,
|
|
4159
4180
|
},
|
|
4160
4181
|
)
|
|
@@ -4163,12 +4184,12 @@ class EthModuleTest:
|
|
|
4163
4184
|
assert excinfo.value.data == data
|
|
4164
4185
|
|
|
4165
4186
|
def test_eth_estimate_gas(
|
|
4166
|
-
self, w3: "Web3",
|
|
4187
|
+
self, w3: "Web3", keyfile_account_address_dual_type: ChecksumAddress
|
|
4167
4188
|
) -> None:
|
|
4168
4189
|
gas_estimate = w3.eth.estimate_gas(
|
|
4169
4190
|
{
|
|
4170
|
-
"from":
|
|
4171
|
-
"to":
|
|
4191
|
+
"from": keyfile_account_address_dual_type,
|
|
4192
|
+
"to": keyfile_account_address_dual_type,
|
|
4172
4193
|
"value": Wei(1),
|
|
4173
4194
|
}
|
|
4174
4195
|
)
|
|
@@ -4176,12 +4197,12 @@ class EthModuleTest:
|
|
|
4176
4197
|
assert gas_estimate > 0
|
|
4177
4198
|
|
|
4178
4199
|
def test_eth_estimate_gas_with_block(
|
|
4179
|
-
self, w3: "Web3",
|
|
4200
|
+
self, w3: "Web3", keyfile_account_address_dual_type: ChecksumAddress
|
|
4180
4201
|
) -> None:
|
|
4181
4202
|
gas_estimate = w3.eth.estimate_gas(
|
|
4182
4203
|
{
|
|
4183
|
-
"from":
|
|
4184
|
-
"to":
|
|
4204
|
+
"from": keyfile_account_address_dual_type,
|
|
4205
|
+
"to": keyfile_account_address_dual_type,
|
|
4185
4206
|
"value": Wei(1),
|
|
4186
4207
|
},
|
|
4187
4208
|
"latest",
|
|
@@ -4212,9 +4233,9 @@ class EthModuleTest:
|
|
|
4212
4233
|
self,
|
|
4213
4234
|
w3: "Web3",
|
|
4214
4235
|
math_contract: "Contract",
|
|
4215
|
-
params:
|
|
4236
|
+
params: StateOverrideParams,
|
|
4216
4237
|
) -> None:
|
|
4217
|
-
txn_params: TxParams = {"from": w3.eth.
|
|
4238
|
+
txn_params: TxParams = {"from": w3.eth.accounts[0]}
|
|
4218
4239
|
|
|
4219
4240
|
# assert does not raise
|
|
4220
4241
|
w3.eth.estimate_gas(txn_params, None, {math_contract.address: params})
|
|
@@ -4241,12 +4262,9 @@ class EthModuleTest:
|
|
|
4241
4262
|
block = w3.eth.get_block(empty_block["number"])
|
|
4242
4263
|
assert block["number"] == empty_block["number"]
|
|
4243
4264
|
|
|
4244
|
-
def test_eth_getBlockByNumber_latest(
|
|
4245
|
-
self, w3: "Web3", empty_block: BlockData
|
|
4246
|
-
) -> None:
|
|
4247
|
-
current_block_number = w3.eth.block_number
|
|
4265
|
+
def test_eth_getBlockByNumber_latest(self, w3: "Web3") -> None:
|
|
4248
4266
|
block = w3.eth.get_block("latest")
|
|
4249
|
-
assert block["
|
|
4267
|
+
assert block["hash"] is not None
|
|
4250
4268
|
|
|
4251
4269
|
def test_eth_getBlockByNumber_not_found(
|
|
4252
4270
|
self, w3: "Web3", empty_block: BlockData
|
|
@@ -4287,8 +4305,36 @@ class EthModuleTest:
|
|
|
4287
4305
|
self, w3: "Web3", block_with_txn: BlockData
|
|
4288
4306
|
) -> None:
|
|
4289
4307
|
block = w3.eth.get_block(block_with_txn["number"], True)
|
|
4290
|
-
transaction = block["transactions"][0]
|
|
4291
|
-
assert transaction["hash"] == block_with_txn["transactions"][0]
|
|
4308
|
+
transaction = cast(TxData, block["transactions"][0])
|
|
4309
|
+
assert transaction["hash"] == block_with_txn["transactions"][0]
|
|
4310
|
+
|
|
4311
|
+
def test_eth_getBlockReceipts_hash(
|
|
4312
|
+
self, w3: "Web3", empty_block: BlockData
|
|
4313
|
+
) -> None:
|
|
4314
|
+
receipts = w3.eth.get_block_receipts(empty_block["hash"])
|
|
4315
|
+
assert isinstance(receipts, list)
|
|
4316
|
+
|
|
4317
|
+
def test_eth_getBlockReceipts_not_found(self, w3: "Web3") -> None:
|
|
4318
|
+
with pytest.raises(BlockNotFound):
|
|
4319
|
+
w3.eth.get_block_receipts(UNKNOWN_HASH)
|
|
4320
|
+
|
|
4321
|
+
def test_eth_getBlockReceipts_with_integer(
|
|
4322
|
+
self, w3: "Web3", empty_block: BlockData
|
|
4323
|
+
) -> None:
|
|
4324
|
+
receipts = w3.eth.get_block_receipts(empty_block["number"])
|
|
4325
|
+
assert isinstance(receipts, list)
|
|
4326
|
+
|
|
4327
|
+
def test_eth_getBlockReceipts_safe(
|
|
4328
|
+
self, w3: "Web3", empty_block: BlockData
|
|
4329
|
+
) -> None:
|
|
4330
|
+
receipts = w3.eth.get_block_receipts("safe")
|
|
4331
|
+
assert isinstance(receipts, list)
|
|
4332
|
+
|
|
4333
|
+
def test_eth_getBlockReceipts_finalized(
|
|
4334
|
+
self, w3: "Web3", empty_block: BlockData
|
|
4335
|
+
) -> None:
|
|
4336
|
+
receipts = w3.eth.get_block_receipts("finalized")
|
|
4337
|
+
assert isinstance(receipts, list)
|
|
4292
4338
|
|
|
4293
4339
|
def test_eth_getTransactionByHash(self, w3: "Web3", mined_txn_hash: HexStr) -> None:
|
|
4294
4340
|
transaction = w3.eth.get_transaction(mined_txn_hash)
|
|
@@ -4333,13 +4379,14 @@ class EthModuleTest:
|
|
|
4333
4379
|
assert isinstance(effective_gas_price, int)
|
|
4334
4380
|
assert effective_gas_price > 0
|
|
4335
4381
|
|
|
4382
|
+
@flaky_geth_dev_mining
|
|
4336
4383
|
def test_eth_get_transaction_receipt_unmined(
|
|
4337
|
-
self, w3: "Web3",
|
|
4384
|
+
self, w3: "Web3", keyfile_account_address_dual_type: ChecksumAddress
|
|
4338
4385
|
) -> None:
|
|
4339
4386
|
txn_hash = w3.eth.send_transaction(
|
|
4340
4387
|
{
|
|
4341
|
-
"from":
|
|
4342
|
-
"to":
|
|
4388
|
+
"from": keyfile_account_address_dual_type,
|
|
4389
|
+
"to": keyfile_account_address_dual_type,
|
|
4343
4390
|
"value": Wei(1),
|
|
4344
4391
|
"gas": 21000,
|
|
4345
4392
|
"maxFeePerGas": w3.to_wei(3, "gwei"),
|
|
@@ -4390,13 +4437,14 @@ class EthModuleTest:
|
|
|
4390
4437
|
assert isinstance(effective_gas_price, int)
|
|
4391
4438
|
assert effective_gas_price > 0
|
|
4392
4439
|
|
|
4440
|
+
@flaky_geth_dev_mining
|
|
4393
4441
|
def test_eth_wait_for_transaction_receipt_unmined(
|
|
4394
|
-
self, w3: "Web3",
|
|
4442
|
+
self, w3: "Web3", keyfile_account_address_dual_type: ChecksumAddress
|
|
4395
4443
|
) -> None:
|
|
4396
4444
|
txn_hash = w3.eth.send_transaction(
|
|
4397
4445
|
{
|
|
4398
|
-
"from":
|
|
4399
|
-
"to":
|
|
4446
|
+
"from": keyfile_account_address_dual_type,
|
|
4447
|
+
"to": keyfile_account_address_dual_type,
|
|
4400
4448
|
"value": Wei(1),
|
|
4401
4449
|
"gas": 21000,
|
|
4402
4450
|
"maxFeePerGas": w3.to_wei(3, "gwei"),
|
|
@@ -4494,7 +4542,7 @@ class EthModuleTest:
|
|
|
4494
4542
|
"fromBlock": block_with_txn_with_log["number"],
|
|
4495
4543
|
"toBlock": BlockNumber(block_with_txn_with_log["number"] - 1),
|
|
4496
4544
|
}
|
|
4497
|
-
with pytest.raises(
|
|
4545
|
+
with pytest.raises(Web3RPCError):
|
|
4498
4546
|
w3.eth.get_logs(filter_params)
|
|
4499
4547
|
|
|
4500
4548
|
# Test with `address`
|
|
@@ -4603,44 +4651,47 @@ class EthModuleTest:
|
|
|
4603
4651
|
assert len(result) == 0
|
|
4604
4652
|
|
|
4605
4653
|
def test_eth_call_old_contract_state(
|
|
4606
|
-
self,
|
|
4654
|
+
self,
|
|
4655
|
+
w3: "Web3",
|
|
4656
|
+
math_contract: "Contract",
|
|
4657
|
+
keyfile_account_address: ChecksumAddress,
|
|
4607
4658
|
) -> None:
|
|
4608
|
-
|
|
4609
|
-
block_num =
|
|
4610
|
-
block_hash =
|
|
4659
|
+
current_block = w3.eth.get_block("latest")
|
|
4660
|
+
block_num = current_block["number"]
|
|
4661
|
+
block_hash = current_block["hash"]
|
|
4611
4662
|
|
|
4612
|
-
math_contract.functions.
|
|
4663
|
+
default_call_result = math_contract.functions.counter().call()
|
|
4664
|
+
latest_call_result = math_contract.functions.counter().call(
|
|
4665
|
+
block_identifier="latest"
|
|
4666
|
+
)
|
|
4667
|
+
|
|
4668
|
+
# increment counter and get tx receipt
|
|
4669
|
+
tx_hash = math_contract.functions.incrementCounter().transact(
|
|
4670
|
+
{"from": keyfile_account_address}
|
|
4671
|
+
)
|
|
4672
|
+
tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
|
|
4613
4673
|
|
|
4614
|
-
#
|
|
4615
|
-
|
|
4616
|
-
|
|
4617
|
-
|
|
4618
|
-
|
|
4619
|
-
#
|
|
4620
|
-
# value in an old block
|
|
4674
|
+
# get new state value
|
|
4675
|
+
post_state_block_num_call_result = math_contract.functions.counter().call(
|
|
4676
|
+
block_identifier=tx_receipt["blockNumber"]
|
|
4677
|
+
)
|
|
4678
|
+
|
|
4679
|
+
# call old state values with different block identifiers
|
|
4621
4680
|
block_hash_call_result = math_contract.functions.counter().call(
|
|
4622
4681
|
block_identifier=block_hash
|
|
4623
4682
|
)
|
|
4624
|
-
|
|
4683
|
+
pre_state_block_num_call_result = math_contract.functions.counter().call(
|
|
4625
4684
|
block_identifier=block_num
|
|
4626
4685
|
)
|
|
4627
|
-
latest_call_result = math_contract.functions.counter().call(
|
|
4628
|
-
block_identifier="latest"
|
|
4629
|
-
)
|
|
4630
|
-
default_call_result = math_contract.functions.counter().call()
|
|
4631
|
-
pending_call_result = math_contract.functions.counter().call(
|
|
4632
|
-
block_identifier="pending"
|
|
4633
|
-
)
|
|
4634
4686
|
|
|
4635
|
-
assert
|
|
4636
|
-
assert
|
|
4637
|
-
assert
|
|
4638
|
-
|
|
4639
|
-
|
|
4640
|
-
|
|
4641
|
-
|
|
4642
|
-
|
|
4643
|
-
)
|
|
4687
|
+
# assert old state values before incrementing counter
|
|
4688
|
+
assert pre_state_block_num_call_result == post_state_block_num_call_result - 1
|
|
4689
|
+
assert (
|
|
4690
|
+
pre_state_block_num_call_result
|
|
4691
|
+
== block_hash_call_result
|
|
4692
|
+
== default_call_result
|
|
4693
|
+
== latest_call_result
|
|
4694
|
+
)
|
|
4644
4695
|
|
|
4645
4696
|
def test_eth_uninstall_filter(self, w3: "Web3") -> None:
|
|
4646
4697
|
filter = w3.eth.filter({})
|
|
@@ -4665,22 +4716,24 @@ class EthModuleTest:
|
|
|
4665
4716
|
def test_eth_get_raw_transaction_by_block(
|
|
4666
4717
|
self,
|
|
4667
4718
|
w3: "Web3",
|
|
4668
|
-
|
|
4719
|
+
keyfile_account_address_dual_type: ChecksumAddress,
|
|
4669
4720
|
block_with_txn: BlockData,
|
|
4670
4721
|
) -> None:
|
|
4671
4722
|
# eth_getRawTransactionByBlockNumberAndIndex: block identifier
|
|
4672
|
-
# send a txn to make sure pending block has at least one txn
|
|
4673
4723
|
w3.eth.send_transaction(
|
|
4674
4724
|
{
|
|
4675
|
-
"from":
|
|
4676
|
-
"to":
|
|
4725
|
+
"from": keyfile_account_address_dual_type,
|
|
4726
|
+
"to": keyfile_account_address_dual_type,
|
|
4677
4727
|
"value": Wei(1),
|
|
4678
4728
|
}
|
|
4679
4729
|
)
|
|
4680
|
-
|
|
4681
|
-
|
|
4682
|
-
|
|
4683
|
-
|
|
4730
|
+
raw_transaction = None
|
|
4731
|
+
while not raw_transaction:
|
|
4732
|
+
try:
|
|
4733
|
+
raw_transaction = w3.eth.get_raw_transaction_by_block("latest", 0)
|
|
4734
|
+
except TransactionNotFound:
|
|
4735
|
+
continue
|
|
4736
|
+
|
|
4684
4737
|
assert is_bytes(raw_transaction)
|
|
4685
4738
|
|
|
4686
4739
|
# eth_getRawTransactionByBlockNumberAndIndex: block number
|
|
@@ -4713,28 +4766,27 @@ class EthModuleTest:
|
|
|
4713
4766
|
) -> None:
|
|
4714
4767
|
unknown_identifier = "unknown"
|
|
4715
4768
|
with pytest.raises(
|
|
4716
|
-
|
|
4769
|
+
Web3ValueError,
|
|
4717
4770
|
match=(
|
|
4718
4771
|
"Value did not match any of the recognized block identifiers: "
|
|
4719
4772
|
f"{unknown_identifier}"
|
|
4720
4773
|
),
|
|
4721
4774
|
):
|
|
4775
|
+
# type ignored because we are testing an invalid input
|
|
4722
4776
|
w3.eth.get_raw_transaction_by_block(unknown_identifier, 0) # type: ignore
|
|
4723
4777
|
|
|
4724
4778
|
def test_default_account(
|
|
4725
|
-
self, w3: "Web3",
|
|
4779
|
+
self, w3: "Web3", keyfile_account_address_dual_type: ChecksumAddress
|
|
4726
4780
|
) -> None:
|
|
4727
|
-
|
|
4728
|
-
default_account = w3.eth.default_account
|
|
4729
|
-
assert default_account is empty
|
|
4781
|
+
current_default = w3.eth.default_account
|
|
4730
4782
|
|
|
4731
4783
|
# check setter
|
|
4732
|
-
w3.eth.default_account =
|
|
4784
|
+
w3.eth.default_account = keyfile_account_address_dual_type
|
|
4733
4785
|
default_account = w3.eth.default_account
|
|
4734
|
-
assert default_account ==
|
|
4786
|
+
assert default_account == keyfile_account_address_dual_type
|
|
4735
4787
|
|
|
4736
4788
|
# reset to default
|
|
4737
|
-
w3.eth.default_account =
|
|
4789
|
+
w3.eth.default_account = current_default
|
|
4738
4790
|
|
|
4739
4791
|
def test_default_block(
|
|
4740
4792
|
self,
|