{"size": 1862, "ext": "js", "max_stars_repo_path": "node_modules/truffle/test/scenarios/migrations/parameters.js", "max_stars_repo_name": "ethercyrcus/web-app", "max_stars_repo_stars_event_min_datetime": "2018-11-23T09:41:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-25T09:02:55.000Z", "max_issues_repo_path": "node_modules/truffle/test/scenarios/migrations/parameters.js", "max_issues_repo_name": "ethercyrcus/web-app", "max_issues_repo_issues_event_min_datetime": "2020-07-20T05:07:07.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-08T23:20:04.000Z", "max_forks_repo_path": "node_modules/truffle/test/scenarios/migrations/parameters.js", "max_forks_repo_name": "ethercyrcus/web-app", "max_forks_repo_forks_event_min_datetime": "2018-11-26T01:43:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-25T09:03:01.000Z"}
{"max_stars_count": 4, "max_issues_count": 8, "max_forks_count": 4, "avg_line_length": 26.6, "max_line_length": 135, "alphanum_fraction": 0.6364124597}
var Box = require("truffle-box");
var MemoryLogger = require("../memorylogger");
var CommandRunner = require("../commandrunner");
var contract = require("truffle-contract");
var fs = require("fs-extra");
var path = require("path");
var assert = require("assert");
var Reporter = require("../reporter");
var Server = require("../server");
var Web3 = require("web3");

describe("Migration Parameters", function() {
  var config;
  var logger = new MemoryLogger();
  var accounts;

  before("set up the server", function(done) {
    Server.start(done);
  });

  after("stop server", function(done) {
    Server.stop(done);
  });

  before("set up sandbox", function(done) {
    this.timeout(10000);
    Box.sandbox("default", function(err, conf) {
      if (err) return done(err);
      config = conf;
      config.logger = logger;
      config.network = "development";
      config.mocha = {
        reporter: new Reporter(logger)
      }
      done();
    });
  });

  before("copy template migration", function() {
    fs.copySync(path.join(__dirname, "2_deploy_contract.js.template"), path.join(config.migrations_directory, "2_deploy_contract.js"));
  });

  before("get accounts", function(done) {
    var web3 = new Web3(config.provider);
    web3.eth.getAccounts(function(err, accs) {
      if (err) return done(err);
      accounts = accs;
      done();
    });
  });

  it("will migrate and save the correct output data", function(done) {
    this.timeout(50000);

    var expected_file = path.join(config.migrations_directory, "output.json");

    CommandRunner.run("migrate", config, function(err) {
      if (err) return done(err);

      var data = fs.readFileSync(expected_file, "utf8");
      data = JSON.parse(data);

      assert.equal(data.network, "development");
      assert.deepEqual(data.accounts, accounts);

      done();
    });
  });
});
