From 1ce0ada74508fac563f9eb2bc78bfec6eeed0b72 Mon Sep 17 00:00:00 2001 From: Piper Merriam Date: Wed, 3 Aug 2016 09:22:24 -0600 Subject: [PATCH] change wait for transaction, use explicit empty web3 in places --- conftest.py | 6 +++--- tests/eth-module/test_eth_call.py | 2 +- tests/eth-module/test_eth_estimateGas.py | 2 +- .../test_eth_getBlockTransactionCount.py | 2 +- tests/eth-module/test_eth_getCode.py | 2 +- .../eth-module/test_eth_getTransactionFromBlock.py | 2 +- tests/eth-module/test_eth_getTransactionReciept.py | 2 +- tests/eth-module/test_eth_sendRawTransaction.py | 4 ++-- tests/eth-module/test_eth_sendTransaction.py | 4 ++-- tests/filtering/conftest.py | 2 +- .../filtering/test_contract_on_event_filtering.py | 9 ++++++--- .../test_contract_past_event_filtering.py | 5 ++++- .../filtering/test_filter_against_latest_blocks.py | 3 +++ .../test_filter_against_pending_transactions.py | 7 +++++-- .../test_filter_against_transaction_logs.py | 5 ++++- tests/mining/conftest.py | 7 ++----- tests/mining/test_miner_hashrate.py | 5 ++--- tests/mining/test_miner_setExtra.py | 5 ++--- tests/mining/test_miner_setGasPrice.py | 5 ++--- tests/mining/test_miner_start.py | 5 ++--- tests/mining/test_miner_stop.py | 7 +++---- tests/personal-module/conftest.py | 2 +- .../personal-module/test_personal_importRawKey.py | 14 ++++++++------ tests/personal-module/test_personal_lockAccount.py | 2 +- .../test_personal_signAndSendTransaction.py | 2 +- .../personal-module/test_personal_unlockAccount.py | 2 +- tests/txpool-module/conftest.py | 7 ++----- tests/txpool-module/test_txpool_content.py | 5 ++--- tests/txpool-module/test_txpool_inspect.py | 8 ++------ 29 files changed, 67 insertions(+), 66 deletions(-) diff --git a/conftest.py b/conftest.py index 5287572..0d478bc 100644 --- a/conftest.py +++ b/conftest.py @@ -71,10 +71,10 @@ def wait_for_block(): @pytest.fixture() -def wait_for_transaction(web3): +def wait_for_transaction(): import gevent - def _wait_for_transaction(txn_hash, timeout=120): + def _wait_for_transaction(web3, txn_hash, timeout=120): with gevent.Timeout(timeout): while True: txn_receipt = web3.eth.getTransactionReceipt(txn_hash) @@ -201,7 +201,7 @@ def web3(request): @pytest.fixture() -def empty_account(web3, wait_for_transaction): +def empty_account(web3): from eth_tester_client.utils import mk_random_privkey address = web3.personal.importRawKey(mk_random_privkey(), "a-password") diff --git a/tests/eth-module/test_eth_call.py b/tests/eth-module/test_eth_call.py index 9d53601..d09d3f0 100644 --- a/tests/eth-module/test_eth_call.py +++ b/tests/eth-module/test_eth_call.py @@ -17,7 +17,7 @@ def test_eth_call_with_no_args(web3, wait_for_transaction, MATH_CODE, MATH_RUNTI "gas": 3000000, }) - wait_for_transaction(txn_hash) + wait_for_transaction(web3, txn_hash) txn_receipt = web3.eth.getTransactionReceipt(txn_hash) contract_address = txn_receipt['contractAddress'] diff --git a/tests/eth-module/test_eth_estimateGas.py b/tests/eth-module/test_eth_estimateGas.py index e6e515b..4b1c15a 100644 --- a/tests/eth-module/test_eth_estimateGas.py +++ b/tests/eth-module/test_eth_estimateGas.py @@ -20,7 +20,7 @@ def math_contract(web3, MATH_ABI, MATH_CODE, MATH_RUNTIME, MATH_SOURCE, source=MATH_SOURCE, ) deploy_txn = MathContract.deploy({'from': web3.eth.coinbase}) - deploy_receipt = wait_for_transaction(deploy_txn) + deploy_receipt = wait_for_transaction(web3, deploy_txn) assert deploy_receipt is not None contract_address = deploy_receipt['contractAddress'] diff --git a/tests/eth-module/test_eth_getBlockTransactionCount.py b/tests/eth-module/test_eth_getBlockTransactionCount.py index 9c63108..aa10292 100644 --- a/tests/eth-module/test_eth_getBlockTransactionCount.py +++ b/tests/eth-module/test_eth_getBlockTransactionCount.py @@ -26,7 +26,7 @@ def test_eth_getBlockTransactionCount(web3, extra_accounts, wait_for_transaction # wait for them to resolve for txn_hash in transaction_hashes: - wait_for_transaction(txn_hash) + wait_for_transaction(web3, txn_hash) # gather all receipts and sort/group them by block number. all_receipts = sorted( diff --git a/tests/eth-module/test_eth_getCode.py b/tests/eth-module/test_eth_getCode.py index 15ceb58..7b0c037 100644 --- a/tests/eth-module/test_eth_getCode.py +++ b/tests/eth-module/test_eth_getCode.py @@ -15,7 +15,7 @@ def test_eth_getCode(web3, wait_for_transaction, MATH_CODE, MATH_RUNTIME): "gas": 3000000, }) - wait_for_transaction(txn_hash) + wait_for_transaction(web3, txn_hash) txn_receipt = web3.eth.getTransactionReceipt(txn_hash) contract_address = txn_receipt['contractAddress'] diff --git a/tests/eth-module/test_eth_getTransactionFromBlock.py b/tests/eth-module/test_eth_getTransactionFromBlock.py index 4993da1..afdbe51 100644 --- a/tests/eth-module/test_eth_getTransactionFromBlock.py +++ b/tests/eth-module/test_eth_getTransactionFromBlock.py @@ -27,7 +27,7 @@ def test_eth_getTransactionFromBlock(web3, extra_accounts, wait_for_transaction) # wait for them to resolve for txn_hash in transaction_hashes: - wait_for_transaction(txn_hash) + wait_for_transaction(web3, txn_hash) # gather all receipts and sort/group them by block number. all_receipts = sorted( diff --git a/tests/eth-module/test_eth_getTransactionReciept.py b/tests/eth-module/test_eth_getTransactionReciept.py index 4fab395..73e1b1c 100644 --- a/tests/eth-module/test_eth_getTransactionReciept.py +++ b/tests/eth-module/test_eth_getTransactionReciept.py @@ -15,7 +15,7 @@ def test_eth_getTransactionReceipt(web3, extra_accounts, wait_for_transaction): "value": 1234, }) - wait_for_transaction(txn_hash) + wait_for_transaction(web3, txn_hash) txn_receipt = web3.eth.getTransactionReceipt(txn_hash) assert txn_receipt['transactionHash'] == txn_hash diff --git a/tests/eth-module/test_eth_sendRawTransaction.py b/tests/eth-module/test_eth_sendRawTransaction.py index 5d12c52..0d52fd5 100644 --- a/tests/eth-module/test_eth_sendRawTransaction.py +++ b/tests/eth-module/test_eth_sendRawTransaction.py @@ -21,7 +21,7 @@ def test_eth_sendRawTransaction(web3, wait_for_transaction, extra_accounts): "to": address, "value": 10000000000000000, }) - wait_for_transaction(funding_txn_hash) + wait_for_transaction(web3, funding_txn_hash) if isinstance(web3.currentProvider, TestRPCProvider): # ethereum-tester-client doesn't quite implement the @@ -46,7 +46,7 @@ def test_eth_sendRawTransaction(web3, wait_for_transaction, extra_accounts): raw_tx_hex = encode_data(raw_tx) txn_hash = web3.eth.sendRawTransaction(raw_tx_hex) - wait_for_transaction(txn_hash) + wait_for_transaction(web3, txn_hash) txn_receipt = web3.eth.getTransactionReceipt(txn_hash) after_balance = web3.eth.getBalance(extra_accounts[1]) diff --git a/tests/eth-module/test_eth_sendTransaction.py b/tests/eth-module/test_eth_sendTransaction.py index c54e5e1..37636c0 100644 --- a/tests/eth-module/test_eth_sendTransaction.py +++ b/tests/eth-module/test_eth_sendTransaction.py @@ -18,7 +18,7 @@ def test_eth_sendTransaction_with_value_only_transaction(web3, extra_accounts, "value": 1234, }) - wait_for_transaction(txn_hash) + wait_for_transaction(web3, txn_hash) after_balance = web3.eth.getBalance(extra_accounts[1]) @@ -32,7 +32,7 @@ def test_eth_sendTransaction_with_data(web3, wait_for_transaction, MATH_CODE, MA "gas": 3000000, }) - wait_for_transaction(txn_hash) + wait_for_transaction(web3, txn_hash) txn_receipt = web3.eth.getTransactionReceipt(txn_hash) contract_address = txn_receipt['contractAddress'] diff --git a/tests/filtering/conftest.py b/tests/filtering/conftest.py index 14888e3..00ade4c 100644 --- a/tests/filtering/conftest.py +++ b/tests/filtering/conftest.py @@ -126,7 +126,7 @@ def Emitter(web3, EMITTER): def emitter(web3, Emitter, wait_for_transaction, wait_for_block): wait_for_block(web3) deploy_txn_hash = Emitter.deploy({'from': web3.eth.coinbase, 'gas': 1000000}) - deploy_receipt = wait_for_transaction(deploy_txn_hash) + deploy_receipt = wait_for_transaction(web3, deploy_txn_hash) contract_address = deploy_receipt['contractAddress'] code = web3.eth.getCode(contract_address) diff --git a/tests/filtering/test_contract_on_event_filtering.py b/tests/filtering/test_contract_on_event_filtering.py index d231698..2ce73dd 100644 --- a/tests/filtering/test_contract_on_event_filtering.py +++ b/tests/filtering/test_contract_on_event_filtering.py @@ -3,6 +3,9 @@ import gevent from flaky import flaky +reset_chain = True + + @flaky(max_runs=3) def test_on_filter_with_only_event_name(web3, emitter, @@ -15,7 +18,7 @@ def test_on_filter_with_only_event_name(web3, filter = emitter.on('LogNoArguments', {}, seen_logs.append) txn_hash = emitter.transact().logNoArgs(emitter_event_ids.LogNoArguments) - txn_receipt = wait_for_transaction(txn_hash) + txn_receipt = wait_for_transaction(web3, txn_hash) with gevent.Timeout(5): while not seen_logs: @@ -51,7 +54,7 @@ def test_on_filter_with_event_name_and_single_argument(web3, emitter.transact().logTriple(emitter_event_ids.LogTripleWithIndex, 12345, 2, 54321) ) for txn_hash in txn_hashes: - wait_for_transaction(txn_hash) + wait_for_transaction(web3, txn_hash) with gevent.Timeout(5): while not seen_logs: @@ -87,7 +90,7 @@ def test_on_filter_with_event_name_and_non_indexed_argument(web3, emitter.transact().logTriple(emitter_event_ids.LogTripleWithIndex, 12345, 2, 54321) ) for txn_hash in txn_hashes: - wait_for_transaction(txn_hash) + wait_for_transaction(web3, txn_hash) with gevent.Timeout(5): while not seen_logs: diff --git a/tests/filtering/test_contract_past_event_filtering.py b/tests/filtering/test_contract_past_event_filtering.py index 1d1403e..dead608 100644 --- a/tests/filtering/test_contract_past_event_filtering.py +++ b/tests/filtering/test_contract_past_event_filtering.py @@ -3,6 +3,9 @@ import gevent from flaky import flaky +reset_chain = True + + @flaky(max_runs=3) def test_past_events_filter_with_only_event_name(web3, emitter, @@ -10,7 +13,7 @@ def test_past_events_filter_with_only_event_name(web3, emitter_log_topics, emitter_event_ids): txn_hash = emitter.transact().logNoArgs(emitter_event_ids.LogNoArguments) - txn_receipt = wait_for_transaction(txn_hash) + txn_receipt = wait_for_transaction(web3, txn_hash) seen_logs = [] diff --git a/tests/filtering/test_filter_against_latest_blocks.py b/tests/filtering/test_filter_against_latest_blocks.py index f889009..2803222 100644 --- a/tests/filtering/test_filter_against_latest_blocks.py +++ b/tests/filtering/test_filter_against_latest_blocks.py @@ -3,6 +3,9 @@ import gevent from flaky import flaky +reset_chain = True + + @flaky(max_runs=3) def test_filter_against_latest_blocks(web3, wait_for_block): seen_blocks = [] diff --git a/tests/filtering/test_filter_against_pending_transactions.py b/tests/filtering/test_filter_against_pending_transactions.py index 2a23cde..5948d6e 100644 --- a/tests/filtering/test_filter_against_pending_transactions.py +++ b/tests/filtering/test_filter_against_pending_transactions.py @@ -3,6 +3,9 @@ import gevent from flaky import flaky +reset_chain = True + + @flaky(max_runs=3) def test_filter_against_pending_transactions(web3, wait_for_transaction): seen_txns = [] @@ -20,8 +23,8 @@ def test_filter_against_pending_transactions(web3, wait_for_transaction): 'value': 54321, }) - wait_for_transaction(txn_1_hash) - wait_for_transaction(txn_2_hash) + wait_for_transaction(web3, txn_1_hash) + wait_for_transaction(web3, txn_2_hash) with gevent.Timeout(5): while not seen_txns: diff --git a/tests/filtering/test_filter_against_transaction_logs.py b/tests/filtering/test_filter_against_transaction_logs.py index 7d61f78..35bbec3 100644 --- a/tests/filtering/test_filter_against_transaction_logs.py +++ b/tests/filtering/test_filter_against_transaction_logs.py @@ -3,6 +3,9 @@ import gevent from flaky import flaky +reset_chain = True + + @flaky(max_runs=3) def test_filter_against_log_events(web3, emitter, @@ -19,7 +22,7 @@ def test_filter_against_log_events(web3, txn_hashes.append(emitter.transact().logNoArgs(emitter_event_ids.LogNoArguments)) for txn_hash in txn_hashes: - wait_for_transaction(txn_hash) + wait_for_transaction(web3, txn_hash) with gevent.Timeout(5): while not seen_logs: diff --git a/tests/mining/conftest.py b/tests/mining/conftest.py index cf90dd4..ba49cd6 100644 --- a/tests/mining/conftest.py +++ b/tests/mining/conftest.py @@ -1,12 +1,9 @@ import pytest -from web3.providers.rpc import TestRPCProvider - @pytest.fixture(autouse=True) -def skip_testrpc_and_wait_for_mining_start(web3, wait_for_miner_start): - if isinstance(web3.currentProvider, TestRPCProvider): - pytest.skip("No miner interface on eth-testrpc") +def skip_testrpc_and_wait_for_mining_start(web3_ipc_empty, wait_for_miner_start): + web3 = web3_ipc_empty wait_for_miner_start(web3) diff --git a/tests/mining/test_miner_hashrate.py b/tests/mining/test_miner_hashrate.py index 22d953d..6558a74 100644 --- a/tests/mining/test_miner_hashrate.py +++ b/tests/mining/test_miner_hashrate.py @@ -1,9 +1,8 @@ from web3.providers.rpc import TestRPCProvider -reset_chain = True +def test_miner_hashrate(web3_ipc_empty, wait_for_miner_start): + web3 = web3_ipc_empty - -def test_miner_hashrate(web3, wait_for_miner_start): hashrate = web3.miner.hashrate assert hashrate > 0 diff --git a/tests/mining/test_miner_setExtra.py b/tests/mining/test_miner_setExtra.py index c299822..73d916c 100644 --- a/tests/mining/test_miner_setExtra.py +++ b/tests/mining/test_miner_setExtra.py @@ -5,10 +5,9 @@ import gevent from web3.utils.encoding import decode_hex -reset_chain = True +def test_miner_setExtra(web3_ipc_empty, wait_for_block): + web3 = web3_ipc_empty - -def test_miner_setExtra(web3, wait_for_block): initial_extra = decode_hex(web3.eth.getBlock(web3.eth.blockNumber)['extraData']) new_extra_data = b'-this-is-32-bytes-of-extra-data-' diff --git a/tests/mining/test_miner_setGasPrice.py b/tests/mining/test_miner_setGasPrice.py index be0e1eb..682a0fe 100644 --- a/tests/mining/test_miner_setGasPrice.py +++ b/tests/mining/test_miner_setGasPrice.py @@ -1,7 +1,6 @@ -reset_chain = True +def test_miner_setGasPrice(web3_ipc_empty, wait_for_block): + web3 = web3_ipc_empty - -def test_miner_setGasPrice(web3, wait_for_block): initial_gas_price = web3.eth.gasPrice # sanity check diff --git a/tests/mining/test_miner_start.py b/tests/mining/test_miner_start.py index 4ad7a80..54a0087 100644 --- a/tests/mining/test_miner_start.py +++ b/tests/mining/test_miner_start.py @@ -3,10 +3,9 @@ import random import gevent -reset_chain = True +def test_miner_start(web3_ipc_empty, wait_for_miner_start): + web3 = web3_ipc_empty - -def test_miner_start(web3, wait_for_miner_start): # sanity assert web3.eth.mining assert web3.miner.hashrate diff --git a/tests/mining/test_miner_stop.py b/tests/mining/test_miner_stop.py index 65d2c5d..a1b481e 100644 --- a/tests/mining/test_miner_stop.py +++ b/tests/mining/test_miner_stop.py @@ -5,11 +5,10 @@ import gevent from flaky import flaky -reset_chain = True - - @flaky(max_runs=3) -def test_miner_stop(web3): +def test_miner_stop(web3_ipc_empty): + web3 = web3_ipc_empty + assert web3.eth.mining assert web3.miner.hashrate diff --git a/tests/personal-module/conftest.py b/tests/personal-module/conftest.py index 75ce7d9..0adb53d 100644 --- a/tests/personal-module/conftest.py +++ b/tests/personal-module/conftest.py @@ -36,7 +36,7 @@ def password_account(web3, account_password, 'to': address, 'value': initial_balance, }, 'this-is-not-a-secure-password') - wait_for_transaction(funding_txn_hash) + wait_for_transaction(web3, funding_txn_hash) assert web3.eth.getBalance(address) == initial_balance return address diff --git a/tests/personal-module/test_personal_importRawKey.py b/tests/personal-module/test_personal_importRawKey.py index 1eb333f..a86f761 100644 --- a/tests/personal-module/test_personal_importRawKey.py +++ b/tests/personal-module/test_personal_importRawKey.py @@ -8,8 +8,8 @@ from eth_tester_client.utils import ( reset_chain = True -def test_personal_importRawKey_as_bytes(web3, account_private_key, account_password, - account_public_key): +def test_personal_importRawKey_as_bytes(web3, account_private_key, + account_password, account_public_key): address = web3.personal.importRawKey(account_private_key, account_password) # sanity check @@ -18,8 +18,9 @@ def test_personal_importRawKey_as_bytes(web3, account_private_key, account_passw assert web3.personal.unlockAccount(address, account_password) is True -def test_personal_importRawKey_as_hex_with_0x(web3, account_private_key, account_password, - account_public_key): +def test_personal_importRawKey_as_hex_with_0x(web3, account_private_key, + account_password, + account_public_key): address = web3.personal.importRawKey(encode_32bytes(account_private_key), account_password) # sanity check @@ -28,8 +29,9 @@ def test_personal_importRawKey_as_hex_with_0x(web3, account_private_key, account assert web3.personal.unlockAccount(address, account_password) is True -def test_personal_importRawKey_as_hex_without_0x(web3, account_private_key, account_password, - account_public_key): +def test_personal_importRawKey_as_hex_without_0x(web3, account_private_key, + account_password, + account_public_key): address = web3.personal.importRawKey(strip_0x(encode_32bytes(account_private_key)), account_password) # sanity check diff --git a/tests/personal-module/test_personal_lockAccount.py b/tests/personal-module/test_personal_lockAccount.py index a6b45ee..35a107a 100644 --- a/tests/personal-module/test_personal_lockAccount.py +++ b/tests/personal-module/test_personal_lockAccount.py @@ -14,7 +14,7 @@ def test_personal_lockAccount(web3, password_account, account_password, 'to': empty_account, 'value': 1234, }) - wait_for_transaction(txn_hash) + wait_for_transaction(web3, txn_hash) after_balance = web3.eth.getBalance(empty_account) diff --git a/tests/personal-module/test_personal_signAndSendTransaction.py b/tests/personal-module/test_personal_signAndSendTransaction.py index 30962df..0a1c101 100644 --- a/tests/personal-module/test_personal_signAndSendTransaction.py +++ b/tests/personal-module/test_personal_signAndSendTransaction.py @@ -7,7 +7,7 @@ def test_personal_signAndSendTransaction(web3, password_account, 'to': empty_account, 'value': 1234, }, account_password) - wait_for_transaction(txn_hash) + wait_for_transaction(web3, txn_hash) txn_receipt = web3.eth.getTransactionReceipt(txn_hash) assert txn_receipt['transactionHash'] == txn_hash diff --git a/tests/personal-module/test_personal_unlockAccount.py b/tests/personal-module/test_personal_unlockAccount.py index 9628d2e..a12bee9 100644 --- a/tests/personal-module/test_personal_unlockAccount.py +++ b/tests/personal-module/test_personal_unlockAccount.py @@ -28,7 +28,7 @@ def test_personal_unlockAccount(web3, password_account, account_password, 'to': empty_account, 'value': 1234, }) - wait_for_transaction(txn_hash) + wait_for_transaction(web3, txn_hash) after_balance = web3.eth.getBalance(empty_account) diff --git a/tests/txpool-module/conftest.py b/tests/txpool-module/conftest.py index cf90dd4..ba49cd6 100644 --- a/tests/txpool-module/conftest.py +++ b/tests/txpool-module/conftest.py @@ -1,12 +1,9 @@ import pytest -from web3.providers.rpc import TestRPCProvider - @pytest.fixture(autouse=True) -def skip_testrpc_and_wait_for_mining_start(web3, wait_for_miner_start): - if isinstance(web3.currentProvider, TestRPCProvider): - pytest.skip("No miner interface on eth-testrpc") +def skip_testrpc_and_wait_for_mining_start(web3_ipc_empty, wait_for_miner_start): + web3 = web3_ipc_empty wait_for_miner_start(web3) diff --git a/tests/txpool-module/test_txpool_content.py b/tests/txpool-module/test_txpool_content.py index 66d4f35..b06a351 100644 --- a/tests/txpool-module/test_txpool_content.py +++ b/tests/txpool-module/test_txpool_content.py @@ -2,10 +2,9 @@ import random import gevent -reset_chain = True +def test_txpool_content(web3_ipc_empty): + web3 = web3_ipc_empty - -def test_txpool_content(web3): web3.miner.stop() with gevent.Timeout(30): diff --git a/tests/txpool-module/test_txpool_inspect.py b/tests/txpool-module/test_txpool_inspect.py index 41e5577..66f75d6 100644 --- a/tests/txpool-module/test_txpool_inspect.py +++ b/tests/txpool-module/test_txpool_inspect.py @@ -2,13 +2,9 @@ import random import gevent -reset_chain = True +def test_txpool_inspect(web3_ipc_empty): + web3 = web3_ipc_empty - -def test_txpool_inspect(web3): - """ - TODO: How can this test be modified to be different from the test for `txpool_content` - """ web3.miner.stop() with gevent.Timeout(30):