Пример #1
0
def test_get_gas_remaining_with_vmerror(computation):
    assert computation.get_gas_remaining() == 100
    # Trigger an out of gas error causing get gas remaining to be 0
    with computation:
        raise VMError('Triggered VMError for tests')
    assert computation.is_error
    assert computation.get_gas_remaining() == 0
Пример #2
0
def test_output_with_vmerror(computation):
    # Trigger an out of gas error causing output to be b''
    computation.output = b'1'
    with computation:
        raise VMError('Triggered VMError for tests')
    assert computation.is_error
    assert computation.output == b''
Пример #3
0
def test_get_gas_refund_with_vmerror(computation):
    # Trigger an out of gas error causing get gas refund to be 0
    computation._gas_meter.refund_gas(100)
    with computation:
        raise VMError('Triggered VMError for tests')
    assert computation.is_error
    assert computation.get_gas_refund() == 0
Пример #4
0
def test_get_log_entries_with_vmerror(computation):
    # Trigger an out of gas error causing get log entries to be ()
    computation.add_log_entry(CANONICAL_ADDRESS_A, [1, 2, 3], b'')
    with computation:
        raise VMError('Triggered VMError for tests')
    assert computation.is_error
    assert computation.get_log_entries() == ()
Пример #5
0
def test_get_gas_used_with_vmerror(computation):
    # Trigger an out of gas error causing get gas used to be 150
    computation.consume_gas(3, reason='testing')
    computation.consume_gas(2, reason='testing')
    with computation:
        raise VMError('Triggered VMError for tests')
    assert computation.is_error
    assert computation.get_gas_used() == 100
Пример #6
0
def ecpairing(computation):
    if len(computation.msg.data) % 192:
        # data length must be an exact multiple of 192
        raise VMError("Invalid ECPAIRING parameters")

    num_points = len(computation.msg.data) // 192
    gas_fee = constants.GAS_ECPAIRING_BASE + num_points * constants.GAS_ECPAIRING_PER_POINT

    computation.consume_gas(gas_fee, reason='ECPAIRING Precompile')

    try:
        result = _ecpairing(computation.msg.data)
    except ValidationError:
        raise VMError("Invalid ECPAIRING parameters")

    if result is True:
        computation.output = pad32(b'\x01')
    elif result is False:
        computation.output = pad32(b'\x00')
    else:
        raise Exception("Invariant: unreachable code path")
    return computation
Пример #7
0
def ecmul(computation):
    computation.consume_gas(constants.GAS_ECMUL, reason='ECMUL Precompile')

    try:
        result = _ecmull(computation.msg.data)
    except ValidationError:
        raise VMError("Invalid ECMUL parameters")

    result_x, result_y = result
    result_bytes = b''.join((
        pad32(int_to_big_endian(result_x.n)),
        pad32(int_to_big_endian(result_y.n)),
    ))
    computation.output = result_bytes
    return computation
Пример #8
0
def test_should_erase_return_data_with_vm_error(computation):
    assert computation.get_gas_remaining() == 100
    # Trigger an out of gas error causing get gas remaining to be 0
    with computation:
        raise VMError('Triggered VMError for tests')
    assert computation.should_erase_return_data