def test_pass_name_resolver(w3):
    return_chain_on_mainnet = construct_fixture_middleware({
        'net_version': '1',
    })
    return_balance = construct_fixture_middleware(
        {'platon_getBalance': BALANCE})
    w3.middleware_stack.inject(return_chain_on_mainnet, layer=0)
    w3.middleware_stack.inject(return_balance, layer=0)
    assert w3.eth.getBalance(NAME) == BALANCE
Example #2
0
def test_full_extra_data(web3):
    return_block_with_long_extra_data = construct_fixture_middleware({
        'eth_getBlockByNumber': {'extraData': '0x' + 'ff' * 32},
    })
    web3.middleware_stack.inject(return_block_with_long_extra_data, layer=0)
    block = web3.eth.getBlock('latest')
    assert block.extraData == b'\xff' * 32
Example #3
0
def test_long_extra_data(web3):
    return_block_with_long_extra_data = construct_fixture_middleware({
        'eth_getBlockByNumber': {'extraData': '0x' + 'ff' * 33},
    })
    web3.middleware_stack.inject(return_block_with_long_extra_data, layer=0)
    with pytest.raises(ValidationError):
        web3.eth.getBlock('latest')
def test_fail_name_resolver(w3):
    return_chain_on_mainnet = construct_fixture_middleware({
        'net_version': '2',
    })
    w3.middleware_stack.inject(return_chain_on_mainnet, layer=0)
    with pytest.raises(InvalidAddress, match='.*ethereum\.eth.*'):
        w3.eth.getBalance("ethereum.eth")
Example #5
0
def test_geth_proof_of_authority(web3):
    return_block_with_long_extra_data = construct_fixture_middleware({
        'eth_getBlockByNumber': {'extraData': '0x' + 'ff' * 33},
    })
    web3.middleware_stack.inject(geth_poa_middleware, layer=0)
    web3.middleware_stack.inject(return_block_with_long_extra_data, layer=0)
    block = web3.eth.getBlock('latest')
    assert 'extraData' not in block
    assert block.proofOfAuthorityData == b'\xff' * 33
def test_fixture_middleware(w3, method, expected):
    w3.middleware_stack.add(construct_fixture_middleware({'test_endpoint': 'value-a'}))

    if isinstance(expected, type) and issubclass(expected, Exception):
        with pytest.raises(expected):
            w3.manager.request_blocking(method, [])
    else:
        actual = w3.manager.request_blocking(method, [])
        assert actual == expected
def test_web3_auto_gethdev():
    assert isinstance(w3.providers[0], IPCProvider)
    return_block_with_long_extra_data = construct_fixture_middleware({
        'eth_getBlockByNumber': {
            'extraData': '0x' + 'ff' * 33
        },
    })
    w3.middleware_stack.inject(return_block_with_long_extra_data, layer=0)
    block = w3.eth.getBlock('latest')
    assert 'extraData' not in block
    assert block.proofOfAuthorityData == b'\xff' * 33
        # EVM
        'evm_snapshot':
        integer_to_hex,
    },
)

ethereum_tester_fixture_middleware = construct_fixture_middleware({
    # Eth
    'eth_protocolVersion':
    '63',
    'eth_hashrate':
    0,
    'eth_gasPrice':
    1,
    'eth_syncing':
    False,
    'eth_mining':
    False,
    # Net
    'net_version':
    '1',
    'net_listening':
    False,
    'net_peerCount':
    0,
})


def guess_from(web3, transaction):
    coinbase = web3.eth.coinbase
    if coinbase is not None:
        return coinbase