Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filters from "latest" to "latest" always return empty list #77

Open
4gn3s opened this issue Dec 2, 2016 · 0 comments
Open

Filters from "latest" to "latest" always return empty list #77

4gn3s opened this issue Dec 2, 2016 · 0 comments

Comments

@4gn3s
Copy link
Contributor

4gn3s commented Dec 2, 2016

Package versions:
eth-testrpc: 0.8.7
ethereum-tester-client: 1.2.5
geth: 1.5.3, 1.5.4

What was wrong?

When using filters, if filter has {"fromBlock": "latest", "toBlock": "latest"} (to retrieve logs from the most recently mined transaction), testrpc returns an empty list, while geth returns a correct log.
A minimal example which shows the current behaviour:

import pytest
from eth_tester_client.utils import encode_address
from ethereum import tester


@pytest.fixture(params=[
    'testrpc',
    'temp',
])
def chain(project, request):
    with project.get_chain(request.param) as chain:
        if request.param == 'temp':
            address = chain.web3.personal.importRawKey(tester.keys[0], "")
            assert address == encode_address(tester.accounts[0])
            chain.web3.personal.unlockAccount(address, "", duration=0)
            chain.wait.for_unlock(address)
        yield chain


def deploy(chain, contract_name):
    contract_factory = chain.get_contract_factory(contract_name)
    deploy_txn_hash = contract_factory.deploy()
    deploy_address = chain.wait.for_contract_address(deploy_txn_hash, timeout=120)
    return contract_factory(address=deploy_address)


def test_latest_logs(chain):
    contract = deploy(chain, 'TestContract')
    event_filter = contract.pastEvents('TestEvent', {"fromBlock": "latest",
                                                     "toBlock": "latest"})
    txn_hash = contract.transact().do_action(1234)
    chain.wait.for_receipt(txn_hash)
    event_logs = event_filter.get()
    assert event_logs
    event_logs = filter(lambda log: log["transactionHash"] == txn_hash, event_logs)
    assert len([e["args"] for e in event_logs]) > 0

and the TestContract.sol:

contract TestContract {
    event TestEvent(uint value);
    function do_action(uint value){
        TestEvent(value);
    }
}

When running, I get:

____ test_latest_logs[testrpc] ____

chain = <populus.chain.TestRPCChain object at 0x7fa413aa0f50>

    def test_latest_logs(chain):
        contract = deploy(chain, 'TestContract')
        event_filter = contract.pastEvents('TestEvent', {"fromBlock": "latest",
                                                         "toBlock": "latest"})
        txn_hash = contract.transact().do_action(1234)
        chain.wait.for_receipt(txn_hash)
        event_logs = event_filter.get()
>       assert event_logs
E       assert []

tests/unit/testrpc_bug_logs.py:43: AssertionError

...

===== 1 failed, 1 passed in 13.80 seconds =====

Cute Animal Picture

wet tiger

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant