예제 #1
0
def do_book(testnet):
    # Filenames.
    if testnet:
        filename = 'book.testnet'
    else:
        filename = 'book.mainnet'
    old = CURR_DIR + '/' + filename
    new = old + '.new'

    # Get last block_index of old book.
    with open(old, 'r') as f:
        block_index = int(f.readlines()[-1][7:13])

    # Use temporary DB.
    clearinghoused.set_options(testnet=testnet)
    default_db = config.DATABASE
    temp_db = tempfile.gettempdir() + '/' + os.path.basename(config.DATABASE)
    shutil.copyfile(default_db, temp_db)
    clearinghoused.set_options(database_file=temp_db, testnet=testnet)
    db = util.connect_to_db()
    cursor = db.cursor()

    # TODO: USE API
    import subprocess
    if testnet:
        subprocess.check_call(['./clearinghoused.py', '--database-file=' + temp_db, '--testnet', 'reparse'])
    else:
        subprocess.check_call(['./clearinghoused.py', '--database-file=' + temp_db, 'reparse'])

    # Get new book.
    with open(new, 'w') as f:
        # Credits.
        cursor.execute('select * from credits where block_index <= ? order by block_index, address, asset', (block_index,))
        for credit in list(cursor):
            f.write('credit ' + str(summarise(credit)) + '\n')
        # Debits.
        cursor.execute('select * from debits where block_index <= ? order by block_index, address, asset', (block_index,))
        for debit in cursor.fetchall():
            f.write('debit ' + str(summarise(debit)) + '\n')

    # Compare books.
    compare(filename)

    # Clean up.
    cursor.close()
    os.remove(temp_db)
예제 #2
0
# Set test environment
os.environ['TZ'] = 'EST'
time.tzset()
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')

CURR_DIR = os.path.dirname(os.path.realpath(os.path.join(os.getcwd(), os.path.expanduser(__file__))))
sys.path.append(os.path.normpath(os.path.join(CURR_DIR, '..')))

from lib import (config, api, util, exceptions, bitcoin, blocks)
from lib import (send, order, btcpay, issuance, broadcast, bet, dividend, burn, cancel, callback, rps, rpsresolve, notary)
import clearinghoused

# config.BLOCK_FIRST = 0
# config.BURN_START = 0
# config.BURN_END = 9999999
clearinghoused.set_options(rpc_port=9999, database_file=CURR_DIR+'/clearinghoused.unittest.db', testnet=True, testcoin=False, unittest=True, backend_rpc_ssl_verify=False)

# unit tests private keys
config.UNITTEST_PRIVKEY = {
    'mn6q3dS2EnDUx3bmyWc6D4szJNVGtaR7zc': 'cPdUqd5EbBWsjcG9xiL1hz8bEyGFiz4SW99maU9JgpL9TEcxUf3j',
    'mtQheFaSfWELRB2MyMBaiWjdDm6ux9Ezns': 'cQ897jnCVRrawNbw8hgmjMiRNHejwzg4KbzdMCzc91iaTif8ReqX'
}

# Logs.
try: os.remove(CURR_DIR + '/log.new')
except: pass
logging.basicConfig(filename=CURR_DIR + '/log.new', level=logging.DEBUG, format='%(message)s')
requests_log = logging.getLogger("requests")
requests_log.setLevel(logging.WARNING)

# Output.