web3 7.0.0b1__py3-none-any.whl → 7.7.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 +4 -4
- ens/async_ens.py +31 -21
- ens/base_ens.py +3 -1
- ens/contract_data.py +2 -2
- ens/ens.py +14 -11
- ens/exceptions.py +16 -29
- ens/specs/nf.json +1 -1
- ens/specs/normalization_spec.json +1 -1
- ens/utils.py +33 -41
- web3/__init__.py +23 -12
- web3/_utils/abi.py +162 -274
- web3/_utils/async_transactions.py +34 -20
- web3/_utils/batching.py +217 -0
- web3/_utils/blocks.py +6 -2
- web3/_utils/caching/__init__.py +12 -0
- web3/_utils/caching/caching_utils.py +433 -0
- web3/_utils/caching/request_caching_validation.py +287 -0
- web3/_utils/compat/__init__.py +2 -3
- web3/_utils/contract_sources/compile_contracts.py +1 -1
- web3/_utils/contract_sources/contract_data/ambiguous_function_contract.py +42 -0
- 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 +50 -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 +172 -220
- web3/_utils/datatypes.py +5 -1
- web3/_utils/decorators.py +6 -1
- web3/_utils/empty.py +1 -1
- web3/_utils/encoding.py +16 -12
- web3/_utils/error_formatters_utils.py +5 -3
- web3/_utils/events.py +78 -72
- web3/_utils/fee_utils.py +1 -3
- web3/_utils/filters.py +24 -22
- web3/_utils/formatters.py +2 -2
- web3/_utils/http.py +8 -2
- web3/_utils/http_session_manager.py +314 -0
- web3/_utils/math.py +14 -15
- web3/_utils/method_formatters.py +161 -34
- web3/_utils/module.py +2 -1
- web3/_utils/module_testing/__init__.py +3 -2
- web3/_utils/module_testing/eth_module.py +736 -583
- web3/_utils/module_testing/go_ethereum_debug_module.py +128 -0
- web3/_utils/module_testing/module_testing_utils.py +81 -24
- web3/_utils/module_testing/persistent_connection_provider.py +702 -220
- web3/_utils/module_testing/utils.py +114 -33
- web3/_utils/module_testing/web3_module.py +438 -17
- web3/_utils/normalizers.py +13 -11
- web3/_utils/rpc_abi.py +10 -22
- web3/_utils/threads.py +8 -7
- web3/_utils/transactions.py +32 -25
- web3/_utils/type_conversion.py +5 -1
- web3/_utils/validation.py +20 -17
- web3/beacon/__init__.py +5 -0
- web3/beacon/api_endpoints.py +3 -0
- web3/beacon/async_beacon.py +29 -6
- web3/beacon/beacon.py +24 -6
- web3/contract/__init__.py +7 -0
- web3/contract/async_contract.py +285 -82
- web3/contract/base_contract.py +556 -258
- web3/contract/contract.py +295 -84
- web3/contract/utils.py +251 -55
- web3/datastructures.py +56 -41
- web3/eth/__init__.py +7 -0
- web3/eth/async_eth.py +89 -69
- web3/eth/base_eth.py +7 -3
- web3/eth/eth.py +43 -66
- web3/exceptions.py +158 -83
- web3/gas_strategies/time_based.py +8 -6
- web3/geth.py +53 -184
- web3/main.py +77 -43
- web3/manager.py +368 -101
- web3/method.py +43 -15
- web3/middleware/__init__.py +26 -8
- web3/middleware/attrdict.py +12 -22
- web3/middleware/base.py +55 -2
- web3/middleware/filter.py +45 -23
- web3/middleware/formatting.py +6 -3
- web3/middleware/names.py +4 -1
- web3/middleware/signing.py +15 -6
- web3/middleware/stalecheck.py +2 -1
- web3/module.py +62 -26
- web3/providers/__init__.py +21 -0
- web3/providers/async_base.py +93 -38
- web3/providers/base.py +85 -40
- web3/providers/eth_tester/__init__.py +5 -0
- web3/providers/eth_tester/defaults.py +2 -55
- web3/providers/eth_tester/main.py +57 -35
- web3/providers/eth_tester/middleware.py +16 -17
- web3/providers/ipc.py +42 -18
- web3/providers/legacy_websocket.py +27 -2
- web3/providers/persistent/__init__.py +7 -0
- web3/providers/persistent/async_ipc.py +61 -121
- web3/providers/persistent/persistent.py +324 -17
- web3/providers/persistent/persistent_connection.py +54 -5
- web3/providers/persistent/request_processor.py +136 -56
- web3/providers/persistent/subscription_container.py +56 -0
- web3/providers/persistent/subscription_manager.py +233 -0
- web3/providers/persistent/websocket.py +29 -92
- web3/providers/rpc/__init__.py +5 -0
- web3/providers/rpc/async_rpc.py +73 -18
- web3/providers/rpc/rpc.py +73 -30
- web3/providers/rpc/utils.py +1 -13
- web3/scripts/install_pre_releases.py +33 -0
- web3/scripts/parse_pygeth_version.py +16 -0
- web3/testing.py +4 -4
- web3/tracing.py +9 -5
- web3/types.py +141 -74
- web3/utils/__init__.py +64 -5
- web3/utils/abi.py +790 -10
- web3/utils/address.py +8 -0
- web3/utils/async_exception_handling.py +20 -11
- web3/utils/caching.py +34 -4
- web3/utils/exception_handling.py +9 -12
- web3/utils/subscriptions.py +285 -0
- {web3-7.0.0b1.dist-info → web3-7.7.0.dist-info}/LICENSE +1 -1
- web3-7.7.0.dist-info/METADATA +130 -0
- web3-7.7.0.dist-info/RECORD +171 -0
- {web3-7.0.0b1.dist-info → web3-7.7.0.dist-info}/WHEEL +1 -1
- {web3-7.0.0b1.dist-info → web3-7.7.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/caching.py +0 -155
- web3/_utils/contract_sources/contract_data/address_reflector.py +0 -29
- web3/_utils/module_testing/go_ethereum_personal_module.py +0 -300
- web3/_utils/request.py +0 -265
- web3/pm.py +0 -602
- web3/tools/__init__.py +0 -4
- web3/tools/benchmark/__init__.py +0 -0
- web3/tools/benchmark/main.py +0 -185
- web3/tools/benchmark/node.py +0 -126
- web3/tools/benchmark/reporting.py +0 -39
- web3/tools/benchmark/utils.py +0 -69
- 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-7.0.0b1.dist-info/METADATA +0 -114
- web3-7.0.0b1.dist-info/RECORD +0 -280
- web3-7.0.0b1.dist-info/entry_points.txt +0 -2
- /web3/_utils/{function_identifiers.py → abi_element_identifiers.py} +0 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import asyncio
|
|
1
2
|
import json
|
|
2
3
|
import math
|
|
3
4
|
import pytest
|
|
@@ -41,9 +42,6 @@ from hexbytes import (
|
|
|
41
42
|
HexBytes,
|
|
42
43
|
)
|
|
43
44
|
|
|
44
|
-
from web3._utils.empty import (
|
|
45
|
-
empty,
|
|
46
|
-
)
|
|
47
45
|
from web3._utils.ens import (
|
|
48
46
|
ens_addresses,
|
|
49
47
|
)
|
|
@@ -82,10 +80,13 @@ from web3.exceptions import (
|
|
|
82
80
|
TooManyRequests,
|
|
83
81
|
TransactionNotFound,
|
|
84
82
|
TransactionTypeMismatch,
|
|
83
|
+
Web3RPCError,
|
|
85
84
|
Web3ValidationError,
|
|
85
|
+
Web3ValueError,
|
|
86
86
|
)
|
|
87
87
|
from web3.middleware import (
|
|
88
88
|
ExtraDataToPOAMiddleware,
|
|
89
|
+
SignAndSendRawMiddlewareBuilder,
|
|
89
90
|
)
|
|
90
91
|
from web3.types import (
|
|
91
92
|
ENS,
|
|
@@ -110,7 +111,7 @@ UNKNOWN_HASH = HexStr(
|
|
|
110
111
|
# "test offchain lookup" as an abi-encoded string
|
|
111
112
|
OFFCHAIN_LOOKUP_TEST_DATA = "0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001474657374206f6666636861696e206c6f6f6b7570000000000000000000000000" # noqa: E501
|
|
112
113
|
OFFCHAIN_LOOKUP_4BYTE_DATA = "0x556f1830"
|
|
113
|
-
OFFCHAIN_LOOKUP_RETURN_DATA = "
|
|
114
|
+
OFFCHAIN_LOOKUP_RETURN_DATA = "00000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001a0da96d05a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002200000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000002c68747470733a2f2f776562332e70792f676174657761792f7b73656e6465727d2f7b646174617d2e6a736f6e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001768747470733a2f2f776562332e70792f6761746577617900000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001474657374206f6666636861696e206c6f6f6b757000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001474657374206f6666636861696e206c6f6f6b7570000000000000000000000000" # noqa: E501
|
|
114
115
|
# "web3py" as an abi-encoded string
|
|
115
116
|
WEB3PY_AS_HEXBYTES = "0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000067765623370790000000000000000000000000000000000000000000000000000" # noqa: E501
|
|
116
117
|
|
|
@@ -139,7 +140,10 @@ RPC_ACCESS_LIST = [
|
|
|
139
140
|
if TYPE_CHECKING:
|
|
140
141
|
from _pytest.monkeypatch import MonkeyPatch # noqa: F401
|
|
141
142
|
|
|
142
|
-
from web3.contract import
|
|
143
|
+
from web3.contract import ( # noqa: F401
|
|
144
|
+
AsyncContract,
|
|
145
|
+
Contract,
|
|
146
|
+
)
|
|
143
147
|
from web3.main import ( # noqa: F401
|
|
144
148
|
AsyncWeb3,
|
|
145
149
|
Web3,
|
|
@@ -147,7 +151,8 @@ if TYPE_CHECKING:
|
|
|
147
151
|
|
|
148
152
|
|
|
149
153
|
def abi_encoded_offchain_lookup_contract_address(
|
|
150
|
-
w3: Union["Web3", "AsyncWeb3"],
|
|
154
|
+
w3: Union["Web3", "AsyncWeb3"],
|
|
155
|
+
offchain_lookup_contract: Union["Contract", "AsyncContract"],
|
|
151
156
|
) -> HexAddress:
|
|
152
157
|
return HexAddress(
|
|
153
158
|
remove_0x_prefix(
|
|
@@ -175,11 +180,13 @@ class AsyncEthModuleTest:
|
|
|
175
180
|
|
|
176
181
|
@pytest.mark.asyncio
|
|
177
182
|
async def test_eth_send_transaction_legacy(
|
|
178
|
-
self,
|
|
183
|
+
self,
|
|
184
|
+
async_w3: "AsyncWeb3",
|
|
185
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
179
186
|
) -> None:
|
|
180
187
|
txn_params: TxParams = {
|
|
181
|
-
"from":
|
|
182
|
-
"to":
|
|
188
|
+
"from": async_keyfile_account_address_dual_type,
|
|
189
|
+
"to": async_keyfile_account_address_dual_type,
|
|
183
190
|
"value": Wei(1),
|
|
184
191
|
"gas": 21000,
|
|
185
192
|
"gasPrice": await async_w3.eth.gas_price,
|
|
@@ -195,11 +202,13 @@ class AsyncEthModuleTest:
|
|
|
195
202
|
|
|
196
203
|
@pytest.mark.asyncio
|
|
197
204
|
async def test_eth_modify_transaction_legacy(
|
|
198
|
-
self,
|
|
205
|
+
self,
|
|
206
|
+
async_w3: "AsyncWeb3",
|
|
207
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
199
208
|
) -> None:
|
|
200
209
|
txn_params: TxParams = {
|
|
201
|
-
"from":
|
|
202
|
-
"to":
|
|
210
|
+
"from": async_keyfile_account_address_dual_type,
|
|
211
|
+
"to": async_keyfile_account_address_dual_type,
|
|
203
212
|
"value": Wei(1),
|
|
204
213
|
"gas": 21000,
|
|
205
214
|
"gasPrice": async_w3.to_wei(
|
|
@@ -209,7 +218,7 @@ class AsyncEthModuleTest:
|
|
|
209
218
|
txn_hash = await async_w3.eth.send_transaction(txn_params)
|
|
210
219
|
|
|
211
220
|
modified_txn_hash = await async_w3.eth.modify_transaction(
|
|
212
|
-
txn_hash, gasPrice=(cast(
|
|
221
|
+
txn_hash, gasPrice=(cast(Wei, txn_params["gasPrice"] * 2)), value=Wei(2)
|
|
213
222
|
)
|
|
214
223
|
modified_txn = await async_w3.eth.get_transaction(modified_txn_hash)
|
|
215
224
|
|
|
@@ -225,11 +234,13 @@ class AsyncEthModuleTest:
|
|
|
225
234
|
|
|
226
235
|
@pytest.mark.asyncio
|
|
227
236
|
async def test_eth_modify_transaction(
|
|
228
|
-
self,
|
|
237
|
+
self,
|
|
238
|
+
async_w3: "AsyncWeb3",
|
|
239
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
229
240
|
) -> None:
|
|
230
241
|
txn_params: TxParams = {
|
|
231
|
-
"from":
|
|
232
|
-
"to":
|
|
242
|
+
"from": async_keyfile_account_address_dual_type,
|
|
243
|
+
"to": async_keyfile_account_address_dual_type,
|
|
233
244
|
"value": Wei(1),
|
|
234
245
|
"gas": 21000,
|
|
235
246
|
"maxPriorityFeePerGas": async_w3.to_wei(1, "gwei"),
|
|
@@ -239,9 +250,9 @@ class AsyncEthModuleTest:
|
|
|
239
250
|
|
|
240
251
|
modified_txn_hash = await async_w3.eth.modify_transaction(
|
|
241
252
|
txn_hash,
|
|
242
|
-
value=2,
|
|
243
|
-
maxPriorityFeePerGas=(cast(Wei, txn_params["maxPriorityFeePerGas"]
|
|
244
|
-
maxFeePerGas=(cast(Wei, txn_params["maxFeePerGas"]
|
|
253
|
+
value=Wei(2),
|
|
254
|
+
maxPriorityFeePerGas=(cast(Wei, txn_params["maxPriorityFeePerGas"] * 2)),
|
|
255
|
+
maxFeePerGas=(cast(Wei, txn_params["maxFeePerGas"] * 2)),
|
|
245
256
|
)
|
|
246
257
|
modified_txn = await async_w3.eth.get_transaction(modified_txn_hash)
|
|
247
258
|
|
|
@@ -261,11 +272,13 @@ class AsyncEthModuleTest:
|
|
|
261
272
|
|
|
262
273
|
@pytest.mark.asyncio
|
|
263
274
|
async def test_async_eth_sign_transaction(
|
|
264
|
-
self,
|
|
275
|
+
self,
|
|
276
|
+
async_w3: "AsyncWeb3",
|
|
277
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
265
278
|
) -> None:
|
|
266
279
|
txn_params: TxParams = {
|
|
267
|
-
"from":
|
|
268
|
-
"to":
|
|
280
|
+
"from": async_keyfile_account_address_dual_type,
|
|
281
|
+
"to": async_keyfile_account_address_dual_type,
|
|
269
282
|
"value": Wei(1),
|
|
270
283
|
"gas": 21000,
|
|
271
284
|
"maxFeePerGas": async_w3.to_wei(2, "gwei"),
|
|
@@ -274,7 +287,7 @@ class AsyncEthModuleTest:
|
|
|
274
287
|
}
|
|
275
288
|
result = await async_w3.eth.sign_transaction(txn_params)
|
|
276
289
|
signatory_account = async_w3.eth.account.recover_transaction(result["raw"])
|
|
277
|
-
assert
|
|
290
|
+
assert async_keyfile_account_address_dual_type == signatory_account
|
|
278
291
|
assert result["tx"]["to"] == txn_params["to"]
|
|
279
292
|
assert result["tx"]["value"] == txn_params["value"]
|
|
280
293
|
assert result["tx"]["gas"] == txn_params["gas"]
|
|
@@ -288,7 +301,7 @@ class AsyncEthModuleTest:
|
|
|
288
301
|
async def test_eth_sign_typed_data(
|
|
289
302
|
self,
|
|
290
303
|
async_w3: "AsyncWeb3",
|
|
291
|
-
|
|
304
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
292
305
|
async_skip_if_testrpc: Callable[["AsyncWeb3"], None],
|
|
293
306
|
) -> None:
|
|
294
307
|
validJSONMessage = """
|
|
@@ -333,7 +346,7 @@ class AsyncEthModuleTest:
|
|
|
333
346
|
async_skip_if_testrpc(async_w3)
|
|
334
347
|
signature = HexBytes(
|
|
335
348
|
await async_w3.eth.sign_typed_data(
|
|
336
|
-
|
|
349
|
+
async_keyfile_account_address_dual_type, json.loads(validJSONMessage)
|
|
337
350
|
)
|
|
338
351
|
)
|
|
339
352
|
assert len(signature) == 32 + 32 + 1
|
|
@@ -342,7 +355,7 @@ class AsyncEthModuleTest:
|
|
|
342
355
|
async def test_invalid_eth_sign_typed_data(
|
|
343
356
|
self,
|
|
344
357
|
async_w3: "AsyncWeb3",
|
|
345
|
-
|
|
358
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
346
359
|
async_skip_if_testrpc: Callable[["AsyncWeb3"], None],
|
|
347
360
|
) -> None:
|
|
348
361
|
async_skip_if_testrpc(async_w3)
|
|
@@ -386,20 +399,21 @@ class AsyncEthModuleTest:
|
|
|
386
399
|
}
|
|
387
400
|
"""
|
|
388
401
|
with pytest.raises(
|
|
389
|
-
|
|
402
|
+
Web3ValueError,
|
|
390
403
|
match=r".*Expected 2 items for array type Person\[2\], got 1 items.*",
|
|
391
404
|
):
|
|
392
405
|
await async_w3.eth.sign_typed_data(
|
|
393
|
-
|
|
406
|
+
async_keyfile_account_address_dual_type,
|
|
407
|
+
json.loads(invalid_typed_message),
|
|
394
408
|
)
|
|
395
409
|
|
|
396
410
|
@pytest.mark.asyncio
|
|
397
411
|
async def test_async_eth_sign_transaction_legacy(
|
|
398
|
-
self, async_w3: "AsyncWeb3",
|
|
412
|
+
self, async_w3: "AsyncWeb3", async_keyfile_account_address: ChecksumAddress
|
|
399
413
|
) -> None:
|
|
400
414
|
txn_params: TxParams = {
|
|
401
|
-
"from":
|
|
402
|
-
"to":
|
|
415
|
+
"from": async_keyfile_account_address,
|
|
416
|
+
"to": async_keyfile_account_address,
|
|
403
417
|
"value": Wei(1),
|
|
404
418
|
"gas": 21000,
|
|
405
419
|
"gasPrice": await async_w3.eth.gas_price,
|
|
@@ -407,7 +421,7 @@ class AsyncEthModuleTest:
|
|
|
407
421
|
}
|
|
408
422
|
result = await async_w3.eth.sign_transaction(txn_params)
|
|
409
423
|
signatory_account = async_w3.eth.account.recover_transaction(result["raw"])
|
|
410
|
-
assert
|
|
424
|
+
assert async_keyfile_account_address == signatory_account
|
|
411
425
|
assert result["tx"]["to"] == txn_params["to"]
|
|
412
426
|
assert result["tx"]["value"] == txn_params["value"]
|
|
413
427
|
assert result["tx"]["gas"] == txn_params["gas"]
|
|
@@ -416,11 +430,11 @@ class AsyncEthModuleTest:
|
|
|
416
430
|
|
|
417
431
|
@pytest.mark.asyncio
|
|
418
432
|
async def test_async_eth_sign_transaction_hex_fees(
|
|
419
|
-
self, async_w3: "AsyncWeb3",
|
|
433
|
+
self, async_w3: "AsyncWeb3", async_keyfile_account_address: ChecksumAddress
|
|
420
434
|
) -> None:
|
|
421
435
|
txn_params: TxParams = {
|
|
422
|
-
"from":
|
|
423
|
-
"to":
|
|
436
|
+
"from": async_keyfile_account_address,
|
|
437
|
+
"to": async_keyfile_account_address,
|
|
424
438
|
"value": Wei(1),
|
|
425
439
|
"gas": 21000,
|
|
426
440
|
"maxFeePerGas": hex(async_w3.to_wei(2, "gwei")),
|
|
@@ -429,7 +443,7 @@ class AsyncEthModuleTest:
|
|
|
429
443
|
}
|
|
430
444
|
result = await async_w3.eth.sign_transaction(txn_params)
|
|
431
445
|
signatory_account = async_w3.eth.account.recover_transaction(result["raw"])
|
|
432
|
-
assert
|
|
446
|
+
assert async_keyfile_account_address == signatory_account
|
|
433
447
|
assert result["tx"]["to"] == txn_params["to"]
|
|
434
448
|
assert result["tx"]["value"] == txn_params["value"]
|
|
435
449
|
assert result["tx"]["gas"] == txn_params["gas"]
|
|
@@ -444,9 +458,11 @@ class AsyncEthModuleTest:
|
|
|
444
458
|
reason="async name_to_address_middleware has not been implemented yet"
|
|
445
459
|
)
|
|
446
460
|
async def test_async_eth_sign_transaction_ens_names(
|
|
447
|
-
self, async_w3: "AsyncWeb3",
|
|
461
|
+
self, async_w3: "AsyncWeb3", async_keyfile_account_address: ChecksumAddress
|
|
448
462
|
) -> None:
|
|
449
|
-
with ens_addresses(
|
|
463
|
+
with ens_addresses(
|
|
464
|
+
async_w3, {"unlocked-account.eth": async_keyfile_account_address}
|
|
465
|
+
):
|
|
450
466
|
txn_params: TxParams = {
|
|
451
467
|
"from": "unlocked-account.eth",
|
|
452
468
|
"to": "unlocked-account.eth",
|
|
@@ -458,8 +474,8 @@ class AsyncEthModuleTest:
|
|
|
458
474
|
}
|
|
459
475
|
result = await async_w3.eth.sign_transaction(txn_params)
|
|
460
476
|
signatory_account = async_w3.eth.account.recover_transaction(result["raw"])
|
|
461
|
-
assert
|
|
462
|
-
assert result["tx"]["to"] ==
|
|
477
|
+
assert async_keyfile_account_address == signatory_account
|
|
478
|
+
assert result["tx"]["to"] == async_keyfile_account_address
|
|
463
479
|
assert result["tx"]["value"] == txn_params["value"]
|
|
464
480
|
assert result["tx"]["gas"] == txn_params["gas"]
|
|
465
481
|
assert result["tx"]["maxFeePerGas"] == txn_params["maxFeePerGas"]
|
|
@@ -471,16 +487,19 @@ class AsyncEthModuleTest:
|
|
|
471
487
|
|
|
472
488
|
@pytest.mark.asyncio
|
|
473
489
|
async def test_eth_send_transaction(
|
|
474
|
-
self,
|
|
490
|
+
self,
|
|
491
|
+
async_w3: "AsyncWeb3",
|
|
492
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
475
493
|
) -> None:
|
|
476
494
|
txn_params: TxParams = {
|
|
477
|
-
"from":
|
|
478
|
-
"to":
|
|
495
|
+
"from": async_keyfile_account_address_dual_type,
|
|
496
|
+
"to": async_keyfile_account_address_dual_type,
|
|
479
497
|
"value": Wei(1),
|
|
480
498
|
"gas": 21000,
|
|
481
499
|
"maxFeePerGas": async_w3.to_wei(3, "gwei"),
|
|
482
500
|
"maxPriorityFeePerGas": async_w3.to_wei(1, "gwei"),
|
|
483
501
|
}
|
|
502
|
+
|
|
484
503
|
txn_hash = await async_w3.eth.send_transaction(txn_params)
|
|
485
504
|
txn = await async_w3.eth.get_transaction(txn_hash)
|
|
486
505
|
|
|
@@ -490,18 +509,21 @@ class AsyncEthModuleTest:
|
|
|
490
509
|
assert txn["gas"] == 21000
|
|
491
510
|
assert txn["maxFeePerGas"] == txn_params["maxFeePerGas"]
|
|
492
511
|
assert txn["maxPriorityFeePerGas"] == txn_params["maxPriorityFeePerGas"]
|
|
493
|
-
assert txn["gasPrice"]
|
|
512
|
+
assert txn["gasPrice"] <= txn["maxFeePerGas"] # effective gas price
|
|
494
513
|
|
|
495
514
|
@pytest.mark.asyncio
|
|
496
515
|
async def test_eth_send_transaction_default_fees(
|
|
497
|
-
self,
|
|
516
|
+
self,
|
|
517
|
+
async_w3: "AsyncWeb3",
|
|
518
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
498
519
|
) -> None:
|
|
499
520
|
txn_params: TxParams = {
|
|
500
|
-
"from":
|
|
501
|
-
"to":
|
|
521
|
+
"from": async_keyfile_account_address_dual_type,
|
|
522
|
+
"to": async_keyfile_account_address_dual_type,
|
|
502
523
|
"value": Wei(1),
|
|
503
524
|
"gas": 21000,
|
|
504
525
|
}
|
|
526
|
+
|
|
505
527
|
txn_hash = await async_w3.eth.send_transaction(txn_params)
|
|
506
528
|
txn = await async_w3.eth.get_transaction(txn_hash)
|
|
507
529
|
|
|
@@ -511,15 +533,17 @@ class AsyncEthModuleTest:
|
|
|
511
533
|
assert txn["gas"] == 21000
|
|
512
534
|
assert is_integer(txn["maxPriorityFeePerGas"])
|
|
513
535
|
assert is_integer(txn["maxFeePerGas"])
|
|
514
|
-
assert txn["gasPrice"]
|
|
536
|
+
assert txn["gasPrice"] <= txn["maxFeePerGas"] # effective gas price
|
|
515
537
|
|
|
516
538
|
@pytest.mark.asyncio
|
|
517
539
|
async def test_eth_send_transaction_hex_fees(
|
|
518
|
-
self,
|
|
540
|
+
self,
|
|
541
|
+
async_w3: "AsyncWeb3",
|
|
542
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
519
543
|
) -> None:
|
|
520
544
|
txn_params: TxParams = {
|
|
521
|
-
"from":
|
|
522
|
-
"to":
|
|
545
|
+
"from": async_keyfile_account_address_dual_type,
|
|
546
|
+
"to": async_keyfile_account_address_dual_type,
|
|
523
547
|
"value": Wei(1),
|
|
524
548
|
"gas": 21000,
|
|
525
549
|
"maxFeePerGas": hex(250 * 10**9),
|
|
@@ -537,11 +561,13 @@ class AsyncEthModuleTest:
|
|
|
537
561
|
|
|
538
562
|
@pytest.mark.asyncio
|
|
539
563
|
async def test_eth_send_transaction_no_gas(
|
|
540
|
-
self,
|
|
564
|
+
self,
|
|
565
|
+
async_w3: "AsyncWeb3",
|
|
566
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
541
567
|
) -> None:
|
|
542
568
|
txn_params: TxParams = {
|
|
543
|
-
"from":
|
|
544
|
-
"to":
|
|
569
|
+
"from": async_keyfile_account_address_dual_type,
|
|
570
|
+
"to": async_keyfile_account_address_dual_type,
|
|
545
571
|
"value": Wei(1),
|
|
546
572
|
"maxFeePerGas": Wei(250 * 10**9),
|
|
547
573
|
"maxPriorityFeePerGas": Wei(2 * 10**9),
|
|
@@ -556,11 +582,13 @@ class AsyncEthModuleTest:
|
|
|
556
582
|
|
|
557
583
|
@pytest.mark.asyncio
|
|
558
584
|
async def test_eth_send_transaction_with_gas_price(
|
|
559
|
-
self,
|
|
585
|
+
self,
|
|
586
|
+
async_w3: "AsyncWeb3",
|
|
587
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
560
588
|
) -> None:
|
|
561
589
|
txn_params: TxParams = {
|
|
562
|
-
"from":
|
|
563
|
-
"to":
|
|
590
|
+
"from": async_keyfile_account_address_dual_type,
|
|
591
|
+
"to": async_keyfile_account_address_dual_type,
|
|
564
592
|
"value": Wei(1),
|
|
565
593
|
"gas": 21000,
|
|
566
594
|
"gasPrice": Wei(1),
|
|
@@ -572,11 +600,13 @@ class AsyncEthModuleTest:
|
|
|
572
600
|
|
|
573
601
|
@pytest.mark.asyncio
|
|
574
602
|
async def test_eth_send_transaction_no_priority_fee(
|
|
575
|
-
self,
|
|
603
|
+
self,
|
|
604
|
+
async_w3: "AsyncWeb3",
|
|
605
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
576
606
|
) -> None:
|
|
577
607
|
txn_params: TxParams = {
|
|
578
|
-
"from":
|
|
579
|
-
"to":
|
|
608
|
+
"from": async_keyfile_account_address_dual_type,
|
|
609
|
+
"to": async_keyfile_account_address_dual_type,
|
|
580
610
|
"value": Wei(1),
|
|
581
611
|
"gas": 21000,
|
|
582
612
|
"maxFeePerGas": Wei(250 * 10**9),
|
|
@@ -588,12 +618,14 @@ class AsyncEthModuleTest:
|
|
|
588
618
|
|
|
589
619
|
@pytest.mark.asyncio
|
|
590
620
|
async def test_eth_send_transaction_no_max_fee(
|
|
591
|
-
self,
|
|
621
|
+
self,
|
|
622
|
+
async_w3: "AsyncWeb3",
|
|
623
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
592
624
|
) -> None:
|
|
593
625
|
maxPriorityFeePerGas = async_w3.to_wei(2, "gwei")
|
|
594
626
|
txn_params: TxParams = {
|
|
595
|
-
"from":
|
|
596
|
-
"to":
|
|
627
|
+
"from": async_keyfile_account_address_dual_type,
|
|
628
|
+
"to": async_keyfile_account_address_dual_type,
|
|
597
629
|
"value": Wei(1),
|
|
598
630
|
"gas": 21000,
|
|
599
631
|
"maxPriorityFeePerGas": maxPriorityFeePerGas,
|
|
@@ -611,11 +643,13 @@ class AsyncEthModuleTest:
|
|
|
611
643
|
|
|
612
644
|
@pytest.mark.asyncio
|
|
613
645
|
async def test_eth_send_transaction_max_fee_less_than_tip(
|
|
614
|
-
self,
|
|
646
|
+
self,
|
|
647
|
+
async_w3: "AsyncWeb3",
|
|
648
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
615
649
|
) -> None:
|
|
616
650
|
txn_params: TxParams = {
|
|
617
|
-
"from":
|
|
618
|
-
"to":
|
|
651
|
+
"from": async_keyfile_account_address_dual_type,
|
|
652
|
+
"to": async_keyfile_account_address_dual_type,
|
|
619
653
|
"value": Wei(1),
|
|
620
654
|
"gas": 21000,
|
|
621
655
|
"maxFeePerGas": Wei(1 * 10**9),
|
|
@@ -628,14 +662,16 @@ class AsyncEthModuleTest:
|
|
|
628
662
|
|
|
629
663
|
@pytest.mark.asyncio
|
|
630
664
|
async def test_validation_middleware_chain_id_mismatch(
|
|
631
|
-
self,
|
|
665
|
+
self,
|
|
666
|
+
async_w3: "AsyncWeb3",
|
|
667
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
632
668
|
) -> None:
|
|
633
669
|
wrong_chain_id = 1234567890
|
|
634
670
|
actual_chain_id = await async_w3.eth.chain_id
|
|
635
671
|
|
|
636
672
|
txn_params: TxParams = {
|
|
637
|
-
"from":
|
|
638
|
-
"to":
|
|
673
|
+
"from": async_keyfile_account_address_dual_type,
|
|
674
|
+
"to": async_keyfile_account_address_dual_type,
|
|
639
675
|
"value": Wei(1),
|
|
640
676
|
"gas": 21000,
|
|
641
677
|
"maxFeePerGas": async_w3.to_wei(2, "gwei"),
|
|
@@ -669,29 +705,54 @@ class AsyncEthModuleTest:
|
|
|
669
705
|
async_w3.middleware_onion.remove("poa")
|
|
670
706
|
|
|
671
707
|
@pytest.mark.asyncio
|
|
672
|
-
async def
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
"
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
708
|
+
async def test_async_eth_send_raw_transaction(
|
|
709
|
+
self, async_w3: "AsyncWeb3", keyfile_account_pkey: HexStr
|
|
710
|
+
) -> None:
|
|
711
|
+
keyfile_account = async_w3.eth.account.from_key(keyfile_account_pkey)
|
|
712
|
+
txn = {
|
|
713
|
+
"chainId": 131277322940537, # the chainId set for the fixture
|
|
714
|
+
"from": keyfile_account.address,
|
|
715
|
+
"to": keyfile_account.address,
|
|
716
|
+
"value": Wei(0),
|
|
717
|
+
"gas": 21000,
|
|
718
|
+
"nonce": await async_w3.eth.get_transaction_count(
|
|
719
|
+
keyfile_account.address, "pending"
|
|
720
|
+
),
|
|
721
|
+
"gasPrice": 10**9,
|
|
722
|
+
}
|
|
723
|
+
signed = keyfile_account.sign_transaction(txn)
|
|
724
|
+
txn_hash = await async_w3.eth.send_raw_transaction(signed.raw_transaction)
|
|
725
|
+
assert txn_hash == HexBytes(signed.hash)
|
|
726
|
+
|
|
727
|
+
@pytest.mark.asyncio
|
|
728
|
+
async def test_async_sign_and_send_raw_middleware(
|
|
729
|
+
self, async_w3: "AsyncWeb3", keyfile_account_pkey: HexStr
|
|
730
|
+
) -> None:
|
|
731
|
+
keyfile_account = async_w3.eth.account.from_key(keyfile_account_pkey)
|
|
732
|
+
txn: TxParams = {
|
|
733
|
+
"from": keyfile_account.address,
|
|
734
|
+
"to": keyfile_account.address,
|
|
735
|
+
"value": Wei(0),
|
|
736
|
+
"gas": 21000,
|
|
737
|
+
}
|
|
738
|
+
async_w3.middleware_onion.inject(
|
|
739
|
+
SignAndSendRawMiddlewareBuilder.build(keyfile_account), "signing", layer=0
|
|
740
|
+
)
|
|
741
|
+
txn_hash = await async_w3.eth.send_transaction(txn)
|
|
742
|
+
assert isinstance(txn_hash, HexBytes)
|
|
743
|
+
|
|
744
|
+
# clean up
|
|
745
|
+
async_w3.middleware_onion.remove("signing")
|
|
687
746
|
|
|
688
747
|
@pytest.mark.asyncio
|
|
689
748
|
async def test_GasPriceStrategyMiddleware(
|
|
690
|
-
self,
|
|
749
|
+
self,
|
|
750
|
+
async_w3: "AsyncWeb3",
|
|
751
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
691
752
|
) -> None:
|
|
692
753
|
txn_params: TxParams = {
|
|
693
|
-
"from":
|
|
694
|
-
"to":
|
|
754
|
+
"from": async_keyfile_account_address_dual_type,
|
|
755
|
+
"to": async_keyfile_account_address_dual_type,
|
|
695
756
|
"value": Wei(1),
|
|
696
757
|
"gas": 21000,
|
|
697
758
|
}
|
|
@@ -710,11 +771,13 @@ class AsyncEthModuleTest:
|
|
|
710
771
|
|
|
711
772
|
@pytest.mark.asyncio
|
|
712
773
|
async def test_gas_price_strategy_middleware_hex_value(
|
|
713
|
-
self,
|
|
774
|
+
self,
|
|
775
|
+
async_w3: "AsyncWeb3",
|
|
776
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
714
777
|
) -> None:
|
|
715
778
|
txn_params: TxParams = {
|
|
716
|
-
"from":
|
|
717
|
-
"to":
|
|
779
|
+
"from": async_keyfile_account_address_dual_type,
|
|
780
|
+
"to": async_keyfile_account_address_dual_type,
|
|
718
781
|
"value": Wei(1),
|
|
719
782
|
"gas": 21000,
|
|
720
783
|
}
|
|
@@ -738,13 +801,13 @@ class AsyncEthModuleTest:
|
|
|
738
801
|
async def test_gas_price_from_strategy_bypassed_for_dynamic_fee_txn(
|
|
739
802
|
self,
|
|
740
803
|
async_w3: "AsyncWeb3",
|
|
741
|
-
|
|
804
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
742
805
|
max_fee: Wei,
|
|
743
806
|
) -> None:
|
|
744
807
|
max_priority_fee = async_w3.to_wei(1, "gwei")
|
|
745
808
|
txn_params: TxParams = {
|
|
746
|
-
"from":
|
|
747
|
-
"to":
|
|
809
|
+
"from": async_keyfile_account_address_dual_type,
|
|
810
|
+
"to": async_keyfile_account_address_dual_type,
|
|
748
811
|
"value": Wei(1),
|
|
749
812
|
"gas": 21000,
|
|
750
813
|
"maxPriorityFeePerGas": max_priority_fee,
|
|
@@ -767,7 +830,7 @@ class AsyncEthModuleTest:
|
|
|
767
830
|
else 2 * latest_block["baseFeePerGas"] + max_priority_fee
|
|
768
831
|
)
|
|
769
832
|
assert txn["maxPriorityFeePerGas"] == max_priority_fee
|
|
770
|
-
assert txn["gasPrice"]
|
|
833
|
+
assert txn["gasPrice"] <= txn["maxFeePerGas"] # effective gas price
|
|
771
834
|
|
|
772
835
|
async_w3.eth.set_gas_price_strategy(None) # reset strategy
|
|
773
836
|
|
|
@@ -775,11 +838,11 @@ class AsyncEthModuleTest:
|
|
|
775
838
|
async def test_gas_price_from_strategy_bypassed_for_dynamic_fee_txn_no_tip(
|
|
776
839
|
self,
|
|
777
840
|
async_w3: "AsyncWeb3",
|
|
778
|
-
|
|
841
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
779
842
|
) -> None:
|
|
780
843
|
txn_params: TxParams = {
|
|
781
|
-
"from":
|
|
782
|
-
"to":
|
|
844
|
+
"from": async_keyfile_account_address_dual_type,
|
|
845
|
+
"to": async_keyfile_account_address_dual_type,
|
|
783
846
|
"value": Wei(1),
|
|
784
847
|
"gas": 21000,
|
|
785
848
|
"maxFeePerGas": Wei(1000000000),
|
|
@@ -799,12 +862,14 @@ class AsyncEthModuleTest:
|
|
|
799
862
|
|
|
800
863
|
@pytest.mark.asyncio
|
|
801
864
|
async def test_eth_estimate_gas(
|
|
802
|
-
self,
|
|
865
|
+
self,
|
|
866
|
+
async_w3: "AsyncWeb3",
|
|
867
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
803
868
|
) -> None:
|
|
804
869
|
gas_estimate = await async_w3.eth.estimate_gas(
|
|
805
870
|
{
|
|
806
|
-
"from":
|
|
807
|
-
"to":
|
|
871
|
+
"from": async_keyfile_account_address_dual_type,
|
|
872
|
+
"to": async_keyfile_account_address_dual_type,
|
|
808
873
|
"value": Wei(1),
|
|
809
874
|
}
|
|
810
875
|
)
|
|
@@ -834,10 +899,11 @@ class AsyncEthModuleTest:
|
|
|
834
899
|
async def test_eth_estimate_gas_with_override_param_type_check(
|
|
835
900
|
self,
|
|
836
901
|
async_w3: "AsyncWeb3",
|
|
837
|
-
async_math_contract: "
|
|
902
|
+
async_math_contract: "AsyncContract",
|
|
838
903
|
params: StateOverrideParams,
|
|
839
904
|
) -> None:
|
|
840
|
-
|
|
905
|
+
accounts = await async_w3.eth.accounts
|
|
906
|
+
txn_params: TxParams = {"from": accounts[0]}
|
|
841
907
|
|
|
842
908
|
# assert does not raise
|
|
843
909
|
await async_w3.eth.estimate_gas(
|
|
@@ -933,9 +999,8 @@ class AsyncEthModuleTest:
|
|
|
933
999
|
async def test_eth_getBlockByNumber_latest(
|
|
934
1000
|
self, async_w3: "AsyncWeb3", async_empty_block: BlockData
|
|
935
1001
|
) -> None:
|
|
936
|
-
current_block_number = await async_w3.eth.block_number
|
|
937
1002
|
block = await async_w3.eth.get_block("latest")
|
|
938
|
-
assert block["
|
|
1003
|
+
assert block["hash"] is not None
|
|
939
1004
|
|
|
940
1005
|
@pytest.mark.asyncio
|
|
941
1006
|
async def test_eth_getBlockByNumber_not_found(
|
|
@@ -948,9 +1013,8 @@ class AsyncEthModuleTest:
|
|
|
948
1013
|
async def test_eth_getBlockByNumber_pending(
|
|
949
1014
|
self, async_w3: "AsyncWeb3", async_empty_block: BlockData
|
|
950
1015
|
) -> None:
|
|
951
|
-
current_block_number = await async_w3.eth.block_number
|
|
952
1016
|
block = await async_w3.eth.get_block("pending")
|
|
953
|
-
assert block["
|
|
1017
|
+
assert block["hash"] is None
|
|
954
1018
|
|
|
955
1019
|
@pytest.mark.asyncio
|
|
956
1020
|
async def test_eth_getBlockByNumber_earliest(
|
|
@@ -977,6 +1041,39 @@ class AsyncEthModuleTest:
|
|
|
977
1041
|
assert block is not None
|
|
978
1042
|
assert isinstance(block["number"], int)
|
|
979
1043
|
|
|
1044
|
+
@pytest.mark.asyncio
|
|
1045
|
+
async def test_eth_getBlockReceipts_hash(
|
|
1046
|
+
self, async_w3: "AsyncWeb3", async_empty_block: BlockData
|
|
1047
|
+
) -> None:
|
|
1048
|
+
receipts = await async_w3.eth.get_block_receipts(async_empty_block["hash"])
|
|
1049
|
+
assert isinstance(receipts, list)
|
|
1050
|
+
|
|
1051
|
+
@pytest.mark.asyncio
|
|
1052
|
+
async def test_eth_getBlockReceipts_not_found(self, async_w3: "AsyncWeb3") -> None:
|
|
1053
|
+
with pytest.raises(BlockNotFound):
|
|
1054
|
+
await async_w3.eth.get_block_receipts(UNKNOWN_HASH)
|
|
1055
|
+
|
|
1056
|
+
@pytest.mark.asyncio
|
|
1057
|
+
async def test_eth_getBlockReceipts_with_integer(
|
|
1058
|
+
self, async_w3: "AsyncWeb3", async_empty_block: BlockData
|
|
1059
|
+
) -> None:
|
|
1060
|
+
receipts = await async_w3.eth.get_block_receipts(async_empty_block["number"])
|
|
1061
|
+
assert isinstance(receipts, list)
|
|
1062
|
+
|
|
1063
|
+
@pytest.mark.asyncio
|
|
1064
|
+
async def test_eth_getBlockReceipts_safe(
|
|
1065
|
+
self, async_w3: "AsyncWeb3", async_empty_block: BlockData
|
|
1066
|
+
) -> None:
|
|
1067
|
+
receipts = await async_w3.eth.get_block_receipts("safe")
|
|
1068
|
+
assert isinstance(receipts, list)
|
|
1069
|
+
|
|
1070
|
+
@pytest.mark.asyncio
|
|
1071
|
+
async def test_eth_getBlockReceipts_finalized(
|
|
1072
|
+
self, async_w3: "AsyncWeb3", async_empty_block: BlockData
|
|
1073
|
+
) -> None:
|
|
1074
|
+
receipts = await async_w3.eth.get_block_receipts("finalized")
|
|
1075
|
+
assert isinstance(receipts, list)
|
|
1076
|
+
|
|
980
1077
|
@pytest.mark.asyncio
|
|
981
1078
|
async def test_eth_get_block_by_number_full_transactions(
|
|
982
1079
|
self, async_w3: "AsyncWeb3", async_block_with_txn: BlockData
|
|
@@ -1006,22 +1103,26 @@ class AsyncEthModuleTest:
|
|
|
1006
1103
|
self,
|
|
1007
1104
|
async_w3: "AsyncWeb3",
|
|
1008
1105
|
async_block_with_txn: BlockData,
|
|
1009
|
-
|
|
1106
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
1010
1107
|
) -> None:
|
|
1011
1108
|
# eth_getRawTransactionByBlockNumberAndIndex: block identifier
|
|
1012
|
-
# send a txn to make sure pending block has at least one txn
|
|
1013
1109
|
await async_w3.eth.send_transaction(
|
|
1014
1110
|
{
|
|
1015
|
-
"from":
|
|
1016
|
-
"to":
|
|
1111
|
+
"from": async_keyfile_account_address_dual_type,
|
|
1112
|
+
"to": async_keyfile_account_address_dual_type,
|
|
1017
1113
|
"value": Wei(1),
|
|
1018
1114
|
}
|
|
1019
1115
|
)
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1116
|
+
|
|
1117
|
+
async def wait_for_block_with_txn() -> HexBytes:
|
|
1118
|
+
while True:
|
|
1119
|
+
try:
|
|
1120
|
+
return await async_w3.eth.get_raw_transaction_by_block("latest", 0)
|
|
1121
|
+
except TransactionNotFound:
|
|
1122
|
+
await asyncio.sleep(0.1)
|
|
1123
|
+
continue
|
|
1124
|
+
|
|
1125
|
+
raw_txn = await asyncio.wait_for(wait_for_block_with_txn(), timeout=5)
|
|
1025
1126
|
assert is_bytes(raw_txn)
|
|
1026
1127
|
|
|
1027
1128
|
# eth_getRawTransactionByBlockNumberAndIndex: block number
|
|
@@ -1061,26 +1162,26 @@ class AsyncEthModuleTest:
|
|
|
1061
1162
|
) -> None:
|
|
1062
1163
|
unknown_identifier = "unknown"
|
|
1063
1164
|
with pytest.raises(
|
|
1064
|
-
|
|
1165
|
+
Web3ValueError,
|
|
1065
1166
|
match=(
|
|
1066
1167
|
"Value did not match any of the recognized block identifiers: "
|
|
1067
1168
|
f"{unknown_identifier}"
|
|
1068
1169
|
),
|
|
1069
1170
|
):
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
)
|
|
1171
|
+
# type ignored because we are testing an invalid block identifier
|
|
1172
|
+
await async_w3.eth.get_raw_transaction_by_block(unknown_identifier, 0) # type: ignore # noqa: E501
|
|
1073
1173
|
|
|
1074
1174
|
@pytest.mark.asyncio
|
|
1075
1175
|
async def test_eth_get_balance(self, async_w3: "AsyncWeb3") -> None:
|
|
1076
|
-
|
|
1176
|
+
accounts = await async_w3.eth.accounts
|
|
1177
|
+
account = accounts[0]
|
|
1077
1178
|
|
|
1078
1179
|
with pytest.raises(InvalidAddress):
|
|
1079
1180
|
await async_w3.eth.get_balance(
|
|
1080
|
-
ChecksumAddress(HexAddress(HexStr(
|
|
1181
|
+
ChecksumAddress(HexAddress(HexStr(account.lower())))
|
|
1081
1182
|
)
|
|
1082
1183
|
|
|
1083
|
-
balance = await async_w3.eth.get_balance(
|
|
1184
|
+
balance = await async_w3.eth.get_balance(account)
|
|
1084
1185
|
|
|
1085
1186
|
assert is_integer(balance)
|
|
1086
1187
|
assert balance >= 0
|
|
@@ -1097,7 +1198,7 @@ class AsyncEthModuleTest:
|
|
|
1097
1198
|
async def test_eth_get_code_invalid_address(
|
|
1098
1199
|
self,
|
|
1099
1200
|
async_w3: "AsyncWeb3",
|
|
1100
|
-
async_math_contract: "
|
|
1201
|
+
async_math_contract: "AsyncContract",
|
|
1101
1202
|
) -> None:
|
|
1102
1203
|
with pytest.raises(InvalidAddress):
|
|
1103
1204
|
await async_w3.eth.get_code(
|
|
@@ -1106,7 +1207,7 @@ class AsyncEthModuleTest:
|
|
|
1106
1207
|
|
|
1107
1208
|
@pytest.mark.asyncio
|
|
1108
1209
|
async def test_eth_get_code_with_block_identifier(
|
|
1109
|
-
self, async_w3: "AsyncWeb3", async_emitter_contract: "
|
|
1210
|
+
self, async_w3: "AsyncWeb3", async_emitter_contract: "AsyncContract"
|
|
1110
1211
|
) -> None:
|
|
1111
1212
|
block_id = await async_w3.eth.block_number
|
|
1112
1213
|
code = await async_w3.eth.get_code(async_emitter_contract.address, block_id)
|
|
@@ -1117,57 +1218,55 @@ class AsyncEthModuleTest:
|
|
|
1117
1218
|
async def test_eth_create_access_list(
|
|
1118
1219
|
self,
|
|
1119
1220
|
async_w3: "AsyncWeb3",
|
|
1120
|
-
|
|
1121
|
-
async_math_contract: "
|
|
1221
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
1222
|
+
async_math_contract: "AsyncContract",
|
|
1122
1223
|
) -> None:
|
|
1123
|
-
#
|
|
1124
|
-
|
|
1125
|
-
"from":
|
|
1126
|
-
"value": Wei(1),
|
|
1127
|
-
"gas": 21000,
|
|
1128
|
-
}
|
|
1129
|
-
txn = async_math_contract._prepare_transaction(
|
|
1130
|
-
fn_name="incrementCounter",
|
|
1131
|
-
fn_args=[1],
|
|
1132
|
-
transaction=txn_params,
|
|
1224
|
+
# build txn
|
|
1225
|
+
txn = await async_math_contract.functions.incrementCounter(1).build_transaction(
|
|
1226
|
+
{"from": async_keyfile_account_address_dual_type}
|
|
1133
1227
|
)
|
|
1134
1228
|
|
|
1135
|
-
# create access list
|
|
1136
|
-
response = await async_w3.eth.create_access_list(
|
|
1137
|
-
{
|
|
1138
|
-
"from": async_unlocked_account_dual_type,
|
|
1139
|
-
"to": async_math_contract.address,
|
|
1140
|
-
"data": txn["data"],
|
|
1141
|
-
}
|
|
1142
|
-
)
|
|
1229
|
+
# create access list
|
|
1230
|
+
response = await async_w3.eth.create_access_list(txn)
|
|
1143
1231
|
|
|
1144
1232
|
assert is_dict(response)
|
|
1145
1233
|
access_list = response["accessList"]
|
|
1146
1234
|
assert len(access_list) > 0
|
|
1147
1235
|
assert access_list[0]["address"] is not None
|
|
1148
1236
|
assert is_checksum_address(access_list[0]["address"])
|
|
1149
|
-
assert len(access_list[0]["storageKeys"][0]) ==
|
|
1237
|
+
assert len(access_list[0]["storageKeys"][0]) == 66
|
|
1150
1238
|
assert int(response["gasUsed"]) >= 0
|
|
1151
1239
|
|
|
1240
|
+
# assert the result can be used directly in a transaction dict
|
|
1241
|
+
txn["accessList"] = response["accessList"]
|
|
1242
|
+
txn["gas"] = response["gasUsed"]
|
|
1243
|
+
|
|
1244
|
+
# send txn with access list
|
|
1245
|
+
await async_w3.eth.send_transaction(txn)
|
|
1246
|
+
|
|
1152
1247
|
@pytest.mark.asyncio
|
|
1153
1248
|
async def test_eth_get_transaction_count(
|
|
1154
|
-
self,
|
|
1249
|
+
self,
|
|
1250
|
+
async_w3: "AsyncWeb3",
|
|
1251
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
1155
1252
|
) -> None:
|
|
1156
1253
|
transaction_count = await async_w3.eth.get_transaction_count(
|
|
1157
|
-
|
|
1254
|
+
async_keyfile_account_address_dual_type
|
|
1158
1255
|
)
|
|
1159
1256
|
assert is_integer(transaction_count)
|
|
1160
1257
|
assert transaction_count >= 0
|
|
1161
1258
|
|
|
1162
1259
|
@pytest.mark.asyncio
|
|
1163
1260
|
async def test_eth_call(
|
|
1164
|
-
self, async_w3: "AsyncWeb3", async_math_contract: "
|
|
1261
|
+
self, async_w3: "AsyncWeb3", async_math_contract: "AsyncContract"
|
|
1165
1262
|
) -> None:
|
|
1166
|
-
|
|
1263
|
+
accounts = await async_w3.eth.accounts
|
|
1264
|
+
account = accounts[0]
|
|
1265
|
+
|
|
1167
1266
|
txn_params = async_math_contract._prepare_transaction(
|
|
1168
|
-
|
|
1267
|
+
abi_element_identifier="add",
|
|
1169
1268
|
fn_args=(7, 11),
|
|
1170
|
-
transaction={"from":
|
|
1269
|
+
transaction={"from": account, "to": async_math_contract.address},
|
|
1171
1270
|
)
|
|
1172
1271
|
call_result = await async_w3.eth.call(txn_params)
|
|
1173
1272
|
assert is_string(call_result)
|
|
@@ -1178,12 +1277,13 @@ class AsyncEthModuleTest:
|
|
|
1178
1277
|
async def test_eth_call_with_override_code(
|
|
1179
1278
|
self,
|
|
1180
1279
|
async_w3: "AsyncWeb3",
|
|
1181
|
-
async_revert_contract: "
|
|
1280
|
+
async_revert_contract: "AsyncContract",
|
|
1182
1281
|
) -> None:
|
|
1183
|
-
|
|
1282
|
+
accounts = await async_w3.eth.accounts
|
|
1283
|
+
account = accounts[0]
|
|
1184
1284
|
txn_params = async_revert_contract._prepare_transaction(
|
|
1185
|
-
|
|
1186
|
-
transaction={"from":
|
|
1285
|
+
abi_element_identifier="normalFunction",
|
|
1286
|
+
transaction={"from": account, "to": async_revert_contract.address},
|
|
1187
1287
|
)
|
|
1188
1288
|
call_result = await async_w3.eth.call(txn_params)
|
|
1189
1289
|
(result,) = async_w3.codec.decode(["bool"], call_result)
|
|
@@ -1234,11 +1334,11 @@ class AsyncEthModuleTest:
|
|
|
1234
1334
|
async def test_eth_call_with_override_param_type_check(
|
|
1235
1335
|
self,
|
|
1236
1336
|
async_w3: "AsyncWeb3",
|
|
1237
|
-
async_math_contract: "
|
|
1337
|
+
async_math_contract: "AsyncContract",
|
|
1238
1338
|
params: StateOverrideParams,
|
|
1239
1339
|
) -> None:
|
|
1240
|
-
|
|
1241
|
-
txn_params: TxParams = {"from":
|
|
1340
|
+
accounts = await async_w3.eth.accounts
|
|
1341
|
+
txn_params: TxParams = {"from": accounts[0]}
|
|
1242
1342
|
|
|
1243
1343
|
# assert does not raise
|
|
1244
1344
|
await async_w3.eth.call(
|
|
@@ -1247,13 +1347,13 @@ class AsyncEthModuleTest:
|
|
|
1247
1347
|
|
|
1248
1348
|
@pytest.mark.asyncio
|
|
1249
1349
|
async def test_eth_call_with_0_result(
|
|
1250
|
-
self, async_w3: "AsyncWeb3", async_math_contract: "
|
|
1350
|
+
self, async_w3: "AsyncWeb3", async_math_contract: "AsyncContract"
|
|
1251
1351
|
) -> None:
|
|
1252
|
-
|
|
1352
|
+
accounts = await async_w3.eth.accounts
|
|
1253
1353
|
txn_params = async_math_contract._prepare_transaction(
|
|
1254
|
-
|
|
1354
|
+
abi_element_identifier="add",
|
|
1255
1355
|
fn_args=(0, 0),
|
|
1256
|
-
transaction={"from":
|
|
1356
|
+
transaction={"from": accounts[0], "to": async_math_contract.address},
|
|
1257
1357
|
)
|
|
1258
1358
|
call_result = await async_w3.eth.call(txn_params)
|
|
1259
1359
|
assert is_string(call_result)
|
|
@@ -1264,13 +1364,13 @@ class AsyncEthModuleTest:
|
|
|
1264
1364
|
async def test_eth_call_revert_with_msg(
|
|
1265
1365
|
self,
|
|
1266
1366
|
async_w3: "AsyncWeb3",
|
|
1267
|
-
async_revert_contract: "
|
|
1268
|
-
|
|
1367
|
+
async_revert_contract: "AsyncContract",
|
|
1368
|
+
async_keyfile_account_address: ChecksumAddress,
|
|
1269
1369
|
) -> None:
|
|
1270
1370
|
txn_params = async_revert_contract._prepare_transaction(
|
|
1271
|
-
|
|
1371
|
+
abi_element_identifier="revertWithMessage",
|
|
1272
1372
|
transaction={
|
|
1273
|
-
"from":
|
|
1373
|
+
"from": async_keyfile_account_address,
|
|
1274
1374
|
"to": async_revert_contract.address,
|
|
1275
1375
|
},
|
|
1276
1376
|
)
|
|
@@ -1283,14 +1383,14 @@ class AsyncEthModuleTest:
|
|
|
1283
1383
|
async def test_eth_call_revert_without_msg(
|
|
1284
1384
|
self,
|
|
1285
1385
|
async_w3: "AsyncWeb3",
|
|
1286
|
-
async_revert_contract: "
|
|
1287
|
-
|
|
1386
|
+
async_revert_contract: "AsyncContract",
|
|
1387
|
+
async_keyfile_account_address: ChecksumAddress,
|
|
1288
1388
|
) -> None:
|
|
1289
1389
|
with pytest.raises(ContractLogicError, match="execution reverted"):
|
|
1290
1390
|
txn_params = async_revert_contract._prepare_transaction(
|
|
1291
|
-
|
|
1391
|
+
abi_element_identifier="revertWithoutMessage",
|
|
1292
1392
|
transaction={
|
|
1293
|
-
"from":
|
|
1393
|
+
"from": async_keyfile_account_address,
|
|
1294
1394
|
"to": async_revert_contract.address,
|
|
1295
1395
|
},
|
|
1296
1396
|
)
|
|
@@ -1300,16 +1400,17 @@ class AsyncEthModuleTest:
|
|
|
1300
1400
|
async def test_eth_call_revert_custom_error_with_msg(
|
|
1301
1401
|
self,
|
|
1302
1402
|
async_w3: "AsyncWeb3",
|
|
1303
|
-
async_revert_contract: "
|
|
1304
|
-
|
|
1403
|
+
async_revert_contract: "AsyncContract",
|
|
1404
|
+
async_keyfile_account_address: ChecksumAddress,
|
|
1305
1405
|
) -> None:
|
|
1306
|
-
data = async_revert_contract.
|
|
1307
|
-
|
|
1406
|
+
data = async_revert_contract.encode_abi(
|
|
1407
|
+
abi_element_identifier="UnauthorizedWithMessage",
|
|
1408
|
+
args=["You are not authorized"],
|
|
1308
1409
|
)
|
|
1309
1410
|
txn_params = async_revert_contract._prepare_transaction(
|
|
1310
|
-
|
|
1411
|
+
abi_element_identifier="customErrorWithMessage",
|
|
1311
1412
|
transaction={
|
|
1312
|
-
"from":
|
|
1413
|
+
"from": async_keyfile_account_address,
|
|
1313
1414
|
"to": async_revert_contract.address,
|
|
1314
1415
|
},
|
|
1315
1416
|
)
|
|
@@ -1320,14 +1421,14 @@ class AsyncEthModuleTest:
|
|
|
1320
1421
|
async def test_eth_call_revert_custom_error_without_msg(
|
|
1321
1422
|
self,
|
|
1322
1423
|
async_w3: "AsyncWeb3",
|
|
1323
|
-
async_revert_contract: "
|
|
1324
|
-
|
|
1424
|
+
async_revert_contract: "AsyncContract",
|
|
1425
|
+
async_keyfile_account_address: ChecksumAddress,
|
|
1325
1426
|
) -> None:
|
|
1326
|
-
data = async_revert_contract.
|
|
1427
|
+
data = async_revert_contract.encode_abi(abi_element_identifier="Unauthorized")
|
|
1327
1428
|
txn_params = async_revert_contract._prepare_transaction(
|
|
1328
|
-
|
|
1429
|
+
abi_element_identifier="customErrorWithoutMessage",
|
|
1329
1430
|
transaction={
|
|
1330
|
-
"from":
|
|
1431
|
+
"from": async_keyfile_account_address,
|
|
1331
1432
|
"to": async_revert_contract.address,
|
|
1332
1433
|
},
|
|
1333
1434
|
)
|
|
@@ -1352,7 +1453,7 @@ class AsyncEthModuleTest:
|
|
|
1352
1453
|
async def test_contract_panic_errors(
|
|
1353
1454
|
self,
|
|
1354
1455
|
async_w3: "AsyncWeb3",
|
|
1355
|
-
async_panic_errors_contract: "
|
|
1456
|
+
async_panic_errors_contract: "AsyncContract",
|
|
1356
1457
|
panic_error: str,
|
|
1357
1458
|
params: List[Any],
|
|
1358
1459
|
) -> None:
|
|
@@ -1369,8 +1470,8 @@ class AsyncEthModuleTest:
|
|
|
1369
1470
|
async def test_eth_call_offchain_lookup(
|
|
1370
1471
|
self,
|
|
1371
1472
|
async_w3: "AsyncWeb3",
|
|
1372
|
-
async_offchain_lookup_contract: "
|
|
1373
|
-
|
|
1473
|
+
async_offchain_lookup_contract: "AsyncContract",
|
|
1474
|
+
async_keyfile_account_address: ChecksumAddress,
|
|
1374
1475
|
monkeypatch: "MonkeyPatch",
|
|
1375
1476
|
) -> None:
|
|
1376
1477
|
normalized_contract_address = to_hex_if_bytes(
|
|
@@ -1395,7 +1496,7 @@ class AsyncEthModuleTest:
|
|
|
1395
1496
|
async def test_eth_call_offchain_lookup_raises_when_ccip_read_is_disabled(
|
|
1396
1497
|
self,
|
|
1397
1498
|
async_w3: "AsyncWeb3",
|
|
1398
|
-
async_offchain_lookup_contract: "
|
|
1499
|
+
async_offchain_lookup_contract: "AsyncContract",
|
|
1399
1500
|
) -> None:
|
|
1400
1501
|
return_data = (
|
|
1401
1502
|
OFFCHAIN_LOOKUP_4BYTE_DATA
|
|
@@ -1433,8 +1534,8 @@ class AsyncEthModuleTest:
|
|
|
1433
1534
|
async def test_eth_call_offchain_lookup_call_flag_overrides_provider_flag(
|
|
1434
1535
|
self,
|
|
1435
1536
|
async_w3: "AsyncWeb3",
|
|
1436
|
-
async_offchain_lookup_contract: "
|
|
1437
|
-
|
|
1537
|
+
async_offchain_lookup_contract: "AsyncContract",
|
|
1538
|
+
async_keyfile_account_address: ChecksumAddress,
|
|
1438
1539
|
monkeypatch: "MonkeyPatch",
|
|
1439
1540
|
) -> None:
|
|
1440
1541
|
normalized_contract_address = to_hex_if_bytes(
|
|
@@ -1461,13 +1562,13 @@ class AsyncEthModuleTest:
|
|
|
1461
1562
|
async def test_eth_call_offchain_lookup_raises_if_max_redirects_is_less_than_4(
|
|
1462
1563
|
self,
|
|
1463
1564
|
async_w3: "AsyncWeb3",
|
|
1464
|
-
async_offchain_lookup_contract: "
|
|
1565
|
+
async_offchain_lookup_contract: "AsyncContract",
|
|
1465
1566
|
max_redirects: int,
|
|
1466
1567
|
) -> None:
|
|
1467
1568
|
default_max_redirects = async_w3.provider.ccip_read_max_redirects
|
|
1468
1569
|
|
|
1469
1570
|
async_w3.provider.ccip_read_max_redirects = max_redirects
|
|
1470
|
-
with pytest.raises(
|
|
1571
|
+
with pytest.raises(Web3ValueError, match="at least 4"):
|
|
1471
1572
|
await async_offchain_lookup_contract.caller().testOffchainLookup(
|
|
1472
1573
|
OFFCHAIN_LOOKUP_TEST_DATA
|
|
1473
1574
|
)
|
|
@@ -1478,8 +1579,8 @@ class AsyncEthModuleTest:
|
|
|
1478
1579
|
async def test_eth_call_offchain_lookup_raises_for_improperly_formatted_rest_request_response( # noqa: E501
|
|
1479
1580
|
self,
|
|
1480
1581
|
async_w3: "AsyncWeb3",
|
|
1481
|
-
async_offchain_lookup_contract: "
|
|
1482
|
-
|
|
1582
|
+
async_offchain_lookup_contract: "AsyncContract",
|
|
1583
|
+
async_keyfile_account_address: ChecksumAddress,
|
|
1483
1584
|
monkeypatch: "MonkeyPatch",
|
|
1484
1585
|
) -> None:
|
|
1485
1586
|
normalized_contract_address = to_hex_if_bytes(
|
|
@@ -1502,8 +1603,8 @@ class AsyncEthModuleTest:
|
|
|
1502
1603
|
async def test_eth_call_offchain_lookup_tries_next_url_for_non_4xx_error_status_and_tests_POST( # noqa: E501
|
|
1503
1604
|
self,
|
|
1504
1605
|
async_w3: "AsyncWeb3",
|
|
1505
|
-
async_offchain_lookup_contract: "
|
|
1506
|
-
|
|
1606
|
+
async_offchain_lookup_contract: "AsyncContract",
|
|
1607
|
+
async_keyfile_account_address: ChecksumAddress,
|
|
1507
1608
|
monkeypatch: "MonkeyPatch",
|
|
1508
1609
|
status_code_non_4xx_error: int,
|
|
1509
1610
|
) -> None:
|
|
@@ -1525,7 +1626,7 @@ class AsyncEthModuleTest:
|
|
|
1525
1626
|
async_mock_offchain_lookup_request_response(
|
|
1526
1627
|
monkeypatch,
|
|
1527
1628
|
http_method="POST",
|
|
1528
|
-
mocked_request_url=
|
|
1629
|
+
mocked_request_url="https://web3.py/gateway",
|
|
1529
1630
|
mocked_status_code=200,
|
|
1530
1631
|
mocked_json_data=WEB3PY_AS_HEXBYTES,
|
|
1531
1632
|
sender=normalized_contract_address,
|
|
@@ -1540,8 +1641,8 @@ class AsyncEthModuleTest:
|
|
|
1540
1641
|
async def test_eth_call_offchain_lookup_calls_raise_for_status_for_4xx_status_code(
|
|
1541
1642
|
self,
|
|
1542
1643
|
async_w3: "AsyncWeb3",
|
|
1543
|
-
async_offchain_lookup_contract: "
|
|
1544
|
-
|
|
1644
|
+
async_offchain_lookup_contract: "AsyncContract",
|
|
1645
|
+
async_keyfile_account_address: ChecksumAddress,
|
|
1545
1646
|
monkeypatch: "MonkeyPatch",
|
|
1546
1647
|
) -> None:
|
|
1547
1648
|
normalized_contract_address = to_hex_if_bytes(
|
|
@@ -1562,8 +1663,7 @@ class AsyncEthModuleTest:
|
|
|
1562
1663
|
@pytest.mark.asyncio
|
|
1563
1664
|
async def test_eth_call_offchain_lookup_raises_when_all_supplied_urls_fail(
|
|
1564
1665
|
self,
|
|
1565
|
-
|
|
1566
|
-
async_offchain_lookup_contract: "Contract",
|
|
1666
|
+
async_offchain_lookup_contract: "AsyncContract",
|
|
1567
1667
|
) -> None:
|
|
1568
1668
|
# GET and POST requests should fail since responses are not mocked
|
|
1569
1669
|
with pytest.raises(
|
|
@@ -1576,9 +1676,7 @@ class AsyncEthModuleTest:
|
|
|
1576
1676
|
@pytest.mark.asyncio
|
|
1577
1677
|
async def test_eth_call_continuous_offchain_lookup_raises_with_too_many_requests(
|
|
1578
1678
|
self,
|
|
1579
|
-
|
|
1580
|
-
async_offchain_lookup_contract: "Contract",
|
|
1581
|
-
async_unlocked_account: ChecksumAddress,
|
|
1679
|
+
async_offchain_lookup_contract: "AsyncContract",
|
|
1582
1680
|
monkeypatch: "MonkeyPatch",
|
|
1583
1681
|
) -> None:
|
|
1584
1682
|
normalized_contract_address = to_hex_if_bytes(
|
|
@@ -1592,23 +1690,12 @@ class AsyncEthModuleTest:
|
|
|
1592
1690
|
with pytest.raises(TooManyRequests, match="Too many CCIP read redirects"):
|
|
1593
1691
|
await async_offchain_lookup_contract.caller().continuousOffchainLookup() # noqa: E501 type: ignore
|
|
1594
1692
|
|
|
1595
|
-
@pytest.mark.asyncio
|
|
1596
|
-
async def test_async_eth_hashrate(self, async_w3: "AsyncWeb3") -> None:
|
|
1597
|
-
hashrate = await async_w3.eth.hashrate
|
|
1598
|
-
assert is_integer(hashrate)
|
|
1599
|
-
assert hashrate >= 0
|
|
1600
|
-
|
|
1601
1693
|
@pytest.mark.asyncio
|
|
1602
1694
|
async def test_async_eth_chain_id(self, async_w3: "AsyncWeb3") -> None:
|
|
1603
1695
|
chain_id = await async_w3.eth.chain_id
|
|
1604
1696
|
# chain id value from geth fixture genesis file
|
|
1605
1697
|
assert chain_id == 131277322940537
|
|
1606
1698
|
|
|
1607
|
-
@pytest.mark.asyncio
|
|
1608
|
-
async def test_async_eth_mining(self, async_w3: "AsyncWeb3") -> None:
|
|
1609
|
-
mining = await async_w3.eth.mining
|
|
1610
|
-
assert is_boolean(mining)
|
|
1611
|
-
|
|
1612
1699
|
@pytest.mark.asyncio
|
|
1613
1700
|
async def test_async_eth_get_transaction_receipt_mined(
|
|
1614
1701
|
self,
|
|
@@ -1630,14 +1717,17 @@ class AsyncEthModuleTest:
|
|
|
1630
1717
|
assert isinstance(effective_gas_price, int)
|
|
1631
1718
|
assert effective_gas_price > 0
|
|
1632
1719
|
|
|
1720
|
+
@flaky_geth_dev_mining
|
|
1633
1721
|
@pytest.mark.asyncio
|
|
1634
1722
|
async def test_async_eth_get_transaction_receipt_unmined(
|
|
1635
|
-
self,
|
|
1723
|
+
self,
|
|
1724
|
+
async_w3: "AsyncWeb3",
|
|
1725
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
1636
1726
|
) -> None:
|
|
1637
1727
|
txn_hash = await async_w3.eth.send_transaction(
|
|
1638
1728
|
{
|
|
1639
|
-
"from":
|
|
1640
|
-
"to":
|
|
1729
|
+
"from": async_keyfile_account_address_dual_type,
|
|
1730
|
+
"to": async_keyfile_account_address_dual_type,
|
|
1641
1731
|
"value": Wei(1),
|
|
1642
1732
|
"gas": 21000,
|
|
1643
1733
|
"maxFeePerGas": async_w3.to_wei(3, "gwei"),
|
|
@@ -1652,7 +1742,7 @@ class AsyncEthModuleTest:
|
|
|
1652
1742
|
self,
|
|
1653
1743
|
async_w3: "AsyncWeb3",
|
|
1654
1744
|
async_block_with_txn_with_log: BlockData,
|
|
1655
|
-
async_emitter_contract: "
|
|
1745
|
+
async_emitter_contract: "AsyncContract",
|
|
1656
1746
|
txn_hash_with_log: HexStr,
|
|
1657
1747
|
) -> None:
|
|
1658
1748
|
receipt = await async_w3.eth.wait_for_transaction_receipt(txn_hash_with_log)
|
|
@@ -1693,14 +1783,17 @@ class AsyncEthModuleTest:
|
|
|
1693
1783
|
assert isinstance(effective_gas_price, int)
|
|
1694
1784
|
assert effective_gas_price > 0
|
|
1695
1785
|
|
|
1786
|
+
@flaky_geth_dev_mining
|
|
1696
1787
|
@pytest.mark.asyncio
|
|
1697
1788
|
async def test_async_eth_wait_for_transaction_receipt_unmined(
|
|
1698
|
-
self,
|
|
1789
|
+
self,
|
|
1790
|
+
async_w3: "AsyncWeb3",
|
|
1791
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
1699
1792
|
) -> None:
|
|
1700
1793
|
txn_hash = await async_w3.eth.send_transaction(
|
|
1701
1794
|
{
|
|
1702
|
-
"from":
|
|
1703
|
-
"to":
|
|
1795
|
+
"from": async_keyfile_account_address_dual_type,
|
|
1796
|
+
"to": async_keyfile_account_address_dual_type,
|
|
1704
1797
|
"value": Wei(1),
|
|
1705
1798
|
"gas": 21000,
|
|
1706
1799
|
"maxFeePerGas": async_w3.to_wei(3, "gwei"),
|
|
@@ -1719,7 +1812,7 @@ class AsyncEthModuleTest:
|
|
|
1719
1812
|
self,
|
|
1720
1813
|
async_w3: "AsyncWeb3",
|
|
1721
1814
|
async_block_with_txn_with_log: BlockData,
|
|
1722
|
-
async_emitter_contract: "
|
|
1815
|
+
async_emitter_contract: "AsyncContract",
|
|
1723
1816
|
txn_hash_with_log: HexStr,
|
|
1724
1817
|
) -> None:
|
|
1725
1818
|
receipt = await async_w3.eth.wait_for_transaction_receipt(txn_hash_with_log)
|
|
@@ -1744,8 +1837,13 @@ class AsyncEthModuleTest:
|
|
|
1744
1837
|
accounts = await async_w3.eth.accounts
|
|
1745
1838
|
assert is_list_like(accounts)
|
|
1746
1839
|
assert len(accounts) != 0
|
|
1747
|
-
assert all(
|
|
1748
|
-
|
|
1840
|
+
assert all(is_checksum_address(account) for account in accounts)
|
|
1841
|
+
|
|
1842
|
+
@pytest.mark.asyncio
|
|
1843
|
+
async def test_async_eth_blob_base_fee(self, async_w3: "AsyncWeb3") -> None:
|
|
1844
|
+
blob_base_fee = await async_w3.eth.blob_base_fee
|
|
1845
|
+
assert is_integer(blob_base_fee)
|
|
1846
|
+
assert blob_base_fee >= 0
|
|
1749
1847
|
|
|
1750
1848
|
@pytest.mark.asyncio
|
|
1751
1849
|
async def test_async_eth_get_logs_without_logs(
|
|
@@ -1765,7 +1863,7 @@ class AsyncEthModuleTest:
|
|
|
1765
1863
|
"fromBlock": async_block_with_txn_with_log["number"],
|
|
1766
1864
|
"toBlock": BlockNumber(async_block_with_txn_with_log["number"] - 1),
|
|
1767
1865
|
}
|
|
1768
|
-
with pytest.raises(
|
|
1866
|
+
with pytest.raises(Web3RPCError):
|
|
1769
1867
|
result = await async_w3.eth.get_logs(filter_params)
|
|
1770
1868
|
|
|
1771
1869
|
# Test with `address`
|
|
@@ -1891,9 +1989,8 @@ class AsyncEthModuleTest:
|
|
|
1891
1989
|
# Test with None overflowing
|
|
1892
1990
|
filter_params: FilterParams = {
|
|
1893
1991
|
"fromBlock": BlockNumber(0),
|
|
1894
|
-
"topics": [None, None, None],
|
|
1992
|
+
"topics": [None, None, None, None],
|
|
1895
1993
|
}
|
|
1896
|
-
|
|
1897
1994
|
result = await async_w3.eth.get_logs(filter_params)
|
|
1898
1995
|
assert len(result) == 0
|
|
1899
1996
|
|
|
@@ -1917,7 +2014,7 @@ class AsyncEthModuleTest:
|
|
|
1917
2014
|
|
|
1918
2015
|
@pytest.mark.asyncio
|
|
1919
2016
|
async def test_async_eth_get_storage_at(
|
|
1920
|
-
self, async_w3: "AsyncWeb3", async_storage_contract: "
|
|
2017
|
+
self, async_w3: "AsyncWeb3", async_storage_contract: "AsyncContract"
|
|
1921
2018
|
) -> None:
|
|
1922
2019
|
async_storage_contract_address = async_storage_contract.address
|
|
1923
2020
|
|
|
@@ -1945,7 +2042,7 @@ class AsyncEthModuleTest:
|
|
|
1945
2042
|
@pytest.mark.asyncio
|
|
1946
2043
|
@pytest.mark.xfail
|
|
1947
2044
|
async def test_async_eth_get_storage_at_ens_name(
|
|
1948
|
-
self, async_w3: "AsyncWeb3", async_storage_contract: "
|
|
2045
|
+
self, async_w3: "AsyncWeb3", async_storage_contract: "AsyncContract"
|
|
1949
2046
|
) -> None:
|
|
1950
2047
|
with ens_addresses(async_w3, {"storage.eth": async_storage_contract.address}):
|
|
1951
2048
|
storage = await async_w3.eth.get_storage_at(ENS("storage.eth"), 1)
|
|
@@ -1955,26 +2052,26 @@ class AsyncEthModuleTest:
|
|
|
1955
2052
|
async def test_async_eth_get_storage_at_invalid_address(
|
|
1956
2053
|
self, async_w3: "AsyncWeb3"
|
|
1957
2054
|
) -> None:
|
|
1958
|
-
|
|
2055
|
+
accounts = await async_w3.eth.accounts
|
|
1959
2056
|
with pytest.raises(InvalidAddress):
|
|
1960
2057
|
await async_w3.eth.get_storage_at(
|
|
1961
|
-
ChecksumAddress(HexAddress(HexStr(
|
|
2058
|
+
ChecksumAddress(HexAddress(HexStr(accounts[0].lower()))), 0
|
|
1962
2059
|
)
|
|
1963
2060
|
|
|
1964
2061
|
def test_async_provider_default_account(
|
|
1965
|
-
self,
|
|
2062
|
+
self,
|
|
2063
|
+
async_w3: "AsyncWeb3",
|
|
2064
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
1966
2065
|
) -> None:
|
|
1967
|
-
|
|
1968
|
-
default_account = async_w3.eth.default_account
|
|
1969
|
-
assert default_account is empty
|
|
2066
|
+
current_default_account = async_w3.eth.default_account
|
|
1970
2067
|
|
|
1971
2068
|
# check setter
|
|
1972
|
-
async_w3.eth.default_account =
|
|
2069
|
+
async_w3.eth.default_account = async_keyfile_account_address_dual_type
|
|
1973
2070
|
default_account = async_w3.eth.default_account
|
|
1974
|
-
assert default_account ==
|
|
2071
|
+
assert default_account == async_keyfile_account_address_dual_type
|
|
1975
2072
|
|
|
1976
2073
|
# reset to default
|
|
1977
|
-
async_w3.eth.default_account =
|
|
2074
|
+
async_w3.eth.default_account = current_default_account
|
|
1978
2075
|
|
|
1979
2076
|
def test_async_provider_default_block(
|
|
1980
2077
|
self,
|
|
@@ -2056,17 +2153,20 @@ class AsyncEthModuleTest:
|
|
|
2056
2153
|
|
|
2057
2154
|
@pytest.mark.asyncio
|
|
2058
2155
|
async def test_async_eth_sign(
|
|
2059
|
-
self,
|
|
2156
|
+
self,
|
|
2157
|
+
async_w3: "AsyncWeb3",
|
|
2158
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
2060
2159
|
) -> None:
|
|
2061
2160
|
signature = await async_w3.eth.sign(
|
|
2062
|
-
|
|
2161
|
+
async_keyfile_account_address_dual_type,
|
|
2162
|
+
text="Message tö sign. Longer than hash!",
|
|
2063
2163
|
)
|
|
2064
2164
|
assert is_bytes(signature)
|
|
2065
2165
|
assert len(signature) == 32 + 32 + 1
|
|
2066
2166
|
|
|
2067
2167
|
# test other formats
|
|
2068
2168
|
hexsign = await async_w3.eth.sign(
|
|
2069
|
-
|
|
2169
|
+
async_keyfile_account_address_dual_type,
|
|
2070
2170
|
hexstr=HexStr(
|
|
2071
2171
|
"0x4d6573736167652074c3b6207369676e2e204c6f6e676572207468616e206861736821" # noqa: E501
|
|
2072
2172
|
),
|
|
@@ -2074,19 +2174,20 @@ class AsyncEthModuleTest:
|
|
|
2074
2174
|
assert hexsign == signature
|
|
2075
2175
|
|
|
2076
2176
|
intsign = await async_w3.eth.sign(
|
|
2077
|
-
|
|
2177
|
+
async_keyfile_account_address_dual_type,
|
|
2078
2178
|
0x4D6573736167652074C3B6207369676E2E204C6F6E676572207468616E206861736821,
|
|
2079
2179
|
)
|
|
2080
2180
|
assert intsign == signature
|
|
2081
2181
|
|
|
2082
2182
|
bytessign = await async_w3.eth.sign(
|
|
2083
|
-
|
|
2183
|
+
async_keyfile_account_address_dual_type,
|
|
2084
2184
|
b"Message t\xc3\xb6 sign. Longer than hash!",
|
|
2085
2185
|
)
|
|
2086
2186
|
assert bytessign == signature
|
|
2087
2187
|
|
|
2088
2188
|
new_signature = await async_w3.eth.sign(
|
|
2089
|
-
|
|
2189
|
+
async_keyfile_account_address_dual_type,
|
|
2190
|
+
text="different message is different",
|
|
2090
2191
|
)
|
|
2091
2192
|
assert new_signature != signature
|
|
2092
2193
|
|
|
@@ -2095,10 +2196,12 @@ class AsyncEthModuleTest:
|
|
|
2095
2196
|
reason="Async middleware to convert ENS names to addresses is missing"
|
|
2096
2197
|
)
|
|
2097
2198
|
async def test_async_eth_sign_ens_names(
|
|
2098
|
-
self,
|
|
2199
|
+
self,
|
|
2200
|
+
async_w3: "AsyncWeb3",
|
|
2201
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
2099
2202
|
) -> None:
|
|
2100
2203
|
with ens_addresses(
|
|
2101
|
-
async_w3, {"unlocked-acct.eth":
|
|
2204
|
+
async_w3, {"unlocked-acct.eth": async_keyfile_account_address_dual_type}
|
|
2102
2205
|
):
|
|
2103
2206
|
signature = await async_w3.eth.sign(
|
|
2104
2207
|
ENS("unlocked-acct.eth"), text="Message tö sign. Longer than hash!"
|
|
@@ -2109,11 +2212,13 @@ class AsyncEthModuleTest:
|
|
|
2109
2212
|
@flaky_geth_dev_mining
|
|
2110
2213
|
@pytest.mark.asyncio
|
|
2111
2214
|
async def test_async_eth_replace_transaction_legacy(
|
|
2112
|
-
self,
|
|
2215
|
+
self,
|
|
2216
|
+
async_w3: "AsyncWeb3",
|
|
2217
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
2113
2218
|
) -> None:
|
|
2114
2219
|
txn_params: TxParams = {
|
|
2115
|
-
"from":
|
|
2116
|
-
"to":
|
|
2220
|
+
"from": async_keyfile_account_address_dual_type,
|
|
2221
|
+
"to": async_keyfile_account_address_dual_type,
|
|
2117
2222
|
"value": Wei(1),
|
|
2118
2223
|
"gas": 21000,
|
|
2119
2224
|
"gasPrice": async_w3.to_wei(1, "gwei"),
|
|
@@ -2137,14 +2242,16 @@ class AsyncEthModuleTest:
|
|
|
2137
2242
|
@flaky_geth_dev_mining
|
|
2138
2243
|
@pytest.mark.asyncio
|
|
2139
2244
|
async def test_async_eth_replace_transaction(
|
|
2140
|
-
self,
|
|
2245
|
+
self,
|
|
2246
|
+
async_w3: "AsyncWeb3",
|
|
2247
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
2141
2248
|
) -> None:
|
|
2142
2249
|
two_gwei_in_wei = async_w3.to_wei(2, "gwei")
|
|
2143
2250
|
three_gwei_in_wei = async_w3.to_wei(3, "gwei")
|
|
2144
2251
|
|
|
2145
2252
|
txn_params: TxParams = {
|
|
2146
|
-
"from":
|
|
2147
|
-
"to":
|
|
2253
|
+
"from": async_keyfile_account_address_dual_type,
|
|
2254
|
+
"to": async_keyfile_account_address_dual_type,
|
|
2148
2255
|
"value": Wei(1),
|
|
2149
2256
|
"gas": 21000,
|
|
2150
2257
|
"maxFeePerGas": two_gwei_in_wei,
|
|
@@ -2172,11 +2279,13 @@ class AsyncEthModuleTest:
|
|
|
2172
2279
|
@flaky_geth_dev_mining
|
|
2173
2280
|
@pytest.mark.asyncio
|
|
2174
2281
|
async def test_async_eth_replace_transaction_underpriced(
|
|
2175
|
-
self,
|
|
2282
|
+
self,
|
|
2283
|
+
async_w3: "AsyncWeb3",
|
|
2284
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
2176
2285
|
) -> None:
|
|
2177
2286
|
txn_params: TxParams = {
|
|
2178
|
-
"from":
|
|
2179
|
-
"to":
|
|
2287
|
+
"from": async_keyfile_account_address_dual_type,
|
|
2288
|
+
"to": async_keyfile_account_address_dual_type,
|
|
2180
2289
|
"value": Wei(1),
|
|
2181
2290
|
"gas": 21000,
|
|
2182
2291
|
"maxFeePerGas": async_w3.to_wei(3, "gwei"),
|
|
@@ -2188,17 +2297,19 @@ class AsyncEthModuleTest:
|
|
|
2188
2297
|
txn_params["maxFeePerGas"] = one_gwei_in_wei
|
|
2189
2298
|
txn_params["maxPriorityFeePerGas"] = one_gwei_in_wei
|
|
2190
2299
|
|
|
2191
|
-
with pytest.raises(
|
|
2300
|
+
with pytest.raises(Web3RPCError, match="replacement transaction underpriced"):
|
|
2192
2301
|
await async_w3.eth.replace_transaction(txn_hash, txn_params)
|
|
2193
2302
|
|
|
2194
2303
|
@flaky_geth_dev_mining
|
|
2195
2304
|
@pytest.mark.asyncio
|
|
2196
2305
|
async def test_async_eth_replace_transaction_non_existing_transaction(
|
|
2197
|
-
self,
|
|
2306
|
+
self,
|
|
2307
|
+
async_w3: "AsyncWeb3",
|
|
2308
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
2198
2309
|
) -> None:
|
|
2199
2310
|
txn_params: TxParams = {
|
|
2200
|
-
"from":
|
|
2201
|
-
"to":
|
|
2311
|
+
"from": async_keyfile_account_address_dual_type,
|
|
2312
|
+
"to": async_keyfile_account_address_dual_type,
|
|
2202
2313
|
"value": Wei(1),
|
|
2203
2314
|
"gas": 21000,
|
|
2204
2315
|
"maxFeePerGas": async_w3.to_wei(3, "gwei"),
|
|
@@ -2215,11 +2326,13 @@ class AsyncEthModuleTest:
|
|
|
2215
2326
|
@flaky_geth_dev_mining
|
|
2216
2327
|
@pytest.mark.asyncio
|
|
2217
2328
|
async def test_async_eth_replace_transaction_already_mined(
|
|
2218
|
-
self,
|
|
2329
|
+
self,
|
|
2330
|
+
async_w3: "AsyncWeb3",
|
|
2331
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
2219
2332
|
) -> None:
|
|
2220
2333
|
txn_params: TxParams = {
|
|
2221
|
-
"from":
|
|
2222
|
-
"to":
|
|
2334
|
+
"from": async_keyfile_account_address_dual_type,
|
|
2335
|
+
"to": async_keyfile_account_address_dual_type,
|
|
2223
2336
|
"value": Wei(1),
|
|
2224
2337
|
"gas": 21000,
|
|
2225
2338
|
"maxFeePerGas": async_w3.to_wei(2, "gwei"),
|
|
@@ -2230,17 +2343,17 @@ class AsyncEthModuleTest:
|
|
|
2230
2343
|
|
|
2231
2344
|
txn_params["maxFeePerGas"] = async_w3.to_wei(3, "gwei")
|
|
2232
2345
|
txn_params["maxPriorityFeePerGas"] = async_w3.to_wei(2, "gwei")
|
|
2233
|
-
with pytest.raises(
|
|
2346
|
+
with pytest.raises(Web3ValueError, match="Supplied transaction with hash"):
|
|
2234
2347
|
await async_w3.eth.replace_transaction(txn_hash, txn_params)
|
|
2235
2348
|
|
|
2236
2349
|
@flaky_geth_dev_mining
|
|
2237
2350
|
@pytest.mark.asyncio
|
|
2238
2351
|
async def test_async_eth_replace_transaction_incorrect_nonce(
|
|
2239
|
-
self, async_w3: "AsyncWeb3",
|
|
2352
|
+
self, async_w3: "AsyncWeb3", async_keyfile_account_address: ChecksumAddress
|
|
2240
2353
|
) -> None:
|
|
2241
2354
|
txn_params: TxParams = {
|
|
2242
|
-
"from":
|
|
2243
|
-
"to":
|
|
2355
|
+
"from": async_keyfile_account_address,
|
|
2356
|
+
"to": async_keyfile_account_address,
|
|
2244
2357
|
"value": Wei(1),
|
|
2245
2358
|
"gas": 21000,
|
|
2246
2359
|
"maxFeePerGas": async_w3.to_wei(2, "gwei"),
|
|
@@ -2252,17 +2365,19 @@ class AsyncEthModuleTest:
|
|
|
2252
2365
|
txn_params["maxFeePerGas"] = async_w3.to_wei(3, "gwei")
|
|
2253
2366
|
txn_params["maxPriorityFeePerGas"] = async_w3.to_wei(2, "gwei")
|
|
2254
2367
|
txn_params["nonce"] = Nonce(txn["nonce"] + 1)
|
|
2255
|
-
with pytest.raises(
|
|
2368
|
+
with pytest.raises(Web3ValueError):
|
|
2256
2369
|
await async_w3.eth.replace_transaction(txn_hash, txn_params)
|
|
2257
2370
|
|
|
2258
2371
|
@flaky_geth_dev_mining
|
|
2259
2372
|
@pytest.mark.asyncio
|
|
2260
2373
|
async def test_async_eth_replace_transaction_gas_price_too_low(
|
|
2261
|
-
self,
|
|
2374
|
+
self,
|
|
2375
|
+
async_w3: "AsyncWeb3",
|
|
2376
|
+
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
2262
2377
|
) -> None:
|
|
2263
2378
|
txn_params: TxParams = {
|
|
2264
|
-
"from":
|
|
2265
|
-
"to":
|
|
2379
|
+
"from": async_keyfile_account_address_dual_type,
|
|
2380
|
+
"to": async_keyfile_account_address_dual_type,
|
|
2266
2381
|
"value": Wei(1),
|
|
2267
2382
|
"gas": 21000,
|
|
2268
2383
|
"gasPrice": async_w3.to_wei(2, "gwei"),
|
|
@@ -2270,19 +2385,18 @@ class AsyncEthModuleTest:
|
|
|
2270
2385
|
txn_hash = await async_w3.eth.send_transaction(txn_params)
|
|
2271
2386
|
|
|
2272
2387
|
txn_params["gasPrice"] = async_w3.to_wei(1, "gwei")
|
|
2273
|
-
with pytest.raises(
|
|
2388
|
+
with pytest.raises(Web3ValueError):
|
|
2274
2389
|
await async_w3.eth.replace_transaction(txn_hash, txn_params)
|
|
2275
2390
|
|
|
2276
|
-
@flaky_geth_dev_mining
|
|
2277
2391
|
@pytest.mark.asyncio
|
|
2278
2392
|
async def test_async_eth_replace_transaction_gas_price_defaulting_minimum(
|
|
2279
|
-
self, async_w3: "AsyncWeb3",
|
|
2393
|
+
self, async_w3: "AsyncWeb3", async_keyfile_account_address: ChecksumAddress
|
|
2280
2394
|
) -> None:
|
|
2281
2395
|
gas_price = async_w3.to_wei(1, "gwei")
|
|
2282
2396
|
|
|
2283
2397
|
txn_params: TxParams = {
|
|
2284
|
-
"from":
|
|
2285
|
-
"to":
|
|
2398
|
+
"from": async_keyfile_account_address,
|
|
2399
|
+
"to": async_keyfile_account_address,
|
|
2286
2400
|
"value": Wei(1),
|
|
2287
2401
|
"gas": 21000,
|
|
2288
2402
|
"gasPrice": gas_price,
|
|
@@ -2297,14 +2411,13 @@ class AsyncEthModuleTest:
|
|
|
2297
2411
|
gas_price * 1.125
|
|
2298
2412
|
) # minimum gas price
|
|
2299
2413
|
|
|
2300
|
-
@flaky_geth_dev_mining
|
|
2301
2414
|
@pytest.mark.asyncio
|
|
2302
2415
|
async def test_async_eth_replace_transaction_gas_price_defaulting_strategy_higher(
|
|
2303
|
-
self, async_w3: "AsyncWeb3",
|
|
2416
|
+
self, async_w3: "AsyncWeb3", async_keyfile_account_address: ChecksumAddress
|
|
2304
2417
|
) -> None:
|
|
2305
2418
|
txn_params: TxParams = {
|
|
2306
|
-
"from":
|
|
2307
|
-
"to":
|
|
2419
|
+
"from": async_keyfile_account_address,
|
|
2420
|
+
"to": async_keyfile_account_address,
|
|
2308
2421
|
"value": Wei(1),
|
|
2309
2422
|
"gas": 21000,
|
|
2310
2423
|
"gasPrice": async_w3.to_wei(1, "gwei"),
|
|
@@ -2313,7 +2426,7 @@ class AsyncEthModuleTest:
|
|
|
2313
2426
|
|
|
2314
2427
|
two_gwei_in_wei = async_w3.to_wei(2, "gwei")
|
|
2315
2428
|
|
|
2316
|
-
def higher_gas_price_strategy(
|
|
2429
|
+
def higher_gas_price_strategy(_async_w3: "AsyncWeb3", _txn: TxParams) -> Wei:
|
|
2317
2430
|
return two_gwei_in_wei
|
|
2318
2431
|
|
|
2319
2432
|
async_w3.eth.set_gas_price_strategy(higher_gas_price_strategy)
|
|
@@ -2326,16 +2439,14 @@ class AsyncEthModuleTest:
|
|
|
2326
2439
|
) # Strategy provides higher gas price
|
|
2327
2440
|
async_w3.eth.set_gas_price_strategy(None) # reset strategy
|
|
2328
2441
|
|
|
2329
|
-
@flaky_geth_dev_mining
|
|
2330
2442
|
@pytest.mark.asyncio
|
|
2331
2443
|
async def test_async_eth_replace_transaction_gas_price_defaulting_strategy_lower(
|
|
2332
|
-
self, async_w3: "AsyncWeb3",
|
|
2444
|
+
self, async_w3: "AsyncWeb3", async_keyfile_account_address: ChecksumAddress
|
|
2333
2445
|
) -> None:
|
|
2334
2446
|
gas_price = async_w3.to_wei(2, "gwei")
|
|
2335
|
-
|
|
2336
2447
|
txn_params: TxParams = {
|
|
2337
|
-
"from":
|
|
2338
|
-
"to":
|
|
2448
|
+
"from": async_keyfile_account_address,
|
|
2449
|
+
"to": async_keyfile_account_address,
|
|
2339
2450
|
"value": Wei(1),
|
|
2340
2451
|
"gas": 21000,
|
|
2341
2452
|
"gasPrice": gas_price,
|
|
@@ -2424,19 +2535,6 @@ class EthModuleTest:
|
|
|
2424
2535
|
assert is_integer(sync_dict["currentBlock"])
|
|
2425
2536
|
assert is_integer(sync_dict["highestBlock"])
|
|
2426
2537
|
|
|
2427
|
-
def test_eth_coinbase(self, w3: "Web3") -> None:
|
|
2428
|
-
coinbase = w3.eth.coinbase
|
|
2429
|
-
assert is_checksum_address(coinbase)
|
|
2430
|
-
|
|
2431
|
-
def test_eth_mining(self, w3: "Web3") -> None:
|
|
2432
|
-
mining = w3.eth.mining
|
|
2433
|
-
assert is_boolean(mining)
|
|
2434
|
-
|
|
2435
|
-
def test_eth_hashrate(self, w3: "Web3") -> None:
|
|
2436
|
-
hashrate = w3.eth.hashrate
|
|
2437
|
-
assert is_integer(hashrate)
|
|
2438
|
-
assert hashrate >= 0
|
|
2439
|
-
|
|
2440
2538
|
def test_eth_chain_id(self, w3: "Web3") -> None:
|
|
2441
2539
|
chain_id = w3.eth.chain_id
|
|
2442
2540
|
# chain id value from geth fixture genesis file
|
|
@@ -2503,8 +2601,12 @@ class EthModuleTest:
|
|
|
2503
2601
|
accounts = w3.eth.accounts
|
|
2504
2602
|
assert is_list_like(accounts)
|
|
2505
2603
|
assert len(accounts) != 0
|
|
2506
|
-
assert all(
|
|
2507
|
-
|
|
2604
|
+
assert all(is_checksum_address(account) for account in accounts)
|
|
2605
|
+
|
|
2606
|
+
def test_eth_blob_base_fee(self, w3: "Web3") -> None:
|
|
2607
|
+
blob_base_fee = w3.eth.blob_base_fee
|
|
2608
|
+
assert is_integer(blob_base_fee)
|
|
2609
|
+
assert blob_base_fee >= 0
|
|
2508
2610
|
|
|
2509
2611
|
def test_eth_block_number(self, w3: "Web3") -> None:
|
|
2510
2612
|
block_number = w3.eth.block_number
|
|
@@ -2517,12 +2619,12 @@ class EthModuleTest:
|
|
|
2517
2619
|
assert block_number >= 0
|
|
2518
2620
|
|
|
2519
2621
|
def test_eth_get_balance(self, w3: "Web3") -> None:
|
|
2520
|
-
|
|
2622
|
+
account = w3.eth.accounts[0]
|
|
2521
2623
|
|
|
2522
2624
|
with pytest.raises(InvalidAddress):
|
|
2523
|
-
w3.eth.get_balance(ChecksumAddress(HexAddress(HexStr(
|
|
2625
|
+
w3.eth.get_balance(ChecksumAddress(HexAddress(HexStr(account.lower()))))
|
|
2524
2626
|
|
|
2525
|
-
balance = w3.eth.get_balance(
|
|
2627
|
+
balance = w3.eth.get_balance(account)
|
|
2526
2628
|
|
|
2527
2629
|
assert is_integer(balance)
|
|
2528
2630
|
assert balance >= 0
|
|
@@ -2584,24 +2686,26 @@ class EthModuleTest:
|
|
|
2584
2686
|
assert storage == HexBytes(f"0x{'00' * 31}01")
|
|
2585
2687
|
|
|
2586
2688
|
def test_eth_get_storage_at_invalid_address(self, w3: "Web3") -> None:
|
|
2587
|
-
|
|
2689
|
+
account = w3.eth.accounts[0]
|
|
2588
2690
|
with pytest.raises(InvalidAddress):
|
|
2589
2691
|
w3.eth.get_storage_at(
|
|
2590
|
-
ChecksumAddress(HexAddress(HexStr(
|
|
2692
|
+
ChecksumAddress(HexAddress(HexStr(account.lower()))), 0
|
|
2591
2693
|
)
|
|
2592
2694
|
|
|
2593
2695
|
def test_eth_get_transaction_count(
|
|
2594
|
-
self, w3: "Web3",
|
|
2696
|
+
self, w3: "Web3", keyfile_account_address_dual_type: ChecksumAddress
|
|
2595
2697
|
) -> None:
|
|
2596
|
-
transaction_count = w3.eth.get_transaction_count(
|
|
2698
|
+
transaction_count = w3.eth.get_transaction_count(
|
|
2699
|
+
keyfile_account_address_dual_type
|
|
2700
|
+
)
|
|
2597
2701
|
assert is_integer(transaction_count)
|
|
2598
2702
|
assert transaction_count >= 0
|
|
2599
2703
|
|
|
2600
2704
|
def test_eth_get_transaction_count_ens_name(
|
|
2601
|
-
self, w3: "Web3",
|
|
2705
|
+
self, w3: "Web3", keyfile_account_address_dual_type: ChecksumAddress
|
|
2602
2706
|
) -> None:
|
|
2603
2707
|
with ens_addresses(
|
|
2604
|
-
w3, {"unlocked-acct-dual-type.eth":
|
|
2708
|
+
w3, {"unlocked-acct-dual-type.eth": keyfile_account_address_dual_type}
|
|
2605
2709
|
):
|
|
2606
2710
|
transaction_count = w3.eth.get_transaction_count(
|
|
2607
2711
|
ENS("unlocked-acct-dual-type.eth")
|
|
@@ -2610,10 +2714,10 @@ class EthModuleTest:
|
|
|
2610
2714
|
assert transaction_count >= 0
|
|
2611
2715
|
|
|
2612
2716
|
def test_eth_get_transaction_count_invalid_address(self, w3: "Web3") -> None:
|
|
2613
|
-
|
|
2717
|
+
account = w3.eth.accounts[0]
|
|
2614
2718
|
with pytest.raises(InvalidAddress):
|
|
2615
2719
|
w3.eth.get_transaction_count(
|
|
2616
|
-
ChecksumAddress(HexAddress(HexStr(
|
|
2720
|
+
ChecksumAddress(HexAddress(HexStr(account.lower())))
|
|
2617
2721
|
)
|
|
2618
2722
|
|
|
2619
2723
|
def test_eth_getBlockTransactionCountByHash_empty_block(
|
|
@@ -2699,47 +2803,44 @@ class EthModuleTest:
|
|
|
2699
2803
|
def test_eth_create_access_list(
|
|
2700
2804
|
self,
|
|
2701
2805
|
w3: "Web3",
|
|
2702
|
-
|
|
2806
|
+
keyfile_account_address_dual_type: ChecksumAddress,
|
|
2703
2807
|
math_contract: "Contract",
|
|
2704
2808
|
) -> None:
|
|
2705
|
-
#
|
|
2706
|
-
|
|
2707
|
-
"from":
|
|
2708
|
-
"value": Wei(1),
|
|
2709
|
-
"gas": 21000,
|
|
2710
|
-
}
|
|
2711
|
-
|
|
2712
|
-
txn = math_contract.functions.incrementCounter(1).build_transaction(txn_params)
|
|
2713
|
-
|
|
2714
|
-
# create access list using data from transaction
|
|
2715
|
-
response = w3.eth.create_access_list(
|
|
2716
|
-
{
|
|
2717
|
-
"from": unlocked_account_dual_type,
|
|
2718
|
-
"to": math_contract.address,
|
|
2719
|
-
"data": txn["data"],
|
|
2720
|
-
}
|
|
2809
|
+
# build txn
|
|
2810
|
+
txn = math_contract.functions.incrementCounter(1).build_transaction(
|
|
2811
|
+
{"from": keyfile_account_address_dual_type}
|
|
2721
2812
|
)
|
|
2722
2813
|
|
|
2814
|
+
# create access list
|
|
2815
|
+
response = w3.eth.create_access_list(txn)
|
|
2816
|
+
|
|
2723
2817
|
assert is_dict(response)
|
|
2724
2818
|
access_list = response["accessList"]
|
|
2725
2819
|
assert len(access_list) > 0
|
|
2726
2820
|
assert access_list[0]["address"] is not None
|
|
2727
2821
|
assert is_checksum_address(access_list[0]["address"])
|
|
2728
|
-
assert len(access_list[0]["storageKeys"][0]) ==
|
|
2822
|
+
assert len(access_list[0]["storageKeys"][0]) == 66
|
|
2729
2823
|
assert int(response["gasUsed"]) >= 0
|
|
2730
2824
|
|
|
2825
|
+
# assert the result can be used directly in a transaction dict
|
|
2826
|
+
txn["accessList"] = response["accessList"]
|
|
2827
|
+
txn["gas"] = response["gasUsed"]
|
|
2828
|
+
|
|
2829
|
+
# send txn with access list
|
|
2830
|
+
w3.eth.send_transaction(txn)
|
|
2831
|
+
|
|
2731
2832
|
def test_eth_sign(
|
|
2732
|
-
self, w3: "Web3",
|
|
2833
|
+
self, w3: "Web3", keyfile_account_address_dual_type: ChecksumAddress
|
|
2733
2834
|
) -> None:
|
|
2734
2835
|
signature = w3.eth.sign(
|
|
2735
|
-
|
|
2836
|
+
keyfile_account_address_dual_type, text="Message tö sign. Longer than hash!"
|
|
2736
2837
|
)
|
|
2737
2838
|
assert is_bytes(signature)
|
|
2738
2839
|
assert len(signature) == 32 + 32 + 1
|
|
2739
2840
|
|
|
2740
2841
|
# test other formats
|
|
2741
2842
|
hexsign = w3.eth.sign(
|
|
2742
|
-
|
|
2843
|
+
keyfile_account_address_dual_type,
|
|
2743
2844
|
hexstr=HexStr(
|
|
2744
2845
|
"0x4d6573736167652074c3b6207369676e2e204c6f6e676572207468616e206861736821" # noqa: E501
|
|
2745
2846
|
),
|
|
@@ -2747,25 +2848,28 @@ class EthModuleTest:
|
|
|
2747
2848
|
assert hexsign == signature
|
|
2748
2849
|
|
|
2749
2850
|
intsign = w3.eth.sign(
|
|
2750
|
-
|
|
2851
|
+
keyfile_account_address_dual_type,
|
|
2751
2852
|
0x4D6573736167652074C3B6207369676E2E204C6F6E676572207468616E206861736821,
|
|
2752
2853
|
)
|
|
2753
2854
|
assert intsign == signature
|
|
2754
2855
|
|
|
2755
2856
|
bytessign = w3.eth.sign(
|
|
2756
|
-
|
|
2857
|
+
keyfile_account_address_dual_type,
|
|
2858
|
+
b"Message t\xc3\xb6 sign. Longer than hash!",
|
|
2757
2859
|
)
|
|
2758
2860
|
assert bytessign == signature
|
|
2759
2861
|
|
|
2760
2862
|
new_signature = w3.eth.sign(
|
|
2761
|
-
|
|
2863
|
+
keyfile_account_address_dual_type, text="different message is different"
|
|
2762
2864
|
)
|
|
2763
2865
|
assert new_signature != signature
|
|
2764
2866
|
|
|
2765
2867
|
def test_eth_sign_ens_names(
|
|
2766
|
-
self, w3: "Web3",
|
|
2868
|
+
self, w3: "Web3", keyfile_account_address_dual_type: ChecksumAddress
|
|
2767
2869
|
) -> None:
|
|
2768
|
-
with ens_addresses(
|
|
2870
|
+
with ens_addresses(
|
|
2871
|
+
w3, {"unlocked-acct.eth": keyfile_account_address_dual_type}
|
|
2872
|
+
):
|
|
2769
2873
|
signature = w3.eth.sign(
|
|
2770
2874
|
"unlocked-acct.eth", text="Message tö sign. Longer than hash!"
|
|
2771
2875
|
)
|
|
@@ -2775,7 +2879,7 @@ class EthModuleTest:
|
|
|
2775
2879
|
def test_eth_sign_typed_data(
|
|
2776
2880
|
self,
|
|
2777
2881
|
w3: "Web3",
|
|
2778
|
-
|
|
2882
|
+
keyfile_account_address_dual_type: ChecksumAddress,
|
|
2779
2883
|
skip_if_testrpc: Callable[["Web3"], None],
|
|
2780
2884
|
) -> None:
|
|
2781
2885
|
validJSONMessage = """
|
|
@@ -2820,7 +2924,7 @@ class EthModuleTest:
|
|
|
2820
2924
|
skip_if_testrpc(w3)
|
|
2821
2925
|
signature = HexBytes(
|
|
2822
2926
|
w3.eth.sign_typed_data(
|
|
2823
|
-
|
|
2927
|
+
keyfile_account_address_dual_type, json.loads(validJSONMessage)
|
|
2824
2928
|
)
|
|
2825
2929
|
)
|
|
2826
2930
|
assert len(signature) == 32 + 32 + 1
|
|
@@ -2828,7 +2932,7 @@ class EthModuleTest:
|
|
|
2828
2932
|
def test_invalid_eth_sign_typed_data(
|
|
2829
2933
|
self,
|
|
2830
2934
|
w3: "Web3",
|
|
2831
|
-
|
|
2935
|
+
keyfile_account_address_dual_type: ChecksumAddress,
|
|
2832
2936
|
skip_if_testrpc: Callable[["Web3"], None],
|
|
2833
2937
|
) -> None:
|
|
2834
2938
|
skip_if_testrpc(w3)
|
|
@@ -2872,19 +2976,19 @@ class EthModuleTest:
|
|
|
2872
2976
|
}
|
|
2873
2977
|
"""
|
|
2874
2978
|
with pytest.raises(
|
|
2875
|
-
|
|
2979
|
+
Web3ValueError,
|
|
2876
2980
|
match=r".*Expected 2 items for array type Person\[2\], got 1 items.*",
|
|
2877
2981
|
):
|
|
2878
2982
|
w3.eth.sign_typed_data(
|
|
2879
|
-
|
|
2983
|
+
keyfile_account_address_dual_type, json.loads(invalid_typed_message)
|
|
2880
2984
|
)
|
|
2881
2985
|
|
|
2882
2986
|
def test_eth_sign_transaction_legacy(
|
|
2883
|
-
self, w3: "Web3",
|
|
2987
|
+
self, w3: "Web3", keyfile_account_address: ChecksumAddress
|
|
2884
2988
|
) -> None:
|
|
2885
2989
|
txn_params: TxParams = {
|
|
2886
|
-
"from":
|
|
2887
|
-
"to":
|
|
2990
|
+
"from": keyfile_account_address,
|
|
2991
|
+
"to": keyfile_account_address,
|
|
2888
2992
|
"value": Wei(1),
|
|
2889
2993
|
"gas": 21000,
|
|
2890
2994
|
"gasPrice": w3.eth.gas_price,
|
|
@@ -2892,7 +2996,7 @@ class EthModuleTest:
|
|
|
2892
2996
|
}
|
|
2893
2997
|
result = w3.eth.sign_transaction(txn_params)
|
|
2894
2998
|
signatory_account = w3.eth.account.recover_transaction(result["raw"])
|
|
2895
|
-
assert
|
|
2999
|
+
assert keyfile_account_address == signatory_account
|
|
2896
3000
|
assert result["tx"]["to"] == txn_params["to"]
|
|
2897
3001
|
assert result["tx"]["value"] == txn_params["value"]
|
|
2898
3002
|
assert result["tx"]["gas"] == txn_params["gas"]
|
|
@@ -2900,11 +3004,11 @@ class EthModuleTest:
|
|
|
2900
3004
|
assert result["tx"]["nonce"] == txn_params["nonce"]
|
|
2901
3005
|
|
|
2902
3006
|
def test_eth_sign_transaction(
|
|
2903
|
-
self, w3: "Web3",
|
|
3007
|
+
self, w3: "Web3", keyfile_account_address: ChecksumAddress
|
|
2904
3008
|
) -> None:
|
|
2905
3009
|
txn_params: TxParams = {
|
|
2906
|
-
"from":
|
|
2907
|
-
"to":
|
|
3010
|
+
"from": keyfile_account_address,
|
|
3011
|
+
"to": keyfile_account_address,
|
|
2908
3012
|
"value": Wei(1),
|
|
2909
3013
|
"gas": 21000,
|
|
2910
3014
|
"maxFeePerGas": w3.to_wei(2, "gwei"),
|
|
@@ -2913,7 +3017,7 @@ class EthModuleTest:
|
|
|
2913
3017
|
}
|
|
2914
3018
|
result = w3.eth.sign_transaction(txn_params)
|
|
2915
3019
|
signatory_account = w3.eth.account.recover_transaction(result["raw"])
|
|
2916
|
-
assert
|
|
3020
|
+
assert keyfile_account_address == signatory_account
|
|
2917
3021
|
assert result["tx"]["to"] == txn_params["to"]
|
|
2918
3022
|
assert result["tx"]["value"] == txn_params["value"]
|
|
2919
3023
|
assert result["tx"]["gas"] == txn_params["gas"]
|
|
@@ -2924,11 +3028,11 @@ class EthModuleTest:
|
|
|
2924
3028
|
assert result["tx"]["nonce"] == txn_params["nonce"]
|
|
2925
3029
|
|
|
2926
3030
|
def test_eth_sign_transaction_hex_fees(
|
|
2927
|
-
self, w3: "Web3",
|
|
3031
|
+
self, w3: "Web3", keyfile_account_address: ChecksumAddress
|
|
2928
3032
|
) -> None:
|
|
2929
3033
|
txn_params: TxParams = {
|
|
2930
|
-
"from":
|
|
2931
|
-
"to":
|
|
3034
|
+
"from": keyfile_account_address,
|
|
3035
|
+
"to": keyfile_account_address,
|
|
2932
3036
|
"value": Wei(1),
|
|
2933
3037
|
"gas": 21000,
|
|
2934
3038
|
"maxFeePerGas": hex(w3.to_wei(2, "gwei")),
|
|
@@ -2937,7 +3041,7 @@ class EthModuleTest:
|
|
|
2937
3041
|
}
|
|
2938
3042
|
result = w3.eth.sign_transaction(txn_params)
|
|
2939
3043
|
signatory_account = w3.eth.account.recover_transaction(result["raw"])
|
|
2940
|
-
assert
|
|
3044
|
+
assert keyfile_account_address == signatory_account
|
|
2941
3045
|
assert result["tx"]["to"] == txn_params["to"]
|
|
2942
3046
|
assert result["tx"]["value"] == txn_params["value"]
|
|
2943
3047
|
assert result["tx"]["gas"] == txn_params["gas"]
|
|
@@ -2948,9 +3052,9 @@ class EthModuleTest:
|
|
|
2948
3052
|
assert result["tx"]["nonce"] == txn_params["nonce"]
|
|
2949
3053
|
|
|
2950
3054
|
def test_eth_sign_transaction_ens_names(
|
|
2951
|
-
self, w3: "Web3",
|
|
3055
|
+
self, w3: "Web3", keyfile_account_address: ChecksumAddress
|
|
2952
3056
|
) -> None:
|
|
2953
|
-
with ens_addresses(w3, {"unlocked-account.eth":
|
|
3057
|
+
with ens_addresses(w3, {"unlocked-account.eth": keyfile_account_address}):
|
|
2954
3058
|
txn_params: TxParams = {
|
|
2955
3059
|
"from": "unlocked-account.eth",
|
|
2956
3060
|
"to": "unlocked-account.eth",
|
|
@@ -2962,8 +3066,8 @@ class EthModuleTest:
|
|
|
2962
3066
|
}
|
|
2963
3067
|
result = w3.eth.sign_transaction(txn_params)
|
|
2964
3068
|
signatory_account = w3.eth.account.recover_transaction(result["raw"])
|
|
2965
|
-
assert
|
|
2966
|
-
assert result["tx"]["to"] ==
|
|
3069
|
+
assert keyfile_account_address == signatory_account
|
|
3070
|
+
assert result["tx"]["to"] == keyfile_account_address
|
|
2967
3071
|
assert result["tx"]["value"] == txn_params["value"]
|
|
2968
3072
|
assert result["tx"]["gas"] == txn_params["gas"]
|
|
2969
3073
|
assert result["tx"]["maxFeePerGas"] == txn_params["maxFeePerGas"]
|
|
@@ -2974,12 +3078,12 @@ class EthModuleTest:
|
|
|
2974
3078
|
assert result["tx"]["nonce"] == txn_params["nonce"]
|
|
2975
3079
|
|
|
2976
3080
|
def test_eth_send_transaction_addr_checksum_required(
|
|
2977
|
-
self, w3: "Web3",
|
|
3081
|
+
self, w3: "Web3", keyfile_account_address: ChecksumAddress
|
|
2978
3082
|
) -> None:
|
|
2979
|
-
non_checksum_addr =
|
|
3083
|
+
non_checksum_addr = keyfile_account_address.lower()
|
|
2980
3084
|
txn_params: TxParams = {
|
|
2981
|
-
"from":
|
|
2982
|
-
"to":
|
|
3085
|
+
"from": keyfile_account_address,
|
|
3086
|
+
"to": keyfile_account_address,
|
|
2983
3087
|
"value": Wei(1),
|
|
2984
3088
|
"gas": 21000,
|
|
2985
3089
|
"maxFeePerGas": w3.to_wei(2, "gwei"),
|
|
@@ -2999,11 +3103,11 @@ class EthModuleTest:
|
|
|
2999
3103
|
w3.eth.send_transaction(invalid_params)
|
|
3000
3104
|
|
|
3001
3105
|
def test_eth_send_transaction_legacy(
|
|
3002
|
-
self, w3: "Web3",
|
|
3106
|
+
self, w3: "Web3", keyfile_account_address_dual_type: ChecksumAddress
|
|
3003
3107
|
) -> None:
|
|
3004
3108
|
txn_params: TxParams = {
|
|
3005
|
-
"from":
|
|
3006
|
-
"to":
|
|
3109
|
+
"from": keyfile_account_address_dual_type,
|
|
3110
|
+
"to": keyfile_account_address_dual_type,
|
|
3007
3111
|
"value": Wei(1),
|
|
3008
3112
|
"gas": 21000,
|
|
3009
3113
|
"gasPrice": w3.to_wei(
|
|
@@ -3020,16 +3124,17 @@ class EthModuleTest:
|
|
|
3020
3124
|
assert txn["gasPrice"] == txn_params["gasPrice"]
|
|
3021
3125
|
|
|
3022
3126
|
def test_eth_send_transaction(
|
|
3023
|
-
self, w3: "Web3",
|
|
3127
|
+
self, w3: "Web3", keyfile_account_address_dual_type: ChecksumAddress
|
|
3024
3128
|
) -> None:
|
|
3025
3129
|
txn_params: TxParams = {
|
|
3026
|
-
"from":
|
|
3027
|
-
"to":
|
|
3130
|
+
"from": keyfile_account_address_dual_type,
|
|
3131
|
+
"to": keyfile_account_address_dual_type,
|
|
3028
3132
|
"value": Wei(1),
|
|
3029
3133
|
"gas": 21000,
|
|
3030
3134
|
"maxFeePerGas": w3.to_wei(3, "gwei"),
|
|
3031
3135
|
"maxPriorityFeePerGas": w3.to_wei(1, "gwei"),
|
|
3032
3136
|
}
|
|
3137
|
+
|
|
3033
3138
|
txn_hash = w3.eth.send_transaction(txn_params)
|
|
3034
3139
|
txn = w3.eth.get_transaction(txn_hash)
|
|
3035
3140
|
|
|
@@ -3039,23 +3144,25 @@ class EthModuleTest:
|
|
|
3039
3144
|
assert txn["gas"] == 21000
|
|
3040
3145
|
assert txn["maxFeePerGas"] == txn_params["maxFeePerGas"]
|
|
3041
3146
|
assert txn["maxPriorityFeePerGas"] == txn_params["maxPriorityFeePerGas"]
|
|
3042
|
-
assert txn["gasPrice"]
|
|
3147
|
+
assert txn["gasPrice"] <= txn["maxFeePerGas"] # effective gas price
|
|
3043
3148
|
|
|
3044
3149
|
def test_eth_send_transaction_with_nonce(
|
|
3045
|
-
self, w3: "Web3",
|
|
3150
|
+
self, w3: "Web3", keyfile_account_address: ChecksumAddress
|
|
3046
3151
|
) -> None:
|
|
3047
3152
|
max_priority_fee_per_gas = w3.to_wei(1.234, "gwei")
|
|
3048
3153
|
max_fee_per_gas = Wei(
|
|
3049
3154
|
w3.eth.get_block("latest")["baseFeePerGas"] + max_priority_fee_per_gas
|
|
3050
3155
|
)
|
|
3051
3156
|
txn_params: TxParams = {
|
|
3052
|
-
"from":
|
|
3053
|
-
"to":
|
|
3157
|
+
"from": keyfile_account_address,
|
|
3158
|
+
"to": keyfile_account_address,
|
|
3054
3159
|
"value": Wei(1),
|
|
3055
3160
|
"gas": 21000,
|
|
3056
3161
|
"maxFeePerGas": max_fee_per_gas,
|
|
3057
3162
|
"maxPriorityFeePerGas": max_priority_fee_per_gas,
|
|
3058
|
-
"nonce": Nonce(
|
|
3163
|
+
"nonce": Nonce(
|
|
3164
|
+
w3.eth.get_transaction_count(keyfile_account_address, "pending")
|
|
3165
|
+
),
|
|
3059
3166
|
}
|
|
3060
3167
|
txn_hash = w3.eth.send_transaction(txn_params)
|
|
3061
3168
|
txn = w3.eth.get_transaction(txn_hash)
|
|
@@ -3071,11 +3178,11 @@ class EthModuleTest:
|
|
|
3071
3178
|
assert is_integer(txn_params["maxFeePerGas"])
|
|
3072
3179
|
|
|
3073
3180
|
def test_eth_send_transaction_default_fees(
|
|
3074
|
-
self, w3: "Web3",
|
|
3181
|
+
self, w3: "Web3", keyfile_account_address_dual_type: ChecksumAddress
|
|
3075
3182
|
) -> None:
|
|
3076
3183
|
txn_params: TxParams = {
|
|
3077
|
-
"from":
|
|
3078
|
-
"to":
|
|
3184
|
+
"from": keyfile_account_address_dual_type,
|
|
3185
|
+
"to": keyfile_account_address_dual_type,
|
|
3079
3186
|
"value": Wei(1),
|
|
3080
3187
|
"gas": 21000,
|
|
3081
3188
|
}
|
|
@@ -3088,14 +3195,14 @@ class EthModuleTest:
|
|
|
3088
3195
|
assert txn["gas"] == 21000
|
|
3089
3196
|
assert is_integer(txn["maxPriorityFeePerGas"])
|
|
3090
3197
|
assert is_integer(txn["maxFeePerGas"])
|
|
3091
|
-
assert txn["gasPrice"]
|
|
3198
|
+
assert txn["gasPrice"] <= txn["maxFeePerGas"] # effective gas price
|
|
3092
3199
|
|
|
3093
3200
|
def test_eth_send_transaction_hex_fees(
|
|
3094
|
-
self, w3: "Web3",
|
|
3201
|
+
self, w3: "Web3", keyfile_account_address_dual_type: ChecksumAddress
|
|
3095
3202
|
) -> None:
|
|
3096
3203
|
txn_params: TxParams = {
|
|
3097
|
-
"from":
|
|
3098
|
-
"to":
|
|
3204
|
+
"from": keyfile_account_address_dual_type,
|
|
3205
|
+
"to": keyfile_account_address_dual_type,
|
|
3099
3206
|
"value": Wei(1),
|
|
3100
3207
|
"gas": 21000,
|
|
3101
3208
|
"maxFeePerGas": hex(250 * 10**9),
|
|
@@ -3112,11 +3219,11 @@ class EthModuleTest:
|
|
|
3112
3219
|
assert txn["maxPriorityFeePerGas"] == 2 * 10**9
|
|
3113
3220
|
|
|
3114
3221
|
def test_eth_send_transaction_no_gas(
|
|
3115
|
-
self, w3: "Web3",
|
|
3222
|
+
self, w3: "Web3", keyfile_account_address_dual_type: ChecksumAddress
|
|
3116
3223
|
) -> None:
|
|
3117
3224
|
txn_params: TxParams = {
|
|
3118
|
-
"from":
|
|
3119
|
-
"to":
|
|
3225
|
+
"from": keyfile_account_address_dual_type,
|
|
3226
|
+
"to": keyfile_account_address_dual_type,
|
|
3120
3227
|
"value": Wei(1),
|
|
3121
3228
|
"maxFeePerGas": Wei(250 * 10**9),
|
|
3122
3229
|
"maxPriorityFeePerGas": Wei(2 * 10**9),
|
|
@@ -3130,11 +3237,11 @@ class EthModuleTest:
|
|
|
3130
3237
|
assert txn["gas"] == 121000 # 21000 + buffer
|
|
3131
3238
|
|
|
3132
3239
|
def test_eth_send_transaction_with_gas_price(
|
|
3133
|
-
self, w3: "Web3",
|
|
3240
|
+
self, w3: "Web3", keyfile_account_address_dual_type: ChecksumAddress
|
|
3134
3241
|
) -> None:
|
|
3135
3242
|
txn_params: TxParams = {
|
|
3136
|
-
"from":
|
|
3137
|
-
"to":
|
|
3243
|
+
"from": keyfile_account_address_dual_type,
|
|
3244
|
+
"to": keyfile_account_address_dual_type,
|
|
3138
3245
|
"value": Wei(1),
|
|
3139
3246
|
"gas": 21000,
|
|
3140
3247
|
"gasPrice": Wei(1),
|
|
@@ -3145,11 +3252,11 @@ class EthModuleTest:
|
|
|
3145
3252
|
w3.eth.send_transaction(txn_params)
|
|
3146
3253
|
|
|
3147
3254
|
def test_eth_send_transaction_no_priority_fee(
|
|
3148
|
-
self, w3: "Web3",
|
|
3255
|
+
self, w3: "Web3", keyfile_account_address_dual_type: ChecksumAddress
|
|
3149
3256
|
) -> None:
|
|
3150
3257
|
txn_params: TxParams = {
|
|
3151
|
-
"from":
|
|
3152
|
-
"to":
|
|
3258
|
+
"from": keyfile_account_address_dual_type,
|
|
3259
|
+
"to": keyfile_account_address_dual_type,
|
|
3153
3260
|
"value": Wei(1),
|
|
3154
3261
|
"gas": 21000,
|
|
3155
3262
|
"maxFeePerGas": Wei(250 * 10**9),
|
|
@@ -3160,12 +3267,12 @@ class EthModuleTest:
|
|
|
3160
3267
|
w3.eth.send_transaction(txn_params)
|
|
3161
3268
|
|
|
3162
3269
|
def test_eth_send_transaction_no_max_fee(
|
|
3163
|
-
self, w3: "Web3",
|
|
3270
|
+
self, w3: "Web3", keyfile_account_address_dual_type: ChecksumAddress
|
|
3164
3271
|
) -> None:
|
|
3165
3272
|
max_priority_fee_per_gas = w3.to_wei(2, "gwei")
|
|
3166
3273
|
txn_params: TxParams = {
|
|
3167
|
-
"from":
|
|
3168
|
-
"to":
|
|
3274
|
+
"from": keyfile_account_address_dual_type,
|
|
3275
|
+
"to": keyfile_account_address_dual_type,
|
|
3169
3276
|
"value": Wei(1),
|
|
3170
3277
|
"gas": 21000,
|
|
3171
3278
|
"maxPriorityFeePerGas": max_priority_fee_per_gas,
|
|
@@ -3182,11 +3289,11 @@ class EthModuleTest:
|
|
|
3182
3289
|
assert is_integer(txn["maxFeePerGas"])
|
|
3183
3290
|
|
|
3184
3291
|
def test_eth_send_transaction_max_fee_less_than_tip(
|
|
3185
|
-
self, w3: "Web3",
|
|
3292
|
+
self, w3: "Web3", keyfile_account_address_dual_type: ChecksumAddress
|
|
3186
3293
|
) -> None:
|
|
3187
3294
|
txn_params: TxParams = {
|
|
3188
|
-
"from":
|
|
3189
|
-
"to":
|
|
3295
|
+
"from": keyfile_account_address_dual_type,
|
|
3296
|
+
"to": keyfile_account_address_dual_type,
|
|
3190
3297
|
"value": Wei(1),
|
|
3191
3298
|
"gas": 21000,
|
|
3192
3299
|
"maxFeePerGas": Wei(1 * 10**9),
|
|
@@ -3198,14 +3305,14 @@ class EthModuleTest:
|
|
|
3198
3305
|
w3.eth.send_transaction(txn_params)
|
|
3199
3306
|
|
|
3200
3307
|
def test_validation_middleware_chain_id_mismatch(
|
|
3201
|
-
self, w3: "Web3",
|
|
3308
|
+
self, w3: "Web3", keyfile_account_address_dual_type: ChecksumAddress
|
|
3202
3309
|
) -> None:
|
|
3203
3310
|
wrong_chain_id = 1234567890
|
|
3204
3311
|
actual_chain_id = w3.eth.chain_id
|
|
3205
3312
|
|
|
3206
3313
|
txn_params: TxParams = {
|
|
3207
|
-
"from":
|
|
3208
|
-
"to":
|
|
3314
|
+
"from": keyfile_account_address_dual_type,
|
|
3315
|
+
"to": keyfile_account_address_dual_type,
|
|
3209
3316
|
"value": Wei(1),
|
|
3210
3317
|
"gas": Wei(21000),
|
|
3211
3318
|
"maxFeePerGas": w3.to_wei(2, "gwei"),
|
|
@@ -3223,12 +3330,15 @@ class EthModuleTest:
|
|
|
3223
3330
|
"max_fee", (1000000000, None), ids=["with_max_fee", "without_max_fee"]
|
|
3224
3331
|
)
|
|
3225
3332
|
def test_gas_price_from_strategy_bypassed_for_dynamic_fee_txn(
|
|
3226
|
-
self,
|
|
3333
|
+
self,
|
|
3334
|
+
w3: "Web3",
|
|
3335
|
+
keyfile_account_address_dual_type: ChecksumAddress,
|
|
3336
|
+
max_fee: Wei,
|
|
3227
3337
|
) -> None:
|
|
3228
3338
|
max_priority_fee = w3.to_wei(1, "gwei")
|
|
3229
3339
|
txn_params: TxParams = {
|
|
3230
|
-
"from":
|
|
3231
|
-
"to":
|
|
3340
|
+
"from": keyfile_account_address_dual_type,
|
|
3341
|
+
"to": keyfile_account_address_dual_type,
|
|
3232
3342
|
"value": Wei(1),
|
|
3233
3343
|
"gas": 21000,
|
|
3234
3344
|
"maxPriorityFeePerGas": max_priority_fee,
|
|
@@ -3251,18 +3361,18 @@ class EthModuleTest:
|
|
|
3251
3361
|
else 2 * latest_block["baseFeePerGas"] + max_priority_fee
|
|
3252
3362
|
)
|
|
3253
3363
|
assert txn["maxPriorityFeePerGas"] == max_priority_fee
|
|
3254
|
-
assert txn["gasPrice"]
|
|
3364
|
+
assert txn["gasPrice"] <= txn["maxFeePerGas"] # effective gas price
|
|
3255
3365
|
|
|
3256
3366
|
w3.eth.set_gas_price_strategy(None) # reset strategy
|
|
3257
3367
|
|
|
3258
3368
|
def test_gas_price_from_strategy_bypassed_for_dynamic_fee_txn_no_tip(
|
|
3259
3369
|
self,
|
|
3260
3370
|
w3: "Web3",
|
|
3261
|
-
|
|
3371
|
+
keyfile_account_address_dual_type: ChecksumAddress,
|
|
3262
3372
|
) -> None:
|
|
3263
3373
|
txn_params: TxParams = {
|
|
3264
|
-
"from":
|
|
3265
|
-
"to":
|
|
3374
|
+
"from": keyfile_account_address_dual_type,
|
|
3375
|
+
"to": keyfile_account_address_dual_type,
|
|
3266
3376
|
"value": Wei(1),
|
|
3267
3377
|
"gas": 21000,
|
|
3268
3378
|
"maxFeePerGas": Wei(1000000000),
|
|
@@ -3281,11 +3391,11 @@ class EthModuleTest:
|
|
|
3281
3391
|
w3.eth.set_gas_price_strategy(None) # reset strategy
|
|
3282
3392
|
|
|
3283
3393
|
def test_gas_price_strategy_hex_value(
|
|
3284
|
-
self, w3: "Web3",
|
|
3394
|
+
self, w3: "Web3", keyfile_account_address_dual_type: ChecksumAddress
|
|
3285
3395
|
) -> None:
|
|
3286
3396
|
txn_params: TxParams = {
|
|
3287
|
-
"from":
|
|
3288
|
-
"to":
|
|
3397
|
+
"from": keyfile_account_address_dual_type,
|
|
3398
|
+
"to": keyfile_account_address_dual_type,
|
|
3289
3399
|
"value": Wei(1),
|
|
3290
3400
|
"gas": 21000,
|
|
3291
3401
|
}
|
|
@@ -3304,11 +3414,11 @@ class EthModuleTest:
|
|
|
3304
3414
|
|
|
3305
3415
|
@flaky_geth_dev_mining
|
|
3306
3416
|
def test_eth_replace_transaction_legacy(
|
|
3307
|
-
self, w3: "Web3",
|
|
3417
|
+
self, w3: "Web3", keyfile_account_address_dual_type: ChecksumAddress
|
|
3308
3418
|
) -> None:
|
|
3309
3419
|
txn_params: TxParams = {
|
|
3310
|
-
"from":
|
|
3311
|
-
"to":
|
|
3420
|
+
"from": keyfile_account_address_dual_type,
|
|
3421
|
+
"to": keyfile_account_address_dual_type,
|
|
3312
3422
|
"value": Wei(1),
|
|
3313
3423
|
"gas": 21000,
|
|
3314
3424
|
"gasPrice": w3.to_wei(
|
|
@@ -3333,14 +3443,14 @@ class EthModuleTest:
|
|
|
3333
3443
|
|
|
3334
3444
|
@flaky_geth_dev_mining
|
|
3335
3445
|
def test_eth_replace_transaction(
|
|
3336
|
-
self, w3: "Web3",
|
|
3446
|
+
self, w3: "Web3", keyfile_account_address_dual_type: ChecksumAddress
|
|
3337
3447
|
) -> None:
|
|
3338
3448
|
two_gwei_in_wei = w3.to_wei(2, "gwei")
|
|
3339
3449
|
three_gwei_in_wei = w3.to_wei(3, "gwei")
|
|
3340
3450
|
|
|
3341
3451
|
txn_params: TxParams = {
|
|
3342
|
-
"from":
|
|
3343
|
-
"to":
|
|
3452
|
+
"from": keyfile_account_address_dual_type,
|
|
3453
|
+
"to": keyfile_account_address_dual_type,
|
|
3344
3454
|
"value": Wei(1),
|
|
3345
3455
|
"gas": 21000,
|
|
3346
3456
|
"maxFeePerGas": two_gwei_in_wei,
|
|
@@ -3367,11 +3477,11 @@ class EthModuleTest:
|
|
|
3367
3477
|
|
|
3368
3478
|
@flaky_geth_dev_mining
|
|
3369
3479
|
def test_eth_replace_transaction_underpriced(
|
|
3370
|
-
self, w3: "Web3",
|
|
3480
|
+
self, w3: "Web3", keyfile_account_address_dual_type: ChecksumAddress
|
|
3371
3481
|
) -> None:
|
|
3372
3482
|
txn_params: TxParams = {
|
|
3373
|
-
"from":
|
|
3374
|
-
"to":
|
|
3483
|
+
"from": keyfile_account_address_dual_type,
|
|
3484
|
+
"to": keyfile_account_address_dual_type,
|
|
3375
3485
|
"value": Wei(1),
|
|
3376
3486
|
"gas": 21000,
|
|
3377
3487
|
"maxFeePerGas": w3.to_wei(3, "gwei"),
|
|
@@ -3383,16 +3493,16 @@ class EthModuleTest:
|
|
|
3383
3493
|
txn_params["maxFeePerGas"] = one_gwei_in_wei
|
|
3384
3494
|
txn_params["maxPriorityFeePerGas"] = one_gwei_in_wei
|
|
3385
3495
|
|
|
3386
|
-
with pytest.raises(
|
|
3496
|
+
with pytest.raises(Web3RPCError, match="replacement transaction underpriced"):
|
|
3387
3497
|
w3.eth.replace_transaction(txn_hash, txn_params)
|
|
3388
3498
|
|
|
3389
3499
|
@flaky_geth_dev_mining
|
|
3390
3500
|
def test_eth_replace_transaction_non_existing_transaction(
|
|
3391
|
-
self, w3: "Web3",
|
|
3501
|
+
self, w3: "Web3", keyfile_account_address_dual_type: ChecksumAddress
|
|
3392
3502
|
) -> None:
|
|
3393
3503
|
txn_params: TxParams = {
|
|
3394
|
-
"from":
|
|
3395
|
-
"to":
|
|
3504
|
+
"from": keyfile_account_address_dual_type,
|
|
3505
|
+
"to": keyfile_account_address_dual_type,
|
|
3396
3506
|
"value": Wei(1),
|
|
3397
3507
|
"gas": 21000,
|
|
3398
3508
|
"maxFeePerGas": w3.to_wei(3, "gwei"),
|
|
@@ -3408,11 +3518,11 @@ class EthModuleTest:
|
|
|
3408
3518
|
|
|
3409
3519
|
@flaky_geth_dev_mining
|
|
3410
3520
|
def test_eth_replace_transaction_already_mined(
|
|
3411
|
-
self, w3: "Web3",
|
|
3521
|
+
self, w3: "Web3", keyfile_account_address_dual_type: ChecksumAddress
|
|
3412
3522
|
) -> None:
|
|
3413
3523
|
txn_params: TxParams = {
|
|
3414
|
-
"from":
|
|
3415
|
-
"to":
|
|
3524
|
+
"from": keyfile_account_address_dual_type,
|
|
3525
|
+
"to": keyfile_account_address_dual_type,
|
|
3416
3526
|
"value": Wei(1),
|
|
3417
3527
|
"gas": 21000,
|
|
3418
3528
|
"maxFeePerGas": w3.to_wei(2, "gwei"),
|
|
@@ -3423,16 +3533,16 @@ class EthModuleTest:
|
|
|
3423
3533
|
|
|
3424
3534
|
txn_params["maxFeePerGas"] = w3.to_wei(3, "gwei")
|
|
3425
3535
|
txn_params["maxPriorityFeePerGas"] = w3.to_wei(2, "gwei")
|
|
3426
|
-
with pytest.raises(
|
|
3536
|
+
with pytest.raises(Web3ValueError, match="Supplied transaction with hash"):
|
|
3427
3537
|
w3.eth.replace_transaction(txn_hash, txn_params)
|
|
3428
3538
|
|
|
3429
3539
|
@flaky_geth_dev_mining
|
|
3430
3540
|
def test_eth_replace_transaction_incorrect_nonce(
|
|
3431
|
-
self, w3: "Web3",
|
|
3541
|
+
self, w3: "Web3", keyfile_account_address: ChecksumAddress
|
|
3432
3542
|
) -> None:
|
|
3433
3543
|
txn_params: TxParams = {
|
|
3434
|
-
"from":
|
|
3435
|
-
"to":
|
|
3544
|
+
"from": keyfile_account_address,
|
|
3545
|
+
"to": keyfile_account_address,
|
|
3436
3546
|
"value": Wei(1),
|
|
3437
3547
|
"gas": 21000,
|
|
3438
3548
|
"maxFeePerGas": w3.to_wei(2, "gwei"),
|
|
@@ -3444,16 +3554,16 @@ class EthModuleTest:
|
|
|
3444
3554
|
txn_params["maxFeePerGas"] = w3.to_wei(3, "gwei")
|
|
3445
3555
|
txn_params["maxPriorityFeePerGas"] = w3.to_wei(2, "gwei")
|
|
3446
3556
|
txn_params["nonce"] = Nonce(txn["nonce"] + 1)
|
|
3447
|
-
with pytest.raises(
|
|
3557
|
+
with pytest.raises(Web3ValueError):
|
|
3448
3558
|
w3.eth.replace_transaction(txn_hash, txn_params)
|
|
3449
3559
|
|
|
3450
3560
|
@flaky_geth_dev_mining
|
|
3451
3561
|
def test_eth_replace_transaction_gas_price_too_low(
|
|
3452
|
-
self, w3: "Web3",
|
|
3562
|
+
self, w3: "Web3", keyfile_account_address_dual_type: ChecksumAddress
|
|
3453
3563
|
) -> None:
|
|
3454
3564
|
txn_params: TxParams = {
|
|
3455
|
-
"from":
|
|
3456
|
-
"to":
|
|
3565
|
+
"from": keyfile_account_address_dual_type,
|
|
3566
|
+
"to": keyfile_account_address_dual_type,
|
|
3457
3567
|
"value": Wei(1),
|
|
3458
3568
|
"gas": 21000,
|
|
3459
3569
|
"gasPrice": w3.to_wei(2, "gwei"),
|
|
@@ -3461,18 +3571,18 @@ class EthModuleTest:
|
|
|
3461
3571
|
txn_hash = w3.eth.send_transaction(txn_params)
|
|
3462
3572
|
|
|
3463
3573
|
txn_params["gasPrice"] = w3.to_wei(1, "gwei")
|
|
3464
|
-
with pytest.raises(
|
|
3574
|
+
with pytest.raises(Web3ValueError):
|
|
3465
3575
|
w3.eth.replace_transaction(txn_hash, txn_params)
|
|
3466
3576
|
|
|
3467
3577
|
@flaky_geth_dev_mining
|
|
3468
3578
|
def test_eth_replace_transaction_gas_price_defaulting_minimum(
|
|
3469
|
-
self, w3: "Web3",
|
|
3579
|
+
self, w3: "Web3", keyfile_account_address: ChecksumAddress
|
|
3470
3580
|
) -> None:
|
|
3471
3581
|
gas_price = w3.to_wei(1, "gwei")
|
|
3472
3582
|
|
|
3473
3583
|
txn_params: TxParams = {
|
|
3474
|
-
"from":
|
|
3475
|
-
"to":
|
|
3584
|
+
"from": keyfile_account_address,
|
|
3585
|
+
"to": keyfile_account_address,
|
|
3476
3586
|
"value": Wei(1),
|
|
3477
3587
|
"gas": 21000,
|
|
3478
3588
|
"gasPrice": gas_price,
|
|
@@ -3489,11 +3599,11 @@ class EthModuleTest:
|
|
|
3489
3599
|
|
|
3490
3600
|
@flaky_geth_dev_mining
|
|
3491
3601
|
def test_eth_replace_transaction_gas_price_defaulting_strategy_higher(
|
|
3492
|
-
self, w3: "Web3",
|
|
3602
|
+
self, w3: "Web3", keyfile_account_address: ChecksumAddress
|
|
3493
3603
|
) -> None:
|
|
3494
3604
|
txn_params: TxParams = {
|
|
3495
|
-
"from":
|
|
3496
|
-
"to":
|
|
3605
|
+
"from": keyfile_account_address,
|
|
3606
|
+
"to": keyfile_account_address,
|
|
3497
3607
|
"value": Wei(1),
|
|
3498
3608
|
"gas": 21000,
|
|
3499
3609
|
"gasPrice": w3.to_wei(1, "gwei"),
|
|
@@ -3517,13 +3627,12 @@ class EthModuleTest:
|
|
|
3517
3627
|
|
|
3518
3628
|
@flaky_geth_dev_mining
|
|
3519
3629
|
def test_eth_replace_transaction_gas_price_defaulting_strategy_lower(
|
|
3520
|
-
self, w3: "Web3",
|
|
3630
|
+
self, w3: "Web3", keyfile_account_address: ChecksumAddress
|
|
3521
3631
|
) -> None:
|
|
3522
3632
|
gas_price = w3.to_wei(2, "gwei")
|
|
3523
|
-
|
|
3524
3633
|
txn_params: TxParams = {
|
|
3525
|
-
"from":
|
|
3526
|
-
"to":
|
|
3634
|
+
"from": keyfile_account_address,
|
|
3635
|
+
"to": keyfile_account_address,
|
|
3527
3636
|
"value": Wei(1),
|
|
3528
3637
|
"gas": 21000,
|
|
3529
3638
|
"gasPrice": gas_price,
|
|
@@ -3543,11 +3652,11 @@ class EthModuleTest:
|
|
|
3543
3652
|
w3.eth.set_gas_price_strategy(None) # reset strategy
|
|
3544
3653
|
|
|
3545
3654
|
def test_eth_modify_transaction_legacy(
|
|
3546
|
-
self, w3: "Web3",
|
|
3655
|
+
self, w3: "Web3", keyfile_account_address: ChecksumAddress
|
|
3547
3656
|
) -> None:
|
|
3548
3657
|
txn_params: TxParams = {
|
|
3549
|
-
"from":
|
|
3550
|
-
"to":
|
|
3658
|
+
"from": keyfile_account_address,
|
|
3659
|
+
"to": keyfile_account_address,
|
|
3551
3660
|
"value": Wei(1),
|
|
3552
3661
|
"gas": 21000,
|
|
3553
3662
|
"gasPrice": w3.to_wei(
|
|
@@ -3557,7 +3666,7 @@ class EthModuleTest:
|
|
|
3557
3666
|
txn_hash = w3.eth.send_transaction(txn_params)
|
|
3558
3667
|
|
|
3559
3668
|
modified_txn_hash = w3.eth.modify_transaction(
|
|
3560
|
-
txn_hash, gasPrice=(cast(
|
|
3669
|
+
txn_hash, gasPrice=(cast(Wei, txn_params["gasPrice"] * 2)), value=Wei(2)
|
|
3561
3670
|
)
|
|
3562
3671
|
modified_txn = w3.eth.get_transaction(modified_txn_hash)
|
|
3563
3672
|
|
|
@@ -3572,11 +3681,11 @@ class EthModuleTest:
|
|
|
3572
3681
|
assert modified_txn["gasPrice"] == cast(int, txn_params["gasPrice"]) * 2
|
|
3573
3682
|
|
|
3574
3683
|
def test_eth_modify_transaction(
|
|
3575
|
-
self, w3: "Web3",
|
|
3684
|
+
self, w3: "Web3", keyfile_account_address: ChecksumAddress
|
|
3576
3685
|
) -> None:
|
|
3577
3686
|
txn_params: TxParams = {
|
|
3578
|
-
"from":
|
|
3579
|
-
"to":
|
|
3687
|
+
"from": keyfile_account_address,
|
|
3688
|
+
"to": keyfile_account_address,
|
|
3580
3689
|
"value": Wei(1),
|
|
3581
3690
|
"gas": 21000,
|
|
3582
3691
|
"maxPriorityFeePerGas": w3.to_wei(1, "gwei"),
|
|
@@ -3586,9 +3695,9 @@ class EthModuleTest:
|
|
|
3586
3695
|
|
|
3587
3696
|
modified_txn_hash = w3.eth.modify_transaction(
|
|
3588
3697
|
txn_hash,
|
|
3589
|
-
value=2,
|
|
3590
|
-
maxPriorityFeePerGas=(cast(Wei, txn_params["maxPriorityFeePerGas"]
|
|
3591
|
-
maxFeePerGas=(cast(Wei, txn_params["maxFeePerGas"]
|
|
3698
|
+
value=Wei(2),
|
|
3699
|
+
maxPriorityFeePerGas=(cast(Wei, txn_params["maxPriorityFeePerGas"] * 2)),
|
|
3700
|
+
maxFeePerGas=(cast(Wei, txn_params["maxFeePerGas"] * 2)),
|
|
3592
3701
|
)
|
|
3593
3702
|
modified_txn = w3.eth.get_transaction(modified_txn_hash)
|
|
3594
3703
|
|
|
@@ -3607,30 +3716,46 @@ class EthModuleTest:
|
|
|
3607
3716
|
assert modified_txn["maxFeePerGas"] == cast(Wei, txn_params["maxFeePerGas"]) * 2
|
|
3608
3717
|
|
|
3609
3718
|
def test_eth_send_raw_transaction(
|
|
3610
|
-
self, w3: "Web3",
|
|
3611
|
-
) -> None:
|
|
3612
|
-
|
|
3613
|
-
|
|
3614
|
-
|
|
3615
|
-
|
|
3616
|
-
|
|
3617
|
-
|
|
3618
|
-
|
|
3619
|
-
|
|
3620
|
-
|
|
3621
|
-
|
|
3622
|
-
|
|
3623
|
-
|
|
3719
|
+
self, w3: "Web3", keyfile_account_pkey: HexStr
|
|
3720
|
+
) -> None:
|
|
3721
|
+
keyfile_account = w3.eth.account.from_key(keyfile_account_pkey)
|
|
3722
|
+
txn = {
|
|
3723
|
+
"chainId": 131277322940537, # the chainId set for the fixture
|
|
3724
|
+
"from": keyfile_account.address,
|
|
3725
|
+
"to": keyfile_account.address,
|
|
3726
|
+
"value": Wei(0),
|
|
3727
|
+
"gas": 21000,
|
|
3728
|
+
"nonce": w3.eth.get_transaction_count(keyfile_account.address, "pending"),
|
|
3729
|
+
"gasPrice": 10**9,
|
|
3730
|
+
}
|
|
3731
|
+
signed = keyfile_account.sign_transaction(txn)
|
|
3732
|
+
txn_hash = w3.eth.send_raw_transaction(signed.raw_transaction)
|
|
3733
|
+
assert txn_hash == HexBytes(signed.hash)
|
|
3734
|
+
|
|
3735
|
+
def test_sign_and_send_raw_middleware(
|
|
3736
|
+
self, w3: "Web3", keyfile_account_pkey: HexStr
|
|
3737
|
+
) -> None:
|
|
3738
|
+
keyfile_account = w3.eth.account.from_key(keyfile_account_pkey)
|
|
3739
|
+
txn: TxParams = {
|
|
3740
|
+
"from": keyfile_account.address,
|
|
3741
|
+
"to": keyfile_account.address,
|
|
3742
|
+
"value": Wei(0),
|
|
3743
|
+
"gas": 21000,
|
|
3744
|
+
}
|
|
3745
|
+
w3.middleware_onion.inject(
|
|
3746
|
+
SignAndSendRawMiddlewareBuilder.build(keyfile_account), "signing", layer=0
|
|
3624
3747
|
)
|
|
3625
|
-
txn_hash = w3.eth.
|
|
3626
|
-
assert txn_hash
|
|
3748
|
+
txn_hash = w3.eth.send_transaction(txn)
|
|
3749
|
+
assert isinstance(txn_hash, HexBytes)
|
|
3750
|
+
|
|
3751
|
+
# cleanup
|
|
3752
|
+
w3.middleware_onion.remove("signing")
|
|
3627
3753
|
|
|
3628
3754
|
def test_eth_call(self, w3: "Web3", math_contract: "Contract") -> None:
|
|
3629
|
-
coinbase = w3.eth.coinbase
|
|
3630
3755
|
txn_params = math_contract._prepare_transaction(
|
|
3631
|
-
|
|
3756
|
+
abi_element_identifier="add",
|
|
3632
3757
|
fn_args=(7, 11),
|
|
3633
|
-
transaction={"from":
|
|
3758
|
+
transaction={"from": w3.eth.accounts[0], "to": math_contract.address},
|
|
3634
3759
|
)
|
|
3635
3760
|
call_result = w3.eth.call(txn_params)
|
|
3636
3761
|
assert is_string(call_result)
|
|
@@ -3640,10 +3765,9 @@ class EthModuleTest:
|
|
|
3640
3765
|
def test_eth_call_with_override_code(
|
|
3641
3766
|
self, w3: "Web3", revert_contract: "Contract"
|
|
3642
3767
|
) -> None:
|
|
3643
|
-
coinbase = w3.eth.coinbase
|
|
3644
3768
|
txn_params = revert_contract._prepare_transaction(
|
|
3645
|
-
|
|
3646
|
-
transaction={"from":
|
|
3769
|
+
abi_element_identifier="normalFunction",
|
|
3770
|
+
transaction={"from": w3.eth.accounts[0], "to": revert_contract.address},
|
|
3647
3771
|
)
|
|
3648
3772
|
call_result = w3.eth.call(txn_params)
|
|
3649
3773
|
(result,) = w3.codec.decode(["bool"], call_result)
|
|
@@ -3694,7 +3818,7 @@ class EthModuleTest:
|
|
|
3694
3818
|
math_contract: "Contract",
|
|
3695
3819
|
params: StateOverrideParams,
|
|
3696
3820
|
) -> None:
|
|
3697
|
-
txn_params: TxParams = {"from": w3.eth.
|
|
3821
|
+
txn_params: TxParams = {"from": w3.eth.accounts[0]}
|
|
3698
3822
|
|
|
3699
3823
|
# assert does not raise
|
|
3700
3824
|
w3.eth.call(txn_params, "latest", {math_contract.address: params})
|
|
@@ -3702,11 +3826,10 @@ class EthModuleTest:
|
|
|
3702
3826
|
def test_eth_call_with_0_result(
|
|
3703
3827
|
self, w3: "Web3", math_contract: "Contract"
|
|
3704
3828
|
) -> None:
|
|
3705
|
-
coinbase = w3.eth.coinbase
|
|
3706
3829
|
txn_params = math_contract._prepare_transaction(
|
|
3707
|
-
|
|
3830
|
+
abi_element_identifier="add",
|
|
3708
3831
|
fn_args=(0, 0),
|
|
3709
|
-
transaction={"from":
|
|
3832
|
+
transaction={"from": w3.eth.accounts[0], "to": math_contract.address},
|
|
3710
3833
|
)
|
|
3711
3834
|
call_result = w3.eth.call(txn_params)
|
|
3712
3835
|
assert is_string(call_result)
|
|
@@ -3717,12 +3840,12 @@ class EthModuleTest:
|
|
|
3717
3840
|
self,
|
|
3718
3841
|
w3: "Web3",
|
|
3719
3842
|
revert_contract: "Contract",
|
|
3720
|
-
|
|
3843
|
+
keyfile_account_address: ChecksumAddress,
|
|
3721
3844
|
) -> None:
|
|
3722
3845
|
txn_params = revert_contract._prepare_transaction(
|
|
3723
|
-
|
|
3846
|
+
abi_element_identifier="revertWithMessage",
|
|
3724
3847
|
transaction={
|
|
3725
|
-
"from":
|
|
3848
|
+
"from": keyfile_account_address,
|
|
3726
3849
|
"to": revert_contract.address,
|
|
3727
3850
|
},
|
|
3728
3851
|
)
|
|
@@ -3737,13 +3860,13 @@ class EthModuleTest:
|
|
|
3737
3860
|
self,
|
|
3738
3861
|
w3: "Web3",
|
|
3739
3862
|
revert_contract: "Contract",
|
|
3740
|
-
|
|
3863
|
+
keyfile_account_address: ChecksumAddress,
|
|
3741
3864
|
) -> None:
|
|
3742
3865
|
with pytest.raises(ContractLogicError, match="execution reverted"):
|
|
3743
3866
|
txn_params = revert_contract._prepare_transaction(
|
|
3744
|
-
|
|
3867
|
+
abi_element_identifier="revertWithoutMessage",
|
|
3745
3868
|
transaction={
|
|
3746
|
-
"from":
|
|
3869
|
+
"from": keyfile_account_address,
|
|
3747
3870
|
"to": revert_contract.address,
|
|
3748
3871
|
},
|
|
3749
3872
|
)
|
|
@@ -3753,15 +3876,16 @@ class EthModuleTest:
|
|
|
3753
3876
|
self,
|
|
3754
3877
|
w3: "Web3",
|
|
3755
3878
|
revert_contract: "Contract",
|
|
3756
|
-
|
|
3879
|
+
keyfile_account_address: ChecksumAddress,
|
|
3757
3880
|
) -> None:
|
|
3758
|
-
data = revert_contract.
|
|
3759
|
-
|
|
3881
|
+
data = revert_contract.encode_abi(
|
|
3882
|
+
abi_element_identifier="UnauthorizedWithMessage",
|
|
3883
|
+
args=["You are not authorized"],
|
|
3760
3884
|
)
|
|
3761
3885
|
txn_params = revert_contract._prepare_transaction(
|
|
3762
|
-
|
|
3886
|
+
abi_element_identifier="customErrorWithMessage",
|
|
3763
3887
|
transaction={
|
|
3764
|
-
"from":
|
|
3888
|
+
"from": keyfile_account_address,
|
|
3765
3889
|
"to": revert_contract.address,
|
|
3766
3890
|
},
|
|
3767
3891
|
)
|
|
@@ -3773,13 +3897,13 @@ class EthModuleTest:
|
|
|
3773
3897
|
self,
|
|
3774
3898
|
w3: "Web3",
|
|
3775
3899
|
revert_contract: "Contract",
|
|
3776
|
-
|
|
3900
|
+
keyfile_account_address: ChecksumAddress,
|
|
3777
3901
|
) -> None:
|
|
3778
|
-
data = revert_contract.
|
|
3902
|
+
data = revert_contract.encode_abi(abi_element_identifier="Unauthorized")
|
|
3779
3903
|
txn_params = revert_contract._prepare_transaction(
|
|
3780
|
-
|
|
3904
|
+
abi_element_identifier="customErrorWithoutMessage",
|
|
3781
3905
|
transaction={
|
|
3782
|
-
"from":
|
|
3906
|
+
"from": keyfile_account_address,
|
|
3783
3907
|
"to": revert_contract.address,
|
|
3784
3908
|
},
|
|
3785
3909
|
)
|
|
@@ -3821,7 +3945,7 @@ class EthModuleTest:
|
|
|
3821
3945
|
self,
|
|
3822
3946
|
w3: "Web3",
|
|
3823
3947
|
offchain_lookup_contract: "Contract",
|
|
3824
|
-
|
|
3948
|
+
keyfile_account_address: ChecksumAddress,
|
|
3825
3949
|
monkeypatch: "MonkeyPatch",
|
|
3826
3950
|
) -> None:
|
|
3827
3951
|
normalized_contract_address = to_hex_if_bytes(
|
|
@@ -3876,7 +4000,7 @@ class EthModuleTest:
|
|
|
3876
4000
|
self,
|
|
3877
4001
|
w3: "Web3",
|
|
3878
4002
|
offchain_lookup_contract: "Contract",
|
|
3879
|
-
|
|
4003
|
+
keyfile_account_address: ChecksumAddress,
|
|
3880
4004
|
monkeypatch: "MonkeyPatch",
|
|
3881
4005
|
) -> None:
|
|
3882
4006
|
normalized_contract_address = to_hex_if_bytes(
|
|
@@ -3907,7 +4031,7 @@ class EthModuleTest:
|
|
|
3907
4031
|
default_max_redirects = w3.provider.ccip_read_max_redirects
|
|
3908
4032
|
|
|
3909
4033
|
w3.provider.ccip_read_max_redirects = max_redirects
|
|
3910
|
-
with pytest.raises(
|
|
4034
|
+
with pytest.raises(Web3ValueError, match="at least 4"):
|
|
3911
4035
|
offchain_lookup_contract.functions.testOffchainLookup(
|
|
3912
4036
|
OFFCHAIN_LOOKUP_TEST_DATA
|
|
3913
4037
|
).call()
|
|
@@ -3918,7 +4042,7 @@ class EthModuleTest:
|
|
|
3918
4042
|
self,
|
|
3919
4043
|
w3: "Web3",
|
|
3920
4044
|
offchain_lookup_contract: "Contract",
|
|
3921
|
-
|
|
4045
|
+
keyfile_account_address: ChecksumAddress,
|
|
3922
4046
|
monkeypatch: "MonkeyPatch",
|
|
3923
4047
|
) -> None:
|
|
3924
4048
|
normalized_contract_address = to_hex_if_bytes(
|
|
@@ -3940,7 +4064,7 @@ class EthModuleTest:
|
|
|
3940
4064
|
self,
|
|
3941
4065
|
w3: "Web3",
|
|
3942
4066
|
offchain_lookup_contract: "Contract",
|
|
3943
|
-
|
|
4067
|
+
keyfile_account_address: ChecksumAddress,
|
|
3944
4068
|
monkeypatch: "MonkeyPatch",
|
|
3945
4069
|
status_code_non_4xx_error: int,
|
|
3946
4070
|
) -> None:
|
|
@@ -3962,7 +4086,7 @@ class EthModuleTest:
|
|
|
3962
4086
|
mock_offchain_lookup_request_response(
|
|
3963
4087
|
monkeypatch,
|
|
3964
4088
|
http_method="POST",
|
|
3965
|
-
mocked_request_url=
|
|
4089
|
+
mocked_request_url="https://web3.py/gateway",
|
|
3966
4090
|
mocked_status_code=200,
|
|
3967
4091
|
mocked_json_data=WEB3PY_AS_HEXBYTES,
|
|
3968
4092
|
sender=normalized_contract_address,
|
|
@@ -3977,7 +4101,7 @@ class EthModuleTest:
|
|
|
3977
4101
|
self,
|
|
3978
4102
|
w3: "Web3",
|
|
3979
4103
|
offchain_lookup_contract: "Contract",
|
|
3980
|
-
|
|
4104
|
+
keyfile_account_address: ChecksumAddress,
|
|
3981
4105
|
monkeypatch: "MonkeyPatch",
|
|
3982
4106
|
) -> None:
|
|
3983
4107
|
normalized_contract_address = to_hex_if_bytes(
|
|
@@ -3996,7 +4120,6 @@ class EthModuleTest:
|
|
|
3996
4120
|
|
|
3997
4121
|
def test_eth_call_offchain_lookup_raises_when_all_supplied_urls_fail(
|
|
3998
4122
|
self,
|
|
3999
|
-
w3: "Web3",
|
|
4000
4123
|
offchain_lookup_contract: "Contract",
|
|
4001
4124
|
) -> None:
|
|
4002
4125
|
# GET and POST requests should fail since responses are not mocked
|
|
@@ -4009,9 +4132,7 @@ class EthModuleTest:
|
|
|
4009
4132
|
|
|
4010
4133
|
def test_eth_call_continuous_offchain_lookup_raises_with_too_many_requests(
|
|
4011
4134
|
self,
|
|
4012
|
-
w3: "Web3",
|
|
4013
4135
|
offchain_lookup_contract: "Contract",
|
|
4014
|
-
unlocked_account: ChecksumAddress,
|
|
4015
4136
|
monkeypatch: "MonkeyPatch",
|
|
4016
4137
|
) -> None:
|
|
4017
4138
|
normalized_contract_address = to_hex_if_bytes(
|
|
@@ -4028,15 +4149,15 @@ class EthModuleTest:
|
|
|
4028
4149
|
self,
|
|
4029
4150
|
w3: "Web3",
|
|
4030
4151
|
revert_contract: "Contract",
|
|
4031
|
-
|
|
4152
|
+
keyfile_account_address: ChecksumAddress,
|
|
4032
4153
|
) -> None:
|
|
4033
4154
|
with pytest.raises(
|
|
4034
4155
|
ContractLogicError, match="execution reverted: Function has been reverted"
|
|
4035
4156
|
):
|
|
4036
4157
|
txn_params = revert_contract._prepare_transaction(
|
|
4037
|
-
|
|
4158
|
+
abi_element_identifier="revertWithMessage",
|
|
4038
4159
|
transaction={
|
|
4039
|
-
"from":
|
|
4160
|
+
"from": keyfile_account_address,
|
|
4040
4161
|
"to": revert_contract.address,
|
|
4041
4162
|
},
|
|
4042
4163
|
)
|
|
@@ -4046,13 +4167,13 @@ class EthModuleTest:
|
|
|
4046
4167
|
self,
|
|
4047
4168
|
w3: "Web3",
|
|
4048
4169
|
revert_contract: "Contract",
|
|
4049
|
-
|
|
4170
|
+
keyfile_account_address: ChecksumAddress,
|
|
4050
4171
|
) -> None:
|
|
4051
4172
|
with pytest.raises(ContractLogicError, match="execution reverted"):
|
|
4052
4173
|
txn_params = revert_contract._prepare_transaction(
|
|
4053
|
-
|
|
4174
|
+
abi_element_identifier="revertWithoutMessage",
|
|
4054
4175
|
transaction={
|
|
4055
|
-
"from":
|
|
4176
|
+
"from": keyfile_account_address,
|
|
4056
4177
|
"to": revert_contract.address,
|
|
4057
4178
|
},
|
|
4058
4179
|
)
|
|
@@ -4062,15 +4183,16 @@ class EthModuleTest:
|
|
|
4062
4183
|
self,
|
|
4063
4184
|
w3: "Web3",
|
|
4064
4185
|
revert_contract: "Contract",
|
|
4065
|
-
|
|
4186
|
+
keyfile_account_address: ChecksumAddress,
|
|
4066
4187
|
) -> None:
|
|
4067
|
-
data = revert_contract.
|
|
4068
|
-
|
|
4188
|
+
data = revert_contract.encode_abi(
|
|
4189
|
+
abi_element_identifier="UnauthorizedWithMessage",
|
|
4190
|
+
args=["You are not authorized"],
|
|
4069
4191
|
)
|
|
4070
4192
|
txn_params = revert_contract._prepare_transaction(
|
|
4071
|
-
|
|
4193
|
+
abi_element_identifier="customErrorWithMessage",
|
|
4072
4194
|
transaction={
|
|
4073
|
-
"from":
|
|
4195
|
+
"from": keyfile_account_address,
|
|
4074
4196
|
"to": revert_contract.address,
|
|
4075
4197
|
},
|
|
4076
4198
|
)
|
|
@@ -4082,13 +4204,13 @@ class EthModuleTest:
|
|
|
4082
4204
|
self,
|
|
4083
4205
|
w3: "Web3",
|
|
4084
4206
|
revert_contract: "Contract",
|
|
4085
|
-
|
|
4207
|
+
keyfile_account_address: ChecksumAddress,
|
|
4086
4208
|
) -> None:
|
|
4087
|
-
data = revert_contract.
|
|
4209
|
+
data = revert_contract.encode_abi(abi_element_identifier="Unauthorized")
|
|
4088
4210
|
txn_params = revert_contract._prepare_transaction(
|
|
4089
|
-
|
|
4211
|
+
abi_element_identifier="customErrorWithoutMessage",
|
|
4090
4212
|
transaction={
|
|
4091
|
-
"from":
|
|
4213
|
+
"from": keyfile_account_address,
|
|
4092
4214
|
"to": revert_contract.address,
|
|
4093
4215
|
},
|
|
4094
4216
|
)
|
|
@@ -4097,12 +4219,12 @@ class EthModuleTest:
|
|
|
4097
4219
|
assert excinfo.value.data == data
|
|
4098
4220
|
|
|
4099
4221
|
def test_eth_estimate_gas(
|
|
4100
|
-
self, w3: "Web3",
|
|
4222
|
+
self, w3: "Web3", keyfile_account_address_dual_type: ChecksumAddress
|
|
4101
4223
|
) -> None:
|
|
4102
4224
|
gas_estimate = w3.eth.estimate_gas(
|
|
4103
4225
|
{
|
|
4104
|
-
"from":
|
|
4105
|
-
"to":
|
|
4226
|
+
"from": keyfile_account_address_dual_type,
|
|
4227
|
+
"to": keyfile_account_address_dual_type,
|
|
4106
4228
|
"value": Wei(1),
|
|
4107
4229
|
}
|
|
4108
4230
|
)
|
|
@@ -4110,12 +4232,12 @@ class EthModuleTest:
|
|
|
4110
4232
|
assert gas_estimate > 0
|
|
4111
4233
|
|
|
4112
4234
|
def test_eth_estimate_gas_with_block(
|
|
4113
|
-
self, w3: "Web3",
|
|
4235
|
+
self, w3: "Web3", keyfile_account_address_dual_type: ChecksumAddress
|
|
4114
4236
|
) -> None:
|
|
4115
4237
|
gas_estimate = w3.eth.estimate_gas(
|
|
4116
4238
|
{
|
|
4117
|
-
"from":
|
|
4118
|
-
"to":
|
|
4239
|
+
"from": keyfile_account_address_dual_type,
|
|
4240
|
+
"to": keyfile_account_address_dual_type,
|
|
4119
4241
|
"value": Wei(1),
|
|
4120
4242
|
},
|
|
4121
4243
|
"latest",
|
|
@@ -4148,7 +4270,7 @@ class EthModuleTest:
|
|
|
4148
4270
|
math_contract: "Contract",
|
|
4149
4271
|
params: StateOverrideParams,
|
|
4150
4272
|
) -> None:
|
|
4151
|
-
txn_params: TxParams = {"from": w3.eth.
|
|
4273
|
+
txn_params: TxParams = {"from": w3.eth.accounts[0]}
|
|
4152
4274
|
|
|
4153
4275
|
# assert does not raise
|
|
4154
4276
|
w3.eth.estimate_gas(txn_params, None, {math_contract.address: params})
|
|
@@ -4175,12 +4297,9 @@ class EthModuleTest:
|
|
|
4175
4297
|
block = w3.eth.get_block(empty_block["number"])
|
|
4176
4298
|
assert block["number"] == empty_block["number"]
|
|
4177
4299
|
|
|
4178
|
-
def test_eth_getBlockByNumber_latest(
|
|
4179
|
-
self, w3: "Web3", empty_block: BlockData
|
|
4180
|
-
) -> None:
|
|
4181
|
-
current_block_number = w3.eth.block_number
|
|
4300
|
+
def test_eth_getBlockByNumber_latest(self, w3: "Web3") -> None:
|
|
4182
4301
|
block = w3.eth.get_block("latest")
|
|
4183
|
-
assert block["
|
|
4302
|
+
assert block["hash"] is not None
|
|
4184
4303
|
|
|
4185
4304
|
def test_eth_getBlockByNumber_not_found(
|
|
4186
4305
|
self, w3: "Web3", empty_block: BlockData
|
|
@@ -4221,8 +4340,36 @@ class EthModuleTest:
|
|
|
4221
4340
|
self, w3: "Web3", block_with_txn: BlockData
|
|
4222
4341
|
) -> None:
|
|
4223
4342
|
block = w3.eth.get_block(block_with_txn["number"], True)
|
|
4224
|
-
transaction = block["transactions"][0]
|
|
4225
|
-
assert transaction["hash"] == block_with_txn["transactions"][0]
|
|
4343
|
+
transaction = cast(TxData, block["transactions"][0])
|
|
4344
|
+
assert transaction["hash"] == block_with_txn["transactions"][0]
|
|
4345
|
+
|
|
4346
|
+
def test_eth_getBlockReceipts_hash(
|
|
4347
|
+
self, w3: "Web3", empty_block: BlockData
|
|
4348
|
+
) -> None:
|
|
4349
|
+
receipts = w3.eth.get_block_receipts(empty_block["hash"])
|
|
4350
|
+
assert isinstance(receipts, list)
|
|
4351
|
+
|
|
4352
|
+
def test_eth_getBlockReceipts_not_found(self, w3: "Web3") -> None:
|
|
4353
|
+
with pytest.raises(BlockNotFound):
|
|
4354
|
+
w3.eth.get_block_receipts(UNKNOWN_HASH)
|
|
4355
|
+
|
|
4356
|
+
def test_eth_getBlockReceipts_with_integer(
|
|
4357
|
+
self, w3: "Web3", empty_block: BlockData
|
|
4358
|
+
) -> None:
|
|
4359
|
+
receipts = w3.eth.get_block_receipts(empty_block["number"])
|
|
4360
|
+
assert isinstance(receipts, list)
|
|
4361
|
+
|
|
4362
|
+
def test_eth_getBlockReceipts_safe(
|
|
4363
|
+
self, w3: "Web3", empty_block: BlockData
|
|
4364
|
+
) -> None:
|
|
4365
|
+
receipts = w3.eth.get_block_receipts("safe")
|
|
4366
|
+
assert isinstance(receipts, list)
|
|
4367
|
+
|
|
4368
|
+
def test_eth_getBlockReceipts_finalized(
|
|
4369
|
+
self, w3: "Web3", empty_block: BlockData
|
|
4370
|
+
) -> None:
|
|
4371
|
+
receipts = w3.eth.get_block_receipts("finalized")
|
|
4372
|
+
assert isinstance(receipts, list)
|
|
4226
4373
|
|
|
4227
4374
|
def test_eth_getTransactionByHash(self, w3: "Web3", mined_txn_hash: HexStr) -> None:
|
|
4228
4375
|
transaction = w3.eth.get_transaction(mined_txn_hash)
|
|
@@ -4267,13 +4414,14 @@ class EthModuleTest:
|
|
|
4267
4414
|
assert isinstance(effective_gas_price, int)
|
|
4268
4415
|
assert effective_gas_price > 0
|
|
4269
4416
|
|
|
4417
|
+
@flaky_geth_dev_mining
|
|
4270
4418
|
def test_eth_get_transaction_receipt_unmined(
|
|
4271
|
-
self, w3: "Web3",
|
|
4419
|
+
self, w3: "Web3", keyfile_account_address_dual_type: ChecksumAddress
|
|
4272
4420
|
) -> None:
|
|
4273
4421
|
txn_hash = w3.eth.send_transaction(
|
|
4274
4422
|
{
|
|
4275
|
-
"from":
|
|
4276
|
-
"to":
|
|
4423
|
+
"from": keyfile_account_address_dual_type,
|
|
4424
|
+
"to": keyfile_account_address_dual_type,
|
|
4277
4425
|
"value": Wei(1),
|
|
4278
4426
|
"gas": 21000,
|
|
4279
4427
|
"maxFeePerGas": w3.to_wei(3, "gwei"),
|
|
@@ -4324,13 +4472,14 @@ class EthModuleTest:
|
|
|
4324
4472
|
assert isinstance(effective_gas_price, int)
|
|
4325
4473
|
assert effective_gas_price > 0
|
|
4326
4474
|
|
|
4475
|
+
@flaky_geth_dev_mining
|
|
4327
4476
|
def test_eth_wait_for_transaction_receipt_unmined(
|
|
4328
|
-
self, w3: "Web3",
|
|
4477
|
+
self, w3: "Web3", keyfile_account_address_dual_type: ChecksumAddress
|
|
4329
4478
|
) -> None:
|
|
4330
4479
|
txn_hash = w3.eth.send_transaction(
|
|
4331
4480
|
{
|
|
4332
|
-
"from":
|
|
4333
|
-
"to":
|
|
4481
|
+
"from": keyfile_account_address_dual_type,
|
|
4482
|
+
"to": keyfile_account_address_dual_type,
|
|
4334
4483
|
"value": Wei(1),
|
|
4335
4484
|
"gas": 21000,
|
|
4336
4485
|
"maxFeePerGas": w3.to_wei(3, "gwei"),
|
|
@@ -4428,7 +4577,7 @@ class EthModuleTest:
|
|
|
4428
4577
|
"fromBlock": block_with_txn_with_log["number"],
|
|
4429
4578
|
"toBlock": BlockNumber(block_with_txn_with_log["number"] - 1),
|
|
4430
4579
|
}
|
|
4431
|
-
with pytest.raises(
|
|
4580
|
+
with pytest.raises(Web3RPCError):
|
|
4432
4581
|
w3.eth.get_logs(filter_params)
|
|
4433
4582
|
|
|
4434
4583
|
# Test with `address`
|
|
@@ -4537,44 +4686,47 @@ class EthModuleTest:
|
|
|
4537
4686
|
assert len(result) == 0
|
|
4538
4687
|
|
|
4539
4688
|
def test_eth_call_old_contract_state(
|
|
4540
|
-
self,
|
|
4689
|
+
self,
|
|
4690
|
+
w3: "Web3",
|
|
4691
|
+
math_contract: "Contract",
|
|
4692
|
+
keyfile_account_address: ChecksumAddress,
|
|
4541
4693
|
) -> None:
|
|
4542
|
-
|
|
4543
|
-
block_num =
|
|
4544
|
-
block_hash =
|
|
4694
|
+
current_block = w3.eth.get_block("latest")
|
|
4695
|
+
block_num = current_block["number"]
|
|
4696
|
+
block_hash = current_block["hash"]
|
|
4697
|
+
|
|
4698
|
+
default_call_result = math_contract.functions.counter().call()
|
|
4699
|
+
latest_call_result = math_contract.functions.counter().call(
|
|
4700
|
+
block_identifier="latest"
|
|
4701
|
+
)
|
|
4702
|
+
|
|
4703
|
+
# increment counter and get tx receipt
|
|
4704
|
+
tx_hash = math_contract.functions.incrementCounter().transact(
|
|
4705
|
+
{"from": keyfile_account_address}
|
|
4706
|
+
)
|
|
4707
|
+
tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
|
|
4545
4708
|
|
|
4546
|
-
|
|
4709
|
+
# get new state value
|
|
4710
|
+
post_state_block_num_call_result = math_contract.functions.counter().call(
|
|
4711
|
+
block_identifier=tx_receipt["blockNumber"]
|
|
4712
|
+
)
|
|
4547
4713
|
|
|
4548
|
-
#
|
|
4549
|
-
# the default resolved block is latest, So if block_identifier was ignored
|
|
4550
|
-
# we would get the same result. For now, we mostly depend on core tests.
|
|
4551
|
-
# Ideas to improve this test:
|
|
4552
|
-
# - Enable on-demand mining in more clients
|
|
4553
|
-
# - Increment the math contract in all of the fixtures, and check the
|
|
4554
|
-
# value in an old block
|
|
4714
|
+
# call old state values with different block identifiers
|
|
4555
4715
|
block_hash_call_result = math_contract.functions.counter().call(
|
|
4556
4716
|
block_identifier=block_hash
|
|
4557
4717
|
)
|
|
4558
|
-
|
|
4718
|
+
pre_state_block_num_call_result = math_contract.functions.counter().call(
|
|
4559
4719
|
block_identifier=block_num
|
|
4560
4720
|
)
|
|
4561
|
-
latest_call_result = math_contract.functions.counter().call(
|
|
4562
|
-
block_identifier="latest"
|
|
4563
|
-
)
|
|
4564
|
-
default_call_result = math_contract.functions.counter().call()
|
|
4565
|
-
pending_call_result = math_contract.functions.counter().call(
|
|
4566
|
-
block_identifier="pending"
|
|
4567
|
-
)
|
|
4568
|
-
|
|
4569
|
-
assert block_hash_call_result == 0
|
|
4570
|
-
assert block_num_call_result == 0
|
|
4571
|
-
assert latest_call_result == 0
|
|
4572
|
-
assert default_call_result == 0
|
|
4573
4721
|
|
|
4574
|
-
|
|
4575
|
-
|
|
4576
|
-
|
|
4577
|
-
|
|
4722
|
+
# assert old state values before incrementing counter
|
|
4723
|
+
assert pre_state_block_num_call_result == post_state_block_num_call_result - 1
|
|
4724
|
+
assert (
|
|
4725
|
+
pre_state_block_num_call_result
|
|
4726
|
+
== block_hash_call_result
|
|
4727
|
+
== default_call_result
|
|
4728
|
+
== latest_call_result
|
|
4729
|
+
)
|
|
4578
4730
|
|
|
4579
4731
|
def test_eth_uninstall_filter(self, w3: "Web3") -> None:
|
|
4580
4732
|
filter = w3.eth.filter({})
|
|
@@ -4599,22 +4751,24 @@ class EthModuleTest:
|
|
|
4599
4751
|
def test_eth_get_raw_transaction_by_block(
|
|
4600
4752
|
self,
|
|
4601
4753
|
w3: "Web3",
|
|
4602
|
-
|
|
4754
|
+
keyfile_account_address_dual_type: ChecksumAddress,
|
|
4603
4755
|
block_with_txn: BlockData,
|
|
4604
4756
|
) -> None:
|
|
4605
4757
|
# eth_getRawTransactionByBlockNumberAndIndex: block identifier
|
|
4606
|
-
# send a txn to make sure pending block has at least one txn
|
|
4607
4758
|
w3.eth.send_transaction(
|
|
4608
4759
|
{
|
|
4609
|
-
"from":
|
|
4610
|
-
"to":
|
|
4760
|
+
"from": keyfile_account_address_dual_type,
|
|
4761
|
+
"to": keyfile_account_address_dual_type,
|
|
4611
4762
|
"value": Wei(1),
|
|
4612
4763
|
}
|
|
4613
4764
|
)
|
|
4614
|
-
|
|
4615
|
-
|
|
4616
|
-
|
|
4617
|
-
|
|
4765
|
+
raw_transaction = None
|
|
4766
|
+
while not raw_transaction:
|
|
4767
|
+
try:
|
|
4768
|
+
raw_transaction = w3.eth.get_raw_transaction_by_block("latest", 0)
|
|
4769
|
+
except TransactionNotFound:
|
|
4770
|
+
continue
|
|
4771
|
+
|
|
4618
4772
|
assert is_bytes(raw_transaction)
|
|
4619
4773
|
|
|
4620
4774
|
# eth_getRawTransactionByBlockNumberAndIndex: block number
|
|
@@ -4647,28 +4801,27 @@ class EthModuleTest:
|
|
|
4647
4801
|
) -> None:
|
|
4648
4802
|
unknown_identifier = "unknown"
|
|
4649
4803
|
with pytest.raises(
|
|
4650
|
-
|
|
4804
|
+
Web3ValueError,
|
|
4651
4805
|
match=(
|
|
4652
4806
|
"Value did not match any of the recognized block identifiers: "
|
|
4653
4807
|
f"{unknown_identifier}"
|
|
4654
4808
|
),
|
|
4655
4809
|
):
|
|
4810
|
+
# type ignored because we are testing an invalid input
|
|
4656
4811
|
w3.eth.get_raw_transaction_by_block(unknown_identifier, 0) # type: ignore
|
|
4657
4812
|
|
|
4658
4813
|
def test_default_account(
|
|
4659
|
-
self, w3: "Web3",
|
|
4814
|
+
self, w3: "Web3", keyfile_account_address_dual_type: ChecksumAddress
|
|
4660
4815
|
) -> None:
|
|
4661
|
-
|
|
4662
|
-
default_account = w3.eth.default_account
|
|
4663
|
-
assert default_account is empty
|
|
4816
|
+
current_default = w3.eth.default_account
|
|
4664
4817
|
|
|
4665
4818
|
# check setter
|
|
4666
|
-
w3.eth.default_account =
|
|
4819
|
+
w3.eth.default_account = keyfile_account_address_dual_type
|
|
4667
4820
|
default_account = w3.eth.default_account
|
|
4668
|
-
assert default_account ==
|
|
4821
|
+
assert default_account == keyfile_account_address_dual_type
|
|
4669
4822
|
|
|
4670
4823
|
# reset to default
|
|
4671
|
-
w3.eth.default_account =
|
|
4824
|
+
w3.eth.default_account = current_default
|
|
4672
4825
|
|
|
4673
4826
|
def test_default_block(
|
|
4674
4827
|
self,
|