コード例 #1
0
def mk_test(b, e, m, execgas):
    encoded = mk_modexp_data(b, e, m)
    s = c.snapshot()
    x = c.contract(kode %
                   (len(encoded) + 36, max(intlen(m), 1), max(intlen(m), 1)),
                   language='viper')
    pre = tester.mk_state_test_prefill(c)
    try:
        o = x.foo(
            encoded,
            startgas=21000 +
            intrinsic_gas_of_data(x.translator.encode('foo', [encoded])) +
            execgas)
        if big_endian_to_int(o[:intlen(m)]) != (pow(b, e, m) if m else 0):
            raise Exception(
                "Mismatch! %d %d %d expected %d computed %d" %
                (b, e, m, pow(b, e, m), big_endian_to_int(o[:intlen(m)])))
        print("Succeeded %d %d %d sg %d" % (b, e, m, execgas))
    except tester.TransactionFailed:
        print('OOG %d %d %d sg %d' % (b, e, m, execgas))
    o = tester.mk_state_test_postfill(c, pre)
    o2 = tester.mk_state_test_postfill(c, pre, filler_mode=True)
    assert new_statetest_utils.verify_state_test(o)
    c.revert(s)
    return o, o2
コード例 #2
0
ファイル: mk_ecpairing_tests.py プロジェクト: wub11/pyetherum
def mk_test(encoded, execgas, expect):
    pre = tester.mk_state_test_prefill(c)
    try:
        o = x1.foo(
            encoded,
            startgas=21000 +
            intrinsic_gas_of_data(x1.translator.encode('foo', [encoded])) +
            execgas)
    except tester.TransactionFailed:
        o = False
    if o is False:
        if expect != 'error':
            raise Exception('OOG')
    elif o == encode_int32(1):
        if expect != 'yes':
            raise Exception('False positive')
    elif o == encode_int32(0):
        if expect != 'no':
            raise Exception('False negative')
    else:
        raise Exception("wtf: %r" % o)
    o = tester.mk_state_test_postfill(c, pre)
    o2 = tester.mk_state_test_postfill(c, pre, filler_mode=True)
    assert new_statetest_utils.verify_state_test(o)
    return o, o2
コード例 #3
0
def mk_test(p1, p2, execgas, datarestrict=128):
    encoded = mk_ecadd_data(p1, p2)[:datarestrict] + \
        b'\x00' * max(datarestrict - 128, 0)
    pre = tester.mk_state_test_prefill(c)
    try:
        o = x1.foo(
            encoded,
            startgas=21000 +
            intrinsic_gas_of_data(x1.translator.encode('foo', [encoded])) +
            execgas)
        x, y = big_endian_to_int(o[:32]), big_endian_to_int(o[32:])
        if py_pairing.normalize(py_pairing.add(
                p1, p2)) != (py_pairing.FQ(x), py_pairing.FQ(y)):
            raise Exception("Mismatch! %r %r %d, expected %r computed %r" %
                            (p1, p2, datarestrict,
                             py_pairing.normalize(py_pairing.add(p1, p2)),
                             (x, y)))
        print('Succeeded! %r %r %d %r' % (p1, p2, datarestrict, (x, y)))
    except tester.TransactionFailed:
        print('OOG %r %r %d %d' % (p1, p2, datarestrict, execgas))
    o = tester.mk_state_test_postfill(c, pre)
    o2 = tester.mk_state_test_postfill(c, pre, filler_mode=True)
    assert new_statetest_utils.verify_state_test(o)
    return o, o2