예제 #1
0
def exec_npm_install_all(working_directory):
    '''
    execute "npm i"
    :param working_directory:
    :return:
    '''
    if 'package.json' in os.listdir(
            working_directory) and 'package-lock.json' in os.listdir(
                working_directory):
        os.remove(working_directory + os.sep + 'package-lock.json')
    if_success = True
    status = ''
    try:
        # subprocess.call("pkill node", stderr=subprocess.STDOUT, cwd=working_directory, shell=True)
        status = subprocess.check_output("npm install ; exit 0",
                                         stderr=subprocess.STDOUT,
                                         cwd=working_directory,
                                         shell=True)
        write_file(working_directory + '/exec_npm_install.log', status)
    except Exception as e:
        if_success = False
        # print('npm install\n' + e.output)
        # raise RuntimeError("command '{}' return with error (code {}): {}".format(e.cmd, e.returncode, e.output))
    finally:
        return if_success
예제 #2
0
def exec_truffle_test(working_directory):
    '''
    execute "pkill node ; testrpc ; truffle test;"
    :param working_directory:
    :return:
    '''
    import subprocess
    status = None
    log_path = working_directory + os.sep + 'exec_truffleTest.log'
    try:
        subprocess.call("pkill node",
                        stderr=subprocess.STDOUT,
                        cwd=working_directory,
                        shell=True)
        process = subprocess.Popen('testrpc',
                                   shell=True,
                                   stdout=DEVNULL,
                                   stderr=subprocess.STDOUT)
        # if process.poll() is None:
        status = subprocess.check_output("truffle test ; exit 0",
                                         stderr=subprocess.STDOUT,
                                         cwd=working_directory,
                                         shell=True)
        process.kill()
        # else:
        # do_nothing = None
        # raise Exception('testrpc failed!')
    except subprocess.CalledProcessError as e:
        status = e.output
    except Exception, e:
        status = e.output
        print('truffle test exception, please check:\n %s' % working_directory)
        write_file(log_path, status)
        return None
예제 #3
0
def exec_solcover(working_directory):
    '''
    execute "./node_modules/.bin/solidity-coverage"
    :param working_directory:
    :return:
    '''
    try:
        status = subprocess.call("pkill node",
                                 stderr=subprocess.STDOUT,
                                 cwd=working_directory,
                                 shell=True)
        status = subprocess.check_output(
            "./node_modules/.bin/solidity-coverage ; exit 0",
            stderr=subprocess.STDOUT,
            cwd=working_directory,
            shell=True)
    except Exception as e:
        # print('./node_modules/.bin/solidity-coverage\n' + e.output)
        status = e.output
    finally:
        if 'coverage reports generated' in status:
            log_path = working_directory + '/exec-solcover-valid.log'
        else:
            log_path = working_directory + '/exec-solcover-invalid.log'
        write_file(log_path, status)
        from src.utils.truffle_util import analysis_truffle_test_result
        exec_result = analysis_truffle_test_result(log_path)
        # init
        exec_msg = None
        if 'Error: ENOENT: no such file or directory, open \'./allFiredEvents\'' in status:
            exec_msg = 'allFiredEventIssue'
        if_generated = True if 'coverage reports generated' in status else False
        return if_generated, exec_msg
예제 #4
0
def exec_npm_rebuild(working_directory):
    '''
    execute "npm rebuild"
    :param working_directory:
    :return:
    '''
    if_success = True
    try:
        # subprocess.call("pkill node", stderr=subprocess.STDOUT, cwd=working_directory, shell=True)
        status = subprocess.check_output("npm rebuild ; exit 0",
                                         stderr=subprocess.STDOUT,
                                         cwd=working_directory,
                                         shell=True)
        write_file(working_directory + '/exec_npm_rebuild.log', status)
    except Exception as e:
        if_success = False
        print('npm rebuild\n' + e.output)
        # raise RuntimeError("command '{}' return with error (code {}): {}".format(e.cmd, e.returncode, e.output))
    finally:
        return if_success
예제 #5
0
def exec_npm_install_specific_package(working_directory, package):
    '''
    execute "npm i package"
    :param working_directory:
    :return:
    '''
    if_success = True
    try:
        # subprocess.call("pkill node", stderr=subprocess.STDOUT, cwd=working_directory, shell=True)
        status = subprocess.check_output("npm install " + package +
                                         " ; exit 0",
                                         stderr=subprocess.STDOUT,
                                         cwd=working_directory,
                                         shell=True)
        write_file(working_directory + '/exec_npm_' + package + '.log', status)
    except Exception as e:
        if_success = False
        print('npm i ' + package + '\n' + e.message)
    finally:
        return if_success
예제 #6
0
def exec_npm_install_solcover(working_directory):
    '''
    execute "npm i solidity-coverage"
    :param working_directory:
    :return:
    '''
    if_success = True
    try:
        # subprocess.call("pkill node", stderr=subprocess.STDOUT, cwd=working_directory, shell=True)
        status = subprocess.check_output(
            "npm install --save-dev solidity-coverage ; exit 0",
            stderr=subprocess.STDOUT,
            cwd=working_directory,
            shell=True)
        write_file(working_directory + '/exec_npm_solcov.log', status)
        if '+ solidity-coverage' not in status:
            if_success = False
    except Exception as e:
        if_success = False
        print('npm i solidity-coverage\n' + e.message)
    finally:
        return if_success
예제 #7
0
        # raise Exception('testrpc failed!')
    except subprocess.CalledProcessError as e:
        status = e.output
    except Exception, e:
        status = e.output
        print('truffle test exception, please check:\n %s' % working_directory)
        write_file(log_path, status)
        return None
    finally:
        if 'Error: Exceeds block gas limit' in status:
            status = exec_truffle_test_large_limitation(working_directory)
        # do not swith the order
        if 'Could not connect to your Ethereum client.' in status:
            print('Configure error! Please modify truffle.js:\n %s' %
                  working_directory)
            write_file(log_path, status)
            return None
        if 'Error: Cannot find module' in status:
            print(
                'Cannot find module error! Please add module manually:\n %s' %
                working_directory)
            write_file(log_path, status)
            return None
        write_file(log_path, status)
        return analysis_truffle_test_result(log_path)


def clean_symbols(str_tmp):
    str_tmp = str_tmp.replace('', '').replace('', '').replace(
        '', '').replace('',
                             '').replace('',