예제 #1
0
파일: state.py 프로젝트: cd4761/ecc-trinity
def fill_state_test(filler: Dict[str, Any]) -> Dict[str, Dict[str, Any]]:
    """
    Filler function for filling state tests.
    """
    test_name = get_test_name(filler)
    test = filler[test_name]

    environment = normalize_environment(test["env"])
    pre_state = normalize_state(test["pre"])
    transaction_group = normalize_transaction_group(test["transaction"])

    post = defaultdict(list)  # type: Dict[int, List[Dict[str, str]]]
    for expect in test["expect"]:
        indexes = expect["indexes"]
        networks = normalize_networks(expect["networks"])
        result = normalize_state(expect["result"])
        post_state = deep_merge(pre_state, result)
        for network in networks:
            state_class = STATE_CLASSES[network]
            post_state_root = calc_state_root(post_state, state_class)
            post[network].append({
                "hash": encode_hex(post_state_root),
                "indexes": indexes,
            })

    return {
        test_name: {
            "env": environment,
            "pre": pre_state,
            "transaction": transaction_group,
            "post": post
        }
    }
예제 #2
0
def normalize_unsigned_transaction(transaction: TransactionDict,
                                   indexes: Dict[str, Any]) -> TransactionDict:

    normalized = normalize_transaction_group(transaction)
    return merge(normalized, {
        # Dynamic key access not yet allowed with TypedDict
        # https://github.com/python/mypy/issues/5359
        transaction_key: normalized[transaction_key][indexes[index_key]]  # type: ignore
        for transaction_key, index_key in [
            ("gasLimit", "gas"),
            ("value", "value"),
            ("data", "data"),
        ]
        if index_key in indexes
    })