Skip to content

Commit

Permalink
Remove unecessary generators
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanjw committed Aug 16, 2018
1 parent fa39d7a commit 15f0a32
Showing 1 changed file with 22 additions and 38 deletions.
60 changes: 22 additions & 38 deletions tests/core/filtering/test_filters_against_many_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
to_tuple,
)

SEED = 50505050505
random.seed(SEED)


@to_tuple
def deploy_contracts(web3, contract, wait_for_transaction):
Expand All @@ -19,25 +16,20 @@ def deploy_contracts(web3, contract, wait_for_transaction):

def pad_with_transactions(w3):
accounts = w3.eth.accounts
while True:
transact = yield
tx_hash = transact()
for tx_count in range(random.randint(0, 10)):
_from = accounts[random.randint(0, len(accounts) - 1)]
_to = accounts[random.randint(0, len(accounts) - 1)]
value = 50 + tx_count
w3.eth.sendTransaction({'from': _from, 'to': _to, 'value': value})
yield tx_hash
for tx_count in range(random.randint(0, 10)):
_from = accounts[random.randint(0, len(accounts) - 1)]
_to = accounts[random.randint(0, len(accounts) - 1)]
value = 50 + tx_count
w3.eth.sendTransaction({'from': _from, 'to': _to, 'value': value})


def single_transaction(w3):
accounts = w3.eth.accounts
while True:
_from = accounts[random.randint(0, len(accounts) - 1)]
_to = accounts[random.randint(0, len(accounts) - 1)]
value = 50
tx_hash = w3.eth.sendTransaction({'from': _from, 'to': _to, 'value': value})
yield tx_hash
_from = accounts[random.randint(0, len(accounts) - 1)]
_to = accounts[random.randint(0, len(accounts) - 1)]
value = 50
tx_hash = w3.eth.sendTransaction({'from': _from, 'to': _to, 'value': value})
return tx_hash


def test_event_filter_new_events(
Expand All @@ -57,30 +49,25 @@ def test_event_filter_new_events(

expected_match_counter = 0

tx_padder = pad_with_transactions(web3)
tx_padder.send(None)
while web3.eth.blockNumber < 50:
is_match = bool(random.randint(0, 1))
if is_match:
expected_match_counter += 1
tx_padder.send(matching_transact)
next(tx_padder)
matching_transact()
pad_with_transactions(web3)
continue
tx_padder.send(non_matching_transact)
next(tx_padder)
non_matching_transact()
pad_with_transactions(web3)

assert len(event_filter.get_new_entries()) == expected_match_counter


@pytest.mark.xfail
@pytest.mark.xfail("Suspected eth-tester bug")
def test_block_filter(web3):
block_filter = web3.eth.filter("latest")

tx_padder = pad_with_transactions(web3)
tx_padder.send(None)
while web3.eth.blockNumber < 50:
tx_padder.send(lambda: "ok")
next(tx_padder)
pad_with_transactions(web3)

assert len(block_filter.get_new_entries()) == web3.eth.blockNumber

Expand All @@ -92,15 +79,14 @@ def test_transaction_filter_with_mining(

transaction_counter = 0

transact_once = single_transaction(web3)
while transaction_counter < 100:
next(transact_once)
single_transaction(web3)
transaction_counter += 1

assert len(transaction_filter.get_new_entries()) == transaction_counter


@pytest.mark.xfail
@pytest.mark.xfail("Suspected eth-tester bug")
def test_transaction_filter_without_mining(
web3):

Expand Down Expand Up @@ -143,16 +129,14 @@ def gen_non_matching_transact():

expected_match_counter = 0

tx_padder = pad_with_transactions(web3)
tx_padder.send(None)
while web3.eth.blockNumber < 50:
is_match = bool(random.randint(0, 1))
if is_match:
expected_match_counter += 1
tx_padder.send(matching_transact)
next(tx_padder)
matching_transact()
pad_with_transactions(web3)
continue
tx_padder.send(next(non_matching_transact))
next(tx_padder)
next(non_matching_transact)()
pad_with_transactions(web3)

assert len(event_filter.get_new_entries()) == expected_match_counter

0 comments on commit 15f0a32

Please sign in to comment.