Ejemplo n.º 1
0
def start_test_server(port):
    global SERVER_THREAD

    t = WebServerThread(port)
    SERVER_THREAD = t
    
    testlib.add_cleanup(stop_test_server)
    t.start()
def start_subdomain_registrar():
    global SUBDOMAIN_PROC
    # needs to exist

    # write out config file
    working_dir = os.environ.get('BLOCKSTACK_WORKING_DIR')
    assert working_dir

    config_path = os.path.join(working_dir, 'subdomain_registrar.conf')
    with open(config_path, 'w') as f:
        f.write(subdomain_registrar_config)

    os.environ['BSK_SUBDOMAIN_CONFIG'] = config_path

    try:
        os.rename('/tmp/subdomain_registrar.db',
                  '/tmp/subdomain_registrar.last')
        os.rename('/tmp/subdomain_registrar.log',
                  '/tmp/subdomain_registrar.log.bak')
    except OSError:
        pass

    env = {'BSK_SUBDOMAIN_REGTEST': '1', 'BSK_SUBDOMAIN_CONFIG': config_path}
    if os.environ.get('BLOCKSTACK_TEST_CLIENT_RPC_PORT', False):
        env['BLOCKSTACK_TEST_CLIENT_RPC_PORT'] = os.environ.get(
            'BLOCKSTACK_TEST_CLIENT_RPC_PORT')

    fd = open('/tmp/subdomain_registrar.log', 'w+')
    SUBDOMAIN_PROC = subprocess.Popen(['node', SUBDOMAIN_REGISTRAR_LOCATION],
                                      stdout=fd,
                                      stderr=fd,
                                      env=env)

    is_up = False
    for i in range(0, 3):
        time.sleep(5)
        try:
            res = requests.get(
                "http://localhost:{}/index".format(registrar_port))
            is_up = True
            break
        except Exception as e:
            traceback.print_exc()
            print >> sys.stderr, 'Subdomain registrar is not responding on localhost:{}, trying again...'.format(
                registrar_port)
            continue

    if not is_up:
        raise Exception('Subdomain registrar failed to start')

    testlib.add_cleanup(lambda: SUBDOMAIN_PROC.kill())
def start_subdomain_registrar():
    global SUBDOMAIN_PROC

    try:
        os.rename('/tmp/subdomain_registrar.db',
                  '/tmp/subdomain_registrar.last')
    except OSError:
        pass
    env = {'BSK_SUBDOMAIN_REGTEST': '1'}
    if os.environ.get('BLOCKSTACK_TEST_CLIENT_RPC_PORT', False):
        env['BLOCKSTACK_TEST_CLIENT_RPC_PORT'] = os.environ.get(
            'BLOCKSTACK_TEST_CLIENT_RPC_PORT')

    SUBDOMAIN_PROC = Popen(['node', SUBDOMAIN_REGISTRAR_LOCATION], env=env)
    testlib.add_cleanup(lambda: SUBDOMAIN_PROC.kill())
Ejemplo n.º 4
0
def start_subdomain_registrar():
    global SUBDOMAIN_PROC
    global SUBDOMAIN_REGISTRAR_CONFIG

    # send batches every 30 seconds
    # check transactions every second
    SUBDOMAIN_REGISTRAR_CONFIG = """
    {
      "winstonConsoleTransport": {
          "level": "debug",
          "handleExceptions": false,
          "timestamp": true,
          "stringify": true,
          "colorize": true,
          "json": false
      },
      "domainName": "%s",
      "ownerKey": "%s",
      "paymentKey": "%s",
      "batchDelayPeriod": 0.5,
      "checkTransactionPeriod": 0.5,
      "dbLocation": "%s/subdomain_registrar.db",
      "adminPassword": "******",
      "domainUri": "%s/%s/profile.json",
      "zonefileSize": 40960,
      "development": false,
      "port": %s,
      "regtest": true,
      "ipLimit": 0,
      "apiKeys": [],
      "proofsRequired": 0,
      "disableRegistrationsWithoutKey": false
    }
    """ % (SUBDOMAIN_DOMAIN, SUBDOMAIN_OWNER_KEY, SUBDOMAIN_PAYMENT_KEY, os.environ['BLOCKSTACK_WORKING_DIR'], SUBDOMAIN_ADMIN_PASSWORD, GAIA_READ_URL, SUBDOMAIN_OWNER_ADDRESS, SUBDOMAIN_REGISTRAR_PORT)

    subdomain_registrar_config_path = os.path.join(os.environ['BLOCKSTACK_WORKING_DIR'], 'subdomain-registrar.conf')
    with open(subdomain_registrar_config_path, 'w') as f:
        f.write(SUBDOMAIN_REGISTRAR_CONFIG.strip())

    subdomain_log_path = os.path.join(os.environ['BLOCKSTACK_WORKING_DIR'], 'subdomain-registrar.log')
    subdomain_stdout = open(subdomain_log_path, 'w')
    subdomain_stderr = open(subdomain_log_path, 'w')

    os.environ['BSK_SUBDOMAIN_CONFIG'] = subdomain_registrar_config_path 
    SUBDOMAIN_PROC = subprocess.Popen('blockstack-subdomain-registrar start {}'.format(SUBDOMAIN_DOMAIN), shell=True, stdout=subdomain_stdout, stderr=subdomain_stderr)

    testlib.add_cleanup(stop_subdomain_registrar)