def test_testutils_check_vm_test():
    func_name, filename, testname, testdata = collected[1]
    testutils.check_vm_test(testutils.fixture_to_bytes(testdata))
    # manipulate post data
    storage = testdata['post'].values()[0]['storage']
    assert storage['0x23'] == '0x01'
    storage['0x23'] = '0x02'
    failed_as_expected = False
    try:
        testutils.check_vm_test(testutils.fixture_to_bytes(testdata))
    except Exception:
        failed_as_expected = True
    assert failed_as_expected
Exemple #2
0
def test_testutils_check_vm_test():
    func_name, filename, testname, testdata = collected[1]
    testutils.check_vm_test(testutils.fixture_to_bytes(testdata))
    # manipulate post data
    storage = testdata['post'].values()[0]['storage']
    assert storage['0x23'] == '0x01'
    storage['0x23'] = '0x02'
    failed_as_expected = False
    try:
        testutils.check_vm_test(testutils.fixture_to_bytes(testdata))
    except Exception:
        failed_as_expected = True
    assert failed_as_expected
Exemple #3
0
def test_transaction(filename, testname, testdata):
    testdata = fixture_to_bytes(testdata)

    try:
        rlpdata = decode_hex(testdata["rlp"][2:])
        o = {}
        tx = rlp.decode(rlpdata, transactions.Transaction)
        blknum = int(testdata["blocknumber"])
        if blknum >= config.default_config["HOMESTEAD_FORK_BLKNUM"]:
            tx.check_low_s()
        o["sender"] = tx.sender
        o["transaction"] = {
            "data": b'0x' * (len(tx.data) > 0) + encode_hex(tx.data),
            "gasLimit": str_to_bytes(str(tx.startgas)),
            "gasPrice": str_to_bytes(str(tx.gasprice)),
            "nonce": str_to_bytes(str(tx.nonce)),
            "r":
            b'0x' + encode_hex(utils.zpad(utils.int_to_big_endian(tx.r), 32)),
            "s":
            b'0x' + encode_hex(utils.zpad(utils.int_to_big_endian(tx.s), 32)),
            "v": str_to_bytes(str(tx.v)),
            "value": str_to_bytes(str(tx.value)),
            "to": encode_hex(tx.to),
        }
    except Exception as e:
        tx = None
        sys.stderr.write(str(e))
    if 'transaction' not in testdata:  # expected to fail
        assert tx is None
    else:
        assert set(o['transaction'].keys()) == set(
            testdata.get("transaction", dict()).keys())
        o.get("transaction", None) == testdata.get("transaction", None)
        assert encode_hex(o.get("sender", '')) == testdata.get("sender", '')
def test_difficulty(filename, testname, testdata):
    testdata = fixture_to_bytes(testdata)

    parent_timestamp = int(testdata["parentTimestamp"],
                           10 if testdata["parentTimestamp"].isdigit() else 16)
    parent_difficulty = int(
        testdata["parentDifficulty"],
        10 if testdata["parentDifficulty"].isdigit() else 16)
    parent_blk_number = int(
        testdata["currentBlockNumber"],
        10 if testdata["currentBlockNumber"].isdigit() else 16) - 1
    cur_blk_timestamp = int(
        testdata["currentTimestamp"],
        10 if testdata["currentTimestamp"].isdigit() else 16)
    reference_dif = int(testdata["currentDifficulty"],
                        10 if testdata["currentDifficulty"].isdigit() else 16)

    env = tester.state().env
    if 'Homestead' in filename:
        env.config['HOMESTEAD_FORK_BLKNUM'] = 0
    if 'difficultyMorden' in filename:
        env.config['HOMESTEAD_FORK_BLKNUM'] = 494000

    parent_bh = blocks.BlockHeader(timestamp=parent_timestamp,
                                   difficulty=parent_difficulty,
                                   number=parent_blk_number)
    block = blocks.Block(parent_bh, [], env=env, making=True)

    calculated_dif = blocks.calc_difficulty(block, cur_blk_timestamp)

    print(calculated_dif)
    print(reference_dif)
    assert calculated_dif == reference_dif
def run_test(filename, testname, testdata):
    testdata = fixture_to_bytes(testdata)

    try:
        rlpdata = decode_hex(testdata["rlp"][2:])
        print rlpdata.encode("hex")
        o = {}
        tx = rlp.decode(rlpdata, transactions.Transaction)
        o["sender"] = tx.sender
        o["transaction"] = {
            "data": b"0x" * (len(tx.data) > 0) + encode_hex(tx.data),
            "gasLimit": str_to_bytes(str(tx.startgas)),
            "gasPrice": str_to_bytes(str(tx.gasprice)),
            "nonce": str_to_bytes(str(tx.nonce)),
            "r": b"0x" + encode_hex(utils.zpad(utils.int_to_big_endian(tx.r), 32)),
            "s": b"0x" + encode_hex(utils.zpad(utils.int_to_big_endian(tx.s), 32)),
            "v": str_to_bytes(str(tx.v)),
            "value": str_to_bytes(str(tx.value)),
            "to": encode_hex(tx.to),
        }
    except:
        tx = None
    if "transaction" not in testdata:  # expected to fail
        assert tx is None
    else:
        assert set(o["transaction"].keys()) == set(testdata.get("transaction", dict()).keys())
        o.get("transaction", None) == testdata.get("transaction", None)
        assert encode_hex(o.get("sender", "")) == testdata.get("sender", "")
Exemple #6
0
def test_difficulty(filename, testname, testdata):
    testdata = fixture_to_bytes(testdata)

    parent_timestamp=int(testdata["parentTimestamp"], 10 if testdata["parentTimestamp"].isdigit() else 16)
    parent_difficulty=int(testdata["parentDifficulty"], 10 if testdata["parentDifficulty"].isdigit() else 16)
    parent_blk_number=int(testdata["currentBlockNumber"], 10 if testdata["currentBlockNumber"].isdigit() else 16)-1
    cur_blk_timestamp=int(testdata["currentTimestamp"], 10 if testdata["currentTimestamp"].isdigit() else 16)
    reference_dif = int(testdata["currentDifficulty"], 10 if testdata["currentDifficulty"].isdigit() else 16)


    env = tester.state().env
    if 'Homestead' in filename:
        env.config['HOMESTEAD_FORK_BLKNUM'] = 0
    if 'difficultyMorden' in filename:
        env.config['HOMESTEAD_FORK_BLKNUM'] = 494000

    parent_bh = blocks.BlockHeader(timestamp=parent_timestamp,
                             difficulty=parent_difficulty,
                             number=parent_blk_number)
    block = blocks.Block(parent_bh, [], env=env,
                      making=True)


    calculated_dif = blocks.calc_difficulty(block, cur_blk_timestamp)

    print(calculated_dif)
    print(reference_dif)
    assert calculated_dif == reference_dif
def run_test(filename, testname, testdata):
    testdata = fixture_to_bytes(testdata)

    try:
        rlpdata = decode_hex(testdata["rlp"][2:])
        print rlpdata.encode('hex')
        o = {}
        tx = rlp.decode(rlpdata, transactions.Transaction)
        o["sender"] = tx.sender
        o["transaction"] = {
            "data": b'0x' * (len(tx.data) > 0) + encode_hex(tx.data),
            "gasLimit": str_to_bytes(str(tx.startgas)),
            "gasPrice": str_to_bytes(str(tx.gasprice)),
            "nonce": str_to_bytes(str(tx.nonce)),
            "r":
            b'0x' + encode_hex(utils.zpad(utils.int_to_big_endian(tx.r), 32)),
            "s":
            b'0x' + encode_hex(utils.zpad(utils.int_to_big_endian(tx.s), 32)),
            "v": str_to_bytes(str(tx.v)),
            "value": str_to_bytes(str(tx.value)),
            "to": encode_hex(tx.to),
        }
    except:
        tx = None
    if 'transaction' not in testdata:  # expected to fail
        assert tx is None
    else:
        assert set(o['transaction'].keys()) == set(
            testdata.get("transaction", dict()).keys())
        o.get("transaction", None) == testdata.get("transaction", None)
        assert encode_hex(o.get("sender", '')) == testdata.get("sender", '')
def test_transaction(filename, testname, testdata):
    testdata = fixture_to_bytes(testdata)

    try:
        rlpdata = decode_hex(testdata["rlp"][2:])
        o = {}
        tx = rlp.decode(rlpdata, transactions.Transaction)
        blknum = int(testdata["blocknumber"])
        if blknum >= config.default_config["HOMESTEAD_FORK_BLKNUM"]:
            tx.check_low_s()
        o["sender"] = tx.sender
        o["transaction"] = {
            "data": b'0x' * (len(tx.data) > 0) + encode_hex(tx.data),
            "gasLimit": str_to_bytes(str(tx.startgas)),
            "gasPrice": str_to_bytes(str(tx.gasprice)),
            "nonce": str_to_bytes(str(tx.nonce)),
            "r": b'0x' + encode_hex(utils.zpad(utils.int_to_big_endian(tx.r), 32)),
            "s": b'0x' + encode_hex(utils.zpad(utils.int_to_big_endian(tx.s), 32)),
            "v": str_to_bytes(str(tx.v)),
            "value": str_to_bytes(str(tx.value)),
            "to": encode_hex(tx.to),
        }
    except Exception as e:
        tx = None
        sys.stderr.write(str(e))
    if 'transaction' not in testdata:  # expected to fail
        assert tx is None
    else:
        assert set(o['transaction'].keys()) == set(testdata.get("transaction", dict()).keys())
        o.get("transaction", None) == testdata.get("transaction", None)
        assert encode_hex(o.get("sender", '')) == testdata.get("sender", '')
Exemple #9
0
def do_test_vm(filename,
               testname=None,
               testdata=None,
               limit=99999999,
               profiler=None):
    logger.debug('running test:%r in %r' % (testname, filename))
    testutils.run_vm_test(testutils.fixture_to_bytes(testdata),
                          testutils.VERIFY,
                          profiler=profiler)
Exemple #10
0
def load_tests():
    fixture = {}
    testdir = os.path.join(fixture_path, 'TrieTests')
    for f in os.listdir(testdir):
        if f != 'trietest.json':
            continue
        sub_fixture = json.load(open(os.path.join(testdir, f)))
        for k, v in sub_fixture.items():
            fixture[f + "_" + k] = v
    return fixture_to_bytes(fixture)
Exemple #11
0
def load_tests():
    try:
        fn = os.path.join(testutils.fixture_path, 'TrieTests', 'trietest.json')
        fixture = json.load(open(fn, 'r'))
    except IOError:
        raise IOError("Could not read trietests.json from fixtures",
                      "Make sure you did 'git submodule init'")
    expected_keys = set(['jeff', 'emptyValues', 'branchingTests'])
    assert set(fixture.keys()) == expected_keys, ("test data changed!", list(fixture.keys()))
    return fixture_to_bytes(fixture)
Exemple #12
0
def test_testutils_check_vm_test():
    func_name, filename, testname, testdata = collected[1]
    testutils.check_vm_test(testutils.fixture_to_bytes(testdata))
    for address_data in testdata['post'].values():
        storage = address_data['storage']
        if "0x23" not in storage:
            continue
        assert storage['0x23'] == '0x01'
        # manipulate post data
        storage['0x23'] = '0x02'
        break
    else:
        raise AssertionError("Did not find `0x23` in storage values")

    failed_as_expected = False
    try:
        testutils.check_vm_test(testutils.fixture_to_bytes(testdata))
    except Exception:
        failed_as_expected = True
    assert failed_as_expected
Exemple #13
0
def test_testutils_check_vm_test():
    func_name, filename, testname, testdata = collected[1]
    testutils.check_vm_test(testutils.fixture_to_bytes(testdata))
    for address_data in testdata['post'].values():
        storage = address_data['storage']
        if "0x23" not in storage:
            continue
        assert storage['0x23'] == '0x01'
        # manipulate post data
        storage['0x23'] = '0x02'
        break
    else:
        raise AssertionError("Did not find `0x23` in storage values")

    failed_as_expected = False
    try:
        testutils.check_vm_test(testutils.fixture_to_bytes(testdata))
    except Exception:
        failed_as_expected = True
    assert failed_as_expected
def run_test(name):

    logger.debug('testing %s' % name)
    t = trie.Trie(new_db())
    data = fixture_to_bytes(load_tests()[name])

    for k in data['in']:
        logger.debug('updating with (%s, %s)' % (k, k))
        k = to_string(k)
        t.update(k, k)
    for point, prev, nxt in data['tests']:
        assert to_string(nxt) == (t.next(point) or b'')
        assert to_string(prev) == (t.prev(point) or b'')
def run_test(name):

    logger.debug('testing %s' % name)
    t = trie.Trie(new_db())
    data = fixture_to_bytes(load_tests()[name])

    for k in data['in']:
        logger.debug('updating with (%s, %s)' % (k, k))
        k = to_string(k)
        t.update(k, k)
    for point, prev, nxt in data['tests']:
        assert to_string(nxt) == (t.next(point) or b'')
        assert to_string(prev) == (t.prev(point) or b'')
def genesis_fixture():
    """
    Read genesis block from fixtures.
    """
    genesis_fixture = None
    fn = os.path.join(testutils.fixture_path, 'BasicTests', 'genesishashestest.json')
    with open(fn, 'r') as f:
        genesis_fixture = json.load(f)
    assert genesis_fixture is not None, "Could not read genesishashtest.json from fixtures. Make sure you did 'git submodule init'!"
    # FIXME: assert that link is uptodate
    for k in ('genesis_rlp_hex', 'genesis_state_root', 'genesis_hash'):
        assert k in genesis_fixture
    return fixture_to_bytes(genesis_fixture)
Exemple #17
0
def run_test(filename, testname, testdata):
    testdata = fixture_to_bytes(testdata)

    try:
        rlpdata = decode_hex(testdata["rlp"][2:])
        o = {}
        tx = rlp.decode(rlpdata, transactions.Transaction)
        o["sender"] = tx.sender
        o["transaction"] = {
            "data": b'0x' * (len(tx.data) > 0) + encode_hex(tx.data),
            "gasLimit": str_to_bytes(str(tx.startgas)),
            "gasPrice": str_to_bytes(str(tx.gasprice)),
            "nonce": str_to_bytes(str(tx.nonce)),
            "r": b'0x' + encode_hex(utils.zpad(utils.int_to_big_endian(tx.r), 32)),
            "s": b'0x' + encode_hex(utils.zpad(utils.int_to_big_endian(tx.s), 32)),
            "v": str_to_bytes(str(tx.v)),
            "value": str_to_bytes(str(tx.value)),
            "to": encode_hex(tx.to),
        }
    except Exception, e:
        tx = None
        sys.stderr.write(str(e))
Exemple #18
0
def run_test(filename, testname, testdata):
    testdata = fixture_to_bytes(testdata)

    try:
        rlpdata = decode_hex(testdata["rlp"][2:])
        o = {}
        tx = rlp.decode(rlpdata, transactions.Transaction)
        o["sender"] = tx.sender
        o["transaction"] = {
            "data": b'0x' * (len(tx.data) > 0) + encode_hex(tx.data),
            "gasLimit": str_to_bytes(str(tx.startgas)),
            "gasPrice": str_to_bytes(str(tx.gasprice)),
            "nonce": str_to_bytes(str(tx.nonce)),
            "r":
            b'0x' + encode_hex(utils.zpad(utils.int_to_big_endian(tx.r), 32)),
            "s":
            b'0x' + encode_hex(utils.zpad(utils.int_to_big_endian(tx.s), 32)),
            "v": str_to_bytes(str(tx.v)),
            "value": str_to_bytes(str(tx.value)),
            "to": encode_hex(tx.to),
        }
    except Exception, e:
        tx = None
        sys.stderr.write(str(e))
Exemple #19
0
def test_vm(filename, testname, testdata):
    testutils.check_vm_test(testutils.fixture_to_bytes(testdata))
Exemple #20
0
def do_test_state(filename, testname=None, testdata=None, limit=99999999):
    set_level(None, 'info')
    logger.debug('running test:%r in %r' % (testname, filename))
    testutils.check_state_test(testutils.fixture_to_bytes(testdata))
Exemple #21
0
def do_test_vm(filename, testname=None, testdata=None, limit=99999999):
    logger.debug('running test:%r in %r' % (testname, filename))
    testutils.check_vm_test(testutils.fixture_to_bytes(testdata))
Exemple #22
0
def test_state(filename, testname, testdata):  # pylint: disable=unused-argument
    # test data generated by testutils.generate_test_params
    testutils.check_abi_test(testutils.fixture_to_bytes(testdata))
Exemple #23
0
def test_state(filename, testname, testdata):
    logger.debug('running test:%r in %r' % (testname, filename))
    testutils.check_state_test(testutils.fixture_to_bytes(testdata))
Exemple #24
0
def test_vm(filename, testname, testdata):
    testutils.check_vm_test(testutils.fixture_to_bytes(testdata))
Exemple #25
0
def do_test_state(filename, testname=None, testdata=None, limit=99999999):
    set_level(None, 'info')
    logger.debug('running test:%r in %r' % (testname, filename))
    testutils.check_state_test(testutils.fixture_to_bytes(testdata))
def test_state(filename, testname, testdata):
    testutils.check_abi_test(testutils.fixture_to_bytes(testdata))
Exemple #27
0
def test_state(filename, testname, testdata):
    testutils.check_abi_test(testutils.fixture_to_bytes(testdata))
Exemple #28
0
def test_state(filename, testname, testdata):
    logger.debug("running test:%r in %r" % (testname, filename))
    testutils.check_state_test(testutils.fixture_to_bytes(testdata))
Exemple #29
0
def do_test_vm(filename, testname=None, testdata=None, limit=99999999, profiler=None):
    logger.debug('running test:%r in %r' % (testname, filename))
    testutils.run_vm_test(testutils.fixture_to_bytes(testdata), testutils.VERIFY, profiler=profiler)