Esempio n. 1
0
    else:
        assert TypeError("State definition must either be a mapping or a sequence")

    seen_keys = set(concat(d.keys() for d in state_dict.values()))
    bad_keys = seen_keys - {"balance", "nonce", "storage", "code"}
    if bad_keys:
        raise ValidationError(
            f"State definition contains the following invalid account fields: {', '.join(bad_keys)}"
        )

    return state_dict


normalize_storage = compose(
    curried.keymap(normalize_int),
    curried.valmap(normalize_int),
)


normalize_state = compose(
    curried.keymap(to_canonical_address),
    curried.valmap(dict_normalizer({
        "balance": normalize_int,
        "code": normalize_bytes,
        "nonce": normalize_int,
        "storage": normalize_storage
    }, required=[])),
    apply_formatter_if(
        lambda s: isinstance(s, Iterable) and not isinstance(s, Mapping),
        state_definition_to_dict
    ),
Esempio n. 2
0
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(
        curried.keymap(to_ascii_if_bytes),
        curried.valmap(transaction_result_formatter),
    ),
    'queued':
    compose(
        curried.keymap(to_ascii_if_bytes),
        curried.valmap(transaction_result_formatter),
    ),
}

transaction_pool_content_formatter = apply_formatters_to_dict(
    TRANSACTION_POOL_CONTENT_FORMATTERS)

TRANSACTION_POOL_INSPECT_FORMATTERS = {
    'pending': curried.keymap(to_ascii_if_bytes),
    'queued': curried.keymap(to_ascii_if_bytes),
}
Esempio n. 3
0
    "gas": to_hex,
})

expect_element_formatter = apply_formatters_to_dict(
    {"result": state_formatter})
expect_formatter: Callable[[List[Any]], List[Any]]
expect_formatter = apply_formatter_to_array(expect_element_formatter)

test_formatter = apply_formatters_to_dict({
    "env": environment_formatter,
    "pre": state_formatter,
    "transaction": transaction_group_formatter,
    "expect": expect_formatter,
    "exec": execution_formatter,
})
filler_formatter = curried.valmap(test_formatter)

state_post_formatter = apply_formatters_to_dict({"hash": encode_hex})

filled_state_test_formatter = curried.valmap(
    apply_formatters_to_dict({
        "env": environment_formatter,
        "pre": state_formatter,
        "transaction": transaction_group_formatter,
        "post": state_post_formatter,
    }))

call_create_item_formatter = apply_formatters_to_dict({
    "data": encode_hex,
    "destination": to_checksum_address,
    "gasLimit": to_hex,