コード例 #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 setup_filler(name, environment=None):
    environment = normalize_environment(environment or {})
    return {
        name: {
            "env": environment,
            "pre": {},
        }
    }
コード例 #3
0
def setup_filler(
        name: str,
        environment: Dict[Any, Any] = None) -> Dict[str, Dict[str, Any]]:
    environment = normalize_environment(environment or {})
    return {
        name: {
            "env": environment,
            "pre": {},
        }
    }
コード例 #4
0
def fill_vm_test(
        filler: Dict[str, Any],
        *,
        call_creates: Any=None,
        gas_price: Union[int, str]=None,
        gas_remaining: Union[int, str]=0,
        logs: Iterable[Tuple[bytes, List[int], bytes]]=None,
        output: bytes=b"") -> Dict[str, Dict[str, Any]]:

    test_name = get_test_name(filler)
    test = filler[test_name]

    environment = normalize_environment(test["env"])
    pre_state = normalize_state(test["pre"])
    execution = normalize_execution(test["exec"])

    assert len(test["expect"]) == 1
    expect = test["expect"][0]
    assert "network" not in test
    assert "indexes" not in test

    result = normalize_state(expect["result"])
    post_state = deep_merge(pre_state, result)

    call_creates = normalize_call_creates(call_creates or [])
    gas_remaining = normalize_int(gas_remaining)
    output = normalize_bytes(output)

    logs = normalize_logs(logs or [])
    log_hash = hash_log_entries(logs)

    return {
        test_name: {
            "env": environment,
            "pre": pre_state,
            "exec": execution,
            "post": post_state,
            "callcreates": call_creates,
            "gas": gas_remaining,
            "output": output,
            "logs": log_hash,
        }
    }