src/index.js
function wafr(options, callback) {
  const contractsPath = options.path;
  const optimizeCompiler = options.optimize;
  const sourcesExclude = options.exclude;
  const sourcesInclude = options.include;
  const focusContract = options.focus;
  const reportLogs = {
    contracts: {},
    status: 'success',
    failure: 0,
    success: 0,
    logs: {},
  };

  // get allinput sources
  getInputSources(contractsPath, sourcesExclude, sourcesInclude, focusContract, (inputError, sources) => {
    if (inputError) {
      throwError(`while getting input sources: ${inputError}`);
    }

    // build contract sources input for compiler
    const compilerInput = {
      sources: Object.assign({ 'wafr/Test.sol': testContract }, sources),
    };

    // compiling contracts
    log(`compiling contracts from ${Object.keys(sources).length} sources...`);

    // compile solc output (sync method)
    const output = solc.compile(compilerInput, optimizeCompiler);

    // output compiler warnings
    filterErrorErrors(output.errors).forEach((outputError) => {
      log(`while compiling contracts in path warning.. ${contractsPath}: ${outputError}`);
    });

    // handle all compiling errors
    if (filterErrorWarnings(output.errors).length > 0) {
      output.errors.forEach((outputError) => {
        throwError(`while compiling contracts in path ${contractsPath}: ${outputError}`);
      });
    } else {
      // compiling contracts
      log('contracts compiled!');

      const outputContracts = contractNameProcessing(options.onlyContractName, output.contracts);

      // add output to report
      reportLogs.contracts = outputContracts;

      // find and build test contracts array
      const testContracts = buildTestContractsArray(outputContracts);
      const startIndex = 0;

      // done function
      const contractComplete = (contractReport) => {
        // if contract failed, then all tests fail
        if (contractReport !== false) {
          if (contractReport.status === 'failure') {
            reportLogs.status = 'failure';
            reportLogs.failure += contractReport.failure;
          } else {
            reportLogs.success += contractReport.success;
          }
        }

        // if contract report is false, there is no more contracts to test
        if (contractReport === false) {
          // report done in log
          report(`

  ${reportLogs.failure && chalk.red(`${reportLogs.failure} not passing`) || ''}
  ${reportLogs.success && chalk.green(`${reportLogs.success} passing`) || ''}
`);

          // report logs
          callback(null, reportLogs);
        } else {
          reportLogs.logs[contractReport.name] = contractReport;
        }
      };

      // if no test contracts, end testing
      if (testContracts.length === 0) {
        contractComplete(false);
      } else {
        // test each contract sequentially
        testContractsSeq(startIndex, testContracts, contractComplete);
      }
    }
  });
}
function wafr(options, callback) {
  const contractsPath = options.path;
  const optimizeCompiler = options.optimize;
  const sourcesExclude = options.exclude;
  const sourcesInclude = options.include;
  const focusContract = options.focus;
  const reportLogs = {
    contracts: {},
    status: 'success',
    failure: 0,
    success: 0,
    logs: {},
  };

  // get allinput sources
  getInputSources(contractsPath, sourcesExclude, sourcesInclude, focusContract, (inputError, sources) => {
    if (inputError) {
      throwError(`while getting input sources: ${inputError}`);
    }

    // build contract sources input for compiler
    const compilerInput = {
      sources: Object.assign({ 'wafr/Test.sol': testContract }, sources),
    };

    // compiling contracts
    log(`compiling contracts from ${Object.keys(sources).length} sources...`);

    // compile solc output (sync method)
    const output = solc.compile(compilerInput, optimizeCompiler);

    // output compiler warnings
    filterErrorErrors(output.errors).forEach((outputError) => {
      log(`while compiling contracts in path warning.. ${contractsPath}: ${outputError}`);
    });

    // handle all compiling errors
    if (filterErrorWarnings(output.errors).length > 0) {
      output.errors.forEach((outputError) => {
        throwError(`while compiling contracts in path ${contractsPath}: ${outputError}`);
      });
    } else {
      // compiling contracts
      log('contracts compiled!');

      const outputContracts = contractNameProcessing(options.onlyContractName, output.contracts);

      // add output to report
      reportLogs.contracts = outputContracts;

      // find and build test contracts array
      const testContracts = buildTestContractsArray(outputContracts);
      const startIndex = 0;

      // done function
      const contractComplete = (contractReport) => {
        // if contract failed, then all tests fail
        if (contractReport !== false) {
          if (contractReport.status === 'failure') {
            reportLogs.status = 'failure';
            reportLogs.failure += contractReport.failure;
          } else {
            reportLogs.success += contractReport.success;
          }
        }

        // if contract report is false, there is no more contracts to test
        if (contractReport === false) {
          // report done in log
          report(`

  ${reportLogs.failure && chalk.red(`${reportLogs.failure} not passing`) || ''}
  ${reportLogs.success && chalk.green(`${reportLogs.success} passing`) || ''}
`);

          // report logs
          callback(null, reportLogs);
        } else {
          reportLogs.logs[contractReport.name] = contractReport;
        }
      };

      // if no test contracts, end testing
      if (testContracts.length === 0) {
        contractComplete(false);
      } else {
        // test each contract sequentially
        testContractsSeq(startIndex, testContracts, contractComplete);
      }
    }
  });
}
function wafr ( options , callback ) { const contractsPath = options . path ; const optimizeCompiler = options . optimize ; const sourcesExclude = options . exclude ; const sourcesInclude = options . include ; const focusContract = options . focus ; const reportLogs = { contracts : { } , status : 'success' , failure : 0 , success : 0 , logs : { } , } ; // get allinput sources getInputSources ( contractsPath , sourcesExclude , sourcesInclude , focusContract , ( inputError , sources ) => { if ( inputError ) { throwError ( ` ${ inputError } ` ) ; } // build contract sources input for compiler const compilerInput = { sources : Object . assign ( { 'wafr/Test.sol' : testContract } , sources ) , } ; // compiling contracts log ( ` ${ Object . keys ( sources ) . length } ` ) ; // compile solc output (sync method) const output = solc . compile ( compilerInput , optimizeCompiler ) ; // output compiler warnings filterErrorErrors ( output . errors ) . forEach ( ( outputError ) => { log ( ` ${ contractsPath } ${ outputError } ` ) ; } ) ; // handle all compiling errors if ( filterErrorWarnings ( output . errors ) . length > 0 ) { output . errors . forEach ( ( outputError ) => { throwError ( ` ${ contractsPath } ${ outputError } ` ) ; } ) ; } else { // compiling contracts log ( 'contracts compiled!' ) ; const outputContracts = contractNameProcessing ( options . onlyContractName , output . contracts ) ; // add output to report reportLogs . contracts = outputContracts ; // find and build test contracts array const testContracts = buildTestContractsArray ( outputContracts ) ; const startIndex = 0 ; // done function const contractComplete = ( contractReport ) => { // if contract failed, then all tests fail if ( contractReport !== false ) { if ( contractReport . status === 'failure' ) { reportLogs . status = 'failure' ; reportLogs . failure += contractReport . failure ; } else { reportLogs . success += contractReport . success ; } } // if contract report is false, there is no more contracts to test if ( contractReport === false ) { // report done in log report ( ` ${ reportLogs . failure && chalk . red ( ` ${ reportLogs . failure } ` ) || '' } ${ reportLogs . success && chalk . green ( ` ${ reportLogs . success } ` ) || '' } ` ) ; // report logs callback ( null , reportLogs ) ; } else { reportLogs . logs [ contractReport . name ] = contractReport ; } } ; // if no test contracts, end testing if ( testContracts . length === 0 ) { contractComplete ( false ) ; } else { // test each contract sequentially testContractsSeq ( startIndex , testContracts , contractComplete ) ; } } } ) ; }
run the main solTest export
run the main solTest export