<commit_before>const util = require('util');
const web3Utils = require('web3-utils');
const readline = require('readline');
const ora = require('ora');

const indentedSpinner = require('./indentedSpinner');
const MigrationsMessages = require('./messages');

/**
 *  Reporter consumed by a migrations sequence which iteself consumes a series of Migration and
 *  Deployer instances that emit both async `Emittery` events and conventional EventEmitter
 *  events (from Web3PromiEvent). This reporter is designed to track the execution of
 *  several migrations files in sequence and is analagous to the Mocha reporter in that:
 *
 *  test:: deployment
 *  suite:: deployer.start to deployer.finish
 *  test file:: migrations file
 *
 *  Each time a new migrations file loads, the reporter needs the following properties
 *  updated to reflect the current emitter source:
 *  + `this.migration`
 *  + `this.deployer`
 */
class Reporter {

  constructor(){
    this.deployer = null;
    this.migration = null;
    this.currentGasTotal = 0;
    this.currentCostTotal = new web3Utils.BN(0);
    this.finalCostTotal = new web3Utils.BN(0);
    this.deployments = 0;
    this.separator = '\n';
    this.summary = [];
    this.currentFileIndex = -1;
    this.blockSpinner = null;
    this.currentBlockWait = '';

    this.messages = new MigrationsMessages(this);
  }

  // ------------------------------------  Utilities -----------------------------------------------

  /**
   * Sets a Migration instance to be the current migrations events emitter source
   * @param {Migration} migration
   */
  setMigration(migration){
    this.migration = migration;
  }

  /**
   * Sets a Deployer instance as the current deployer events emitter source
   * @param {Deployer} deployer
   */
  setDeployer(deployer){
    this.deployer = deployer
  }

  /**
   * Registers emitter handlers
   */
  listen(){

    // Migration
    this.migration.emitter.on('preMigrate',          this.preMigrate.bind(this));
    this.migration.emitter.on('startTransaction',    this.startTransaction.bind(this));
    this.migration.emitter.on('endTransaction',      this.endTransaction.bind(this));
    this.migration.emitter.on('postMigrate',         this.postMigrate.bind(this));
    this.migration.emitter.on('error',               this.error.bind(this));

    // Deployment
    this.deployer.emitter.on('preDeploy',            this.preDeploy.bind(this));
    this.deployer.emitter.on('postDeploy',           this.postDeploy.bind(this));
    this.deployer.emitter.on('deployFailed',         this.deployFailed.bind(this));
    this.deployer.emitter.on('linking',              this.linking.bind(this));
    this.deployer.emitter.on('error',                this.error.bind(this));
    this.deployer.emitter.on('transactionHash',      this.hash.bind(this));
    this.deployer.emitter.on('confirmation',         this.confirmation.bind(this));
    this.deployer.emitter.on('block',                this.block.bind(this));
    this.deployer.emitter.on('startTransaction',     this.startTransaction.bind(this));
    this.deployer.emitter.on('endTransaction',       this.endTransaction.bind(this));
  }

  /**
   * Retrieves gas usage totals per migrations file / totals since the reporter
   * started running. Calling this method resets the gas counters for migrations totals
   */
  getTotals(){
    const gas = this.currentGasTotal;
    const cost = web3Utils.fromWei(this.currentCostTotal, "ether");
    this.finalCostTotal = this.finalCostTotal.add(this.currentCostTotal);

    this.currentGasTotal = 0;
    this.currentCostTotal = new web3Utils.BN(0);

    return {
      gas: gas,
      cost: cost,
      finalCost: web3Utils.fromWei(this.finalCostTotal, "ether"),
      deployments: this.deployments.toString()
    }
  }

  /**
   * Queries the user for a true/false response and resolves the result.
   * @param  {String} type identifier the reporter consumes to format query
   * @return {Promise}
   */
  askBoolean(type){
    const self = this;
    const question = this.messages.questions(type);
    const exitLine = this.messages.exitLines(type);

    // NB: We need direct access to a writeable stream here.
    // This ignores `quiet` - but we only use that mode for `truffle test`.
    const input = readline.createInterface({
      input: process.stdin,
      output: process.stdout
    });

    const affirmations = ['y', 'yes', 'YES', 'Yes'];

    return new Promise(resolve => {

      input.question(question, (answer) => {
        if (affirmations.includes(answer.trim())){
          input.close();
          return resolve(true);
        };

        input.close();
        self.deployer && self.deployer.logger.log(exitLine);
        resolve(false);
      })
    });
  }

  /**
   * Error dispatcher. Parses the error returned from web3 and outputs a more verbose error after
   * doing what it can to evaluate the failure context from data passed to it.
   * @param  {Object} data info collected during deployment attempt
   */
  async processDeploymentError(data){
    let message;
    const error = data.estimateError || data.error;

    data.reason = (data.error) ? data.error.reason : null;

    const errors = {
      ETH: error.message.includes('funds'),
      OOG: error.message.includes('out of gas') || (data.gas === data.blockLimit),<commit_msg>Remove failing blockLimit check<commit_after>const util = require('util');
const web3Utils = require('web3-utils');
const readline = require('readline');
const ora = require('ora');

const indentedSpinner = require('./indentedSpinner');
const MigrationsMessages = require('./messages');

/**
 *  Reporter consumed by a migrations sequence which iteself consumes a series of Migration and
 *  Deployer instances that emit both async `Emittery` events and conventional EventEmitter
 *  events (from Web3PromiEvent). This reporter is designed to track the execution of
 *  several migrations files in sequence and is analagous to the Mocha reporter in that:
 *
 *  test:: deployment
 *  suite:: deployer.start to deployer.finish
 *  test file:: migrations file
 *
 *  Each time a new migrations file loads, the reporter needs the following properties
 *  updated to reflect the current emitter source:
 *  + `this.migration`
 *  + `this.deployer`
 */
class Reporter {

  constructor(){
    this.deployer = null;
    this.migration = null;
    this.currentGasTotal = 0;
    this.currentCostTotal = new web3Utils.BN(0);
    this.finalCostTotal = new web3Utils.BN(0);
    this.deployments = 0;
    this.separator = '\n';
    this.summary = [];
    this.currentFileIndex = -1;
    this.blockSpinner = null;
    this.currentBlockWait = '';

    this.messages = new MigrationsMessages(this);
  }

  // ------------------------------------  Utilities -----------------------------------------------

  /**
   * Sets a Migration instance to be the current migrations events emitter source
   * @param {Migration} migration
   */
  setMigration(migration){
    this.migration = migration;
  }

  /**
   * Sets a Deployer instance as the current deployer events emitter source
   * @param {Deployer} deployer
   */
  setDeployer(deployer){
    this.deployer = deployer
  }

  /**
   * Registers emitter handlers
   */
  listen(){

    // Migration
    this.migration.emitter.on('preMigrate',          this.preMigrate.bind(this));
    this.migration.emitter.on('startTransaction',    this.startTransaction.bind(this));
    this.migration.emitter.on('endTransaction',      this.endTransaction.bind(this));
    this.migration.emitter.on('postMigrate',         this.postMigrate.bind(this));
    this.migration.emitter.on('error',               this.error.bind(this));

    // Deployment
    this.deployer.emitter.on('preDeploy',            this.preDeploy.bind(this));
    this.deployer.emitter.on('postDeploy',           this.postDeploy.bind(this));
    this.deployer.emitter.on('deployFailed',         this.deployFailed.bind(this));
    this.deployer.emitter.on('linking',              this.linking.bind(this));
    this.deployer.emitter.on('error',                this.error.bind(this));
    this.deployer.emitter.on('transactionHash',      this.hash.bind(this));
    this.deployer.emitter.on('confirmation',         this.confirmation.bind(this));
    this.deployer.emitter.on('block',                this.block.bind(this));
    this.deployer.emitter.on('startTransaction',     this.startTransaction.bind(this));
    this.deployer.emitter.on('endTransaction',       this.endTransaction.bind(this));
  }

  /**
   * Retrieves gas usage totals per migrations file / totals since the reporter
   * started running. Calling this method resets the gas counters for migrations totals
   */
  getTotals(){
    const gas = this.currentGasTotal;
    const cost = web3Utils.fromWei(this.currentCostTotal, "ether");
    this.finalCostTotal = this.finalCostTotal.add(this.currentCostTotal);

    this.currentGasTotal = 0;
    this.currentCostTotal = new web3Utils.BN(0);

    return {
      gas: gas,
      cost: cost,
      finalCost: web3Utils.fromWei(this.finalCostTotal, "ether"),
      deployments: this.deployments.toString()
    }
  }

  /**
   * Queries the user for a true/false response and resolves the result.
   * @param  {String} type identifier the reporter consumes to format query
   * @return {Promise}
   */
  askBoolean(type){
    const self = this;
    const question = this.messages.questions(type);
    const exitLine = this.messages.exitLines(type);

    // NB: We need direct access to a writeable stream here.
    // This ignores `quiet` - but we only use that mode for `truffle test`.
    const input = readline.createInterface({
      input: process.stdin,
      output: process.stdout
    });

    const affirmations = ['y', 'yes', 'YES', 'Yes'];

    return new Promise(resolve => {

      input.question(question, (answer) => {
        if (affirmations.includes(answer.trim())){
          input.close();
          return resolve(true);
        };

        input.close();
        self.deployer && self.deployer.logger.log(exitLine);
        resolve(false);
      })
    });
  }

  /**
   * Error dispatcher. Parses the error returned from web3 and outputs a more verbose error after
   * doing what it can to evaluate the failure context from data passed to it.
   * @param  {Object} data info collected during deployment attempt
   */
  async processDeploymentError(data){
    let message;
    const error = data.estimateError || data.error;

    data.reason = (data.error) ? data.error.reason : null;

    const errors = {
      ETH: error.message.includes('funds'),
      OOG: error.message.includes('out of gas'),
{'fraction_non_alphanumeric': 0.13353978978978978, 'fraction_numerical': 0.003003003003003003, 'mean_word_length': 2.8951023391812867, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7248641', 'n_tokens_mistral': 3174, 'n_tokens_neox': 3025, 'n_words': 780}