Ejemplo n.º 1
0
def validate_abi(abi):
    """
    Helper function for validating an ABI
    """
    if not is_list_like(abi):
        raise ValueError("'abi' is not a list")

    if not all(is_dict(e) for e in abi):
        raise ValueError("'abi' is not a list of dictionaries")

    functions = filter_by_type('function', abi)
    selectors = groupby(compose(encode_hex, function_abi_to_4byte_selector),
                        functions)
    duplicates = valfilter(lambda funcs: len(funcs) > 1, selectors)
    if duplicates:
        raise ValueError('Abi contains functions with colliding selectors. '
                         'Functions {0}'.format(
                             _prepare_selector_collision_msg(duplicates)))
Ejemplo n.º 2
0
def chain_id_validator(web3):
    return compose(
        apply_formatter_at_index(transaction_normalizer, 0),
        transaction_param_validator(web3)
    )
TRANSACTION_PARAMS_MAPPING = {
    'gasPrice': 'gas_price',
}

transaction_params_remapper = apply_key_map(TRANSACTION_PARAMS_MAPPING)

TRANSACTION_PARAMS_FORMATTERS = {
    'gas': to_integer_if_hex,
    'gasPrice': to_integer_if_hex,
    'value': to_integer_if_hex,
    'nonce': to_integer_if_hex,
}

transaction_params_formatter = compose(
    # remove nonce for now due to issue https://github.com/ethereum/eth-tester/issues/80
    remove_key_if('nonce', lambda _: True),
    apply_formatters_to_dict(TRANSACTION_PARAMS_FORMATTERS),
)

FILTER_PARAMS_MAPPINGS = {
    'fromBlock': 'from_block',
    'toBlock': 'to_block',
}

filter_params_remapper = apply_key_map(FILTER_PARAMS_MAPPINGS)

FILTER_PARAMS_FORMATTERS = {
    'fromBlock': to_integer_if_hex,
    'toBlock': to_integer_if_hex,
}
Ejemplo n.º 4
0
        eth_tester.unlock_account(transaction['from'], password)
        transaction_hash = eth_tester.send_transaction(transaction)
    finally:
        eth_tester.lock_account(transaction['from'])

    return transaction_hash


API_ENDPOINTS = {
    'web3': {
        'clientVersion':
        client_version,
        'sha3':
        compose(
            encode_hex,
            keccak,
            decode_hex,
            without_eth_tester(operator.itemgetter(0)),
        ),
    },
    'net': {
        'version': static_return('1'),
        'peerCount': static_return(0),
        'listening': static_return(False),
    },
    'eth': {
        'protocolVersion':
        static_return('63'),
        'syncing':
        static_return(False),
        'coinbase':
        compose(
Ejemplo n.º 5
0
@to_tuple
def pop_singlets(seq):
    yield from (i[0] if is_list_like(i) and len(i) == 1 else i for i in seq)


@curry
def remove_trailing_from_seq(seq, remove_value=None):
    index = len(seq)
    while index > 0 and seq[index - 1] == remove_value:
        index -= 1
    return seq[:index]


normalize_topic_list = compose(
    remove_trailing_from_seq(remove_value=None),
    pop_singlets,
)


def is_indexed(arg):
    if isinstance(arg, TopicArgumentFilter) is True:
        return True
    return False


is_not_indexed = complement(is_indexed)


class EventFilterBuilder:
    formatter = None
    _fromBlock = None

@pytest.fixture()
def string_contract(web3, StringContract, address_conversion_func):
    deploy_txn = StringContract.constructor("Caqalai").transact()
    deploy_receipt = web3.eth.waitForTransactionReceipt(deploy_txn)
    assert deploy_receipt is not None
    contract_address = address_conversion_func(
        deploy_receipt['contractAddress'])
    contract = StringContract(address=contract_address)
    assert contract.address == contract_address
    assert len(web3.eth.getCode(contract.address)) > 0
    return contract


map_repr = compose(list, curry(map, repr))


@pytest.mark.parametrize(
    'method,args,repr_func,expected',
    (
        ('all_functions', (), map_repr, [
            '<Function blockHashAmphithyronVersify(uint256)>',
            '<Function identity(uint256,bool)>',
            '<Function identity(int256,bool)>'
        ]),
        ('get_function_by_signature', ('identity(uint256,bool)', ), repr,
         '<Function identity(uint256,bool)>'),
        ('find_functions_by_name', ('identity', ), map_repr, [
            '<Function identity(uint256,bool)>',
            '<Function identity(int256,bool)>'
def apply_formatters_to_args(*formatters):
    return compose(*(apply_formatter_at_index(formatter, index)
                     for index, formatter in enumerate(formatters)))
Ejemplo n.º 8
0
 def factory(cls, *args, **kwargs):
     return compose(cls, Contract.factory(*args, **kwargs))
Ejemplo n.º 9
0
block_formatter = apply_formatters_to_dict(BLOCK_FORMATTERS)

SYNCING_FORMATTERS = {
    'startingBlock': to_integer_if_hex,
    'currentBlock': to_integer_if_hex,
    'highestBlock': to_integer_if_hex,
    'knownStates': to_integer_if_hex,
    'pulledStates': to_integer_if_hex,
}

syncing_formatter = apply_formatters_to_dict(SYNCING_FORMATTERS)

TRANSACTION_POOL_CONTENT_FORMATTERS = {
    'pending': compose(
        keymap(to_ascii_if_bytes),
        valmap(transaction_formatter),
    ),
    'queued': compose(
        keymap(to_ascii_if_bytes),
        valmap(transaction_formatter),
    ),
}

transaction_pool_content_formatter = apply_formatters_to_dict(
    TRANSACTION_POOL_CONTENT_FORMATTERS)

TRANSACTION_POOL_INSPECT_FORMATTERS = {
    'pending': keymap(to_ascii_if_bytes),
    'queued': keymap(to_ascii_if_bytes),
}