<commit_before>const { assert } = require("chai");
const CommandRunner = require("../commandrunner");
const Server = require("../server");
const sandbox = require("../sandbox");
const path = require("path");
const MemoryLogger = require("../memorylogger");

describe("truffle migrate --describe-json", () => {
  let config, projectPath;
  let logger = new MemoryLogger();

  before("before all setup", done => {
    projectPath = path.join(__dirname, "../../sources/migrations/init");
    sandbox
      .create(projectPath)
      .then(conf => {
        config = conf;
        config.network = "development";
        config.logger = logger;
      })
      .then(() => Server.start(done));
  });

  after(done => Server.stop(done));

  describe("when run on the most basic truffle project without --describe-json", () => {
    let contents;

    it("runs the migration without throwing", done => {
      CommandRunner.run("migrate --reset", config, error => {
        assert(error === undefined, "error should be undefined here");
        contents = logger.contents();
        done();
      });
    }).timeout(20000);

    it("does not include any `MIGRATION_STATUS` lines", done => {
      assert(!contents.includes("MIGRATION_STATUS"));
      done();
    });
  });

  describe("when run on the most basic truffle project with --describe-json", () => {
    let statuses = [];
    let cost = 0;

    it("runs the migration without throwing", done => {
      CommandRunner.run("migrate --reset --describe-json", config, error => {
        assert(error === undefined, "error should be undefined here");

        const contents = logger.contents();
        statuses = contents
          .split("\n")
          .filter(line => line.includes("MIGRATION_STATUS"))
          .map(line => JSON.parse(line.replace("MIGRATION_STATUS:", "")));

        done();
      });
    }).timeout(20000);

    it("includes all statuses", done => {
      assert.equal(statuses.length, 7);
      done();
    });

    it("includes preAllMigrations status", done => {
      const status = statuses[0];
      assert.equal(status.status, "preAllMigrations");
      assert.equal(status.data.dryRun, false);
      assert.equal(status.data.migrations.length, 1);
      done();
    });

    it("includes preMigrate status", done => {
      const status = statuses[1];
      assert.equal(status.status, "preMigrate");
      assert.equal(status.data.file, "1_initial_migration.js");
      assert.equal(status.data.number, 1);
      assert.equal(status.data.isFirst, true);
      assert.equal(status.data.network, "development");
      done();
    });

    it("includes replacing (aka deploying on fresh migrations) status", done => {
      const status = statuses[2];
      assert.equal(status.status, "replacing");
      assert.equal(status.data.contractName, "Migrations");
      assert.equal(typeof status.data.priorAddress, "string");
      assert.equal(status.data.priorAddress.slice(0, 2), "0x");
      assert.equal(status.data.priorAddress.length, 42);
      done();
    });

    it("includes deployed status", done => {
      const status = statuses[3];
      assert.equal(status.status, "deployed");
      assert.equal(status.data.contract.contractName, "Migrations");
      assert.equal(typeof status.data.contract.address, "string");
      assert.equal(status.data.contract.address.slice(0, 2), "0x");
      assert.equal(status.data.contract.address.length, 42);
      assert.equal(status.data.deployed, true);
      cost = parseFloat(status.data.cost);
      assert.equal(cost, 0.00522786);
      done();
    });

    it("includes postMigrate status", done => {
      const status = statuses[4];
      assert.equal(status.status, "postMigrate");
      assert.equal(status.data.number, 1);
      assert.equal(parseFloat(status.data.cost), cost);
      done();
    });
<commit_msg>make the cost check more permissive<commit_after>const { assert } = require("chai");
const CommandRunner = require("../commandrunner");
const Server = require("../server");
const sandbox = require("../sandbox");
const path = require("path");
const MemoryLogger = require("../memorylogger");

describe("truffle migrate --describe-json", () => {
  let config, projectPath;
  let logger = new MemoryLogger();

  before("before all setup", done => {
    projectPath = path.join(__dirname, "../../sources/migrations/init");
    sandbox
      .create(projectPath)
      .then(conf => {
        config = conf;
        config.network = "development";
        config.logger = logger;
      })
      .then(() => Server.start(done));
  });

  after(done => Server.stop(done));

  describe("when run on the most basic truffle project without --describe-json", () => {
    let contents;

    it("runs the migration without throwing", done => {
      CommandRunner.run("migrate --reset", config, error => {
        assert(error === undefined, "error should be undefined here");
        contents = logger.contents();
        done();
      });
    }).timeout(20000);

    it("does not include any `MIGRATION_STATUS` lines", done => {
      assert(!contents.includes("MIGRATION_STATUS"));
      done();
    });
  });

  describe("when run on the most basic truffle project with --describe-json", () => {
    let statuses = [];
    let cost = 0;

    it("runs the migration without throwing", done => {
      CommandRunner.run("migrate --reset --describe-json", config, error => {
        assert(error === undefined, "error should be undefined here");

        const contents = logger.contents();
        statuses = contents
          .split("\n")
          .filter(line => line.includes("MIGRATION_STATUS"))
          .map(line => JSON.parse(line.replace("MIGRATION_STATUS:", "")));

        done();
      });
    }).timeout(20000);

    it("includes all statuses", done => {
      assert.equal(statuses.length, 7);
      done();
    });

    it("includes preAllMigrations status", done => {
      const status = statuses[0];
      assert.equal(status.status, "preAllMigrations");
      assert.equal(status.data.dryRun, false);
      assert.equal(status.data.migrations.length, 1);
      done();
    });

    it("includes preMigrate status", done => {
      const status = statuses[1];
      assert.equal(status.status, "preMigrate");
      assert.equal(status.data.file, "1_initial_migration.js");
      assert.equal(status.data.number, 1);
      assert.equal(status.data.isFirst, true);
      assert.equal(status.data.network, "development");
      done();
    });

    it("includes replacing (aka deploying on fresh migrations) status", done => {
      const status = statuses[2];
      assert.equal(status.status, "replacing");
      assert.equal(status.data.contractName, "Migrations");
      assert.equal(typeof status.data.priorAddress, "string");
      assert.equal(status.data.priorAddress.slice(0, 2), "0x");
      assert.equal(status.data.priorAddress.length, 42);
      done();
    });

    it("includes deployed status", done => {
      const status = statuses[3];
      assert.equal(status.status, "deployed");
      assert.equal(status.data.contract.contractName, "Migrations");
      assert.equal(typeof status.data.contract.address, "string");
      assert.equal(status.data.contract.address.slice(0, 2), "0x");
      assert.equal(status.data.contract.address.length, 42);
      assert.equal(status.data.deployed, true);
      cost = parseFloat(status.data.cost);
      assert(cost > 0);
      done();
    });

    it("includes postMigrate status", done => {
      const status = statuses[4];
      assert.equal(status.status, "postMigrate");
      assert.equal(status.data.number, 1);
      assert.equal(parseFloat(status.data.cost), cost);
      done();
    });

{'fraction_non_alphanumeric': 0.16321243523316062, 'fraction_numerical': 0.00932642487046632, 'mean_word_length': 2.9984464008285863, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 44, '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': '3953803', 'n_tokens_mistral': 2309, 'n_tokens_neox': 2220, 'n_words': 483}