Beispiel #1
0
def check_chain_version(config):
    key = '__chain_version__'
    chain_version = str(Packeter.ETHEREUM_PROTOCOL_VERSION)
    db = DB(db_path(config.get('misc', 'data_dir')))
    if not key in db:
        db.put(key, chain_version)
    if db.get(key) != chain_version:
        log.critical('db version mismatch', db_version=db.get(
            key), chain_version=chain_version, db_path=db_path)
        time.sleep(5)
Beispiel #2
0
def test_db():
    set_db()
    db = DB(utils.get_db_path())
    a, b = DB(utils.get_db_path()),  DB(utils.get_db_path())
    assert a == b
    assert a.uncommitted == b.uncommitted
    a.put('a', 'b')
    b.get('a') == 'b'
    assert a.uncommitted == b.uncommitted
    a.commit()
    assert a.uncommitted == b.uncommitted
    assert 'test' not in db
    set_db()
    assert a != DB(utils.get_db_path())
Beispiel #3
0
def check_chain_version(config):
    key = '__chain_version__'
    chain_version = str(Packeter.ETHEREUM_PROTOCOL_VERSION)
    db_path = get_db_path()
    db = DB(db_path)
    if not key in db:
        db.put(key, chain_version)
    if db.get(key) != chain_version:
        print \
"""
ATTENTION --------------------------------------------------------------------
the chain in the db (V:%r) doesn't match the the software version (V:%r)
This may lead to unexpected errors.
Consider to delete the db directory: %s
--------- --------------------------------------------------------------------
""" % (db.get(key), chain_version, db_path)
        time.sleep(5)
Beispiel #4
0
def test_db():
    set_db()
    db = DB(utils.get_db_path())
    a, b = DB(utils.get_db_path()), DB(utils.get_db_path())
    assert a == b
    assert a.uncommitted == b.uncommitted
    a.put('a', 'b')
    b.get('a') == 'b'
    assert a.uncommitted == b.uncommitted
    a.commit()
    assert a.uncommitted == b.uncommitted
    assert 'test' not in db
    set_db()
    assert a != DB(utils.get_db_path())
Beispiel #5
0
def test_genesis():
    k, v, k2, v2 = accounts()
    set_db()
    blk = blocks.genesis({v: utils.denoms.ether * 1})
    sr = blk.state_root
    db = DB(utils.get_db_path())
    assert blk.state.db.db == db.db
    db.put(blk.hash, blk.serialize())
    blk.state.db.commit()
    assert sr in db
    db.commit()
    assert sr in db
    blk2 = blocks.genesis({v: utils.denoms.ether * 1})
    blk3 = blocks.genesis()
    assert blk == blk2
    assert blk != blk3
    set_db()
    blk2 = blocks.genesis({v: utils.denoms.ether * 1})
    blk3 = blocks.genesis()
    assert blk == blk2
    assert blk != blk3
Beispiel #6
0
def check_chain_version(config):
    key = '__chain_version__'
    chain_version = str(Packeter.ETHEREUM_PROTOCOL_VERSION)
    db = DB(db_path(config.get('misc', 'data_dir')))
    if not key in db:
        db.put(key, chain_version)
    if db.get(key) != chain_version:
        log.critical('db version mismatch',
                     db_version=db.get(key),
                     chain_version=chain_version,
                     db_path=db_path)
        time.sleep(5)
Beispiel #7
0
def check_chain_version(config):
    key = '__chain_version__'
    chain_version = str(Packeter.ETHEREUM_PROTOCOL_VERSION)
    db_path = get_db_path()
    db = DB(db_path)
    if not key in db:
        db.put(key, chain_version)
    if db.get(key) != chain_version:
        print \
"""
ATTENTION --------------------------------------------------------------------
the chain in the db (V:%r) doesn't match the the software version (V:%r)
This may lead to unexpected errors.
Consider to delete the db directory: %s
--------- --------------------------------------------------------------------
""" % (db.get(key), chain_version, db_path)
        time.sleep(5)
Beispiel #8
0
def test_genesis():
    k, v, k2, v2 = accounts()
    set_db()
    blk = blocks.genesis({v: utils.denoms.ether * 1})
    sr = blk.state_root
    db = DB(utils.get_db_path())
    assert blk.state.db.db == db.db
    db.put(blk.hash, blk.serialize())
    blk.state.db.commit()
    assert sr in db
    db.commit()
    assert sr in db
    blk2 = blocks.genesis({v: utils.denoms.ether * 1})
    blk3 = blocks.genesis()
    assert blk == blk2
    assert blk != blk3
    set_db()
    blk2 = blocks.genesis({v: utils.denoms.ether * 1})
    blk3 = blocks.genesis()
    assert blk == blk2
    assert blk != blk3
Beispiel #9
0
def test_db():
    db = DB(utils.get_db_path())
    assert 'test' not in db
Beispiel #10
0
def db_store(blk):
    db = DB(utils.get_db_path())
    db.put(blk.hash, blk.serialize())
    db.commit()
    assert blocks.get_block(blk.hash) == blk
Beispiel #11
0
import json, ast
from pyethereum import transactions
from pyethereum import blocks
from pyethereum import processblock as pb
from pyethereum import utils as u
from pyethereum import vm
from pyethereum.slogging import get_logger, LogRecorder, configure_logging
import time
from pyethereum.db import DB
import tempfile
import os
import sys

sys.setrecursionlimit(10000)

db = DB(u.db_path(tempfile.mktemp()))


def profile_vm_test(params):
    pre = params['pre']
    exek = params['exec']
    env = params['env']

    # setup env
    blk = blocks.Block(db,
                       prevhash=env['previousHash'].decode('hex'),
                       number=int(env['currentNumber']),
                       coinbase=env['currentCoinbase'],
                       difficulty=int(env['currentDifficulty']),
                       gas_limit=int(env['currentGasLimit']),
                       timestamp=int(env['currentTimestamp']))
def new_db():
    return DB(utils.db_path(tempfile.mktemp()))
Beispiel #13
0
def db_store(blk):
    db = DB(utils.get_db_path())
    db.put(blk.hash, blk.serialize())
    db.commit()
    assert blocks.get_block(blk.hash) == blk
Beispiel #14
0
from pyethereum import opcodes, utils, blocks, vm, processblock, transactions
from pyethereum.db import DB
import tempfile
import random
import json
pb, u = processblock, utils

db = DB(utils.db_path(tempfile.mktemp()))

push_params = [range(1, 3), range(4, 8), range(9, 16), range(17, 32)]
codesize_params = [[50, 50]]


def generate_op_tests():
    outs = {}
    for opcode, (name, inargs, outargs, _) in opcodes.opcodes.items():
        _subid = 0
        for push_depths in push_params:
            for jump_num, code_size in codesize_params:
                if name in [
                        'CALL', 'CREATE', 'CALLCODE', 'LOG', 'POP', 'RETURN',
                        'STOP', 'INVALID', 'JUMP', 'JUMPI', 'CALLDATALOAD',
                        'CALLDATACOPY', 'CODECOPY', 'EXTCODECOPY', 'SHA3',
                        'MLOAD', 'MSTORE', 'MSTORE8', 'SUICIDE'
                ]:
                    continue
                if name[:3] in ['DUP', 'SWA', 'LOG']:
                    continue
                if name == 'SSTORE':
                    jump_num /= 10
                c = '\x5b'