mirror of
https://github.com/FlipsideCrypto/web3.py.git
synced 2026-02-06 10:56:47 +00:00
change wait for transaction, use explicit empty web3 in places
This commit is contained in:
parent
a9d92192e4
commit
1ce0ada745
@ -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")
|
||||
|
||||
|
||||
@ -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']
|
||||
|
||||
@ -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']
|
||||
|
||||
@ -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(
|
||||
|
||||
@ -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']
|
||||
|
||||
@ -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(
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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])
|
||||
|
||||
@ -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']
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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 = []
|
||||
|
||||
|
||||
@ -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 = []
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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)
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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-'
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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)
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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)
|
||||
|
||||
|
||||
@ -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)
|
||||
|
||||
|
||||
@ -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):
|
||||
|
||||
@ -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):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user