예제 #1
0
async def run(rumor, args):
    peer_id = await connect_rumor(rumor, args['client'], args['enr'])

    logs = []
    return_code = 0

    req_data = uint64(0).encode_bytes().hex()
    req_call = rumor.rpc.ping.req.raw(peer_id,
                                      req_data,
                                      raw=True,
                                      compression='snappy')
    await req_call
    await req_call.next()
    resp = await req_call.next()

    (resp_data, l) = parse_chunk_response(resp)
    logs.extend(l)
    if resp_data is None:
        return_code = 1

    else:
        pong = uint64.decode_bytes(bytes.fromhex(resp_data))

        if not isinstance(pong, int) or pong < 0:
            logs.append(f'invalid ping response: {pong}')
            return_code = 1

    return (return_code, logs)
예제 #2
0
def test_gasused_gaslimit_plus_regular_payload(spec, state):
    # pre-state
    state = build_state_with_complete_transition(spec, state)
    next_slot(spec, state)

    # execution payload
    execution_payload = build_empty_execution_payload(spec, state)
    execution_payload.gas_used = execution_payload.gas_limit + uint64(1)

    yield from run_execution_payload_processing(spec, state, execution_payload, valid=False)
예제 #3
0
def test_gaslimit_max_first_payload(spec, state):
    # pre-state
    state = build_state_with_incomplete_transition(spec, state)
    next_slot(spec, state)

    # execution payload
    execution_payload = build_empty_execution_payload(spec, state)
    execution_payload.gas_limit = uint64(2**64 - 1)

    yield from run_execution_payload_processing(spec, state, execution_payload)
예제 #4
0
def test_gaslimit_minimum_minus_regular_payload(spec, state):
    # pre-state
    state = build_state_with_complete_transition(spec, state)
    next_slot(spec, state)
    state.latest_execution_payload_header.gas_limit = spec.MIN_GAS_LIMIT

    # execution payload
    execution_payload = build_empty_execution_payload(spec, state)
    execution_payload.gas_limit = execution_payload.gas_limit - uint64(1)

    yield from run_execution_payload_processing(spec, state, execution_payload, valid=False)
예제 #5
0
def test_gaslimit_lower_regular_payload(spec, state):
    # pre-state
    state = build_state_with_complete_transition(spec, state)
    next_slot(spec, state)

    # execution payload
    execution_payload = build_empty_execution_payload(spec, state)
    execution_payload.gas_limit = (
        execution_payload.gas_limit -
        execution_payload.gas_limit // spec.GAS_LIMIT_DENOMINATOR + uint64(1)
    )

    yield from run_execution_payload_processing(spec, state, execution_payload)
예제 #6
0
def translate_value(value, typ):
    """
    Translate a value output from Py-SSZ deserialization into the given spec type.
    :param value: The PySSZ value
    :param typ: The type from the spec to translate into
    :return: the translated value
    """
    if issubclass(typ, spec_ssz.uint):
        if typ.byte_len == 1:
            return spec_ssz.uint8(value)
        elif typ.byte_len == 2:
            return spec_ssz.uint16(value)
        elif typ.byte_len == 4:
            return spec_ssz.uint32(value)
        elif typ.byte_len == 8:
            return spec_ssz.uint64(value)
        elif typ.byte_len == 16:
            return spec_ssz.uint128(value)
        elif typ.byte_len == 32:
            return spec_ssz.uint256(value)
        else:
            raise TypeError("invalid uint size")
    elif issubclass(typ, spec_ssz.List):
        return [translate_value(elem, typ.elem_type) for elem in value]
    elif issubclass(typ, spec_ssz.boolean):
        return value
    elif issubclass(typ, spec_ssz.Vector):
        return typ(*(translate_value(elem, typ.elem_type) for elem in value))
    elif issubclass(typ, spec_ssz.Bitlist):
        return typ(value)
    elif issubclass(typ, spec_ssz.Bitvector):
        return typ(value)
    elif issubclass(typ, spec_ssz.BytesN):
        return typ(value)
    elif issubclass(typ, spec_ssz.Bytes):
        return value
    if issubclass(typ, spec_ssz.Container):
        return typ(
            **{
                f_name: translate_value(f_val, f_typ)
                for (f_val, (f_name, f_typ)) in zip(value,
                                                    typ.get_fields().items())
            })
    else:
        raise TypeError("Type not supported: {}".format(typ))