Skip to content

Commit cdf35dd

Browse files
committed
Use yield instead of long if statement
1 parent 94ed39f commit cdf35dd

File tree

5 files changed

+73
-70
lines changed

5 files changed

+73
-70
lines changed

tests/integration/go_ethereum/common.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
Web3ModuleTest,
1111
)
1212

13-
GETH_VERSIONS_WITHOUT_MINING_CONTROL = ['v1.7.2', 'v1.8.22']
14-
GETH_VERSIONS_WITHOUT_ETH_SUBMITHASH = ['v1.8.22', 'v1.9.7']
13+
VERSIONS_WITHOUT_MINING_CONTROL = ['v1.7.2', 'v1.8.22']
14+
VERSIONS_WITHOUT_ETH_SUBMITHASH = ['v1.8.22', 'v1.9.7']
1515

1616

1717
class GoEthereumTest(Web3ModuleTest):
@@ -21,7 +21,7 @@ def _check_web3_clientVersion(self, client_version):
2121

2222
class GoEthereumEthModuleTest(EthModuleTest):
2323
def test_eth_replaceTransaction(self, web3, unlocked_account):
24-
if any([v in web3.clientVersion for v in GETH_VERSIONS_WITHOUT_MINING_CONTROL]):
24+
if any([v in web3.clientVersion for v in VERSIONS_WITHOUT_MINING_CONTROL]):
2525
pytest.xfail(reason='Needs ability to efficiently control mining')
2626
super().test_eth_replaceTransaction(web3, unlocked_account)
2727

@@ -31,14 +31,14 @@ def test_eth_replaceTransaction_already_mined(self, web3, unlocked_account_dual_
3131
web3.geth.miner.stop()
3232

3333
def test_eth_replaceTransaction_gas_price_defaulting_minimum(self, web3, unlocked_account):
34-
if any([v in web3.clientVersion for v in GETH_VERSIONS_WITHOUT_MINING_CONTROL]):
34+
if any([v in web3.clientVersion for v in VERSIONS_WITHOUT_MINING_CONTROL]):
3535
pytest.xfail(reason='Needs ability to efficiently control mining')
3636
super().test_eth_replaceTransaction_gas_price_defaulting_minimum(web3, unlocked_account)
3737

3838
def test_eth_replaceTransaction_gas_price_defaulting_strategy_higher(self,
3939
web3,
4040
unlocked_account):
41-
if any([v in web3.clientVersion for v in GETH_VERSIONS_WITHOUT_MINING_CONTROL]):
41+
if any([v in web3.clientVersion for v in VERSIONS_WITHOUT_MINING_CONTROL]):
4242
pytest.xfail(reason='Needs ability to efficiently control mining')
4343
super().test_eth_replaceTransaction_gas_price_defaulting_strategy_higher(
4444
web3, unlocked_account
@@ -47,14 +47,14 @@ def test_eth_replaceTransaction_gas_price_defaulting_strategy_higher(self,
4747
def test_eth_replaceTransaction_gas_price_defaulting_strategy_lower(self,
4848
web3,
4949
unlocked_account):
50-
if any([v in web3.clientVersion for v in GETH_VERSIONS_WITHOUT_MINING_CONTROL]):
50+
if any([v in web3.clientVersion for v in VERSIONS_WITHOUT_MINING_CONTROL]):
5151
pytest.xfail(reason='Needs ability to efficiently control mining')
5252
super().test_eth_replaceTransaction_gas_price_defaulting_strategy_lower(
5353
web3, unlocked_account
5454
)
5555

5656
def test_eth_modifyTransaction(self, web3, unlocked_account):
57-
if any([v in web3.clientVersion for v in GETH_VERSIONS_WITHOUT_MINING_CONTROL]):
57+
if any([v in web3.clientVersion for v in VERSIONS_WITHOUT_MINING_CONTROL]):
5858
pytest.xfail(reason='Needs ability to efficiently control mining')
5959
super().test_eth_modifyTransaction(web3, unlocked_account)
6060

@@ -67,7 +67,7 @@ def test_eth_estimateGas_with_block(self,
6767
)
6868

6969
def test_eth_submitHashrate(self, web3):
70-
if any([v in web3.clientVersion for v in GETH_VERSIONS_WITHOUT_ETH_SUBMITHASH]):
70+
if any([v in web3.clientVersion for v in VERSIONS_WITHOUT_ETH_SUBMITHASH]):
7171
# https://github.com/ethereum/go-ethereum/commit/51db5975cc5fb88db6a0dba1826b534fd4df29d7
7272
pytest.xfail('eth_submitHashrate deprecated in 1.8.22 for ethash_submitHashRate')
7373
super().test_eth_submitHashrate(web3)

tests/integration/go_ethereum/test_goethereum_http.py

+24-26
Original file line numberDiff line numberDiff line change
@@ -29,37 +29,35 @@ def endpoint_uri(rpc_port):
2929
return 'http://localhost:{0}'.format(rpc_port)
3030

3131

32+
def _geth_command_arguments(rpc_port,
33+
base_geth_command_arguments,
34+
geth_version):
35+
yield from base_geth_command_arguments
36+
if geth_version.major == 1:
37+
yield from (
38+
'--rpc',
39+
'--rpcport', rpc_port,
40+
'--rpcapi', 'admin,db,eth,net,web3,personal,shh,miner',
41+
'--ipcdisable',
42+
)
43+
if geth_version.minor == 9:
44+
yield '--allow-insecure-unlock'
45+
elif geth_version.minor not in [9, 8, 7]:
46+
raise AssertionError("Unsupported Geth version")
47+
else:
48+
raise AssertionError("Unsupported Geth version")
49+
50+
3251
@pytest.fixture(scope='module')
3352
def geth_command_arguments(rpc_port,
3453
base_geth_command_arguments,
3554
get_geth_version):
3655

37-
if get_geth_version.major == 1:
38-
if get_geth_version.minor == 9:
39-
return (
40-
base_geth_command_arguments +
41-
(
42-
'--rpc',
43-
'--rpcport', rpc_port,
44-
'--rpcapi', 'admin,db,eth,net,web3,personal,shh,miner',
45-
'--ipcdisable',
46-
'--allow-insecure-unlock',
47-
)
48-
)
49-
elif get_geth_version.minor == 8 or get_geth_version.minor == 7:
50-
return (
51-
base_geth_command_arguments +
52-
(
53-
'--rpc',
54-
'--rpcport', rpc_port,
55-
'--rpcapi', 'admin,db,eth,net,web3,personal,shh,miner',
56-
'--ipcdisable',
57-
)
58-
)
59-
else:
60-
assert False, "Unsupported geth version"
61-
else:
62-
assert False, "Unsupported geth version"
56+
return _geth_command_arguments(
57+
rpc_port,
58+
base_geth_command_arguments,
59+
get_geth_version
60+
)
6361

6462

6563
@pytest.fixture(scope="module")

tests/integration/go_ethereum/test_goethereum_ipc.py

+15-7
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,24 @@
2121
)
2222

2323

24+
def _geth_command_arguments(geth_ipc_path,
25+
base_geth_command_arguments):
26+
27+
geth_port = get_open_port()
28+
yield from base_geth_command_arguments
29+
yield from (
30+
'--port', geth_port,
31+
'--ipcpath', geth_ipc_path,
32+
)
33+
34+
2435
@pytest.fixture(scope='module')
2536
def geth_command_arguments(geth_ipc_path,
2637
base_geth_command_arguments):
27-
geth_port = get_open_port()
28-
return (
29-
base_geth_command_arguments +
30-
(
31-
'--port', geth_port,
32-
'--ipcpath', geth_ipc_path,
33-
)
38+
39+
return _geth_command_arguments(
40+
geth_ipc_path,
41+
base_geth_command_arguments
3442
)
3543

3644

tests/integration/go_ethereum/test_goethereum_ws.py

+25-28
Original file line numberDiff line numberDiff line change
@@ -30,41 +30,38 @@ def endpoint_uri(ws_port):
3030
return 'ws://localhost:{0}'.format(ws_port)
3131

3232

33+
def _geth_command_arguments(ws_port,
34+
base_geth_command_arguments,
35+
geth_version):
36+
yield from base_geth_command_arguments
37+
if geth_version.major == 1:
38+
yield from (
39+
'--ws',
40+
'--wsport', ws_port,
41+
'--wsapi', 'admin,db,eth,net,shh,web3,personal,miner',
42+
'--wsorigins', '*',
43+
'--ipcdisable',
44+
)
45+
if geth_version.minor == 9:
46+
yield '--allow-insecure-unlock'
47+
elif geth_version.minor not in [9, 8, 7]:
48+
raise AssertionError("Unsupported Geth version")
49+
else:
50+
raise AssertionError("Unsupported Geth version")
51+
52+
3353
@pytest.fixture(scope='module')
3454
def geth_command_arguments(geth_binary,
3555
get_geth_version,
3656
datadir,
3757
ws_port,
3858
base_geth_command_arguments):
3959

40-
if get_geth_version.major == 1:
41-
if get_geth_version.minor == 9:
42-
return (
43-
base_geth_command_arguments +
44-
(
45-
'--ws',
46-
'--wsport', ws_port,
47-
'--wsapi', 'admin,db,eth,net,shh,web3,personal,miner',
48-
'--wsorigins', '*',
49-
'--ipcdisable',
50-
'--allow-insecure-unlock',
51-
)
52-
)
53-
elif get_geth_version.minor == 8 or get_geth_version.minor == 7:
54-
return (
55-
base_geth_command_arguments +
56-
(
57-
'--ws',
58-
'--wsport', ws_port,
59-
'--wsapi', 'admin,db,eth,net,shh,web3,personal,miner',
60-
'--wsorigins', '*',
61-
'--ipcdisable',
62-
)
63-
)
64-
else:
65-
assert False, "Unsupported geth version"
66-
else:
67-
assert False, "Unsupported geth version"
60+
return _geth_command_arguments(
61+
ws_port,
62+
base_geth_command_arguments,
63+
get_geth_version
64+
)
6865

6966

7067
@pytest.fixture(scope="module")

web3/_utils/module_testing/eth_module.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ def test_eth_signTransaction(self, web3: "Web3", unlocked_account: ChecksumAddre
356356
'nonce': Nonce(0),
357357
}
358358
result = web3.eth.signTransaction(txn_params)
359-
signatory_account = web3.eth.account.recoverTransaction(result['raw'])
359+
signatory_account = web3.eth.account.recover_transaction(result['raw'])
360360
assert unlocked_account == signatory_account
361361
assert result['tx']['to'] == txn_params['to']
362362
assert result['tx']['value'] == txn_params['value']

0 commit comments

Comments
 (0)